contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
75 | B | Facetook Priority Wall | PROGRAMMING | 1,500 | [
"expression parsing",
"implementation",
"strings"
] | B. Facetook Priority Wall | 2 | 256 | Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).
This priority factor will be affected by three types of actions:
- 1. "*X* posted on *Y*'s wall" (15 points), - 2. "*X* commented on *Y*'s post" (10 points), - 3. "*X* likes *Y*'s post" (5 points).
*X* and *Y* will be two distinct names. And each action will increase the priority factor between *X* and *Y* (and vice versa) by the above value of points (the priority factor between *X* and *Y* is the same as the priority factor between *Y* and *X*).
You will be given *n* actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you. | The first line contains your name. The second line contains an integer *n*, which is the number of actions (1<=≤<=*n*<=≤<=100). Then *n* lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters. | Print *m* lines, where *m* is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order.
Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor.
The lexicographical comparison is performed by the standard "<" operator in modern programming languages. The line *a* is lexicographically smaller than the line *b*, if either *a* is the prefix of *b*, or if exists such an *i* (1<=≤<=*i*<=≤<=*min*(|*a*|,<=|*b*|)), that *a**i*<=<<=*b**i*, and for any *j* (1<=≤<=*j*<=<<=*i*) *a**j*<==<=*b**j*, where |*a*| and |*b*| stand for the lengths of strings *a* and *b* correspondently. | [
"ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post\n",
"aba\n1\nlikes likes posted's post\n"
] | [
"fatma\nmona\n",
"likes\nposted\n"
] | none | 1,000 | [
{
"input": "ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post",
"output": "fatma\nmona"
},
{
"input": "aba\n1\nlikes likes posted's post",
"output": "likes\nposted"
},
{
"input": "nu\n5\ng commented on pwyndmh's post\nqv posted on g's wall\ng likes nu's post\ng posted on nu's wall\nqv commented on pwyndmh's post",
"output": "g\npwyndmh\nqv"
},
{
"input": "szfwtzfp\n5\nzqx posted on szfwtzfp's wall\nr commented on scguem's post\nr posted on civ's wall\nr likes scguem's post\nr likes scguem's post",
"output": "zqx\nciv\nr\nscguem"
},
{
"input": "oaquudhavr\n3\ni posted on cwfwujpc's wall\ni likes oaquudhavr's post\noaquudhavr commented on cwfwujpc's post",
"output": "cwfwujpc\ni"
},
{
"input": "eo\n4\neo commented on xkgjgwxtrx's post\neo posted on iqquh's wall\nn commented on xkgjgwxtrx's post\niqquh commented on n's post",
"output": "iqquh\nxkgjgwxtrx\nn"
},
{
"input": "plwun\n3\neusjuq commented on plwun's post\nagktgdar likes eusjuq's post\nagppcoil likes agktgdar's post",
"output": "eusjuq\nagktgdar\nagppcoil"
},
{
"input": "fgzrn\n3\nzhl likes fgzrn's post\nxryet likes fgzrn's post\nzhl commented on fgzrn's post",
"output": "zhl\nxryet"
},
{
"input": "qatugmdjwg\n3\nb posted on cf's wall\nyjxkat posted on b's wall\nko commented on qatugmdjwg's post",
"output": "ko\nb\ncf\nyjxkat"
},
{
"input": "dagwdwxsuf\n5\nesrvncb commented on dagwdwxsuf's post\nzcepigpbz posted on dagwdwxsuf's wall\nesrvncb commented on zcepigpbz's post\nesrvncb commented on dagwdwxsuf's post\ndagwdwxsuf commented on esrvncb's post",
"output": "esrvncb\nzcepigpbz"
},
{
"input": "a\n1\nb likes c's post",
"output": "b\nc"
},
{
"input": "a\n1\nc likes b's post",
"output": "b\nc"
},
{
"input": "wuaiz\n10\nmnbggnud posted on xttaqvel's wall\ns posted on xopffmspf's wall\nkysxb likes qnrtpzkh's post\ngptks likes quebtsup's post\nkgmd commented on kmtnhsiue's post\newqjtxtiyn commented on a's post\nol posted on iglplaj's wall\nif posted on yuo's wall\nfs posted on dwjtuhgrq's wall\nygmdprun likes tzfneuly's post",
"output": "a\ndwjtuhgrq\newqjtxtiyn\nfs\ngptks\nif\niglplaj\nkgmd\nkmtnhsiue\nkysxb\nmnbggnud\nol\nqnrtpzkh\nquebtsup\ns\ntzfneuly\nxopffmspf\nxttaqvel\nygmdprun\nyuo"
},
{
"input": "fzhzg\n11\nv likes xyf's post\nktqtpzhlh commented on ffsxarrn's post\nktqtpzhlh commented on lbt's post\njcdwpcycj commented on qbuigcgflm's post\nl likes pmg's post\nracszbmsk posted on ojr's wall\nojr commented on n's post\nnzqx commented on lkj's post\nv posted on lzoca's wall\nnwqnoham commented on gyivezpu's post\nfzhzg likes uqvzgzrpac's post",
"output": "uqvzgzrpac\nffsxarrn\ngyivezpu\njcdwpcycj\nktqtpzhlh\nl\nlbt\nlkj\nlzoca\nn\nnwqnoham\nnzqx\nojr\npmg\nqbuigcgflm\nracszbmsk\nv\nxyf"
},
{
"input": "qdrnpb\n12\nymklhj commented on dkcbo's post\nhcucrenckl posted on mut's wall\nnvkyta commented on eo's post\npvgow likes mut's post\nob likes wlwcxtf's post\npvgow commented on advpu's post\nkfflyfbr commented on igozjnrxw's post\nsq commented on qdrnpb's post\nmrvn posted on lahduc's wall\ngsnlicy likes u's post\ndltqujf commented on qgzk's post\nr posted on bey's wall",
"output": "sq\nadvpu\nbey\ndkcbo\ndltqujf\neo\ngsnlicy\nhcucrenckl\nigozjnrxw\nkfflyfbr\nlahduc\nmrvn\nmut\nnvkyta\nob\npvgow\nqgzk\nr\nu\nwlwcxtf\nymklhj"
},
{
"input": "biycvwb\n13\nhp likes cigobksf's post\nmcoqt commented on gaswzwat's post\nnz posted on xyvetbokl's wall\nqbnwy commented on ylkfbwjy's post\nqdwktrro likes rxgujnzecs's post\nbbsw commented on hwtatkfnps's post\ngspx posted on ugjxfnahuc's wall\nxlmut likes plle's post\numbwlleag commented on xfwlhen's post\nrlwxqksbwi commented on rypqtrgf's post\nbj posted on vovq's wall\nozpdpb commented on zti's post\nhqj posted on rxgujnzecs's wall",
"output": "bbsw\nbj\ncigobksf\ngaswzwat\ngspx\nhp\nhqj\nhwtatkfnps\nmcoqt\nnz\nozpdpb\nplle\nqbnwy\nqdwktrro\nrlwxqksbwi\nrxgujnzecs\nrypqtrgf\nugjxfnahuc\numbwlleag\nvovq\nxfwlhen\nxlmut\nxyvetbokl\nylkfbwjy\nzti"
},
{
"input": "kmircqsffq\n14\nfrnf likes xgmmp's post\nfnfdpupayp commented on syz's post\nxefshpn commented on xgmmp's post\nm posted on gdwydzktok's wall\neskm likes pqmbnuc's post\npnqiapduhz likes zzqvjdz's post\nx likes nouuurc's post\nvnyxhoukuo posted on uhblapjab's wall\nblpjpxn likes zvwbger's post\nj posted on vuknetvl's wall\nscsw commented on xaggwxlxe's post\npqmbnuc commented on ojwaibie's post\niaazdlqdew commented on kmircqsffq's post\nqznqshxdi commented on umdqztoqun's post",
"output": "iaazdlqdew\nblpjpxn\neskm\nfnfdpupayp\nfrnf\ngdwydzktok\nj\nm\nnouuurc\nojwaibie\npnqiapduhz\npqmbnuc\nqznqshxdi\nscsw\nsyz\nuhblapjab\numdqztoqun\nvnyxhoukuo\nvuknetvl\nx\nxaggwxlxe\nxefshpn\nxgmmp\nzvwbger\nzzqvjdz"
},
{
"input": "posted\n3\nposted posted on fatma's wall\nfatma commented on posted's post\nmona likes posted's post",
"output": "fatma\nmona"
},
{
"input": "posted\n3\nposted posted on wall's wall\nwall commented on posted's post\nmona likes posted's post",
"output": "wall\nmona"
},
{
"input": "posted\n3\nposted posted on wall's wall\nwall commented on posted's post\npost likes posted's post",
"output": "wall\npost"
},
{
"input": "wall\n5\nwall posted on posted's wall\nwall posted on on's wall\nwall posted on commented's wall\nwall posted on likes's wall\nwall posted on post's wall",
"output": "commented\nlikes\non\npost\nposted"
},
{
"input": "commented\n5\non commented on commented's post\npos commented on commented's post\nlikes commented on commented's post\nposted commented on commented's post\nwall commented on commented's post",
"output": "likes\non\npos\nposted\nwall"
},
{
"input": "likes\n3\nlikes posted on post's wall\nlikes commented on on's post\nlikes likes commented's post",
"output": "post\non\ncommented"
},
{
"input": "on\n4\non posted on posted's wall\non commented on commented's post\non posted on wall's wall\non commented on post's post",
"output": "posted\nwall\ncommented\npost"
},
{
"input": "wall\n9\nwall posted on posted's wall\non commented on wall's post\nwall likes post's post\nposted posted on wall's wall\nwall commented on post's post\nlikes likes wall's post\nwall posted on on's wall\npost commented on wall's post\nwall likes likes's post",
"output": "posted\non\npost\nlikes"
},
{
"input": "post\n9\npost posted on wall's wall\non commented on post's post\npost likes likes's post\ncommented posted on post's wall\npost commented on likes's post\nlikes likes post's post\npost posted on posted's wall\non commented on post's post\npost likes commented's post",
"output": "commented\nlikes\non\nposted\nwall"
},
{
"input": "ahmed\n9\npost posted on ahmeds's wall\nahmeds commented on post's post\npost likes ahmeds's post\nahmeds posted on post's wall\npost commented on ahmeds's post\nahmeds likes post's post\npost posted on ahmeds's wall\nahmeds commented on post's post\npost likes ahmeds's post",
"output": "ahmeds\npost"
}
] | 1,684,246,725 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 60 | 124 | 0 | class Chain:
def __init__(self, f, s):
self.f = f
self.s = s
me = input()
n = int(input())
mp = {}
for i in range(n):
a = list(map(str, input().split()))
if a[1] == "likes":
ot = a[2]
else:
ot = a[3]
# parse the name
her = ""
for j in range(len(ot)-2):
her += ot[j]
if me != a[0] and me != her:
try:
x = mp.get(a[0])
mp[a[0]] += 0
except:
mp[a[0]] = 0
try:
x = mp.get(her)
mp[her] += 0
except:
mp[her] = 0
continue
if a[1] == "posted":
try:
x = mp.get(a[0])
mp[a[0]] += 15
except:
mp[a[0]] = 15
try:
x = mp.get(a[0])
mp[her] += 15
except:
mp[her] = 15
elif a[1] == "commented":
try:
x = mp.get(a[0])
mp[a[0]] += 10
except:
mp[a[0]] = 10
try:
x = mp.get(a[0])
mp[her] += 10
except:
mp[her] = 10
else:
try:
x = mp.get(a[0])
mp[a[0]] += 5
except:
mp[a[0]] = 5
try:
x = mp.get(a[0])
mp[her] += 5
except:
mp[her] = 5
names = []
for i in mp:
if i != me:
names.append(Chain(mp[i], i))
l = sorted(names, key=lambda x: (-x.f, x.s))
for i in range(len(names)):
print(l[i].s)
| Title: Facetook Priority Wall
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).
This priority factor will be affected by three types of actions:
- 1. "*X* posted on *Y*'s wall" (15 points), - 2. "*X* commented on *Y*'s post" (10 points), - 3. "*X* likes *Y*'s post" (5 points).
*X* and *Y* will be two distinct names. And each action will increase the priority factor between *X* and *Y* (and vice versa) by the above value of points (the priority factor between *X* and *Y* is the same as the priority factor between *Y* and *X*).
You will be given *n* actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you.
Input Specification:
The first line contains your name. The second line contains an integer *n*, which is the number of actions (1<=≤<=*n*<=≤<=100). Then *n* lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters.
Output Specification:
Print *m* lines, where *m* is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order.
Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor.
The lexicographical comparison is performed by the standard "<" operator in modern programming languages. The line *a* is lexicographically smaller than the line *b*, if either *a* is the prefix of *b*, or if exists such an *i* (1<=≤<=*i*<=≤<=*min*(|*a*|,<=|*b*|)), that *a**i*<=<<=*b**i*, and for any *j* (1<=≤<=*j*<=<<=*i*) *a**j*<==<=*b**j*, where |*a*| and |*b*| stand for the lengths of strings *a* and *b* correspondently.
Demo Input:
["ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post\n", "aba\n1\nlikes likes posted's post\n"]
Demo Output:
['fatma\nmona\n', 'likes\nposted\n']
Note:
none | ```python
class Chain:
def __init__(self, f, s):
self.f = f
self.s = s
me = input()
n = int(input())
mp = {}
for i in range(n):
a = list(map(str, input().split()))
if a[1] == "likes":
ot = a[2]
else:
ot = a[3]
# parse the name
her = ""
for j in range(len(ot)-2):
her += ot[j]
if me != a[0] and me != her:
try:
x = mp.get(a[0])
mp[a[0]] += 0
except:
mp[a[0]] = 0
try:
x = mp.get(her)
mp[her] += 0
except:
mp[her] = 0
continue
if a[1] == "posted":
try:
x = mp.get(a[0])
mp[a[0]] += 15
except:
mp[a[0]] = 15
try:
x = mp.get(a[0])
mp[her] += 15
except:
mp[her] = 15
elif a[1] == "commented":
try:
x = mp.get(a[0])
mp[a[0]] += 10
except:
mp[a[0]] = 10
try:
x = mp.get(a[0])
mp[her] += 10
except:
mp[her] = 10
else:
try:
x = mp.get(a[0])
mp[a[0]] += 5
except:
mp[a[0]] = 5
try:
x = mp.get(a[0])
mp[her] += 5
except:
mp[her] = 5
names = []
for i in mp:
if i != me:
names.append(Chain(mp[i], i))
l = sorted(names, key=lambda x: (-x.f, x.s))
for i in range(len(names)):
print(l[i].s)
``` | 3.969 |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "10000220"
},
{
"input": ".",
"output": "0"
},
{
"input": "-.",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "..",
"output": "00"
},
{
"input": "--.",
"output": "20"
},
{
"input": ".--.",
"output": "020"
},
{
"input": ".-.-..",
"output": "0110"
},
{
"input": "----.-.",
"output": "2201"
},
{
"input": "-..--.-.",
"output": "10201"
},
{
"input": "..--..--.",
"output": "0020020"
},
{
"input": "-.-.---.--..-..-.-.-..-..-.--.",
"output": "112120010111010120"
},
{
"input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.",
"output": "21112220010101011012011011221011"
},
{
"input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------",
"output": "11020111110111222212021020002022111100201121222020012022110010222"
},
{
"input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..",
"output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110"
},
{
"input": ".-..-.-.---.-----.--.---...-.--.-.-....-..",
"output": "01011212212021001201100010"
},
{
"input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..",
"output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210"
},
{
"input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.",
"output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220"
},
{
"input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----",
"output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122"
},
{
"input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..",
"output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110"
},
{
"input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.",
"output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020"
},
{
"input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..",
"output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200"
},
{
"input": "-.---...----...--.--...-.--.----",
"output": "121002200020200012022"
},
{
"input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.",
"output": "202020212012111010201021100001021221200011222112012201012220"
}
] | 1,649,009,325 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | s = input()
def just_print(s):
print(s, sep = "", end = "")
dashed = False
for c in s:
if dashed:
dashed = False
if c == '.':
just_print(1)
elif c == '-':
just_print(2)
elif c == '-':
dashed = True
else:
just_print(0) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input Specification:
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output Specification:
Output the decoded ternary number. It can have leading zeroes.
Demo Input:
['.-.--\n', '--.\n', '-..-.--\n']
Demo Output:
['012', '20', '1012']
Note:
none | ```python
s = input()
def just_print(s):
print(s, sep = "", end = "")
dashed = False
for c in s:
if dashed:
dashed = False
if c == '.':
just_print(1)
elif c == '-':
just_print(2)
elif c == '-':
dashed = True
else:
just_print(0)
``` | 3.977 |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B",
"output": "#Color"
},
{
"input": "1 6\nC M Y W G B",
"output": "#Color"
},
{
"input": "1 3\nW G B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G C",
"output": "#Color"
},
{
"input": "2 3\nW W W\nB G M",
"output": "#Color"
},
{
"input": "3 3\nC B W\nB Y M\nB B W",
"output": "#Color"
},
{
"input": "1 3\nW C W",
"output": "#Color"
},
{
"input": "3 3\nB W B\nB C W\nB W W",
"output": "#Color"
},
{
"input": "1 2\nW Y",
"output": "#Color"
},
{
"input": "1 1\nG",
"output": "#Black&White"
},
{
"input": "1 3\nB G W",
"output": "#Black&White"
},
{
"input": "2 2\nW W\nB C",
"output": "#Color"
},
{
"input": "1 1\nM",
"output": "#Color"
},
{
"input": "1 2\nW C",
"output": "#Color"
},
{
"input": "2 3\nW W M\nW W M",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB C",
"output": "#Color"
},
{
"input": "2 3\nW W C\nW W W",
"output": "#Color"
},
{
"input": "1 3\nG G G",
"output": "#Black&White"
},
{
"input": "1 1\nC",
"output": "#Color"
},
{
"input": "1 2\nC W",
"output": "#Color"
},
{
"input": "1 3\nW W C",
"output": "#Color"
},
{
"input": "2 2\nW B\nB G",
"output": "#Black&White"
},
{
"input": "2 2\nB B\nY Y",
"output": "#Color"
},
{
"input": "2 2\nG G\nC C",
"output": "#Color"
},
{
"input": "1 2\nB C",
"output": "#Color"
},
{
"input": "1 4\nG G G C",
"output": "#Color"
},
{
"input": "1 1\nB",
"output": "#Black&White"
},
{
"input": "2 1\nY\nB",
"output": "#Color"
}
] | 1,692,955,733 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | m,n = map(int,input().split())
a = []
for i in range(m):
a.append([str(j) for j in input().split()])
s=set()
for i in range(m):
for j in range (n):
s.add(a[i][j])
if "C" in s or "M" in s or "Y" in s or "G" in s:
print("#Color")
print(s)
else:
print("#Black&White") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output Specification:
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Demo Input:
['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n']
Demo Output:
['#Color', '#Black&White', '#Black&White']
Note:
none | ```python
m,n = map(int,input().split())
a = []
for i in range(m):
a.append([str(j) for j in input().split()])
s=set()
for i in range(m):
for j in range (n):
s.add(a[i][j])
if "C" in s or "M" in s or "Y" in s or "G" in s:
print("#Color")
print(s)
else:
print("#Black&White")
``` | 0 |
|
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "3 2",
"output": "5"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "999 2",
"output": "1997"
},
{
"input": "1000 3",
"output": "1499"
},
{
"input": "1000 4",
"output": "1333"
},
{
"input": "1 1000",
"output": "1"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "10 4",
"output": "13"
},
{
"input": "4 3",
"output": "5"
},
{
"input": "91 5",
"output": "113"
},
{
"input": "777 17",
"output": "825"
},
{
"input": "100 4",
"output": "133"
},
{
"input": "5 3",
"output": "7"
},
{
"input": "6 4",
"output": "7"
},
{
"input": "26 8",
"output": "29"
},
{
"input": "9 4",
"output": "11"
},
{
"input": "20 3",
"output": "29"
},
{
"input": "17 3",
"output": "25"
}
] | 1,693,578,358 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | a,b=list(map(int,input().split(" ")))
res=a
li=res
while(li>=b):
li/=b
res+=round(li)
print(res) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
Input Specification:
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Output Specification:
Print a single integer — the number of hours Vasily can light up the room for.
Demo Input:
['4 2\n', '6 3\n']
Demo Output:
['7\n', '8\n']
Note:
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | ```python
a,b=list(map(int,input().split(" ")))
res=a
li=res
while(li>=b):
li/=b
res+=round(li)
print(res)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers *p* and *k*, find a polynomial *f*(*x*) with non-negative integer coefficients strictly less than *k*, whose remainder is *p* when divided by (*x*<=+<=*k*). That is, *f*(*x*)<==<=*q*(*x*)·(*x*<=+<=*k*)<=+<=*p*, where *q*(*x*) is a polynomial (not necessarily with integer coefficients). | The only line of input contains two space-separated integers *p* and *k* (1<=≤<=*p*<=≤<=1018, 2<=≤<=*k*<=≤<=2<=000). | If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer *d* — the number of coefficients in the polynomial.
In the second line print *d* space-separated integers *a*0,<=*a*1,<=...,<=*a**d*<=-<=1, describing a polynomial fulfilling the given requirements. Your output should satisfy 0<=≤<=*a**i*<=<<=*k* for all 0<=≤<=*i*<=≤<=*d*<=-<=1, and *a**d*<=-<=1<=≠<=0.
If there are many possible solutions, print any of them. | [
"46 2\n",
"2018 214\n"
] | [
"7\n0 1 0 0 1 1 1\n",
"3\n92 205 1\n"
] | In the first example, *f*(*x*) = *x*<sup class="upper-index">6</sup> + *x*<sup class="upper-index">5</sup> + *x*<sup class="upper-index">4</sup> + *x* = (*x*<sup class="upper-index">5</sup> - *x*<sup class="upper-index">4</sup> + 3*x*<sup class="upper-index">3</sup> - 6*x*<sup class="upper-index">2</sup> + 12*x* - 23)·(*x* + 2) + 46.
In the second example, *f*(*x*) = *x*<sup class="upper-index">2</sup> + 205*x* + 92 = (*x* - 9)·(*x* + 214) + 2018. | 0 | [
{
"input": "46 2",
"output": "7\n0 1 0 0 1 1 1"
},
{
"input": "2018 214",
"output": "3\n92 205 1"
},
{
"input": "4 2",
"output": "3\n0 0 1"
},
{
"input": "5 2",
"output": "3\n1 0 1"
},
{
"input": "10 3",
"output": "3\n1 0 1"
},
{
"input": "250 1958",
"output": "1\n250"
},
{
"input": "1000000000000000000 2000",
"output": "7\n0 0 0 0 500 1969 1"
},
{
"input": "1 2",
"output": "1\n1"
},
{
"input": "2 2",
"output": "3\n0 1 1"
},
{
"input": "3 2",
"output": "3\n1 1 1"
},
{
"input": "6 2",
"output": "5\n0 1 0 1 1"
},
{
"input": "7 2",
"output": "5\n1 1 0 1 1"
},
{
"input": "8 2",
"output": "5\n0 0 0 1 1"
},
{
"input": "9 2",
"output": "5\n1 0 0 1 1"
},
{
"input": "10 2",
"output": "5\n0 1 1 1 1"
},
{
"input": "1 3",
"output": "1\n1"
},
{
"input": "2 3",
"output": "1\n2"
},
{
"input": "3 3",
"output": "3\n0 2 1"
},
{
"input": "4 3",
"output": "3\n1 2 1"
},
{
"input": "5 3",
"output": "3\n2 2 1"
},
{
"input": "6 3",
"output": "3\n0 1 1"
},
{
"input": "7 3",
"output": "3\n1 1 1"
},
{
"input": "8 3",
"output": "3\n2 1 1"
},
{
"input": "9 3",
"output": "3\n0 0 1"
},
{
"input": "462 2",
"output": "11\n0 1 0 0 1 0 1 1 0 1 1"
},
{
"input": "462 3",
"output": "7\n0 2 1 1 0 1 1"
},
{
"input": "2018 4",
"output": "7\n2 0 2 1 0 2 1"
},
{
"input": "20180214 5",
"output": "11\n4 3 4 4 4 3 2 2 2 0 2"
},
{
"input": "1317 221",
"output": "3\n212 216 1"
},
{
"input": "1314 520",
"output": "3\n274 518 1"
},
{
"input": "1562 862",
"output": "3\n700 861 1"
},
{
"input": "6666666666666666 3",
"output": "35\n0 1 2 0 0 2 2 1 2 2 1 1 2 2 2 2 0 0 0 2 1 2 1 1 1 1 1 2 1 2 0 1 1 2 1"
},
{
"input": "252525252525252525 252",
"output": "9\n189 176 211 80 27 238 231 249 1"
},
{
"input": "271828182845904523 536",
"output": "7\n3 157 21 240 147 288 12"
},
{
"input": "314159265358979323 846",
"output": "7\n553 47 111 353 790 122 1"
},
{
"input": "393939393939393939 393",
"output": "7\n237 191 82 181 11 30 107"
},
{
"input": "233333333333333333 2000",
"output": "7\n1333 1334 1334 1334 584 1993 1"
},
{
"input": "998244353998244353 2000",
"output": "7\n353 878 500 1456 391 1969 1"
},
{
"input": "1000000000000000000 2",
"output": "61\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 1 0 0 0 0 1 0 0 0 1 0 0 1"
},
{
"input": "1000000000000000000 3",
"output": "39\n1 0 0 0 2 0 2 2 0 2 0 0 1 1 1 2 1 1 1 0 1 2 2 0 1 1 1 2 0 0 0 1 0 0 0 1 1 1 1"
}
] | 1,518,615,190 | 5,290 | PyPy 3 | WRONG_ANSWER | PRETESTS | 5 | 77 | 19,968,000 | # import sys
# sys.stdin = open('in.txt', 'r')
p, k = map(int, input().split())
b = []
for i in range(200):
if i == 0:
if p%k == 0:
b.append(-p//k)
else:
b.append(-p//k+1)
else:
if b[i-1]%k == 0:
b.append(-b[i-1]//k)
else:
b.append(-b[i-1]//k+1)
if b[-1] == 0:
b.pop()
break
# print(b)
if(len(b) == 0):
print(-1)
exit(0)
a = []
for i in range(len(b)):
if i == 0:
a.append(k*b[i]+p)
else:
a.append(k*b[i]+b[i-1])
a.append(b[-1])
if all(map(lambda x: x < k, a)):
print(len(a))
print(' '.join(map(str, a)))
else:
print(-1)
#
# b[2] b[1] b[0]
# kb[2] kb[1] kb[0]+p
#
# 0 <= b[1] + kb[2] < k
# 0 <= b[0] + kb[1] < k
# 0 <= kb[0] + p < k
#
# -p/k <= b[0] < (k-p)/k
# -b[0]/k <= b[1] < (k-b[0])/k
# -b[1]/k <= b[2] < (k-b[1])/k
# 0 <= b[2] < k
#
# -p/k <= b[0] < -p/k + 1
# -b[0]/k <= b[1] < -b[0]/k + 1
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers *p* and *k*, find a polynomial *f*(*x*) with non-negative integer coefficients strictly less than *k*, whose remainder is *p* when divided by (*x*<=+<=*k*). That is, *f*(*x*)<==<=*q*(*x*)·(*x*<=+<=*k*)<=+<=*p*, where *q*(*x*) is a polynomial (not necessarily with integer coefficients).
Input Specification:
The only line of input contains two space-separated integers *p* and *k* (1<=≤<=*p*<=≤<=1018, 2<=≤<=*k*<=≤<=2<=000).
Output Specification:
If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer *d* — the number of coefficients in the polynomial.
In the second line print *d* space-separated integers *a*0,<=*a*1,<=...,<=*a**d*<=-<=1, describing a polynomial fulfilling the given requirements. Your output should satisfy 0<=≤<=*a**i*<=<<=*k* for all 0<=≤<=*i*<=≤<=*d*<=-<=1, and *a**d*<=-<=1<=≠<=0.
If there are many possible solutions, print any of them.
Demo Input:
['46 2\n', '2018 214\n']
Demo Output:
['7\n0 1 0 0 1 1 1\n', '3\n92 205 1\n']
Note:
In the first example, *f*(*x*) = *x*<sup class="upper-index">6</sup> + *x*<sup class="upper-index">5</sup> + *x*<sup class="upper-index">4</sup> + *x* = (*x*<sup class="upper-index">5</sup> - *x*<sup class="upper-index">4</sup> + 3*x*<sup class="upper-index">3</sup> - 6*x*<sup class="upper-index">2</sup> + 12*x* - 23)·(*x* + 2) + 46.
In the second example, *f*(*x*) = *x*<sup class="upper-index">2</sup> + 205*x* + 92 = (*x* - 9)·(*x* + 214) + 2018. | ```python
# import sys
# sys.stdin = open('in.txt', 'r')
p, k = map(int, input().split())
b = []
for i in range(200):
if i == 0:
if p%k == 0:
b.append(-p//k)
else:
b.append(-p//k+1)
else:
if b[i-1]%k == 0:
b.append(-b[i-1]//k)
else:
b.append(-b[i-1]//k+1)
if b[-1] == 0:
b.pop()
break
# print(b)
if(len(b) == 0):
print(-1)
exit(0)
a = []
for i in range(len(b)):
if i == 0:
a.append(k*b[i]+p)
else:
a.append(k*b[i]+b[i-1])
a.append(b[-1])
if all(map(lambda x: x < k, a)):
print(len(a))
print(' '.join(map(str, a)))
else:
print(-1)
#
# b[2] b[1] b[0]
# kb[2] kb[1] kb[0]+p
#
# 0 <= b[1] + kb[2] < k
# 0 <= b[0] + kb[1] < k
# 0 <= kb[0] + p < k
#
# -p/k <= b[0] < (k-p)/k
# -b[0]/k <= b[1] < (k-b[0])/k
# -b[1]/k <= b[2] < (k-b[1])/k
# 0 <= b[2] < k
#
# -p/k <= b[0] < -p/k + 1
# -b[0]/k <= b[1] < -b[0]/k + 1
``` | 0 |
|
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*). | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 100\n71 73\n80 94\n81 92\n84 85\n85 100\n88 91\n91 95\n92 98\n92 98\n99 100\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 6\n1 6\n1 2\n1 3\n1 2\n1 3\n2 5\n2 4\n2 3\n2 4\n2 6\n2 2\n2 5\n2 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 9\n3 3\n3 7\n3 9\n3 3\n3 9\n4 6\n4 7\n4 5\n4 7\n5 8\n5 5\n5 9\n5 7\n5 5\n6 6\n6 9\n6 7\n6 8\n6 9\n6 8\n7 7\n7 8\n7 7\n7 8\n8 9\n8 8\n8 9\n8 8\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 10\n8 10\n9 9\n9 9\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 100\n1 38\n2 82\n5 35\n7 71\n8 53\n11 49\n15 27\n17 84\n17 75\n18 99\n18 43\n18 69\n21 89\n27 60\n27 29\n38 62\n38 77\n39 83\n40 66\n48 80\n48 100\n50 51\n50 61\n53 77\n53 63\n55 58\n56 68\n60 82\n62 95\n66 74\n67 83\n69 88\n69 81\n69 88\n69 98\n70 91\n70 76\n71 90\n72 99\n81 99\n85 87\n88 97\n88 93\n90 97\n90 97\n92 98\n98 99\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 10\n1 9\n1 6\n1 2\n1 3\n1 2\n2 6\n2 5\n2 4\n2 3\n2 10\n2 2\n2 6\n2 2\n3 10\n3 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 10\n3 5\n3 3\n3 7\n4 8\n4 8\n4 9\n4 6\n5 7\n5 10\n5 7\n5 8\n5 5\n6 8\n6 9\n6 10\n6 6\n6 9\n6 7\n7 8\n7 9\n7 10\n7 10\n8 8\n8 8\n8 9\n8 10\n9 10\n9 9\n9 10\n9 10\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 4\n1 5\n1 9\n1 1\n1 6\n1 6\n2 5\n2 7\n2 7\n2 7\n2 7\n3 4\n3 7\n3 9\n3 5\n3 3\n4 4\n4 6\n4 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n5 8\n5 9\n5 8\n6 8\n6 7\n6 8\n6 9\n6 9\n6 6\n6 9\n6 7\n7 7\n7 7\n7 7\n7 8\n7 7\n7 8\n7 8\n7 9\n8 8\n8 8\n8 8\n8 8\n8 8\n8 9\n8 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 40\n38 38\n40 40",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 92\n92 97\n96 99\n97 98\n97 99\n99 99\n100 100\n100 100\n100 100",
"output": "NO"
},
{
"input": "1 10\n0 10",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 40\n23 23\n23 28\n24 29\n25 38\n26 35\n27 37\n28 39\n28 33\n28 40\n28 33\n29 31\n29 33\n30 38\n30 36\n30 30\n30 38\n31 37\n31 35\n31 32\n31 36\n33 39\n33 40\n35 38\n36 38\n37 38\n37 40\n38 39\n38 40\n38 39\n39 39\n39 40\n40 40\n40 40\n40 40\n40 40",
"output": "YES"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 40\n11 31\n12 26\n13 25\n14 32\n17 19\n21 29\n22 36\n24 27\n25 39\n25 27\n27 32\n27 29\n27 39\n27 29\n28 38\n30 38\n32 40\n32 38\n33 33\n33 40\n34 35\n34 34\n34 38\n34 38\n35 37\n36 39\n36 39\n37 37\n38 40\n39 39\n40 40",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 22\n23 28\n23 39\n24 24\n25 27\n26 38\n27 39\n28 33\n28 39\n28 34\n28 33\n29 30\n29 35\n30 30\n30 38\n30 34\n30 31\n31 36\n31 31\n31 32\n31 38\n33 34\n33 34\n35 36\n36 38\n37 38\n37 39\n38 38\n38 38\n38 38\n39 39\n39 39\n40 40\n40 40\n40 40\n40 40",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n88 99",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 10\n7 10\n9 10",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 5\n4 8\n5 5\n5 7\n6 7\n6 6\n7 7\n7 7\n7 7\n7 8\n7 8\n8 8\n8 8\n8 9\n8 8\n8 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n32 37",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 10\n4 6\n5 9\n5 5\n6 7\n6 10\n7 8\n7 7\n7 7\n7 7\n7 10\n8 8\n8 8\n8 10\n8 8\n8 8\n9 10\n9 10\n9 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "1 1\n0 1",
"output": "YES"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 36\n38 38\n40 40",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 82\n71 94\n80 90\n81 88\n84 93\n85 89\n88 92\n91 97\n92 99\n92 97\n99 99\n100 100",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n79 100",
"output": "YES"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n37 40",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 10\n1 2\n1 5\n1 10\n1 8\n1 1\n2 8\n2 7\n2 5\n2 5\n2 7\n3 5\n3 7\n3 5\n3 4\n3 7\n4 7\n4 8\n4 6\n5 7\n5 10\n5 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n6 10\n6 9\n6 7\n6 10\n6 8\n6 7\n6 10\n6 10\n7 8\n7 9\n7 8\n7 8\n7 8\n7 8\n7 7\n7 7\n8 8\n8 8\n8 10\n8 9\n8 9\n8 9\n8 9\n9 9\n9 10\n9 9\n9 9\n9 9\n9 9\n9 10\n9 10\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 7\n1 69\n2 83\n5 67\n7 82\n8 31\n11 25\n15 44\n17 75\n17 27\n18 43\n18 69\n18 40\n21 66\n27 29\n27 64\n38 77\n38 90\n39 52\n40 60\n48 91\n48 98\n50 89\n50 63\n53 54\n53 95\n55 76\n56 59\n60 96\n62 86\n66 70\n67 77\n69 88\n69 98\n69 80\n69 95\n70 74\n70 77\n71 99\n72 73\n81 87\n85 99\n88 96\n88 91\n90 97\n90 99\n92 92\n98 99\n100 100",
"output": "NO"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 35\n11 23\n12 36\n13 31\n14 31\n17 17\n21 25\n22 33\n24 26\n25 32\n25 25\n27 39\n27 29\n27 34\n27 32\n28 34\n30 36\n32 37\n32 33\n33 35\n33 33\n34 38\n34 38\n34 36\n34 36\n35 36\n36 36\n36 39\n37 37\n38 39\n39 39\n40 40",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 9\n7 7\n9 9",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 100\n92 97\n96 96\n97 98\n97 100\n99 100\n100 100\n100 100\n100 100",
"output": "YES"
},
{
"input": "2 2\n0 2\n0 1",
"output": "YES"
},
{
"input": "2 100\n0 49\n50 100",
"output": "NO"
},
{
"input": "2 100\n0 50\n50 100",
"output": "YES"
},
{
"input": "10 100\n0 10\n10 20\n20 30\n30 40\n40 50\n50 60\n60 70\n70 80\n80 90\n90 100",
"output": "YES"
},
{
"input": "100 10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 10",
"output": "YES"
},
{
"input": "1 4\n1 4",
"output": "NO"
},
{
"input": "3 5\n0 2\n2 5\n3 4",
"output": "YES"
},
{
"input": "2 5\n0 5\n1 2",
"output": "YES"
},
{
"input": "5 5\n0 2\n0 2\n3 5\n3 5\n3 5",
"output": "NO"
},
{
"input": "4 10\n0 3\n2 10\n4 10\n5 7",
"output": "YES"
},
{
"input": "3 8\n0 0\n1 8\n2 8",
"output": "NO"
},
{
"input": "6 8\n0 3\n1 5\n2 3\n5 6\n6 7\n7 8",
"output": "YES"
}
] | 1,513,915,688 | 1,088 | Python 3 | OK | TESTS | 55 | 62 | 5,632,000 |
n, m = map(int, input().split())
cur = 0
for _ in range(n):
x, y = map(int, input().split())
if (x <= cur):
cur = max(cur,y)
if (cur >= m):
print("YES")
else:
print("NO") | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*).
Output Specification:
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n']
Demo Output:
['YES\n', 'NO\n']
Note:
The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | ```python
n, m = map(int, input().split())
cur = 0
for _ in range(n):
x, y = map(int, input().split())
if (x <= cur):
cur = max(cur,y)
if (cur >= m):
print("YES")
else:
print("NO")
``` | 3 |
|
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReality\nSoul\nSpace\nMind"
},
{
"input": "3\nblue\norange\npurple",
"output": "3\nTime\nReality\nMind"
},
{
"input": "2\nyellow\nred",
"output": "4\nPower\nSoul\nSpace\nTime"
},
{
"input": "1\ngreen",
"output": "5\nReality\nSpace\nPower\nSoul\nMind"
},
{
"input": "2\npurple\ngreen",
"output": "4\nReality\nMind\nSpace\nSoul"
},
{
"input": "1\nblue",
"output": "5\nPower\nReality\nSoul\nTime\nMind"
},
{
"input": "2\npurple\nblue",
"output": "4\nMind\nSoul\nTime\nReality"
},
{
"input": "2\ngreen\nblue",
"output": "4\nReality\nMind\nPower\nSoul"
},
{
"input": "3\npurple\ngreen\nblue",
"output": "3\nMind\nReality\nSoul"
},
{
"input": "1\norange",
"output": "5\nReality\nTime\nPower\nSpace\nMind"
},
{
"input": "2\npurple\norange",
"output": "4\nReality\nMind\nTime\nSpace"
},
{
"input": "2\norange\ngreen",
"output": "4\nSpace\nMind\nReality\nPower"
},
{
"input": "3\norange\npurple\ngreen",
"output": "3\nReality\nSpace\nMind"
},
{
"input": "2\norange\nblue",
"output": "4\nTime\nMind\nReality\nPower"
},
{
"input": "3\nblue\ngreen\norange",
"output": "3\nPower\nMind\nReality"
},
{
"input": "4\nblue\norange\ngreen\npurple",
"output": "2\nMind\nReality"
},
{
"input": "1\nred",
"output": "5\nTime\nSoul\nMind\nPower\nSpace"
},
{
"input": "2\nred\npurple",
"output": "4\nMind\nSpace\nTime\nSoul"
},
{
"input": "2\nred\ngreen",
"output": "4\nMind\nSpace\nPower\nSoul"
},
{
"input": "3\nred\npurple\ngreen",
"output": "3\nSoul\nSpace\nMind"
},
{
"input": "2\nblue\nred",
"output": "4\nMind\nTime\nPower\nSoul"
},
{
"input": "3\nred\nblue\npurple",
"output": "3\nTime\nMind\nSoul"
},
{
"input": "3\nred\nblue\ngreen",
"output": "3\nSoul\nPower\nMind"
},
{
"input": "4\npurple\nblue\ngreen\nred",
"output": "2\nMind\nSoul"
},
{
"input": "2\norange\nred",
"output": "4\nPower\nMind\nTime\nSpace"
},
{
"input": "3\nred\norange\npurple",
"output": "3\nMind\nSpace\nTime"
},
{
"input": "3\nred\norange\ngreen",
"output": "3\nMind\nSpace\nPower"
},
{
"input": "4\nred\norange\ngreen\npurple",
"output": "2\nSpace\nMind"
},
{
"input": "3\nblue\norange\nred",
"output": "3\nPower\nMind\nTime"
},
{
"input": "4\norange\nblue\npurple\nred",
"output": "2\nTime\nMind"
},
{
"input": "4\ngreen\norange\nred\nblue",
"output": "2\nMind\nPower"
},
{
"input": "5\npurple\norange\nblue\nred\ngreen",
"output": "1\nMind"
},
{
"input": "1\nyellow",
"output": "5\nPower\nSoul\nReality\nSpace\nTime"
},
{
"input": "2\npurple\nyellow",
"output": "4\nTime\nReality\nSpace\nSoul"
},
{
"input": "2\ngreen\nyellow",
"output": "4\nSpace\nReality\nPower\nSoul"
},
{
"input": "3\npurple\nyellow\ngreen",
"output": "3\nSoul\nReality\nSpace"
},
{
"input": "2\nblue\nyellow",
"output": "4\nTime\nReality\nPower\nSoul"
},
{
"input": "3\nyellow\nblue\npurple",
"output": "3\nSoul\nReality\nTime"
},
{
"input": "3\ngreen\nyellow\nblue",
"output": "3\nSoul\nReality\nPower"
},
{
"input": "4\nyellow\nblue\ngreen\npurple",
"output": "2\nReality\nSoul"
},
{
"input": "2\nyellow\norange",
"output": "4\nTime\nSpace\nReality\nPower"
},
{
"input": "3\nyellow\npurple\norange",
"output": "3\nSpace\nReality\nTime"
},
{
"input": "3\norange\nyellow\ngreen",
"output": "3\nSpace\nReality\nPower"
},
{
"input": "4\ngreen\nyellow\norange\npurple",
"output": "2\nSpace\nReality"
},
{
"input": "3\nyellow\nblue\norange",
"output": "3\nTime\nReality\nPower"
},
{
"input": "4\norange\npurple\nblue\nyellow",
"output": "2\nReality\nTime"
},
{
"input": "4\nblue\norange\nyellow\ngreen",
"output": "2\nReality\nPower"
},
{
"input": "5\ngreen\nyellow\norange\nblue\npurple",
"output": "1\nReality"
},
{
"input": "3\nyellow\npurple\nred",
"output": "3\nTime\nSoul\nSpace"
},
{
"input": "3\nred\ngreen\nyellow",
"output": "3\nPower\nSoul\nSpace"
},
{
"input": "4\nred\npurple\ngreen\nyellow",
"output": "2\nSpace\nSoul"
},
{
"input": "3\nred\nyellow\nblue",
"output": "3\nPower\nSoul\nTime"
},
{
"input": "4\nblue\nyellow\nred\npurple",
"output": "2\nTime\nSoul"
},
{
"input": "4\nblue\nyellow\nred\ngreen",
"output": "2\nSoul\nPower"
},
{
"input": "5\nred\nyellow\ngreen\nblue\npurple",
"output": "1\nSoul"
},
{
"input": "3\nred\nyellow\norange",
"output": "3\nPower\nSpace\nTime"
},
{
"input": "4\norange\ngreen\nyellow\nred",
"output": "2\nPower\nSpace"
},
{
"input": "5\norange\nred\ngreen\nyellow\npurple",
"output": "1\nSpace"
},
{
"input": "4\nyellow\nred\norange\nblue",
"output": "2\nTime\nPower"
},
{
"input": "5\npurple\nblue\norange\nyellow\nred",
"output": "1\nTime"
},
{
"input": "5\norange\nblue\nyellow\nred\ngreen",
"output": "1\nPower"
}
] | 1,579,467,619 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 109 | 307,200 | n = int(input())
gems = { 'purple': 'Power', 'green':'Time', 'blue':'Space', 'orange':'Soul', 'red':'Reality', 'yellow':'Mind' }
count = 6
missing = [ 'Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind']
for _ in range(n):
s = input()
missing.remove(gems[s])
count -= 1
print(count)
for _ in missing:
print(_) | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input Specification:
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output Specification:
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Demo Input:
['4\nred\npurple\nyellow\norange\n', '0\n']
Demo Output:
['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n']
Note:
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | ```python
n = int(input())
gems = { 'purple': 'Power', 'green':'Time', 'blue':'Space', 'orange':'Soul', 'red':'Reality', 'yellow':'Mind' }
count = 6
missing = [ 'Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind']
for _ in range(n):
s = input()
missing.remove(gems[s])
count -= 1
print(count)
for _ in missing:
print(_)
``` | 3 |
|
320 | B | Ping-Pong (Easy Version) | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | In this problem at each moment you have a set of intervals. You can move from interval (*a*,<=*b*) from our set to interval (*c*,<=*d*) from our set if and only if *c*<=<<=*a*<=<<=*d* or *c*<=<<=*b*<=<<=*d*. Also there is a path from interval *I*1 from our set to interval *I*2 from our set if there is a sequence of successive moves starting from *I*1 so that we can reach *I*2.
Your program should handle the queries of the following two types:
1. "1 x y" (*x*<=<<=*y*) — add the new interval (*x*,<=*y*) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.1. "2 a b" (*a*<=≠<=*b*) — answer the question: is there a path from *a*-th (one-based) added interval to *b*-th (one-based) added interval?
Answer all the queries. Note, that initially you have an empty set of intervals. | The first line of the input contains integer *n* denoting the number of queries, (1<=≤<=*n*<=≤<=100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct. | For each query of the second type print "YES" or "NO" on a separate line depending on the answer. | [
"5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2\n"
] | [
"NO\nYES\n"
] | none | 1,000 | [
{
"input": "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2",
"output": "NO\nYES"
},
{
"input": "10\n1 -311 -186\n1 -1070 -341\n1 -1506 -634\n1 688 1698\n2 2 4\n1 70 1908\n2 1 2\n2 2 4\n1 -1053 1327\n2 5 4",
"output": "NO\nNO\nNO\nYES"
},
{
"input": "10\n1 -1365 -865\n1 1244 1834\n2 1 2\n1 -1508 -752\n2 3 2\n2 2 1\n1 -779 595\n1 -1316 877\n2 2 1\n1 -698 1700",
"output": "NO\nNO\nNO\nNO"
},
{
"input": "20\n1 1208 1583\n1 -258 729\n1 -409 1201\n1 194 1938\n1 -958 1575\n1 -1466 1752\n2 1 2\n2 1 2\n2 6 5\n1 -1870 1881\n1 -2002 2749\n1 -2002 2984\n1 -2002 3293\n2 2 4\n2 8 10\n2 9 6\n1 -2002 3572\n1 -2002 4175\n1 -2002 4452\n1 -2002 4605",
"output": "YES\nYES\nYES\nYES\nYES\nNO"
},
{
"input": "9\n1 1 4\n1 5 20\n1 11 30\n1 29 60\n1 59 100\n1 100 200\n2 1 5\n2 1 6\n2 2 5",
"output": "NO\nNO\nYES"
}
] | 1,632,476,836 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 20,172,800 | def dfs(adj, vis, v):
global flag
vis[v] = True
for u in adj[v]:
if not vis[u]:
dfs(adj, vis, u)
n = int(input())
adj = []
intervals = []
icount = 0
for _ in range(n):
query = [int(x) for x in input().split()]
if query[0] == 1:
ls, x, y = [], query[1], query[2]
for i, (x1, y1) in enumerate(intervals):
if x < x1 < y or x < y1 < y:
ls.append(i)
if x1 < x < y1 or x1 < y < y1:
adj[i].append(icount)
adj.append(ls)
icount += 1
intervals.append((x, y))
else:
a, b = query[1], query[2]
vis = [False] * len(intervals)
dfs(adj, vis, a - 1)
print('YES' if vis[b - 1] else 'NO')
# print(adj)
| Title: Ping-Pong (Easy Version)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem at each moment you have a set of intervals. You can move from interval (*a*,<=*b*) from our set to interval (*c*,<=*d*) from our set if and only if *c*<=<<=*a*<=<<=*d* or *c*<=<<=*b*<=<<=*d*. Also there is a path from interval *I*1 from our set to interval *I*2 from our set if there is a sequence of successive moves starting from *I*1 so that we can reach *I*2.
Your program should handle the queries of the following two types:
1. "1 x y" (*x*<=<<=*y*) — add the new interval (*x*,<=*y*) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.1. "2 a b" (*a*<=≠<=*b*) — answer the question: is there a path from *a*-th (one-based) added interval to *b*-th (one-based) added interval?
Answer all the queries. Note, that initially you have an empty set of intervals.
Input Specification:
The first line of the input contains integer *n* denoting the number of queries, (1<=≤<=*n*<=≤<=100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
It's guaranteed that all queries are correct.
Output Specification:
For each query of the second type print "YES" or "NO" on a separate line depending on the answer.
Demo Input:
['5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2\n']
Demo Output:
['NO\nYES\n']
Note:
none | ```python
def dfs(adj, vis, v):
global flag
vis[v] = True
for u in adj[v]:
if not vis[u]:
dfs(adj, vis, u)
n = int(input())
adj = []
intervals = []
icount = 0
for _ in range(n):
query = [int(x) for x in input().split()]
if query[0] == 1:
ls, x, y = [], query[1], query[2]
for i, (x1, y1) in enumerate(intervals):
if x < x1 < y or x < y1 < y:
ls.append(i)
if x1 < x < y1 or x1 < y < y1:
adj[i].append(icount)
adj.append(ls)
icount += 1
intervals.append((x, y))
else:
a, b = query[1], query[2]
vis = [False] * len(intervals)
dfs(adj, vis, a - 1)
print('YES' if vis[b - 1] else 'NO')
# print(adj)
``` | 0 |
|
644 | C | Hostname Aliases | PROGRAMMING | 2,100 | [
"*special",
"binary search",
"data structures",
"implementation",
"sortings",
"strings"
] | null | null | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where:
- <hostname> — server name (consists of words and maybe some dots separating them), - /<path> — optional part, where <path> consists of words separated by slashes.
We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.
Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.
Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of page queries. Then follow *n* lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where:
- <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. - <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20.
Addresses are not guaranteed to be distinct. | First print *k* — the number of groups of server names that correspond to one website. You should count only groups of size greater than one.
Next *k* lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | [
"10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n",
"14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a\n"
] | [
"1\nhttp://abacaba.de http://abacaba.ru \n",
"2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc \n"
] | none | 1,500 | [
{
"input": "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test",
"output": "1\nhttp://abacaba.de http://abacaba.ru "
},
{
"input": "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a",
"output": "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc "
},
{
"input": "10\nhttp://tqr.ekdb.nh/w\nhttp://p.ulz/ifw\nhttp://w.gw.dw.xn/kpe\nhttp://byt.mqii.zkv/j/xt\nhttp://ovquj.rbgrlw/k..\nhttp://bv.plu.e.dslg/j/xt\nhttp://udgci.ufgi.gwbd.s/\nhttp://l.oh.ne.o.r/.vo\nhttp://l.oh.ne.o.r/w\nhttp://tqr.ekdb.nh/.vo",
"output": "2\nhttp://l.oh.ne.o.r http://tqr.ekdb.nh \nhttp://bv.plu.e.dslg http://byt.mqii.zkv "
},
{
"input": "12\nhttp://ickght.ck/mr\nhttp://a.exhel/.b\nhttp://a.exhel/\nhttp://ti.cdm/\nhttp://ti.cdm/x/wd/lm.h.\nhttp://ickght.ck/a\nhttp://ickght.ck\nhttp://c.gcnk.d/.b\nhttp://c.gcnk.d/x/wd/lm.h.\nhttp://ti.cdm/.b\nhttp://a.exhel/x/wd/lm.h.\nhttp://c.gcnk.d/",
"output": "1\nhttp://a.exhel http://c.gcnk.d http://ti.cdm "
},
{
"input": "14\nhttp://jr/kgb\nhttp://ps.p.t.jeua.x.a.q.t\nhttp://gsqqs.n/t/\nhttp://w.afwsnuc.ff.km/cohox/u.\nhttp://u.s.wbumkuqm/\nhttp://u.s.wbumkuqm/cohox/u.\nhttp://nq.dzjkjcwv.f.s/bvm/\nhttp://zoy.shgg\nhttp://gsqqs.n\nhttp://u.s.wbumkuqm/b.pd.\nhttp://w.afwsnuc.ff.km/\nhttp://w.afwsnuc.ff.km/b.pd.\nhttp://nq.dzjkjcwv.f.s/n\nhttp://nq.dzjkjcwv.f.s/ldbw",
"output": "2\nhttp://ps.p.t.jeua.x.a.q.t http://zoy.shgg \nhttp://u.s.wbumkuqm http://w.afwsnuc.ff.km "
},
{
"input": "15\nhttp://l.edzplwqsij.rw/\nhttp://m.e.mehd.acsoinzm/s\nhttp://yg.ttahn.xin.obgez/ap/\nhttp://qqbb.pqkaqcncodxmaae\nhttp://lzi.a.flkp.lnn.k/o/qfr.cp\nhttp://lzi.a.flkp.lnn.k/f\nhttp://p.ngu.gkoq/.szinwwi\nhttp://qqbb.pqkaqcncodxmaae/od\nhttp://qqbb.pqkaqcncodxmaae\nhttp://wsxvmi.qpe.fihtgdvi/e./\nhttp://p.ngu.gkoq/zfoh\nhttp://m.e.mehd.acsoinzm/xp\nhttp://c.gy.p.h.tkrxt.jnsjt/j\nhttp://wsxvmi.qpe.fihtgdvi/grkag.z\nhttp://p.ngu.gkoq/t",
"output": "0"
},
{
"input": "15\nhttp://w.hhjvdn.mmu/.ca.p\nhttp://m.p.p.lar/\nhttp://lgmjun.r.kogpr.ijn/./t\nhttp://bapchpl.mcw.a.lob/d/ym/./g.q\nhttp://uxnjfnjp.kxr.ss.e.uu/jwo./hjl/\nhttp://fd.ezw.ykbb.xhl.t/\nhttp://i.xcb.kr/.ca.p\nhttp://jofec.ry.fht.gt\nhttp://qeo.gghwe.lcr/d/ym/./g.q\nhttp://gt\nhttp://gjvifpf.d/d/ym/./g.q\nhttp://oba\nhttp://rjs.qwd/v/hi\nhttp://fgkj/\nhttp://ivun.naumc.l/.ca.p",
"output": "4\nhttp://gt http://jofec.ry.fht.gt http://oba \nhttp://fd.ezw.ykbb.xhl.t http://fgkj http://m.p.p.lar \nhttp://i.xcb.kr http://ivun.naumc.l http://w.hhjvdn.mmu \nhttp://bapchpl.mcw.a.lob http://gjvifpf.d http://qeo.gghwe.lcr "
},
{
"input": "20\nhttp://gjwr/xsoiagp/\nhttp://gdnmu/j\nhttp://yfygudx.e.aqa.ezh/j\nhttp://mpjxue.cuvipq/\nhttp://a/\nhttp://kr/..n/c.\nhttp://a/xsoiagp/\nhttp://kr/z\nhttp://kr/v.cv/rk/k\nhttp://lvhpz\nhttp://qv.v.jqzhq\nhttp://y.no/\nhttp://kr/n\nhttp://y.no/xsoiagp/\nhttp://kr/ebe/z/\nhttp://olsvbxxw.win.n/j\nhttp://p.ct/j\nhttp://mpjxue.cuvipq/xsoiagp/\nhttp://kr/j\nhttp://gjwr/",
"output": "3\nhttp://lvhpz http://qv.v.jqzhq \nhttp://a http://gjwr http://mpjxue.cuvipq http://y.no \nhttp://gdnmu http://olsvbxxw.win.n http://p.ct http://yfygudx.e.aqa.ezh "
},
{
"input": "1\nhttp://a",
"output": "0"
},
{
"input": "3\nhttp://abacaba.com/test\nhttp://abacaba.de/test\nhttp://abacaba.de/test",
"output": "1\nhttp://abacaba.com http://abacaba.de "
}
] | 1,458,163,851 | 45,051 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | n = int(input())
w = {}
for g in range(n):
s = input().split('/')
s[2] = 'http://' + s[2]
if not(w.get(s[2])):
w[s[2]] = set(s[3:])
else:
w[s[2]] = w[s[2]].union(s[3:])
bad = set()
for name, s in w.items():
bad.add(name)
for name2, s2 in w.items():
if name2 in bad: continue
if s == s2: print(name, name2) | Title: Hostname Aliases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where:
- <hostname> — server name (consists of words and maybe some dots separating them), - /<path> — optional part, where <path> consists of words separated by slashes.
We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.
Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.
Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of page queries. Then follow *n* lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where:
- <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. - <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20.
Addresses are not guaranteed to be distinct.
Output Specification:
First print *k* — the number of groups of server names that correspond to one website. You should count only groups of size greater than one.
Next *k* lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order.
Demo Input:
['10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n', '14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a\n']
Demo Output:
['1\nhttp://abacaba.de http://abacaba.ru \n', '2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc \n']
Note:
none | ```python
n = int(input())
w = {}
for g in range(n):
s = input().split('/')
s[2] = 'http://' + s[2]
if not(w.get(s[2])):
w[s[2]] = set(s[3:])
else:
w[s[2]] = w[s[2]].union(s[3:])
bad = set()
for name, s in w.items():
bad.add(name)
for name2, s2 in w.items():
if name2 in bad: continue
if s == s2: print(name, name2)
``` | 0 |
|
754 | A | Lesha and array splitting | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array *A*.
Lesha is tired now so he asked you to split the array. Help Lesha! | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array *A*.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=103<=≤<=*a**i*<=≤<=103) — the elements of the array *A*. | If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes).
Otherwise in the first line print "YES" (without quotes). In the next line print single integer *k* — the number of new arrays. In each of the next *k* lines print two integers *l**i* and *r**i* which denote the subarray *A*[*l**i*... *r**i*] of the initial array *A* being the *i*-th new array. Integers *l**i*, *r**i* should satisfy the following conditions:
- *l*1<==<=1 - *r**k*<==<=*n* - *r**i*<=+<=1<==<=*l**i*<=+<=1 for each 1<=≤<=*i*<=<<=*k*.
If there are multiple answers, print any of them. | [
"3\n1 2 -3\n",
"8\n9 -12 3 4 -4 -10 7 3\n",
"1\n0\n",
"4\n1 2 3 -5\n"
] | [
"YES\n2\n1 2\n3 3\n",
"YES\n2\n1 2\n3 8\n",
"NO\n",
"YES\n4\n1 1\n2 2\n3 3\n4 4\n"
] | none | 500 | [
{
"input": "3\n1 2 -3",
"output": "YES\n3\n1 1\n2 2\n3 3"
},
{
"input": "8\n9 -12 3 4 -4 -10 7 3",
"output": "YES\n8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "4\n1 2 3 -5",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "6\n0 0 0 0 0 0",
"output": "NO"
},
{
"input": "100\n507 -724 -243 -846 697 -569 -786 472 756 -272 731 -534 -664 202 592 -381 161 -668 -895 296 472 -868 599 396 -617 310 -283 -118 829 -218 807 939 -152 -343 -96 692 -570 110 442 159 -446 -631 -881 784 894 -3 -792 654 -273 -791 638 -599 -763 586 -812 248 -590 455 926 -402 61 228 209 419 -511 310 -283 857 369 472 -82 -435 -717 -421 862 -384 659 -235 406 793 -167 -504 -432 -951 0 165 36 650 -145 -500 988 -513 -495 -476 312 -754 332 819 -797 -715",
"output": "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75..."
},
{
"input": "100\n1 -2 -1 -1 2 2 0 1 -1 1 0 -2 1 -1 0 -2 -1 -1 2 0 -1 2 0 1 -2 -2 -1 1 2 0 -2 -2 -1 1 1 -1 -2 -1 0 -1 2 1 -1 -2 0 2 1 1 -2 1 1 -1 2 -2 2 0 1 -1 1 -2 0 0 0 0 0 0 -2 -2 2 1 2 2 0 -1 1 1 -2 -2 -2 1 0 2 -1 -2 -1 0 0 0 2 1 -2 0 -2 0 2 1 -2 -1 2 1",
"output": "YES\n78\n1 1\n2 2\n3 3\n4 4\n5 5\n6 7\n8 8\n9 9\n10 11\n12 12\n13 13\n14 15\n16 16\n17 17\n18 18\n19 20\n21 21\n22 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 39\n40 40\n41 41\n42 42\n43 43\n44 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 56\n57 57\n58 58\n59 59\n60 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 73\n74 74\n75 75\n76 76\n77 77\n78 78\n79 79\n80 81\n82 82\n83 83\n84 84\n85 88\n89 89\n90 90\n91 92\n93 94\n95 95\n96 96\n..."
},
{
"input": "7\n0 0 0 0 3 -3 0",
"output": "YES\n2\n1 5\n6 7"
},
{
"input": "5\n0 0 -4 0 0",
"output": "YES\n1\n1 5"
},
{
"input": "100\n2 -38 51 -71 -24 19 35 -27 48 18 64 -4 30 -28 74 -17 -19 -25 54 41 3 -46 -43 -42 87 -76 -62 28 1 32 7 -76 15 0 -82 -33 17 40 -41 -7 43 -18 -27 65 -27 -13 46 -38 75 7 62 -23 7 -12 80 36 37 14 6 -40 -11 -35 -77 -24 -59 75 -41 -21 17 -21 -14 67 -36 16 -1 34 -26 30 -62 -4 -63 15 -49 18 57 7 77 23 -26 8 -20 8 -16 9 50 -24 -33 9 -9 -33",
"output": "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75 75\n76..."
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n1\n1 100"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "100\n0 0 -17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n2\n1 34\n35 100"
},
{
"input": "3\n1 -3 3",
"output": "YES\n3\n1 1\n2 2\n3 3"
},
{
"input": "3\n1 0 -1",
"output": "YES\n2\n1 2\n3 3"
},
{
"input": "3\n3 0 0",
"output": "YES\n1\n1 3"
},
{
"input": "3\n0 0 0",
"output": "NO"
},
{
"input": "3\n-3 3 0",
"output": "YES\n2\n1 1\n2 3"
},
{
"input": "4\n3 -2 -1 3",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "4\n-1 0 1 0",
"output": "YES\n2\n1 2\n3 4"
},
{
"input": "4\n0 0 0 3",
"output": "YES\n1\n1 4"
},
{
"input": "4\n0 0 0 0",
"output": "NO"
},
{
"input": "4\n3 0 -3 0",
"output": "YES\n2\n1 2\n3 4"
},
{
"input": "5\n-3 2 2 0 -2",
"output": "YES\n4\n1 1\n2 2\n3 4\n5 5"
},
{
"input": "5\n0 -1 2 0 -1",
"output": "YES\n3\n1 2\n3 4\n5 5"
},
{
"input": "5\n0 2 0 0 0",
"output": "YES\n1\n1 5"
},
{
"input": "5\n0 0 0 0 0",
"output": "NO"
},
{
"input": "5\n0 0 0 0 0",
"output": "NO"
},
{
"input": "20\n101 89 -166 -148 -38 -135 -138 193 14 -134 -185 -171 -52 -191 195 39 -148 200 51 -73",
"output": "YES\n20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20"
},
{
"input": "20\n-118 -5 101 7 9 144 55 -55 -9 -126 -71 -71 189 -64 -187 123 0 -48 -12 138",
"output": "YES\n19\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 17\n18 18\n19 19\n20 20"
},
{
"input": "20\n-161 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n1\n1 20"
},
{
"input": "20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 -137 0 0 0 0 137",
"output": "YES\n2\n1 19\n20 20"
},
{
"input": "40\n64 -94 -386 -78 35 -233 33 82 -5 -200 368 -259 124 353 390 -305 -247 -133 379 44 133 -146 151 -217 -16 53 -157 186 -203 -8 117 -71 272 -290 -97 133 52 113 -280 -176",
"output": "YES\n40\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40"
},
{
"input": "40\n120 -96 -216 131 231 -80 -166 -102 16 227 -120 105 43 -83 -53 229 24 190 -268 119 230 348 -33 19 0 -187 -349 -25 80 -38 -30 138 -104 337 -98 0 1 -66 -243 -231",
"output": "YES\n38\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 36\n37 37\n38 38\n39 39\n40 40"
},
{
"input": "40\n0 0 0 0 0 0 324 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n1\n1 40"
},
{
"input": "40\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "40\n0 0 0 0 0 308 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -308 0 0 0 0 0 0 0",
"output": "YES\n2\n1 32\n33 40"
},
{
"input": "60\n-288 -213 -213 -23 496 489 137 -301 -219 -296 -577 269 -153 -52 -505 -138 -377 500 -256 405 588 274 -115 375 -93 117 -360 -160 429 -339 502 310 502 572 -41 -26 152 -203 562 -525 -179 -67 424 62 -329 -127 352 -474 417 -30 518 326 200 -598 471 107 339 107 -9 -244",
"output": "YES\n60\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60"
},
{
"input": "60\n112 141 -146 -389 175 399 -59 327 -41 397 263 -422 157 0 471 -2 -381 -438 99 368 173 9 -171 118 24 111 120 70 11 317 -71 -574 -139 0 -477 -211 -116 -367 16 568 -75 -430 75 -179 -21 156 291 -422 441 -224 -8 -337 -104 381 60 -138 257 91 103 -359",
"output": "YES\n58\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60"
},
{
"input": "60\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -238 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n1\n1 60"
},
{
"input": "60\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "60\n0 0 0 0 0 0 0 0 0 -98 0 0 0 0 0 0 0 0 98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n2\n1 18\n19 60"
},
{
"input": "80\n-295 -774 -700 -366 -304 -173 -672 288 -721 -256 -348 650 223 211 379 -13 -483 162 800 631 -550 -704 -357 -306 490 713 -80 -234 -669 675 -688 471 315 607 -87 -327 -799 514 248 379 271 325 -244 98 -100 -447 574 -154 554 -377 380 -423 -140 -147 -189 -420 405 464 -110 273 -226 -109 -578 641 -426 -548 214 -184 -397 570 -428 -676 652 -155 127 462 338 534 -782 -481",
"output": "YES\n80\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75..."
},
{
"input": "80\n237 66 409 -208 -460 4 -448 29 -420 -192 -21 -76 -147 435 205 -42 -299 -29 244 -480 -4 -38 2 -214 -311 556 692 111 -19 -84 -90 -350 -354 125 -207 -137 93 367 -481 -462 -440 -92 424 -107 221 -100 -631 -72 105 201 226 -90 197 -264 427 113 202 -144 -115 398 331 147 56 -24 292 -267 -31 -11 202 506 334 -103 534 -155 -472 -124 -257 209 12 360",
"output": "YES\n80\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75..."
},
{
"input": "80\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 668 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n1\n1 80"
},
{
"input": "80\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "80\n0 0 0 0 0 0 0 0 0 0 0 0 -137 137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n2\n1 13\n14 80"
},
{
"input": "100\n-98 369 544 197 -991 231 399 521 582 -820 -650 -919 -615 -411 -843 -974 231 140 239 -209 721 84 -834 -27 162 460 -157 -40 0 -778 -491 -607 -34 -647 834 -7 -518 -5 -31 -766 -54 -698 -838 497 980 -77 238 549 -135 7 -629 -892 455 181 527 314 465 -321 656 -390 368 384 601 332 561 -1000 -636 -106 412 -216 -58 -365 -155 -445 404 114 260 -392 -20 840 -395 620 -860 -936 1 882 958 536 589 235 300 676 478 434 229 698 157 -95 908 -170",
"output": "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75 75\n76..."
},
{
"input": "100\n-149 -71 -300 288 -677 -580 248 49 -167 264 -215 878 7 252 -239 25 -369 -22 526 -415 -175 173 549 679 161 -411 743 -454 -34 -714 282 -198 -47 -519 -45 71 615 -214 -317 399 86 -97 246 689 -22 -197 -139 237 -501 477 -385 -421 -463 -641 409 -279 538 -382 48 189 652 -696 74 303 6 -183 336 17 -178 -617 -739 280 -202 454 864 218 480 293 -118 -518 -24 -866 -357 410 239 -833 510 316 -168 38 -370 -22 741 470 -60 -507 -209 704 141 -148",
"output": "YES\n100\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n7..."
},
{
"input": "100\n0 0 697 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "YES\n1\n1 100"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -475 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 475 0 0 0 0",
"output": "YES\n2\n1 95\n96 100"
},
{
"input": "4\n0 0 3 -3",
"output": "YES\n2\n1 3\n4 4"
},
{
"input": "4\n1 0 0 0",
"output": "YES\n1\n1 4"
},
{
"input": "4\n3 3 3 3",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "2\n0 1",
"output": "YES\n1\n1 2"
},
{
"input": "4\n0 -1 1 0",
"output": "YES\n2\n1 2\n3 4"
},
{
"input": "1\n1",
"output": "YES\n1\n1 1"
},
{
"input": "5\n0 0 1 0 0",
"output": "YES\n1\n1 5"
},
{
"input": "4\n0 0 1 0",
"output": "YES\n1\n1 4"
},
{
"input": "10\n1 2 0 0 3 -3 0 0 -3 0",
"output": "YES\n5\n1 1\n2 4\n5 5\n6 8\n9 10"
},
{
"input": "3\n0 -1 0",
"output": "YES\n1\n1 3"
},
{
"input": "2\n1 0",
"output": "YES\n1\n1 2"
},
{
"input": "5\n3 -3 0 0 0",
"output": "YES\n2\n1 1\n2 5"
},
{
"input": "3\n0 1 0",
"output": "YES\n1\n1 3"
},
{
"input": "4\n0 0 0 1",
"output": "YES\n1\n1 4"
},
{
"input": "4\n1 -1 1 -1",
"output": "YES\n4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "1\n-1",
"output": "YES\n1\n1 1"
},
{
"input": "2\n1 1",
"output": "YES\n2\n1 1\n2 2"
},
{
"input": "2\n1 -1",
"output": "YES\n2\n1 1\n2 2"
},
{
"input": "2\n0 0",
"output": "NO"
},
{
"input": "2\n0 -1",
"output": "YES\n1\n1 2"
},
{
"input": "2\n-1 1",
"output": "YES\n2\n1 1\n2 2"
},
{
"input": "2\n-1 0",
"output": "YES\n1\n1 2"
},
{
"input": "2\n-1 -1",
"output": "YES\n2\n1 1\n2 2"
},
{
"input": "3\n5 -5 5",
"output": "YES\n3\n1 1\n2 2\n3 3"
},
{
"input": "5\n1 0 -1 0 1",
"output": "YES\n3\n1 2\n3 4\n5 5"
},
{
"input": "6\n0 0 0 3 0 0",
"output": "YES\n1\n1 6"
},
{
"input": "3\n1 -1 1",
"output": "YES\n3\n1 1\n2 2\n3 3"
}
] | 1,641,376,331 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a=int(input())
l=list(map(int,input().split()))
i=1
while(i<a) and l[i-1]<l[i]:
i=i+1
while(i<a) and l[i-1]==l[i]:
i=i+1
while(i<a) and l[i-1]>l[i]:
i=i+1
if(i==a):
print("Yes")
else:
print("No")
[03/01, 5:03 pm] +91 99959 59240: a=int(input())
for i in range(a):
n=int(input())
l=list(map(int,input().split()))
h=sorted(l)
m=h[1]
for j in h:
if j!=m:
print(l.index(j)+1) | Title: Lesha and array splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array *A*.
Lesha is tired now so he asked you to split the array. Help Lesha!
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array *A*.
The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=103<=≤<=*a**i*<=≤<=103) — the elements of the array *A*.
Output Specification:
If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes).
Otherwise in the first line print "YES" (without quotes). In the next line print single integer *k* — the number of new arrays. In each of the next *k* lines print two integers *l**i* and *r**i* which denote the subarray *A*[*l**i*... *r**i*] of the initial array *A* being the *i*-th new array. Integers *l**i*, *r**i* should satisfy the following conditions:
- *l*1<==<=1 - *r**k*<==<=*n* - *r**i*<=+<=1<==<=*l**i*<=+<=1 for each 1<=≤<=*i*<=<<=*k*.
If there are multiple answers, print any of them.
Demo Input:
['3\n1 2 -3\n', '8\n9 -12 3 4 -4 -10 7 3\n', '1\n0\n', '4\n1 2 3 -5\n']
Demo Output:
['YES\n2\n1 2\n3 3\n', 'YES\n2\n1 2\n3 8\n', 'NO\n', 'YES\n4\n1 1\n2 2\n3 3\n4 4\n']
Note:
none | ```python
a=int(input())
l=list(map(int,input().split()))
i=1
while(i<a) and l[i-1]<l[i]:
i=i+1
while(i<a) and l[i-1]==l[i]:
i=i+1
while(i<a) and l[i-1]>l[i]:
i=i+1
if(i==a):
print("Yes")
else:
print("No")
[03/01, 5:03 pm] +91 99959 59240: a=int(input())
for i in range(a):
n=int(input())
l=list(map(int,input().split()))
h=sorted(l)
m=h[1]
for j in h:
if j!=m:
print(l.index(j)+1)
``` | -1 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,694,612,742 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | A=input()
B=input()
A1=A[::-1]
if A1==B:
print("YES")
else:
print("NO") | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
A=input()
B=input()
A1=A[::-1]
if A1==B:
print("YES")
else:
print("NO")
``` | 3.977 |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers. | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
{
"input": "192",
"output": "4 188"
},
{
"input": "86",
"output": "4 82"
},
{
"input": "46220",
"output": "4 46216"
},
{
"input": "57114",
"output": "4 57110"
},
{
"input": "869",
"output": "4 865"
},
{
"input": "738457",
"output": "4 738453"
},
{
"input": "58113",
"output": "6 58107"
},
{
"input": "4864",
"output": "4 4860"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "74752",
"output": "4 74748"
},
{
"input": "6073",
"output": "4 6069"
},
{
"input": "1289",
"output": "4 1285"
},
{
"input": "20",
"output": "4 16"
},
{
"input": "58134",
"output": "4 58130"
},
{
"input": "57756",
"output": "4 57752"
},
{
"input": "765",
"output": "6 759"
},
{
"input": "59",
"output": "4 55"
},
{
"input": "991666",
"output": "4 991662"
},
{
"input": "70761",
"output": "4 70757"
},
{
"input": "13",
"output": "4 9"
},
{
"input": "999999",
"output": "4 999995"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "21",
"output": "6 15"
},
{
"input": "19",
"output": "4 15"
},
{
"input": "100007",
"output": "6 100001"
},
{
"input": "999987",
"output": "6 999981"
},
{
"input": "22",
"output": "4 18"
}
] | 1,682,129,981 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 108 | 0 | def prime(n):
for i in range(2,n//2+1):
if n%i==0:
return False
return True
n=int(input())
for i in range(2,n):
if prime(i)==False and prime(n-i)==False:
print(i,n-i)
break | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
Input Specification:
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output Specification:
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
Demo Input:
['12\n', '15\n', '23\n', '1000000\n']
Demo Output:
['4 8\n', '6 9\n', '8 15\n', '500000 500000\n']
Note:
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | ```python
def prime(n):
for i in range(2,n//2+1):
if n%i==0:
return False
return True
n=int(input())
for i in range(2,n):
if prime(i)==False and prime(n-i)==False:
print(i,n-i)
break
``` | 3 |
|
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
{
"input": "2 7\n1 1",
"output": "1"
},
{
"input": "3 3\n18 1 9",
"output": "10"
},
{
"input": "3 3\n15 17 9",
"output": "3"
},
{
"input": "3 3\n10 9 12",
"output": "2"
},
{
"input": "10 3\n2 1 17 10 5 16 8 4 15 17",
"output": "31"
},
{
"input": "10 3\n6 11 4 12 22 15 23 26 24 26",
"output": "13"
},
{
"input": "10 3\n10 24 13 15 18 14 15 26 33 35",
"output": "29"
},
{
"input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580",
"output": "15717"
},
{
"input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327",
"output": "16133"
}
] | 1,686,529,140 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,d=map(int,input().split())
a=list(map(int,input().split()))
l=0
for i in range(1,len(a)):
k = 0
k = (a[i-1]-a[i]//d)+1
print(k)
| Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
Input Specification:
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output Specification:
Output the minimal number of moves needed to make the sequence increasing.
Demo Input:
['4 2\n1 3 3 2\n']
Demo Output:
['3\n']
Note:
none | ```python
n,d=map(int,input().split())
a=list(map(int,input().split()))
l=0
for i in range(1,len(a)):
k = 0
k = (a[i-1]-a[i]//d)+1
print(k)
``` | 0 |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output": "1"
},
{
"input": "86",
"output": "2"
},
{
"input": "2",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "34",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "28",
"output": "2"
},
{
"input": "23",
"output": "1"
},
{
"input": "57",
"output": "2"
},
{
"input": "29",
"output": "2"
},
{
"input": "353869285",
"output": "3"
},
{
"input": "549548646",
"output": "2"
},
{
"input": "858893424",
"output": "2"
},
{
"input": "644818852",
"output": "3"
},
{
"input": "360322525",
"output": "3"
},
{
"input": "122937520",
"output": "2"
},
{
"input": "288403032",
"output": "2"
},
{
"input": "677257481",
"output": "3"
},
{
"input": "58059561",
"output": "3"
},
{
"input": "211288847",
"output": "2"
},
{
"input": "339900034079539584",
"output": "2"
},
{
"input": "784084029310269952",
"output": "3"
},
{
"input": "774730557264864000",
"output": "3"
},
{
"input": "478233807148352256",
"output": "3"
},
{
"input": "165646874056812544",
"output": "3"
},
{
"input": "477533739511673792",
"output": "3"
},
{
"input": "660119944377002240",
"output": "3"
},
{
"input": "448375218506078080",
"output": "3"
},
{
"input": "77213334785795616",
"output": "3"
},
{
"input": "165767221702271872",
"output": "3"
},
{
"input": "1",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561",
"output": "3"
},
{
"input": "9",
"output": "0"
}
] | 1,684,846,087 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | def digital_root(n):
if n < 10:
return 0
sum_digits = sum(int(digit) for digit in str(n))
return 1 + digital_root(sum_digits)
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
Input Specification:
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Output Specification:
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Demo Input:
['0\n', '10\n', '991\n']
Demo Output:
['0\n', '1\n', '3\n']
Note:
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | ```python
def digital_root(n):
if n < 10:
return 0
sum_digits = sum(int(digit) for digit in str(n))
return 1 + digital_root(sum_digits)
``` | 0 |
109 | B | Lucky Probability | PROGRAMMING | 1,900 | [
"brute force",
"probabilities"
] | B. Lucky Probability | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer *p* from the interval [*p**l*,<=*p**r*] and Vasya chooses an integer *v* from the interval [*v**l*,<=*v**r*] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [*min*(*v*,<=*p*),<=*max*(*v*,<=*p*)] contains exactly *k* lucky numbers. | The single line contains five integers *p**l*, *p**r*, *v**l*, *v**r* and *k* (1<=≤<=*p**l*<=≤<=*p**r*<=≤<=109,<=1<=≤<=*v**l*<=≤<=*v**r*<=≤<=109,<=1<=≤<=*k*<=≤<=1000). | On the single line print the result with an absolute error of no more than 10<=-<=9. | [
"1 10 1 10 2\n",
"5 6 8 10 1\n"
] | [
"0.320000000000\n",
"1.000000000000\n"
] | Consider that [*a*, *b*] denotes an interval of integers; this interval includes the boundaries. That is, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18b4a6012d95ad18891561410f0314497a578d63.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10·10 = 100, so answer is 32 / 100.
In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number. | 1,000 | [
{
"input": "1 10 1 10 2",
"output": "0.320000000000"
},
{
"input": "5 6 8 10 1",
"output": "1.000000000000"
},
{
"input": "1 20 100 120 5",
"output": "0.150000000000"
},
{
"input": "1 10 1 10 3",
"output": "0.000000000000"
},
{
"input": "1 100 1 100 2",
"output": "0.362600000000"
},
{
"input": "47 95 18 147 4",
"output": "0.080533751962"
},
{
"input": "1 1000000000 1 1000000000 47",
"output": "0.000000010664"
},
{
"input": "1 2 3 4 12",
"output": "0.000000000000"
},
{
"input": "1 50 64 80 4",
"output": "0.231764705882"
},
{
"input": "1 128 45 99 2",
"output": "0.432954545455"
},
{
"input": "45 855 69 854 7",
"output": "0.005859319848"
},
{
"input": "1 1000 1 1000 2",
"output": "0.082970000000"
},
{
"input": "999 999 1000 1000 1",
"output": "0.000000000000"
},
{
"input": "789 5888 1 10 7",
"output": "0.000000000000"
},
{
"input": "1 1000 1 1000 14",
"output": "0.001792000000"
},
{
"input": "4 4 7 7 2",
"output": "1.000000000000"
},
{
"input": "7 7 4 4 2",
"output": "1.000000000000"
},
{
"input": "2588 3000 954 8555 4",
"output": "0.035122336227"
},
{
"input": "1 10000 1 10000 2",
"output": "0.009328580000"
},
{
"input": "1 10000 1 10000 6",
"output": "0.009012260000"
},
{
"input": "69 98200 9999 88888 7",
"output": "0.000104470975"
},
{
"input": "1 1000000000 1 1000000000 1000",
"output": "0.000001185373"
},
{
"input": "1 1000000 1 1000000 19",
"output": "0.000010456080"
},
{
"input": "4855 95555 485 95554750 7",
"output": "0.000000239243"
},
{
"input": "2 999999999 3 999999998 999",
"output": "0.000000001334"
},
{
"input": "45 8555 969 4000 3",
"output": "0.000704970039"
},
{
"input": "369 852 741 963 2",
"output": "0.134584738539"
},
{
"input": "8548 8554575 895 9954448 47",
"output": "0.000001161081"
},
{
"input": "488 985544 8500 74844999 105",
"output": "0.000000323831"
},
{
"input": "458995 855555 999999 84444444 245",
"output": "0.000000065857"
},
{
"input": "8544 8855550 9874 8800000 360",
"output": "0.000000000000"
},
{
"input": "1 1000000000 1 1000000000 584",
"output": "0.000003345099"
},
{
"input": "1 1000000000 1 1000000000 48",
"output": "0.000094672776"
},
{
"input": "1 1000000000 1 1000000000 470",
"output": "0.000000073832"
},
{
"input": "1 1000000000 1 1000000000 49",
"output": "0.000000010664"
},
{
"input": "1 1000000000 1 1000000000 998",
"output": "0.000000012002"
},
{
"input": "4555 99878870 950000 400000000 458",
"output": "0.000000218543"
},
{
"input": "99999999 989999999 1 1000000000 21",
"output": "0.000000009517"
},
{
"input": "9887400 488085444 599 600000000 374",
"output": "0.000000066330"
},
{
"input": "4 47777777 444444444 777777777 320",
"output": "0.010618322184"
},
{
"input": "4 7 1 1000000000 395",
"output": "0.000000021000"
},
{
"input": "123456789 987654321 4588 95470 512",
"output": "0.000734548731"
},
{
"input": "1 1000000000 488 744444444 748",
"output": "0.000000298888"
},
{
"input": "69 74444 47 744444 100",
"output": "0.000000000000"
},
{
"input": "1 1000000000 100000000 1000000000 300",
"output": "0.000000594125"
},
{
"input": "987654215 1000000000 9854874 854888120 270",
"output": "0.000000031951"
},
{
"input": "85478 999999999 1 1000000000 1000",
"output": "0.000000592737"
},
{
"input": "47 555555555 8596 584987999 894",
"output": "0.000000000000"
},
{
"input": "74 182015585 98247 975000999 678",
"output": "0.000000083341"
},
{
"input": "1 1000000000 7 1000000000 987",
"output": "0.000000001335"
},
{
"input": "47 47 47 47 1",
"output": "1.000000000000"
},
{
"input": "6 8 6 8 1",
"output": "0.777777777778"
},
{
"input": "5 30 6 43 1",
"output": "0.159919028340"
},
{
"input": "777777776 778777777 777777775 1000000000 1",
"output": "0.000002013496"
},
{
"input": "28 46 8 45 1",
"output": "0.199445983380"
},
{
"input": "444444 444445 444440 444446 1",
"output": "0.857142857143"
},
{
"input": "1 6 2 4 1",
"output": "0.666666666667"
},
{
"input": "1 10 1 10 1",
"output": "0.460000000000"
},
{
"input": "4 4 4 4 1",
"output": "1.000000000000"
},
{
"input": "4 7 4 7 2",
"output": "0.125000000000"
}
] | 1,697,994,485 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 102,400 | def main():
inp = input().split()
p1, p2, v1, v2, k = map(int, inp)
probability = 0
# +1 потому что скобки квадратные, мы включаем границы
all_possible_exoduses = (p2 - p1 + 1) * (v2 - v1 + 1)
all_k_lucky_combinations = score_all_k_lucky_combinations(
k, find_all_lucky_numbers(p1, p2, v1, v2))
for combination in all_k_lucky_combinations:
probability += find_probability_for_one_combination(combination, p1, p2, v1, v2, k)
print(probability)
def find_all_lucky_numbers(p1, p2, v1, v2):
max_x = max(p2, v2)
min_x = min(p1, v1)
all_possible_lucky_numbers_in_segment = []
for i in range(min_x, max_x):
if is_only_4s_and_7s(i):
all_possible_lucky_numbers_in_segment.append(i)
return all_possible_lucky_numbers_in_segment
def score_all_k_lucky_combinations(
k, all_possible_lucky_numbers_in_segment):
all_k_lucky_combinations = []
for i in range(len(all_possible_lucky_numbers_in_segment)):
if len(all_possible_lucky_numbers_in_segment[i:k + i]) == k:
all_k_lucky_combinations.append(
all_possible_lucky_numbers_in_segment[i:k + i])
return all_k_lucky_combinations
def find_probability_for_one_combination(combination, p1, p2, v1, v2, k):
left_elem = combination[0]
right_elem = combination[k - 1]
v_len = v2 - v1 + 1
p_len = p2 - p1 + 1
v1_to_left = left_elem - v1 + 1
p1_to_left = left_elem - p1 + 1
v2_to_right = v2 - right_elem + 1
p2_to_right = p2 - right_elem + 1
v1_probability = 0
p1_probability = 0
v2_probability = 0
p2_probability = 0
if v1_to_left > 0:
v1_probability = v1_to_left / v_len
if p1_to_left > 0:
p1_probability = p1_to_left / p_len
if v2_to_right > 0:
v2_probability = v2_to_right / v_len
if p2_to_right > 0:
p2_probability = p2_to_right / p_len
if right_elem <= v1 and right_elem <= v2:
v1_probability = 1
v2_probability = 1
if right_elem <= p1 and right_elem <= p2:
p1_probability = 1
p2_probability = 1
if left_elem >= v1 and left_elem >= v2:
v1_probability = 1
v2_probability = 1
if left_elem >= p1 and left_elem >= p2:
p1_probability = 1
p2_probability = 1
if v1_probability * p2_probability and v2_probability * p1_probability == 1:
return 1
if v1_probability * p2_probability == 1:
v1_probability = 0
p2_probability = 0
if v2_probability * p1_probability == 1:
v2_probability = 0
p1_probability = 0
probability = (v1_probability * p2_probability) \
+ (v2_probability * p1_probability)
return probability
def is_only_4s_and_7s(number):
for digit in str(number):
if digit not in ['4', '7']:
return False
return True
if __name__ == "__main__":
main()
| Title: Lucky Probability
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer *p* from the interval [*p**l*,<=*p**r*] and Vasya chooses an integer *v* from the interval [*v**l*,<=*v**r*] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [*min*(*v*,<=*p*),<=*max*(*v*,<=*p*)] contains exactly *k* lucky numbers.
Input Specification:
The single line contains five integers *p**l*, *p**r*, *v**l*, *v**r* and *k* (1<=≤<=*p**l*<=≤<=*p**r*<=≤<=109,<=1<=≤<=*v**l*<=≤<=*v**r*<=≤<=109,<=1<=≤<=*k*<=≤<=1000).
Output Specification:
On the single line print the result with an absolute error of no more than 10<=-<=9.
Demo Input:
['1 10 1 10 2\n', '5 6 8 10 1\n']
Demo Output:
['0.320000000000\n', '1.000000000000\n']
Note:
Consider that [*a*, *b*] denotes an interval of integers; this interval includes the boundaries. That is, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18b4a6012d95ad18891561410f0314497a578d63.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10·10 = 100, so answer is 32 / 100.
In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number. | ```python
def main():
inp = input().split()
p1, p2, v1, v2, k = map(int, inp)
probability = 0
# +1 потому что скобки квадратные, мы включаем границы
all_possible_exoduses = (p2 - p1 + 1) * (v2 - v1 + 1)
all_k_lucky_combinations = score_all_k_lucky_combinations(
k, find_all_lucky_numbers(p1, p2, v1, v2))
for combination in all_k_lucky_combinations:
probability += find_probability_for_one_combination(combination, p1, p2, v1, v2, k)
print(probability)
def find_all_lucky_numbers(p1, p2, v1, v2):
max_x = max(p2, v2)
min_x = min(p1, v1)
all_possible_lucky_numbers_in_segment = []
for i in range(min_x, max_x):
if is_only_4s_and_7s(i):
all_possible_lucky_numbers_in_segment.append(i)
return all_possible_lucky_numbers_in_segment
def score_all_k_lucky_combinations(
k, all_possible_lucky_numbers_in_segment):
all_k_lucky_combinations = []
for i in range(len(all_possible_lucky_numbers_in_segment)):
if len(all_possible_lucky_numbers_in_segment[i:k + i]) == k:
all_k_lucky_combinations.append(
all_possible_lucky_numbers_in_segment[i:k + i])
return all_k_lucky_combinations
def find_probability_for_one_combination(combination, p1, p2, v1, v2, k):
left_elem = combination[0]
right_elem = combination[k - 1]
v_len = v2 - v1 + 1
p_len = p2 - p1 + 1
v1_to_left = left_elem - v1 + 1
p1_to_left = left_elem - p1 + 1
v2_to_right = v2 - right_elem + 1
p2_to_right = p2 - right_elem + 1
v1_probability = 0
p1_probability = 0
v2_probability = 0
p2_probability = 0
if v1_to_left > 0:
v1_probability = v1_to_left / v_len
if p1_to_left > 0:
p1_probability = p1_to_left / p_len
if v2_to_right > 0:
v2_probability = v2_to_right / v_len
if p2_to_right > 0:
p2_probability = p2_to_right / p_len
if right_elem <= v1 and right_elem <= v2:
v1_probability = 1
v2_probability = 1
if right_elem <= p1 and right_elem <= p2:
p1_probability = 1
p2_probability = 1
if left_elem >= v1 and left_elem >= v2:
v1_probability = 1
v2_probability = 1
if left_elem >= p1 and left_elem >= p2:
p1_probability = 1
p2_probability = 1
if v1_probability * p2_probability and v2_probability * p1_probability == 1:
return 1
if v1_probability * p2_probability == 1:
v1_probability = 0
p2_probability = 0
if v2_probability * p1_probability == 1:
v2_probability = 0
p1_probability = 0
probability = (v1_probability * p2_probability) \
+ (v2_probability * p1_probability)
return probability
def is_only_4s_and_7s(number):
for digit in str(number):
if digit not in ['4', '7']:
return False
return True
if __name__ == "__main__":
main()
``` | 0 |
253 | C | Text Editor | PROGRAMMING | 1,600 | [
"data structures",
"dfs and similar",
"graphs",
"greedy",
"shortest paths"
] | null | null | Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In fact, he is going to become a programmer. So, he would take great pleasure in writing a program, but none — in writing a composition.
As Vasya was fishing for a sentence in the dark pond of his imagination, he suddenly wondered: what is the least number of times he should push a key to shift the cursor from one position to another one?
Let's describe his question more formally: to type a text, Vasya is using the text editor. He has already written *n* lines, the *i*-th line contains *a**i* characters (including spaces). If some line contains *k* characters, then this line overall contains (*k*<=+<=1) positions where the cursor can stand: before some character or after all characters (at the end of the line). Thus, the cursor's position is determined by a pair of integers (*r*,<=*c*), where *r* is the number of the line and *c* is the cursor's position in the line (the positions are indexed starting from one from the beginning of the line).
Vasya doesn't use the mouse to move the cursor. He uses keys "Up", "Down", "Right" and "Left". When he pushes each of these keys, the cursor shifts in the needed direction. Let's assume that before the corresponding key is pressed, the cursor was located in the position (*r*,<=*c*), then Vasya pushed key:
- "Up": if the cursor was located in the first line (*r*<==<=1), then it does not move. Otherwise, it moves to the previous line (with number *r*<=-<=1), to the same position. At that, if the previous line was short, that is, the cursor couldn't occupy position *c* there, the cursor moves to the last position of the line with number *r*<=-<=1;- "Down": if the cursor was located in the last line (*r*<==<=*n*), then it does not move. Otherwise, it moves to the next line (with number *r*<=+<=1), to the same position. At that, if the next line was short, that is, the cursor couldn't occupy position *c* there, the cursor moves to the last position of the line with number *r*<=+<=1;- "Right": if the cursor can move to the right in this line (*c*<=<<=*a**r*<=+<=1), then it moves to the right (to position *c*<=+<=1). Otherwise, it is located at the end of the line and doesn't move anywhere when Vasya presses the "Right" key;- "Left": if the cursor can move to the left in this line (*c*<=><=1), then it moves to the left (to position *c*<=-<=1). Otherwise, it is located at the beginning of the line and doesn't move anywhere when Vasya presses the "Left" key.
You've got the number of lines in the text file and the number of characters, written in each line of this file. Find the least number of times Vasya should push the keys, described above, to shift the cursor from position (*r*1,<=*c*1) to position (*r*2,<=*c*2). | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the file. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105), separated by single spaces. The third line contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*r*2<=≤<=*n*,<=1<=≤<=*c*1<=≤<=*a**r*1<=+<=1,<=1<=≤<=*c*2<=≤<=*a**r*2<=+<=1). | Print a single integer — the minimum number of times Vasya should push a key to move the cursor from position (*r*1,<=*c*1) to position (*r*2,<=*c*2). | [
"4\n2 1 6 4\n3 4 4 2\n",
"4\n10 5 6 4\n1 11 4 2\n",
"3\n10 1 10\n1 10 1 1\n"
] | [
"3\n",
"6\n",
"3\n"
] | In the first sample the editor contains four lines. Let's represent the cursor's possible positions in the line as numbers. Letter *s* represents the cursor's initial position, letter *t* represents the last one. Then all possible positions of the cursor in the text editor are described by the following table.
123
12
123s567
1t345
One of the possible answers in the given sample is: "Left", "Down", "Left". | 1,500 | [
{
"input": "4\n2 1 6 4\n3 4 4 2",
"output": "3"
},
{
"input": "4\n10 5 6 4\n1 11 4 2",
"output": "6"
},
{
"input": "3\n10 1 10\n1 10 1 1",
"output": "3"
},
{
"input": "4\n2 1 6 4\n4 2 3 5",
"output": "4"
},
{
"input": "3\n20 3 20\n1 20 1 1",
"output": "5"
},
{
"input": "2\n10 1\n1 3 2 1",
"output": "2"
},
{
"input": "20\n3 1 9 9 6 1 3 4 5 6 7 3 1 9 9 1 9 1 5 7\n17 7 19 5",
"output": "5"
},
{
"input": "20\n81 90 11 68 23 18 78 75 45 86 58 37 21 15 98 40 53 100 10 70\n11 55 8 19",
"output": "7"
},
{
"input": "25\n55 47 5 63 55 11 8 32 0 62 41 7 17 70 33 6 41 68 37 82 33 64 28 33 12\n6 11 14 12",
"output": "19"
},
{
"input": "30\n77 38 82 87 88 1 90 3 79 69 64 36 85 12 1 19 80 89 75 56 49 28 10 31 37 65 27 84 10 72\n26 65 19 3",
"output": "15"
},
{
"input": "100\n119 384 220 357 394 123 371 57 6 221 219 79 305 292 71 113 428 326 166 235 120 404 77 223 2 171 81 1 119 307 200 323 89 294 178 421 125 197 89 154 335 46 210 311 216 182 246 262 195 99 175 153 310 302 417 167 222 349 63 325 175 345 6 78 9 147 126 308 229 295 175 368 230 116 95 254 443 15 299 265 322 171 179 184 435 115 384 324 213 359 414 159 322 49 209 296 376 173 369 302\n8 47 23 65",
"output": "73"
},
{
"input": "100\n120 336 161 474 285 126 321 63 82 303 421 110 143 279 505 231 40 413 20 421 271 30 465 186 495 156 225 445 530 156 516 305 360 261 123 5 50 377 124 8 115 529 395 408 271 166 121 240 336 348 352 359 487 471 171 379 381 182 109 425 252 434 131 430 461 386 33 189 481 461 163 89 374 505 525 526 132 468 80 88 90 538 280 281 552 415 194 41 333 296 297 205 40 79 22 219 108 213 158 410\n58 119 82 196",
"output": "186"
},
{
"input": "100\n9 8 5 2 10 6 10 10 1 9 8 5 0 9 1 6 6 2 3 9 9 3 2 7 2 7 8 10 6 6 2 8 5 0 0 8 7 3 0 4 7 5 9 0 3 6 9 6 5 0 4 9 4 7 7 1 5 8 2 4 10 3 9 8 10 6 10 7 4 9 0 1 3 6 6 2 1 1 5 7 0 9 6 0 4 6 8 4 7 6 1 9 4 3 10 9 7 0 0 7\n72 2 87 2",
"output": "16"
},
{
"input": "100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44\n6 76 89 15",
"output": "97"
},
{
"input": "100\n176 194 157 24 27 153 31 159 196 85 127 114 142 39 133 4 44 36 141 96 80 40 120 16 88 29 157 136 158 98 145 152 19 40 106 116 19 195 184 70 72 95 78 146 199 1 103 3 120 71 52 77 160 148 24 156 108 64 86 124 103 97 108 66 107 126 29 172 23 106 29 69 64 90 9 171 59 85 1 63 79 50 136 21 115 164 30 115 86 26 25 6 128 48 122 14 198 88 182 117\n71 4 85 80",
"output": "92"
},
{
"input": "100\n1622 320 1261 282 1604 57 1427 1382 904 911 1719 1682 984 1727 1301 1799 1110 1057 248 764 1642 1325 1172 1677 182 32 665 397 1146 73 412 554 973 874 774 1948 1676 1959 518 280 1467 568 613 760 594 252 224 1359 876 253 760 1566 929 1614 940 1079 288 245 1432 1647 1534 1768 1947 733 225 495 1239 644 124 522 1859 1856 1464 485 1962 131 1693 1622 242 1119 1290 538 998 1342 791 711 809 1407 1369 414 124 758 1104 1142 355 324 665 1155 551 1611\n36 1383 51 21",
"output": "47"
},
{
"input": "50\n966 151 777 841 507 884 487 813 29 230 966 819 390 482 137 365 391 693 56 756 327 500 895 22 361 619 8 516 21 770 572 53 497 682 162 32 308 309 110 470 699 318 947 658 720 679 435 645 481 42\n45 510 25 48",
"output": "59"
},
{
"input": "50\n4143 2907 2028 539 3037 1198 6597 3658 972 9809 854 4931 642 3170 9777 2992 7121 8094 6634 684 5580 4684 3397 7909 3908 3822 2137 8299 8146 2105 7578 4338 7363 8237 530 301 4566 1153 4795 5342 3257 6953 4401 8311 9977 9260 7019 7705 5416 6754\n21 3413 23 218",
"output": "112"
},
{
"input": "50\n8974 13208 81051 72024 84908 49874 22875 64935 27340 38682 28512 43441 78752 83458 63344 5723 83425 54009 61980 7824 59956 43184 49274 3896 44079 67313 68565 9138 55087 68458 43009 3685 22879 85032 84273 93643 64957 73428 57016 33405 85961 47708 90325 1352 1551 20935 76821 75406 59309 40757\n14 45232 2 6810",
"output": "1102"
},
{
"input": "100\n34 80 42 99 7 49 109 61 20 7 92 2 62 96 65 77 70 5 16 83 99 39 88 66 106 1 80 68 71 74 28 75 19 97 38 100 30 1 55 86 3 13 61 82 72 50 68 18 77 89 96 27 26 35 46 13 83 77 40 31 85 108 15 5 40 80 1 108 44 18 66 26 46 7 36 80 34 76 17 9 23 57 109 90 88 1 54 66 71 94 6 89 50 22 93 82 32 74 41 74\n91 7 56 3",
"output": "36"
},
{
"input": "100\n156 150 75 72 205 133 139 99 212 82 58 104 133 88 46 157 49 179 32 72 159 188 42 47 36 58 127 215 125 115 209 118 109 11 62 159 110 151 92 202 203 25 44 209 153 8 199 168 126 34 21 106 31 40 48 212 106 0 131 166 2 126 13 126 103 44 2 66 33 25 194 41 37 198 199 6 22 1 161 16 95 11 198 198 166 145 214 159 143 2 181 130 159 118 176 165 192 178 42 168\n49 12 66 23",
"output": "39"
},
{
"input": "100\n289 16 321 129 0 121 61 86 93 5 63 276 259 144 275 236 309 257 244 138 107 18 158 14 295 162 7 113 58 101 142 196 181 329 115 109 62 237 110 87 19 205 68 257 252 0 166 45 310 244 140 251 262 315 213 206 290 128 287 230 198 83 135 40 8 273 319 295 288 274 34 260 288 252 172 129 201 110 294 111 95 180 34 98 16 188 170 40 274 153 11 159 245 51 328 290 112 11 105 182\n99 53 21 77",
"output": "154"
},
{
"input": "10\n11284 10942 14160 10062 1858 6457 1336 13842 5498 4236\n1 7123 5 664",
"output": "681"
},
{
"input": "53\n29496 9630 10781 25744 28508 15670 8252 14284 25995 20215 24251 14240 1370 15724 28268 30377 4839 16791 33515 23776 24252 1045 15245 12839 17531 28591 13091 27339 23361 10997 30438 26977 26789 18402 32938 2106 26599 10733 29549 9760 31507 33572 16934 7273 26477 15040 23704 19905 1941 3861 5950 1265 34\n11 6571 1 3145",
"output": "1788"
},
{
"input": "31\n14324 29226 58374 19956 61695 71586 13261 11436 58443 34879 12689 62786 68194 34303 99201 67616 51364 67539 56799 60130 22021 64546 28331 75746 45036 43950 2150 61718 33030 37781 34319\n24 57393 7 6152",
"output": "4024"
},
{
"input": "23\n5397 13279 11741 20182 18311 20961 16720 11864 2486 14081 15637 16216 3736 437 16346 12449 20205 10949 14237 2213 15281 15271 19138\n5 11479 13 68",
"output": "380"
},
{
"input": "40\n41997 20736 34699 73866 45509 41964 36050 16673 10454 21166 28306 69335 6172 65943 78569 16794 10439 68061 40392 52510 78248 63851 45294 49929 22580 5574 40993 18334 73897 59148 47727 76645 4280 23651 58772 64500 13704 60366 37099 20336\n14 29991 16 11904",
"output": "1468"
},
{
"input": "16\n922 7593 4748 4103 7672 6001 1573 3973 8524 8265 4747 3202 4796 2637 889 9359\n12 2165 12 1654",
"output": "90"
},
{
"input": "18\n22746 9084 3942 1120 25391 25307 7409 1189 23473 26175 10964 13584 5541 500 24338 12272 15824 27656\n3 1395 12 90",
"output": "424"
},
{
"input": "45\n2286 4425 14666 34959 10792 3723 30132 34266 18100 22813 28627 23310 33911 27285 1211 993 15526 4751 13611 21400 25712 24437 27435 34808 33950 18373 33685 23487 5444 10249 21415 16368 35398 7889 30918 19940 1552 12164 34292 13922 10011 31377 24102 34539 11992\n20 21252 28 2058",
"output": "531"
},
{
"input": "29\n56328 80183 27682 79083 60680 12286 34299 8015 51808 50756 82133 45930 43695 65863 25178 70825 2288 15111 39667 39637 11453 62821 81484 84216 54524 53749 8396 67712 76146\n13 10739 9 3622",
"output": "1345"
},
{
"input": "46\n67864 68218 3593 30646 66413 65542 65322 26801 28984 61330 15247 16522 39142 14013 49272 41585 56739 6881 44227 7101 57657 21121 51857 39351 13500 71528 8488 66118 14756 43923 21284 20018 49049 60198 6181 62460 44141 55828 42636 14623 59758 68321 12192 29978 24745 16467\n27 5545 4 3766",
"output": "197"
},
{
"input": "70\n53691 15034 17444 13375 23285 29211 24567 21643 45514 10290 70111 24541 25072 5365 12162 34564 27535 48253 39581 13468 33718 35105 30468 50214 53365 74800 16749 33935 36346 54230 73796 26826 27866 41887 67566 40813 32267 58821 56828 26439 23708 32335 69515 33825 6092 20510 50174 11129 4592 74116 21498 77951 48056 28554 43904 21885 5967 40253 4990 70029 34374 41201 25399 6101 10354 61833 43646 20534 371 11111\n21 3911 45 1755",
"output": "1455"
},
{
"input": "10\n8121 10681 10179 10221 9410 5214 19040 17893 7862 4611\n7 7780 7 3369",
"output": "1249"
},
{
"input": "2\n1 2\n1 1 1 1",
"output": "0"
},
{
"input": "3\n1 10 20\n2 10 3 1",
"output": "4"
}
] | 1,620,644,227 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 6,963,200 | class Solution_once:
def singleNumber(self, arr):
ones, twos = 0, 0
for x in arr:
ones, twos = (ones ^ x) & ~twos, (ones & x) | (twos & ~x)
assert twos == 0
return ones
class Solution_twice:
def single_number(arr):
ones, twos, threes = 0, 0, 0
for x in arr:
ones, twos, threes = (~x & ones) | (x & ~ones & ~twos & ~threes), (~x & twos) | (x & ones), (~x & threes) | (x & twos)
return twos
if __name__ == "__main__":
print(Solution_once().singleNumber([1, 1, 1, 2, 2, 2, 3]))
print(Solution_once().singleNumber([5, 3, 0, 3, 5, 5, 3]))
| Title: Text Editor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is pressing the keys on the keyboard reluctantly, squeezing out his ideas on the classical epos depicted in Homer's Odysseus... How can he explain to his literature teacher that he isn't going to become a writer? In fact, he is going to become a programmer. So, he would take great pleasure in writing a program, but none — in writing a composition.
As Vasya was fishing for a sentence in the dark pond of his imagination, he suddenly wondered: what is the least number of times he should push a key to shift the cursor from one position to another one?
Let's describe his question more formally: to type a text, Vasya is using the text editor. He has already written *n* lines, the *i*-th line contains *a**i* characters (including spaces). If some line contains *k* characters, then this line overall contains (*k*<=+<=1) positions where the cursor can stand: before some character or after all characters (at the end of the line). Thus, the cursor's position is determined by a pair of integers (*r*,<=*c*), where *r* is the number of the line and *c* is the cursor's position in the line (the positions are indexed starting from one from the beginning of the line).
Vasya doesn't use the mouse to move the cursor. He uses keys "Up", "Down", "Right" and "Left". When he pushes each of these keys, the cursor shifts in the needed direction. Let's assume that before the corresponding key is pressed, the cursor was located in the position (*r*,<=*c*), then Vasya pushed key:
- "Up": if the cursor was located in the first line (*r*<==<=1), then it does not move. Otherwise, it moves to the previous line (with number *r*<=-<=1), to the same position. At that, if the previous line was short, that is, the cursor couldn't occupy position *c* there, the cursor moves to the last position of the line with number *r*<=-<=1;- "Down": if the cursor was located in the last line (*r*<==<=*n*), then it does not move. Otherwise, it moves to the next line (with number *r*<=+<=1), to the same position. At that, if the next line was short, that is, the cursor couldn't occupy position *c* there, the cursor moves to the last position of the line with number *r*<=+<=1;- "Right": if the cursor can move to the right in this line (*c*<=<<=*a**r*<=+<=1), then it moves to the right (to position *c*<=+<=1). Otherwise, it is located at the end of the line and doesn't move anywhere when Vasya presses the "Right" key;- "Left": if the cursor can move to the left in this line (*c*<=><=1), then it moves to the left (to position *c*<=-<=1). Otherwise, it is located at the beginning of the line and doesn't move anywhere when Vasya presses the "Left" key.
You've got the number of lines in the text file and the number of characters, written in each line of this file. Find the least number of times Vasya should push the keys, described above, to shift the cursor from position (*r*1,<=*c*1) to position (*r*2,<=*c*2).
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the file. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105), separated by single spaces. The third line contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*r*2<=≤<=*n*,<=1<=≤<=*c*1<=≤<=*a**r*1<=+<=1,<=1<=≤<=*c*2<=≤<=*a**r*2<=+<=1).
Output Specification:
Print a single integer — the minimum number of times Vasya should push a key to move the cursor from position (*r*1,<=*c*1) to position (*r*2,<=*c*2).
Demo Input:
['4\n2 1 6 4\n3 4 4 2\n', '4\n10 5 6 4\n1 11 4 2\n', '3\n10 1 10\n1 10 1 1\n']
Demo Output:
['3\n', '6\n', '3\n']
Note:
In the first sample the editor contains four lines. Let's represent the cursor's possible positions in the line as numbers. Letter *s* represents the cursor's initial position, letter *t* represents the last one. Then all possible positions of the cursor in the text editor are described by the following table.
123
12
123s567
1t345
One of the possible answers in the given sample is: "Left", "Down", "Left". | ```python
class Solution_once:
def singleNumber(self, arr):
ones, twos = 0, 0
for x in arr:
ones, twos = (ones ^ x) & ~twos, (ones & x) | (twos & ~x)
assert twos == 0
return ones
class Solution_twice:
def single_number(arr):
ones, twos, threes = 0, 0, 0
for x in arr:
ones, twos, threes = (~x & ones) | (x & ~ones & ~twos & ~threes), (~x & twos) | (x & ones), (~x & threes) | (x & twos)
return twos
if __name__ == "__main__":
print(Solution_once().singleNumber([1, 1, 1, 2, 2, 2, 3]))
print(Solution_once().singleNumber([5, 3, 0, 3, 5, 5, 3]))
``` | 0 |
|
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
"output": "YES"
},
{
"input": "5 7",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "11 13",
"output": "YES"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "17 19",
"output": "YES"
},
{
"input": "19 23",
"output": "YES"
},
{
"input": "23 29",
"output": "YES"
},
{
"input": "29 31",
"output": "YES"
},
{
"input": "31 37",
"output": "YES"
},
{
"input": "37 41",
"output": "YES"
},
{
"input": "41 43",
"output": "YES"
},
{
"input": "43 47",
"output": "YES"
},
{
"input": "2 5",
"output": "NO"
},
{
"input": "2 7",
"output": "NO"
},
{
"input": "2 6",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
},
{
"input": "3 6",
"output": "NO"
},
{
"input": "3 7",
"output": "NO"
},
{
"input": "3 9",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 9",
"output": "NO"
},
{
"input": "5 11",
"output": "NO"
},
{
"input": "5 13",
"output": "NO"
},
{
"input": "5 15",
"output": "NO"
},
{
"input": "7 8",
"output": "NO"
},
{
"input": "7 13",
"output": "NO"
},
{
"input": "13 15",
"output": "NO"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "19 21",
"output": "NO"
},
{
"input": "13 20",
"output": "NO"
},
{
"input": "41 49",
"output": "NO"
},
{
"input": "43 49",
"output": "NO"
},
{
"input": "47 50",
"output": "NO"
},
{
"input": "47 49",
"output": "NO"
},
{
"input": "47 48",
"output": "NO"
},
{
"input": "23 25",
"output": "NO"
},
{
"input": "2 50",
"output": "NO"
},
{
"input": "31 33",
"output": "NO"
}
] | 1,675,415,536 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 39 | 186 | 2,150,400 | primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
n, m = map(int, input().split())
print("YES") if primes[primes.index(n) + 1] == m else print("NO")
| Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
Input Specification:
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
Output Specification:
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
Demo Input:
['3 5\n', '7 11\n', '7 9\n']
Demo Output:
['YES', 'YES', 'NO']
Note:
none | ```python
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
n, m = map(int, input().split())
print("YES") if primes[primes.index(n) + 1] == m else print("NO")
``` | -1 |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | 0 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3",
"output": "16"
},
{
"input": "10\n2 3 0 1 3 1 2 2 1 0",
"output": "3"
},
{
"input": "45\n3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "2\n3 3",
"output": "0"
},
{
"input": "3\n3 3 3",
"output": "0"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "2\n0 2",
"output": "1"
},
{
"input": "10\n2 2 3 3 3 3 2 1 3 2",
"output": "2"
},
{
"input": "15\n0 1 0 0 0 2 0 1 0 0 0 2 0 0 0",
"output": "11"
},
{
"input": "15\n1 3 2 2 2 3 3 3 3 2 3 2 2 1 1",
"output": "4"
},
{
"input": "15\n3 1 3 2 3 2 2 2 3 3 3 3 2 3 2",
"output": "3"
},
{
"input": "20\n0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0",
"output": "12"
},
{
"input": "20\n2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3",
"output": "5"
},
{
"input": "20\n3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2",
"output": "4"
},
{
"input": "25\n0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1",
"output": "16"
},
{
"input": "25\n1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3",
"output": "5"
},
{
"input": "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3",
"output": "3"
},
{
"input": "30\n0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0",
"output": "22"
},
{
"input": "30\n1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2",
"output": "9"
},
{
"input": "30\n1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3",
"output": "2"
},
{
"input": "35\n0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0",
"output": "21"
},
{
"input": "35\n2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2",
"output": "11"
},
{
"input": "35\n1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2",
"output": "7"
},
{
"input": "40\n2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0",
"output": "28"
},
{
"input": "40\n2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1",
"output": "10"
},
{
"input": "40\n1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3",
"output": "8"
},
{
"input": "45\n2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2",
"output": "29"
},
{
"input": "45\n3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3",
"output": "8"
},
{
"input": "50\n3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0",
"output": "32"
},
{
"input": "50\n3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2",
"output": "16"
},
{
"input": "50\n3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3",
"output": "7"
},
{
"input": "55\n0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0",
"output": "40"
},
{
"input": "55\n3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2",
"output": "13"
},
{
"input": "55\n3 3 1 3 2 3 2 3 2 2 3 3 3 3 3 1 1 3 3 2 3 2 3 2 0 1 3 3 3 3 2 3 2 3 1 1 2 2 2 3 3 3 3 3 2 2 2 3 2 3 3 3 3 1 3",
"output": "7"
},
{
"input": "60\n0 1 0 0 0 0 0 0 0 2 1 1 3 0 0 0 0 0 1 0 1 1 0 0 0 3 0 1 0 1 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0",
"output": "44"
},
{
"input": "60\n3 2 1 3 2 2 3 3 3 1 1 3 2 2 3 3 1 3 2 2 3 3 2 2 2 2 0 2 2 3 2 3 0 3 3 3 2 3 3 0 1 3 2 1 3 1 1 2 1 3 1 1 2 2 1 3 3 3 2 2",
"output": "15"
},
{
"input": "60\n3 2 2 3 2 3 2 3 3 2 3 2 3 3 2 3 3 3 3 3 3 2 3 3 1 2 3 3 3 2 1 3 3 1 3 1 3 0 3 3 3 2 3 2 3 2 3 3 1 1 2 3 3 3 3 2 1 3 2 3",
"output": "8"
},
{
"input": "65\n1 0 2 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 2 0 2 1 0 2 1 0 1 0 1 1 0 1 1 1 2 1 0 1 0 0 0 0 1 2 2 1 0 0 1 2 1 2 0 2 0 0 0 1 1",
"output": "35"
},
{
"input": "65\n2 2 2 3 0 2 1 2 3 3 1 3 1 2 1 3 2 3 2 2 2 1 2 0 3 1 3 1 1 3 1 3 3 3 3 3 1 3 0 3 1 3 1 2 2 3 2 0 3 1 3 2 1 2 2 2 3 3 2 3 3 3 2 2 3",
"output": "13"
},
{
"input": "65\n3 2 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 3 3 2 3 3 2 3 3 3 3 2 3 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 3 3 1 3 3 3 3",
"output": "6"
},
{
"input": "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1",
"output": "43"
},
{
"input": "70\n2 3 3 3 1 3 3 1 2 1 1 2 2 3 0 2 3 3 1 3 3 2 2 3 3 3 2 2 2 2 1 3 3 0 2 1 1 3 2 3 3 2 2 3 1 3 1 2 3 2 3 3 2 2 2 3 1 1 2 1 3 3 2 2 3 3 3 1 1 1",
"output": "16"
},
{
"input": "70\n3 3 2 2 1 2 1 2 2 2 2 2 3 3 2 3 3 3 3 2 2 2 2 3 3 3 1 3 3 3 2 3 3 3 3 2 3 3 1 3 1 3 2 3 3 2 3 3 3 2 3 2 3 3 1 2 3 3 2 2 2 3 2 3 3 3 3 3 3 1",
"output": "10"
},
{
"input": "75\n1 0 0 1 1 0 0 1 0 1 2 0 0 2 1 1 0 0 0 0 0 0 2 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 2 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0",
"output": "51"
},
{
"input": "75\n1 3 3 3 1 1 3 2 3 3 1 3 3 3 2 1 3 2 2 3 1 1 1 1 1 1 2 3 3 3 3 3 3 2 3 3 3 3 3 2 3 3 2 2 2 1 2 3 3 2 2 3 0 1 1 3 3 0 0 1 1 3 2 3 3 3 3 1 2 2 3 3 3 3 1",
"output": "16"
},
{
"input": "75\n3 3 3 3 2 2 3 2 2 3 2 2 1 2 3 3 2 2 3 3 1 2 2 2 1 3 3 3 1 2 2 3 3 3 2 3 2 2 2 3 3 1 3 2 2 3 3 3 0 3 2 1 3 3 2 3 3 3 3 1 2 3 3 3 2 2 3 3 3 3 2 2 3 3 1",
"output": "11"
},
{
"input": "80\n0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 1 1 0 2 2 1 1 0 1 0 1 0 1 1 1 0 1 2 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 2 2 0 1 1 0 0 0 0 0 0 0 0 1",
"output": "56"
},
{
"input": "80\n2 2 3 3 2 1 0 1 0 3 2 2 3 2 1 3 1 3 3 2 3 3 3 2 3 3 3 2 1 3 3 1 3 3 3 3 3 3 2 2 2 1 3 2 1 3 2 1 1 0 1 1 2 1 3 0 1 2 3 2 2 3 2 3 1 3 3 2 1 1 0 3 3 3 3 1 2 1 2 0",
"output": "17"
},
{
"input": "80\n2 3 3 2 2 2 3 3 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 1 3 2 3 3 0 3 1 2 3 3 1 2 3 2 3 3 2 3 3 3 3 3 2 2 3 0 3 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 3 2 3",
"output": "9"
},
{
"input": "85\n0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 2 0 1 0 0 2 0 1 1 0 0 0 0 2 2 0 0 0 1 0 0 0 1 2 0 1 0 0 0 2 1 1 2 0 3 1 0 2 2 1 0 0 1 1 0 0 0 0 1 0 2 1 1 2 1 0 0 1 2 1 2 0 0 1 0 1 0",
"output": "54"
},
{
"input": "85\n2 3 1 3 2 3 1 3 3 2 1 2 1 2 2 3 2 2 3 2 0 3 3 2 1 2 2 2 3 3 2 3 3 3 2 1 1 3 1 3 2 2 2 3 3 2 3 2 3 1 1 3 2 3 1 3 3 2 3 3 2 2 3 0 1 1 2 2 2 2 1 2 3 1 3 3 1 3 2 2 3 2 3 3 3",
"output": "19"
},
{
"input": "85\n1 2 1 2 3 2 3 3 3 3 3 3 3 2 1 3 2 3 3 3 3 2 3 3 3 1 3 3 3 3 2 3 3 3 3 3 3 2 2 1 3 3 3 3 2 2 3 1 1 2 3 3 3 2 3 3 3 3 3 2 3 3 3 2 2 3 3 1 1 1 3 3 3 3 1 3 3 3 1 3 3 1 3 2 3",
"output": "9"
},
{
"input": "90\n2 0 1 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 2 2 0 2 0 0 2 1 0 2 0 1 0 1 0 0 1 2 2 0 0 1 0 0 1 0 1 0 2 0 1 1 1 0 1 1 0 1 0 2 0 1 0 1 0 0 0 1 0 0 1 2 0 0 0 1 0 0 2 2 0 0 0 0 0 1 3 1 1 0 1",
"output": "57"
},
{
"input": "90\n2 3 3 3 2 3 2 1 3 0 3 2 3 3 2 1 3 3 2 3 2 3 3 2 1 3 1 3 3 1 2 2 3 3 2 1 2 3 2 3 0 3 3 2 2 3 1 0 3 3 1 3 3 3 3 2 1 2 2 1 3 2 1 3 3 1 2 0 2 2 3 2 2 3 3 3 1 3 2 1 2 3 3 2 3 2 3 3 2 1",
"output": "17"
},
{
"input": "90\n2 3 2 3 2 2 3 3 2 3 2 1 2 3 3 3 2 3 2 3 3 2 3 3 3 1 3 3 1 3 2 3 2 2 1 3 3 3 3 3 3 3 3 3 3 2 3 2 3 2 1 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 1 3 2 3 3 3 2 2 3 2 3 2 1 3 2",
"output": "9"
},
{
"input": "95\n0 0 3 0 2 0 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 2 0 1 2 2 0 0 1 0 2 0 0 0 1 0 2 1 2 1 0 1 0 0 0 1 0 0 1 1 2 1 1 1 1 2 0 0 0 0 0 1 1 0 1",
"output": "61"
},
{
"input": "95\n2 3 3 2 1 1 3 3 3 2 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 1 2 3 3 3 1 3 0 3 3 1 3 3 1 0 1 3 3 3 0 2 1 3 3 3 3 0 1 3 2 3 3 2 1 3 1 2 1 1 2 3 0 3 3 2 1 3 2 1 3 3 3 2 2 3 2 3 3 3 2 1 3 3 3 2 3 3 1 2",
"output": "15"
},
{
"input": "95\n2 3 3 2 3 2 2 1 3 1 2 1 2 3 1 2 3 3 1 3 3 3 1 2 3 2 2 2 2 3 3 3 2 2 3 3 3 3 3 1 2 2 3 3 3 3 2 3 2 2 2 3 3 2 3 3 3 3 3 3 3 0 3 2 0 3 3 1 3 3 3 2 3 2 3 2 3 3 3 3 2 2 1 1 3 3 3 3 3 1 3 3 3 3 2",
"output": "14"
},
{
"input": "100\n1 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 1 0 1 2 0 1 1 0 0 1 0 1 1 0 0 0 2 0 1 0 0 2 0 0 0 0 0 1 1 1 0 0 1 0 2 0 0 0 0 1 0 1 0 1 0 1 0 1 2 2 0 0 2 0 1 0 1 0 1 0 0 0 1 0 0 2 1 1 1 0 0 1 0 0 0 2 0 0 2 1 1 0 0 2",
"output": "63"
},
{
"input": "100\n3 2 1 3 2 3 2 3 2 2 3 1 3 3 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 1 2 1 3 3 3 3 1 3 3 3 3 3 2 3 2 1 3 3 1 2 2 3 1 3 3 1 2 2 1 3 1 3 2 2 3 3 1 3 2 3 1 2 1 2 3 3 2 2 1 2 3 3 3 3 3 1 3 3 3 3 2 1 3 0 3 3 3 2 3 3",
"output": "15"
},
{
"input": "100\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "0"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "50"
},
{
"input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "49"
},
{
"input": "100\n2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100"
},
{
"input": "2\n0 3",
"output": "1"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 0",
"output": "1"
},
{
"input": "2\n2 1",
"output": "0"
},
{
"input": "2\n2 3",
"output": "0"
},
{
"input": "2\n3 0",
"output": "1"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "100\n3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0",
"output": "50"
}
] | 1,468,938,650 | 5,150 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 77 | 307,200 | from sys import stdin
def remplir(inf,sup,val):
global programme
for i in range(inf,sup+1):
programme[i]=val
val=(val+1)%2
n=int(input())+2
programme=list(map(int,stdin.readline().split()))
programme=[0]+programme
programme.append(0)
chaines=[]
antagoniste=[0,2,1,3]
i=0
while i<n:
inf=i
while i<n and programme[i]==3:
i+=1
chaines.append((inf,i-1))
i+=1
for inf,sup in chaines:
precedent=programme[inf-1]
suivant=programme[sup+1]
longueur=sup-inf+1
if precedent==0 and suivant==0:
remplir(inf,sup,1)
elif precedent!=0:
remplir(inf,sup,antagoniste[precedent])
else:
if longueur%2==0:
remplir(inf,sup,suivant)
else:
remplir(inf,sup,antagoniste[suivant])
nombreRepos=0
for i in range(n-1):
if programme[i]==0 or programme[i]==programme[i+1]:
nombreRepos+=1
if programme[n-1]==0:
nombreRepos+=1
print(nombreRepos-2)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Output Specification:
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days.
Demo Input:
['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | ```python
from sys import stdin
def remplir(inf,sup,val):
global programme
for i in range(inf,sup+1):
programme[i]=val
val=(val+1)%2
n=int(input())+2
programme=list(map(int,stdin.readline().split()))
programme=[0]+programme
programme.append(0)
chaines=[]
antagoniste=[0,2,1,3]
i=0
while i<n:
inf=i
while i<n and programme[i]==3:
i+=1
chaines.append((inf,i-1))
i+=1
for inf,sup in chaines:
precedent=programme[inf-1]
suivant=programme[sup+1]
longueur=sup-inf+1
if precedent==0 and suivant==0:
remplir(inf,sup,1)
elif precedent!=0:
remplir(inf,sup,antagoniste[precedent])
else:
if longueur%2==0:
remplir(inf,sup,suivant)
else:
remplir(inf,sup,antagoniste[suivant])
nombreRepos=0
for i in range(n-1):
if programme[i]==0 or programme[i]==programme[i+1]:
nombreRepos+=1
if programme[n-1]==0:
nombreRepos+=1
print(nombreRepos-2)
``` | 0 |
|
839 | A | Arya and Bran | PROGRAMMING | 900 | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*).
Print -1 if she can't give him *k* candies during *n* given days. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | 500 | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",
"output": "18"
},
{
"input": "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5",
"output": "30"
},
{
"input": "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 55 52 72 71 38 21 43 83 48 47",
"output": "40"
},
{
"input": "50 300\n5 3 11 8 7 4 9 5 5 1 6 3 5 7 4 2 2 10 8 1 7 10 4 4 11 5 2 4 9 1 5 4 11 9 11 2 7 4 4 8 10 9 1 11 10 2 4 11 6 9",
"output": "-1"
},
{
"input": "37 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "30"
},
{
"input": "100 456\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "57"
},
{
"input": "90 298\n94 90 98 94 93 90 99 98 90 96 93 96 92 92 97 98 94 94 96 100 93 96 95 98 94 91 95 95 94 90 93 96 93 100 99 98 94 95 98 91 91 98 97 100 98 93 92 93 91 100 92 97 95 95 97 94 98 97 99 100 90 96 93 100 95 99 92 100 99 91 97 99 98 93 90 93 97 95 94 96 90 100 94 93 91 92 97 97 97 100",
"output": "38"
},
{
"input": "7 43\n4 3 7 9 3 8 10",
"output": "-1"
},
{
"input": "99 585\n8 2 3 3 10 7 9 4 7 4 6 8 7 11 5 8 7 4 7 7 6 7 11 8 1 7 3 2 10 1 6 10 10 5 10 2 5 5 11 6 4 1 5 10 5 8 1 3 7 10 6 1 1 3 8 11 5 8 2 2 5 4 7 6 7 5 8 7 10 9 6 11 4 8 2 7 1 7 1 4 11 1 9 6 1 10 6 10 1 5 6 5 2 5 11 5 1 10 8",
"output": "-1"
},
{
"input": "30 177\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 8",
"output": "-1"
},
{
"input": "19 129\n3 3 10 11 4 7 3 8 10 2 11 6 11 9 4 2 11 10 5",
"output": "-1"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "13 104\n94 55 20 96 86 76 13 71 13 1 32 76 69",
"output": "13"
},
{
"input": "85 680\n61 44 55 6 30 74 27 26 17 45 73 1 67 71 39 32 13 25 79 66 4 59 49 28 29 22 10 17 98 80 36 99 52 24 59 44 27 79 29 46 29 12 47 72 82 25 6 30 81 72 95 65 30 71 72 45 39 16 16 89 48 42 59 71 50 58 31 65 91 70 48 56 28 34 53 89 94 98 49 55 94 65 91 11 53",
"output": "85"
},
{
"input": "100 458\n3 6 4 1 8 4 1 5 4 4 5 8 4 4 6 6 5 1 2 2 2 1 7 1 1 2 6 5 7 8 3 3 8 3 7 5 7 6 6 2 4 2 2 1 1 8 6 1 5 3 3 4 1 4 6 8 5 4 8 5 4 5 5 1 3 1 6 7 6 2 7 3 4 8 1 8 6 7 1 2 4 6 7 4 8 8 8 4 8 7 5 2 8 4 2 5 6 8 8 5",
"output": "100"
},
{
"input": "98 430\n4 7 6 3 4 1 7 1 1 6 6 1 5 4 6 1 5 4 6 6 1 5 1 1 8 1 6 6 2 6 8 4 4 6 6 8 8 7 4 1 2 4 1 5 4 3 7 3 2 5 7 7 7 2 2 2 7 2 8 7 3 4 5 7 8 3 7 6 7 3 2 4 7 1 4 4 7 1 1 8 4 5 8 3 1 5 3 5 2 1 3 3 8 1 3 5 8 6",
"output": "98"
},
{
"input": "90 80\n6 1 7 1 1 8 6 6 6 1 5 4 2 2 8 4 8 7 7 2 5 7 7 8 5 5 6 3 3 8 3 5 6 3 4 2 6 5 5 3 3 3 8 6 6 1 8 3 6 5 4 8 5 4 3 7 1 3 2 3 3 7 7 7 3 5 2 6 2 3 6 4 6 5 5 3 2 1 1 7 3 3 4 3 4 2 1 2 3 1",
"output": "18"
},
{
"input": "89 99\n7 7 3 5 2 7 8 8 1 1 5 7 7 4 1 5 3 4 4 8 8 3 3 2 6 3 8 2 7 5 8 1 3 5 3 6 4 3 6 2 3 3 4 5 1 6 1 7 7 7 6 7 7 7 8 8 8 2 1 7 5 8 6 7 7 4 7 5 7 8 1 3 5 8 7 1 4 2 5 8 3 4 4 5 5 6 2 4 2",
"output": "21"
},
{
"input": "50 700\n4 3 2 8 8 5 5 3 3 4 7 2 6 6 3 3 8 4 2 4 8 6 5 4 5 4 5 8 6 5 4 7 2 4 1 6 2 6 8 6 2 5 8 1 3 8 3 8 4 1",
"output": "-1"
},
{
"input": "82 359\n95 98 95 90 90 96 91 94 93 99 100 100 92 99 96 94 99 90 94 96 91 91 90 93 97 96 90 94 97 99 93 90 99 98 96 100 93 97 100 91 100 92 93 100 92 90 90 94 99 95 100 98 99 96 94 96 96 99 99 91 97 100 95 100 99 91 94 91 98 98 100 97 93 93 96 97 94 94 92 100 91 91",
"output": "45"
},
{
"input": "60 500\n93 93 100 99 91 92 95 93 95 99 93 91 97 98 90 91 98 100 95 100 94 93 92 91 91 98 98 90 93 91 90 96 92 93 92 94 94 91 96 94 98 100 97 96 96 97 91 99 97 95 96 94 91 92 99 95 97 92 98 90",
"output": "-1"
},
{
"input": "98 776\n48 63 26 3 88 81 27 33 37 10 2 89 41 84 98 93 25 44 42 90 41 65 97 1 28 69 42 14 86 18 96 28 28 94 78 8 44 31 96 45 26 52 93 25 48 39 3 75 94 93 63 59 67 86 18 74 27 38 68 7 31 60 69 67 20 11 19 34 47 43 86 96 3 49 56 60 35 49 89 28 92 69 48 15 17 73 99 69 2 73 27 35 28 53 11 1 96 50",
"output": "97"
},
{
"input": "100 189\n15 14 32 65 28 96 33 93 48 28 57 20 32 20 90 42 57 53 18 58 94 21 27 29 37 22 94 45 67 60 83 23 20 23 35 93 3 42 6 46 68 46 34 25 17 16 50 5 49 91 23 76 69 100 58 68 81 32 88 41 64 29 37 13 95 25 6 59 74 58 31 35 16 80 13 80 10 59 85 18 16 70 51 40 44 28 8 76 8 87 53 86 28 100 2 73 14 100 52 9",
"output": "24"
},
{
"input": "99 167\n72 4 79 73 49 58 15 13 92 92 42 36 35 21 13 10 51 94 64 35 86 50 6 80 93 77 59 71 2 88 22 10 27 30 87 12 77 6 34 56 31 67 78 84 36 27 15 15 12 56 80 7 56 14 10 9 14 59 15 20 34 81 8 49 51 72 4 58 38 77 31 86 18 61 27 86 95 36 46 36 39 18 78 39 48 37 71 12 51 92 65 48 39 22 16 87 4 5 42",
"output": "21"
},
{
"input": "90 4\n48 4 4 78 39 3 85 29 69 52 70 39 11 98 42 56 65 98 77 24 61 31 6 59 60 62 84 46 67 59 15 44 99 23 12 74 2 48 84 60 51 28 17 90 10 82 3 43 50 100 45 57 57 95 53 71 20 74 52 46 64 59 72 33 74 16 44 44 80 71 83 1 70 59 61 6 82 69 81 45 88 28 17 24 22 25 53 97 1 100",
"output": "1"
},
{
"input": "30 102\n55 94 3 96 3 47 92 85 25 78 27 70 97 83 40 2 55 12 74 84 91 37 31 85 7 40 33 54 72 5",
"output": "13"
},
{
"input": "81 108\n61 59 40 100 8 75 5 74 87 12 6 23 98 26 59 68 27 4 98 79 14 44 4 11 89 77 29 90 33 3 43 1 87 91 28 24 4 84 75 7 37 46 15 46 8 87 68 66 5 21 36 62 77 74 91 95 88 28 12 48 18 93 14 51 33 5 99 62 99 38 49 15 56 87 52 64 69 46 41 12 92",
"output": "14"
},
{
"input": "2 16\n10 6",
"output": "2"
},
{
"input": "2 8\n7 8",
"output": "2"
},
{
"input": "2 9\n4 8",
"output": "2"
},
{
"input": "3 19\n9 9 1",
"output": "3"
},
{
"input": "4 32\n9 9 9 5",
"output": "4"
},
{
"input": "2 15\n14 1",
"output": "2"
},
{
"input": "2 3\n3 3",
"output": "1"
},
{
"input": "3 10\n10 1 1",
"output": "2"
},
{
"input": "12 20\n3 16 19 10 1 6 17 8 6 20 1 4",
"output": "4"
},
{
"input": "4 15\n14 3 3 3",
"output": "2"
},
{
"input": "5 40\n10 10 10 10 1",
"output": "5"
},
{
"input": "4 31\n9 9 8 5",
"output": "4"
},
{
"input": "4 31\n20 7 1 1",
"output": "-1"
},
{
"input": "2 10\n9 1",
"output": "2"
},
{
"input": "10 50\n100 10 1 1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "2 11\n10 2",
"output": "2"
},
{
"input": "3 21\n10 10 1",
"output": "3"
},
{
"input": "2 2\n1 2",
"output": "2"
},
{
"input": "3 2\n1 8 8",
"output": "2"
},
{
"input": "2 11\n10 1",
"output": "2"
},
{
"input": "2 16\n12 4",
"output": "2"
},
{
"input": "3 11\n9 2 2",
"output": "2"
},
{
"input": "3 11\n4 3 4",
"output": "3"
},
{
"input": "2 13\n7 6",
"output": "2"
},
{
"input": "3 24\n14 3 4",
"output": "-1"
},
{
"input": "2 13\n10 3",
"output": "2"
},
{
"input": "3 11\n9 2 1",
"output": "2"
},
{
"input": "2 15\n12 3",
"output": "2"
},
{
"input": "2 14\n11 4",
"output": "2"
}
] | 1,643,627,934 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 31 | 0 | n, k = map(int, input().split())
v = list(map(int, input().split()))
t = 0
i = 0
for i in range(0, n):
t += v[i]
x = min(8, t)
k -= x
t -= x
if k <= 0:
break
print([i + 1, -1][k > 0])
| Title: Arya and Bran
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. Formally, you need to output the minimum day index to the end of which *k* candies will be given out (the days are indexed from 1 to *n*).
Print -1 if she can't give him *k* candies during *n* given days.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day.
Demo Input:
['2 3\n1 2\n', '3 17\n10 10 10\n', '1 9\n10\n']
Demo Output:
['2', '3', '-1']
Note:
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | ```python
n, k = map(int, input().split())
v = list(map(int, input().split()))
t = 0
i = 0
for i in range(0, n):
t += v[i]
x = min(8, t)
k -= x
t -= x
if k <= 0:
break
print([i + 1, -1][k > 0])
``` | 3 |
|
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
"input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ",
"output": "1077"
},
{
"input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA",
"output": "568"
},
{
"input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA",
"output": "70"
},
{
"input": "W",
"output": "0"
},
{
"input": "DBA",
"output": "0"
},
{
"input": "RQAWNACASAAKAGAAAAQ",
"output": "10"
},
{
"input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA",
"output": "111"
},
{
"input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA",
"output": "411"
},
{
"input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ",
"output": "625"
},
{
"input": "QORZOYAQ",
"output": "1"
},
{
"input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA",
"output": "13174"
},
{
"input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT",
"output": "10420"
},
{
"input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ",
"output": "12488"
},
{
"input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA",
"output": "9114"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "35937"
},
{
"input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE",
"output": "254"
},
{
"input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE",
"output": "2174"
},
{
"input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ",
"output": "2962"
},
{
"input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA",
"output": "2482"
},
{
"input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ",
"output": "7768"
},
{
"input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA",
"output": "5422"
},
{
"input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ",
"output": "3024"
},
{
"input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ",
"output": "4527"
},
{
"input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH",
"output": "6416"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ",
"output": "13136"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA",
"output": "14231"
},
{
"input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "15296"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA",
"output": "20825"
},
{
"input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ",
"output": "20825"
},
{
"input": "Q",
"output": "0"
},
{
"input": "A",
"output": "0"
},
{
"input": "FFF",
"output": "0"
},
{
"input": "AAAAAA",
"output": "0"
}
] | 1,617,297,759 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 62 | 0 | a=input()
print(sum(a[:i].count('Q')*a[i:].count('Q') for i in range(len(a)) if a[i]=='A')) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
Input Specification:
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Output Specification:
Print a single integer — the number of subsequences "QAQ" in the string.
Demo Input:
['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n']
Demo Output:
['4\n', '3\n']
Note:
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | ```python
a=input()
print(sum(a[:i].count('Q')*a[i:].count('Q') for i in range(len(a)) if a[i]=='A'))
``` | 3 |
|
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,682,695,919 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | n=int(input())
f=list(map(int,input().split()))
b = sum(f)
c = 0
for x in range(1, 6):
if (x + b) % (n+1) != 1:
c += 1
print(c) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
n=int(input())
f=list(map(int,input().split()))
b = sum(f)
c = 0
for x in range(1, 6):
if (x + b) % (n+1) != 1:
c += 1
print(c)
``` | 3 |
|
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
"output": "QCCYXL"
},
{
"input": "3\nAZID\nEERWBC\nEERWBC",
"output": "EERWBC"
},
{
"input": "3\nHNCGYL\nHNCGYL\nHNCGYL",
"output": "HNCGYL"
},
{
"input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG",
"output": "ZZWZTG"
},
{
"input": "4\nA\nA\nKUDLJMXCSE\nA",
"output": "A"
},
{
"input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW",
"output": "PHBTW"
},
{
"input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN",
"output": "PKUZYTFYWN"
},
{
"input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH",
"output": "HH"
},
{
"input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW",
"output": "W"
},
{
"input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP",
"output": "XBCP"
},
{
"input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS",
"output": "PYPAS"
},
{
"input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC",
"output": "NC"
},
{
"input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI",
"output": "VOCI"
},
{
"input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA",
"output": "HA"
},
{
"input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS",
"output": "G"
},
{
"input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL",
"output": "WL"
}
] | 1,657,288,179 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | dic={}
for i in range(int(input())):
goal=input()
if goal in dic.keys():
dic[goal]+=1
else:
dic[goal]=1
print(max(dic)) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output Specification:
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Demo Input:
['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n']
Demo Output:
['ABC\n', 'A\n']
Note:
none | ```python
dic={}
for i in range(int(input())):
goal=input()
if goal in dic.keys():
dic[goal]+=1
else:
dic[goal]=1
print(max(dic))
``` | 0 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,612,180,684 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | t = input()
s = input()
if(s=="".join(reversed(t))):
print('YES')
else:
print('NO')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
t = input()
s = input()
if(s=="".join(reversed(t))):
print('YES')
else:
print('NO')
``` | 3.969 |
608 | B | Hamming Distance Sum | PROGRAMMING | 1,500 | [
"combinatorics",
"strings"
] | null | null | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2.
Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only. | Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | [
"01\n00111\n",
"0011\n0110\n"
] | [
"3\n",
"2\n"
] | For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3.
The second sample case is described in the statement. | 1,000 | [
{
"input": "01\n00111",
"output": "3"
},
{
"input": "0011\n0110",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1001101001101110101101000\n01111000010011111111110010001101000100011110101111",
"output": "321"
},
{
"input": "1110010001000101001011111\n00011011000000100001010000010100110011010001111010",
"output": "316"
}
] | 1,651,488,509 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 78,028,800 | x=input()
y=input()
sum=''
i=0
lx=len(x)
while(i+lx<=len(y)):
ans=int(x,2) ^ int(y[i:i+lx],2)
ans=bin(ans)[2:]
sum+=ans
i+=1
out=sum.count("1")
print(out)
| Title: Hamming Distance Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2.
Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
Input Specification:
The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only.
Output Specification:
Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
Demo Input:
['01\n00111\n', '0011\n0110\n']
Demo Output:
['3\n', '2\n']
Note:
For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3.
The second sample case is described in the statement. | ```python
x=input()
y=input()
sum=''
i=0
lx=len(x)
while(i+lx<=len(y)):
ans=int(x,2) ^ int(y[i:i+lx],2)
ans=bin(ans)[2:]
sum+=ans
i+=1
out=sum.count("1")
print(out)
``` | 0 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,614,921,166 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | s=input()
c1=c2=0
for i in range(len(s)):
if s[i].islower():
c1=c1+1
elif s[i].isupper():
c2=c2+1
if c1>c2 or c1==c2:
s=s.lower()
elif c2>c1:
s=s.upper()
print(s)
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
s=input()
c1=c2=0
for i in range(len(s)):
if s[i].islower():
c1=c1+1
elif s[i].isupper():
c2=c2+1
if c1>c2 or c1==c2:
s=s.lower()
elif c2>c1:
s=s.upper()
print(s)
``` | 3.969 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,610,403,747 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 186 | 0 | if __name__ == '__main__':
n = int(input())
ls = list(map(int, input().split()))
evens = []
odds = []
for x in ls:
if x % 2 == 0:
evens.append(x)
else:
odds.append(x)
if len(odds) == 1:
x = odds[0]
else:
x = evens[0]
for i in range(len(ls)):
if ls[i] == x:
print(i+1)
break
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
if __name__ == '__main__':
n = int(input())
ls = list(map(int, input().split()))
evens = []
odds = []
for x in ls:
if x % 2 == 0:
evens.append(x)
else:
odds.append(x)
if len(odds) == 1:
x = odds[0]
else:
x = evens[0]
for i in range(len(ls)):
if ls[i] == x:
print(i+1)
break
``` | 3.9535 |
978 | A | Remove Duplicates | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. | The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. | In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. | [
"6\n1 5 5 1 6 1\n",
"5\n2 4 2 4 4\n",
"5\n6 6 6 6 6\n"
] | [
"3\n5 6 1 \n",
"2\n2 4 \n",
"1\n6 \n"
] | In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | 0 | [
{
"input": "6\n1 5 5 1 6 1",
"output": "3\n5 6 1 "
},
{
"input": "5\n2 4 2 4 4",
"output": "2\n2 4 "
},
{
"input": "5\n6 6 6 6 6",
"output": "1\n6 "
},
{
"input": "7\n1 2 3 4 2 2 3",
"output": "4\n1 4 2 3 "
},
{
"input": "9\n100 100 100 99 99 99 100 100 100",
"output": "2\n99 100 "
},
{
"input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868",
"output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 "
},
{
"input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421",
"output": "8\n117 151 183 227 954 222 909 421 "
},
{
"input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2",
"output": "4\n62 726 903 2 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2",
"output": "6\n5 33 375 37 3 2 "
},
{
"input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6",
"output": "6\n4 3 2 5 1 6 "
},
{
"input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2\n233 1 "
},
{
"input": "47\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1\n1 "
},
{
"input": "2\n964 964",
"output": "1\n964 "
},
{
"input": "2\n1000 1000",
"output": "1\n1000 "
},
{
"input": "1\n1000",
"output": "1\n1000 "
},
{
"input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993",
"output": "10\n996 1000 999 992 997 991 995 998 994 993 "
},
{
"input": "6\n994 993 1000 998 991 994",
"output": "5\n993 1000 998 991 994 "
},
{
"input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999",
"output": "10\n993 996 995 991 994 997 998 992 1000 999 "
},
{
"input": "3\n6 6 3",
"output": "2\n6 3 "
},
{
"input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997",
"output": "9\n1000 995 994 993 999 996 998 991 997 "
},
{
"input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996",
"output": "10\n998 995 999 992 1000 993 994 997 991 996 "
},
{
"input": "2\n1000 999",
"output": "2\n1000 999 "
},
{
"input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000",
"output": "10\n996 999 993 994 997 995 991 992 998 1000 "
},
{
"input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992",
"output": "8\n993 997 998 994 1000 991 995 992 "
},
{
"input": "6\n1000 1 1000 2 1000 1",
"output": "3\n2 1000 1 "
},
{
"input": "6\n1000 1 1000 2 1 1000",
"output": "3\n2 1 1000 "
},
{
"input": "7\n1 1000 1 999 1000 1 2",
"output": "4\n999 1000 1 2 "
}
] | 1,681,739,088 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 93 | 0 | n=int(input())
s=list(map(int,input().split()))[::-1]
g=[]
for i in s:
if i not in g:
g.append(i)
print(len(g))
print(*g[::-1]) | Title: Remove Duplicates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
Output Specification:
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
Demo Input:
['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n']
Demo Output:
['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n']
Note:
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | ```python
n=int(input())
s=list(map(int,input().split()))[::-1]
g=[]
for i in s:
if i not in g:
g.append(i)
print(len(g))
print(*g[::-1])
``` | 3 |
|
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string. | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
},
{
"input": "5\naaaaa",
"output": "aaaaa"
},
{
"input": "3\naabaaaaabb",
"output": "-1"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "2\nbabac",
"output": "-1"
},
{
"input": "3\nbbbccc",
"output": "bcbcbc"
},
{
"input": "2\naa",
"output": "aa"
},
{
"input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece",
"output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece"
},
{
"input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa",
"output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc"
},
{
"input": "1\naaa",
"output": "aaa"
},
{
"input": "1\naabaab",
"output": "aaaabb"
},
{
"input": "2\naabbbbccccccdddddddd",
"output": "abbcccddddabbcccdddd"
},
{
"input": "3\naaaaaaaaacccdddddd",
"output": "aaacddaaacddaaacdd"
},
{
"input": "3\naaaaaaaaacccbbbbbb",
"output": "aaabbcaaabbcaaabbc"
},
{
"input": "2\naazzzz",
"output": "azzazz"
},
{
"input": "2\naaaa",
"output": "aaaa"
},
{
"input": "2\naaaazz",
"output": "aazaaz"
},
{
"input": "2\naaaabb",
"output": "aabaab"
},
{
"input": "2\naabbbb",
"output": "abbabb"
},
{
"input": "2\naaaazzzz",
"output": "aazzaazz"
},
{
"input": "2\naaazz",
"output": "-1"
},
{
"input": "2\nbbbbaa",
"output": "abbabb"
},
{
"input": "2\naaaaaabbbb",
"output": "aaabbaaabb"
},
{
"input": "2\naaaaaazz",
"output": "aaazaaaz"
},
{
"input": "2\naaaabbbb",
"output": "aabbaabb"
},
{
"input": "2\naabaab",
"output": "aabaab"
},
{
"input": "1\naaaaa",
"output": "aaaaa"
},
{
"input": "2\nbbaaaa",
"output": "aabaab"
},
{
"input": "2\nacaccc",
"output": "accacc"
}
] | 1,634,157,994 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 216 | 102,400 | from collections import Counter
def solve():
k=int(input())
s=list(input())
c=Counter(s)
ans=''
for key,v in c.items():
if v%k:
return -1
ans+=(key)*(v//k)
return ans*k
print(solve()) | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
Input Specification:
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Output Specification:
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
Demo Input:
['2\naazz\n', '3\nabcabcabz\n']
Demo Output:
['azaz\n', '-1\n']
Note:
none | ```python
from collections import Counter
def solve():
k=int(input())
s=list(input())
c=Counter(s)
ans=''
for key,v in c.items():
if v%k:
return -1
ans+=(key)*(v//k)
return ans*k
print(solve())
``` | 3 |
|
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not. | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence. | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFFFFSFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "20\nSSFSFSFSFSFSFSFSSFSF",
"output": "YES"
},
{
"input": "20\nSSSSFSFSSFSFSSSSSSFS",
"output": "NO"
},
{
"input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF",
"output": "NO"
},
{
"input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF",
"output": "YES"
},
{
"input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS",
"output": "NO"
},
{
"input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS",
"output": "NO"
},
{
"input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS",
"output": "NO"
},
{
"input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS",
"output": "NO"
},
{
"input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF",
"output": "YES"
},
{
"input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF",
"output": "YES"
},
{
"input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF",
"output": "YES"
},
{
"input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF",
"output": "YES"
},
{
"input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF",
"output": "YES"
},
{
"input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF",
"output": "YES"
},
{
"input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "2\nSS",
"output": "NO"
}
] | 1,666,102,293 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | #867A Between the offices
#SSFFSFFSFF
n=int(input())
s=input()
x=0
y=0
previous=s[0]
for current in s[1:]:
if previous=='S' and current=='F':
x+=1
elif previous=='F' and current=='S':
y+=1
previous=current
if x>y:
print("YES")
else:
print("NO") | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
Input Specification:
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Output Specification:
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['4\nFSSF\n', '2\nSF\n', '10\nFFFFFFFFFF\n', '10\nSSFFSFFSFF\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n', 'YES\n']
Note:
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | ```python
#867A Between the offices
#SSFFSFFSFF
n=int(input())
s=input()
x=0
y=0
previous=s[0]
for current in s[1:]:
if previous=='S' and current=='F':
x+=1
elif previous=='F' and current=='S':
y+=1
previous=current
if x>y:
print("YES")
else:
print("NO")
``` | 3 |
|
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"input": "ABAXXXAB",
"output": "YES"
},
{
"input": "TESTABAXXABTEST",
"output": "YES"
},
{
"input": "A",
"output": "NO"
},
{
"input": "B",
"output": "NO"
},
{
"input": "X",
"output": "NO"
},
{
"input": "BA",
"output": "NO"
},
{
"input": "AB",
"output": "NO"
},
{
"input": "AA",
"output": "NO"
},
{
"input": "BB",
"output": "NO"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "AAB",
"output": "NO"
},
{
"input": "BAA",
"output": "NO"
},
{
"input": "ABB",
"output": "NO"
},
{
"input": "BBA",
"output": "NO"
},
{
"input": "AAA",
"output": "NO"
},
{
"input": "BBB",
"output": "NO"
},
{
"input": "AXBXBXA",
"output": "NO"
},
{
"input": "SKDSKDJABSDBADKFJDK",
"output": "YES"
},
{
"input": "ABAXXBBXXAA",
"output": "NO"
},
{
"input": "ABAB",
"output": "NO"
},
{
"input": "BABA",
"output": "NO"
},
{
"input": "AAAB",
"output": "NO"
},
{
"input": "AAAA",
"output": "NO"
},
{
"input": "AABA",
"output": "NO"
},
{
"input": "ABAA",
"output": "NO"
},
{
"input": "BAAA",
"output": "NO"
},
{
"input": "AABB",
"output": "NO"
},
{
"input": "BAAB",
"output": "YES"
},
{
"input": "BBAA",
"output": "NO"
},
{
"input": "BBBA",
"output": "NO"
},
{
"input": "BBAB",
"output": "NO"
},
{
"input": "BABB",
"output": "NO"
},
{
"input": "ABBB",
"output": "NO"
},
{
"input": "BBBB",
"output": "NO"
},
{
"input": "BABAB",
"output": "YES"
},
{
"input": "ABABA",
"output": "YES"
},
{
"input": "AAABAAACBBBC",
"output": "NO"
},
{
"input": "AABBBACBBBBBBAACBCCACBBAABBBBBCAACABAACABCACCBCBCCCBCBCABCBBCCBCBBAACBACAABACBBCACCBCCACCABBCBABBAAC",
"output": "YES"
},
{
"input": "CBBABDDBBADAC",
"output": "YES"
},
{
"input": "ABYFAB",
"output": "NO"
},
{
"input": "BABXXAB",
"output": "YES"
},
{
"input": "ABAXAB",
"output": "YES"
},
{
"input": "ABABXAB",
"output": "YES"
},
{
"input": "ABXABXABXABXABXBAXBAXBAXBA",
"output": "YES"
},
{
"input": "QQQQQQQQQABABQQQQQQQQ",
"output": "NO"
}
] | 1,697,987,565 | 2,147,483,647 | PyPy 3 | OK | TESTS | 85 | 92 | 614,400 | s = input()
sAB = s.find("AB")
sBA = s.find("BA")
if sAB != -1 and sBA != -1 and abs(sAB - sBA) > 1:
print("YES")
else:
if "AB" in s and "BA" in s[s.index("AB") + 2:]:
print("YES")
exit()
if "BA" in s and "AB" in s[s.index("BA") + 2:]:
print("YES")
exit()
else:
print("NO")
| Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Output Specification:
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
Demo Input:
['ABA\n', 'BACFAB\n', 'AXBYBXA\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | ```python
s = input()
sAB = s.find("AB")
sBA = s.find("BA")
if sAB != -1 and sBA != -1 and abs(sAB - sBA) > 1:
print("YES")
else:
if "AB" in s and "BA" in s[s.index("AB") + 2:]:
print("YES")
exit()
if "BA" in s and "AB" in s[s.index("BA") + 2:]:
print("YES")
exit()
else:
print("NO")
``` | 3 |
|
285 | B | Find Marble | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position *p*1, the glass from the second position to position *p*2 and so on. That is, a glass goes from position *i* to position *p**i*. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position *t*. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position *s* to position *t*. | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaranteed that all *p**i*'s are distinct.
Note that *s* can equal *t*. | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1 5 6 2 9 4 3",
"output": "-1"
},
{
"input": "10 3 6\n5 6 7 3 8 4 2 1 10 9",
"output": "3"
},
{
"input": "10 10 4\n4 2 6 9 5 3 8 1 10 7",
"output": "4"
},
{
"input": "100 90 57\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "-1"
},
{
"input": "100 11 20\n80 25 49 55 22 98 35 59 88 14 91 20 68 66 53 50 77 45 82 63 96 93 85 46 37 74 84 9 7 95 41 86 23 36 33 27 81 39 18 13 12 92 24 71 3 48 83 61 31 87 28 79 75 38 11 21 29 69 44 100 72 62 32 43 30 16 47 56 89 60 42 17 26 70 94 99 4 6 2 73 8 52 65 1 15 90 67 51 78 10 5 76 57 54 34 58 19 64 40 97",
"output": "26"
},
{
"input": "100 84 83\n30 67 53 89 94 54 92 17 26 57 15 5 74 85 10 61 18 70 91 75 14 11 93 41 25 78 88 81 20 51 35 4 62 1 97 39 68 52 47 77 64 3 2 72 60 80 8 83 65 98 21 22 45 7 58 31 43 38 90 99 49 87 55 36 29 6 37 23 66 76 59 79 40 86 63 44 82 32 48 16 50 100 28 96 46 12 27 13 24 9 19 84 73 69 71 42 56 33 34 95",
"output": "71"
},
{
"input": "100 6 93\n74 62 67 81 40 85 35 42 59 72 80 28 79 41 16 19 33 63 13 10 69 76 70 93 49 84 89 94 8 37 11 90 26 52 47 7 36 95 86 75 56 15 61 99 88 12 83 21 20 3 100 17 32 82 6 5 43 25 66 68 73 78 18 77 92 27 23 2 4 39 60 48 22 24 14 97 29 34 54 64 71 57 87 38 9 50 30 53 51 45 44 31 58 91 98 65 55 1 46 96",
"output": "-1"
},
{
"input": "100 27 56\n58 18 50 41 33 37 14 87 77 73 61 53 15 8 70 68 45 96 54 78 39 67 51 60 80 12 93 99 20 92 17 79 4 13 62 91 69 29 49 36 98 34 90 35 84 64 38 83 28 89 97 94 9 16 26 48 10 57 23 75 27 88 44 21 72 76 30 43 32 2 71 24 100 1 31 81 42 40 47 55 86 85 66 5 52 22 95 74 11 19 7 82 6 25 56 63 65 59 46 3",
"output": "20"
},
{
"input": "87 42 49\n45 55 24 44 56 72 74 23 4 7 37 67 22 6 58 76 40 36 3 20 26 87 64 75 49 70 62 42 31 1 80 33 25 59 78 27 32 2 41 61 66 28 19 85 15 69 52 77 50 14 16 34 18 43 73 83 11 39 29 9 35 13 81 54 79 21 60 46 71 57 12 17 5 47 38 30 10 84 53 63 68 8 51 65 48 86 82",
"output": "-1"
},
{
"input": "2 1 2\n1 2",
"output": "-1"
},
{
"input": "2 1 2\n2 1",
"output": "1"
},
{
"input": "2 2 2\n1 2",
"output": "0"
},
{
"input": "2 2 2\n2 1",
"output": "0"
},
{
"input": "2 1 1\n2 1",
"output": "0"
}
] | 1,658,487,139 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 186 | 14,131,200 | import sys
import math
input = sys.stdin.readline
from collections import defaultdict
n, s, t = map(int, input().split())
lst = list(map(int, input().split()))
if s == t:
print(0)
exit()
# for i in range(n):
# if lst[i] == i+1 or lst[lst[i] - 1] == lst[i]:
# print(-1)
# exit()
p = lst[s-1]
count = 1
while t != p:
p = lst[p-1]
count += 1
if count > n:
print(-1)
exit()
print(count) | Title: Find Marble
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position *p*1, the glass from the second position to position *p*2 and so on. That is, a glass goes from position *i* to position *p**i*. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position *t*. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position *s* to position *t*.
Input Specification:
The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaranteed that all *p**i*'s are distinct.
Note that *s* can equal *t*.
Output Specification:
If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1.
Demo Input:
['4 2 1\n2 3 4 1\n', '4 3 3\n4 1 3 2\n', '4 3 4\n1 2 3 4\n', '3 1 3\n2 1 3\n']
Demo Output:
['3\n', '0\n', '-1\n', '-1\n']
Note:
none | ```python
import sys
import math
input = sys.stdin.readline
from collections import defaultdict
n, s, t = map(int, input().split())
lst = list(map(int, input().split()))
if s == t:
print(0)
exit()
# for i in range(n):
# if lst[i] == i+1 or lst[lst[i] - 1] == lst[i]:
# print(-1)
# exit()
p = lst[s-1]
count = 1
while t != p:
p = lst[p-1]
count += 1
if count > n:
print(-1)
exit()
print(count)
``` | 3 |
|
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 3",
"output": "5001"
},
{
"input": "10000 10",
"output": "5000"
},
{
"input": "9999 3",
"output": "5001"
},
{
"input": "9999 2",
"output": "5000"
},
{
"input": "9999 10",
"output": "5000"
},
{
"input": "9999 9",
"output": "5004"
},
{
"input": "18 10",
"output": "10"
},
{
"input": "19 10",
"output": "10"
},
{
"input": "20 10",
"output": "10"
},
{
"input": "21 10",
"output": "20"
},
{
"input": "7688 5",
"output": "3845"
},
{
"input": "4608 5",
"output": "2305"
},
{
"input": "3979 2",
"output": "1990"
},
{
"input": "9985 6",
"output": "4998"
},
{
"input": "3230 8",
"output": "1616"
},
{
"input": "24 9",
"output": "18"
},
{
"input": "3275 8",
"output": "1640"
},
{
"input": "6240 7",
"output": "3122"
},
{
"input": "5227 4",
"output": "2616"
},
{
"input": "3832 6",
"output": "1920"
},
{
"input": "4 2",
"output": "2"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "10 5",
"output": "5"
},
{
"input": "3 2",
"output": "2"
},
{
"input": "6 4",
"output": "4"
},
{
"input": "5 2",
"output": "4"
},
{
"input": "8 2",
"output": "4"
},
{
"input": "9 9",
"output": "9"
},
{
"input": "4 5",
"output": "-1"
}
] | 1,682,145,335 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | stairs, multiple = map(int, input().split())
twos = 0
ones = 0
if stairs < multiple:
print(-1)
if stairs % 2 == 0:
twos = stairs // 2
ones = 0
else:
twos = stairs // 2
ones = 1
# check = True
# if (stairs / multiple)
while twos >= 0:
if (twos + ones) % multiple == 0:
print(twos + ones)
break
else:
twos -= 1
ones += 2
| Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
Input Specification:
The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10).
Output Specification:
Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead.
Demo Input:
['10 2\n', '3 5\n']
Demo Output:
['6\n', '-1\n']
Note:
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | ```python
stairs, multiple = map(int, input().split())
twos = 0
ones = 0
if stairs < multiple:
print(-1)
if stairs % 2 == 0:
twos = stairs // 2
ones = 0
else:
twos = stairs // 2
ones = 1
# check = True
# if (stairs / multiple)
while twos >= 0:
if (twos + ones) % multiple == 0:
print(twos + ones)
break
else:
twos -= 1
ones += 2
``` | 3 |
|
391 | A | Genetic Engineering | PROGRAMMING | 0 | [
"implementation",
"two pointers"
] | null | null | You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein. | The input consists of a single line, containing a string *s* of length *n* (1<=≤<=*n*<=≤<=100). Each character of *s* will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length. | [
"GTTAAAG\n",
"AACCAACCAAAAC\n"
] | [
"1\n",
"5\n"
] | In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein. | 3 | [
{
"input": "GTTAAAG",
"output": "1"
},
{
"input": "AACCAACCAAAAC",
"output": "5"
},
{
"input": "GTGAATTTCC",
"output": "2"
},
{
"input": "CAGGGGGCCGCCCATGAAAAAAACCCGGCCCCTTGGGAAAACTTGGGTTA",
"output": "7"
},
{
"input": "CCCTTCACCCGGATCCAAATCCCTTAGAAATAATCCCCGACGGCGTTGTATCACCTCTGCACTTGTTAGTAAGGTCAGGCGTCCATTACGGAAGAACGTA",
"output": "19"
},
{
"input": "GCATTACATGGGGGGGTCCTACGAGCCCGGCATCCCGGAAACTAGCCGGTTAATTTGGTTTAAACCCTCCCACCCCGGATTGTAACCCCCCTCATTGGTT",
"output": "17"
},
{
"input": "TTCCCAGAGAAAAAAAGGGGCCCAAATGCCCTAAAAACCCCCTTTGCCCCCCAACCCCTTTTTAAAATAAAAAGGGGCCCATTCCCTTAAAAATTTTTTG",
"output": "10"
},
{
"input": "AGCCGCCCCCCCAAAAAAGGGGGAAAAAAAAAAAAAAAAAAAAACTTTTGGAAACCCCCCCCTTTTTTTTTTTTTTTTTTTTTTTTTGGGGAAGGGGGGG",
"output": "7"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "1"
},
{
"input": "AAAAAAAAAAAAAAAAAATTTTTTTTTTTTTTTTGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTGGGGGGGGGGGGGGGGGGGGAAAAATTTT",
"output": "5"
},
{
"input": "AACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTAACCGGTTCCGG",
"output": "50"
},
{
"input": "A",
"output": "0"
},
{
"input": "TTT",
"output": "0"
},
{
"input": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "0"
},
{
"input": "G",
"output": "0"
},
{
"input": "T",
"output": "0"
},
{
"input": "C",
"output": "0"
},
{
"input": "AA",
"output": "1"
},
{
"input": "GGG",
"output": "0"
},
{
"input": "AAG",
"output": "1"
}
] | 1,561,211,370 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | tot=1
ans=0
a=input()
l=len(a)
i=1
while i<l+1:
if a[i]==a[i-1]:
tot+=1
else:
if tot%2==0:
ans+=1
tot=1
i+=1
print(ans) | Title: Genetic Engineering
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You will receive 3 points for solving this problem.
Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.
Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.
Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.
Input Specification:
The input consists of a single line, containing a string *s* of length *n* (1<=≤<=*n*<=≤<=100). Each character of *s* will be from the set {'A', 'T', 'G', 'C'}.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output Specification:
The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.
Demo Input:
['GTTAAAG\n', 'AACCAACCAAAAC\n']
Demo Output:
['1\n', '5\n']
Note:
In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein. | ```python
tot=1
ans=0
a=input()
l=len(a)
i=1
while i<l+1:
if a[i]==a[i-1]:
tot+=1
else:
if tot%2==0:
ans+=1
tot=1
i+=1
print(ans)
``` | -1 |
|
631 | C | Report | PROGRAMMING | 1,700 | [
"data structures",
"sortings"
] | null | null | Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands of *m* managers. Each of them may reorder the elements in some order. Namely, the *i*-th manager either sorts first *r**i* numbers in non-descending or non-ascending order and then passes the report to the manager *i*<=+<=1, or directly to Blake (if this manager has number *i*<==<=*m*).
Employees of the "Blake Technologies" are preparing the report right now. You know the initial sequence *a**i* of length *n* and the description of each manager, that is value *r**i* and his favourite order. You are asked to speed up the process and determine how the final report will look like. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the number of commodities in the report and the number of managers, respectively.
The second line contains *n* integers *a**i* (|*a**i*|<=≤<=109) — the initial report before it gets to the first manager.
Then follow *m* lines with the descriptions of the operations managers are going to perform. The *i*-th of these lines contains two integers *t**i* and *r**i* (, 1<=≤<=*r**i*<=≤<=*n*), meaning that the *i*-th manager sorts the first *r**i* numbers either in the non-descending (if *t**i*<==<=1) or non-ascending (if *t**i*<==<=2) order. | Print *n* integers — the final report, which will be passed to Blake by manager number *m*. | [
"3 1\n1 2 3\n2 2\n",
"4 2\n1 2 4 3\n2 3\n1 2\n"
] | [
"2 1 3 ",
"2 4 1 3 "
] | In the first sample, the initial report looked like: 1 2 3. After the first manager the first two numbers were transposed: 2 1 3. The report got to Blake in this form.
In the second sample the original report was like this: 1 2 4 3. After the first manager the report changed to: 4 2 1 3. After the second manager the report changed to: 2 4 1 3. This report was handed over to Blake. | 1,500 | [
{
"input": "3 1\n1 2 3\n2 2",
"output": "2 1 3 "
},
{
"input": "4 2\n1 2 4 3\n2 3\n1 2",
"output": "2 4 1 3 "
},
{
"input": "4 1\n4 3 2 1\n1 4",
"output": "1 2 3 4 "
},
{
"input": "5 1\n1 2 3 4 5\n2 5",
"output": "5 4 3 2 1 "
},
{
"input": "6 2\n3 1 2 6 4 5\n1 6\n2 3",
"output": "3 2 1 4 5 6 "
},
{
"input": "10 3\n6 4 0 2 -3 7 8 -9 1 5\n1 8\n1 4\n2 2",
"output": "-3 -9 0 2 4 6 7 8 1 5 "
},
{
"input": "100 30\n65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 74 57 115 16 55 88 79 97 21 80 41 56 49 103 61 66 1 36 44 43 82 37 38 106 27 114 51 112 55 87 41 69 31 86 58 27 46 99 18 105 91 38 5 9 2 109 39 2 27 47\n2 38\n2 32\n1 46\n1 37\n1 20\n1 5\n2 42\n2 18\n1 35\n1 36\n2 44\n1 36\n1 20\n2 21\n2 14\n1 13\n2 2\n1 15\n2 50\n2 35\n1 42\n1 21\n1 50\n2 50\n1 1\n2 48\n2 24\n1 34\n1 23\n2 9",
"output": "65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 74 57 115 16 55 88 79 97 21 80 41 56 49 103 61 66 1 36 44 43 82 37 38 106 27 114 51 112 55 87 41 69 31 86 58 27 46 99 18 105 91 38 5 9 2 109 39 2 27 47 "
},
{
"input": "1 1\n1234\n1 1",
"output": "1234 "
},
{
"input": "1 1\n1000000000\n2 1",
"output": "1000000000 "
},
{
"input": "1 2\n-1000000000\n1 1\n2 1",
"output": "-1000000000 "
},
{
"input": "30 13\n15 44 5 56 84 15 24 72 97 3 61 97 36 33 98 49 1 40 76 94 7 46 85 53 79 68 78 54 80 33\n2 18\n1 9\n1 6\n2 30\n2 15\n2 4\n2 17\n2 16\n2 20\n2 16\n2 7\n2 12\n1 20",
"output": "40 44 46 49 53 54 56 61 68 72 76 78 79 80 84 85 94 97 97 98 36 33 33 24 15 15 7 5 3 1 "
}
] | 1,459,433,197 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 23 | 2,000 | 20,992,000 | a, b = (int(i) for i in input().split())
f = list(map(int,input().split()))
d = []
for i in range(b):
c, e = (int(t) for t in input().split())
while len(d) > 0 and e > d[-1][1]:
d.pop()
d.append([c, e])
c, e = 0, d[0][1]
d.append([0, 0])
g = sorted(f[:e])
for i in range(1,len(d)):
for y in range(d[i - 1][1], d[i][1], -1):
if d[i - 1][0] == 1:
f[y - 1] = g[-1]
del g[-1]
else:
f[y - 1] = g[0]
del g[0]
for i in range(len(f)):
print(f[i],end = ' ')
| Title: Report
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are *n* commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands of *m* managers. Each of them may reorder the elements in some order. Namely, the *i*-th manager either sorts first *r**i* numbers in non-descending or non-ascending order and then passes the report to the manager *i*<=+<=1, or directly to Blake (if this manager has number *i*<==<=*m*).
Employees of the "Blake Technologies" are preparing the report right now. You know the initial sequence *a**i* of length *n* and the description of each manager, that is value *r**i* and his favourite order. You are asked to speed up the process and determine how the final report will look like.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the number of commodities in the report and the number of managers, respectively.
The second line contains *n* integers *a**i* (|*a**i*|<=≤<=109) — the initial report before it gets to the first manager.
Then follow *m* lines with the descriptions of the operations managers are going to perform. The *i*-th of these lines contains two integers *t**i* and *r**i* (, 1<=≤<=*r**i*<=≤<=*n*), meaning that the *i*-th manager sorts the first *r**i* numbers either in the non-descending (if *t**i*<==<=1) or non-ascending (if *t**i*<==<=2) order.
Output Specification:
Print *n* integers — the final report, which will be passed to Blake by manager number *m*.
Demo Input:
['3 1\n1 2 3\n2 2\n', '4 2\n1 2 4 3\n2 3\n1 2\n']
Demo Output:
['2 1 3 ', '2 4 1 3 ']
Note:
In the first sample, the initial report looked like: 1 2 3. After the first manager the first two numbers were transposed: 2 1 3. The report got to Blake in this form.
In the second sample the original report was like this: 1 2 4 3. After the first manager the report changed to: 4 2 1 3. After the second manager the report changed to: 2 4 1 3. This report was handed over to Blake. | ```python
a, b = (int(i) for i in input().split())
f = list(map(int,input().split()))
d = []
for i in range(b):
c, e = (int(t) for t in input().split())
while len(d) > 0 and e > d[-1][1]:
d.pop()
d.append([c, e])
c, e = 0, d[0][1]
d.append([0, 0])
g = sorted(f[:e])
for i in range(1,len(d)):
for y in range(d[i - 1][1], d[i][1], -1):
if d[i - 1][0] == 1:
f[y - 1] = g[-1]
del g[-1]
else:
f[y - 1] = g[0]
del g[0]
for i in range(len(f)):
print(f[i],end = ' ')
``` | 0 |
|
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"output": "11 13"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "10",
"output": "3 7"
},
{
"input": "69",
"output": "34 35"
},
{
"input": "100",
"output": "49 51"
},
{
"input": "57",
"output": "28 29"
},
{
"input": "1000",
"output": "499 501"
},
{
"input": "999",
"output": "499 500"
},
{
"input": "998",
"output": "497 501"
},
{
"input": "997",
"output": "498 499"
},
{
"input": "996",
"output": "497 499"
},
{
"input": "995",
"output": "497 498"
},
{
"input": "994",
"output": "495 499"
},
{
"input": "5",
"output": "2 3"
},
{
"input": "6",
"output": "1 5"
},
{
"input": "8",
"output": "3 5"
},
{
"input": "9",
"output": "4 5"
},
{
"input": "423",
"output": "211 212"
},
{
"input": "876",
"output": "437 439"
},
{
"input": "29",
"output": "14 15"
}
] | 1,544,249,143 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | n = int(input())
m = 0
l = []
d = []
for i in range(1, n):
for j in range(1, n):
x = 0
if i + j == n and i < j and i / j > m:
for a in range(2, i//2+1):
if i % a == 0:
d.append(a)
for a in d:
if j % a == 0:
x = 1
if x == 1:
continue
else:
m = i / j
l = [i, j]
print(*l) | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
Input Specification:
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output Specification:
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
Demo Input:
['3\n', '4\n', '12\n']
Demo Output:
['1 2\n', '1 3\n', '5 7\n']
Note:
none | ```python
n = int(input())
m = 0
l = []
d = []
for i in range(1, n):
for j in range(1, n):
x = 0
if i + j == n and i < j and i / j > m:
for a in range(2, i//2+1):
if i % a == 0:
d.append(a)
for a in d:
if j % a == 0:
x = 1
if x == 1:
continue
else:
m = i / j
l = [i, j]
print(*l)
``` | 0 |
|
757 | A | Gotta Catch Em' All! | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different. | Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. . | Output a single integer, the answer to the problem. | [
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | 500 | [
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr",
"output": "0"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr",
"output": "10"
},
{
"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "20"
},
{
"input": "CeSlSwec",
"output": "0"
},
{
"input": "PnMrWPBGzVcmRcO",
"output": "0"
},
{
"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM",
"output": "0"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC",
"output": "6"
},
{
"input": "bulsar",
"output": "0"
},
{
"input": "Bblsar",
"output": "0"
},
{
"input": "Bbusar",
"output": "0"
},
{
"input": "Bbular",
"output": "0"
},
{
"input": "Bbulsr",
"output": "0"
},
{
"input": "Bbulsa",
"output": "0"
},
{
"input": "Bbulsar",
"output": "0"
},
{
"input": "Bbulsar",
"output": "0"
},
{
"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh",
"output": "2"
},
{
"input": "Bulbasaur",
"output": "1"
},
{
"input": "BulbasaurBulbasaur",
"output": "2"
},
{
"input": "Bulbbasar",
"output": "0"
},
{
"input": "Bulbasur",
"output": "0"
},
{
"input": "Bulbsaur",
"output": "0"
},
{
"input": "BulbsurBulbsurBulbsurBulbsur",
"output": "0"
},
{
"input": "Blbbasar",
"output": "0"
},
{
"input": "Bulbasar",
"output": "0"
},
{
"input": "BBullllbbaassaauurr",
"output": "1"
},
{
"input": "BulbasaurBulbasar",
"output": "1"
},
{
"input": "BulbasaurBulbsaur",
"output": "1"
},
{
"input": "Bubasaur",
"output": "0"
},
{
"input": "ulbasaurulbasaur",
"output": "0"
},
{
"input": "Bulbasr",
"output": "0"
},
{
"input": "BBBuuulllbbbaaasssaaauuurrr",
"output": "3"
},
{
"input": "BBuuuullbbaaaassrr",
"output": "2"
},
{
"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr",
"output": "4"
},
{
"input": "BBuullbbaassaarr",
"output": "1"
},
{
"input": "Bulbasau",
"output": "0"
},
{
"input": "BBuullbbaassaauurr",
"output": "2"
},
{
"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau",
"output": "0"
},
{
"input": "Blbasaur",
"output": "0"
},
{
"input": "BulbasaurBulbasaurd",
"output": "2"
},
{
"input": "ulbasaur",
"output": "0"
},
{
"input": "Bulbaaur",
"output": "0"
},
{
"input": "BBuuuullbbbbbbbbbbbbbbbaassrr",
"output": "1"
},
{
"input": "Bulbasua",
"output": "0"
},
{
"input": "Bubbasaur",
"output": "0"
},
{
"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr",
"output": "3"
},
{
"input": "BulbasaurBubasaur",
"output": "1"
},
{
"input": "Baab",
"output": "0"
},
{
"input": "BulbasaurBulbasau",
"output": "1"
},
{
"input": "Bulbasauu",
"output": "0"
},
{
"input": "BulbasauBulbasau",
"output": "0"
},
{
"input": "BBBBBBBBBBB",
"output": "0"
},
{
"input": "Bulbbasau",
"output": "0"
},
{
"input": "BulbbasaurBulbbasar",
"output": "1"
},
{
"input": "Bulaaaasaur",
"output": "0"
},
{
"input": "BulbasaurBulbasauBulbasauBulbasau",
"output": "1"
}
] | 1,484,340,511 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 4,812,800 | x=input()
s=x
w=0
d=set('Bulbasaur')
for i in range(len(s)):
if 'B' in s and 'u' in s and 'l' in s and 'b' in s and 'a' in s and 's' in s and 'a' in s and 'u' in s and 'r' in s:
w+=1
s=s.replace('B','',1)
s=s.replace('u','',1)
s=s.replace('l','',1)
s=s.replace('b','',1)
s=s.replace('a','',1)
s=s.replace('s','',1)
s=s.replace('a','',1)
s=s.replace('u','',1)
s=s.replace('r','',1)
print(w)
| Title: Gotta Catch Em' All!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
Input Specification:
Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. .
Output Specification:
Output a single integer, the answer to the problem.
Demo Input:
['Bulbbasaur\n', 'F\n', 'aBddulbasaurrgndgbualdBdsagaurrgndbb\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | ```python
x=input()
s=x
w=0
d=set('Bulbasaur')
for i in range(len(s)):
if 'B' in s and 'u' in s and 'l' in s and 'b' in s and 'a' in s and 's' in s and 'a' in s and 'u' in s and 'r' in s:
w+=1
s=s.replace('B','',1)
s=s.replace('u','',1)
s=s.replace('l','',1)
s=s.replace('b','',1)
s=s.replace('a','',1)
s=s.replace('s','',1)
s=s.replace('a','',1)
s=s.replace('u','',1)
s=s.replace('r','',1)
print(w)
``` | 0 |
|
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George. | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98",
"output": "24"
}
] | 1,578,445,596 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 93 | 307,200 | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]*(3000 + 1)
count = 0
dif = m - n
for i in b:
c[i] += 1
for i in a:
if c[i] == 0:
count += 1
if dif >= 0 and count == 0:
print(0)
else:
if abs(dif) > count:
print(dif)
else:
print(count)
| Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3 5\n1 2 3\n1 2 2 3 3\n', '3 5\n1 2 3\n1 1 1 1 1\n', '3 1\n2 3 4\n1\n']
Demo Output:
['0\n', '2\n', '3\n']
Note:
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0]*(3000 + 1)
count = 0
dif = m - n
for i in b:
c[i] += 1
for i in a:
if c[i] == 0:
count += 1
if dif >= 0 and count == 0:
print(0)
else:
if abs(dif) > count:
print(dif)
else:
print(count)
``` | -1 |
|
834 | B | The Festive Evening | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.
There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.
For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.
Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened. | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.
In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door. | 1,000 | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
},
{
"input": "6 2\nABCABC",
"output": "YES"
},
{
"input": "8 3\nABCBCDCA",
"output": "NO"
},
{
"input": "73 2\nDEBECECBBADAADEAABEAEEEAEBEAEBCDDBABBAEBACCBEEBBAEADEECACEDEEDABACDCDBBBD",
"output": "YES"
},
{
"input": "44 15\nHGJIFCGGCDGIJDHBIBGAEABCIABIGBDEADBBBAGDFDHA",
"output": "NO"
},
{
"input": "41 19\nTMEYYIIELFDCMBDKWWKYNRNDUPRONYROXQCLVQALP",
"output": "NO"
},
{
"input": "377 3\nEADADBBBBDEAABBAEBABACDBDBBCACAADBEAEACDEAABACADEEDEACACDADABBBBDDEECBDABACACBAECBADAEBDEEBDBCDAEADBCDDACACDCCEEDBCCBBCEDBECBABCDDBBDEADEDAEACDECECBEBACBCCDCDBDAECDECADBCBEDBBDAAEBCAAECCDCCDBDDEBADEEBDCAEABBDEDBBDDEAECCBDDCDEACDAECCBDDABABEAEDCDEDBAECBDEACEBCECEACDCBABCBAAEAADACADBBBBABEADBCADEBCBECCABBDDDEEBCDEBADEBDAAABBEABADEDEAEABCEEBEEDEAEBEABCEDDBACBCCADEBAAAAAEABABBCE",
"output": "YES"
},
{
"input": "433 3\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVITKNFLVCPMZSDMCHBTVAWYVZLIXXIADXNYILEYNIQHKMOGMVOCWGHCWIYMPEPADSJAAKEGTUSEDWAHMNYJDIHBKHVUHLYGNGZDBULRXLSAJHPCMNWCEAAPYMHDTYWPADOTJTXTXUKLCHWKUSZRHEKQEFPVJEJJHRWCKYOIWALRTIBUMNOCRXLSIKQCJVQXEPGOHRUDJDKMUUUDORURWXJNVRVMNOUNRFKSVMTMZGOIJLXEPAMVGESOADYIGZXRBJDIWKNOWTCSROAQTBECHTOZVSQUOOJRZIBAUHMKAXDCIMDZJFMABGRNTGPUJAUNFPFWCJG",
"output": "YES"
},
{
"input": "5 2\nABCAB",
"output": "YES"
},
{
"input": "5 1\nAZAZA",
"output": "YES"
},
{
"input": "7 2\nABCDBCD",
"output": "YES"
},
{
"input": "3 26\nAAB",
"output": "NO"
}
] | 1,501,431,316 | 6,016 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 31 | 4,608,000 | n,k=map(int,input().split())
s=input()
gate=[False]*26
count=[0]*26
for i in range(n):
index=ord(s[i])-65
count[index]+=1
guard=0
exc=False
print(count)
for i in range(n):
index=ord(s[i])-65
if gate[index]:
count[index]-=1
if count[index]==0:
guard=guard-1
else:
count[index]-=1
gate[index]=True
guard=guard+1
if guard>k:
exc=True
break
if count[index]==0:
guard=guard-1
last=s[i]
print(s[i])
print(count)
print(gate)
if exc:
print("YES")
else :
print("NO") | Title: The Festive Evening
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.
There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.
For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.
Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened.
Input Specification:
Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest.
Output Specification:
Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower).
Demo Input:
['5 1\nAABBB\n', '5 1\nABABB\n']
Demo Output:
['NO\n', 'YES\n']
Note:
In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.
In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door. | ```python
n,k=map(int,input().split())
s=input()
gate=[False]*26
count=[0]*26
for i in range(n):
index=ord(s[i])-65
count[index]+=1
guard=0
exc=False
print(count)
for i in range(n):
index=ord(s[i])-65
if gate[index]:
count[index]-=1
if count[index]==0:
guard=guard-1
else:
count[index]-=1
gate[index]=True
guard=guard+1
if guard>k:
exc=True
break
if count[index]==0:
guard=guard-1
last=s[i]
print(s[i])
print(count)
print(gate)
if exc:
print("YES")
else :
print("NO")
``` | 0 |
|
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,688,627,273 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 60 | 0 | input=int(input())
if input%2==0:
print("YES")
elif input==0:
print("NO")
else:
print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input Specification:
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Output Specification:
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Demo Input:
['8\n']
Demo Output:
['YES\n']
Note:
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | ```python
input=int(input())
if input%2==0:
print("YES")
elif input==0:
print("NO")
else:
print("NO")
``` | 0 |
898 | C | Phone Numbers | PROGRAMMING | 1,400 | [
"implementation",
"strings"
] | null | null | Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record.
Vasya also believes that if the phone number *a* is a suffix of the phone number *b* (that is, the number *b* ends up with *a*), and both numbers are written by Vasya as the phone numbers of the same person, then *a* is recorded without the city code and it should not be taken into account.
The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers *x* and *y*, and *x* is a suffix of *y* (that is, *y* ends in *x*), then you shouldn't print number *x*. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once.
Read the examples to understand statement and format of the output better. | First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books.
The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros. | Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books.
The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend.
Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order. | [
"2\nivan 1 00123\nmasha 1 00123\n",
"3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n",
"4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n"
] | [
"2\nmasha 1 00123 \nivan 1 00123 \n",
"3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n",
"2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n"
] | none | 1,500 | [
{
"input": "2\nivan 1 00123\nmasha 1 00123",
"output": "2\nmasha 1 00123 \nivan 1 00123 "
},
{
"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612",
"output": "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 "
},
{
"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789",
"output": "2\ndasha 2 789 23 \nivan 4 2 123 456 789 "
},
{
"input": "20\nnxj 6 7 6 6 7 7 7\nnxj 10 8 5 1 7 6 1 0 7 0 6\nnxj 2 6 5\nnxj 10 6 7 6 6 5 8 3 6 6 8\nnxj 10 6 1 7 6 7 1 8 7 8 6\nnxj 10 8 5 8 6 5 6 1 9 6 3\nnxj 10 8 1 6 4 8 0 4 6 0 1\nnxj 9 2 6 6 8 1 1 3 6 6\nnxj 10 8 9 0 9 1 3 2 3 2 3\nnxj 6 6 7 0 8 1 2\nnxj 7 7 7 8 1 3 6 9\nnxj 10 2 7 0 1 5 1 9 1 2 6\nnxj 6 9 6 9 6 3 7\nnxj 9 0 1 7 8 2 6 6 5 6\nnxj 4 0 2 3 7\nnxj 10 0 4 0 6 1 1 8 8 4 7\nnxj 8 4 6 2 6 6 1 2 7\nnxj 10 5 3 4 2 1 0 7 0 7 6\nnxj 10 9 6 0 6 1 6 2 1 9 6\nnxj 4 2 9 0 1",
"output": "1\nnxj 10 4 1 8 7 5 3 6 9 0 2 "
},
{
"input": "20\nl 6 02 02 2 02 02 2\nl 8 8 8 8 2 62 13 31 3\ne 9 0 91 0 0 60 91 60 2 44\ne 9 69 2 1 44 2 91 66 1 70\nl 9 7 27 27 3 1 3 7 80 81\nl 9 2 1 13 7 2 10 02 3 92\ne 9 0 15 3 5 5 15 91 09 44\nl 7 2 50 4 5 98 31 98\nl 3 26 7 3\ne 6 7 5 0 62 65 91\nl 8 80 0 4 0 2 2 0 13\nl 9 19 13 02 2 1 4 19 26 02\nl 10 7 39 7 9 22 22 26 2 90 4\ne 7 65 2 36 0 34 57 9\ne 8 13 02 09 91 73 5 36 62\nl 9 75 0 10 8 76 7 82 8 34\nl 7 34 0 19 80 6 4 7\ne 5 4 2 5 7 2\ne 7 4 02 69 7 07 20 2\nl 4 8 2 1 63",
"output": "2\ne 18 70 07 62 36 20 69 66 57 02 65 34 44 73 60 91 15 09 13 \nl 21 02 80 27 63 19 50 81 76 34 90 98 92 31 26 22 75 39 13 10 82 62 "
},
{
"input": "20\no 10 6 6 97 45 6 6 6 6 5 6\nl 8 5 5 5 19 59 5 8 5\nj 9 2 30 58 2 2 1 0 30 4\nc 10 1 1 7 51 7 7 51 1 1 1\no 9 7 97 87 70 2 19 2 14 6\ne 6 26 6 6 6 26 5\ng 9 3 3 3 3 3 78 69 8 9\nl 8 8 01 1 5 8 41 72 3\nz 10 1 2 2 2 9 1 9 1 6 7\ng 8 7 78 05 36 7 3 67 9\no 5 6 9 9 7 7\ne 10 30 2 1 1 2 5 04 0 6 6\ne 9 30 30 2 2 0 26 30 79 8\nt 10 2 2 9 29 7 7 7 9 2 9\nc 7 7 51 1 31 2 7 4\nc 9 83 1 6 78 94 74 54 8 32\ng 8 4 1 01 9 39 28 6 6\nt 7 9 2 01 4 4 9 58\nj 5 0 1 58 02 4\nw 10 80 0 91 91 06 91 9 9 27 7",
"output": "9\nw 5 91 06 27 9 80 \nt 6 01 29 4 58 2 7 \ne 8 2 8 30 04 26 5 79 1 \nl 8 8 41 72 01 19 59 3 5 \nj 5 58 02 1 4 30 \nz 5 7 9 6 2 1 \ng 10 39 67 3 01 36 4 05 69 78 28 \no 8 19 2 45 6 87 14 97 70 \nc 10 7 94 32 6 78 74 31 83 51 54 "
},
{
"input": "1\negew 5 3 123 23 1234 134",
"output": "1\negew 3 134 123 1234 "
}
] | 1,666,451,508 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 59 | 62 | 0 | """ Prositka
10.10.2022"""
n=int(input())
d=dict()
for i in range(n):
a=input().split()
if a[0] not in d:
d[a[0]]=[]
for j in range(2, len(a)):
a[j]=a[j][::-1]
d[a[0]]+=a[2:]
print(len(d))
for x in d:
a=d[x]
a.sort(reverse=True)
b=[a[0]]
for i in range(1, len(a)):
if a[i-1][:len(a[i])]!=a[i]:
b+=[a[i]]
for i in range(len(b)):
b[i]=b[i][::-1]
print(x,len(b),*b) | Title: Phone Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record.
Vasya also believes that if the phone number *a* is a suffix of the phone number *b* (that is, the number *b* ends up with *a*), and both numbers are written by Vasya as the phone numbers of the same person, then *a* is recorded without the city code and it should not be taken into account.
The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers *x* and *y*, and *x* is a suffix of *y* (that is, *y* ends in *x*), then you shouldn't print number *x*. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once.
Read the examples to understand statement and format of the output better.
Input Specification:
First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books.
The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros.
Output Specification:
Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books.
The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend.
Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order.
Demo Input:
['2\nivan 1 00123\nmasha 1 00123\n', '3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n', '4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n']
Demo Output:
['2\nmasha 1 00123 \nivan 1 00123 \n', '3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n', '2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n']
Note:
none | ```python
""" Prositka
10.10.2022"""
n=int(input())
d=dict()
for i in range(n):
a=input().split()
if a[0] not in d:
d[a[0]]=[]
for j in range(2, len(a)):
a[j]=a[j][::-1]
d[a[0]]+=a[2:]
print(len(d))
for x in d:
a=d[x]
a.sort(reverse=True)
b=[a[0]]
for i in range(1, len(a)):
if a[i-1][:len(a[i])]!=a[i]:
b+=[a[i]]
for i in range(len(b)):
b[i]=b[i][::-1]
print(x,len(b),*b)
``` | 3 |
|
851 | A | Arpa and a research in Mexican wave | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Arpa is researching the Mexican wave.
There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0.
- At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits.
Arpa wants to know how many spectators are standing at time *t*. | The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=<<=*n*<=+<=*k*). | Print single integer: how many spectators are standing at time *t*. | [
"10 5 3\n",
"10 5 7\n",
"10 5 12\n"
] | [
"3\n",
"5\n",
"3\n"
] | In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
- At *t* = 0 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. - At *t* = 1 ^--------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 2 ^^-------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 3 ^^^------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 4 ^^^^------ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 5 ^^^^^----- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 6 -^^^^^---- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 7 --^^^^^--- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 8 ---^^^^^-- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 9 ----^^^^^- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 10 -----^^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 11 ------^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 12 -------^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 13 --------^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 14 ---------^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 15 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. | 500 | [
{
"input": "10 5 3",
"output": "3"
},
{
"input": "10 5 7",
"output": "5"
},
{
"input": "10 5 12",
"output": "3"
},
{
"input": "840585600 770678331 788528791",
"output": "770678331"
},
{
"input": "25462281 23343504 8024619",
"output": "8024619"
},
{
"input": "723717988 205757169 291917494",
"output": "205757169"
},
{
"input": "27462087 20831796 15492397",
"output": "15492397"
},
{
"input": "966696824 346707476 1196846860",
"output": "116557440"
},
{
"input": "290274403 41153108 327683325",
"output": "3744186"
},
{
"input": "170963478 151220598 222269210",
"output": "99914866"
},
{
"input": "14264008 309456 11132789",
"output": "309456"
},
{
"input": "886869816 281212106 52891064",
"output": "52891064"
},
{
"input": "330543750 243917820 205522400",
"output": "205522400"
},
{
"input": "457658451 18625039 157624558",
"output": "18625039"
},
{
"input": "385908940 143313325 509731380",
"output": "19490885"
},
{
"input": "241227633 220621961 10025257",
"output": "10025257"
},
{
"input": "474139818 268918981 388282504",
"output": "268918981"
},
{
"input": "25963410 3071034 820199",
"output": "820199"
},
{
"input": "656346757 647995766 75748423",
"output": "75748423"
},
{
"input": "588568132 411878522 521753621",
"output": "411878522"
},
{
"input": "735788762 355228487 139602545",
"output": "139602545"
},
{
"input": "860798593 463398487 506871376",
"output": "463398487"
},
{
"input": "362624055 110824996 194551217",
"output": "110824996"
},
{
"input": "211691721 195866131 313244576",
"output": "94313276"
},
{
"input": "45661815 26072719 9643822",
"output": "9643822"
},
{
"input": "757183104 590795077 709609355",
"output": "590795077"
},
{
"input": "418386749 1915035 197248338",
"output": "1915035"
},
{
"input": "763782282 297277890 246562421",
"output": "246562421"
},
{
"input": "893323188 617630677 607049638",
"output": "607049638"
},
{
"input": "506708261 356545583 296093684",
"output": "296093684"
},
{
"input": "984295813 427551190 84113823",
"output": "84113823"
},
{
"input": "774984967 61373612 96603505",
"output": "61373612"
},
{
"input": "774578969 342441237 91492393",
"output": "91492393"
},
{
"input": "76495801 8780305 56447339",
"output": "8780305"
},
{
"input": "48538385 582843 16805978",
"output": "582843"
},
{
"input": "325794610 238970909 553089099",
"output": "11676420"
},
{
"input": "834925315 316928679 711068031",
"output": "316928679"
},
{
"input": "932182199 454838315 267066713",
"output": "267066713"
},
{
"input": "627793782 552043394 67061810",
"output": "67061810"
},
{
"input": "24317170 17881607 218412",
"output": "218412"
},
{
"input": "1000000000 1000 1",
"output": "1"
},
{
"input": "1000000000 1000 2",
"output": "2"
},
{
"input": "1000000000 1 1000",
"output": "1"
},
{
"input": "100 100 100",
"output": "100"
},
{
"input": "100 100 99",
"output": "99"
},
{
"input": "100 100 101",
"output": "99"
},
{
"input": "100 100 199",
"output": "1"
},
{
"input": "1000000000 1000000000 1999999999",
"output": "1"
},
{
"input": "10 5 5",
"output": "5"
},
{
"input": "5 3 5",
"output": "3"
},
{
"input": "10 3 3",
"output": "3"
},
{
"input": "10 5 6",
"output": "5"
},
{
"input": "3 2 4",
"output": "1"
},
{
"input": "10 5 14",
"output": "1"
},
{
"input": "6 1 4",
"output": "1"
},
{
"input": "10 10 19",
"output": "1"
},
{
"input": "10 4 11",
"output": "3"
},
{
"input": "2 2 3",
"output": "1"
},
{
"input": "10 5 11",
"output": "4"
},
{
"input": "600 200 700",
"output": "100"
},
{
"input": "2000 1000 2001",
"output": "999"
},
{
"input": "1000 1000 1001",
"output": "999"
},
{
"input": "5 4 6",
"output": "3"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "10 3 10",
"output": "3"
},
{
"input": "15 10 10",
"output": "10"
},
{
"input": "10 5 13",
"output": "2"
},
{
"input": "2 2 2",
"output": "2"
},
{
"input": "5 5 6",
"output": "4"
},
{
"input": "10 6 12",
"output": "4"
},
{
"input": "7 5 8",
"output": "4"
},
{
"input": "10 4 9",
"output": "4"
},
{
"input": "9 2 6",
"output": "2"
},
{
"input": "5 2 6",
"output": "1"
},
{
"input": "6 2 6",
"output": "2"
},
{
"input": "5 5 8",
"output": "2"
},
{
"input": "3 3 5",
"output": "1"
},
{
"input": "10 2 5",
"output": "2"
},
{
"input": "5 3 7",
"output": "1"
},
{
"input": "5 4 8",
"output": "1"
},
{
"input": "10 6 11",
"output": "5"
},
{
"input": "5 3 6",
"output": "2"
},
{
"input": "10 6 14",
"output": "2"
},
{
"input": "10 10 10",
"output": "10"
},
{
"input": "1000000000 1 1000000000",
"output": "1"
},
{
"input": "20 4 22",
"output": "2"
},
{
"input": "5 4 4",
"output": "4"
},
{
"input": "4 3 6",
"output": "1"
},
{
"input": "12 8 18",
"output": "2"
},
{
"input": "10 5 10",
"output": "5"
},
{
"input": "100 50 149",
"output": "1"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "7 6 9",
"output": "4"
},
{
"input": "16 10 21",
"output": "5"
},
{
"input": "10 2 11",
"output": "1"
},
{
"input": "600 200 500",
"output": "200"
},
{
"input": "100 30 102",
"output": "28"
},
{
"input": "10 10 18",
"output": "2"
},
{
"input": "15 3 10",
"output": "3"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "5 5 5",
"output": "5"
},
{
"input": "10 3 12",
"output": "1"
},
{
"input": "747 457 789",
"output": "415"
},
{
"input": "5 4 7",
"output": "2"
},
{
"input": "15 5 11",
"output": "5"
},
{
"input": "3 2 2",
"output": "2"
},
{
"input": "7 6 8",
"output": "5"
},
{
"input": "7 4 8",
"output": "3"
},
{
"input": "10 4 13",
"output": "1"
},
{
"input": "10 3 9",
"output": "3"
},
{
"input": "20 2 21",
"output": "1"
},
{
"input": "6 5 9",
"output": "2"
},
{
"input": "10 9 18",
"output": "1"
},
{
"input": "12 4 9",
"output": "4"
},
{
"input": "10 7 15",
"output": "2"
},
{
"input": "999999999 999999998 1500000000",
"output": "499999997"
},
{
"input": "20 5 20",
"output": "5"
},
{
"input": "4745 4574 4757",
"output": "4562"
},
{
"input": "10 7 12",
"output": "5"
},
{
"input": "17 15 18",
"output": "14"
},
{
"input": "3 1 3",
"output": "1"
},
{
"input": "100 3 7",
"output": "3"
},
{
"input": "6 2 7",
"output": "1"
},
{
"input": "8 5 10",
"output": "3"
},
{
"input": "3 3 3",
"output": "3"
},
{
"input": "9 5 10",
"output": "4"
},
{
"input": "10 6 13",
"output": "3"
},
{
"input": "13 10 14",
"output": "9"
},
{
"input": "13 12 15",
"output": "10"
},
{
"input": "10 4 12",
"output": "2"
},
{
"input": "41 3 3",
"output": "3"
},
{
"input": "1000000000 1000000000 1400000000",
"output": "600000000"
},
{
"input": "10 3 11",
"output": "2"
},
{
"input": "12 7 18",
"output": "1"
},
{
"input": "15 3 17",
"output": "1"
},
{
"input": "10 2 8",
"output": "2"
},
{
"input": "1000000000 1000 1000000999",
"output": "1"
},
{
"input": "5 5 9",
"output": "1"
},
{
"input": "100 3 6",
"output": "3"
},
{
"input": "100 5 50",
"output": "5"
},
{
"input": "10000 10 10000",
"output": "10"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "6 4 4",
"output": "4"
},
{
"input": "9979797 555554 10101010",
"output": "434341"
},
{
"input": "13 5 12",
"output": "5"
},
{
"input": "9 4 10",
"output": "3"
},
{
"input": "7 5 10",
"output": "2"
},
{
"input": "100000000 10000000 100005000",
"output": "9995000"
},
{
"input": "100000 50000 100001",
"output": "49999"
},
{
"input": "15 10 20",
"output": "5"
},
{
"input": "4 4 5",
"output": "3"
},
{
"input": "5 3 3",
"output": "3"
},
{
"input": "30 5 30",
"output": "5"
},
{
"input": "200000 10 200005",
"output": "5"
},
{
"input": "10 9 12",
"output": "7"
},
{
"input": "10 6 15",
"output": "1"
},
{
"input": "1000000000 10 1000000000",
"output": "10"
},
{
"input": "7 5 11",
"output": "1"
},
{
"input": "9 4 4",
"output": "4"
},
{
"input": "14 3 15",
"output": "2"
},
{
"input": "1000000000 100000000 1000000000",
"output": "100000000"
},
{
"input": "40 10 22",
"output": "10"
},
{
"input": "50 10 51",
"output": "9"
},
{
"input": "999999997 999999995 1999999991",
"output": "1"
},
{
"input": "92 79 144",
"output": "27"
},
{
"input": "8 4 4",
"output": "4"
}
] | 1,504,536,077 | 377 | Python 3 | OK | TESTS | 166 | 78 | 0 | n,t,k = map(int,input().split())
if(t>k):
print(k)
elif(k>n):
print(t-(k-n))
else:
print(t) | Title: Arpa and a research in Mexican wave
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is researching the Mexican wave.
There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0.
- At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits.
Arpa wants to know how many spectators are standing at time *t*.
Input Specification:
The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=<<=*n*<=+<=*k*).
Output Specification:
Print single integer: how many spectators are standing at time *t*.
Demo Input:
['10 5 3\n', '10 5 7\n', '10 5 12\n']
Demo Output:
['3\n', '5\n', '3\n']
Note:
In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
- At *t* = 0 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. - At *t* = 1 ^--------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 2 ^^-------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 3 ^^^------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 4 ^^^^------ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 5 ^^^^^----- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 6 -^^^^^---- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 7 --^^^^^--- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 8 ---^^^^^-- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 9 ----^^^^^- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 10 -----^^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 11 ------^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 12 -------^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 13 --------^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 14 ---------^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 15 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. | ```python
n,t,k = map(int,input().split())
if(t>k):
print(k)
elif(k>n):
print(t-(k-n))
else:
print(t)
``` | 3 |
|
20 | B | Equation | PROGRAMMING | 2,000 | [
"math"
] | B. Equation | 1 | 256 | You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order. | The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0. | In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point. | [
"1 -5 6\n"
] | [
"2\n2.0000000000\n3.0000000000"
] | none | 1,000 | [
{
"input": "1 -5 6",
"output": "2\n2.0000000000\n3.0000000000"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "1\n-1.0000000000"
},
{
"input": "0 0 0",
"output": "-1"
},
{
"input": "0 -2 1",
"output": "1\n0.5000000000"
},
{
"input": "0 -2 0",
"output": "1\n0.0000000000"
},
{
"input": "0 0 1",
"output": "0"
},
{
"input": "0 0 -100000",
"output": "0"
},
{
"input": "0 10000 -100000",
"output": "1\n10.0000000000"
},
{
"input": "1 100000 -100000",
"output": "2\n-100000.9999900002\n0.9999900002"
},
{
"input": "0 3431 43123",
"output": "1\n-12.5686388808"
},
{
"input": "100 200 100",
"output": "1\n-1.0000000000"
},
{
"input": "50000 100000 50000",
"output": "1\n-1.0000000000"
},
{
"input": "-1 10 20",
"output": "2\n-1.7082039325\n11.7082039325"
},
{
"input": "-50000 100000 -50000",
"output": "1\n1.0000000000"
},
{
"input": "1 -2 1",
"output": "1\n1.0000000000"
},
{
"input": "1000 -5000 6000",
"output": "2\n2.0000000000\n3.0000000000"
},
{
"input": "0 -100000 0",
"output": "1\n0.0000000000"
},
{
"input": "1 -100000 0",
"output": "2\n0.0000000000\n100000.0000000000"
},
{
"input": "1223 -23532 1232",
"output": "2\n0.0524974745\n19.1887126645"
},
{
"input": "-1 -2 -1",
"output": "1\n-1.0000000000"
},
{
"input": "1 0 0",
"output": "1\n0.0000000000"
},
{
"input": "0 1 0",
"output": "1\n-0.0000000000"
},
{
"input": "0 0 1",
"output": "0"
},
{
"input": "0 1 -1",
"output": "1\n1.0000000000"
},
{
"input": "5 0 5",
"output": "0"
},
{
"input": "-2 -5 0",
"output": "2\n-2.5000000000\n-0.0000000000"
},
{
"input": "-2 -4 0",
"output": "2\n-2.0000000000\n-0.0000000000"
},
{
"input": "-2 0 0",
"output": "1\n-0.0000000000"
},
{
"input": "0 -4 -4",
"output": "1\n-1.0000000000"
},
{
"input": "1 1 0",
"output": "2\n-1.0000000000\n0.0000000000"
},
{
"input": "1 0 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "0 0 0",
"output": "-1"
}
] | 1,666,677,856 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | import random as r
######.....FUNCTION TO RETURN WARMER OR COLDER.....######
import sys
import time
counter=1
def find(z,n):
global counter
global Prev_diff
counter+=1
if n==z: return 'BINGO'
elif abs(z-n)>=abs(Prev_diff):
Prev_diff=abs(z - n)
Prev_diff=Prev_diff
return 'COLD'
elif abs(z-n)<abs(Prev_diff):
Prev_diff=abs(z - n)
Prev_diff=Prev_diff
return 'WARM'
######.....FUNCTION TO GUESS NUMBER.....######
n=1000000
guessnumber=5000
Min=0
Max=n
previous1=0
previous2=0
current=(Min+Max)//2
print(current)
print('First')
if guessnumber==current:
print("Bingo")
sys.exit()
Prev_diff=abs(guessnumber-current)
while True:
#time.sleep(.001)
previous2=previous1
previous1=current
current=(current+Max)//2
y=find(guessnumber,current)
if y=='BINGO':
print("current", current)
print("Number of steps",counter)
print('BINGO')
break
if current==Max or current==Min:
previous2=previous1
privious1=current
current=(Min+Max)//2
############# added
y = find(guessnumber, current)
if y == 'BINGO':
print("current", current)
print("Number of steps", counter)
print('BINGO')
break
else:
if y=='WARM':
print("current", current)
print('WARM')
Min=previous1
else:
print("current", current)
print('COLD')
Max=current | Title: Equation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input Specification:
The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0.
Output Specification:
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Demo Input:
['1 -5 6\n']
Demo Output:
['2\n2.0000000000\n3.0000000000']
Note:
none | ```python
import random as r
######.....FUNCTION TO RETURN WARMER OR COLDER.....######
import sys
import time
counter=1
def find(z,n):
global counter
global Prev_diff
counter+=1
if n==z: return 'BINGO'
elif abs(z-n)>=abs(Prev_diff):
Prev_diff=abs(z - n)
Prev_diff=Prev_diff
return 'COLD'
elif abs(z-n)<abs(Prev_diff):
Prev_diff=abs(z - n)
Prev_diff=Prev_diff
return 'WARM'
######.....FUNCTION TO GUESS NUMBER.....######
n=1000000
guessnumber=5000
Min=0
Max=n
previous1=0
previous2=0
current=(Min+Max)//2
print(current)
print('First')
if guessnumber==current:
print("Bingo")
sys.exit()
Prev_diff=abs(guessnumber-current)
while True:
#time.sleep(.001)
previous2=previous1
previous1=current
current=(current+Max)//2
y=find(guessnumber,current)
if y=='BINGO':
print("current", current)
print("Number of steps",counter)
print('BINGO')
break
if current==Max or current==Min:
previous2=previous1
privious1=current
current=(Min+Max)//2
############# added
y = find(guessnumber, current)
if y == 'BINGO':
print("current", current)
print("Number of steps", counter)
print('BINGO')
break
else:
if y=='WARM':
print("current", current)
print('WARM')
Min=previous1
else:
print("current", current)
print('COLD')
Max=current
``` | 0 |
16 | C | Monitor | PROGRAMMING | 1,800 | [
"binary search",
"number theory"
] | C. Monitor | 0 | 64 | Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *x*:<=*y* became popular with users. That's why the company wants to reduce monitor AB999 size so that its screen sides ratio becomes *x*:<=*y*, at the same time they want its total area to be maximal of all possible variants. Your task is to find the screen parameters of the reduced size model, or find out that such a reduction can't be performed. | The first line of the input contains 4 integers — *a*, *b*, *x* and *y* (1<=≤<=*a*,<=*b*,<=*x*,<=*y*<=≤<=2·109). | If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise. | [
"800 600 4 3\n",
"1920 1200 16 9\n",
"1 1 1 2\n"
] | [
"800 600\n",
"1920 1080\n",
"0 0\n"
] | none | 0 | [
{
"input": "800 600 4 3",
"output": "800 600"
},
{
"input": "1920 1200 16 9",
"output": "1920 1080"
},
{
"input": "1 1 1 2",
"output": "0 0"
},
{
"input": "1002105126 227379125 179460772 1295256518",
"output": "0 0"
},
{
"input": "625166755 843062051 1463070160 1958300154",
"output": "0 0"
},
{
"input": "248228385 1458744978 824699604 1589655888",
"output": "206174901 397413972"
},
{
"input": "186329049 1221011622 90104472 1769702163",
"output": "60069648 1179801442"
},
{
"input": "511020182 242192314 394753578 198572007",
"output": "394753578 198572007"
},
{
"input": "134081812 857875240 82707261 667398699",
"output": "105411215 850606185"
},
{
"input": "721746595 799202881 143676564 380427290",
"output": "287353128 760854580"
},
{
"input": "912724694 1268739154 440710604 387545692",
"output": "881421208 775091384"
},
{
"input": "1103702793 1095784840 788679477 432619528",
"output": "788679477 432619528"
},
{
"input": "548893795 861438648 131329677 177735812",
"output": "525318708 710943248"
},
{
"input": "652586118 1793536161 127888702 397268645",
"output": "511554808 1589074580"
},
{
"input": "756278440 578150025 96644319 26752094",
"output": "676510233 187264658"
},
{
"input": "859970763 1510247537 37524734 97452508",
"output": "562871010 1461787620"
},
{
"input": "547278097 1977241684 51768282 183174370",
"output": "543566961 1923330885"
},
{
"input": "62256611 453071697 240966 206678",
"output": "62169228 53322924"
},
{
"input": "1979767797 878430446 5812753 3794880",
"output": "1342745943 876617280"
},
{
"input": "1143276347 1875662241 178868040 116042960",
"output": "1140283755 739773870"
},
{
"input": "435954880 1740366589 19415065 185502270",
"output": "182099920 1739883360"
},
{
"input": "664035593 983601098 4966148 2852768",
"output": "664032908 381448928"
},
{
"input": "1461963719 350925487 135888396 83344296",
"output": "572153868 350918568"
},
{
"input": "754199095 348965411 161206703 67014029",
"output": "754119492 313489356"
},
{
"input": "166102153 494841162 14166516 76948872",
"output": "91096406 494812252"
},
{
"input": "1243276346 1975662240 38441120 291740200",
"output": "259477560 1969246350"
},
{
"input": "535954879 1840366588 26278959 73433046",
"output": "535849118 1497358892"
},
{
"input": "764035592 1083601097 1192390 7267738",
"output": "177777265 1083570463"
},
{
"input": "1561963718 450925486 475523188 136236856",
"output": "1561914768 447486816"
},
{
"input": "854199094 448965410 364102983 125971431",
"output": "853687785 295356745"
},
{
"input": "266102152 594841161 15854566 13392106",
"output": "266043102 224722482"
},
{
"input": "1 1 2 1",
"output": "0 0"
},
{
"input": "2000000000 2000000000 1 1999999999",
"output": "1 1999999999"
},
{
"input": "2000000000 2000000000 1999999999 1",
"output": "1999999999 1"
},
{
"input": "2000000000 2000000000 2 1999999999",
"output": "2 1999999999"
},
{
"input": "1000000000 1000000000 999999999 2",
"output": "999999999 2"
},
{
"input": "2000000000 2000000000 1999999999 2",
"output": "1999999999 2"
},
{
"input": "2000000000 2000000000 1999999999 1999999998",
"output": "1999999999 1999999998"
},
{
"input": "2000000000 2000000000 1999999998 1999999999",
"output": "1999999998 1999999999"
}
] | 1,503,738,735 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 77 | 0 | a, b, x, y = map(int, input().split(' '))
if a < x or b < y:
i = 2
while i * i <= y:
if x % i == 0 and y % i == 0:
if x // i <= a and y // i <= b:
print(x // i, y // i, sep=' ')
exit()
i += 1
l = 0
r = 1e18
while r - l > 1:
mid = (r + l) // 2
if x * mid <= a and y * mid <= b:
l = mid
else:
r = mid
print(int(l * x), int(l * y), sep=' ')
| Title: Monitor
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *x*:<=*y* became popular with users. That's why the company wants to reduce monitor AB999 size so that its screen sides ratio becomes *x*:<=*y*, at the same time they want its total area to be maximal of all possible variants. Your task is to find the screen parameters of the reduced size model, or find out that such a reduction can't be performed.
Input Specification:
The first line of the input contains 4 integers — *a*, *b*, *x* and *y* (1<=≤<=*a*,<=*b*,<=*x*,<=*y*<=≤<=2·109).
Output Specification:
If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise.
Demo Input:
['800 600 4 3\n', '1920 1200 16 9\n', '1 1 1 2\n']
Demo Output:
['800 600\n', '1920 1080\n', '0 0\n']
Note:
none | ```python
a, b, x, y = map(int, input().split(' '))
if a < x or b < y:
i = 2
while i * i <= y:
if x % i == 0 and y % i == 0:
if x // i <= a and y // i <= b:
print(x // i, y // i, sep=' ')
exit()
i += 1
l = 0
r = 1e18
while r - l > 1:
mid = (r + l) // 2
if x * mid <= a and y * mid <= b:
l = mid
else:
r = mid
print(int(l * x), int(l * y), sep=' ')
``` | 0 |
975 | A | Aramic script | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". - Any word in Aramic represents the same object as its root.
You have an ancient script in Aramic. What is the number of different objects mentioned in the script? | The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters. | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | [
"5\na aa aaa ab abb\n",
"3\namer arem mrea\n"
] | [
"2",
"1"
] | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | 500 | [
{
"input": "5\na aa aaa ab abb",
"output": "2"
},
{
"input": "3\namer arem mrea",
"output": "1"
},
{
"input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd",
"output": "6"
},
{
"input": "2\nfhjlqs aceginpr",
"output": "2"
},
{
"input": "2\nbcdfghimn efghijlmo",
"output": "2"
}
] | 1,697,275,525 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def solve():
size = int(input())
words = input().split()
d = {}
for word in word:
x = tuple(sorted(set))
d[x] = d.get(tuple(sorted(set)), 0) + 1
print(len(d.values()))
if __name__ == "__main__":
solve() | Title: Aramic script
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". - Any word in Aramic represents the same object as its root.
You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
Input Specification:
The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters.
Output Specification:
Output one integer — the number of different objects mentioned in the given ancient Aramic script.
Demo Input:
['5\na aa aaa ab abb\n', '3\namer arem mrea\n']
Demo Output:
['2', '1']
Note:
In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | ```python
def solve():
size = int(input())
words = input().split()
d = {}
for word in word:
x = tuple(sorted(set))
d[x] = d.get(tuple(sorted(set)), 0) + 1
print(len(d.values()))
if __name__ == "__main__":
solve()
``` | -1 |
|
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'. | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "99"
},
{
"input": "1 100\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "6"
},
{
"input": "1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "100"
},
{
"input": "100 1\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0",
"output": "8"
},
{
"input": "100 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "1 1\n0 0",
"output": "0"
},
{
"input": "1 1\n0 1",
"output": "1"
},
{
"input": "1 1\n1 0",
"output": "1"
},
{
"input": "1 1\n1 1",
"output": "1"
}
] | 1,447,153,502 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 204,800 | data=input().strip().split()
mas=[]
col=0
for i in range(int(data[0])):
mas.append(input().strip().split())
for j in range(1,len(mas[i]),2):
if mas[i][j]=="1" or mas[i][j-1]=="1":
col+=1
print(col) | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'.
Output Specification:
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Demo Input:
['2 2\n0 0 0 1\n1 0 1 1\n', '1 3\n1 1 0 1 0 0\n']
Demo Output:
['3\n', '2\n']
Note:
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | ```python
data=input().strip().split()
mas=[]
col=0
for i in range(int(data[0])):
mas.append(input().strip().split())
for j in range(1,len(mas[i]),2):
if mas[i][j]=="1" or mas[i][j-1]=="1":
col+=1
print(col)
``` | 3 |
|
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,692,940,675 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | from sys import stdin
def main():
n, k = [ int(x) for x in stdin.
readline().split(" ")]
miti= n- n//2
if ( k<=miti):
print(2*(k-1)+1)
else:
print(2*(k-miti))
main()
| Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
Input Specification:
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the number that will stand at the position number *k* after Volodya's manipulations.
Demo Input:
['10 3\n', '7 7\n']
Demo Output:
['5', '6']
Note:
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | ```python
from sys import stdin
def main():
n, k = [ int(x) for x in stdin.
readline().split(" ")]
miti= n- n//2
if ( k<=miti):
print(2*(k-1)+1)
else:
print(2*(k-miti))
main()
``` | 3 |
|
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "7\n7 7 7 7 7 7 7",
"output": "7"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "4"
},
{
"input": "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2",
"output": "50"
},
{
"input": "99\n99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99",
"output": "49"
},
{
"input": "82\n43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15",
"output": "50"
},
{
"input": "17\n50 14 17 77 74 74 38 76 41 27 45 29 66 98 38 73 38",
"output": "7"
},
{
"input": "94\n81 19 90 99 26 11 86 44 78 36 80 59 99 90 78 72 71 20 94 56 42 40 71 84 10 85 10 70 52 27 39 55 90 16 48 25 7 79 99 100 38 10 99 56 3 4 78 9 16 57 14 40 52 54 57 70 30 86 56 84 97 60 59 69 49 66 23 92 90 46 86 73 53 47 1 83 14 20 24 66 13 45 41 14 86 75 55 88 48 95 82 24 47 87",
"output": "39"
},
{
"input": "88\n64 95 12 90 40 65 98 45 52 54 79 7 81 25 98 19 68 82 41 53 35 50 5 22 32 21 8 39 8 6 72 27 81 30 12 79 21 42 60 2 66 87 46 93 62 78 52 71 76 32 78 94 86 85 55 15 34 76 41 20 32 26 94 81 89 45 74 49 11 40 40 39 49 46 80 85 90 23 80 40 86 58 70 26 48 93 23 53",
"output": "37"
},
{
"input": "84\n95 9 43 43 13 84 60 90 1 8 97 99 54 34 59 83 33 15 51 26 40 12 66 65 19 30 29 78 92 60 25 13 19 84 71 73 12 24 54 49 16 41 11 40 57 59 34 40 39 9 71 83 1 77 79 53 94 47 78 55 77 85 29 52 80 90 53 77 97 97 27 79 28 23 83 25 26 22 49 86 63 56 3 32",
"output": "51"
},
{
"input": "47\n61 97 76 94 91 22 2 68 62 73 90 47 16 79 44 71 98 68 43 6 53 52 40 27 68 67 43 96 14 91 60 61 96 24 97 13 32 65 85 96 81 77 34 18 23 14 80",
"output": "21"
},
{
"input": "69\n71 1 78 74 58 89 30 6 100 90 22 61 11 59 14 74 27 25 78 61 45 19 25 33 37 4 52 43 53 38 9 100 56 67 69 38 76 91 63 60 93 52 28 61 9 98 8 14 57 63 89 64 98 51 36 66 36 86 13 82 50 91 52 64 86 78 78 83 81",
"output": "37"
},
{
"input": "52\n38 78 36 75 19 3 56 1 39 97 24 79 84 16 93 55 96 64 12 24 1 86 80 29 12 32 36 36 73 39 76 65 53 98 30 20 28 8 86 43 70 22 75 69 62 65 81 25 53 40 71 59",
"output": "28"
},
{
"input": "74\n81 31 67 97 26 75 69 81 11 13 13 74 77 88 52 20 52 64 66 75 72 28 41 54 26 75 41 91 75 15 18 36 13 83 63 61 14 48 53 63 19 67 35 48 23 65 73 100 44 55 92 88 99 17 73 25 83 7 31 89 12 80 98 39 42 75 14 29 81 35 77 87 33 94",
"output": "47"
},
{
"input": "44\n46 56 31 31 37 71 94 2 14 100 45 72 36 72 80 3 38 54 42 98 50 32 31 42 62 31 45 50 95 100 18 17 64 22 18 25 52 56 70 57 43 40 81 28",
"output": "15"
},
{
"input": "22\n28 57 40 74 51 4 45 84 99 12 95 14 92 60 47 81 84 51 31 91 59 42",
"output": "11"
},
{
"input": "59\n73 45 94 76 41 49 65 13 74 66 36 25 47 75 40 23 92 72 11 32 32 8 81 26 68 56 41 8 76 47 96 55 70 11 84 14 83 18 70 22 30 39 28 100 48 11 92 45 78 69 86 1 54 90 98 91 13 17 35",
"output": "33"
},
{
"input": "63\n20 18 44 94 68 57 16 43 74 55 68 24 21 95 76 84 50 50 47 86 86 12 58 55 28 72 86 18 34 45 81 88 3 72 41 9 60 90 81 93 12 6 9 6 2 41 1 7 9 29 81 14 64 80 20 36 67 54 7 5 35 81 22",
"output": "37"
},
{
"input": "28\n49 84 48 19 44 91 11 82 96 95 88 90 71 82 87 25 31 23 18 13 98 45 26 65 35 12 31 14",
"output": "15"
},
{
"input": "61\n34 18 28 64 28 45 9 77 77 20 63 92 79 16 16 100 86 2 91 91 57 15 31 95 10 88 84 5 82 83 53 98 59 17 97 80 76 80 81 3 91 81 87 93 61 46 10 49 6 22 21 75 63 89 21 81 30 19 67 38 77",
"output": "35"
},
{
"input": "90\n41 90 43 1 28 75 90 50 3 70 76 64 81 63 25 69 83 82 29 91 59 66 21 61 7 55 72 49 38 69 72 20 64 58 30 81 61 29 96 14 39 5 100 20 29 98 75 29 44 78 97 45 26 77 73 59 22 99 41 6 3 96 71 20 9 18 96 18 90 62 34 78 54 5 41 6 73 33 2 54 26 21 18 6 45 57 43 73 95 75",
"output": "42"
},
{
"input": "45\n93 69 4 27 20 14 71 48 79 3 32 26 49 30 57 88 13 56 49 61 37 32 47 41 41 70 45 68 82 18 8 6 25 20 15 13 71 99 28 6 52 34 19 59 26",
"output": "23"
},
{
"input": "33\n29 95 48 49 91 10 83 71 47 25 66 36 51 12 34 10 54 74 41 96 89 26 89 1 42 33 1 62 9 32 49 65 78",
"output": "15"
},
{
"input": "34\n98 24 42 36 41 82 28 58 89 34 77 70 76 44 74 54 66 100 13 79 4 88 21 1 11 45 91 29 87 100 29 54 82 78",
"output": "13"
},
{
"input": "29\n91 84 26 84 9 63 52 9 65 56 90 2 36 7 67 33 91 14 65 38 53 36 81 83 85 14 33 95 51",
"output": "17"
},
{
"input": "100\n2 88 92 82 87 100 78 28 84 43 78 32 43 33 97 19 15 52 29 84 57 72 54 13 99 28 82 79 40 70 34 92 91 53 9 88 27 43 14 92 72 37 26 37 20 95 19 34 49 64 33 37 34 27 80 79 9 54 99 68 25 4 68 73 46 66 24 78 3 87 26 52 50 84 4 95 23 83 39 58 86 36 33 16 98 2 84 19 53 12 69 60 10 11 78 17 79 92 77 59",
"output": "45"
},
{
"input": "100\n2 95 45 73 9 54 20 97 57 82 88 26 18 71 25 27 75 54 31 11 58 85 69 75 72 91 76 5 25 80 45 49 4 73 8 81 81 38 5 12 53 77 7 96 90 35 28 80 73 94 19 69 96 17 94 49 69 9 32 19 5 12 46 29 26 40 59 59 6 95 82 50 72 2 45 69 12 5 72 29 39 72 23 96 81 28 28 56 68 58 37 41 30 1 90 84 15 24 96 43",
"output": "53"
},
{
"input": "100\n27 72 35 91 13 10 35 45 24 55 83 84 63 96 29 79 34 67 63 92 48 83 18 77 28 27 49 66 29 88 55 15 6 58 14 67 94 36 77 7 7 64 61 52 71 18 36 99 76 6 50 67 16 13 41 7 89 73 61 51 78 22 78 32 76 100 3 31 89 71 63 53 15 85 77 54 89 33 68 74 3 23 57 5 43 89 75 35 9 86 90 11 31 46 48 37 74 17 77 8",
"output": "40"
},
{
"input": "100\n69 98 69 88 11 49 55 8 25 91 17 81 47 26 15 73 96 71 18 42 42 61 48 14 92 78 35 72 4 27 62 75 83 79 17 16 46 80 96 90 82 54 37 69 85 21 67 70 96 10 46 63 21 59 56 92 54 88 77 30 75 45 44 29 86 100 51 11 65 69 66 56 82 63 27 1 51 51 13 10 3 55 26 85 34 16 87 72 13 100 81 71 90 95 86 50 83 55 55 54",
"output": "53"
},
{
"input": "100\n34 35 99 64 2 66 78 93 20 48 12 79 19 10 87 7 42 92 60 79 5 2 24 89 57 48 63 92 74 4 16 51 7 12 90 48 87 17 18 73 51 58 97 97 25 38 15 97 96 73 67 91 6 75 14 13 87 79 75 3 15 55 35 95 71 45 10 13 20 37 82 26 2 22 13 83 97 84 39 79 43 100 54 59 98 8 61 34 7 65 75 44 24 77 73 88 34 95 44 77",
"output": "55"
},
{
"input": "100\n15 86 3 1 51 26 74 85 37 87 64 58 10 6 57 26 30 47 85 65 24 72 50 40 12 35 91 47 91 60 47 87 95 34 80 91 26 3 36 39 14 86 28 70 51 44 28 21 72 79 57 61 16 71 100 94 57 67 36 74 24 21 89 85 25 2 97 67 76 53 76 80 97 64 35 13 8 32 21 52 62 61 67 14 74 73 66 44 55 76 24 3 43 42 99 61 36 80 38 66",
"output": "52"
},
{
"input": "100\n45 16 54 54 80 94 74 93 75 85 58 95 79 30 81 2 84 4 57 23 92 64 78 1 50 36 13 27 56 54 10 77 87 1 5 38 85 74 94 82 30 45 72 83 82 30 81 82 82 3 69 82 7 92 39 60 94 42 41 5 3 17 67 21 79 44 79 96 28 3 53 68 79 89 63 83 1 44 4 31 84 15 73 77 19 66 54 6 73 1 67 24 91 11 86 45 96 82 20 89",
"output": "51"
},
{
"input": "100\n84 23 50 32 90 71 92 43 58 70 6 82 7 55 85 19 70 89 12 26 29 56 74 30 2 27 4 39 63 67 91 81 11 33 75 10 82 88 39 43 43 80 68 35 55 67 53 62 73 65 86 74 43 51 14 48 42 92 83 57 22 33 24 99 5 27 78 96 7 28 11 15 8 38 85 67 5 92 24 96 57 59 14 95 91 4 9 18 45 33 74 83 64 85 14 51 51 94 29 2",
"output": "53"
},
{
"input": "100\n77 56 56 45 73 55 32 37 39 50 30 95 79 21 44 34 51 43 86 91 39 30 85 15 35 93 100 14 57 31 80 79 38 40 88 4 91 54 7 95 76 26 62 84 17 33 67 47 6 82 69 51 17 2 59 24 11 12 31 90 12 11 55 38 72 49 30 50 42 46 5 97 9 9 30 45 86 23 19 82 40 42 5 40 35 98 35 32 60 60 5 28 84 35 21 49 68 53 68 23",
"output": "48"
},
{
"input": "100\n78 38 79 61 45 86 83 83 86 90 74 69 2 84 73 39 2 5 20 71 24 80 54 89 58 34 77 40 39 62 2 47 28 53 97 75 88 98 94 96 33 71 44 90 47 36 19 89 87 98 90 87 5 85 34 79 82 3 42 88 89 63 35 7 89 30 40 48 12 41 56 76 83 60 80 80 39 56 77 4 72 96 30 55 57 51 7 19 11 1 66 1 91 87 11 62 95 85 79 25",
"output": "48"
},
{
"input": "100\n5 34 23 20 76 75 19 51 17 82 60 13 83 6 65 16 20 43 66 54 87 10 87 73 50 24 16 98 33 28 80 52 54 82 26 92 14 13 84 92 94 29 61 21 60 20 48 94 24 20 75 70 58 27 68 45 86 89 29 8 67 38 83 48 18 100 11 22 46 84 52 97 70 19 50 75 3 7 52 53 72 41 18 31 1 38 49 53 11 64 99 76 9 87 48 12 100 32 44 71",
"output": "58"
},
{
"input": "100\n76 89 68 78 24 72 73 95 98 72 58 15 2 5 56 32 9 65 50 70 94 31 29 54 89 52 31 93 43 56 26 35 72 95 51 55 78 70 11 92 17 5 54 94 81 31 78 95 73 91 95 37 59 9 53 48 65 55 84 8 45 97 64 37 96 34 36 53 66 17 72 48 99 23 27 18 92 84 44 73 60 78 53 29 68 99 19 39 61 40 69 6 77 12 47 29 15 4 8 45",
"output": "53"
},
{
"input": "100\n82 40 31 53 8 50 85 93 3 84 54 17 96 59 51 42 18 19 35 84 79 31 17 46 54 82 72 49 35 73 26 89 61 73 3 50 12 29 25 77 88 21 58 24 22 89 96 54 82 29 96 56 77 16 1 68 90 93 20 23 57 22 31 18 92 90 51 14 50 72 31 54 12 50 66 62 2 34 17 45 68 50 87 97 23 71 1 72 17 82 42 15 20 78 4 49 66 59 10 17",
"output": "54"
},
{
"input": "100\n32 82 82 24 39 53 48 5 29 24 9 37 91 37 91 95 1 97 84 52 12 56 93 47 22 20 14 17 40 22 79 34 24 2 69 30 69 29 3 89 21 46 60 92 39 29 18 24 49 18 40 22 60 13 77 50 39 64 50 70 99 8 66 31 90 38 20 54 7 21 5 56 41 68 69 20 54 89 69 62 9 53 43 89 81 97 15 2 52 78 89 65 16 61 59 42 56 25 32 52",
"output": "49"
},
{
"input": "100\n72 54 23 24 97 14 99 87 15 25 7 23 17 87 72 31 71 87 34 82 51 77 74 85 62 38 24 7 84 48 98 21 29 71 70 84 25 58 67 92 18 44 32 9 81 15 53 29 63 18 86 16 7 31 38 99 70 32 89 16 23 11 66 96 69 82 97 59 6 9 49 80 85 19 6 9 52 51 85 74 53 46 73 55 31 63 78 61 34 80 77 65 87 77 92 52 89 8 52 31",
"output": "44"
},
{
"input": "100\n56 88 8 19 7 15 11 54 35 50 19 57 63 72 51 43 50 19 57 90 40 100 8 92 11 96 30 32 59 65 93 47 62 3 50 41 30 50 72 83 61 46 83 60 20 46 33 1 5 18 83 22 34 16 41 95 63 63 7 59 55 95 91 29 64 60 64 81 45 45 10 9 88 37 69 85 21 82 41 76 42 34 47 78 51 83 65 100 13 22 59 76 63 1 26 86 36 94 99 74",
"output": "46"
},
{
"input": "100\n27 89 67 60 62 80 43 50 28 88 72 5 94 11 63 91 18 78 99 3 71 26 12 97 74 62 23 24 22 3 100 72 98 7 94 32 12 75 61 88 42 48 10 14 45 9 48 56 73 76 70 70 79 90 35 39 96 37 81 11 19 65 99 39 23 79 34 61 35 74 90 37 73 23 46 21 94 84 73 58 11 89 13 9 10 85 42 78 73 32 53 39 49 90 43 5 28 31 97 75",
"output": "53"
},
{
"input": "100\n33 24 97 96 1 14 99 51 13 65 67 20 46 88 42 44 20 49 5 89 98 83 15 40 74 83 58 3 10 79 34 2 69 28 37 100 55 52 14 8 44 94 97 89 6 42 11 28 30 33 55 56 20 57 52 25 75 1 87 42 62 41 37 12 54 85 95 80 42 36 94 96 28 76 54 36 4 17 26 24 62 15 17 79 84 36 92 78 74 91 96 77 54 92 81 91 62 98 37 37",
"output": "43"
},
{
"input": "100\n86 24 61 15 11 85 1 31 47 36 23 36 59 34 3 27 16 29 82 28 58 52 52 66 71 61 98 39 60 20 67 41 67 90 73 29 92 17 70 95 58 98 58 32 21 73 46 56 87 72 80 75 40 27 94 31 59 92 93 37 14 99 96 21 97 23 81 91 52 52 96 94 92 28 38 29 52 16 57 27 17 24 91 21 79 55 96 98 95 94 23 78 79 12 77 35 32 75 100 82",
"output": "51"
},
{
"input": "100\n88 85 41 37 69 21 7 69 36 5 92 26 64 75 22 46 67 20 70 22 62 66 38 24 47 49 68 30 90 31 67 86 86 82 9 51 43 45 48 42 73 44 31 94 45 60 54 66 20 87 11 94 34 32 87 66 56 28 75 39 37 90 72 93 55 72 31 42 30 71 87 61 4 12 12 81 23 61 56 98 71 32 30 33 96 63 92 16 8 78 47 91 47 54 49 3 81 82 41 5",
"output": "47"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 1 3 2 2",
"output": "3"
}
] | 1,560,803,973 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 248 | 0 | n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(len(a)):
if sum(a)-a[i]&1==0:
c+=1
print(c) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Output Specification:
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
Demo Input:
['1\n1\n', '10\n1 2 2 3 4 4 4 2 2 2\n', '11\n2 2 2 2 2 2 2 2 2 2 99\n']
Demo Output:
['1\n', '8\n', '1\n']
Note:
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | ```python
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(len(a)):
if sum(a)-a[i]&1==0:
c+=1
print(c)
``` | 3 |
|
459 | E | Pashmak and Graph | PROGRAMMING | 1,900 | [
"dp",
"sortings"
] | null | null | Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem.
You are given a weighted directed graph with *n* vertices and *m* edges. You need to find a path (perhaps, non-simple) with maximum number of edges, such that the weights of the edges increase along the path. In other words, each edge of the path must have strictly greater weight than the previous edge in the path.
Help Pashmak, print the number of edges in the required path. | The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=*min*(*n*·(*n*<=-<=1),<=3·105)). Then, *m* lines follows. The *i*-th line contains three space separated integers: *u**i*, *v**i*, *w**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; 1<=≤<=*w**i*<=≤<=105) which indicates that there's a directed edge with weight *w**i* from vertex *u**i* to vertex *v**i*.
It's guaranteed that the graph doesn't contain self-loops and multiple edges. | Print a single integer — the answer to the problem. | [
"3 3\n1 2 1\n2 3 1\n3 1 1\n",
"3 3\n1 2 1\n2 3 2\n3 1 3\n",
"6 7\n1 2 1\n3 2 5\n2 4 2\n2 5 2\n2 6 9\n5 4 3\n4 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | In the first sample the maximum trail can be any of this trails: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1534088dd4d998a9bcc7e17dba96f7c213c54fc6.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample the maximum trail is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9b1d1f66686c43090329870c208942499764a73b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample the maximum trail is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1db1cef44580d43663d6896f0190e5ccee9502c9.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 3,000 | [
{
"input": "3 3\n1 2 1\n2 3 1\n3 1 1",
"output": "1"
},
{
"input": "3 3\n1 2 1\n2 3 2\n3 1 3",
"output": "3"
},
{
"input": "6 7\n1 2 1\n3 2 5\n2 4 2\n2 5 2\n2 6 9\n5 4 3\n4 3 4",
"output": "6"
},
{
"input": "2 2\n1 2 1\n2 1 2",
"output": "2"
},
{
"input": "4 3\n1 2 1\n2 3 1\n3 4 2",
"output": "2"
},
{
"input": "4 12\n1 2 2\n2 1 2\n1 3 1\n3 1 1\n1 4 1\n4 1 1\n2 3 1\n3 2 1\n2 4 1\n4 2 1\n3 4 2\n4 3 2",
"output": "2"
},
{
"input": "3 4\n1 2 1\n2 1 2\n2 3 2\n3 1 3",
"output": "3"
},
{
"input": "4 3\n1 2 1\n3 4 1\n2 1 2",
"output": "2"
},
{
"input": "5 8\n1 2 1\n2 3 1\n3 4 1\n4 5 1\n1 5 1\n1 3 2\n2 4 2\n3 5 3",
"output": "2"
},
{
"input": "3 6\n1 2 1\n2 3 1\n3 1 1\n2 1 2\n3 2 4\n1 3 3",
"output": "4"
},
{
"input": "3 3\n1 2 1\n1 3 2\n3 2 3",
"output": "2"
},
{
"input": "6 7\n1 2 1\n1 5 1\n5 2 3\n2 3 3\n3 4 4\n1 6 1\n6 2 3",
"output": "3"
},
{
"input": "5 5\n1 2 3\n1 3 3\n2 3 4\n3 4 4\n4 5 5",
"output": "3"
}
] | 1,669,461,117 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | [n, m] = list(map(int, input().split()))
graph = [[] for i in range(m + 1)]
def minDistance(graph, dist, src, sptSet, pre, n):
minim = 1e7
min_index = src
for v in range(n):
if dist[v] != minim and sptSet[v] == False:
sptSet[v] = True
min_index = v
return min_index
def dijkstra(graph, n, start):
preNoode = start
dist = [1e7] * n
dist[start] = 0
paths = [0] * n
h = [False] * n
sptSet = [h.copy()] * n
pre = 0
u = start
for cout in range(n):
r = [False] * n
u = minDistance(graph, dist, preNoode, r, pre, n)
pre = graph[start][u]
for v in range(n):
if (graph[u][v] > 0
and dist[v] >= dist[u] + 1
and sptSet[u][v] == False
and graph[u][v] > pre):
dist[v] = dist[u] + 1
pre = graph[u][v]
sptSet[u][v] = True
paths[u] += 1
preNoode = v
return max(paths)
for i in range(m):
[u, v, w] = list(map(int, input().split()))
graph[w].append([v, u])
def findpath(graph, n):
maxim = 0
for j in range(n):
l = dijkstra(graph, n, j)
if l > maxim:
maxim = l
return maxim
dp = [1] * (n + 1)
for edge in graph:
adj = []
for e in edge:
v = e[0]
u = e[1]
adj.append([v, dp[u] + 1])
for [v, d] in adj:
if(dp[v] < d):
dp[v] = d
print(dp[n])
| Title: Pashmak and Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem.
You are given a weighted directed graph with *n* vertices and *m* edges. You need to find a path (perhaps, non-simple) with maximum number of edges, such that the weights of the edges increase along the path. In other words, each edge of the path must have strictly greater weight than the previous edge in the path.
Help Pashmak, print the number of edges in the required path.
Input Specification:
The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=*min*(*n*·(*n*<=-<=1),<=3·105)). Then, *m* lines follows. The *i*-th line contains three space separated integers: *u**i*, *v**i*, *w**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; 1<=≤<=*w**i*<=≤<=105) which indicates that there's a directed edge with weight *w**i* from vertex *u**i* to vertex *v**i*.
It's guaranteed that the graph doesn't contain self-loops and multiple edges.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3 3\n1 2 1\n2 3 1\n3 1 1\n', '3 3\n1 2 1\n2 3 2\n3 1 3\n', '6 7\n1 2 1\n3 2 5\n2 4 2\n2 5 2\n2 6 9\n5 4 3\n4 3 4\n']
Demo Output:
['1\n', '3\n', '6\n']
Note:
In the first sample the maximum trail can be any of this trails: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1534088dd4d998a9bcc7e17dba96f7c213c54fc6.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample the maximum trail is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9b1d1f66686c43090329870c208942499764a73b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample the maximum trail is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1db1cef44580d43663d6896f0190e5ccee9502c9.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
[n, m] = list(map(int, input().split()))
graph = [[] for i in range(m + 1)]
def minDistance(graph, dist, src, sptSet, pre, n):
minim = 1e7
min_index = src
for v in range(n):
if dist[v] != minim and sptSet[v] == False:
sptSet[v] = True
min_index = v
return min_index
def dijkstra(graph, n, start):
preNoode = start
dist = [1e7] * n
dist[start] = 0
paths = [0] * n
h = [False] * n
sptSet = [h.copy()] * n
pre = 0
u = start
for cout in range(n):
r = [False] * n
u = minDistance(graph, dist, preNoode, r, pre, n)
pre = graph[start][u]
for v in range(n):
if (graph[u][v] > 0
and dist[v] >= dist[u] + 1
and sptSet[u][v] == False
and graph[u][v] > pre):
dist[v] = dist[u] + 1
pre = graph[u][v]
sptSet[u][v] = True
paths[u] += 1
preNoode = v
return max(paths)
for i in range(m):
[u, v, w] = list(map(int, input().split()))
graph[w].append([v, u])
def findpath(graph, n):
maxim = 0
for j in range(n):
l = dijkstra(graph, n, j)
if l > maxim:
maxim = l
return maxim
dp = [1] * (n + 1)
for edge in graph:
adj = []
for e in edge:
v = e[0]
u = e[1]
adj.append([v, dp[u] + 1])
for [v, d] in adj:
if(dp[v] < d):
dp[v] = d
print(dp[n])
``` | 0 |
|
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City? | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,688,629,586 | 2,147,483,647 | Python 3 | OK | TESTS | 5 | 31 | 0 | n = int(input())
if n % 4 == 0:
last_two_digits = 25
else:
last_two_digits = pow(5, n % 4)
last_two_digits = last_two_digits % 100
print(last_two_digits)
| Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
Could you pass the interview in the machine vision company in IT City?
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5.
Output Specification:
Output the last two digits of 5*n* without spaces between them.
Demo Input:
['2\n']
Demo Output:
['25']
Note:
none | ```python
n = int(input())
if n % 4 == 0:
last_two_digits = 25
else:
last_two_digits = pow(5, n % 4)
last_two_digits = last_two_digits % 100
print(last_two_digits)
``` | 3 |
|
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times. | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 21 73839",
"output": "9999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99991 623 36438",
"output": "9999150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 334 94854",
"output": "9999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99252 9827 84849",
"output": "9925270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99313 9833 10561",
"output": "9931330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "94885 55815 11417",
"output": "9488550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99492 58525 53481",
"output": "9949250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99858 28531 79193",
"output": "9985850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99136 47208 42607",
"output": "9913680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "63270 19953 5555",
"output": "-1"
},
{
"input": "10240 128 100000",
"output": "1024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "12 11 3",
"output": "12100"
},
{
"input": "14 12 99998",
"output": "1440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "1 11 3",
"output": "1100"
},
{
"input": "3 40 1",
"output": "-1"
},
{
"input": "150 100 10",
"output": "1500000000000"
},
{
"input": "5 10 1",
"output": "50"
},
{
"input": "1 15 10",
"output": "15000000000"
},
{
"input": "3 13 2",
"output": "390"
}
] | 1,603,789,459 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 108 | 204,800 | a,b,n=map(int,input().split())
c=str(a)
for (i) in range(10):
if int(c+str(i))%b==0:
c=c+str(i)
print(c + "0" * (n - 1))
exit()
print(-1)
| Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times.
Input Specification:
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
Output Specification:
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Demo Input:
['5 4 5\n', '12 11 1\n', '260 150 10\n']
Demo Output:
['524848\n', '121\n', '-1\n']
Note:
none | ```python
a,b,n=map(int,input().split())
c=str(a)
for (i) in range(10):
if int(c+str(i))%b==0:
c=c+str(i)
print(c + "0" * (n - 1))
exit()
print(-1)
``` | 3 |
|
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once.
You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2. | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2",
"output": "1"
},
{
"input": "15\n1 2 3 4 5 5 4 3 2 1 1 2 3 4 5",
"output": "10"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n5000",
"output": "1"
},
{
"input": "4\n5000 5000 5000 5000",
"output": "4"
},
{
"input": "5\n3366 3461 4 5 4370",
"output": "3"
},
{
"input": "10\n8 2 10 3 4 6 1 7 9 5",
"output": "0"
},
{
"input": "10\n551 3192 3213 2846 3068 1224 3447 1 10 9",
"output": "7"
},
{
"input": "15\n4 1459 12 4281 3241 2748 10 3590 14 845 3518 1721 2 2880 1974",
"output": "10"
},
{
"input": "15\n15 1 8 2 13 11 12 7 3 14 6 10 9 4 5",
"output": "0"
},
{
"input": "15\n2436 2354 4259 1210 2037 2665 700 3578 2880 973 1317 1024 24 3621 4142",
"output": "15"
},
{
"input": "30\n28 1 3449 9 3242 4735 26 3472 15 21 2698 7 4073 3190 10 3 29 1301 4526 22 345 3876 19 12 4562 2535 2 630 18 27",
"output": "14"
},
{
"input": "100\n50 39 95 30 66 78 2169 4326 81 31 74 34 80 40 19 48 97 63 82 6 88 16 21 57 92 77 10 1213 17 93 32 91 38 4375 29 75 44 22 4 45 14 2395 3254 59 3379 2 85 96 8 83 27 94 1512 2960 100 9 73 79 7 25 55 69 90 99 51 87 98 62 18 35 43 4376 4668 28 72 56 4070 61 65 36 54 4106 11 24 15 86 70 71 4087 23 13 76 20 4694 26 4962 4726 37 14 64",
"output": "18"
},
{
"input": "100\n340 14 3275 2283 2673 1107 817 2243 1226 32 2382 3638 4652 418 68 4962 387 764 4647 159 1846 225 2760 4904 3150 403 3 2439 91 4428 92 4705 75 348 1566 1465 69 6 49 4 62 4643 564 1090 3447 1871 2255 139 24 99 2669 969 86 61 4550 158 4537 3993 1589 872 2907 1888 401 80 1825 1483 63 1 2264 4068 4113 2548 41 885 4806 36 67 167 4447 34 1248 2593 82 202 81 1783 1284 4973 16 43 95 7 865 2091 3008 1793 20 947 4912 3604",
"output": "70"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "2\n5000 5000",
"output": "2"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
},
{
"input": "2\n3 4",
"output": "2"
},
{
"input": "10\n1 2 3 4 5 6 7 1000 10 10",
"output": "2"
}
] | 1,604,762,024 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 18 | 2,000 | 307,200 | n=int(input())
s = list(map(int,input().rsplit()))
s.sort()
a=0
for i in range (1,n+1):
for j in range (0,n):
if s[j]==i:
break
if j==n-1:
a=a+1
print(a)
| Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once.
You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).
Input Specification:
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*).
Output Specification:
Print the only number — the minimum number of changes needed to get the permutation.
Demo Input:
['3\n3 1 2\n', '2\n2 2\n', '5\n5 3 3 3 1\n']
Demo Output:
['0\n', '1\n', '2\n']
Note:
The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2. | ```python
n=int(input())
s = list(map(int,input().rsplit()))
s.sort()
a=0
for i in range (1,n+1):
for j in range (0,n):
if s[j]==i:
break
if j==n-1:
a=a+1
print(a)
``` | 0 |
|
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible.
Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream. | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n2 5",
"output": "181"
},
{
"input": "6\n22 9 87 89 57\n1 6",
"output": "264"
},
{
"input": "7\n52 36 31 23 74 78\n2 7",
"output": "242"
},
{
"input": "8\n82 14 24 5 91 49 94\n3 8",
"output": "263"
},
{
"input": "9\n12 40 69 39 59 21 59 5\n4 6",
"output": "98"
},
{
"input": "10\n95 81 32 59 71 30 50 61 100\n1 6",
"output": "338"
},
{
"input": "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n3 14",
"output": "617"
},
{
"input": "20\n91 1 41 51 95 67 92 35 23 70 44 91 57 50 21 8 9 71 40\n8 17",
"output": "399"
},
{
"input": "25\n70 95 21 84 97 39 12 98 53 24 78 29 84 65 70 22 100 17 69 27 62 48 35 80\n8 23",
"output": "846"
},
{
"input": "30\n35 69 50 44 19 56 86 56 98 24 21 2 61 24 85 30 2 22 57 35 59 84 12 77 92 53 50 92 9\n1 16",
"output": "730"
},
{
"input": "35\n2 34 47 15 27 61 6 88 67 20 53 65 29 68 77 5 78 86 44 98 32 81 91 79 54 84 95 23 65 97 22 33 42 87\n8 35",
"output": "1663"
},
{
"input": "40\n32 88 59 36 95 45 28 78 73 30 97 13 13 47 48 100 43 21 22 45 88 25 15 13 63 25 72 92 29 5 25 11 50 5 54 51 48 84 23\n7 26",
"output": "862"
},
{
"input": "45\n83 74 73 95 10 31 100 26 29 15 80 100 22 70 31 88 9 56 19 70 2 62 48 30 27 47 52 50 94 44 21 94 23 85 15 3 95 72 43 62 94 89 68 88\n17 40",
"output": "1061"
},
{
"input": "50\n28 8 16 29 19 82 70 51 96 84 74 72 17 69 12 21 37 21 39 3 18 66 19 49 86 96 94 93 2 90 96 84 59 88 58 15 61 33 55 22 35 54 51 29 64 68 29 38 40\n23 28",
"output": "344"
},
{
"input": "60\n24 28 25 21 43 71 64 73 71 90 51 83 69 43 75 43 78 72 56 61 99 7 23 86 9 16 16 94 23 74 18 56 20 72 13 31 75 34 35 86 61 49 4 72 84 7 65 70 66 52 21 38 6 43 69 40 73 46 5\n28 60",
"output": "1502"
},
{
"input": "70\n69 95 34 14 67 61 6 95 94 44 28 94 73 66 39 13 19 71 73 71 28 48 26 22 32 88 38 95 43 59 88 77 80 55 17 95 40 83 67 1 38 95 58 63 56 98 49 2 41 4 73 8 78 41 64 71 60 71 41 61 67 4 4 19 97 14 39 20 27\n9 41",
"output": "1767"
},
{
"input": "80\n65 15 43 6 43 98 100 16 69 98 4 54 25 40 2 35 12 23 38 29 10 89 30 6 4 8 7 96 64 43 11 49 89 38 20 59 54 85 46 16 16 89 60 54 28 37 32 34 67 9 78 30 50 87 58 53 99 48 77 3 5 6 19 99 16 20 31 10 80 76 82 56 56 83 72 81 84 60 28\n18 24",
"output": "219"
},
{
"input": "90\n61 35 100 99 67 87 42 90 44 4 81 65 29 63 66 56 53 22 55 87 39 30 34 42 27 80 29 97 85 28 81 22 50 22 24 75 67 86 78 79 94 35 13 97 48 76 68 66 94 13 82 1 22 85 5 36 86 73 65 97 43 56 35 26 87 25 74 47 81 67 73 75 99 75 53 38 70 21 66 78 38 17 57 40 93 57 68 55 1\n12 44",
"output": "1713"
},
{
"input": "95\n37 74 53 96 65 84 65 72 95 45 6 77 91 35 58 50 51 51 97 30 51 20 79 81 92 10 89 34 40 76 71 54 26 34 73 72 72 28 53 19 95 64 97 10 44 15 12 38 5 63 96 95 86 8 36 96 45 53 81 5 18 18 47 97 65 9 33 53 41 86 37 53 5 40 15 76 83 45 33 18 26 5 19 90 46 40 100 42 10 90 13 81 40 53\n6 15",
"output": "570"
},
{
"input": "96\n51 32 95 75 23 54 70 89 67 3 1 51 4 100 97 30 9 35 56 38 54 77 56 98 43 17 60 43 72 46 87 61 100 65 81 22 74 38 16 96 5 10 54 22 23 22 10 91 9 54 49 82 29 73 33 98 75 8 4 26 24 90 71 42 90 24 94 74 94 10 41 98 56 63 18 43 56 21 26 64 74 33 22 38 67 66 38 60 64 76 53 10 4 65 76\n21 26",
"output": "328"
},
{
"input": "97\n18 90 84 7 33 24 75 55 86 10 96 72 16 64 37 9 19 71 62 97 5 34 85 15 46 72 82 51 52 16 55 68 27 97 42 72 76 97 32 73 14 56 11 86 2 81 59 95 60 93 1 22 71 37 77 100 6 16 78 47 78 62 94 86 16 91 56 46 47 35 93 44 7 86 70 10 29 45 67 62 71 61 74 39 36 92 24 26 65 14 93 92 15 28 79 59\n6 68",
"output": "3385"
},
{
"input": "98\n32 47 26 86 43 42 79 72 6 68 40 46 29 80 24 89 29 7 21 56 8 92 13 33 50 79 5 7 84 85 24 23 1 80 51 21 26 55 96 51 24 2 68 98 81 88 57 100 64 84 54 10 14 2 74 1 89 71 1 20 84 85 17 31 42 58 69 67 48 60 97 90 58 10 21 29 2 21 60 61 68 89 77 39 57 18 61 44 67 100 33 74 27 40 83 29 6\n8 77",
"output": "3319"
},
{
"input": "99\n46 5 16 66 53 12 84 89 26 27 35 68 41 44 63 17 88 43 80 15 59 1 42 50 53 34 75 16 16 55 92 30 28 11 12 71 27 65 11 28 86 47 24 10 60 47 7 53 16 75 6 49 56 66 70 3 20 78 75 41 38 57 89 23 16 74 30 39 1 32 49 84 9 33 25 95 75 45 54 59 17 17 29 40 79 96 47 11 69 86 73 56 91 4 87 47 31 24\n23 36",
"output": "514"
},
{
"input": "100\n63 65 21 41 95 23 3 4 12 23 95 50 75 63 58 34 71 27 75 31 23 94 96 74 69 34 43 25 25 55 44 19 43 86 68 17 52 65 36 29 72 96 84 25 84 23 71 54 6 7 71 7 21 100 99 58 93 35 62 47 36 70 68 9 75 13 35 70 76 36 62 22 52 51 2 87 66 41 54 35 78 62 30 35 65 44 74 93 78 37 96 70 26 32 71 27 85 85 63\n43 92",
"output": "2599"
},
{
"input": "51\n85 38 22 38 42 36 55 24 36 80 49 15 66 91 88 61 46 82 1 61 89 92 6 56 28 8 46 80 56 90 91 38 38 17 69 64 57 68 13 44 45 38 8 72 61 39 87 2 73 88\n15 27",
"output": "618"
},
{
"input": "2\n3\n1 2",
"output": "3"
},
{
"input": "5\n6 8 22 22\n2 3",
"output": "8"
},
{
"input": "6\n3 12 27 28 28\n3 4",
"output": "27"
},
{
"input": "9\n1 2 2 2 2 3 3 5\n3 7",
"output": "9"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1\n6 8",
"output": "2"
},
{
"input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3\n5 17",
"output": "23"
},
{
"input": "25\n1 1 1 4 5 6 8 11 11 11 11 12 13 14 14 14 15 16 16 17 17 17 19 19\n4 8",
"output": "23"
},
{
"input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n30 31",
"output": "2"
},
{
"input": "45\n1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 8 8 8 9 9 9 9 9 10 10 10\n42 45",
"output": "30"
},
{
"input": "50\n1 8 8 13 14 15 15 16 19 21 22 24 26 31 32 37 45 47 47 47 50 50 51 54 55 56 58 61 61 61 63 63 64 66 66 67 67 70 71 80 83 84 85 92 92 94 95 95 100\n4 17",
"output": "285"
},
{
"input": "60\n1 2 4 4 4 6 6 8 9 10 10 13 14 18 20 20 21 22 23 23 26 29 30 32 33 34 35 38 40 42 44 44 46 48 52 54 56 56 60 60 66 67 68 68 69 73 73 74 80 80 81 81 82 84 86 86 87 89 89\n56 58",
"output": "173"
},
{
"input": "70\n1 2 3 3 4 5 5 7 7 7 8 8 8 8 9 9 10 12 12 12 12 13 16 16 16 16 16 16 17 17 18 18 20 20 21 23 24 25 25 26 29 29 29 29 31 32 32 34 35 36 36 37 37 38 39 39 40 40 40 40 41 41 42 43 44 44 44 45 45\n62 65",
"output": "126"
},
{
"input": "80\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 5 5 5 5 5 5 5 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12\n17 65",
"output": "326"
},
{
"input": "90\n1 1 3 5 8 9 10 11 11 11 11 12 13 14 15 15 15 16 16 19 19 20 22 23 24 25 25 28 29 29 30 31 33 34 35 37 37 38 41 43 43 44 45 47 51 54 55 56 58 58 59 59 60 62 66 67 67 67 68 68 69 70 71 72 73 73 76 77 77 78 78 78 79 79 79 82 83 84 85 85 87 87 89 93 93 93 95 99 99\n28 48",
"output": "784"
},
{
"input": "95\n2 2 3 3 4 6 6 7 7 7 9 10 12 12 12 12 13 14 15 16 17 18 20 20 20 20 21 21 21 21 22 22 22 22 22 23 23 23 25 26 26 27 27 27 28 29 29 30 30 31 32 33 34 36 37 37 38 39 39 39 42 43 43 43 45 47 48 50 50 51 52 53 54 54 54 55 55 55 58 59 60 61 61 61 61 62 62 63 64 65 66 67 67 67\n64 93",
"output": "1636"
},
{
"input": "96\n1 1 2 3 3 5 8 9 9 10 10 10 11 11 11 11 11 12 13 13 13 14 15 15 16 16 17 17 17 17 18 18 20 20 20 21 21 21 23 24 24 25 25 26 27 27 27 27 29 29 29 30 30 30 32 32 32 32 32 32 33 33 34 34 34 35 35 35 36 36 37 37 37 38 39 40 41 41 41 41 42 42 43 43 45 45 45 46 46 47 47 49 50 52 52\n76 96",
"output": "898"
},
{
"input": "98\n2 3 4 4 5 7 8 10 10 10 11 11 12 12 12 12 13 14 15 15 16 16 18 19 19 20 21 21 21 21 22 23 24 25 26 26 27 27 27 27 29 29 30 30 31 31 37 40 40 40 41 41 41 42 43 44 44 44 46 46 47 49 49 50 50 50 51 53 55 55 56 56 56 56 56 57 57 58 59 60 60 60 62 62 63 64 64 64 65 66 66 67 68 70 70 71 71\n8 90",
"output": "3016"
},
{
"input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n66 95",
"output": "29"
},
{
"input": "100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17\n39 52",
"output": "82"
},
{
"input": "51\n5 7 9 16 19 25 26 29 29 30 31 32 32 41 43 44 47 49 50 50 51 52 54 55 56 63 64 66 67 70 74 74 77 78 79 80 80 85 86 87 89 89 90 92 93 94 94 95 95 97\n3 44",
"output": "2268"
}
] | 1,584,262,458 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 248 | 307,200 | n = int(input())
y = list(input().split())
y = [int(i) for i in y]
a, b = map(int, input().split())
count = 0
for i in range(b - a):
count += y[a - 1]
a += 1
print(count)
| Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible.
Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream.
Input Specification:
The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated.
Output Specification:
Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*.
Demo Input:
['3\n5 6\n1 2\n', '3\n5 6\n1 3\n']
Demo Output:
['5\n', '11\n']
Note:
none | ```python
n = int(input())
y = list(input().split())
y = [int(i) for i in y]
a, b = map(int, input().split())
count = 0
for i in range(b - a):
count += y[a - 1]
a += 1
print(count)
``` | 3.937428 |
283 | C | Coin Troubles | PROGRAMMING | 2,100 | [
"dp"
] | null | null | In the Isle of Guernsey there are *n* different types of coins. For each *i* (1<=≤<=*i*<=≤<=*n*), coin of type *i* is worth *a**i* cents. It is possible that *a**i*<==<=*a**j* for some *i* and *j* (*i*<=≠<=*j*).
Bessie has some set of these coins totaling *t* cents. She tells Jessie *q* pairs of integers. For each *i* (1<=≤<=*i*<=≤<=*q*), the pair *b**i*,<=*c**i* tells Jessie that Bessie has a strictly greater number of coins of type *b**i* than coins of type *c**i*. It is known that all *b**i* are distinct and all *c**i* are distinct.
Help Jessie find the number of possible combinations of coins Bessie could have. Two combinations are considered different if there is some *i* (1<=≤<=*i*<=≤<=*n*), such that the number of coins Bessie has of type *i* is different in the two combinations. Since the answer can be very large, output it modulo 1000000007 (109<=+<=7).
If there are no possible combinations of coins totaling *t* cents that satisfy Bessie's conditions, output 0. | The first line contains three space-separated integers, *n*,<=*q* and *t* (1<=≤<=*n*<=≤<=300; 0<=≤<=*q*<=≤<=*n*; 1<=≤<=*t*<=≤<=105). The second line contains *n* space separated integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). The next *q* lines each contain two distinct space-separated integers, *b**i* and *c**i* (1<=≤<=*b**i*,<=*c**i*<=≤<=*n*; *b**i*<=≠<=*c**i*).
It's guaranteed that all *b**i* are distinct and all *c**i* are distinct. | A single integer, the number of valid coin combinations that Bessie could have, modulo 1000000007 (109<=+<=7). | [
"4 2 17\n3 1 2 5\n4 2\n3 4\n",
"3 2 6\n3 1 1\n1 2\n2 3\n",
"3 2 10\n1 2 3\n1 2\n2 1\n"
] | [
"3\n",
"0\n",
"0\n"
] | For the first sample, the following 3 combinations give a total of 17 cents and satisfy the given conditions: {0 *of* *type* 1, 1 *of* *type* 2, 3 *of* *type* 3, 2 *of* *type* 4}, {0, 0, 6, 1}, {2, 0, 3, 1}.
No other combinations exist. Note that even though 4 occurs in both *b*<sub class="lower-index">*i*</sub> and *c*<sub class="lower-index">*i*</sub>, the problem conditions are still satisfied because all *b*<sub class="lower-index">*i*</sub> are distinct and all *c*<sub class="lower-index">*i*</sub> are distinct. | 1,500 | [
{
"input": "4 2 17\n3 1 2 5\n4 2\n3 4",
"output": "3"
},
{
"input": "3 2 6\n3 1 1\n1 2\n2 3",
"output": "0"
},
{
"input": "3 2 10\n1 2 3\n1 2\n2 1",
"output": "0"
},
{
"input": "10 0 97\n7 2 10 5 10 5 8 9 6 2",
"output": "823423"
},
{
"input": "10 2 11\n4 9 3 1 4 10 2 6 10 8\n3 6\n6 4",
"output": "0"
},
{
"input": "10 4 18\n9 2 8 2 7 4 9 5 10 9\n7 9\n9 2\n2 5\n5 10",
"output": "0"
},
{
"input": "10 0 96374\n9 4 9 8 4 1 10 1 6 6",
"output": "38660230"
},
{
"input": "10 5 857\n3 9 8 10 10 5 3 3 8 1\n6 9\n9 2\n2 7\n4 3\n8 10",
"output": "396987358"
},
{
"input": "10 5 78\n6 5 9 10 3 7 10 10 5 7\n2 10\n10 6\n6 8\n8 5\n5 1",
"output": "0"
},
{
"input": "30 25 100000\n75 56 61 47 71 52 59 75 30 12 43 29 2 3 37 58 32 47 36 49 51 16 3 25 22 61 63 20 18 8\n15 17\n17 28\n28 18\n18 16\n16 12\n8 9\n9 19\n19 13\n13 7\n7 29\n24 5\n5 6\n6 20\n20 4\n4 26\n26 2\n2 30\n30 1\n1 22\n22 25\n25 27\n27 23\n23 10\n10 11\n11 21",
"output": "219045999"
},
{
"input": "50 20 63791\n63 66 35 40 94 85 40 41 56 76 96 78 3 57 65 27 46 49 53 79 39 77 61 64 47 27 11 41 98 96 98 67 74 9 22 87 22 68 94 43 13 53 24 30 2 72 1 26 18 3\n35 34\n9 4\n4 27\n6 36\n23 7\n37 3\n3 12\n21 39\n39 22\n22 47\n47 14\n14 29\n24 30\n30 18\n18 20\n43 8\n49 13\n33 16\n16 38\n38 42",
"output": "612038014"
},
{
"input": "70 50 34755\n5 2 5 3 2 1 4 2 5 2 2 4 1 2 1 1 1 3 5 2 1 1 3 5 4 2 4 5 4 2 5 3 2 1 3 2 4 3 2 5 5 3 4 1 2 4 3 4 1 4 4 3 2 3 1 1 5 1 3 5 5 5 4 4 4 3 3 3 5 1\n68 39\n39 60\n60 6\n19 41\n41 24\n24 45\n2 57\n15 29\n29 34\n34 56\n56 51\n51 43\n43 46\n46 21\n23 12\n12 66\n66 3\n3 54\n54 17\n17 28\n28 70\n70 4\n4 33\n26 48\n48 9\n1 49\n49 67\n67 11\n11 55\n55 38\n38 30\n30 20\n20 18\n18 40\n40 13\n13 10\n10 61\n61 36\n27 65\n65 59\n59 58\n32 22\n22 53\n53 50\n50 63\n63 35\n7 69\n31 14\n14 8\n8 37",
"output": "955052"
},
{
"input": "50 46 74793\n1 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 1 1 2 1 2 1 2 1 1 1 1 1 1 2 1 1 2 2 2 1 1 2 1 1 2 1 2 1 2 2 1 2 1 2\n47 14\n14 19\n19 22\n22 2\n2 8\n50 10\n10 42\n42 23\n23 34\n34 49\n46 28\n28 32\n32 33\n33 7\n7 43\n43 18\n18 13\n13 41\n41 27\n27 20\n20 12\n12 35\n35 39\n39 1\n1 9\n9 5\n5 21\n21 31\n31 24\n24 6\n6 48\n38 15\n15 4\n4 45\n45 25\n25 26\n26 17\n17 36\n36 11\n11 16\n16 37\n37 44\n44 29\n29 3\n3 30\n30 40",
"output": "775295641"
},
{
"input": "10 9 20\n1 6 3 6 8 5 5 4 5 7\n1 6\n6 9\n9 3\n3 10\n10 7\n7 1\n4 8\n8 5\n5 4",
"output": "0"
},
{
"input": "50 48 40000\n63 28 99 26 67 25 3 64 13 95 4 99 76 70 87 74 95 62 29 72 55 19 70 53 87 46 98 47 46 17 92 23 60 67 82 5 60 5 70 47 90 78 51 98 98 67 8 62 11 23\n27 5\n5 24\n24 47\n47 48\n48 31\n31 28\n28 46\n46 49\n49 15\n15 12\n12 35\n35 22\n22 45\n45 34\n34 39\n39 7\n7 13\n13 41\n41 40\n40 23\n23 18\n18 29\n29 50\n50 33\n33 42\n42 3\n3 26\n26 38\n38 44\n44 36\n36 30\n4 20\n20 17\n17 16\n16 10\n10 32\n32 25\n25 9\n9 6\n6 21\n21 2\n2 14\n14 19\n19 8\n8 1\n1 37\n37 11\n11 43",
"output": "53"
},
{
"input": "50 47 100000\n7 5 24 30 17 22 29 19 13 26 3 8 30 8 28 9 1 1 6 19 15 1 7 1 26 13 23 25 9 10 3 8 18 10 5 25 4 21 26 24 14 30 22 7 18 27 24 14 1 24\n41 3\n3 50\n50 22\n22 48\n48 11\n11 20\n20 26\n26 19\n19 37\n37 27\n27 39\n39 38\n38 28\n28 15\n15 44\n44 29\n29 49\n49 25\n25 10\n10 6\n6 14\n14 35\n35 18\n18 46\n46 34\n34 24\n24 32\n32 5\n45 8\n8 30\n30 33\n33 16\n16 40\n40 12\n12 36\n36 2\n2 4\n4 42\n42 47\n47 7\n7 43\n43 21\n21 31\n31 13\n13 17\n23 9\n9 1",
"output": "674759362"
},
{
"input": "50 10 71619\n9251 4973 9076 8848 9107 2558 2275 7571 5109 7491 1830 8047 1253 4354 2819 843 8258 309 7712 3697 333 4133 9159 7038 8903 7841 5620 9776 4262 3336 3413 982 2240 2666 3977 8531 5693 7770 7041 1851 56 2286 4946 7012 7743 861 2545 9526 702 591\n43 7\n38 45\n10 3\n3 41\n41 22\n22 35\n35 15\n15 20\n20 13\n13 1",
"output": "0"
},
{
"input": "50 49 100000\n4 30 4 36 35 20 47 49 3 32 41 10 28 48 49 28 22 2 41 5 30 31 37 4 49 43 50 10 15 32 44 6 18 50 35 28 18 5 7 49 12 29 26 33 4 38 36 24 44 22\n16 19\n19 17\n17 35\n35 46\n46 4\n4 21\n21 44\n44 40\n40 43\n43 42\n42 37\n37 18\n18 6\n6 32\n32 41\n41 14\n14 50\n50 45\n45 29\n29 39\n39 31\n31 13\n13 9\n9 30\n30 12\n12 10\n10 20\n20 2\n2 8\n8 24\n24 27\n27 5\n5 15\n15 7\n7 1\n1 3\n3 26\n26 25\n25 23\n23 48\n48 36\n36 49\n49 33\n33 28\n28 38\n38 47\n47 11\n11 22\n22 34",
"output": "225562046"
},
{
"input": "50 30 53347\n3252 5324 6506 402 3117 2734 470 1071 1023 5163 5382 1705 6580 7739 5124 9916 5938 9186 4562 9088 9082 5291 349 6807 9253 7645 2364 5707 7479 424 3584 5922 6126 8326 659 9515 6802 7372 939 1088 7732 5768 6965 3508 9760 6930 2044 2948 3677 5917\n50 43\n21 6\n4 24\n8 45\n20 41\n41 39\n39 3\n3 36\n36 37\n37 48\n48 33\n33 11\n11 44\n32 25\n25 2\n2 42\n42 7\n7 16\n16 31\n31 14\n14 49\n49 12\n12 46\n46 13\n13 47\n47 5\n5 15\n15 23\n23 35\n35 40",
"output": "0"
},
{
"input": "50 31 52896\n904 2140 4069 1417 138 1915 3856 252 60 413 2872 2395 753 833 4875 4646 1088 502 432 1367 1201 2874 4696 3577 3272 2544 911 4228 3921 1624 859 4062 57 3386 4540 4002 4123 1330 3690 2541 2504 2541 3370 1931 1061 4546 4649 4286 4793 4218\n31 32\n32 49\n49 15\n26 1\n11 48\n44 19\n19 16\n16 24\n33 6\n6 5\n5 38\n38 21\n23 13\n13 50\n50 36\n36 28\n17 39\n14 37\n37 34\n2 42\n7 30\n30 43\n43 40\n40 47\n47 20\n20 3\n41 8\n8 22\n22 46\n46 27\n29 18",
"output": "0"
},
{
"input": "50 0 97423\n807 8376 3868 6622 2094 1422 1424 6555 8441 789 2763 9375 6605 3659 7592 3493 5387 1609 4795 17 9866 6511 3266 6436 2158 9355 1846 5956 4198 1248 2217 8086 9591 5841 3768 1142 9236 1525 9321 5147 1703 3521 7947 2214 3110 6804 9034 3233 3024 900",
"output": "89229105"
},
{
"input": "50 0 92199\n7437 3796 6996 16720 6903 11061 7623 2072 4645 8613 3446 18466 18584 7824 9332 19439 10793 673 16520 15655 2047 5639 19181 13743 15732 11668 14380 12371 7315 9368 15523 8061 19484 16106 1409 18875 11711 13535 11462 16892 3068 1904 8647 6323 14025 17848 2121 7218 12971 8659",
"output": "43914666"
},
{
"input": "50 0 80851\n2677 3535 2535 3273 2782 1614 4729 3131 1577 2702 1711 1453 4783 4940 624 873 2801 230 1498 4530 92 1116 1662 141 1869 4832 4127 721 2884 1544 1337 193 2698 4745 4084 2462 4108 4939 4671 4695 3791 2577 3959 914 588 3567 4871 1946 1507 4316",
"output": "637731835"
},
{
"input": "50 10 67762\n387 938 646 600 703 181 159 382 802 874 147 227 201 301 119 35 546 33 923 691 780 29 727 916 938 913 71 350 136 593 247 253 692 304 312 56 373 678 264 532 775 138 21 980 581 296 355 292 733 180\n44 42\n20 22\n38 34\n34 2\n39 4\n4 30\n28 31\n41 7\n7 45\n45 43",
"output": "451068924"
},
{
"input": "10 3 74157\n45942 42089 40710 33249 7260 3064 27937 2605 40339 20319\n3 8\n4 7\n6 9",
"output": "0"
},
{
"input": "10 4 94133\n90 51 89 78 36 92 96 60 94 13\n8 7\n7 9\n9 2\n10 4",
"output": "389321092"
},
{
"input": "5 1 94696\n43240 46244 30822 15658 36578\n3 5",
"output": "0"
},
{
"input": "5 3 94384\n47463 49802 36765 6547 34115\n4 2\n3 5\n5 1",
"output": "0"
},
{
"input": "4 2 64391\n21936 49650 27547 43105\n3 2\n2 4",
"output": "0"
},
{
"input": "150 10 69\n2 2 1 2 2 1 2 1 1 1 1 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 1 2 2 1 2 2 1 1 2 1 2 1 2 1 2 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 1 2 2 1 2 1 1 2 2 1 1 1 2 1 2 1 1 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 2 2 1 2 2 2 1 1 2 1 2 2 1 2 1 2 1 2 2 1 2 1 1 1 1 2 2 2 2 1 1 2 1 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2\n147 9\n42 108\n143 131\n52 112\n86 79\n92 4\n29 72\n26 80\n80 40\n63 32",
"output": "881565073"
},
{
"input": "150 10 44\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n100 43\n63 24\n149 78\n78 139\n136 143\n67 16\n73 32\n20 59\n12 61\n57 116",
"output": "760159310"
},
{
"input": "150 10 190\n1 2 1 2 2 2 1 1 1 1 2 1 1 2 2 2 2 1 1 1 1 2 1 2 2 2 1 2 1 2 1 1 1 1 1 1 1 2 2 1 1 2 1 2 2 2 1 1 1 1 2 1 1 1 2 1 2 2 1 2 2 2 2 1 2 1 2 2 2 2 1 1 2 1 2 1 2 1 2 2 2 1 2 2 1 1 1 1 1 2 2 1 2 1 1 2 2 2 2 1 1 2 2 1 2 2 1 2 2 2 2 1 1 2 2 2 1 1 2 1 1 2 1 1 1 1 1 2 2 2 2 1 2 1 1 2 1 2 2 1 1 2 1 2 2 1 2 1 1 1\n7 55\n35 41\n150 76\n76 34\n45 110\n62 1\n97 20\n20 79\n145 133\n133 14",
"output": "734591180"
},
{
"input": "150 2 16\n2 3 2 2 2 2 2 2 1 1 2 3 1 2 2 3 2 3 1 2 1 1 1 1 2 3 3 1 2 3 3 3 3 2 2 3 3 1 1 2 3 3 1 3 2 1 1 2 2 2 3 1 2 1 3 3 1 2 1 1 2 1 3 2 1 3 2 2 1 2 1 1 2 2 3 3 2 2 3 2 1 1 2 2 1 3 1 1 1 2 2 3 1 3 3 3 3 2 3 3 3 2 1 3 2 1 3 2 1 3 2 3 3 2 2 1 3 2 2 2 1 2 1 3 1 1 3 3 1 1 1 3 3 3 2 3 1 2 1 3 2 3 3 2 1 2 2 2 2 3\n2 131\n131 43",
"output": "905924923"
},
{
"input": "150 3 25\n1 3 3 3 3 2 1 3 2 1 1 3 1 3 1 1 2 2 2 2 1 1 3 3 3 1 2 3 2 1 3 2 3 3 3 1 3 3 2 2 3 3 2 3 3 3 2 3 2 3 3 2 2 1 2 1 2 2 2 3 1 1 2 3 3 1 3 2 1 1 1 2 3 2 3 3 3 1 2 3 3 3 2 1 2 2 1 2 3 1 3 2 3 2 1 2 1 2 1 2 3 3 2 1 2 1 1 2 2 2 1 3 3 1 3 1 1 3 2 1 1 3 2 3 3 3 1 1 2 1 3 2 2 2 2 3 2 1 3 3 1 3 2 3 3 1 3 3 3 1\n133 100\n100 7\n82 105",
"output": "130409091"
},
{
"input": "150 4 15\n2 3 3 1 1 3 1 2 3 1 2 2 3 3 2 2 3 3 1 1 3 3 1 2 1 1 2 2 3 3 1 2 1 1 2 3 2 1 1 3 1 1 1 3 3 2 2 1 1 3 1 3 2 2 3 3 1 2 3 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 3 1 2 3 1 2 3 1 2 1 3 2 2 3 1 1 1 1 2 3 1 1 1 1 3 2 2 2 3 2 1 2 2 2 1 1 3 2 2 3 2 2 2 3 3 1 2 1 2 3 3 3 3 3 1 1 2 3 1 1 1 3 1 1 3 1 3 1 2 3 1 3 1 2 1 2\n97 80\n101 138\n105 14\n14 131",
"output": "734625463"
},
{
"input": "200 4 32\n1 1 2 3 1 1 3 1 2 1 3 2 1 1 1 1 2 1 3 1 1 2 2 1 3 2 2 1 1 3 1 1 1 3 1 3 1 2 1 3 1 1 1 1 1 2 3 1 1 1 1 1 3 1 1 3 2 3 2 2 1 3 1 1 3 2 1 3 3 1 1 2 3 2 3 1 2 2 1 1 1 3 3 3 1 1 1 1 2 3 1 1 3 1 3 3 3 1 1 3 2 3 1 1 2 3 1 1 1 2 3 2 2 3 2 3 1 3 2 3 3 3 1 2 3 3 2 3 2 2 3 3 1 1 3 1 2 2 1 1 3 3 1 2 2 2 1 2 3 2 1 3 3 3 1 2 1 3 1 1 2 2 2 3 2 3 1 2 1 3 2 2 3 1 2 3 2 2 2 1 2 1 2 2 1 1 2 1 2 1 3 3 1 3 3 3 2 2 2 1\n41 92\n32 39\n39 191\n133 47",
"output": "639007649"
},
{
"input": "200 5 37\n1 3 3 1 2 2 3 3 2 2 2 2 2 1 2 2 2 2 2 3 1 2 3 1 1 2 2 3 3 2 2 2 2 3 3 2 1 2 2 2 2 2 3 2 2 2 2 1 3 3 2 2 2 3 1 2 2 1 1 2 1 3 1 3 3 2 3 2 3 1 2 3 2 1 2 3 2 1 1 3 3 2 2 2 2 2 3 2 3 1 2 2 3 2 1 3 3 3 2 1 2 2 1 1 1 3 2 2 2 1 1 1 3 1 3 2 3 3 2 3 1 2 1 2 3 2 3 2 1 1 1 2 1 1 3 3 3 2 1 3 1 3 2 3 3 1 2 1 2 3 2 2 3 1 3 2 1 2 2 1 3 3 3 1 1 2 2 1 1 3 2 2 3 3 1 1 1 1 2 3 2 2 1 3 3 1 1 2 1 1 2 1 1 3 2 1 1 2 1 1\n31 86\n86 6\n114 70\n70 170\n113 124",
"output": "863037024"
},
{
"input": "200 5 31\n2 1 2 3 3 3 1 1 2 3 2 2 3 3 3 3 2 2 2 2 3 3 1 2 2 3 1 3 1 2 3 2 1 2 3 2 1 2 3 1 3 1 1 1 1 2 1 1 2 1 2 3 3 2 3 3 2 1 1 3 2 1 2 2 3 1 2 2 2 1 2 1 3 1 2 2 1 1 3 2 3 2 2 2 2 2 2 2 1 3 3 3 2 2 3 1 2 1 2 2 2 1 2 1 2 3 2 2 2 1 2 1 3 2 1 3 3 3 1 1 1 2 3 3 1 1 3 2 2 2 3 1 2 3 3 2 3 3 3 2 3 2 3 2 1 1 3 3 1 3 2 1 2 1 3 2 3 1 2 3 3 1 2 3 3 2 3 2 3 2 2 3 3 2 1 3 1 2 1 1 2 2 3 3 1 3 2 1 3 1 2 3 1 3 2 1 3 1 2 1\n168 181\n53 143\n143 17\n17 62\n157 192",
"output": "442696153"
},
{
"input": "200 5 49\n8 6 4 7 7 6 10 6 10 10 2 1 8 5 1 10 9 6 6 7 1 3 7 4 2 3 10 8 8 9 10 2 8 8 4 3 9 10 3 9 2 4 6 9 2 6 6 6 4 10 9 5 6 5 10 4 8 7 2 8 2 10 9 3 6 4 9 1 9 7 6 7 9 2 1 7 4 4 7 8 7 7 7 10 1 10 1 1 2 10 1 10 7 7 10 7 2 2 2 2 6 8 5 6 6 10 5 9 7 1 4 2 1 7 4 2 5 10 2 5 5 4 5 2 8 2 3 10 3 10 8 7 2 9 8 5 5 2 9 8 7 7 1 4 4 8 5 1 8 1 9 4 3 1 1 1 9 4 8 10 9 9 7 7 1 10 5 5 2 8 3 2 9 10 4 1 4 9 4 3 10 9 4 4 1 9 7 8 2 7 7 4 2 9 6 5 5 7 10 5\n25 185\n185 34\n34 150\n18 107\n169 73",
"output": "831914771"
},
{
"input": "3 2 10\n1 2 3\n1 2\n2 1",
"output": "0"
},
{
"input": "5 5 100\n1 2 3 4 5\n1 2\n2 3\n3 1\n4 5\n5 4",
"output": "0"
},
{
"input": "3 2 4\n1 1 1\n1 2\n2 1",
"output": "0"
},
{
"input": "4 2 17\n3 1 2 5\n4 2\n2 4",
"output": "0"
}
] | 1,665,481,385 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 76 | 312 | 2,969,600 | '''
有n种价值为a[i]的硬币,某人拥有总值为t的硬币,已知q对数字(b,c)中,所有的b之间不同、
所有的c之间不同,其拥有的第b种币数量>第c种。求所有可能的方案数,并取模。
方案数为0的情况:数对表示的大小关系形成环(dfs检测环)
进行预处理之后使用完全背包
'''
R,P,G=lambda:map(int,input().split()),print,range;n,q,t=R();n+=1;a=[0]+[*R()]
# 图的预处理这块没看明白
g,d=[0]*n,[0]*n
for _ in G(q):u,v=R();g[u]=v;d[v]+=1
c=0
for u in G(1,n):
if d[u]==0:
s=0;v=u
while t>=0 and v>0:
c+=1;s+=a[v];a[v]=s
if g[v]>0:t-=s
v=g[v]
if t<0:break
if t<0 or c<n-1:exit(P(0))
f=[1]+[0]*t
for i in G(1,n):
for x in G(a[i],t+1):
f[x]+=f[x-a[i]];f[x]%=(10**9+7)
P(f[t]) | Title: Coin Troubles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the Isle of Guernsey there are *n* different types of coins. For each *i* (1<=≤<=*i*<=≤<=*n*), coin of type *i* is worth *a**i* cents. It is possible that *a**i*<==<=*a**j* for some *i* and *j* (*i*<=≠<=*j*).
Bessie has some set of these coins totaling *t* cents. She tells Jessie *q* pairs of integers. For each *i* (1<=≤<=*i*<=≤<=*q*), the pair *b**i*,<=*c**i* tells Jessie that Bessie has a strictly greater number of coins of type *b**i* than coins of type *c**i*. It is known that all *b**i* are distinct and all *c**i* are distinct.
Help Jessie find the number of possible combinations of coins Bessie could have. Two combinations are considered different if there is some *i* (1<=≤<=*i*<=≤<=*n*), such that the number of coins Bessie has of type *i* is different in the two combinations. Since the answer can be very large, output it modulo 1000000007 (109<=+<=7).
If there are no possible combinations of coins totaling *t* cents that satisfy Bessie's conditions, output 0.
Input Specification:
The first line contains three space-separated integers, *n*,<=*q* and *t* (1<=≤<=*n*<=≤<=300; 0<=≤<=*q*<=≤<=*n*; 1<=≤<=*t*<=≤<=105). The second line contains *n* space separated integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). The next *q* lines each contain two distinct space-separated integers, *b**i* and *c**i* (1<=≤<=*b**i*,<=*c**i*<=≤<=*n*; *b**i*<=≠<=*c**i*).
It's guaranteed that all *b**i* are distinct and all *c**i* are distinct.
Output Specification:
A single integer, the number of valid coin combinations that Bessie could have, modulo 1000000007 (109<=+<=7).
Demo Input:
['4 2 17\n3 1 2 5\n4 2\n3 4\n', '3 2 6\n3 1 1\n1 2\n2 3\n', '3 2 10\n1 2 3\n1 2\n2 1\n']
Demo Output:
['3\n', '0\n', '0\n']
Note:
For the first sample, the following 3 combinations give a total of 17 cents and satisfy the given conditions: {0 *of* *type* 1, 1 *of* *type* 2, 3 *of* *type* 3, 2 *of* *type* 4}, {0, 0, 6, 1}, {2, 0, 3, 1}.
No other combinations exist. Note that even though 4 occurs in both *b*<sub class="lower-index">*i*</sub> and *c*<sub class="lower-index">*i*</sub>, the problem conditions are still satisfied because all *b*<sub class="lower-index">*i*</sub> are distinct and all *c*<sub class="lower-index">*i*</sub> are distinct. | ```python
'''
有n种价值为a[i]的硬币,某人拥有总值为t的硬币,已知q对数字(b,c)中,所有的b之间不同、
所有的c之间不同,其拥有的第b种币数量>第c种。求所有可能的方案数,并取模。
方案数为0的情况:数对表示的大小关系形成环(dfs检测环)
进行预处理之后使用完全背包
'''
R,P,G=lambda:map(int,input().split()),print,range;n,q,t=R();n+=1;a=[0]+[*R()]
# 图的预处理这块没看明白
g,d=[0]*n,[0]*n
for _ in G(q):u,v=R();g[u]=v;d[v]+=1
c=0
for u in G(1,n):
if d[u]==0:
s=0;v=u
while t>=0 and v>0:
c+=1;s+=a[v];a[v]=s
if g[v]>0:t-=s
v=g[v]
if t<0:break
if t<0 or c<n-1:exit(P(0))
f=[1]+[0]*t
for i in G(1,n):
for x in G(a[i],t+1):
f[x]+=f[x-a[i]];f[x]%=(10**9+7)
P(f[t])
``` | 3 |
|
389 | A | Fox and Number Game | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). | Output a single integer — the required minimal sum. | [
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] | [
"2\n",
"6\n",
"12\n",
"15\n"
] | In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
},
{
"input": "2\n87 58",
"output": "58"
},
{
"input": "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52",
"output": "2028"
},
{
"input": "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96",
"output": "5664"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "10000"
},
{
"input": "100\n70 70 77 42 98 84 56 91 35 21 7 70 77 77 56 63 14 84 56 14 77 77 63 70 14 7 28 91 63 49 21 84 98 56 77 98 98 84 98 14 7 56 49 28 91 98 7 56 14 91 14 98 49 28 98 14 98 98 14 70 35 28 63 28 49 63 63 56 91 98 35 42 42 35 63 35 42 14 63 21 77 56 42 77 35 91 56 21 28 84 56 70 70 91 98 70 84 63 21 98",
"output": "700"
},
{
"input": "39\n63 21 21 42 21 63 21 84 42 21 84 63 42 63 84 84 84 42 42 84 21 63 42 63 42 42 63 42 42 63 84 42 21 84 21 63 42 21 42",
"output": "819"
},
{
"input": "59\n70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70",
"output": "4130"
},
{
"input": "87\n44 88 88 88 88 66 88 22 22 88 88 44 88 22 22 22 88 88 88 88 66 22 88 88 88 88 66 66 44 88 44 44 66 22 88 88 22 44 66 44 88 66 66 22 22 22 22 88 22 22 44 66 88 22 22 88 66 66 88 22 66 88 66 88 66 44 88 44 22 44 44 22 44 88 44 44 44 44 22 88 88 88 66 66 88 44 22",
"output": "1914"
},
{
"input": "15\n63 63 63 63 63 63 63 63 63 63 63 63 63 63 63",
"output": "945"
},
{
"input": "39\n63 77 21 14 14 35 21 21 70 42 21 70 28 77 28 77 7 42 63 7 98 49 98 84 35 70 70 91 14 42 98 7 42 7 98 42 56 35 91",
"output": "273"
},
{
"input": "18\n18 18 18 36 36 36 54 72 54 36 72 54 36 36 36 36 18 36",
"output": "324"
},
{
"input": "46\n71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71",
"output": "3266"
},
{
"input": "70\n66 11 66 11 44 11 44 99 55 22 88 11 11 22 55 44 22 77 44 77 77 22 44 55 88 11 99 99 88 22 77 77 66 11 11 66 99 55 55 44 66 44 77 44 44 55 33 55 44 88 77 77 22 66 33 44 11 22 55 44 22 66 77 33 33 44 44 44 22 33",
"output": "770"
},
{
"input": "10\n60 12 96 48 60 24 60 36 60 60",
"output": "120"
},
{
"input": "20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51",
"output": "1020"
},
{
"input": "50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58",
"output": "2900"
},
{
"input": "98\n70 60 100 30 70 20 30 50 50 30 90 40 30 40 60 80 60 60 80 50 10 80 20 10 20 10 50 70 30 80 30 50 60 90 90 100 60 30 90 20 30 60 90 80 60 60 10 90 10 50 40 40 80 90 100 40 70 40 30 50 60 50 60 30 40 20 90 60 20 20 20 70 60 70 50 100 90 50 20 40 80 60 10 60 50 40 40 10 50 10 40 10 80 100 100 90 10 90",
"output": "980"
},
{
"input": "100\n82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82",
"output": "8200"
},
{
"input": "100\n11 87 77 93 3 54 21 93 9 71 37 23 69 85 74 3 48 99 51 31 56 19 21 96 39 6 4 4 29 69 100 42 1 22 81 53 48 49 81 61 10 7 40 61 7 71 51 59 79 44 50 35 95 80 83 8 98 40 18 94 84 49 52 74 66 69 39 37 100 44 38 62 2 80 46 31 35 53 5 60 21 49 63 55 20 53 80 53 66 34 23 92 77 50 86 63 65 24 12 70",
"output": "100"
},
{
"input": "2\n100 1",
"output": "2"
},
{
"input": "2\n18 30",
"output": "12"
},
{
"input": "2\n3 5",
"output": "2"
},
{
"input": "2\n1 10",
"output": "2"
},
{
"input": "2\n8 5",
"output": "2"
},
{
"input": "5\n2 3 5 8 18",
"output": "5"
},
{
"input": "5\n2 4 1 6 8",
"output": "5"
},
{
"input": "3\n12 10 5",
"output": "3"
},
{
"input": "3\n6 10 15",
"output": "3"
}
] | 1,595,859,682 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 109 | 20,172,800 |
n = int(input())
x = list(map(int, input().split()))
x = sorted(x)
y = []
for i in range(n-1):
y.append(x[-i-1]-x[-i-2])
y.append(x[0])
print(min(y)*n)
| Title: Fox and Number Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output Specification:
Output a single integer — the required minimal sum.
Demo Input:
['2\n1 2\n', '3\n2 4 6\n', '2\n12 18\n', '5\n45 12 27 30 18\n']
Demo Output:
['2\n', '6\n', '12\n', '15\n']
Note:
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | ```python
n = int(input())
x = list(map(int, input().split()))
x = sorted(x)
y = []
for i in range(n-1):
y.append(x[-i-1]-x[-i-2])
y.append(x[0])
print(min(y)*n)
``` | 0 |
|
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 91",
"output": "-48"
},
{
"input": "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49",
"output": "-86"
},
{
"input": "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 -63 -49 -76 48 21 -1 -49 -29 -98 -11 76 26 94",
"output": "-98"
},
{
"input": "88\n63 48 1 -53 -89 -49 64 -70 -49 71 -17 -16 76 81 -26 -50 67 -59 -56 97 2 100 14 18 -91 -80 42 92 -25 -88 59 8 -56 38 48 -71 -78 24 -14 48 -1 69 73 -76 54 16 -92 44 47 33 -34 -17 -81 21 -59 -61 53 26 10 -76 67 35 -29 70 65 -13 -29 81 80 32 74 -6 34 46 57 1 -45 -55 69 79 -58 11 -2 22 -18 -16 -89 -46",
"output": "-91"
},
{
"input": "100\n34 32 88 20 76 53 -71 -39 -98 -10 57 37 63 -3 -54 -64 -78 -82 73 20 -30 -4 22 75 51 -64 -91 29 -52 -48 83 19 18 -47 46 57 -44 95 89 89 -30 84 -83 67 58 -99 -90 -53 92 -60 -5 -56 -61 27 68 -48 52 -95 64 -48 -30 -67 66 89 14 -33 -31 -91 39 7 -94 -54 92 -96 -99 -83 -16 91 -28 -66 81 44 14 -85 -21 18 40 16 -13 -82 -33 47 -10 -40 -19 10 25 60 -34 -89",
"output": "-98"
},
{
"input": "2\n-1 -1",
"output": "NO"
},
{
"input": "3\n-2 -2 -2",
"output": "NO"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "10\n40 71 -85 -85 40 -85 -85 64 -85 47",
"output": "40"
},
{
"input": "23\n-90 -90 -41 -64 -64 -90 -15 10 -43 -90 -64 -64 89 -64 36 47 38 -90 -64 -90 -90 68 -90",
"output": "-64"
},
{
"input": "39\n-97 -93 -42 -93 -97 -93 56 -97 -97 -97 76 -33 -60 91 7 82 17 47 -97 -97 -93 73 -97 12 -97 -97 -97 -97 56 -92 -83 -93 -93 49 -93 -97 -97 -17 -93",
"output": "-93"
},
{
"input": "51\n-21 6 -35 -98 -86 -98 -86 -43 -65 32 -98 -40 96 -98 -98 -98 -98 -86 -86 -98 56 -86 -98 -98 -30 -98 -86 -31 -98 -86 -86 -86 -86 -30 96 -86 -86 -86 -60 25 88 -86 -86 58 31 -47 57 -86 37 44 -83",
"output": "-86"
},
{
"input": "66\n-14 -95 65 -95 -95 -97 -90 -71 -97 -97 70 -95 -95 -97 -95 -27 35 -87 -95 -5 -97 -97 87 34 -49 -95 -97 -95 -97 -95 -30 -95 -97 47 -95 -17 -97 -95 -97 -69 51 -97 -97 -95 -75 87 59 21 63 56 76 -91 98 -97 6 -97 -95 -95 -97 -73 11 -97 -35 -95 -95 -43",
"output": "-95"
},
{
"input": "77\n-67 -93 -93 -92 97 29 93 -93 -93 -5 -93 -7 60 -92 -93 44 -84 68 -92 -93 69 -92 -37 56 43 -93 35 -92 -93 19 -79 18 -92 -93 -93 -37 -93 -47 -93 -92 -92 74 67 19 40 -92 -92 -92 -92 -93 -93 -41 -93 -92 -93 -93 -92 -93 51 -80 6 -42 -92 -92 -66 -12 -92 -92 -3 93 -92 -49 -93 40 62 -92 -92",
"output": "-92"
},
{
"input": "89\n-98 40 16 -87 -98 63 -100 55 -96 -98 -21 -100 -93 26 -98 -98 -100 -89 -98 -5 -65 -28 -100 -6 -66 67 -100 -98 -98 10 -98 -98 -70 7 -98 2 -100 -100 -98 25 -100 -100 -98 23 -68 -100 -98 3 98 -100 -98 -98 -98 -98 -24 -100 -100 -9 -98 35 -100 99 -5 -98 -100 -100 37 -100 -84 57 -98 40 -47 -100 -1 -92 -76 -98 -98 -100 -100 -100 -63 30 21 -100 -100 -100 -12",
"output": "-98"
},
{
"input": "99\n10 -84 -100 -100 73 -64 -100 -94 33 -100 -100 -100 -100 71 64 24 7 -100 -32 -100 -100 77 -100 62 -12 55 45 -100 -100 -80 -100 -100 -100 -100 -100 -100 -100 -100 -100 -39 -48 -100 -34 47 -100 -100 -100 -100 -100 -77 -100 -100 -100 -100 -100 -100 -52 40 -55 -100 -44 -100 72 33 70 -100 -100 -78 -100 -3 100 -77 22 -100 95 -30 -100 10 -69 -100 -100 -100 -100 52 -39 -100 -100 -100 7 -100 -98 -66 95 -17 -100 52 -100 68 -100",
"output": "-98"
},
{
"input": "100\n-99 -98 -64 89 53 57 -99 29 -78 18 -3 -54 76 -98 -99 -98 37 -98 19 -47 89 73 -98 -91 -99 -99 -98 -48 -99 22 -99 -98 -99 -99 -98 -60 84 67 -99 -98 20 -98 88 -98 46 -98 -99 -98 -99 -71 -99 -98 -98 -39 83 95 -98 63 -98 -99 32 -98 -99 -64 57 -30 -53 -83 -4 -99 58 20 -98 -10 -99 -44 -99 -99 -99 -99 75 34 -98 -52 -98 -30 -98 -99 -98 -98 51 -99 -99 -99 -98 -99 -99 -82 -90 92",
"output": "-98"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "3\n1 3 2",
"output": "2"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "9\n99 99 99 99 100 100 100 100 100",
"output": "100"
},
{
"input": "5\n-100 -100 -100 -100 -100",
"output": "NO"
}
] | 1,653,409,277 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 10 | 92 | 0 | n = int(input())
li1 = [int(x) for x in input().split()]
li2 = []
c = 0
if len(li1) > 1:
for i in li1:
if i not in li2:
li2.append(i)
li2.sort()
print(li2[1])
else:
print('NO')
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output Specification:
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Demo Input:
['4\n1 2 2 -4\n', '5\n1 2 3 1 1\n']
Demo Output:
['1\n', '2\n']
Note:
none | ```python
n = int(input())
li1 = [int(x) for x in input().split()]
li2 = []
c = 0
if len(li1) > 1:
for i in li1:
if i not in li2:
li2.append(i)
li2.sort()
print(li2[1])
else:
print('NO')
``` | -1 |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
"output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000"
},
{
"input": "2\n-1000000000 1000000000",
"output": "2000000000 2000000000\n2000000000 2000000000"
},
{
"input": "10\n1 10 12 15 59 68 130 912 1239 9123",
"output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122"
},
{
"input": "5\n-2 -1 0 1 2",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "5\n-2 -1 0 1 3",
"output": "1 5\n1 4\n1 3\n1 3\n2 5"
},
{
"input": "3\n-10000 1 10000",
"output": "10001 20000\n9999 10001\n9999 20000"
},
{
"input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706",
"output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010"
},
{
"input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124",
"output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524"
},
{
"input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292",
"output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307"
},
{
"input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986",
"output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14"
},
{
"input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886",
"output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..."
},
{
"input": "3\n-1000000000 999999999 1000000000",
"output": "1999999999 2000000000\n1 1999999999\n1 2000000000"
}
] | 1,679,777,613 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 6,963,200 | n = int(input())
cities = [int(num) for num in input().split()]
for city in cities:
distances = []
for c in cities:
if c == city:
continue
if c > city:
distances.append(c - city)
else:
distances.append(city - c)
print(min(distances), max(distances))
| Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Output Specification:
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
Demo Input:
['4\n-5 -2 2 7\n', '2\n-1 1\n']
Demo Output:
['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n']
Note:
none | ```python
n = int(input())
cities = [int(num) for num in input().split()]
for city in cities:
distances = []
for c in cities:
if c == city:
continue
if c > city:
distances.append(c - city)
else:
distances.append(city - c)
print(min(distances), max(distances))
``` | 0 |
|
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:
The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.
If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).
For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain\nB man\nD woman\nC child\nE rat",
"output": "E\nD\nC\nB\nA"
},
{
"input": "10\nCap captain\nD child\nC woman\nA woman\nE child\nMan man\nB child\nF woman\nRat rat\nRatt rat",
"output": "Rat\nRatt\nD\nC\nA\nE\nB\nF\nMan\nCap"
},
{
"input": "5\nJoyxnkypf captain\nDxssgr woman\nKeojmnpd rat\nGdv man\nHnw man",
"output": "Keojmnpd\nDxssgr\nGdv\nHnw\nJoyxnkypf"
},
{
"input": "11\nJue rat\nWyglbyphk rat\nGjlgu child\nGi man\nAttx rat\nTheorpkgx man\nYm rat\nX child\nB captain\nEnualf rat\nKktsgyuyv woman",
"output": "Jue\nWyglbyphk\nAttx\nYm\nEnualf\nGjlgu\nX\nKktsgyuyv\nGi\nTheorpkgx\nB"
},
{
"input": "22\nWswwcvvm woman\nBtmfats rat\nI rat\nOcmtsnwx man\nUrcqv rat\nYghnogt woman\nWtyfc man\nWqle child\nUjfrelpu rat\nDstixj man\nAhksnio woman\nKhkvaap woman\nSjppvwm rat\nEgdmsv rat\nDank rat\nNquicjnw rat\nLh captain\nTdyaqaqln rat\nQtj rat\nTfgwijvq rat\nNbiso child\nNqthvbf woman",
"output": "Btmfats\nI\nUrcqv\nUjfrelpu\nSjppvwm\nEgdmsv\nDank\nNquicjnw\nTdyaqaqln\nQtj\nTfgwijvq\nWswwcvvm\nYghnogt\nWqle\nAhksnio\nKhkvaap\nNbiso\nNqthvbf\nOcmtsnwx\nWtyfc\nDstixj\nLh"
},
{
"input": "36\nKqxmtwmsf child\nIze woman\nDlpr child\nK woman\nF captain\nRjwfeuhba rat\nBbv rat\nS rat\nMnmg woman\nSmzyx woman\nSr man\nQmhroracn rat\nSoqpuqock rat\nPibdq man\nIlrkrptx rat\nZaecfyqka man\nMmersfs child\nVvvocqi man\nHjeqxvq rat\nMpmb woman\nWmgu woman\nCerelmhoxi child\nA man\nDylv man\nXrdgmmtcpq woman\nXj woman\nCeh child\nOfccguo man\nNevr man\nAknkwdkq child\nBmo man\nLqo woman\nVej child\nT child\nRlijc man\nNsdtpdg woman",
"output": "Rjwfeuhba\nBbv\nS\nQmhroracn\nSoqpuqock\nIlrkrptx\nHjeqxvq\nKqxmtwmsf\nIze\nDlpr\nK\nMnmg\nSmzyx\nMmersfs\nMpmb\nWmgu\nCerelmhoxi\nXrdgmmtcpq\nXj\nCeh\nAknkwdkq\nLqo\nVej\nT\nNsdtpdg\nSr\nPibdq\nZaecfyqka\nVvvocqi\nA\nDylv\nOfccguo\nNevr\nBmo\nRlijc\nF"
},
{
"input": "2\nA captain\nB man",
"output": "B\nA"
},
{
"input": "2\nB woman\nA captain",
"output": "B\nA"
},
{
"input": "2\nX child\nY captain",
"output": "X\nY"
},
{
"input": "2\nX captain\nY rat",
"output": "Y\nX"
},
{
"input": "6\nAbdelrhman captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nAbdelrhman"
},
{
"input": "4\nAratos captain\nMind child\nAman woman\nCarrot man",
"output": "Mind\nAman\nCarrot\nAratos"
}
] | 1,580,761,017 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 216 | 307,200 | n = int(input())
in_list = []
cap = ""
rats = []
kd_w = []
m = []
for i in range(n):
curr = input()
mark = curr.split(" ")[1]
name = curr.split(" ")[0]
if mark == "rat":
rats.append(name)
elif mark == "woman" or mark == "child":
kd_w.append(name)
elif mark == "man":
m.append(name)
else:
cap = name
for i in rats:
print(i)
for i in kd_w:
print(i)
for i in m:
print(i)
print(cap)
| Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:
The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.
If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).
For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew.
Input Specification:
The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain.
Output Specification:
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
Demo Input:
['6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n']
Demo Output:
['Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n']
Note:
none | ```python
n = int(input())
in_list = []
cap = ""
rats = []
kd_w = []
m = []
for i in range(n):
curr = input()
mark = curr.split(" ")[1]
name = curr.split(" ")[0]
if mark == "rat":
rats.append(name)
elif mark == "woman" or mark == "child":
kd_w.append(name)
elif mark == "man":
m.append(name)
else:
cap = name
for i in rats:
print(i)
for i in kd_w:
print(i)
for i in m:
print(i)
print(cap)
``` | 3.945428 |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer. | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"input": "71 85 88",
"output": "17"
},
{
"input": "30 38 99",
"output": "69"
},
{
"input": "23 82 95",
"output": "72"
},
{
"input": "22 41 47",
"output": "25"
},
{
"input": "9 94 77",
"output": "85"
},
{
"input": "1 53 51",
"output": "52"
},
{
"input": "25 97 93",
"output": "72"
},
{
"input": "42 53 51",
"output": "11"
},
{
"input": "81 96 94",
"output": "15"
},
{
"input": "21 5 93",
"output": "88"
},
{
"input": "50 13 75",
"output": "62"
},
{
"input": "41 28 98",
"output": "70"
},
{
"input": "69 46 82",
"output": "36"
},
{
"input": "87 28 89",
"output": "61"
},
{
"input": "44 45 40",
"output": "5"
},
{
"input": "86 97 68",
"output": "29"
},
{
"input": "43 92 30",
"output": "62"
},
{
"input": "16 70 1",
"output": "69"
},
{
"input": "40 46 19",
"output": "27"
},
{
"input": "71 38 56",
"output": "33"
},
{
"input": "82 21 80",
"output": "61"
},
{
"input": "75 8 35",
"output": "67"
},
{
"input": "75 24 28",
"output": "51"
},
{
"input": "78 23 56",
"output": "55"
},
{
"input": "85 31 10",
"output": "75"
},
{
"input": "76 50 9",
"output": "67"
},
{
"input": "95 37 34",
"output": "61"
},
{
"input": "84 61 35",
"output": "49"
},
{
"input": "87 85 37",
"output": "50"
},
{
"input": "1 3 2",
"output": "2"
},
{
"input": "4 2 6",
"output": "4"
},
{
"input": "6 9 3",
"output": "6"
},
{
"input": "12 4 8",
"output": "8"
},
{
"input": "15 10 5",
"output": "10"
},
{
"input": "1 50 17",
"output": "49"
},
{
"input": "10 5 15",
"output": "10"
},
{
"input": "8 1 9",
"output": "8"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "2 1 3",
"output": "2"
},
{
"input": "1 8 2",
"output": "7"
},
{
"input": "1 100 2",
"output": "99"
},
{
"input": "1 4 6",
"output": "5"
}
] | 1,690,001,418 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | a = list(map(int, input().split()))
a.sort()
print(a[2]-a[0]) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer.
Input Specification:
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Output Specification:
Print one integer — the minimum total distance the friends need to travel in order to meet together.
Demo Input:
['7 1 4\n', '30 20 10\n']
Demo Output:
['6\n', '20\n']
Note:
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | ```python
a = list(map(int, input().split()))
a.sort()
print(a[2]-a[0])
``` | 3 |
|
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period. | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash. | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6",
"output": "3"
},
{
"input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32",
"output": "6"
},
{
"input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30",
"output": "10"
},
{
"input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20",
"output": "8"
},
{
"input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49",
"output": "1"
},
{
"input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16",
"output": "5"
},
{
"input": "2\n0 24\n1 0",
"output": "1"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "1\n1 5",
"output": "1"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "3"
},
{
"input": "1\n5 0",
"output": "1"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "5"
},
{
"input": "1\n10 10",
"output": "1"
},
{
"input": "1\n8 0",
"output": "1"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "10"
},
{
"input": "2\n0 0\n0 1",
"output": "1"
},
{
"input": "2\n8 5\n8 5",
"output": "2"
}
] | 1,626,456,942 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 6,963,200 | d=[]
f=[]
for i in range(int(input())):
a,b=map(int,input().split())
d.append(a)
f.append(b)
g=0
for i in range(len(d)):
j=d[i]
l=f[i]
k=i
for i in range(k+1,len(d)):
if j==d[i] and l==f[i]:
g+=1
print(1+g) | Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period.
Output Specification:
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
Demo Input:
['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash. | ```python
d=[]
f=[]
for i in range(int(input())):
a,b=map(int,input().split())
d.append(a)
f.append(b)
g=0
for i in range(len(d)):
j=d[i]
l=f[i]
k=i
for i in range(k+1,len(d)):
if j==d[i] and l==f[i]:
g+=1
print(1+g)
``` | 0 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,635,329,970 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 186 | 17,715,200 | n = int(input())
a, b, c = 0, 0, 0
for i in range(n):
d, e, f = map(int, input().split())
a += d
b += e
c += f
print('YES' if a == 0 and b == 0 and c == 0 else 'NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input())
a, b, c = 0, 0, 0
for i in range(n):
d, e, f = map(int, input().split())
a += d
b += e
c += f
print('YES' if a == 0 and b == 0 and c == 0 else 'NO')
``` | 3.920503 |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected? | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one. | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428",
"output": "25720377\n661369649"
},
{
"input": "3\n796067435 964699482 819602309\n964699482 796067435\n964699482",
"output": "819602309\n796067435"
},
{
"input": "3\n374054998 726316780 902899520\n902899520 726316780\n726316780",
"output": "374054998\n902899520"
},
{
"input": "3\n168638990 939116221 323703261\n168638990 323703261\n168638990",
"output": "939116221\n323703261"
},
{
"input": "3\n77 77 77\n77 77\n77",
"output": "77\n77"
},
{
"input": "3\n84 30 9\n9 84\n9",
"output": "30\n84"
},
{
"input": "6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3",
"output": "5\n5"
},
{
"input": "4\n1 5 7 8\n1 5 7\n1 5",
"output": "8\n7"
}
] | 1,665,969,935 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 170 | 9,523,200 | input()
soma_erros_1 = 0
for erro in list(map(int, input().split())):
soma_erros_1 += erro
soma_erros_2 = 0
for erro in list(map(int, input().split())):
soma_erros_2 += erro
soma_erros_3 = 0
for erro in list(map(int, input().split())):
soma_erros_3 += erro
erro_solucionado_1 = soma_erros_1 - soma_erros_2
erro_solucionado_2 = soma_erros_2 - soma_erros_3
print(erro_solucionado_1)
print(erro_solucionado_2)
| Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected?
Input Specification:
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Output Specification:
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
Demo Input:
['5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n', '6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n']
Demo Output:
['8\n123\n', '1\n3\n']
Note:
In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | ```python
input()
soma_erros_1 = 0
for erro in list(map(int, input().split())):
soma_erros_1 += erro
soma_erros_2 = 0
for erro in list(map(int, input().split())):
soma_erros_2 += erro
soma_erros_3 = 0
for erro in list(map(int, input().split())):
soma_erros_3 += erro
erro_solucionado_1 = soma_erros_1 - soma_erros_2
erro_solucionado_2 = soma_erros_2 - soma_erros_3
print(erro_solucionado_1)
print(erro_solucionado_2)
``` | 3 |
|
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.
Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese.
Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient. | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7 3 9\n100",
"output": "10"
},
{
"input": "BSC\n100 1 1\n100 1 1\n100",
"output": "51"
},
{
"input": "SBBCCSBB\n1 50 100\n31 59 21\n100000",
"output": "370"
},
{
"input": "BBBBCCCCCCCCCCCCCCCCCCCCSSSSBBBBBBBBSS\n100 100 100\n1 1 1\n3628800",
"output": "95502"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n200",
"output": "0"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n2000",
"output": "1"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300",
"output": "0"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300000000",
"output": "42858"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n914159265358",
"output": "130594181"
},
{
"input": "SSSSSSSSSSBBBBBBBBBCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSBB\n31 53 97\n13 17 31\n914159265358",
"output": "647421579"
},
{
"input": "BBBCSBSBBSSSSCCCCBBCSBBBBSSBBBCBSCCSSCSSCSBSSSCCCCBSCSSBSSSCCCBBCCCSCBCBBCCSCCCCSBBCCBBBBCCCCCCBSSCB\n91 87 17\n64 44 43\n958532915587",
"output": "191668251"
},
{
"input": "CSSCBBCCCSBSCBBBCSBBBCBSBCSCBCSCBCBSBCBCSSBBSBBCBBBBSCSBBCCBCCBCBBSBSBCSCSBBSSBBCSSBCSCSCCSSBCBBCBSB\n56 34 48\n78 6 96\n904174875419",
"output": "140968956"
},
{
"input": "CCSCCCSBBBSCBSCSCCSSBBBSSBBBSBBBCBCSSBCSCBBCCCBCBCBCCCSSBSBBCCCCCBBSCBSCBCBBCBBCSSBCSBSSCCSCCSCCBBBS\n33 73 67\n4 56 42\n886653164314",
"output": "277425898"
},
{
"input": "SBCSSCBBSSBCSSBBBSSBSCBSSSCBBSBBBBCSBCSBSCBSCBSCBSBSSCCCCBSBCCBCBSCCCBSCCBSBBCBSSCCCCSBSBBBSSSBCSCBC\n94 16 85\n14 18 91\n836590091442",
"output": "217522127"
},
{
"input": "BSCSBSCCSCSSCCCSBCSSBCBBSCCBSCCSSSSSSSSSCCSBSCCBBCBBSBSCCCCBCSBSBSSBBBBBSSBSSCBCCSSBSSSCBBCSBBSBCCCB\n67 54 8\n36 73 37\n782232051273",
"output": "154164772"
},
{
"input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSSBSBSCBBSBBCSSSSBBBBSBBCBCSBBCBCSSBBCSBSCCSCSBCSCBSCCBBCSC\n71 71 52\n52 88 3\n654400055575",
"output": "137826467"
},
{
"input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCSC\n100 1 1\n1 17 23\n954400055575",
"output": "1355681897"
},
{
"input": "C\n100 100 100\n1 1 1\n1000000000000",
"output": "1000000000100"
},
{
"input": "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n100 100 100\n100 100 100\n1000000000000",
"output": "100000001"
},
{
"input": "B\n100 100 100\n1 1 1\n1",
"output": "101"
},
{
"input": "SC\n2 1 1\n1 1 1\n100000000000",
"output": "50000000001"
},
{
"input": "B\n100 1 1\n1 1 1\n1000000000000",
"output": "1000000000100"
},
{
"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n1 1 1\n100 100 100\n1000000000000",
"output": "100000000"
},
{
"input": "CC\n1 1 1\n100 100 100\n1",
"output": "0"
},
{
"input": "B\n100 100 100\n1 1 1\n1000000000000",
"output": "1000000000100"
},
{
"input": "BSC\n100 100 100\n1 1 1\n1000000000000",
"output": "333333333433"
},
{
"input": "BSC\n100 100 100\n1 1 1\n1",
"output": "100"
}
] | 1,675,221,905 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 62 | 1,433,600 | recipe = input()
bread = recipe.count("B")
sausage = recipe.count("S")
cheese = recipe.count("C")
nB, nS, nC = map(int, input().split())
nBP, nSP, nCP = map(int, input().split())
rubles = int(input())
burger = 0
total_price = bread * nBP + sausage * nSP + cheese * nCP
if bread == 0:
nB = 0
if sausage == 0:
nS = 0
if cheese == 0:
nC = 0
while nB - bread >= 0 and nS - sausage >= 0 and nC - cheese >= 0:
nB -= bread
nS -= sausage
nC -= cheese
burger += 1
if nB < 0 or nS < 0 or nC < 0:
burger -= 1
break
for i in range(rubles):
if nB == nS == nC == 0:
burger += rubles // total_price
break
if nB - bread < 0:
if rubles - nBP * abs(nB - bread) >= 0:
rubles -= nBP * abs(nB - bread)
nB += abs(nB - bread)
if nS - sausage < 0:
if rubles - nSP * abs(nS - sausage) >= 0:
rubles -= nSP * abs(nS - sausage)
nS += abs(nS - sausage)
if nC - cheese < 0:
if rubles - (nCP * abs(nC - cheese)) >= 0:
rubles -= nCP * abs(nC - cheese)
nC += abs(nC - cheese)
u = 0
while nB - bread >= 0 and nS - sausage >= 0 and nC - cheese >= 0 and u == 0:
nB -= bread
nS -= sausage
nC -= cheese
burger += 1
if nB < 0 or nS < 0 or nC < 0:
burger -= 1
u = 1
print(burger) | Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.
Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese.
Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.
Input Specification:
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
Demo Input:
['BBBSSC\n6 4 1\n1 2 3\n4\n', 'BBC\n1 10 1\n1 10 1\n21\n', 'BSC\n1 1 1\n1 1 3\n1000000000000\n']
Demo Output:
['2\n', '7\n', '200000000001\n']
Note:
none | ```python
recipe = input()
bread = recipe.count("B")
sausage = recipe.count("S")
cheese = recipe.count("C")
nB, nS, nC = map(int, input().split())
nBP, nSP, nCP = map(int, input().split())
rubles = int(input())
burger = 0
total_price = bread * nBP + sausage * nSP + cheese * nCP
if bread == 0:
nB = 0
if sausage == 0:
nS = 0
if cheese == 0:
nC = 0
while nB - bread >= 0 and nS - sausage >= 0 and nC - cheese >= 0:
nB -= bread
nS -= sausage
nC -= cheese
burger += 1
if nB < 0 or nS < 0 or nC < 0:
burger -= 1
break
for i in range(rubles):
if nB == nS == nC == 0:
burger += rubles // total_price
break
if nB - bread < 0:
if rubles - nBP * abs(nB - bread) >= 0:
rubles -= nBP * abs(nB - bread)
nB += abs(nB - bread)
if nS - sausage < 0:
if rubles - nSP * abs(nS - sausage) >= 0:
rubles -= nSP * abs(nS - sausage)
nS += abs(nS - sausage)
if nC - cheese < 0:
if rubles - (nCP * abs(nC - cheese)) >= 0:
rubles -= nCP * abs(nC - cheese)
nC += abs(nC - cheese)
u = 0
while nB - bread >= 0 and nS - sausage >= 0 and nC - cheese >= 0 and u == 0:
nB -= bread
nS -= sausage
nC -= cheese
burger += 1
if nB < 0 or nS < 0 or nC < 0:
burger -= 1
u = 1
print(burger)
``` | 3 |
|
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.
For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation.
Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.
Satisfy Arkady's curiosity and tell him the final version of the name. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*. | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e",
"output": "lellelleel"
}
] | 1,485,728,450 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 6,963,200 | import sys
size,swaps=map(int,sys.stdin.readline().split())
word=list(input())
alp=list('abcdefghijklmnopqrstuvwxyz')
for i in range(swaps):
a,b=map(str,sys.stdin.readline().split())
for j in range(26):
if alp[j]==a:
alp[j]=b
elif alp[j]==b:
alp[j]=a
for i in range(size):
print(alp[ord(word[i])-97],end='')
| Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.
For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation.
Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.
Satisfy Arkady's curiosity and tell him the final version of the name.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*.
Output Specification:
Print the new name of the corporation.
Demo Input:
['6 1\npolice\np m\n', '11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n']
Demo Output:
['molice\n', 'cdcbcdcfcdc\n']
Note:
In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
import sys
size,swaps=map(int,sys.stdin.readline().split())
word=list(input())
alp=list('abcdefghijklmnopqrstuvwxyz')
for i in range(swaps):
a,b=map(str,sys.stdin.readline().split())
for j in range(26):
if alp[j]==a:
alp[j]=b
elif alp[j]==b:
alp[j]=a
for i in range(size):
print(alp[ord(word[i])-97],end='')
``` | 0 |
|
66 | A | Petya and Java | PROGRAMMING | 1,300 | [
"implementation",
"strings"
] | A. Petya and Java | 2 | 256 | Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger.
But having attended several classes of the club, Petya realized that not all tasks require using the BigInteger type. It turned out that in some tasks it is much easier to use small data types. That's why a question arises: "Which integer type to use if one wants to store a positive integer *n*?"
Petya knows only 5 integer types:
1) byte occupies 1 byte and allows you to store numbers from <=-<=128 to 127
2) short occupies 2 bytes and allows you to store numbers from <=-<=32768 to 32767
3) int occupies 4 bytes and allows you to store numbers from <=-<=2147483648 to 2147483647
4) long occupies 8 bytes and allows you to store numbers from <=-<=9223372036854775808 to 9223372036854775807
5) BigInteger can store any integer number, but at that it is not a primitive type, and operations with it are much slower.
For all the types given above the boundary values are included in the value range.
From this list, Petya wants to choose the smallest type that can store a positive integer *n*. Since BigInteger works much slower, Peter regards it last. Help him. | The first line contains a positive number *n*. It consists of no more than 100 digits and doesn't contain any leading zeros. The number *n* can't be represented as an empty string.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | Print the first type from the list "byte, short, int, long, BigInteger", that can store the natural number *n*, in accordance with the data given above. | [
"127\n",
"130\n",
"123456789101112131415161718192021222324\n"
] | [
"byte\n",
"short\n",
"BigInteger\n"
] | none | 500 | [
{
"input": "127",
"output": "byte"
},
{
"input": "130",
"output": "short"
},
{
"input": "123456789101112131415161718192021222324",
"output": "BigInteger"
},
{
"input": "6",
"output": "byte"
},
{
"input": "16",
"output": "byte"
},
{
"input": "126",
"output": "byte"
},
{
"input": "128",
"output": "short"
},
{
"input": "32766",
"output": "short"
},
{
"input": "111111",
"output": "int"
},
{
"input": "22222",
"output": "short"
},
{
"input": "32767",
"output": "short"
},
{
"input": "32768",
"output": "int"
},
{
"input": "32769",
"output": "int"
},
{
"input": "2147483645",
"output": "int"
},
{
"input": "2147483646",
"output": "int"
},
{
"input": "2147483647",
"output": "int"
},
{
"input": "2147483648",
"output": "long"
},
{
"input": "2147483649",
"output": "long"
},
{
"input": "9223372036854775805",
"output": "long"
},
{
"input": "9223372036854775806",
"output": "long"
},
{
"input": "9223372036854775807",
"output": "long"
},
{
"input": "9223372036854775808",
"output": "BigInteger"
},
{
"input": "9223372036854775809",
"output": "BigInteger"
},
{
"input": "1111111111111111111111111111111111111111111111",
"output": "BigInteger"
},
{
"input": "232",
"output": "short"
},
{
"input": "241796563564014133460267652699",
"output": "BigInteger"
},
{
"input": "29360359146807441660707083821018832188095237636414144034857851003419752010124705615779249",
"output": "BigInteger"
},
{
"input": "337300529263821789926982715723773719445001702036602052198530564",
"output": "BigInteger"
},
{
"input": "381127467969689863953686682245136076127159921",
"output": "BigInteger"
},
{
"input": "2158324958633591462",
"output": "long"
},
{
"input": "268659422768117401499491767189496733446324586965055954729177892248858259490346",
"output": "BigInteger"
},
{
"input": "3023764505449745844381036446038799100004717936344985",
"output": "BigInteger"
},
{
"input": "13408349824892484976400774",
"output": "BigInteger"
},
{
"input": "18880842614378213198381172973704766723997934818440985546083314104481253291692101136681",
"output": "BigInteger"
},
{
"input": "1180990956946757129733650596194933741",
"output": "BigInteger"
},
{
"input": "73795216631038776655609800540262114612084443385902708034055020082090470662930545328551",
"output": "BigInteger"
},
{
"input": "1658370691480968202384509492140362150472696196949",
"output": "BigInteger"
},
{
"input": "59662093286671707493190399502717308574459619342109544431740791973099298641871347858082458491958703",
"output": "BigInteger"
},
{
"input": "205505005582428018613354752739589866670902346355933720701937",
"output": "BigInteger"
},
{
"input": "53348890623013817139699",
"output": "BigInteger"
},
{
"input": "262373979958859125198440634134122707574734706745701184688685117904709744",
"output": "BigInteger"
},
{
"input": "69113784278456828987289369893745977",
"output": "BigInteger"
},
{
"input": "2210209454022702335652564247406666491086662454147967686455330365147159266087",
"output": "BigInteger"
},
{
"input": "630105816139991597267787581532092408135",
"output": "BigInteger"
},
{
"input": "800461429306907809762708270",
"output": "BigInteger"
},
{
"input": "7685166910821197056344900917707673568669808490600751439157",
"output": "BigInteger"
},
{
"input": "713549841568602590705962611607726022334779480510421458817648621376683672722573289661127894",
"output": "BigInteger"
},
{
"input": "680504312323996476676434432",
"output": "BigInteger"
},
{
"input": "3376595620091080825479292544658464163405755746884100218035",
"output": "BigInteger"
},
{
"input": "303681723783491968617491075591006152690484825330764215796396316561122383310011589365655481",
"output": "BigInteger"
},
{
"input": "4868659422768117401499491767189496733446324586965055954729177892248858259490346614099717639491763430",
"output": "BigInteger"
},
{
"input": "3502376450544974584438103644603879910000471793634498544789130945841846713263971487355748226237288709",
"output": "BigInteger"
},
{
"input": "2334083498248924849764007740114454487565621932425948046430072197452845278935316358800789014185793377",
"output": "BigInteger"
},
{
"input": "1988808426143782131983811729737047667239979348184409855460833141044812532916921011366813880911319644",
"output": "BigInteger"
},
{
"input": "1018099095694675712973365059619493374113337270925179793757322992466016001294122941535439492265169131",
"output": "BigInteger"
},
{
"input": "8437952166310387766556098005402621146120844433859027080340550200820904706629305453285512716464931911",
"output": "BigInteger"
},
{
"input": "6965837069148096820238450949214036215047269619694967357734070611376013382163559966747678150791825071",
"output": "BigInteger"
},
{
"input": "4596620932866717074931903995027173085744596193421095444317407919730992986418713478580824584919587030",
"output": "BigInteger"
},
{
"input": "1905505005582428018613354752739589866670902346355933720701937408006000562951996789032987808118459990",
"output": "BigInteger"
},
{
"input": "8433488906230138171396997888322916936677429522910871017295155818340819168386140293774243244435122950",
"output": "BigInteger"
},
{
"input": "6862373979958859125198440634134122707574734706745701184688685117904709744830303784215298687654884810",
"output": "BigInteger"
},
{
"input": "4491137842784568289872893698937459777201151060689848471272003426250808340375567208957554901863756992",
"output": "BigInteger"
},
{
"input": "9721020945402270233565256424740666649108666245414796768645533036514715926608741510409618545180420952",
"output": "BigInteger"
},
{
"input": "7330105816139991597267787581532092408135003429259616955239761315950805521264994021242873979309182812",
"output": "BigInteger"
},
{
"input": "2000461429306907809762708270752707617318091579531521957022940951538737203583768926365382290530636885",
"output": "BigInteger"
},
{
"input": "9868516691082119705634490091770767356866980849060075143915700796802700437762260163478754592094654326",
"output": "BigInteger"
},
{
"input": "8713549841568602590705962611607726022334779480510421458817648621376683672722573289661127894678771177",
"output": "BigInteger"
},
{
"input": "4580504312323996476676434432646986768872786931159974634901608445720467716981185426771899006352697916",
"output": "BigInteger"
},
{
"input": "2537659562009108082547929254465846416340575574688410021803548570097340949141688442074263189944614467",
"output": "BigInteger"
},
{
"input": "1403681723783491968617491075591006152690484825330764215796396316561122383310011589365655481428540208",
"output": "BigInteger"
},
{
"input": "26",
"output": "byte"
},
{
"input": "302376450544",
"output": "long"
},
{
"input": "13",
"output": "byte"
},
{
"input": "188808426143",
"output": "long"
},
{
"input": "118099095694675",
"output": "long"
},
{
"input": "73795216631038",
"output": "long"
},
{
"input": "1658370691480",
"output": "long"
},
{
"input": "596620932866",
"output": "long"
},
{
"input": "2055050055",
"output": "int"
},
{
"input": "533488906",
"output": "int"
},
{
"input": "26237397",
"output": "int"
},
{
"input": "6911378",
"output": "int"
},
{
"input": "221020945402270233",
"output": "long"
},
{
"input": "63010581613999159",
"output": "long"
},
{
"input": "80046142930",
"output": "long"
},
{
"input": "7685166910821197",
"output": "long"
},
{
"input": "71",
"output": "byte"
},
{
"input": "6805043123239964766",
"output": "long"
},
{
"input": "3376",
"output": "short"
},
{
"input": "3036817237",
"output": "long"
}
] | 1,630,202,026 | 2,147,483,647 | Python 3 | OK | TESTS | 90 | 154 | 6,758,400 | N=int(input())
if(-128<=N<=127):
print('byte')
elif(-32768<=N<=32767):
print('short')
elif(-2147483648<=N<=2147483647):
print('int')
elif((-(2**63))<=N<=(2**63-1)):
print('long')
else:
print('BigInteger') | Title: Petya and Java
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger.
But having attended several classes of the club, Petya realized that not all tasks require using the BigInteger type. It turned out that in some tasks it is much easier to use small data types. That's why a question arises: "Which integer type to use if one wants to store a positive integer *n*?"
Petya knows only 5 integer types:
1) byte occupies 1 byte and allows you to store numbers from <=-<=128 to 127
2) short occupies 2 bytes and allows you to store numbers from <=-<=32768 to 32767
3) int occupies 4 bytes and allows you to store numbers from <=-<=2147483648 to 2147483647
4) long occupies 8 bytes and allows you to store numbers from <=-<=9223372036854775808 to 9223372036854775807
5) BigInteger can store any integer number, but at that it is not a primitive type, and operations with it are much slower.
For all the types given above the boundary values are included in the value range.
From this list, Petya wants to choose the smallest type that can store a positive integer *n*. Since BigInteger works much slower, Peter regards it last. Help him.
Input Specification:
The first line contains a positive number *n*. It consists of no more than 100 digits and doesn't contain any leading zeros. The number *n* can't be represented as an empty string.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Output Specification:
Print the first type from the list "byte, short, int, long, BigInteger", that can store the natural number *n*, in accordance with the data given above.
Demo Input:
['127\n', '130\n', '123456789101112131415161718192021222324\n']
Demo Output:
['byte\n', 'short\n', 'BigInteger\n']
Note:
none | ```python
N=int(input())
if(-128<=N<=127):
print('byte')
elif(-32768<=N<=32767):
print('short')
elif(-2147483648<=N<=2147483647):
print('int')
elif((-(2**63))<=N<=(2**63-1)):
print('long')
else:
print('BigInteger')
``` | 3.948911 |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 91",
"output": "-48"
},
{
"input": "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49",
"output": "-86"
},
{
"input": "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 -63 -49 -76 48 21 -1 -49 -29 -98 -11 76 26 94",
"output": "-98"
},
{
"input": "88\n63 48 1 -53 -89 -49 64 -70 -49 71 -17 -16 76 81 -26 -50 67 -59 -56 97 2 100 14 18 -91 -80 42 92 -25 -88 59 8 -56 38 48 -71 -78 24 -14 48 -1 69 73 -76 54 16 -92 44 47 33 -34 -17 -81 21 -59 -61 53 26 10 -76 67 35 -29 70 65 -13 -29 81 80 32 74 -6 34 46 57 1 -45 -55 69 79 -58 11 -2 22 -18 -16 -89 -46",
"output": "-91"
},
{
"input": "100\n34 32 88 20 76 53 -71 -39 -98 -10 57 37 63 -3 -54 -64 -78 -82 73 20 -30 -4 22 75 51 -64 -91 29 -52 -48 83 19 18 -47 46 57 -44 95 89 89 -30 84 -83 67 58 -99 -90 -53 92 -60 -5 -56 -61 27 68 -48 52 -95 64 -48 -30 -67 66 89 14 -33 -31 -91 39 7 -94 -54 92 -96 -99 -83 -16 91 -28 -66 81 44 14 -85 -21 18 40 16 -13 -82 -33 47 -10 -40 -19 10 25 60 -34 -89",
"output": "-98"
},
{
"input": "2\n-1 -1",
"output": "NO"
},
{
"input": "3\n-2 -2 -2",
"output": "NO"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "10\n40 71 -85 -85 40 -85 -85 64 -85 47",
"output": "40"
},
{
"input": "23\n-90 -90 -41 -64 -64 -90 -15 10 -43 -90 -64 -64 89 -64 36 47 38 -90 -64 -90 -90 68 -90",
"output": "-64"
},
{
"input": "39\n-97 -93 -42 -93 -97 -93 56 -97 -97 -97 76 -33 -60 91 7 82 17 47 -97 -97 -93 73 -97 12 -97 -97 -97 -97 56 -92 -83 -93 -93 49 -93 -97 -97 -17 -93",
"output": "-93"
},
{
"input": "51\n-21 6 -35 -98 -86 -98 -86 -43 -65 32 -98 -40 96 -98 -98 -98 -98 -86 -86 -98 56 -86 -98 -98 -30 -98 -86 -31 -98 -86 -86 -86 -86 -30 96 -86 -86 -86 -60 25 88 -86 -86 58 31 -47 57 -86 37 44 -83",
"output": "-86"
},
{
"input": "66\n-14 -95 65 -95 -95 -97 -90 -71 -97 -97 70 -95 -95 -97 -95 -27 35 -87 -95 -5 -97 -97 87 34 -49 -95 -97 -95 -97 -95 -30 -95 -97 47 -95 -17 -97 -95 -97 -69 51 -97 -97 -95 -75 87 59 21 63 56 76 -91 98 -97 6 -97 -95 -95 -97 -73 11 -97 -35 -95 -95 -43",
"output": "-95"
},
{
"input": "77\n-67 -93 -93 -92 97 29 93 -93 -93 -5 -93 -7 60 -92 -93 44 -84 68 -92 -93 69 -92 -37 56 43 -93 35 -92 -93 19 -79 18 -92 -93 -93 -37 -93 -47 -93 -92 -92 74 67 19 40 -92 -92 -92 -92 -93 -93 -41 -93 -92 -93 -93 -92 -93 51 -80 6 -42 -92 -92 -66 -12 -92 -92 -3 93 -92 -49 -93 40 62 -92 -92",
"output": "-92"
},
{
"input": "89\n-98 40 16 -87 -98 63 -100 55 -96 -98 -21 -100 -93 26 -98 -98 -100 -89 -98 -5 -65 -28 -100 -6 -66 67 -100 -98 -98 10 -98 -98 -70 7 -98 2 -100 -100 -98 25 -100 -100 -98 23 -68 -100 -98 3 98 -100 -98 -98 -98 -98 -24 -100 -100 -9 -98 35 -100 99 -5 -98 -100 -100 37 -100 -84 57 -98 40 -47 -100 -1 -92 -76 -98 -98 -100 -100 -100 -63 30 21 -100 -100 -100 -12",
"output": "-98"
},
{
"input": "99\n10 -84 -100 -100 73 -64 -100 -94 33 -100 -100 -100 -100 71 64 24 7 -100 -32 -100 -100 77 -100 62 -12 55 45 -100 -100 -80 -100 -100 -100 -100 -100 -100 -100 -100 -100 -39 -48 -100 -34 47 -100 -100 -100 -100 -100 -77 -100 -100 -100 -100 -100 -100 -52 40 -55 -100 -44 -100 72 33 70 -100 -100 -78 -100 -3 100 -77 22 -100 95 -30 -100 10 -69 -100 -100 -100 -100 52 -39 -100 -100 -100 7 -100 -98 -66 95 -17 -100 52 -100 68 -100",
"output": "-98"
},
{
"input": "100\n-99 -98 -64 89 53 57 -99 29 -78 18 -3 -54 76 -98 -99 -98 37 -98 19 -47 89 73 -98 -91 -99 -99 -98 -48 -99 22 -99 -98 -99 -99 -98 -60 84 67 -99 -98 20 -98 88 -98 46 -98 -99 -98 -99 -71 -99 -98 -98 -39 83 95 -98 63 -98 -99 32 -98 -99 -64 57 -30 -53 -83 -4 -99 58 20 -98 -10 -99 -44 -99 -99 -99 -99 75 34 -98 -52 -98 -30 -98 -99 -98 -98 51 -99 -99 -99 -98 -99 -99 -82 -90 92",
"output": "-98"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "3\n1 3 2",
"output": "2"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "9\n99 99 99 99 100 100 100 100 100",
"output": "100"
},
{
"input": "5\n-100 -100 -100 -100 -100",
"output": "NO"
}
] | 1,693,412,452 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 124 | 0 | n = int(input())
sequence = list(map(int, input().split()))
unique_sequence = sorted(set(sequence))
if len(unique_sequence) > 1:
print(unique_sequence[1])
else:
print("NO")
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output Specification:
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Demo Input:
['4\n1 2 2 -4\n', '5\n1 2 3 1 1\n']
Demo Output:
['1\n', '2\n']
Note:
none | ```python
n = int(input())
sequence = list(map(int, input().split()))
unique_sequence = sorted(set(sequence))
if len(unique_sequence) > 1:
print(unique_sequence[1])
else:
print("NO")
``` | 3.969 |
928 | A | Login Verification | PROGRAMMING | 1,200 | [
"*special",
"strings"
] | null | null | When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins *s* and *t* are considered similar if we can transform *s* to *t* via a sequence of operations of the following types:
- transform lowercase letters to uppercase and vice versa; - change letter «O» (uppercase latin letter) to digit «0» and vice versa; - change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones. | The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar. | Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes). | [
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] | [
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | 500 | [
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
},
{
"input": "0Lil\n2\nLIL0\n0Ril",
"output": "Yes"
},
{
"input": "iloO\n3\niIl0\noIl0\nIooO",
"output": "Yes"
},
{
"input": "L1il0o1L1\n5\niLLoLL\noOI1Io10il\nIoLLoO\nO01ilOoI\nI10l0o",
"output": "Yes"
},
{
"input": "ELioO1lOoOIOiLoooi1iolul1O\n7\nOoEIuOIl1ui1010uiooOoi0Oio001L0EoEolO0\nOLIoOEuoE11u1u1iLOI0oO\nuEOuO0uIOOlO01OlEI0E1Oo0IO1LI0uE0LILO0\nEOo0Il11iIOOOIiuOiIiiLOLEOOII001EE\niOoO0LOulioE0OLIIIulli01OoiuOOOoOlEiI0EiiElIIu0\nlE1LOE1Oil\n1u0EOliIiIOl1u110il0l1O0u",
"output": "Yes"
},
{
"input": "0blo7X\n20\n1oobb6\nXIXIO2X\n2iYI2\n607XXol\n2I6io22\nOl10I\nbXX0Lo\nolOOb7X\n07LlXL\nlXY17\n12iIX2\n7lL70\nbOo11\n17Y6b62\n0O6L7\n1lX2L\n2iYl6lI\n7bXIi1o\niLIY2\n0OIo1X",
"output": "Yes"
},
{
"input": "lkUL\n25\nIIfL\nokl\nfoo\ni0U\noko\niIoU\nUUv\nvli\nv0Uk\n0Of\niill\n1vkl\nUIf\nUfOO\nlvLO\nUUo0\nIOf1\nlovL\nIkk\noIv\nLvfU\n0UI\nkol\n1OO0\n1OOi",
"output": "Yes"
},
{
"input": "L1lo\n3\nOOo1\nL1lo\n0lOl",
"output": "No"
},
{
"input": "LIoooiLO\n5\nLIoooiLO\nl0o01I00\n0OOl0lLO01\nil10i0\noiloi",
"output": "No"
},
{
"input": "1i1lQI\n7\nuLg1uLLigIiOLoggu\nLLLgIuQIQIIloiQuIIoIO0l0o000\n0u1LQu11oIuooIl0OooLg0i0IQu1O1lloI1\nQuQgIQi0LOIliLOuuuioLQou1l\nlLIO00QLi01LogOliOIggII1\no0Ll1uIOQl10IL0IILQ\n1i1lQI",
"output": "No"
},
{
"input": "oIzz1\n20\n1TTl0O\nloF0LT\n1lLzo\noi0Ov\nFlIF1zT\nzoITzx\n0TIFlT\nl1vllil\nOviix1F\nLFvI1lL\nLIl0loz\nixz1v\n1i1vFi\nTIFTol\noIzz1\nIvTl0o\nxv1U0O\niiiioF\n1oiLUlO\nxToxv1",
"output": "No"
},
{
"input": "00L0\n25\n0il\nIlkZ\nL0I\n00L0\nBd0\nZLd\n0d1k\nddk\nIdl\nkBd\nkBOL\nZ1lI\nkBL\nLOko\noZ0i\nZ1lO\nLiOk\niBld\nLO0d\ndIo\nZ10\n1k1i\n0o0L\nIoBd\ni0B0",
"output": "No"
},
{
"input": "Z\n1\nz",
"output": "No"
},
{
"input": "0\n1\no",
"output": "No"
},
{
"input": "0\n1\nO",
"output": "No"
},
{
"input": "o\n1\n0",
"output": "No"
},
{
"input": "o\n1\nO",
"output": "No"
},
{
"input": "o\n1\no",
"output": "No"
},
{
"input": "O\n1\no",
"output": "No"
},
{
"input": "O\n1\n0",
"output": "No"
},
{
"input": "1\n1\nl",
"output": "No"
},
{
"input": "1\n1\nL",
"output": "No"
},
{
"input": "1\n1\ni",
"output": "No"
},
{
"input": "1\n1\nI",
"output": "No"
},
{
"input": "1\n1\no",
"output": "Yes"
},
{
"input": "i\n1\n1",
"output": "No"
},
{
"input": "i\n1\nL",
"output": "No"
},
{
"input": "i\n1\nl",
"output": "No"
},
{
"input": "I\n1\nL",
"output": "No"
},
{
"input": "I\n1\nl",
"output": "No"
},
{
"input": "I\n1\n1",
"output": "No"
},
{
"input": "l\n1\n1",
"output": "No"
},
{
"input": "l\n1\nL",
"output": "No"
},
{
"input": "l\n1\ni",
"output": "No"
},
{
"input": "l\n1\nI",
"output": "No"
},
{
"input": "L\n1\nl",
"output": "No"
},
{
"input": "L\n1\n1",
"output": "No"
},
{
"input": "L\n1\ni",
"output": "No"
},
{
"input": "L\n1\nI",
"output": "No"
}
] | 1,642,520,390 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 46 | 0 | def tq(q):
for i in range(len(q)):
if q[i]=="l" or q[i]=="i":
q[i]='1'
elif q[i]=="o":
q[i]='0'
p=[]
for i in q:
p+=[i]
return p
s=input()
s=s.lower()
s=list(s)
s=tq(s)
n=int(input())
while n>0:
s1=input()
s1=s1.lower()
s1=list(s1)
s1=tq(s1)
if s==s1:
print("No")
exit()
n-=1
print("Yes")
| Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins *s* and *t* are considered similar if we can transform *s* to *t* via a sequence of operations of the following types:
- transform lowercase letters to uppercase and vice versa; - change letter «O» (uppercase latin letter) to digit «0» and vice versa; - change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
Input Specification:
The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Output Specification:
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
Demo Input:
['1_wat\n2\n2_wat\nwat_1\n', '000\n3\n00\nooA\noOo\n', '_i_\n3\n__i_\n_1_\nI\n', 'La0\n3\n2a0\nLa1\n1a0\n', 'abc\n1\naBc\n', '0Lil\n2\nLIL0\n0Ril\n']
Demo Output:
['Yes\n', 'No\n', 'No\n', 'No\n', 'No\n', 'Yes\n']
Note:
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | ```python
def tq(q):
for i in range(len(q)):
if q[i]=="l" or q[i]=="i":
q[i]='1'
elif q[i]=="o":
q[i]='0'
p=[]
for i in q:
p+=[i]
return p
s=input()
s=s.lower()
s=list(s)
s=tq(s)
n=int(input())
while n>0:
s1=input()
s1=s1.lower()
s1=list(s1)
s1=tq(s1)
if s==s1:
print("No")
exit()
n-=1
print("Yes")
``` | 3 |
|
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully. | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5"
},
{
"input": "111",
"output": "7"
},
{
"input": "112",
"output": "7"
},
{
"input": "745",
"output": "7"
},
{
"input": "23536",
"output": "31"
},
{
"input": "1",
"output": "1"
},
{
"input": "1010011",
"output": "83"
},
{
"input": "312410141",
"output": "511"
},
{
"input": "1000000000",
"output": "512"
},
{
"input": "999999999",
"output": "511"
},
{
"input": "111111111",
"output": "511"
},
{
"input": "101010101",
"output": "341"
},
{
"input": "121212121",
"output": "511"
},
{
"input": "106341103",
"output": "383"
},
{
"input": "901556123",
"output": "511"
},
{
"input": "832513432",
"output": "511"
},
{
"input": "3",
"output": "1"
},
{
"input": "732875234",
"output": "511"
},
{
"input": "7",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "11",
"output": "3"
},
{
"input": "12",
"output": "3"
},
{
"input": "13",
"output": "3"
},
{
"input": "101020101",
"output": "351"
},
{
"input": "111100100",
"output": "484"
},
{
"input": "110110101",
"output": "437"
},
{
"input": "100111001",
"output": "313"
},
{
"input": "100100",
"output": "36"
},
{
"input": "110100102",
"output": "421"
}
] | 1,547,711,555 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 0 | n = list(reversed(input()))
ans = 2 ** len(n) - 1
for i in range(len(n)):
if n[i] == "0":
ans -= 2 ** i
print(ans)
| Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.
Input Specification:
Input data contains the only number *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
Output the only number — answer to the problem.
Demo Input:
['10\n']
Demo Output:
['2']
Note:
For *n* = 10 the answer includes numbers 1 and 10. | ```python
n = list(reversed(input()))
ans = 2 ** len(n) - 1
for i in range(len(n)):
if n[i] == "0":
ans -= 2 ** i
print(ans)
``` | 0 |
719 | B | Anatoly and Cockroaches | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0. | 1,000 | [
{
"input": "5\nrbbrr",
"output": "1"
},
{
"input": "5\nbbbbb",
"output": "2"
},
{
"input": "3\nrbr",
"output": "0"
},
{
"input": "13\nrbbbrbrrbrrbb",
"output": "3"
},
{
"input": "18\nrrrrrrrrrrrrrrrrrb",
"output": "8"
},
{
"input": "100\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbrbbbbbbbbbbbbbbbbrrrrbbbbrrrbbbbbbbrbrrbrbbbbrrrbbbbrbbrbbbrb",
"output": "34"
},
{
"input": "166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb",
"output": "70"
},
{
"input": "1\nr",
"output": "0"
},
{
"input": "1\nb",
"output": "0"
},
{
"input": "2\nrb",
"output": "0"
},
{
"input": "2\nbr",
"output": "0"
},
{
"input": "2\nrr",
"output": "1"
},
{
"input": "2\nbb",
"output": "1"
},
{
"input": "8\nrbbrbrbr",
"output": "1"
},
{
"input": "7\nrrbrbrb",
"output": "1"
}
] | 1,474,735,450 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 109 | 307,200 | #!/usr/bin/env python
#-*-coding:utf-8 -*-
input()
S=4*[0]
e=0
for c in input():
S[e|('r'!=c)<<1]+=1
e=not e
print(min(max(S[0],S[3]),max(S[1],S[2])))
| Title: Anatoly and Cockroaches
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output Specification:
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Demo Input:
['5\nrbbrr\n', '5\nbbbbb\n', '3\nrbr\n']
Demo Output:
['1\n', '2\n', '0\n']
Note:
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0. | ```python
#!/usr/bin/env python
#-*-coding:utf-8 -*-
input()
S=4*[0]
e=0
for c in input():
S[e|('r'!=c)<<1]+=1
e=not e
print(min(max(S[0],S[3]),max(S[1],S[2])))
``` | 3 |
|
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output": "1 2"
},
{
"input": "5\n4 24 6 1 15",
"output": "3 4"
},
{
"input": "2\n511 32",
"output": "1 2"
},
{
"input": "3\n907 452 355",
"output": "2 3"
},
{
"input": "4\n303 872 764 401",
"output": "4 1"
},
{
"input": "10\n684 698 429 694 956 812 594 170 937 764",
"output": "1 2"
},
{
"input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695",
"output": "7 8"
},
{
"input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000",
"output": "12 13"
},
{
"input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58",
"output": "16 17"
},
{
"input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000",
"output": "1 2"
},
{
"input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4",
"output": "1 2"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "86 87"
},
{
"input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25",
"output": "7 8"
},
{
"input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964",
"output": "1 2"
},
{
"input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967",
"output": "81 82"
},
{
"input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17",
"output": "36 37"
}
] | 1,630,511,898 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 154 | 6,963,200 | n=int(input())
l=[int(x) for x in input().split()]
c=abs(l[0]-l[1])
ind=0
for i in range(1,n-1):
if abs(l[i]-l[i+1])<c:
c=abs(l[i]-l[i+1])
ind=i
if abs(l[0]-l[n-1])<c:
ind=n-1
print(ind+1,(ind+1)%n+1) | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output Specification:
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Demo Input:
['5\n10 12 13 15 10\n', '4\n10 20 30 40\n']
Demo Output:
['5 1\n', '1 2\n']
Note:
none | ```python
n=int(input())
l=[int(x) for x in input().split()]
c=abs(l[0]-l[1])
ind=0
for i in range(1,n-1):
if abs(l[i]-l[i+1])<c:
c=abs(l[i]-l[i+1])
ind=i
if abs(l[0]-l[n-1])<c:
ind=n-1
print(ind+1,(ind+1)%n+1)
``` | 3.94853 |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"output": "11 13"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "10",
"output": "3 7"
},
{
"input": "69",
"output": "34 35"
},
{
"input": "100",
"output": "49 51"
},
{
"input": "57",
"output": "28 29"
},
{
"input": "1000",
"output": "499 501"
},
{
"input": "999",
"output": "499 500"
},
{
"input": "998",
"output": "497 501"
},
{
"input": "997",
"output": "498 499"
},
{
"input": "996",
"output": "497 499"
},
{
"input": "995",
"output": "497 498"
},
{
"input": "994",
"output": "495 499"
},
{
"input": "5",
"output": "2 3"
},
{
"input": "6",
"output": "1 5"
},
{
"input": "8",
"output": "3 5"
},
{
"input": "9",
"output": "4 5"
},
{
"input": "423",
"output": "211 212"
},
{
"input": "876",
"output": "437 439"
},
{
"input": "29",
"output": "14 15"
}
] | 1,597,395,828 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = 1
b =2
if (a==b)
print(a) | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
Input Specification:
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output Specification:
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
Demo Input:
['3\n', '4\n', '12\n']
Demo Output:
['1 2\n', '1 3\n', '5 7\n']
Note:
none | ```python
a = 1
b =2
if (a==b)
print(a)
``` | -1 |
|
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once.
You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2. | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2",
"output": "1"
},
{
"input": "15\n1 2 3 4 5 5 4 3 2 1 1 2 3 4 5",
"output": "10"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n5000",
"output": "1"
},
{
"input": "4\n5000 5000 5000 5000",
"output": "4"
},
{
"input": "5\n3366 3461 4 5 4370",
"output": "3"
},
{
"input": "10\n8 2 10 3 4 6 1 7 9 5",
"output": "0"
},
{
"input": "10\n551 3192 3213 2846 3068 1224 3447 1 10 9",
"output": "7"
},
{
"input": "15\n4 1459 12 4281 3241 2748 10 3590 14 845 3518 1721 2 2880 1974",
"output": "10"
},
{
"input": "15\n15 1 8 2 13 11 12 7 3 14 6 10 9 4 5",
"output": "0"
},
{
"input": "15\n2436 2354 4259 1210 2037 2665 700 3578 2880 973 1317 1024 24 3621 4142",
"output": "15"
},
{
"input": "30\n28 1 3449 9 3242 4735 26 3472 15 21 2698 7 4073 3190 10 3 29 1301 4526 22 345 3876 19 12 4562 2535 2 630 18 27",
"output": "14"
},
{
"input": "100\n50 39 95 30 66 78 2169 4326 81 31 74 34 80 40 19 48 97 63 82 6 88 16 21 57 92 77 10 1213 17 93 32 91 38 4375 29 75 44 22 4 45 14 2395 3254 59 3379 2 85 96 8 83 27 94 1512 2960 100 9 73 79 7 25 55 69 90 99 51 87 98 62 18 35 43 4376 4668 28 72 56 4070 61 65 36 54 4106 11 24 15 86 70 71 4087 23 13 76 20 4694 26 4962 4726 37 14 64",
"output": "18"
},
{
"input": "100\n340 14 3275 2283 2673 1107 817 2243 1226 32 2382 3638 4652 418 68 4962 387 764 4647 159 1846 225 2760 4904 3150 403 3 2439 91 4428 92 4705 75 348 1566 1465 69 6 49 4 62 4643 564 1090 3447 1871 2255 139 24 99 2669 969 86 61 4550 158 4537 3993 1589 872 2907 1888 401 80 1825 1483 63 1 2264 4068 4113 2548 41 885 4806 36 67 167 4447 34 1248 2593 82 202 81 1783 1284 4973 16 43 95 7 865 2091 3008 1793 20 947 4912 3604",
"output": "70"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "2\n5000 5000",
"output": "2"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
},
{
"input": "2\n3 4",
"output": "2"
},
{
"input": "10\n1 2 3 4 5 6 7 1000 10 10",
"output": "2"
}
] | 1,420,166,527 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 154 | 307,200 | def main():
n = int(input())
i, res = 1, 0
for a in sorted(map(int, input().split())):
if i <= a <= n:
i = a + 1
else:
res += 1
print(res)
if __name__ == '__main__':
main() | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once.
You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).
Input Specification:
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*).
Output Specification:
Print the only number — the minimum number of changes needed to get the permutation.
Demo Input:
['3\n3 1 2\n', '2\n2 2\n', '5\n5 3 3 3 1\n']
Demo Output:
['0\n', '1\n', '2\n']
Note:
The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2. | ```python
def main():
n = int(input())
i, res = 1, 0
for a in sorted(map(int, input().split())):
if i <= a <= n:
i = a + 1
else:
res += 1
print(res)
if __name__ == '__main__':
main()
``` | 3 |
|
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"input": "H",
"output": "YES"
},
{
"input": "+",
"output": "NO"
},
{
"input": "~",
"output": "NO"
},
{
"input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR",
"output": "YES"
},
{
"input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC",
"output": "YES"
},
{
"input": "@F%K2=%RyL/",
"output": "NO"
},
{
"input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J",
"output": "YES"
},
{
"input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)",
"output": "YES"
},
{
"input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C",
"output": "YES"
},
{
"input": "p-UXsbd&f",
"output": "NO"
},
{
"input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_",
"output": "YES"
},
{
"input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]",
"output": "YES"
},
{
"input": "}do5RU<(w<q[\"-NR)IAH_HyiD{",
"output": "YES"
},
{
"input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8",
"output": "YES"
},
{
"input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv",
"output": "YES"
},
{
"input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`",
"output": "YES"
},
{
"input": "OKBB5z7ud81[Tn@P\"nDUd,>@",
"output": "NO"
},
{
"input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv",
"output": "YES"
},
{
"input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh",
"output": "YES"
},
{
"input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp",
"output": "NO"
},
{
"input": "!3YPv@2JQ44@)R2O_4`GO",
"output": "YES"
},
{
"input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\",
"output": "YES"
},
{
"input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L",
"output": "NO"
},
{
"input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&",
"output": "YES"
},
{
"input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}",
"output": "YES"
},
{
"input": "Uh3>ER](J",
"output": "NO"
},
{
"input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,",
"output": "YES"
},
{
"input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!",
"output": "YES"
},
{
"input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@",
"output": "YES"
},
{
"input": "'jdL(vX",
"output": "NO"
},
{
"input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5",
"output": "YES"
},
{
"input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s",
"output": "YES"
},
{
"input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]",
"output": "YES"
},
{
"input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU",
"output": "YES"
},
{
"input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->",
"output": "YES"
},
{
"input": "&ppw0._:\\p-PuWM@l}%%=",
"output": "NO"
},
{
"input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr",
"output": "YES"
},
{
"input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q",
"output": "YES"
},
{
"input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0",
"output": "YES"
},
{
"input": "VXB&r9Z)IlKOJ:??KDA",
"output": "YES"
},
{
"input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R",
"output": "YES"
},
{
"input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C",
"output": "YES"
},
{
"input": "O.&=qt(`z(",
"output": "NO"
},
{
"input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@",
"output": "YES"
},
{
"input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp",
"output": "YES"
},
{
"input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8",
"output": "YES"
},
{
"input": "!0WKT:$O",
"output": "NO"
},
{
"input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)",
"output": "YES"
},
{
"input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly",
"output": "YES"
},
{
"input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(",
"output": "NO"
},
{
"input": "Qv)X8",
"output": "YES"
},
{
"input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F",
"output": "YES"
},
{
"input": "e{}2vQ+/r@p0}cLKNe4MCk",
"output": "YES"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH",
"output": "YES"
},
{
"input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky",
"output": "YES"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky",
"output": "YES"
},
{
"input": "1H1",
"output": "YES"
},
{
"input": "+Q",
"output": "YES"
},
{
"input": "1ab",
"output": "NO"
},
{
"input": "!",
"output": "NO"
},
{
"input": "0+",
"output": "NO"
},
{
"input": "+H",
"output": "YES"
},
{
"input": "cH",
"output": "YES"
},
{
"input": "+8",
"output": "NO"
},
{
"input": "8+",
"output": "NO"
},
{
"input": "++++++++++++++++++++++++++",
"output": "NO"
},
{
"input": "(+)",
"output": "NO"
},
{
"input": "H+",
"output": "YES"
},
{
"input": "a!",
"output": "NO"
},
{
"input": "++++++++++++++",
"output": "NO"
},
{
"input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
"output": "NO"
},
{
"input": "8",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "HQ9",
"output": "YES"
},
{
"input": "+++H",
"output": "YES"
},
{
"input": "++++++++++",
"output": "NO"
},
{
"input": "HHHHHHH",
"output": "YES"
},
{
"input": "abacabaH",
"output": "YES"
},
{
"input": "+G",
"output": "NO"
}
] | 1,685,819,060 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | a = input()
ans = 0
for i in a:
if i == 'H' or i == 'Q' or i == '9' or i == '+':
print('YES')
break
else:
ans += 1
if ans == len(a):
print('NO') | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
Input Specification:
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output Specification:
Output "YES", if executing the program will produce any output, and "NO" otherwise.
Demo Input:
['Hi!\n', 'Codeforces\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | ```python
a = input()
ans = 0
for i in a:
if i == 'H' or i == 'Q' or i == '9' or i == '+':
print('YES')
break
else:
ans += 1
if ans == len(a):
print('NO')
``` | 0 |
|
940 | B | Our Tanya is Crying Out Loud | PROGRAMMING | 1,400 | [
"dp",
"greedy"
] | null | null | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). | Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. | [
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] | [
"6\n",
"8\n",
"12\n"
] | In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total. | 1,250 | [
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
"output": "16032999235141416"
},
{
"input": "777888456\n1\n98\n43",
"output": "76233068590"
},
{
"input": "1162261467\n3\n1\n2000000000",
"output": "1162261466"
},
{
"input": "1000000000\n1999999999\n789987\n184569875",
"output": "789986999210013"
},
{
"input": "2000000000\n2\n1\n2000000000",
"output": "1999999999"
},
{
"input": "1999888325\n3\n2\n2000000000",
"output": "3333258884"
},
{
"input": "1897546487\n687\n89798979\n879876541",
"output": "110398404423"
},
{
"input": "20\n1\n20\n1",
"output": "380"
},
{
"input": "16\n5\n17\n3",
"output": "54"
},
{
"input": "19\n19\n19\n1",
"output": "1"
},
{
"input": "18\n2\n3\n16",
"output": "40"
},
{
"input": "1\n11\n8\n9",
"output": "0"
},
{
"input": "9\n10\n1\n20",
"output": "8"
},
{
"input": "19\n10\n19\n2",
"output": "173"
},
{
"input": "16\n9\n14\n2",
"output": "100"
},
{
"input": "15\n2\n5\n2",
"output": "21"
},
{
"input": "14\n7\n13\n1",
"output": "14"
},
{
"input": "43\n3\n45\n3",
"output": "189"
},
{
"input": "99\n1\n98\n1",
"output": "9604"
},
{
"input": "77\n93\n100\n77",
"output": "7600"
},
{
"input": "81\n3\n91\n95",
"output": "380"
},
{
"input": "78\n53\n87\n34",
"output": "2209"
},
{
"input": "80\n3\n15\n1",
"output": "108"
},
{
"input": "97\n24\n4\n24",
"output": "40"
},
{
"input": "100\n100\n1\n100",
"output": "99"
},
{
"input": "87\n4\n17\n7",
"output": "106"
},
{
"input": "65\n2\n3\n6",
"output": "36"
},
{
"input": "1000000\n1435\n3\n999999",
"output": "1005804"
},
{
"input": "783464\n483464\n2\n966928",
"output": "1566926"
},
{
"input": "248035\n11\n3\n20",
"output": "202"
},
{
"input": "524287\n2\n945658\n999756",
"output": "34963354"
},
{
"input": "947352\n78946\n85\n789654",
"output": "790589"
},
{
"input": "1000000\n1\n999899\n60",
"output": "999898000101"
},
{
"input": "753687\n977456\n6547\n456",
"output": "4934382242"
},
{
"input": "1000000\n500000\n1\n999997",
"output": "999998"
},
{
"input": "997458\n843596\n1\n843596",
"output": "997457"
},
{
"input": "821109\n92\n6547\n98787",
"output": "394566"
},
{
"input": "1073741823\n2\n9543\n8923453",
"output": "188412866"
},
{
"input": "1000999777\n1934999345\n2356346\n34534565",
"output": "2358701818178496"
},
{
"input": "2000000000\n1\n2000000000\n98",
"output": "3999999998000000000"
},
{
"input": "1999324353\n978435356\n1\n978435356",
"output": "1020888998"
},
{
"input": "2000000000\n2\n2000000000\n2000000000",
"output": "84000000000"
},
{
"input": "241375690\n17\n2\n1998789654",
"output": "482751378"
},
{
"input": "171507000\n350\n789\n6548687",
"output": "14216965"
},
{
"input": "1100220011\n10001\n2\n1999778654",
"output": "1999998674"
},
{
"input": "1867622656\n43216\n789644\n12315468",
"output": "24630936"
},
{
"input": "1867622656\n43216\n1\n1879865413",
"output": "1867622655"
},
{
"input": "1999999999\n1000000000\n789987\n184569875",
"output": "789987183779888"
},
{
"input": "1987987897\n103546\n7\n98754563",
"output": "98946650"
},
{
"input": "10\n2\n2\n5",
"output": "13"
},
{
"input": "7\n2\n1\n100000",
"output": "6"
},
{
"input": "7\n2\n3\n1",
"output": "8"
},
{
"input": "2000000000\n666666667\n1\n1",
"output": "666666668"
},
{
"input": "1999999997\n666666666\n2\n2",
"output": "1333333334"
}
] | 1,519,495,242 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 5,632,000 | n=int(input())
k=int(input())
a=int(input())
b=int(input())
sum=0
x=n
if k==1:
print((n-1)*a)
else:
while x!=1:
if x<k:
sum+=(x-1)*a
x=1
elif x%k!=0:
sum+=(a*(x%k))
x=x-(x%k)
elif ((x-x/k)*a)>=b:
x//=k
sum+=b
elif (x-x/k)*a<b:
x-=1
sum+=a
print(sum)
| Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
Output Specification:
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
Demo Input:
['9\n2\n3\n1\n', '5\n5\n2\n20\n', '19\n3\n4\n2\n']
Demo Output:
['6\n', '8\n', '12\n']
Note:
In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total. | ```python
n=int(input())
k=int(input())
a=int(input())
b=int(input())
sum=0
x=n
if k==1:
print((n-1)*a)
else:
while x!=1:
if x<k:
sum+=(x-1)*a
x=1
elif x%k!=0:
sum+=(a*(x%k))
x=x-(x%k)
elif ((x-x/k)*a)>=b:
x//=k
sum+=b
elif (x-x/k)*a<b:
x-=1
sum+=a
print(sum)
``` | 0 |
|
893 | A | Chess For Three | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.
So they play with each other according to following rules:
- Alex and Bob play the first game, and Carl is spectating; - When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner.
Alex, Bob and Carl play in such a way that there are no draws.
Today they have played *n* games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of games Alex, Bob and Carl played.
Then *n* lines follow, describing the game log. *i*-th line contains one integer *a**i* (1<=≤<=*a**i*<=≤<=3) which is equal to 1 if Alex won *i*-th game, to 2 if Bob won *i*-th game and 3 if Carl won *i*-th game. | Print YES if the situation described in the log was possible. Otherwise print NO. | [
"3\n1\n1\n2\n",
"2\n1\n2\n"
] | [
"YES\n",
"NO\n"
] | In the first example the possible situation is:
1. Alex wins, Carl starts playing instead of Bob; 1. Alex wins, Bob replaces Carl; 1. Bob wins.
The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one. | 0 | [
{
"input": "3\n1\n1\n2",
"output": "YES"
},
{
"input": "2\n1\n2",
"output": "NO"
},
{
"input": "100\n2\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n3\n3\n3\n3\n3\n3\n1\n2\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n3\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n1\n2\n2\n2\n3\n3\n2\n1\n3\n3\n1\n2\n3\n1\n1\n1\n2\n2\n2\n3\n1\n1\n1\n1\n1\n1\n3\n2\n2\n2\n2\n2\n2\n3\n1\n2\n2\n2\n2\n2\n3\n3\n2\n1\n1",
"output": "YES"
},
{
"input": "99\n1\n3\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n1\n1\n3\n3\n3\n3\n1\n1\n3\n2\n1\n1\n1\n1\n1\n1\n1\n3\n2\n2\n2\n1\n3\n3\n1\n1\n3\n2\n1\n3\n3\n1\n2\n3\n3\n3\n1\n2\n2\n2\n3\n3\n3\n3\n3\n3\n2\n2\n2\n2\n3\n3\n3\n1\n1\n3\n2\n1\n1\n2\n2\n2\n3\n3\n2\n1\n1\n2\n2\n1\n3\n2\n1\n1\n2\n3\n3\n3\n3\n2\n2\n2\n2\n2\n1\n3",
"output": "YES"
},
{
"input": "100\n2\n2\n1\n3\n1\n3\n3\n1\n1\n3\n1\n1\n3\n2\n1\n3\n1\n1\n3\n3\n2\n2\n3\n1\n1\n2\n3\n2\n2\n3\n1\n1\n2\n3\n2\n1\n2\n2\n3\n3\n1\n1\n3\n1\n2\n1\n3\n1\n1\n3\n2\n2\n2\n1\n1\n1\n3\n1\n3\n2\n1\n2\n2\n2\n3\n3\n2\n1\n1\n3\n3\n2\n1\n2\n1\n1\n3\n1\n2\n3\n2\n3\n3\n3\n2\n2\n1\n3\n1\n2\n3\n1\n2\n3\n3\n1\n2\n1\n3\n1",
"output": "NO"
},
{
"input": "10\n2\n3\n3\n3\n3\n2\n2\n2\n3\n2",
"output": "NO"
},
{
"input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "YES"
},
{
"input": "1\n3",
"output": "NO"
},
{
"input": "1\n2",
"output": "YES"
},
{
"input": "42\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "YES"
},
{
"input": "4\n2\n3\n3\n3",
"output": "YES"
},
{
"input": "3\n1\n2\n3",
"output": "NO"
},
{
"input": "5\n1\n1\n1\n1\n3",
"output": "NO"
},
{
"input": "5\n2\n3\n3\n3\n3",
"output": "YES"
},
{
"input": "2\n3\n3",
"output": "NO"
},
{
"input": "4\n1\n2\n2\n1",
"output": "NO"
},
{
"input": "3\n2\n2\n3",
"output": "NO"
},
{
"input": "5\n2\n3\n3\n1\n1",
"output": "NO"
},
{
"input": "3\n3\n1\n3",
"output": "NO"
},
{
"input": "3\n3\n3\n1",
"output": "NO"
},
{
"input": "2\n2\n1",
"output": "NO"
},
{
"input": "3\n1\n1\n3",
"output": "NO"
},
{
"input": "6\n2\n2\n2\n3\n1\n3",
"output": "NO"
},
{
"input": "2\n3\n1",
"output": "NO"
},
{
"input": "2\n3\n2",
"output": "NO"
},
{
"input": "2\n1\n3",
"output": "YES"
},
{
"input": "3\n1\n3\n1",
"output": "NO"
},
{
"input": "5\n1\n1\n2\n2\n3",
"output": "NO"
},
{
"input": "3\n2\n1\n1",
"output": "NO"
},
{
"input": "2\n2\n2",
"output": "YES"
},
{
"input": "3\n2\n2\n1",
"output": "YES"
},
{
"input": "5\n2\n2\n2\n2\n2",
"output": "YES"
},
{
"input": "8\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "YES"
},
{
"input": "3\n3\n2\n2",
"output": "NO"
},
{
"input": "3\n3\n2\n3",
"output": "NO"
},
{
"input": "7\n2\n2\n2\n2\n2\n2\n2",
"output": "YES"
},
{
"input": "3\n2\n2\n2",
"output": "YES"
}
] | 1,623,836,998 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 0 | n = int(input())
a, b, c, x = True, True, False, []
d, s = {1: a, 2: b, 3: c}, [1, 2, 3]
for i in range(n):
x.append(int(input()))
for i in range(n):
if d[x[i]]:
b = list(s)
b.remove(x[i])
for j in b:
d[j] = not d[j]
else:
exit(print("NO"))
print("YES")
| Title: Chess For Three
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.
So they play with each other according to following rules:
- Alex and Bob play the first game, and Carl is spectating; - When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner.
Alex, Bob and Carl play in such a way that there are no draws.
Today they have played *n* games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it!
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of games Alex, Bob and Carl played.
Then *n* lines follow, describing the game log. *i*-th line contains one integer *a**i* (1<=≤<=*a**i*<=≤<=3) which is equal to 1 if Alex won *i*-th game, to 2 if Bob won *i*-th game and 3 if Carl won *i*-th game.
Output Specification:
Print YES if the situation described in the log was possible. Otherwise print NO.
Demo Input:
['3\n1\n1\n2\n', '2\n1\n2\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example the possible situation is:
1. Alex wins, Carl starts playing instead of Bob; 1. Alex wins, Bob replaces Carl; 1. Bob wins.
The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one. | ```python
n = int(input())
a, b, c, x = True, True, False, []
d, s = {1: a, 2: b, 3: c}, [1, 2, 3]
for i in range(n):
x.append(int(input()))
for i in range(n):
if d[x[i]]:
b = list(s)
b.remove(x[i])
for j in b:
d[j] = not d[j]
else:
exit(print("NO"))
print("YES")
``` | 3 |
|
998 | B | Cutting | PROGRAMMING | 1,200 | [
"dp",
"greedy",
"sortings"
] | null | null | There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins. | First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers | Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. | [
"6 4\n1 2 5 10 15 20\n",
"4 10\n1 3 2 4\n",
"6 100\n1 2 3 4 5 6\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins. | 1,000 | [
{
"input": "6 4\n1 2 5 10 15 20",
"output": "1"
},
{
"input": "4 10\n1 3 2 4",
"output": "0"
},
{
"input": "6 100\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "2 100\n13 78",
"output": "0"
},
{
"input": "10 1\n56 56 98 2 11 64 97 41 95 53",
"output": "0"
},
{
"input": "10 100\n94 65 24 47 29 98 20 65 6 17",
"output": "2"
},
{
"input": "100 1\n35 6 19 84 49 64 36 91 50 65 21 86 20 89 10 52 50 24 98 74 11 48 58 98 51 85 1 29 44 83 9 97 68 41 83 57 1 57 46 42 87 2 32 50 3 57 17 77 22 100 36 27 3 34 55 8 90 61 34 20 15 39 43 46 60 60 14 23 4 22 75 51 98 23 69 22 99 57 63 30 79 7 16 8 34 84 13 47 93 40 48 25 93 1 80 6 82 93 6 21",
"output": "0"
},
{
"input": "100 10\n3 20 3 29 90 69 2 30 70 28 71 99 22 99 34 70 87 48 3 92 71 61 26 90 14 38 51 81 16 33 49 71 14 52 50 95 65 16 80 57 87 47 29 14 40 31 74 15 87 76 71 61 30 91 44 10 87 48 84 12 77 51 25 68 49 38 79 8 7 9 39 19 48 40 15 53 29 4 60 86 76 84 6 37 45 71 46 38 80 68 94 71 64 72 41 51 71 60 79 7",
"output": "2"
},
{
"input": "100 100\n60 83 82 16 17 7 89 6 83 100 85 41 72 44 23 28 64 84 3 23 33 52 93 30 81 38 67 25 26 97 94 78 41 74 74 17 53 51 54 17 20 81 95 76 42 16 16 56 74 69 30 9 82 91 32 13 47 45 97 40 56 57 27 28 84 98 91 5 61 20 3 43 42 26 83 40 34 100 5 63 62 61 72 5 32 58 93 79 7 18 50 43 17 24 77 73 87 74 98 2",
"output": "11"
},
{
"input": "100 100\n70 54 10 72 81 84 56 15 27 19 43 100 49 44 52 33 63 40 95 17 58 2 51 39 22 18 82 1 16 99 32 29 24 94 9 98 5 37 47 14 42 73 41 31 79 64 12 6 53 26 68 67 89 13 90 4 21 93 46 74 75 88 66 57 23 7 25 48 92 62 30 8 50 61 38 87 71 34 97 28 80 11 60 91 3 35 86 96 36 20 59 65 83 45 76 77 78 69 85 55",
"output": "3"
},
{
"input": "100 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "49"
},
{
"input": "10 10\n94 32 87 13 4 22 85 81 18 95",
"output": "1"
},
{
"input": "10 50\n40 40 9 3 64 96 67 19 21 30",
"output": "1"
},
{
"input": "100 50\n13 31 29 86 46 10 2 87 94 2 28 31 29 15 64 3 94 71 37 76 9 91 89 38 12 46 53 33 58 11 98 4 37 72 30 52 6 86 40 98 28 6 34 80 61 47 45 69 100 47 91 64 87 41 67 58 88 75 13 81 36 58 66 29 10 27 54 83 44 15 11 33 49 36 61 18 89 26 87 1 99 19 57 21 55 84 20 74 14 43 15 51 2 76 22 92 43 14 72 77",
"output": "3"
},
{
"input": "100 1\n78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 21 54 39 68 43 4 32 28 73 6 16 62 72 84 65 86 98 75 33 45 25 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 31 37 12 35 99 67 94 1 87 57 8 61 19 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30",
"output": "0"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "0"
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "1"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "1"
},
{
"input": "100 10\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "10"
},
{
"input": "100 50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "49"
},
{
"input": "100 30\n2 1 2 2 2 2 1 1 1 2 1 1 2 2 1 2 1 2 2 2 2 1 2 1 2 1 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1 1 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 1 1 1 2 2 2 2 1 2 2 1 1 1 1 2 2 2 1 2 2 1 2 1 1 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1 2 1 1 2",
"output": "11"
},
{
"input": "100 80\n1 1 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 2 2 1 1 2 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 2 1 1 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 1 2",
"output": "12"
},
{
"input": "100 30\n100 99 100 99 99 100 100 99 100 99 99 100 100 100 99 99 99 100 99 99 99 99 100 99 99 100 100 99 100 99 99 99 100 99 100 100 99 100 100 100 100 100 99 99 100 99 99 100 99 100 99 99 100 100 99 100 99 99 100 99 100 100 100 100 99 99 99 100 99 100 99 100 100 100 99 100 100 100 99 100 99 99 100 100 100 100 99 99 99 100 99 100 100 99 99 99 100 100 99 99",
"output": "14"
},
{
"input": "100 80\n99 100 100 100 99 99 99 99 100 99 99 99 99 99 99 99 99 100 100 99 99 99 99 99 100 99 100 99 100 100 100 100 100 99 100 100 99 99 100 100 100 100 100 99 100 99 100 99 99 99 100 99 99 99 99 99 99 99 99 100 99 100 100 99 99 99 99 100 100 100 99 100 100 100 100 100 99 100 100 100 100 100 100 100 100 99 99 99 99 100 99 100 100 100 100 100 99 100 99 100",
"output": "4"
},
{
"input": "100 30\n100 100 39 39 39 100 100 39 39 100 39 39 100 39 100 39 100 100 100 100 100 39 100 100 100 39 39 39 100 39 100 100 39 39 100 39 39 39 100 100 39 100 39 100 39 39 100 100 39 100 39 100 39 39 39 100 39 100 39 39 39 100 39 39 100 100 39 39 39 100 100 39 39 39 100 100 100 100 39 100 100 100 39 39 100 39 100 100 39 100 39 100 39 39 100 39 39 100 100 100",
"output": "5"
},
{
"input": "100 80\n39 100 39 100 100 100 100 39 39 100 100 39 39 100 39 39 39 39 100 39 39 39 39 100 100 100 100 39 100 39 39 100 100 39 39 100 39 100 39 100 100 39 39 100 39 39 39 100 39 100 39 100 100 100 100 100 100 100 39 100 39 100 100 100 39 39 39 39 39 100 100 100 39 100 100 100 100 39 100 100 39 39 100 39 39 39 100 39 100 39 39 100 100 39 100 39 39 39 100 39",
"output": "6"
},
{
"input": "4 1\n1 2 3 4",
"output": "1"
},
{
"input": "4 1\n1 2 1 2",
"output": "1"
},
{
"input": "4 4\n1 2 6 7",
"output": "1"
},
{
"input": "4 8\n1 2 10 11",
"output": "1"
},
{
"input": "6 2\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "6 1\n1 2 1 2 1 2",
"output": "1"
},
{
"input": "6 4\n1 2 4 5 7 8",
"output": "2"
},
{
"input": "6 3\n1 2 5 10 15 20",
"output": "1"
}
] | 1,558,269,033 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 140 | 512,000 | # Lets goto the next level
# AIM Specialist at CF *__* asap
# template taken from chaudhary_19
# Remember you were also a novice when you started,
# hence never be rude to anyone who wants to learn something
# Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts
# Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure.
# Any doubts or want to have a talk, contact https://www.facebook.com/chaudhary.mayank
# ///==========Libraries, Constants and Functions=============///
import sys
from bisect import bisect_left,bisect_right,insort
from collections import deque,Counter
from math import gcd,sqrt,factorial,ceil,log10,log2,floor
from itertools import permutations
from heapq import heappush,heappop,heapify
inf = float("inf")
mod = 10**9+7
#sys.setrecursionlimit(10**9)
def factorial_p(n, p):
ans = 1
if n <= p // 2:
for i in range(1, n + 1):
ans = (ans * i) % p
else:
for i in range(1, p - n):
ans = (ans * i) % p
ans = pow(ans, p - 2, p)
if n % 2 == 0:
ans = p - ans
return ans
def nCr_p(n, r, p):
ans = 1
while (n != 0) or (r != 0):
a, b = n % p, r % p
if a < b:
return 0
ans = (ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p)) % p
n //= p
r //= p
return ans
def prime_sieve(n):
"""returns a sieve of primes >= 5 and < n"""
flag = n % 6 == 2
sieve = bytearray((n // 3 + flag >> 3) + 1)
for i in range(1, int(n**0.5) // 3 + 1):
if not (sieve[i >> 3] >> (i & 7)) & 1:
k = (3 * i + 1) | 1
for j in range(k * k // 3, n // 3 + flag, 2 * k):
sieve[j >> 3] |= 1 << (j & 7)
for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
sieve[j >> 3] |= 1 << (j & 7)
return sieve
def prime_list(n): #<----- You have to call me if you wanna get list of primes upto range n
"""returns a list of primes <= n"""
res = []
if n > 1:
res.append(2)
if n > 2:
res.append(3)
if n > 4:
sieve = prime_sieve(n + 1)
res.extend(3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not (sieve[i >> 3] >> (i & 7)) & 1)
return res
def is_prime(n):
"""returns True if n is prime else False"""
if n < 5 or n & 1 == 0 or n % 3 == 0:
return 2 <= n <= 3
s = ((n - 1) & (1 - n)).bit_length() - 1
d = n >> s
for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
p = pow(a, d, n)
if p == 1 or p == n - 1 or a % n == 0:
continue
for _ in range(s):
p = (p * p) % n
if p == n - 1:
break
else:
return False
return True
def all_factors(n):
"""returns a sorted list of all distinct factors of n"""
small, large = [],[]
for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1):
if not n % i:
small.append(i)
large.append(n//i)
large.reverse()
small.extend(large)
return small
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
# ///===========MAIN=============///
n,b=get_ints()
Arr=get_array()
even_suf=[0]*n
odd_suf=[0]*n
if Arr[0]&1:
odd_suf[0]=1
else:
even_suf[0]=1
for i in range(1,n):
if Arr[i]&1:
odd_suf[i]=odd_suf[i-1]+1
even_suf[i]=even_suf[i-1]
else:
even_suf[i]=even_suf[i-1]+1
odd_suf[i]=odd_suf[i-1]
result=[];flag=0
for i in range(1,n-1):
if odd_suf[i]==even_suf[i]:
result.append(abs(Arr[i]-Arr[i+1]))
flag=1
if flag==0:
print(0)
exit()
result.sort()
index=0
total=0
while(index<len(result) and total+result[index]<=b):
total+=result[index]
index+=1
print(index)
| Title: Cutting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins.
Input Specification:
First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers
Output Specification:
Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.
Demo Input:
['6 4\n1 2 5 10 15 20\n', '4 10\n1 3 2 4\n', '6 100\n1 2 3 4 5 6\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins. | ```python
# Lets goto the next level
# AIM Specialist at CF *__* asap
# template taken from chaudhary_19
# Remember you were also a novice when you started,
# hence never be rude to anyone who wants to learn something
# Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts
# Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure.
# Any doubts or want to have a talk, contact https://www.facebook.com/chaudhary.mayank
# ///==========Libraries, Constants and Functions=============///
import sys
from bisect import bisect_left,bisect_right,insort
from collections import deque,Counter
from math import gcd,sqrt,factorial,ceil,log10,log2,floor
from itertools import permutations
from heapq import heappush,heappop,heapify
inf = float("inf")
mod = 10**9+7
#sys.setrecursionlimit(10**9)
def factorial_p(n, p):
ans = 1
if n <= p // 2:
for i in range(1, n + 1):
ans = (ans * i) % p
else:
for i in range(1, p - n):
ans = (ans * i) % p
ans = pow(ans, p - 2, p)
if n % 2 == 0:
ans = p - ans
return ans
def nCr_p(n, r, p):
ans = 1
while (n != 0) or (r != 0):
a, b = n % p, r % p
if a < b:
return 0
ans = (ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p)) % p
n //= p
r //= p
return ans
def prime_sieve(n):
"""returns a sieve of primes >= 5 and < n"""
flag = n % 6 == 2
sieve = bytearray((n // 3 + flag >> 3) + 1)
for i in range(1, int(n**0.5) // 3 + 1):
if not (sieve[i >> 3] >> (i & 7)) & 1:
k = (3 * i + 1) | 1
for j in range(k * k // 3, n // 3 + flag, 2 * k):
sieve[j >> 3] |= 1 << (j & 7)
for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
sieve[j >> 3] |= 1 << (j & 7)
return sieve
def prime_list(n): #<----- You have to call me if you wanna get list of primes upto range n
"""returns a list of primes <= n"""
res = []
if n > 1:
res.append(2)
if n > 2:
res.append(3)
if n > 4:
sieve = prime_sieve(n + 1)
res.extend(3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not (sieve[i >> 3] >> (i & 7)) & 1)
return res
def is_prime(n):
"""returns True if n is prime else False"""
if n < 5 or n & 1 == 0 or n % 3 == 0:
return 2 <= n <= 3
s = ((n - 1) & (1 - n)).bit_length() - 1
d = n >> s
for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
p = pow(a, d, n)
if p == 1 or p == n - 1 or a % n == 0:
continue
for _ in range(s):
p = (p * p) % n
if p == n - 1:
break
else:
return False
return True
def all_factors(n):
"""returns a sorted list of all distinct factors of n"""
small, large = [],[]
for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1):
if not n % i:
small.append(i)
large.append(n//i)
large.reverse()
small.extend(large)
return small
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
# ///===========MAIN=============///
n,b=get_ints()
Arr=get_array()
even_suf=[0]*n
odd_suf=[0]*n
if Arr[0]&1:
odd_suf[0]=1
else:
even_suf[0]=1
for i in range(1,n):
if Arr[i]&1:
odd_suf[i]=odd_suf[i-1]+1
even_suf[i]=even_suf[i-1]
else:
even_suf[i]=even_suf[i-1]+1
odd_suf[i]=odd_suf[i-1]
result=[];flag=0
for i in range(1,n-1):
if odd_suf[i]==even_suf[i]:
result.append(abs(Arr[i]-Arr[i+1]))
flag=1
if flag==0:
print(0)
exit()
result.sort()
index=0
total=0
while(index<len(result) and total+result[index]<=b):
total+=result[index]
index+=1
print(index)
``` | 3 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,644,587,564 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m,n = input().split()
casillas = int(m)*int(n)
p = 0
final = 0
for i in range(casillas):
p = p + 2
if p <= int(casillas):
final += 1
elif p == casillas:
print(final)
exit()
elif p > casillas:
print(final)
exit()
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
m,n = input().split()
casillas = int(m)*int(n)
p = 0
final = 0
for i in range(casillas):
p = p + 2
if p <= int(casillas):
final += 1
elif p == casillas:
print(final)
exit()
elif p > casillas:
print(final)
exit()
``` | 3.977 |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem. | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
"input": "6 100\n170427799 37215529 675016434 168544291 683447134 950090227",
"output": "6"
},
{
"input": "4 2\n194041605 706221269 69909135 257655784",
"output": "3"
},
{
"input": "4 2\n9581849 67346651 530497 272158241",
"output": "4"
},
{
"input": "3 47\n378261451 163985731 230342101",
"output": "3"
},
{
"input": "2 3\n247776868 480572137",
"output": "1"
},
{
"input": "7 77\n366496749 549646417 278840199 119255907 33557677 379268590 150378796",
"output": "7"
},
{
"input": "40 31\n32230963 709031779 144328646 513494529 36547831 416998222 84161665 318773941 170724397 553666286 368402971 48581613 31452501 368026285 47903381 939151438 204145360 189920160 288159400 133145006 314295423 450219949 160203213 358403181 478734385 29331901 31051111 110710191 567314089 139695685 111511396 87708701 317333277 103301481 110400517 634446253 481551313 39202255 105948 738066085",
"output": "40"
},
{
"input": "1 8\n55521105",
"output": "1"
},
{
"input": "49 3\n34644511 150953622 136135827 144208961 359490601 86708232 719413689 188605873 64330753 488776302 104482891 63360106 437791390 46521319 70778345 339141601 136198441 292941209 299339510 582531183 555958105 437904637 74219097 439816011 236010407 122674666 438442529 186501223 63932449 407678041 596993853 92223251 849265278 480265849 30983497 330283357 186901672 20271344 794252593 123774176 27851201 52717531 479907210 196833889 149331196 82147847 255966471 278600081 899317843",
"output": "44"
},
{
"input": "26 2\n330381357 185218042 850474297 483015466 296129476 1205865 538807493 103205601 160403321 694220263 416255901 7245756 507755361 88187633 91426751 1917161 58276681 59540376 576539745 595950717 390256887 105690055 607818885 28976353 488947089 50643601",
"output": "22"
},
{
"input": "38 1\n194481717 126247087 815196361 106258801 381703249 283859137 15290101 40086151 213688513 577996947 513899717 371428417 107799271 11136651 5615081 323386401 381128815 34217126 17709913 520702093 201694245 570931849 169037023 417019726 282437316 7417126 271667553 11375851 185087449 410130883 383045677 5764771 905017051 328584026 215330671 299553233 15838255 234532105",
"output": "20"
},
{
"input": "44 9\n683216389 250581469 130029957 467020047 188395565 206237982 63257361 68314981 732878407 563579660 199133851 53045209 665723851 16273169 10806790 556633156 350593410 474645249 478790761 708234243 71841230 18090541 19836685 146373571 17947452 534010506 46933264 377035021 311636557 75193963 54321761 12759959 71120181 548816939 23608621 31876417 107672995 72575155 369667956 20574379 210596751 532163173 75726739 853719629",
"output": "44"
},
{
"input": "8 6\n204157376 10514197 65483881 347219841 263304577 296402721 11739011 229776191",
"output": "8"
},
{
"input": "38 29\n333702889 680931737 61137217 203030505 68728281 11414209 642645708 590904616 3042901 607198177 189041074 700764043 813035201 198341461 126403544 401436841 420826465 45046581 20249976 46978855 46397957 706610773 24701041 57954481 51603266 593109701 385569073 178982291 582152863 287317968 1474090 34825141 432421977 130257781 151516903 540852403 548392 117246529",
"output": "38"
},
{
"input": "19 3\n562569697 549131571 50676718 84501863 74567295 702372009 365895280 451459937 40378543 167666701 158635641 53639293 442332661 825055617 100109161 326616021 862332843 533271196 4791547",
"output": "18"
},
{
"input": "1 1\n44",
"output": "0"
},
{
"input": "1 1\n4",
"output": "1"
},
{
"input": "10 3\n444 447 774 777 7777 4447 4 7 7 4",
"output": "8"
}
] | 1,655,984,112 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | def main():
[_, k] = list(map(int, input().split()))
ns = input().split()
t = 0
for n in ns:
q = 0
for c in str(n):
if c == '4' or c == '7':
q += 1
if q <= k:
t += 1
print(t)
if __name__ == "__main__":
main()
| Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem.
Input Specification:
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['3 4\n1 2 4\n', '3 2\n447 44 77\n']
Demo Output:
['3\n', '2\n']
Note:
In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | ```python
def main():
[_, k] = list(map(int, input().split()))
ns = input().split()
t = 0
for n in ns:
q = 0
for c in str(n):
if c == '4' or c == '7':
q += 1
if q <= k:
t += 1
print(t)
if __name__ == "__main__":
main()
``` | 3 |
|
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).
You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions.
It is guaranteed that the result will be positive integer number. | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"output": "130"
},
{
"input": "900000000 16",
"output": "1"
},
{
"input": "909090909 50",
"output": "3"
},
{
"input": "1001 2",
"output": "100"
},
{
"input": "5 2",
"output": "3"
},
{
"input": "2 1",
"output": "1"
}
] | 1,698,563,432 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 11 | 61 | 0 | n, k = map(int, input().split())
cnt = 0
while cnt < k:
if n % 10 != 0:
n -= 1
else:
n //= 10
cnt += 1
print(n) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).
You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions.
It is guaranteed that the result will be positive integer number.
Input Specification:
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly.
Output Specification:
Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number.
Demo Input:
['512 4\n', '1000000000 9\n']
Demo Output:
['50\n', '1\n']
Note:
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | ```python
n, k = map(int, input().split())
cnt = 0
while cnt < k:
if n % 10 != 0:
n -= 1
else:
n //= 10
cnt += 1
print(n)
``` | 3 |
|
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*. | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
},
{
"input": "12\n4773\n325\n377\n192\n780\n881\n816\n839\n223\n215\n125\n952\n8",
"output": "7"
},
{
"input": "15\n7758\n182\n272\n763\n910\n24\n359\n583\n890\n735\n819\n66\n992\n440\n496\n227",
"output": "15"
},
{
"input": "30\n70\n6\n2\n10\n4\n7\n10\n5\n1\n8\n10\n4\n3\n5\n9\n3\n6\n6\n4\n2\n6\n5\n10\n1\n9\n7\n2\n1\n10\n7\n5",
"output": "8"
},
{
"input": "40\n15705\n702\n722\n105\n873\n417\n477\n794\n300\n869\n496\n572\n232\n456\n298\n473\n584\n486\n713\n934\n121\n303\n956\n934\n840\n358\n201\n861\n497\n131\n312\n957\n96\n914\n509\n60\n300\n722\n658\n820\n103",
"output": "21"
},
{
"input": "50\n18239\n300\n151\n770\n9\n200\n52\n247\n753\n523\n263\n744\n463\n540\n244\n608\n569\n771\n32\n425\n777\n624\n761\n628\n124\n405\n396\n726\n626\n679\n237\n229\n49\n512\n18\n671\n290\n768\n632\n739\n18\n136\n413\n117\n83\n413\n452\n767\n664\n203\n404",
"output": "31"
},
{
"input": "70\n149\n5\n3\n3\n4\n6\n1\n2\n9\n8\n3\n1\n8\n4\n4\n3\n6\n10\n7\n1\n10\n8\n4\n9\n3\n8\n3\n2\n5\n1\n8\n6\n9\n10\n4\n8\n6\n9\n9\n9\n3\n4\n2\n2\n5\n8\n9\n1\n10\n3\n4\n3\n1\n9\n3\n5\n1\n3\n7\n6\n9\n8\n9\n1\n7\n4\n4\n2\n3\n5\n7",
"output": "17"
},
{
"input": "70\n2731\n26\n75\n86\n94\n37\n25\n32\n35\n92\n1\n51\n73\n53\n66\n16\n80\n15\n81\n100\n87\n55\n48\n30\n71\n39\n87\n77\n25\n70\n22\n75\n23\n97\n16\n75\n95\n61\n61\n28\n10\n78\n54\n80\n51\n25\n24\n90\n58\n4\n77\n40\n54\n53\n47\n62\n30\n38\n71\n97\n71\n60\n58\n1\n21\n15\n55\n99\n34\n88\n99",
"output": "35"
},
{
"input": "70\n28625\n34\n132\n181\n232\n593\n413\n862\n887\n808\n18\n35\n89\n356\n640\n339\n280\n975\n82\n345\n398\n948\n372\n91\n755\n75\n153\n948\n603\n35\n694\n722\n293\n363\n884\n264\n813\n175\n169\n646\n138\n449\n488\n828\n417\n134\n84\n763\n288\n845\n801\n556\n972\n332\n564\n934\n699\n842\n942\n644\n203\n406\n140\n37\n9\n423\n546\n675\n491\n113\n587",
"output": "45"
},
{
"input": "80\n248\n3\n9\n4\n5\n10\n7\n2\n6\n2\n2\n8\n2\n1\n3\n7\n9\n2\n8\n4\n4\n8\n5\n4\n4\n10\n2\n1\n4\n8\n4\n10\n1\n2\n10\n2\n3\n3\n1\n1\n8\n9\n5\n10\n2\n8\n10\n5\n3\n6\n1\n7\n8\n9\n10\n5\n10\n10\n2\n10\n1\n2\n4\n1\n9\n4\n7\n10\n8\n5\n8\n1\n4\n2\n2\n3\n9\n9\n9\n10\n6",
"output": "27"
},
{
"input": "80\n2993\n18\n14\n73\n38\n14\n73\n77\n18\n81\n6\n96\n65\n77\n86\n76\n8\n16\n81\n83\n83\n34\n69\n58\n15\n19\n1\n16\n57\n95\n35\n5\n49\n8\n15\n47\n84\n99\n94\n93\n55\n43\n47\n51\n61\n57\n13\n7\n92\n14\n4\n83\n100\n60\n75\n41\n95\n74\n40\n1\n4\n95\n68\n59\n65\n15\n15\n75\n85\n46\n77\n26\n30\n51\n64\n75\n40\n22\n88\n68\n24",
"output": "38"
},
{
"input": "80\n37947\n117\n569\n702\n272\n573\n629\n90\n337\n673\n589\n576\n205\n11\n284\n645\n719\n777\n271\n567\n466\n251\n402\n3\n97\n288\n699\n208\n173\n530\n782\n266\n395\n957\n159\n463\n43\n316\n603\n197\n386\n132\n799\n778\n905\n784\n71\n851\n963\n883\n705\n454\n275\n425\n727\n223\n4\n870\n833\n431\n463\n85\n505\n800\n41\n954\n981\n242\n578\n336\n48\n858\n702\n349\n929\n646\n528\n993\n506\n274\n227",
"output": "70"
},
{
"input": "90\n413\n5\n8\n10\n7\n5\n7\n5\n7\n1\n7\n8\n4\n3\n9\n4\n1\n10\n3\n1\n10\n9\n3\n1\n8\n4\n7\n5\n2\n9\n3\n10\n10\n3\n6\n3\n3\n10\n7\n5\n1\n1\n2\n4\n8\n2\n5\n5\n3\n9\n5\n5\n3\n10\n2\n3\n8\n5\n9\n1\n3\n6\n5\n9\n2\n3\n7\n10\n3\n4\n4\n1\n5\n9\n2\n6\n9\n1\n1\n9\n9\n7\n7\n7\n8\n4\n5\n3\n4\n6\n9",
"output": "59"
},
{
"input": "90\n4226\n33\n43\n83\n46\n75\n14\n88\n36\n8\n25\n47\n4\n96\n19\n33\n49\n65\n17\n59\n72\n1\n55\n94\n92\n27\n33\n39\n14\n62\n79\n12\n89\n22\n86\n13\n19\n77\n53\n96\n74\n24\n25\n17\n64\n71\n81\n87\n52\n72\n55\n49\n74\n36\n65\n86\n91\n33\n61\n97\n38\n87\n61\n14\n73\n95\n43\n67\n42\n67\n22\n12\n62\n32\n96\n24\n49\n82\n46\n89\n36\n75\n91\n11\n10\n9\n33\n86\n28\n75\n39",
"output": "64"
},
{
"input": "90\n40579\n448\n977\n607\n745\n268\n826\n479\n59\n330\n609\n43\n301\n970\n726\n172\n632\n600\n181\n712\n195\n491\n312\n849\n722\n679\n682\n780\n131\n404\n293\n387\n567\n660\n54\n339\n111\n833\n612\n911\n869\n356\n884\n635\n126\n639\n712\n473\n663\n773\n435\n32\n973\n484\n662\n464\n699\n274\n919\n95\n904\n253\n589\n543\n454\n250\n349\n237\n829\n511\n536\n36\n45\n152\n626\n384\n199\n877\n941\n84\n781\n115\n20\n52\n726\n751\n920\n291\n571\n6\n199",
"output": "64"
},
{
"input": "100\n66\n7\n9\n10\n5\n2\n8\n6\n5\n4\n10\n10\n6\n5\n2\n2\n1\n1\n5\n8\n7\n8\n10\n5\n6\n6\n5\n9\n9\n6\n3\n8\n7\n10\n5\n9\n6\n7\n3\n5\n8\n6\n8\n9\n1\n1\n1\n2\n4\n5\n5\n1\n1\n2\n6\n7\n1\n5\n8\n7\n2\n1\n7\n10\n9\n10\n2\n4\n10\n4\n10\n10\n5\n3\n9\n1\n2\n1\n10\n5\n1\n7\n4\n4\n5\n7\n6\n10\n4\n7\n3\n4\n3\n6\n2\n5\n2\n4\n9\n5\n3",
"output": "7"
},
{
"input": "100\n4862\n20\n47\n85\n47\n76\n38\n48\n93\n91\n81\n31\n51\n23\n60\n59\n3\n73\n72\n57\n67\n54\n9\n42\n5\n32\n46\n72\n79\n95\n61\n79\n88\n33\n52\n97\n10\n3\n20\n79\n82\n93\n90\n38\n80\n18\n21\n43\n60\n73\n34\n75\n65\n10\n84\n100\n29\n94\n56\n22\n59\n95\n46\n22\n57\n69\n67\n90\n11\n10\n61\n27\n2\n48\n69\n86\n91\n69\n76\n36\n71\n18\n54\n90\n74\n69\n50\n46\n8\n5\n41\n96\n5\n14\n55\n85\n39\n6\n79\n75\n87",
"output": "70"
},
{
"input": "100\n45570\n14\n881\n678\n687\n993\n413\n760\n451\n426\n787\n503\n343\n234\n530\n294\n725\n941\n524\n574\n441\n798\n399\n360\n609\n376\n525\n229\n995\n478\n347\n47\n23\n468\n525\n749\n601\n235\n89\n995\n489\n1\n239\n415\n122\n671\n128\n357\n886\n401\n964\n212\n968\n210\n130\n871\n360\n661\n844\n414\n187\n21\n824\n266\n713\n126\n496\n916\n37\n193\n755\n894\n641\n300\n170\n176\n383\n488\n627\n61\n897\n33\n242\n419\n881\n698\n107\n391\n418\n774\n905\n87\n5\n896\n835\n318\n373\n916\n393\n91\n460",
"output": "78"
},
{
"input": "100\n522\n1\n5\n2\n4\n2\n6\n3\n4\n2\n10\n10\n6\n7\n9\n7\n1\n7\n2\n5\n3\n1\n5\n2\n3\n5\n1\n7\n10\n10\n4\n4\n10\n9\n10\n6\n2\n8\n2\n6\n10\n9\n2\n7\n5\n9\n4\n6\n10\n7\n3\n1\n1\n9\n5\n10\n9\n2\n8\n3\n7\n5\n4\n7\n5\n9\n10\n6\n2\n9\n2\n5\n10\n1\n7\n7\n10\n5\n6\n2\n9\n4\n7\n10\n10\n8\n3\n4\n9\n3\n6\n9\n10\n2\n9\n9\n3\n4\n1\n10\n2",
"output": "74"
},
{
"input": "100\n32294\n414\n116\n131\n649\n130\n476\n630\n605\n213\n117\n757\n42\n109\n85\n127\n635\n629\n994\n410\n764\n204\n161\n231\n577\n116\n936\n537\n565\n571\n317\n722\n819\n229\n284\n487\n649\n304\n628\n727\n816\n854\n91\n111\n549\n87\n374\n417\n3\n868\n882\n168\n743\n77\n534\n781\n75\n956\n910\n734\n507\n568\n802\n946\n891\n659\n116\n678\n375\n380\n430\n627\n873\n350\n930\n285\n6\n183\n96\n517\n81\n794\n235\n360\n551\n6\n28\n799\n226\n996\n894\n981\n551\n60\n40\n460\n479\n161\n318\n952\n433",
"output": "42"
},
{
"input": "100\n178\n71\n23\n84\n98\n8\n14\n4\n42\n56\n83\n87\n28\n22\n32\n50\n5\n96\n90\n1\n59\n74\n56\n96\n77\n88\n71\n38\n62\n36\n85\n1\n97\n98\n98\n32\n99\n42\n6\n81\n20\n49\n57\n71\n66\n9\n45\n41\n29\n28\n32\n68\n38\n29\n35\n29\n19\n27\n76\n85\n68\n68\n41\n32\n78\n72\n38\n19\n55\n83\n83\n25\n46\n62\n48\n26\n53\n14\n39\n31\n94\n84\n22\n39\n34\n96\n63\n37\n42\n6\n78\n76\n64\n16\n26\n6\n79\n53\n24\n29\n63",
"output": "2"
},
{
"input": "100\n885\n226\n266\n321\n72\n719\n29\n121\n533\n85\n672\n225\n830\n783\n822\n30\n791\n618\n166\n487\n922\n434\n814\n473\n5\n741\n947\n910\n305\n998\n49\n945\n588\n868\n809\n803\n168\n280\n614\n434\n634\n538\n591\n437\n540\n445\n313\n177\n171\n799\n778\n55\n617\n554\n583\n611\n12\n94\n599\n182\n765\n556\n965\n542\n35\n460\n177\n313\n485\n744\n384\n21\n52\n879\n792\n411\n614\n811\n565\n695\n428\n587\n631\n794\n461\n258\n193\n696\n936\n646\n756\n267\n55\n690\n730\n742\n734\n988\n235\n762\n440",
"output": "1"
},
{
"input": "100\n29\n9\n2\n10\n8\n6\n7\n7\n3\n3\n10\n4\n5\n2\n5\n1\n6\n3\n2\n5\n10\n10\n9\n1\n4\n5\n2\n2\n3\n1\n2\n2\n9\n6\n9\n7\n8\n8\n1\n5\n5\n3\n1\n5\n6\n1\n9\n2\n3\n8\n10\n8\n3\n2\n7\n1\n2\n1\n2\n8\n10\n5\n2\n3\n1\n10\n7\n1\n7\n4\n9\n6\n6\n4\n7\n1\n2\n7\n7\n9\n9\n7\n10\n4\n10\n8\n2\n1\n5\n5\n10\n5\n8\n1\n5\n6\n5\n1\n5\n6\n8",
"output": "3"
},
{
"input": "100\n644\n94\n69\n43\n36\n54\n93\n30\n74\n56\n95\n70\n49\n11\n36\n57\n30\n59\n3\n52\n59\n90\n82\n39\n67\n32\n8\n80\n64\n8\n65\n51\n48\n89\n90\n35\n4\n54\n66\n96\n68\n90\n30\n4\n13\n97\n41\n90\n85\n17\n45\n94\n31\n58\n4\n39\n76\n95\n92\n59\n67\n46\n96\n55\n82\n64\n20\n20\n83\n46\n37\n15\n60\n37\n79\n45\n47\n63\n73\n76\n31\n52\n36\n32\n49\n26\n61\n91\n31\n25\n62\n90\n65\n65\n5\n94\n7\n15\n97\n88\n68",
"output": "7"
},
{
"input": "100\n1756\n98\n229\n158\n281\n16\n169\n149\n239\n235\n182\n147\n215\n49\n270\n194\n242\n295\n289\n249\n19\n12\n144\n157\n92\n270\n122\n212\n97\n152\n14\n42\n12\n198\n98\n295\n154\n229\n191\n294\n5\n156\n43\n185\n184\n20\n125\n23\n10\n257\n244\n264\n79\n46\n277\n13\n22\n97\n212\n77\n293\n20\n51\n17\n109\n37\n68\n117\n51\n248\n10\n149\n179\n192\n239\n161\n13\n173\n297\n73\n43\n109\n288\n198\n81\n70\n254\n187\n277\n1\n295\n113\n95\n291\n293\n119\n205\n191\n37\n34\n116",
"output": "6"
},
{
"input": "100\n20562\n721\n452\n11\n703\n376\n183\n197\n203\n406\n642\n346\n446\n256\n760\n201\n360\n702\n707\n388\n779\n653\n610\n497\n768\n670\n134\n780\n306\n661\n180\n259\n256\n362\n6\n121\n415\n747\n170\n67\n439\n728\n193\n622\n481\n38\n225\n343\n303\n253\n436\n305\n68\n794\n247\n291\n600\n750\n188\n199\n757\n28\n776\n749\n253\n351\n53\n629\n129\n578\n209\n89\n651\n262\n638\n353\n469\n31\n144\n460\n176\n535\n562\n366\n639\n234\n577\n364\n761\n617\n303\n450\n778\n311\n289\n221\n274\n239\n626\n194\n36",
"output": "30"
},
{
"input": "100\n32630\n548\n21\n756\n138\n56\n719\n97\n86\n599\n531\n464\n137\n737\n239\n626\n179\n170\n271\n335\n178\n298\n597\n616\n104\n190\n216\n333\n606\n621\n310\n70\n286\n593\n655\n472\n556\n77\n625\n744\n395\n487\n762\n316\n469\n258\n475\n596\n651\n180\n737\n101\n511\n708\n163\n713\n475\n557\n649\n705\n583\n97\n447\n119\n91\n372\n194\n394\n667\n384\n635\n611\n746\n758\n613\n54\n508\n405\n188\n570\n254\n28\n599\n767\n115\n737\n194\n148\n686\n705\n236\n762\n613\n770\n633\n401\n773\n448\n274\n141\n718",
"output": "52"
},
{
"input": "1\n1\n1",
"output": "1"
}
] | 1,567,814,643 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 0 | a=int(input())
b=int(input())
k=[]
for i in range(a):
k.append(int(input()))
tot=sum(k)
tot1=sum(k)
if tot==b:
print(a)
while k!=[]:
minIndex = k.index(min(k))
tot=tot1
tot1=tot1-min(k)
k.pop(minIndex)
if tot1<b:
print(len(k)+1)
break
| Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
Input Specification:
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*.
Output Specification:
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
Demo Input:
['3\n5\n2\n1\n3\n', '3\n6\n2\n3\n2\n', '2\n5\n5\n10\n']
Demo Output:
['2\n', '3\n', '1\n']
Note:
In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | ```python
a=int(input())
b=int(input())
k=[]
for i in range(a):
k.append(int(input()))
tot=sum(k)
tot1=sum(k)
if tot==b:
print(a)
while k!=[]:
minIndex = k.index(min(k))
tot=tot1
tot1=tot1-min(k)
k.pop(minIndex)
if tot1<b:
print(len(k)+1)
break
``` | 0 |
|
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n1 2 3 3 4",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "2"
},
{
"input": "11\n1 2 3 1 2 3 2 1 2 3 4",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "1\n1234394",
"output": "1"
}
] | 1,654,315,933 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 108 | 7,884,800 | n = int(input())
l = list(map(int, input().split()))
count = 1
max_ = 1
for i in range(len(l)-1):
if l[i] < l[i+1]:
# print(l[i], l[i+1])
count += 1
# print(max_, count)
else:
if max_ < count:
max_ = count
count = 1
print(max(max_, count)) | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Input Specification:
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the maximum length of an increasing subarray of the given array.
Demo Input:
['5\n1 7 2 11 15\n', '6\n100 100 100 100 100 100\n', '3\n1 2 3\n']
Demo Output:
['3\n', '1\n', '3\n']
Note:
none | ```python
n = int(input())
l = list(map(int, input().split()))
count = 1
max_ = 1
for i in range(len(l)-1):
if l[i] < l[i+1]:
# print(l[i], l[i+1])
count += 1
# print(max_, count)
else:
if max_ < count:
max_ = count
count = 1
print(max(max_, count))
``` | 3 |
|
816 | A | Karen and Morning | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Karen is getting ready for a new school day!
It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.
What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?
Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50. | The first and only line of input contains a single string in the format hh:mm (00<=≤<= hh <=≤<=23, 00<=≤<= mm <=≤<=59). | Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome. | [
"05:39\n",
"13:31\n",
"23:59\n"
] | [
"11\n",
"0\n",
"1\n"
] | In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.
In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.
In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome. | 500 | [
{
"input": "05:39",
"output": "11"
},
{
"input": "13:31",
"output": "0"
},
{
"input": "23:59",
"output": "1"
},
{
"input": "13:32",
"output": "69"
},
{
"input": "14:40",
"output": "1"
},
{
"input": "14:00",
"output": "41"
},
{
"input": "05:50",
"output": "0"
},
{
"input": "12:22",
"output": "69"
},
{
"input": "12:34",
"output": "57"
},
{
"input": "05:30",
"output": "20"
},
{
"input": "14:14",
"output": "27"
},
{
"input": "01:10",
"output": "0"
},
{
"input": "02:20",
"output": "0"
},
{
"input": "03:30",
"output": "0"
},
{
"input": "04:40",
"output": "0"
},
{
"input": "10:01",
"output": "0"
},
{
"input": "11:11",
"output": "0"
},
{
"input": "12:21",
"output": "0"
},
{
"input": "14:41",
"output": "0"
},
{
"input": "15:51",
"output": "0"
},
{
"input": "20:02",
"output": "0"
},
{
"input": "21:12",
"output": "0"
},
{
"input": "22:22",
"output": "0"
},
{
"input": "23:32",
"output": "0"
},
{
"input": "01:11",
"output": "69"
},
{
"input": "02:21",
"output": "69"
},
{
"input": "03:31",
"output": "69"
},
{
"input": "04:41",
"output": "69"
},
{
"input": "05:51",
"output": "250"
},
{
"input": "10:02",
"output": "69"
},
{
"input": "11:12",
"output": "69"
},
{
"input": "14:42",
"output": "69"
},
{
"input": "15:52",
"output": "250"
},
{
"input": "20:03",
"output": "69"
},
{
"input": "21:13",
"output": "69"
},
{
"input": "22:23",
"output": "69"
},
{
"input": "23:33",
"output": "27"
},
{
"input": "00:00",
"output": "0"
},
{
"input": "00:01",
"output": "69"
},
{
"input": "22:21",
"output": "1"
},
{
"input": "20:01",
"output": "1"
},
{
"input": "11:10",
"output": "1"
},
{
"input": "06:59",
"output": "182"
},
{
"input": "02:00",
"output": "20"
},
{
"input": "02:19",
"output": "1"
},
{
"input": "17:31",
"output": "151"
},
{
"input": "19:00",
"output": "62"
},
{
"input": "13:37",
"output": "64"
},
{
"input": "07:59",
"output": "122"
},
{
"input": "04:20",
"output": "20"
},
{
"input": "07:10",
"output": "171"
},
{
"input": "06:00",
"output": "241"
},
{
"input": "06:01",
"output": "240"
},
{
"input": "08:15",
"output": "106"
},
{
"input": "06:59",
"output": "182"
},
{
"input": "01:00",
"output": "10"
},
{
"input": "07:00",
"output": "181"
},
{
"input": "06:10",
"output": "231"
},
{
"input": "18:52",
"output": "70"
},
{
"input": "09:59",
"output": "2"
},
{
"input": "19:00",
"output": "62"
},
{
"input": "15:52",
"output": "250"
},
{
"input": "06:50",
"output": "191"
},
{
"input": "00:00",
"output": "0"
},
{
"input": "19:20",
"output": "42"
},
{
"input": "05:51",
"output": "250"
},
{
"input": "06:16",
"output": "225"
},
{
"input": "10:10",
"output": "61"
},
{
"input": "17:11",
"output": "171"
},
{
"input": "18:00",
"output": "122"
},
{
"input": "00:01",
"output": "69"
},
{
"input": "05:04",
"output": "46"
},
{
"input": "16:00",
"output": "242"
},
{
"input": "23:31",
"output": "1"
},
{
"input": "17:25",
"output": "157"
},
{
"input": "23:32",
"output": "0"
},
{
"input": "23:58",
"output": "2"
},
{
"input": "02:21",
"output": "69"
},
{
"input": "01:11",
"output": "69"
},
{
"input": "23:46",
"output": "14"
},
{
"input": "00:09",
"output": "61"
},
{
"input": "09:20",
"output": "41"
},
{
"input": "05:59",
"output": "242"
},
{
"input": "18:59",
"output": "63"
},
{
"input": "02:02",
"output": "18"
},
{
"input": "00:30",
"output": "40"
},
{
"input": "05:54",
"output": "247"
},
{
"input": "19:59",
"output": "3"
},
{
"input": "16:59",
"output": "183"
},
{
"input": "17:51",
"output": "131"
},
{
"input": "09:30",
"output": "31"
},
{
"input": "10:01",
"output": "0"
},
{
"input": "16:55",
"output": "187"
},
{
"input": "20:02",
"output": "0"
},
{
"input": "16:12",
"output": "230"
},
{
"input": "20:00",
"output": "2"
},
{
"input": "01:01",
"output": "9"
},
{
"input": "23:01",
"output": "31"
},
{
"input": "06:05",
"output": "236"
},
{
"input": "19:19",
"output": "43"
},
{
"input": "17:00",
"output": "182"
},
{
"input": "07:50",
"output": "131"
},
{
"input": "21:20",
"output": "62"
},
{
"input": "23:23",
"output": "9"
},
{
"input": "19:30",
"output": "32"
},
{
"input": "00:59",
"output": "11"
},
{
"input": "22:59",
"output": "33"
},
{
"input": "18:18",
"output": "104"
},
{
"input": "17:46",
"output": "136"
},
{
"input": "07:30",
"output": "151"
},
{
"input": "17:16",
"output": "166"
},
{
"input": "06:06",
"output": "235"
},
{
"input": "23:30",
"output": "2"
},
{
"input": "05:57",
"output": "244"
},
{
"input": "19:46",
"output": "16"
},
{
"input": "11:10",
"output": "1"
},
{
"input": "17:07",
"output": "175"
},
{
"input": "18:53",
"output": "69"
},
{
"input": "07:06",
"output": "175"
},
{
"input": "17:50",
"output": "132"
},
{
"input": "09:15",
"output": "46"
},
{
"input": "09:55",
"output": "6"
},
{
"input": "20:05",
"output": "67"
},
{
"input": "22:55",
"output": "37"
},
{
"input": "10:00",
"output": "1"
},
{
"input": "07:55",
"output": "126"
},
{
"input": "07:40",
"output": "141"
},
{
"input": "19:08",
"output": "54"
},
{
"input": "23:24",
"output": "8"
},
{
"input": "16:15",
"output": "227"
},
{
"input": "07:20",
"output": "161"
},
{
"input": "23:10",
"output": "22"
},
{
"input": "06:51",
"output": "190"
},
{
"input": "16:30",
"output": "212"
},
{
"input": "17:54",
"output": "128"
},
{
"input": "07:07",
"output": "174"
},
{
"input": "08:01",
"output": "120"
},
{
"input": "09:58",
"output": "3"
},
{
"input": "18:03",
"output": "119"
},
{
"input": "07:59",
"output": "122"
},
{
"input": "05:55",
"output": "246"
},
{
"input": "07:39",
"output": "142"
},
{
"input": "05:52",
"output": "249"
},
{
"input": "12:02",
"output": "19"
},
{
"input": "08:59",
"output": "62"
},
{
"input": "09:21",
"output": "40"
},
{
"input": "16:04",
"output": "238"
},
{
"input": "04:00",
"output": "40"
},
{
"input": "18:21",
"output": "101"
},
{
"input": "09:13",
"output": "48"
},
{
"input": "17:20",
"output": "162"
},
{
"input": "06:15",
"output": "226"
},
{
"input": "19:21",
"output": "41"
},
{
"input": "16:02",
"output": "240"
},
{
"input": "15:59",
"output": "243"
},
{
"input": "06:07",
"output": "234"
},
{
"input": "08:08",
"output": "113"
},
{
"input": "09:09",
"output": "52"
},
{
"input": "02:19",
"output": "1"
},
{
"input": "21:59",
"output": "23"
}
] | 1,627,153,090 | 2,147,483,647 | Python 3 | OK | TESTS | 160 | 77 | 6,758,400 | h,m=map(int,input().split(":"))
i=0
while h//10!=m%10 or h%10!=m//10:
m=m+1
i=i+1
if m==60:
m=0
h=h+1
h=h%24
print(i) | Title: Karen and Morning
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Karen is getting ready for a new school day!
It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.
What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?
Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.
Input Specification:
The first and only line of input contains a single string in the format hh:mm (00<=≤<= hh <=≤<=23, 00<=≤<= mm <=≤<=59).
Output Specification:
Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.
Demo Input:
['05:39\n', '13:31\n', '23:59\n']
Demo Output:
['11\n', '0\n', '1\n']
Note:
In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.
In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.
In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome. | ```python
h,m=map(int,input().split(":"))
i=0
while h//10!=m%10 or h%10!=m//10:
m=m+1
i=i+1
if m==60:
m=0
h=h+1
h=h%24
print(i)
``` | 3 |
|
873 | B | Balanced Substring | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to determine the length of the longest balanced substring of *s*. | The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*. | If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring. | [
"8\n11010111\n",
"3\n111\n"
] | [
"4\n",
"0\n"
] | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | 0 | [
{
"input": "8\n11010111",
"output": "4"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "11\n00001000100",
"output": "2"
},
{
"input": "10\n0100000000",
"output": "2"
},
{
"input": "13\n0001000011010",
"output": "6"
},
{
"input": "14\n00000100101011",
"output": "10"
},
{
"input": "14\n01111101111111",
"output": "2"
},
{
"input": "18\n110010101101111111",
"output": "10"
},
{
"input": "11\n00010000011",
"output": "4"
},
{
"input": "10\n1000010110",
"output": "6"
},
{
"input": "15\n100000100000011",
"output": "4"
},
{
"input": "18\n011010101110111101",
"output": "8"
},
{
"input": "10\n0011011111",
"output": "6"
},
{
"input": "3\n011",
"output": "2"
},
{
"input": "14\n11111111111111",
"output": "0"
},
{
"input": "65\n11001000110001001011011110111100000000101001001010101111000100010",
"output": "48"
},
{
"input": "10\n0011111000",
"output": "10"
},
{
"input": "13\n1110000001110",
"output": "12"
},
{
"input": "3\n110",
"output": "2"
},
{
"input": "4\n1110",
"output": "2"
},
{
"input": "9\n001011001",
"output": "8"
},
{
"input": "2\n10",
"output": "2"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "12\n110000110000",
"output": "8"
},
{
"input": "3\n001",
"output": "2"
},
{
"input": "14\n11000011000000",
"output": "8"
},
{
"input": "19\n0000011111111100000",
"output": "18"
},
{
"input": "45\n011010001100001111110001011100000001101100111",
"output": "44"
},
{
"input": "18\n000001111111100000",
"output": "16"
},
{
"input": "4\n0101",
"output": "4"
},
{
"input": "12\n000101011001",
"output": "10"
}
] | 1,694,448,020 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | def prefix(string, num=0):
pref = []
pref.append(0)
for i in range(1, len(string)+1):
if int(string[i-1]) == num:
pref.append(pref[i - 1] + 1)
else:
pref.append(pref[i - 1])
return pref
n = int(input())
str1 = input()
res1 = prefix(str1)
res2 = prefix(str1, 1)
max1 = max(res1)
max2 = max(res2)
if max1 > max2 and max2 in res1[1:]:
index1 = res1.index(max2,1)
index2 = res2.index(max2,1)
res = index2 - index1 + 1
elif max2 > max1 and max1 in res2[1:]:
index1 = res1.index(max1,1)
index2 = res2.index(max1,1)
res = index1 - index2 + 1
else:
res = 0
print(res)
| Title: Balanced Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting only of characters 0 and 1. A substring [*l*,<=*r*] of *s* is a string *s**l**s**l*<=+<=1*s**l*<=+<=2... *s**r*, and its length equals to *r*<=-<=*l*<=+<=1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to determine the length of the longest balanced substring of *s*.
Input Specification:
The first line contains *n* (1<=≤<=*n*<=≤<=100000) — the number of characters in *s*.
The second line contains a string *s* consisting of exactly *n* characters. Only characters 0 and 1 can appear in *s*.
Output Specification:
If there is no non-empty balanced substring in *s*, print 0. Otherwise, print the length of the longest balanced substring.
Demo Input:
['8\n11010111\n', '3\n111\n']
Demo Output:
['4\n', '0\n']
Note:
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | ```python
def prefix(string, num=0):
pref = []
pref.append(0)
for i in range(1, len(string)+1):
if int(string[i-1]) == num:
pref.append(pref[i - 1] + 1)
else:
pref.append(pref[i - 1])
return pref
n = int(input())
str1 = input()
res1 = prefix(str1)
res2 = prefix(str1, 1)
max1 = max(res1)
max2 = max(res2)
if max1 > max2 and max2 in res1[1:]:
index1 = res1.index(max2,1)
index2 = res2.index(max2,1)
res = index2 - index1 + 1
elif max2 > max1 and max1 in res2[1:]:
index1 = res1.index(max1,1)
index2 = res2.index(max1,1)
res = index1 - index2 + 1
else:
res = 0
print(res)
``` | 0 |
|
675 | B | Restoring Painting | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.
- The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*, and different cells may contain either different or equal integers. - The sum of integers in each of four squares 2<=×<=2 is equal to the sum of integers in the top left square 2<=×<=2. - Four elements *a*, *b*, *c* and *d* are known and are located as shown on the picture below.
Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.
Two squares are considered to be different, if there exists a cell that contains two different integers in different squares. | The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers. | Print one integer — the number of distinct valid squares. | [
"2 1 1 1 2\n",
"3 3 1 2 3\n"
] | [
"2\n",
"6\n"
] | Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the second sample, only paintings displayed below satisfy all the rules. <img class="tex-graphics" src="https://espresso.codeforces.com/776f231305f8ce7c33e79e887722ce46aa8b6e61.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/2fce9e9a31e70f1e46ea26f11d7305b3414e9b6b.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/be084a4d1f7e475be1183f7dff10e9c89eb175ef.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/96afdb4a35ac14f595d29bea2282f621098902f4.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/79ca8d720334a74910514f017ecf1d0166009a03.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/ad3c37e950bf5702d54f05756db35c831da59ad9.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 1 1 1 2",
"output": "2"
},
{
"input": "3 3 1 2 3",
"output": "6"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1000 522 575 426 445",
"output": "774000"
},
{
"input": "99000 52853 14347 64237 88869",
"output": "1296306000"
},
{
"input": "100000 2 2 2 2",
"output": "10000000000"
},
{
"input": "2 1 1 2 2",
"output": "0"
},
{
"input": "10 9 10 8 10",
"output": "70"
},
{
"input": "100 19 16 35 83",
"output": "1700"
},
{
"input": "1000 102 583 606 929",
"output": "150000"
},
{
"input": "10000 1816 3333 6908 7766",
"output": "4750000"
},
{
"input": "100000 80015 84290 50777 30497",
"output": "1696900000"
},
{
"input": "100000 64022 49026 55956 88430",
"output": "6866200000"
},
{
"input": "100000 10263 46628 10268 22948",
"output": "5095500000"
},
{
"input": "100000 81311 81584 51625 57276",
"output": "4600600000"
},
{
"input": "100000 77594 3226 21255 8541",
"output": "1291800000"
},
{
"input": "100000 65131 35523 58220 87645",
"output": "5478900000"
},
{
"input": "100000 83958 32567 91083 95317",
"output": "3012500000"
},
{
"input": "100000 36851 54432 21164 85520",
"output": "1806300000"
},
{
"input": "100000 55732 17473 23832 75148",
"output": "7422500000"
},
{
"input": "100000 60789 25296 49585 25237",
"output": "4015900000"
},
{
"input": "100000 92060 77234 58709 36956",
"output": "2637100000"
},
{
"input": "100000 87223 66046 27153 40823",
"output": "1470700000"
},
{
"input": "100000 3809 35468 34556 51158",
"output": "5173900000"
},
{
"input": "100000 35038 37363 95275 88903",
"output": "0"
},
{
"input": "100000 45274 9250 36558 49486",
"output": "6848000000"
},
{
"input": "100000 1 1 1 1",
"output": "10000000000"
},
{
"input": "100000 1 1 1 100000",
"output": "100000"
},
{
"input": "100000 1 1 100000 1",
"output": "100000"
},
{
"input": "100000 1 1 100000 100000",
"output": "0"
},
{
"input": "100000 1 100000 1 1",
"output": "100000"
},
{
"input": "100000 1 100000 1 100000",
"output": "0"
},
{
"input": "100000 1 100000 100000 1",
"output": "10000000000"
},
{
"input": "100000 1 100000 100000 100000",
"output": "100000"
},
{
"input": "100000 100000 1 1 1",
"output": "100000"
},
{
"input": "100000 100000 1 1 100000",
"output": "10000000000"
},
{
"input": "100000 100000 1 100000 1",
"output": "0"
},
{
"input": "100000 100000 1 100000 100000",
"output": "100000"
},
{
"input": "100000 100000 100000 1 1",
"output": "0"
},
{
"input": "100000 100000 100000 1 100000",
"output": "100000"
},
{
"input": "100000 100000 100000 100000 1",
"output": "100000"
},
{
"input": "100000 100000 100000 100000 100000",
"output": "10000000000"
},
{
"input": "3 3 3 1 1",
"output": "0"
},
{
"input": "10 1 2 5 10",
"output": "0"
},
{
"input": "5 1 1 5 5",
"output": "0"
},
{
"input": "4 4 4 1 1",
"output": "0"
},
{
"input": "10 10 10 1 1",
"output": "0"
},
{
"input": "5 5 5 1 1",
"output": "0"
},
{
"input": "100 100 100 1 1",
"output": "0"
},
{
"input": "3 1 1 3 3",
"output": "0"
},
{
"input": "10 2 10 1 10",
"output": "0"
},
{
"input": "7 7 7 1 1",
"output": "0"
},
{
"input": "5 5 3 4 1",
"output": "0"
},
{
"input": "7 1 1 7 7",
"output": "0"
},
{
"input": "100 1 1 100 100",
"output": "0"
},
{
"input": "123 1 2 3 100",
"output": "2829"
},
{
"input": "10 1 1 10 10",
"output": "0"
},
{
"input": "803 525 6 623 8",
"output": "0"
}
] | 1,570,560,946 | 5,146 | Python 3 | OK | TESTS | 58 | 296 | 0 | n, a, b, c, d = map(int, input().split())
ans = 0
for centro in range(1, n+1):
q1 = a + b + centro
q2 = a + c + centro
q3 = b + d + centro
q4 = c + d + centro
v = [q1, q2, q3, q4]
v.sort()
q_min = v[0]
q_max = v[-1]
if q_min + n < q_max + 1:
continue
elif q_min + n == q_max + 1:
ans += 1
else:
ans += (q_min + n) - (q_max + 1) + 1
print(ans)
| Title: Restoring Painting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.
- The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*, and different cells may contain either different or equal integers. - The sum of integers in each of four squares 2<=×<=2 is equal to the sum of integers in the top left square 2<=×<=2. - Four elements *a*, *b*, *c* and *d* are known and are located as shown on the picture below.
Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.
Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.
Input Specification:
The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers.
Output Specification:
Print one integer — the number of distinct valid squares.
Demo Input:
['2 1 1 1 2\n', '3 3 1 2 3\n']
Demo Output:
['2\n', '6\n']
Note:
Below are all the possible paintings for the first sample. <img class="tex-graphics" src="https://espresso.codeforces.com/c4c53d4e7b6814d8aad7b72604b6089d61dadb48.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/46a6ad6a5d3db202f3779b045b9dc77fc2348cf1.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the second sample, only paintings displayed below satisfy all the rules. <img class="tex-graphics" src="https://espresso.codeforces.com/776f231305f8ce7c33e79e887722ce46aa8b6e61.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/2fce9e9a31e70f1e46ea26f11d7305b3414e9b6b.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/be084a4d1f7e475be1183f7dff10e9c89eb175ef.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/96afdb4a35ac14f595d29bea2282f621098902f4.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/79ca8d720334a74910514f017ecf1d0166009a03.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/ad3c37e950bf5702d54f05756db35c831da59ad9.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
n, a, b, c, d = map(int, input().split())
ans = 0
for centro in range(1, n+1):
q1 = a + b + centro
q2 = a + c + centro
q3 = b + d + centro
q4 = c + d + centro
v = [q1, q2, q3, q4]
v.sort()
q_min = v[0]
q_max = v[-1]
if q_min + n < q_max + 1:
continue
elif q_min + n == q_max + 1:
ans += 1
else:
ans += (q_min + n) - (q_max + 1) + 1
print(ans)
``` | 3 |
|
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
"output": "21223442"
},
{
"input": "91730629",
"output": "91230320"
},
{
"input": "420062703497",
"output": "420032203402"
},
{
"input": "332711047202",
"output": "332211042202"
},
{
"input": "3395184971407775",
"output": "3304114021402224"
},
{
"input": "8464062628894325",
"output": "1434032321104324"
},
{
"input": "164324828731963982",
"output": "134324121231033012"
},
{
"input": "384979173822804784",
"output": "314020123122104214"
},
{
"input": "41312150450968417",
"output": "41312140440031412"
},
{
"input": "2156",
"output": "2143"
},
{
"input": "1932",
"output": "1032"
},
{
"input": "5902",
"output": "4002"
},
{
"input": "5728",
"output": "4221"
},
{
"input": "8537",
"output": "1432"
},
{
"input": "55403857",
"output": "44403142"
},
{
"input": "270739",
"output": "220230"
},
{
"input": "28746918",
"output": "21243011"
},
{
"input": "10279211",
"output": "10220211"
},
{
"input": "40289679",
"output": "40210320"
},
{
"input": "545203238506",
"output": "444203231403"
},
{
"input": "461117063340",
"output": "431112033340"
},
{
"input": "658492686568",
"output": "341402313431"
},
{
"input": "857373361868",
"output": "142323331131"
},
{
"input": "429325660016",
"output": "420324330013"
},
{
"input": "9894448650287940",
"output": "9104441340212040"
},
{
"input": "6354510839296263",
"output": "3344410130203233"
},
{
"input": "6873575462224593",
"output": "3123424432224403"
},
{
"input": "4237951492601449",
"output": "4232041402301440"
},
{
"input": "2680352384836991",
"output": "2310342314133001"
},
{
"input": "606187734191890310",
"output": "303112234101100310"
},
{
"input": "351499943576823355",
"output": "341400043423123344"
},
{
"input": "180593481782177068",
"output": "110403411212122031"
},
{
"input": "999999999999999999",
"output": "900000000000000000"
},
{
"input": "1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "9999",
"output": "9000"
},
{
"input": "99",
"output": "90"
},
{
"input": "9991",
"output": "9001"
}
] | 1,690,623,841 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 38 | 46 | 0 | def m(c):
if c in "56789":
return str(9 - int(c))
return c
a = list(input())
s = 0
for i in range(len(a)):
if s == 0:
if a[i] == '9':
continue
s = 1
a[i] = m(a[i])
else:
a[i] = m(a[i])
if a == ['0']:
print(9)
else:
print("".join(a))
| Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
Input Specification:
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Output Specification:
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
Demo Input:
['27\n', '4545\n']
Demo Output:
['22\n', '4444\n']
Note:
none | ```python
def m(c):
if c in "56789":
return str(9 - int(c))
return c
a = list(input())
s = 0
for i in range(len(a)):
if s == 0:
if a[i] == '9':
continue
s = 1
a[i] = m(a[i])
else:
a[i] = m(a[i])
if a == ['0']:
print(9)
else:
print("".join(a))
``` | 0 |
|
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,632,871,963 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input))
for j in range(n):
k=int(input())
if k<60 :
print('NO')
elif 360%(180-k)==o:
print('YES')
else:
print('NO')
| Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
Input Specification:
The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees.
Output Specification:
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
Demo Input:
['3\n30\n60\n90\n']
Demo Output:
['NO\nYES\nYES\n']
Note:
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | ```python
n=int(input))
for j in range(n):
k=int(input())
if k<60 :
print('NO')
elif 360%(180-k)==o:
print('YES')
else:
print('NO')
``` | -1 |
|
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},
{
"input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734",
"output": "ksjuuerbnlklcfdjeyq"
},
{
"input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879",
"output": "fcgslzkicjrpbqaifgweyzreajjfdo"
},
{
"input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735",
"output": "aawtvezfntstrcpgbzjbf"
},
{
"input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158",
"output": "ivhgbxiv"
}
] | 1,463,460,339 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 4,505,600 | n = int(input())
d = {}
for i in range(n):
ins = input().split(" ")
iname = ins[0]
iscore = int(ins[1])
xt = d.get(iname)
if xt != None:
iscore += xt[0]
d.update({iname: (iscore, i)})
w = ["", (0, 0)]
for t in d.items():
if t[1][0] > w[1][0] or (t[1][0] == w[1][0] and t[1][1] < w[1][1]):
w = t
print(t[0])
| Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
Input Specification:
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Output Specification:
Print the name of the winner.
Demo Input:
['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n']
Demo Output:
['andrew\n', 'andrew\n']
Note:
none | ```python
n = int(input())
d = {}
for i in range(n):
ins = input().split(" ")
iname = ins[0]
iscore = int(ins[1])
xt = d.get(iname)
if xt != None:
iscore += xt[0]
d.update({iname: (iscore, i)})
w = ["", (0, 0)]
for t in d.items():
if t[1][0] > w[1][0] or (t[1][0] == w[1][0] and t[1][1] < w[1][1]):
w = t
print(t[0])
``` | 0 |
837 | G | Functions On The Segments | PROGRAMMING | 2,500 | [
"data structures"
] | null | null | You have an array *f* of *n* functions.The function *f**i*(*x*) (1<=≤<=*i*<=≤<=*n*) is characterized by parameters: *x*1,<=*x*2,<=*y*1,<=*a*,<=*b*,<=*y*2 and take values:
- *y*1, if *x*<=≤<=*x*1. - *a*·*x*<=+<=*b*, if *x*1<=<<=*x*<=≤<=*x*2. - *y*2, if *x*<=><=*x*2.
There are *m* queries. Each query is determined by numbers *l*, *r* and *x*. For a query with number *i* (1<=≤<=*i*<=≤<=*m*), you need to calculate the sum of all *f**j*(*x**i*) where *l*<=≤<=*j*<=≤<=*r*. The value of *x**i* is calculated as follows: *x**i*<==<=(*x*<=+<=*last*) mod 109, where *last* is the answer to the query with number *i*<=-<=1. The value of *last* equals 0 if *i*<==<=1. | First line contains one integer number *n* (1<=≤<=*n*<=≤<=75000).
Each of the next *n* lines contains six integer numbers: *x*1,<=*x*2,<=*y*1,<=*a*,<=*b*,<=*y*2 (0<=≤<=*x*1<=<<=*x*2<=≤<=2·105, 0<=≤<=*y*1,<=*y*2<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=104).
Next line contains one integer number *m* (1<=≤<=*m*<=≤<=500000).
Each of the next *m* lines contains three integer numbers: *l*, *r* and *x* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, 0<=≤<=*x*<=≤<=109). | none | [
"1\n1 2 1 4 5 10\n1\n1 1 2\n",
"3\n2 5 1 1 1 4\n3 6 8 2 5 7\n1 3 5 1 4 10\n3\n1 3 3\n2 3 2\n1 2 5\n"
] | [
"13\n",
"19\n17\n11\n"
] | none | 0 | [
{
"input": "1\n1 2 1 4 5 10\n1\n1 1 2",
"output": "13"
},
{
"input": "3\n2 5 1 1 1 4\n3 6 8 2 5 7\n1 3 5 1 4 10\n3\n1 3 3\n2 3 2\n1 2 5",
"output": "19\n17\n11"
},
{
"input": "7\n4 8 562244866 6 8 140807945\n5 7 415374420 7 6 596093578\n3 4 766370993 3 7 973128805\n4 6 841321398 3 2 893107667\n4 9 968214628 5 8 329310838\n0 10 64315145 9 4 716996081\n1 6 568407659 3 0 22184171\n15\n4 7 647898558\n6 7 972924557\n7 7 222835064\n4 7 605696049\n3 3 549028549\n7 7 716270684\n2 4 716558406\n3 3 681131761\n2 2 177328926\n3 6 298280462\n6 7 256719966\n3 3 554401527\n5 6 136725488\n5 6 457040333\n7 7 176796906",
"output": "1961598757\n739180252\n22184171\n1961598757\n973128805\n22184171\n2462330050\n973128805\n596093578\n2912543391\n739180252\n973128805\n1046306919\n1046306919\n22184171"
},
{
"input": "8\n1 10 753310968 2 4 688105437\n1 6 193355966 4 7 598962222\n0 8 600395827 5 8 840898713\n0 3 421099093 10 3 239232128\n7 8 984393026 4 0 820591274\n2 3 99820619 1 4 750632847\n8 10 582155129 0 6 387245981\n5 6 667916797 0 4 3445518\n15\n5 5 361972828\n7 8 705501679\n8 8 890961558\n6 6 865121916\n7 7 595820781\n6 7 782831246\n6 6 295277930\n2 5 251627063\n2 6 439397863\n7 7 104400662\n6 8 219241770\n3 4 429934639\n5 6 858415301\n2 4 36071843\n4 7 976548276",
"output": "820591274\n390691499\n3445518\n750632847\n387245981\n1137878828\n750632847\n2499684337\n3250317184\n387245981\n1141324346\n1080130841\n1571224121\n1679093063\n2197702230"
},
{
"input": "9\n3 10 280813558 6 3 193933732\n3 9 971337514 8 4 896798158\n3 7 803016882 1 6 413701329\n2 10 74505717 6 8 658985518\n2 10 571422 8 3 680467929\n9 10 766729875 4 9 415673394\n5 6 669531526 3 0 752307791\n4 7 98000452 6 5 681772410\n8 10 722448957 9 3 55646997\n15\n3 5 232894565\n6 6 13973148\n9 9 401454228\n4 5 253126950\n6 7 708194225\n1 2 868537175\n2 3 32141176\n7 9 949367089\n1 9 596725344\n7 7 624167310\n1 1 835000987\n9 9 526102998\n4 7 50218935\n1 7 695691438\n5 6 878938576",
"output": "1753154776\n415673394\n55646997\n1339453447\n1167981185\n1090731890\n1310499487\n1489727198\n4749287258\n752307791\n193933732\n55646997\n2507434632\n4011867851\n1096141323"
}
] | 1,690,495,159 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1690495159.3495986")# 1690495159.3496218 | Title: Functions On The Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *f* of *n* functions.The function *f**i*(*x*) (1<=≤<=*i*<=≤<=*n*) is characterized by parameters: *x*1,<=*x*2,<=*y*1,<=*a*,<=*b*,<=*y*2 and take values:
- *y*1, if *x*<=≤<=*x*1. - *a*·*x*<=+<=*b*, if *x*1<=<<=*x*<=≤<=*x*2. - *y*2, if *x*<=><=*x*2.
There are *m* queries. Each query is determined by numbers *l*, *r* and *x*. For a query with number *i* (1<=≤<=*i*<=≤<=*m*), you need to calculate the sum of all *f**j*(*x**i*) where *l*<=≤<=*j*<=≤<=*r*. The value of *x**i* is calculated as follows: *x**i*<==<=(*x*<=+<=*last*) mod 109, where *last* is the answer to the query with number *i*<=-<=1. The value of *last* equals 0 if *i*<==<=1.
Input Specification:
First line contains one integer number *n* (1<=≤<=*n*<=≤<=75000).
Each of the next *n* lines contains six integer numbers: *x*1,<=*x*2,<=*y*1,<=*a*,<=*b*,<=*y*2 (0<=≤<=*x*1<=<<=*x*2<=≤<=2·105, 0<=≤<=*y*1,<=*y*2<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=104).
Next line contains one integer number *m* (1<=≤<=*m*<=≤<=500000).
Each of the next *m* lines contains three integer numbers: *l*, *r* and *x* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, 0<=≤<=*x*<=≤<=109).
Output Specification:
none
Demo Input:
['1\n1 2 1 4 5 10\n1\n1 1 2\n', '3\n2 5 1 1 1 4\n3 6 8 2 5 7\n1 3 5 1 4 10\n3\n1 3 3\n2 3 2\n1 2 5\n']
Demo Output:
['13\n', '19\n17\n11\n']
Note:
none | ```python
print("_RANDOM_GUESS_1690495159.3495986")# 1690495159.3496218
``` | 0 |
|
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task. | The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using *k* colors, you can output any of them. | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 "
},
{
"input": "105",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 "
},
{
"input": "123",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "452",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "641",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "293",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "733",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "10",
"output": "2\n1 1 2 1 2 1 2 2 2 1 "
},
{
"input": "287",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "3202",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "728",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "3509",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "5137",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "2023",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "4890",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "8507",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "1796",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "3466",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "1098",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "11226",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "11731",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "11644",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "14553",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "17307",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "23189",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "6818",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "1054",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "28163",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "30885",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "27673",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "11656",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "36325",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "31205",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "29958",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "1696",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "44907",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "13736",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "29594",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "19283",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "15346",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "41794",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "99998",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "100000",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "100000",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "99971",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
}
] | 1,649,050,264 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | #sieve of Eratosthenes
x=int(input())
mo=x+10
prime=[True for i in range(mo)]
prime[0]=False
prime[1]=False
# sieve only till root of n
for i in range(0,int((mo)**0.5),1):
if prime[i]:
for j in range(i*i,mo,i):
prime[j]=False
#print(*prime)
primes=[]
if x>2:
print(2)
else:
print(1)
for i in range(2,x+2):
if prime[i]:
print(1,end=" ")
else:
print(2,end=" ")
| Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input Specification:
The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces.
Output Specification:
The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using *k* colors, you can output any of them.
Demo Input:
['3\n', '4\n']
Demo Output:
['2\n1 1 2 ', '2\n2 1 1 2\n']
Note:
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | ```python
#sieve of Eratosthenes
x=int(input())
mo=x+10
prime=[True for i in range(mo)]
prime[0]=False
prime[1]=False
# sieve only till root of n
for i in range(0,int((mo)**0.5),1):
if prime[i]:
for j in range(i*i,mo,i):
prime[j]=False
#print(*prime)
primes=[]
if x>2:
print(2)
else:
print(1)
for i in range(2,x+2):
if prime[i]:
print(1,end=" ")
else:
print(2,end=" ")
``` | 0 |
|
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates. | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct. | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182 184\n806 663\n468 459",
"output": "21"
},
{
"input": "17\n660 646\n440 442\n689 618\n441 415\n922 865\n950 972\n312 366\n203 229\n873 860\n219 199\n344 308\n169 176\n961 992\n153 84\n201 230\n987 938\n834 815",
"output": "16"
},
{
"input": "11\n798 845\n722 911\n374 270\n629 537\n748 856\n831 885\n486 641\n751 829\n609 492\n98 27\n654 663",
"output": "10"
},
{
"input": "1\n321 88",
"output": "0"
},
{
"input": "9\n811 859\n656 676\n76 141\n945 951\n497 455\n18 55\n335 294\n267 275\n656 689",
"output": "7"
},
{
"input": "7\n948 946\n130 130\n761 758\n941 938\n971 971\n387 385\n509 510",
"output": "6"
},
{
"input": "6\n535 699\n217 337\n508 780\n180 292\n393 112\n732 888",
"output": "5"
},
{
"input": "14\n25 23\n499 406\n193 266\n823 751\n219 227\n101 138\n978 992\n43 74\n997 932\n237 189\n634 538\n774 740\n842 767\n742 802",
"output": "13"
},
{
"input": "12\n548 506\n151 198\n370 380\n655 694\n654 690\n407 370\n518 497\n819 827\n765 751\n802 771\n741 752\n653 662",
"output": "11"
},
{
"input": "40\n685 711\n433 403\n703 710\n491 485\n616 619\n288 282\n884 871\n367 352\n500 511\n977 982\n51 31\n576 564\n508 519\n755 762\n22 20\n368 353\n232 225\n953 955\n452 436\n311 330\n967 988\n369 364\n791 803\n150 149\n651 661\n118 93\n398 387\n748 766\n852 852\n230 228\n555 545\n515 519\n667 678\n867 862\n134 146\n859 863\n96 99\n486 469\n303 296\n780 786",
"output": "38"
},
{
"input": "3\n175 201\n907 909\n388 360",
"output": "2"
},
{
"input": "7\n312 298\n86 78\n73 97\n619 594\n403 451\n538 528\n71 86",
"output": "6"
},
{
"input": "19\n802 820\n368 248\n758 794\n455 378\n876 888\n771 814\n245 177\n586 555\n844 842\n364 360\n820 856\n731 624\n982 975\n825 856\n122 121\n862 896\n42 4\n792 841\n828 820",
"output": "16"
},
{
"input": "32\n643 877\n842 614\n387 176\n99 338\n894 798\n652 728\n611 648\n622 694\n579 781\n243 46\n322 305\n198 438\n708 579\n246 325\n536 459\n874 593\n120 277\n989 907\n223 110\n35 130\n761 692\n690 661\n518 766\n226 93\n678 597\n725 617\n661 574\n775 496\n56 416\n14 189\n358 359\n898 901",
"output": "31"
},
{
"input": "32\n325 327\n20 22\n72 74\n935 933\n664 663\n726 729\n785 784\n170 171\n315 314\n577 580\n984 987\n313 317\n434 435\n962 961\n55 54\n46 44\n743 742\n434 433\n617 612\n332 332\n883 886\n940 936\n793 792\n645 644\n611 607\n418 418\n465 465\n219 218\n167 164\n56 54\n403 405\n210 210",
"output": "29"
},
{
"input": "32\n652 712\n260 241\n27 154\n188 16\n521 351\n518 356\n452 540\n790 827\n339 396\n336 551\n897 930\n828 627\n27 168\n180 113\n134 67\n794 671\n812 711\n100 241\n686 813\n138 289\n384 506\n884 932\n913 959\n470 508\n730 734\n373 478\n788 862\n392 426\n148 68\n113 49\n713 852\n924 894",
"output": "29"
},
{
"input": "14\n685 808\n542 677\n712 747\n832 852\n187 410\n399 338\n626 556\n530 635\n267 145\n215 209\n559 684\n944 949\n753 596\n601 823",
"output": "13"
},
{
"input": "5\n175 158\n16 2\n397 381\n668 686\n957 945",
"output": "4"
},
{
"input": "5\n312 284\n490 509\n730 747\n504 497\n782 793",
"output": "4"
},
{
"input": "2\n802 903\n476 348",
"output": "1"
},
{
"input": "4\n325 343\n425 442\n785 798\n275 270",
"output": "3"
},
{
"input": "28\n462 483\n411 401\n118 94\n111 127\n5 6\n70 52\n893 910\n73 63\n818 818\n182 201\n642 633\n900 886\n893 886\n684 700\n157 173\n953 953\n671 660\n224 225\n832 801\n152 157\n601 585\n115 101\n739 722\n611 606\n659 642\n461 469\n702 689\n649 653",
"output": "25"
},
{
"input": "36\n952 981\n885 900\n803 790\n107 129\n670 654\n143 132\n66 58\n813 819\n849 837\n165 198\n247 228\n15 39\n619 618\n105 138\n868 855\n965 957\n293 298\n613 599\n227 212\n745 754\n723 704\n877 858\n503 487\n678 697\n592 595\n155 135\n962 982\n93 89\n660 673\n225 212\n967 987\n690 680\n804 813\n489 518\n240 221\n111 124",
"output": "34"
},
{
"input": "30\n89 3\n167 156\n784 849\n943 937\n144 95\n24 159\n80 120\n657 683\n585 596\n43 147\n909 964\n131 84\n345 389\n333 321\n91 126\n274 325\n859 723\n866 922\n622 595\n690 752\n902 944\n127 170\n426 383\n905 925\n172 284\n793 810\n414 510\n890 884\n123 24\n267 255",
"output": "29"
},
{
"input": "5\n664 666\n951 941\n739 742\n844 842\n2 2",
"output": "4"
},
{
"input": "3\n939 867\n411 427\n757 708",
"output": "2"
},
{
"input": "36\n429 424\n885 972\n442 386\n512 511\n751 759\n4 115\n461 497\n496 408\n8 23\n542 562\n296 331\n448 492\n412 395\n109 166\n622 640\n379 355\n251 262\n564 586\n66 115\n275 291\n666 611\n629 534\n510 567\n635 666\n738 803\n420 369\n92 17\n101 144\n141 92\n258 258\n184 235\n492 456\n311 210\n394 357\n531 512\n634 636",
"output": "34"
},
{
"input": "29\n462 519\n871 825\n127 335\n156 93\n576 612\n885 830\n634 779\n340 105\n744 795\n716 474\n93 139\n563 805\n137 276\n177 101\n333 14\n391 437\n873 588\n817 518\n460 597\n572 670\n140 303\n392 441\n273 120\n862 578\n670 639\n410 161\n544 577\n193 116\n252 195",
"output": "28"
},
{
"input": "23\n952 907\n345 356\n812 807\n344 328\n242 268\n254 280\n1000 990\n80 78\n424 396\n595 608\n755 813\n383 380\n55 56\n598 633\n203 211\n508 476\n600 593\n206 192\n855 882\n517 462\n967 994\n642 657\n493 488",
"output": "22"
},
{
"input": "10\n579 816\n806 590\n830 787\n120 278\n677 800\n16 67\n188 251\n559 560\n87 67\n104 235",
"output": "8"
},
{
"input": "23\n420 424\n280 303\n515 511\n956 948\n799 803\n441 455\n362 369\n299 289\n823 813\n982 967\n876 878\n185 157\n529 551\n964 989\n655 656\n1 21\n114 112\n45 56\n935 937\n1000 997\n934 942\n360 366\n648 621",
"output": "22"
},
{
"input": "23\n102 84\n562 608\n200 127\n952 999\n465 496\n322 367\n728 690\n143 147\n855 867\n861 866\n26 59\n300 273\n255 351\n192 246\n70 111\n365 277\n32 104\n298 319\n330 354\n241 141\n56 125\n315 298\n412 461",
"output": "22"
},
{
"input": "7\n429 506\n346 307\n99 171\n853 916\n322 263\n115 157\n906 924",
"output": "6"
},
{
"input": "3\n1 1\n2 1\n2 2",
"output": "0"
},
{
"input": "4\n1 1\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "5\n1 1\n1 2\n2 2\n3 1\n3 3",
"output": "0"
},
{
"input": "6\n1 1\n1 2\n2 2\n3 1\n3 2\n3 3",
"output": "0"
},
{
"input": "20\n1 1\n2 2\n3 3\n3 9\n4 4\n5 2\n5 5\n5 7\n5 8\n6 2\n6 6\n6 9\n7 7\n8 8\n9 4\n9 7\n9 9\n10 2\n10 9\n10 10",
"output": "1"
},
{
"input": "21\n1 1\n1 9\n2 1\n2 2\n2 5\n2 6\n2 9\n3 3\n3 8\n4 1\n4 4\n5 5\n5 8\n6 6\n7 7\n8 8\n9 9\n10 4\n10 10\n11 5\n11 11",
"output": "1"
},
{
"input": "22\n1 1\n1 3\n1 4\n1 8\n1 9\n1 11\n2 2\n3 3\n4 4\n4 5\n5 5\n6 6\n6 8\n7 7\n8 3\n8 4\n8 8\n9 9\n10 10\n11 4\n11 9\n11 11",
"output": "3"
},
{
"input": "50\n1 1\n2 2\n2 9\n3 3\n4 4\n4 9\n4 16\n4 24\n5 5\n6 6\n7 7\n8 8\n8 9\n8 20\n9 9\n10 10\n11 11\n12 12\n13 13\n14 7\n14 14\n14 16\n14 25\n15 4\n15 6\n15 15\n15 22\n16 6\n16 16\n17 17\n18 18\n19 6\n19 19\n20 20\n21 21\n22 6\n22 22\n23 23\n24 6\n24 7\n24 8\n24 9\n24 24\n25 1\n25 3\n25 5\n25 7\n25 23\n25 24\n25 25",
"output": "7"
},
{
"input": "55\n1 1\n1 14\n2 2\n2 19\n3 1\n3 3\n3 8\n3 14\n3 23\n4 1\n4 4\n5 5\n5 8\n5 15\n6 2\n6 3\n6 4\n6 6\n7 7\n8 8\n8 21\n9 9\n10 1\n10 10\n11 9\n11 11\n12 12\n13 13\n14 14\n15 15\n15 24\n16 5\n16 16\n17 5\n17 10\n17 17\n17 18\n17 22\n17 27\n18 18\n19 19\n20 20\n21 20\n21 21\n22 22\n23 23\n24 14\n24 24\n25 25\n26 8\n26 11\n26 26\n27 3\n27 27\n28 28",
"output": "5"
},
{
"input": "3\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "6\n4 4\n3 4\n5 4\n4 5\n4 3\n3 1",
"output": "0"
},
{
"input": "4\n1 1\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "3\n1 1\n2 2\n1 2",
"output": "0"
},
{
"input": "8\n1 3\n1 1\n4 1\n2 2\n2 5\n5 9\n5 1\n5 4",
"output": "1"
},
{
"input": "10\n1 1\n1 2\n1 3\n1 4\n5 5\n6 6\n7 7\n8 8\n9 9\n100 100",
"output": "6"
},
{
"input": "7\n1 1\n2 2\n3 3\n4 4\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "6\n1 1\n2 1\n2 2\n2 4\n4 3\n2 3",
"output": "0"
},
{
"input": "4\n3 1\n2 1\n2 2\n1 2",
"output": "0"
},
{
"input": "6\n1 1\n2 2\n2 1\n2 4\n4 3\n2 3",
"output": "0"
},
{
"input": "3\n1 2\n1 3\n1 4",
"output": "0"
},
{
"input": "4\n1 1\n2 2\n1 2\n2 1",
"output": "0"
},
{
"input": "4\n1 3\n2 1\n3 2\n3 1",
"output": "1"
},
{
"input": "7\n1 1\n1 2\n2 2\n3 3\n3 4\n4 4\n1 4",
"output": "0"
},
{
"input": "21\n12 12\n13 12\n12 11\n13 13\n10 10\n11 10\n11 11\n501 500\n501 501\n503 502\n500 500\n503 503\n502 501\n502 502\n700 700\n702 702\n703 702\n701 701\n702 701\n703 703\n701 700",
"output": "2"
},
{
"input": "6\n1 11\n6 8\n11 10\n1 10\n11 11\n6 9",
"output": "1"
},
{
"input": "4\n1 1\n2 2\n3 2\n3 1",
"output": "0"
},
{
"input": "3\n1 2\n3 4\n3 2",
"output": "0"
},
{
"input": "3\n1 1\n1 2\n2 2",
"output": "0"
},
{
"input": "4\n5 5\n5 4\n6 3\n6 4",
"output": "0"
},
{
"input": "3\n1 1\n2 2\n2 1",
"output": "0"
}
] | 1,670,291,882 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 512,000 | def calculate(elem):
if rank[elem] < 0:
rank[elem] = elem
if x != rank[elem]:
rank[elem]= calculate(rank[elem])
return rank[elem]
n = int(input())
rank = [-1] * 9999
for _ in range(n):
x, y = map(int, input().split())
y += 1000
n -= (rank[y] >= 0) + (rank[x] >= 0) - (calculate(y) == calculate(x))
rank[calculate(x)] = calculate(y)
print(n - 1)
| Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input Specification:
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
Output Specification:
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Demo Input:
['2\n2 1\n1 2\n', '2\n2 1\n4 1\n']
Demo Output:
['1\n', '0\n']
Note:
none | ```python
def calculate(elem):
if rank[elem] < 0:
rank[elem] = elem
if x != rank[elem]:
rank[elem]= calculate(rank[elem])
return rank[elem]
n = int(input())
rank = [-1] * 9999
for _ in range(n):
x, y = map(int, input().split())
y += 1000
n -= (rank[y] >= 0) + (rank[x] >= 0) - (calculate(y) == calculate(x))
rank[calculate(x)] = calculate(y)
print(n - 1)
``` | -1 |
|
920 | A | Water The Garden | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *x**i* is turned on, then after one second has passed, the bed *x**i* will be watered; after two seconds have passed, the beds from the segment [*x**i*<=-<=1,<=*x**i*<=+<=1] will be watered (if they exist); after *j* seconds have passed (*j* is an integer number), the beds from the segment [*x**i*<=-<=(*j*<=-<=1),<=*x**i*<=+<=(*j*<=-<=1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [*x**i*<=-<=2.5,<=*x**i*<=+<=2.5] will be watered after 2.5 seconds have passed; only the segment [*x**i*<=-<=2,<=*x**i*<=+<=2] will be watered at that moment.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer! | The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=200).
Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200, 1<=≤<=*k*<=≤<=*n*) — the number of garden beds and water taps, respectively.
Next line contains *k* integers *x**i* (1<=≤<=*x**i*<=≤<=*n*) — the location of *i*-th water tap. It is guaranteed that for each condition *x**i*<=-<=1<=<<=*x**i* holds.
It is guaranteed that the sum of *n* over all test cases doesn't exceed 200.
Note that in hacks you have to set *t*<==<=1. | For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered. | [
"3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n"
] | [
"3\n1\n4\n"
] | The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered. 1. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes. 1. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | 0 | [
{
"input": "3\n5 1\n3\n3 3\n1 2 3\n4 1\n1",
"output": "3\n1\n4"
},
{
"input": "26\n1 1\n1\n2 1\n2\n2 1\n1\n2 2\n1 2\n3 1\n3\n3 1\n2\n3 2\n2 3\n3 1\n1\n3 2\n1 3\n3 2\n1 2\n3 3\n1 2 3\n4 1\n4\n4 1\n3\n4 2\n3 4\n4 1\n2\n4 2\n2 4\n4 2\n2 3\n4 3\n2 3 4\n4 1\n1\n4 2\n1 4\n4 2\n1 3\n4 3\n1 3 4\n4 2\n1 2\n4 3\n1 2 4\n4 3\n1 2 3\n4 4\n1 2 3 4",
"output": "1\n2\n2\n1\n3\n2\n2\n3\n2\n2\n1\n4\n3\n3\n3\n2\n2\n2\n4\n2\n2\n2\n3\n2\n2\n1"
},
{
"input": "31\n5 1\n5\n5 1\n4\n5 2\n4 5\n5 1\n3\n5 2\n3 5\n5 2\n3 4\n5 3\n3 4 5\n5 1\n2\n5 2\n2 5\n5 2\n2 4\n5 3\n2 4 5\n5 2\n2 3\n5 3\n2 3 5\n5 3\n2 3 4\n5 4\n2 3 4 5\n5 1\n1\n5 2\n1 5\n5 2\n1 4\n5 3\n1 4 5\n5 2\n1 3\n5 3\n1 3 5\n5 3\n1 3 4\n5 4\n1 3 4 5\n5 2\n1 2\n5 3\n1 2 5\n5 3\n1 2 4\n5 4\n1 2 4 5\n5 3\n1 2 3\n5 4\n1 2 3 5\n5 4\n1 2 3 4\n5 5\n1 2 3 4 5",
"output": "5\n4\n4\n3\n3\n3\n3\n4\n2\n2\n2\n3\n2\n2\n2\n5\n3\n2\n2\n3\n2\n2\n2\n4\n2\n2\n2\n3\n2\n2\n1"
},
{
"input": "1\n200 1\n200",
"output": "200"
},
{
"input": "1\n5 1\n5",
"output": "5"
},
{
"input": "1\n177 99\n1 4 7 10 11 13 14 15 16 17 19 21 22 24 25 26 27 28 32 34 35 38 39 40 42 45 46 52 54 55 57 58 59 60 62 64 65 67 70 71 74 77 78 79 80 81 83 84 88 92 93 94 95 100 101 102 104 106 107 108 109 110 112 113 114 115 116 118 122 123 124 125 127 128 129 130 134 135 137 138 139 140 142 146 148 149 154 158 160 161 162 165 166 167 169 171 172 173 176",
"output": "4"
},
{
"input": "1\n69 12\n5 7 10 11 12 18 20 27 28 31 47 67",
"output": "11"
},
{
"input": "1\n74 7\n19 39 40 47 55 57 61",
"output": "19"
},
{
"input": "1\n170 11\n14 18 37 39 80 83 103 112 124 127 131",
"output": "40"
},
{
"input": "1\n200 1\n8",
"output": "193"
},
{
"input": "1\n155 53\n2 3 7 9 10 11 12 20 24 26 28 31 38 39 40 51 53 56 58 63 65 66 69 70 72 74 79 81 83 88 90 92 100 103 104 106 111 113 114 115 116 121 124 126 127 128 133 136 142 143 145 148 150",
"output": "6"
},
{
"input": "1\n161 69\n2 5 8 11 12 13 17 18 23 25 28 29 30 33 34 35 36 38 39 44 45 49 52 53 56 57 58 60 62 70 71 74 76 77 82 83 86 90 94 95 97 104 105 108 109 112 113 118 120 123 126 127 132 135 137 139 140 141 142 143 144 146 147 148 151 152 153 154 161",
"output": "5"
},
{
"input": "1\n8 4\n1 2 3 7",
"output": "3"
},
{
"input": "1\n12 2\n5 12",
"output": "5"
},
{
"input": "1\n13 2\n6 12",
"output": "6"
},
{
"input": "1\n13 2\n8 13",
"output": "8"
},
{
"input": "1\n10 4\n1 2 3 5",
"output": "6"
},
{
"input": "1\n200 2\n50 150",
"output": "51"
},
{
"input": "1\n110 2\n1 110",
"output": "55"
}
] | 1,606,739,971 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 108 | 307,200 | for z in range(int(input())):
a, b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))
e = c[0]
f = 0
for i in range(1, len(c)):
f = max(e, -(-(c[i] - c[i - 1]) // 2))
e = -(-(c[i] - c[i - 1]) // 2)
print(a - c[-1] + 1, f)
print(max(a - c[-1] + 1, f)) | Title: Water The Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as *n* consecutive garden beds, numbered from 1 to *n*. *k* beds contain water taps (*i*-th tap is located in the bed *x**i*), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed *x**i* is turned on, then after one second has passed, the bed *x**i* will be watered; after two seconds have passed, the beds from the segment [*x**i*<=-<=1,<=*x**i*<=+<=1] will be watered (if they exist); after *j* seconds have passed (*j* is an integer number), the beds from the segment [*x**i*<=-<=(*j*<=-<=1),<=*x**i*<=+<=(*j*<=-<=1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [*x**i*<=-<=2.5,<=*x**i*<=+<=2.5] will be watered after 2.5 seconds have passed; only the segment [*x**i*<=-<=2,<=*x**i*<=+<=2] will be watered at that moment.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input Specification:
The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=200).
Then *t* test cases follow. The first line of each test case contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200, 1<=≤<=*k*<=≤<=*n*) — the number of garden beds and water taps, respectively.
Next line contains *k* integers *x**i* (1<=≤<=*x**i*<=≤<=*n*) — the location of *i*-th water tap. It is guaranteed that for each condition *x**i*<=-<=1<=<<=*x**i* holds.
It is guaranteed that the sum of *n* over all test cases doesn't exceed 200.
Note that in hacks you have to set *t*<==<=1.
Output Specification:
For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Demo Input:
['3\n5 1\n3\n3 3\n1 2 3\n4 1\n1\n']
Demo Output:
['3\n1\n4\n']
Note:
The first example consists of 3 tests:
1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered. 1. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes. 1. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4. | ```python
for z in range(int(input())):
a, b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))
e = c[0]
f = 0
for i in range(1, len(c)):
f = max(e, -(-(c[i] - c[i - 1]) // 2))
e = -(-(c[i] - c[i - 1]) // 2)
print(a - c[-1] + 1, f)
print(max(a - c[-1] + 1, f))
``` | 0 |
|
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
"output": "1\n1 "
},
{
"input": "2\nBB",
"output": "1\n2 "
},
{
"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB",
"output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1\nW",
"output": "0"
},
{
"input": "2\nWW",
"output": "0"
},
{
"input": "2\nWB",
"output": "1\n1 "
},
{
"input": "2\nBW",
"output": "1\n1 "
},
{
"input": "3\nBBB",
"output": "1\n3 "
},
{
"input": "3\nBWB",
"output": "2\n1 1 "
},
{
"input": "3\nWBB",
"output": "1\n2 "
},
{
"input": "3\nWWB",
"output": "1\n1 "
},
{
"input": "3\nWBW",
"output": "1\n1 "
},
{
"input": "3\nBWW",
"output": "1\n1 "
},
{
"input": "3\nWWW",
"output": "0"
},
{
"input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB",
"output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 "
},
{
"input": "5\nBBBWB",
"output": "2\n3 1 "
},
{
"input": "5\nBWWWB",
"output": "2\n1 1 "
},
{
"input": "5\nWWWWB",
"output": "1\n1 "
},
{
"input": "5\nBWWWW",
"output": "1\n1 "
},
{
"input": "5\nBBBWW",
"output": "1\n3 "
},
{
"input": "5\nWWBBB",
"output": "1\n3 "
},
{
"input": "10\nBBBBBWWBBB",
"output": "2\n5 3 "
},
{
"input": "10\nBBBBWBBWBB",
"output": "3\n4 2 2 "
},
{
"input": "20\nBBBBBWWBWBBWBWWBWBBB",
"output": "6\n5 1 2 1 1 3 "
},
{
"input": "20\nBBBWWWWBBWWWBWBWWBBB",
"output": "5\n3 2 1 1 3 "
},
{
"input": "20\nBBBBBBBBWBBBWBWBWBBB",
"output": "5\n8 3 1 1 3 "
},
{
"input": "20\nBBBWBWBWWWBBWWWWBWBB",
"output": "6\n3 1 1 2 1 2 "
},
{
"input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB",
"output": "5\n6 1 1 1 12 "
},
{
"input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB",
"output": "9\n5 1 2 1 1 4 1 1 8 "
},
{
"input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB",
"output": "7\n11 1 1 8 1 1 6 "
},
{
"input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW",
"output": "9\n5 1 1 1 1 2 2 1 1 "
},
{
"input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB",
"output": "6\n1 1 1 1 1 5 "
},
{
"input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB",
"output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB",
"output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n100 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB",
"output": "11\n20 1 1 1 2 1 1 1 1 1 20 "
},
{
"input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB",
"output": "11\n4 1 1 1 1 2 1 1 1 1 6 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "10\nWWBWWWBWBB",
"output": "3\n1 1 2 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n17 31 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n24 42 "
},
{
"input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB",
"output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 "
},
{
"input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB",
"output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 "
},
{
"input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB",
"output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 "
},
{
"input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB",
"output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 "
},
{
"input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB",
"output": "11\n1 5 3 4 3 1 1 2 1 2 4 "
}
] | 1,633,962,872 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 93 | 20,172,800 | if __name__ == "__main__":
n = int(input())
string = input()
res, total = [], 0
count = 0
for s in string:
if s == "B":
count += 1
else:
if count != 0:
total += 1
res.append(str(count))
count = 0
if count != 0:
total += 1
res.append(str(count))
print(total)
if len(res) != 0:
print(' '.join(res))
| Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
Output Specification:
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
Demo Input:
['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n']
Demo Output:
['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 ']
Note:
The last sample case correspond to the picture in the statement. | ```python
if __name__ == "__main__":
n = int(input())
string = input()
res, total = [], 0
count = 0
for s in string:
if s == "B":
count += 1
else:
if count != 0:
total += 1
res.append(str(count))
count = 0
if count != 0:
total += 1
res.append(str(count))
print(total)
if len(res) != 0:
print(' '.join(res))
``` | 3 |
|
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\n1 2 2 2 4 5 6 7 8 10",
"output": "376"
},
{
"input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002",
"output": "40204082"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "10\n10 8 7 6 5 4 2 2 2 1",
"output": "376"
},
{
"input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821",
"output": "40204082"
},
{
"input": "10\n5 2 6 10 10 10 10 2 2 5",
"output": "485"
},
{
"input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255",
"output": "36742665"
},
{
"input": "10\n2 2 2 5 5 6 10 10 10 10",
"output": "485"
},
{
"input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 6 5 5 2 2 2",
"output": "485"
},
{
"input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 10 10 10 10 10 10",
"output": "640"
},
{
"input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "64000000"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "2\n1 2",
"output": "6"
},
{
"input": "2\n2 3",
"output": "10"
},
{
"input": "2\n1 1",
"output": "4"
}
] | 1,449,766,691 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 5,734,400 | n=int(input())
a=[int(i) for i in input().split()]
he=sum(a)
b=0
while b<n-1:
a.sort()
he=he+sum(a)
del a[0]
b=b+1
print(he) | Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Output Specification:
Print a single integer — the largest possible score.
Demo Input:
['3\n3 1 5\n', '1\n10\n']
Demo Output:
['26\n', '10\n']
Note:
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | ```python
n=int(input())
a=[int(i) for i in input().split()]
he=sum(a)
b=0
while b<n-1:
a.sort()
he=he+sum(a)
del a[0]
b=b+1
print(he)
``` | 0 |
|
931 | B | World Cup | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.
Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids *a* and *b* can meet. | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round. | 1,000 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
},
{
"input": "2 1 2",
"output": "Final!"
},
{
"input": "2 2 1",
"output": "Final!"
},
{
"input": "4 1 3",
"output": "Final!"
},
{
"input": "4 1 4",
"output": "Final!"
},
{
"input": "4 2 1",
"output": "1"
},
{
"input": "4 2 3",
"output": "Final!"
},
{
"input": "4 2 4",
"output": "Final!"
},
{
"input": "4 3 1",
"output": "Final!"
},
{
"input": "4 3 2",
"output": "Final!"
},
{
"input": "4 3 4",
"output": "1"
},
{
"input": "4 4 1",
"output": "Final!"
},
{
"input": "4 4 2",
"output": "Final!"
},
{
"input": "4 4 3",
"output": "1"
},
{
"input": "8 8 7",
"output": "1"
},
{
"input": "8 8 5",
"output": "2"
},
{
"input": "8 8 1",
"output": "Final!"
},
{
"input": "16 4 3",
"output": "1"
},
{
"input": "16 2 4",
"output": "2"
},
{
"input": "16 14 11",
"output": "3"
},
{
"input": "16 3 11",
"output": "Final!"
},
{
"input": "32 10 9",
"output": "1"
},
{
"input": "32 25 28",
"output": "2"
},
{
"input": "32 22 18",
"output": "3"
},
{
"input": "32 17 25",
"output": "4"
},
{
"input": "32 18 3",
"output": "Final!"
},
{
"input": "64 40 39",
"output": "1"
},
{
"input": "64 60 58",
"output": "2"
},
{
"input": "64 34 37",
"output": "3"
},
{
"input": "64 26 24",
"output": "4"
},
{
"input": "64 50 43",
"output": "5"
},
{
"input": "64 17 42",
"output": "Final!"
},
{
"input": "128 116 115",
"output": "1"
},
{
"input": "128 35 33",
"output": "2"
},
{
"input": "128 61 59",
"output": "3"
},
{
"input": "128 116 123",
"output": "4"
},
{
"input": "128 17 15",
"output": "5"
},
{
"input": "128 124 77",
"output": "6"
},
{
"input": "128 4 80",
"output": "Final!"
},
{
"input": "256 224 223",
"output": "1"
},
{
"input": "256 24 22",
"output": "2"
},
{
"input": "256 199 196",
"output": "3"
},
{
"input": "256 148 159",
"output": "4"
},
{
"input": "256 178 166",
"output": "5"
},
{
"input": "256 75 97",
"output": "6"
},
{
"input": "256 185 200",
"output": "7"
},
{
"input": "256 3 238",
"output": "Final!"
},
{
"input": "256 128 129",
"output": "Final!"
},
{
"input": "256 255 129",
"output": "7"
},
{
"input": "256 255 128",
"output": "Final!"
},
{
"input": "256 129 256",
"output": "7"
},
{
"input": "128 98 69",
"output": "6"
},
{
"input": "128 47 83",
"output": "Final!"
},
{
"input": "16 2 3",
"output": "2"
},
{
"input": "64 32 30",
"output": "2"
},
{
"input": "8 4 5",
"output": "Final!"
},
{
"input": "8 7 8",
"output": "1"
},
{
"input": "8 2 3",
"output": "2"
},
{
"input": "8 2 5",
"output": "Final!"
}
] | 1,520,179,288 | 1,588 | Python 3 | OK | TESTS | 64 | 77 | 5,632,000 | arr = input().split(' ')
n = int(arr[0])
a = int(arr[1])
b = int(arr[2])
a -= 1
b -= 1
ra = a//2
rb = b//2
c = 1
while ra!=rb:
ra = ra//2
rb = rb//2
c += 1
if(pow(2,c)==n): print("Final!")
else: print(c) | Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.
Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids *a* and *b* can meet.
Input Specification:
The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal.
Output Specification:
In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1.
Demo Input:
['4 1 2\n', '8 2 6\n', '8 7 5\n']
Demo Output:
['1\n', 'Final!\n', '2\n']
Note:
In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round. | ```python
arr = input().split(' ')
n = int(arr[0])
a = int(arr[1])
b = int(arr[2])
a -= 1
b -= 1
ra = a//2
rb = b//2
c = 1
while ra!=rb:
ra = ra//2
rb = rb//2
c += 1
if(pow(2,c)==n): print("Final!")
else: print(c)
``` | 3 |
|
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "14"
},
{
"input": "5 5\n3 2 1 0 0",
"output": "3"
},
{
"input": "8 6\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "8 7\n10 9 8 7 7 7 5 5",
"output": "8"
},
{
"input": "8 4\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "8 3\n10 9 8 7 7 7 5 5",
"output": "3"
},
{
"input": "8 1\n10 9 8 7 7 7 5 5",
"output": "1"
},
{
"input": "8 2\n10 9 8 7 7 7 5 5",
"output": "2"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "50 25\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "25"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "26"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "11 5\n100 99 98 97 96 95 94 93 92 91 90",
"output": "5"
},
{
"input": "10 4\n100 81 70 69 64 43 34 29 15 3",
"output": "4"
},
{
"input": "11 6\n87 71 62 52 46 46 43 35 32 25 12",
"output": "6"
},
{
"input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2",
"output": "12"
},
{
"input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2",
"output": "3"
},
{
"input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5",
"output": "12"
},
{
"input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1",
"output": "9"
},
{
"input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0",
"output": "29"
},
{
"input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4",
"output": "34"
},
{
"input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4",
"output": "44"
},
{
"input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3",
"output": "13"
},
{
"input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3",
"output": "30"
},
{
"input": "2 1\n10 10",
"output": "2"
},
{
"input": "2 2\n10 10",
"output": "2"
},
{
"input": "2 2\n10 0",
"output": "1"
},
{
"input": "2 2\n10 1",
"output": "2"
},
{
"input": "2 1\n10 0",
"output": "1"
},
{
"input": "2 1\n10 2",
"output": "1"
},
{
"input": "50 13\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "50 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "50 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "10 1\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 2\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 3\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 4\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 5\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 6\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 7\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 8\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 9\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 10\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
}
] | 1,698,826,858 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | # Read the input integer
n = int(input())
# Get the first digit by converting the absolute value of the number to a string
first_digit = int(str(abs(n))[0])
# If the original number is negative, make the first digit negative as well
if n < 0:
first_digit = -first_digit
# Print the first digit
print(first_digit)
| Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output Specification:
Output the number of participants who advance to the next round.
Demo Input:
['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n']
Demo Output:
['6\n', '0\n']
Note:
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | ```python
# Read the input integer
n = int(input())
# Get the first digit by converting the absolute value of the number to a string
first_digit = int(str(abs(n))[0])
# If the original number is negative, make the first digit negative as well
if n < 0:
first_digit = -first_digit
# Print the first digit
print(first_digit)
``` | -1 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,528,311,496 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 186 | 0 | n = int(input())
x = y = z = 0
for k in range(n):
m = list(map(int, input().split()))
x += m[0]
y += m[1]
z += m[2]
if x == y == z == 0:
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input())
x = y = z = 0
for k in range(n):
m = list(map(int, input().split()))
x += m[0]
y += m[1]
z += m[2]
if x == y == z == 0:
print('YES')
else:
print('NO')
``` | 3.9535 |
234 | A | Lefthanders and Righthanders | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave.
On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other.
Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists. | The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. | Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them. | [
"6\nLLRLLL\n",
"4\nRRLL\n"
] | [
"1 4\n2 5\n6 3\n",
"3 1\n4 2\n"
] | none | 0 | [
{
"input": "6\nLLRLLL",
"output": "1 4\n2 5\n6 3"
},
{
"input": "4\nRRLL",
"output": "3 1\n4 2"
},
{
"input": "4\nLLRR",
"output": "1 3\n2 4"
},
{
"input": "6\nRLLRRL",
"output": "1 4\n2 5\n3 6"
},
{
"input": "8\nLRLRLLLR",
"output": "1 5\n6 2\n3 7\n4 8"
},
{
"input": "10\nRLLRLRRRLL",
"output": "1 6\n2 7\n3 8\n9 4\n5 10"
},
{
"input": "12\nLRRRRRLRRRRL",
"output": "1 7\n2 8\n3 9\n4 10\n5 11\n12 6"
},
{
"input": "14\nRLLRLLLLRLLLRL",
"output": "8 1\n2 9\n3 10\n11 4\n5 12\n6 13\n7 14"
},
{
"input": "16\nLLLRRRLRRLLRRLLL",
"output": "1 9\n2 10\n3 11\n4 12\n5 13\n14 6\n7 15\n16 8"
},
{
"input": "18\nRRRLLLLRRRLRLRLLRL",
"output": "1 10\n11 2\n3 12\n4 13\n5 14\n6 15\n7 16\n8 17\n18 9"
},
{
"input": "20\nRLRLLRLRRLLRRRRRRLRL",
"output": "11 1\n2 12\n3 13\n4 14\n5 15\n6 16\n7 17\n18 8\n9 19\n10 20"
},
{
"input": "22\nRLLLRLLLRRLRRRLRLLLLLL",
"output": "1 12\n2 13\n3 14\n4 15\n5 16\n6 17\n7 18\n8 19\n20 9\n21 10\n11 22"
},
{
"input": "24\nLRRRLRLLRLRRRRLLLLRRLRLR",
"output": "1 13\n2 14\n15 3\n16 4\n5 17\n18 6\n7 19\n8 20\n21 9\n10 22\n23 11\n12 24"
},
{
"input": "26\nRLRRLLRRLLRLRRLLRLLRRLRLRR",
"output": "1 14\n2 15\n16 3\n4 17\n5 18\n6 19\n7 20\n8 21\n9 22\n10 23\n24 11\n12 25\n13 26"
},
{
"input": "28\nLLLRRRRRLRRLRRRLRLRLRRLRLRRL",
"output": "1 15\n2 16\n3 17\n18 4\n5 19\n20 6\n7 21\n8 22\n9 23\n10 24\n25 11\n12 26\n13 27\n28 14"
},
{
"input": "30\nLRLLRLRRLLRLRLLRRRRRLRLRLRLLLL",
"output": "1 16\n2 17\n3 18\n4 19\n5 20\n6 21\n7 22\n23 8\n9 24\n10 25\n11 26\n12 27\n28 13\n14 29\n15 30"
},
{
"input": "32\nRLRLLRRLLRRLRLLRLRLRLLRLRRRLLRRR",
"output": "17 1\n2 18\n19 3\n4 20\n5 21\n22 6\n7 23\n8 24\n9 25\n10 26\n11 27\n12 28\n29 13\n14 30\n15 31\n16 32"
},
{
"input": "34\nLRRLRLRLLRRRRLLRLRRLRRLRLRRLRRRLLR",
"output": "1 18\n2 19\n20 3\n4 21\n5 22\n6 23\n7 24\n8 25\n9 26\n10 27\n28 11\n12 29\n13 30\n14 31\n15 32\n33 16\n17 34"
},
{
"input": "36\nRRLLLRRRLLLRRLLLRRLLRLLRLRLLRLRLRLLL",
"output": "19 1\n20 2\n3 21\n4 22\n5 23\n6 24\n25 7\n8 26\n9 27\n10 28\n11 29\n30 12\n13 31\n14 32\n15 33\n16 34\n35 17\n36 18"
},
{
"input": "38\nLLRRRLLRRRLRRLRLRRLRRLRLRLLRRRRLLLLRLL",
"output": "1 20\n2 21\n22 3\n4 23\n24 5\n6 25\n7 26\n27 8\n9 28\n10 29\n11 30\n12 31\n32 13\n14 33\n34 15\n16 35\n17 36\n37 18\n19 38"
},
{
"input": "40\nLRRRRRLRLLRRRLLRRLRLLRLRRLRRLLLRRLRRRLLL",
"output": "1 21\n2 22\n23 3\n4 24\n5 25\n26 6\n7 27\n8 28\n9 29\n10 30\n31 11\n12 32\n13 33\n14 34\n15 35\n16 36\n17 37\n18 38\n39 19\n20 40"
},
{
"input": "42\nRLRRLLLLLLLRRRLRLLLRRRLRLLLRLRLRLLLRLRLRRR",
"output": "1 22\n2 23\n3 24\n25 4\n5 26\n6 27\n7 28\n8 29\n9 30\n10 31\n11 32\n33 12\n34 13\n35 14\n15 36\n37 16\n17 38\n18 39\n19 40\n20 41\n21 42"
},
{
"input": "44\nLLLLRRLLRRLLRRLRLLRRRLRLRLLRLRLRRLLRLRRLLLRR",
"output": "1 23\n2 24\n3 25\n4 26\n27 5\n6 28\n7 29\n8 30\n31 9\n10 32\n11 33\n12 34\n35 13\n14 36\n15 37\n16 38\n17 39\n18 40\n41 19\n42 20\n21 43\n22 44"
},
{
"input": "46\nRRRLLLLRRLRLRRRRRLRLLRLRRLRLLLLLLLLRRLRLRLRLLL",
"output": "1 24\n2 25\n26 3\n4 27\n5 28\n6 29\n7 30\n31 8\n32 9\n10 33\n34 11\n12 35\n13 36\n14 37\n38 15\n16 39\n40 17\n18 41\n42 19\n20 43\n21 44\n45 22\n23 46"
},
{
"input": "48\nLLLLRRLRRRRLRRRLRLLLLLRRLLRLLRLLRRLRRLLRLRLRRRRL",
"output": "1 25\n2 26\n3 27\n4 28\n29 5\n6 30\n7 31\n32 8\n9 33\n10 34\n35 11\n12 36\n13 37\n38 14\n39 15\n16 40\n41 17\n18 42\n19 43\n20 44\n21 45\n22 46\n23 47\n48 24"
},
{
"input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 26\n2 27\n3 28\n4 29\n5 30\n6 31\n7 32\n8 33\n9 34\n10 35\n11 36\n12 37\n13 38\n14 39\n15 40\n16 41\n17 42\n18 43\n19 44\n20 45\n21 46\n22 47\n23 48\n24 49\n25 50"
},
{
"input": "52\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 27\n2 28\n3 29\n4 30\n5 31\n6 32\n7 33\n8 34\n9 35\n10 36\n11 37\n12 38\n13 39\n14 40\n15 41\n16 42\n17 43\n18 44\n19 45\n20 46\n21 47\n22 48\n23 49\n24 50\n25 51\n26 52"
},
{
"input": "54\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 28\n2 29\n3 30\n4 31\n5 32\n6 33\n7 34\n8 35\n9 36\n10 37\n11 38\n12 39\n13 40\n14 41\n15 42\n16 43\n17 44\n18 45\n19 46\n20 47\n21 48\n22 49\n23 50\n24 51\n25 52\n26 53\n27 54"
},
{
"input": "56\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 29\n2 30\n3 31\n4 32\n5 33\n6 34\n7 35\n8 36\n9 37\n10 38\n11 39\n12 40\n13 41\n14 42\n15 43\n16 44\n17 45\n18 46\n19 47\n20 48\n21 49\n22 50\n23 51\n24 52\n25 53\n26 54\n27 55\n28 56"
},
{
"input": "58\nRRRLLLRLLLLRRLRRRLLRLLRLRLLRLRRRRLLLLLLRLRRLRLRRRLRLRRLRRL",
"output": "1 30\n2 31\n3 32\n4 33\n5 34\n6 35\n36 7\n8 37\n9 38\n10 39\n11 40\n41 12\n13 42\n14 43\n44 15\n16 45\n46 17\n18 47\n19 48\n20 49\n21 50\n22 51\n52 23\n24 53\n25 54\n26 55\n27 56\n28 57\n29 58"
},
{
"input": "60\nRLLLLRRLLRRRLLLLRRRRRLRRRLRRRLLLRLLLRLRRRLRLLLRLLRRLLRRRRRLL",
"output": "31 1\n2 32\n3 33\n4 34\n5 35\n36 6\n7 37\n8 38\n9 39\n10 40\n11 41\n42 12\n13 43\n14 44\n15 45\n16 46\n17 47\n48 18\n49 19\n20 50\n21 51\n22 52\n53 23\n24 54\n25 55\n26 56\n27 57\n28 58\n59 29\n30 60"
},
{
"input": "62\nLRRLRLRLLLLRRLLLLRRRLRLLLLRRRLLLLLLRRRLLLLRRLRRLRLLLLLLLLRRLRR",
"output": "1 32\n33 2\n34 3\n4 35\n5 36\n6 37\n7 38\n8 39\n9 40\n10 41\n11 42\n12 43\n13 44\n14 45\n15 46\n16 47\n17 48\n18 49\n50 19\n51 20\n21 52\n53 22\n23 54\n24 55\n25 56\n26 57\n27 58\n28 59\n60 29\n30 61\n31 62"
},
{
"input": "64\nRLLLLRRRLRLLRRRRLRLLLRRRLLLRRRLLRLLRLRLRRRLLRRRRLRLRRRLLLLRRLLLL",
"output": "1 33\n2 34\n3 35\n4 36\n5 37\n6 38\n39 7\n8 40\n9 41\n10 42\n11 43\n12 44\n13 45\n14 46\n15 47\n16 48\n17 49\n18 50\n19 51\n20 52\n21 53\n22 54\n55 23\n56 24\n25 57\n26 58\n27 59\n28 60\n61 29\n62 30\n31 63\n32 64"
},
{
"input": "66\nLLRRRLLRLRLLRRRRRRRLLLLRRLLLLLLRLLLRLLLLLLRRRLRRLLRRRRRLRLLRLLLLRR",
"output": "1 34\n2 35\n3 36\n37 4\n38 5\n6 39\n7 40\n41 8\n9 42\n10 43\n11 44\n12 45\n46 13\n14 47\n15 48\n49 16\n50 17\n18 51\n19 52\n20 53\n21 54\n22 55\n23 56\n24 57\n58 25\n26 59\n27 60\n28 61\n29 62\n30 63\n31 64\n32 65\n33 66"
},
{
"input": "68\nRRLRLRLLRLRLRRRRRRLRRRLLLLRLLRLRLRLRRRRLRLRLLRRRRLRRLLRLRRLLRLRRLRRL",
"output": "35 1\n2 36\n3 37\n4 38\n5 39\n40 6\n7 41\n8 42\n9 43\n10 44\n45 11\n12 46\n13 47\n14 48\n15 49\n50 16\n17 51\n18 52\n19 53\n54 20\n21 55\n56 22\n23 57\n24 58\n25 59\n26 60\n27 61\n28 62\n29 63\n30 64\n31 65\n32 66\n33 67\n68 34"
},
{
"input": "70\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 36\n2 37\n3 38\n4 39\n5 40\n6 41\n7 42\n8 43\n9 44\n10 45\n11 46\n12 47\n13 48\n14 49\n15 50\n16 51\n17 52\n18 53\n19 54\n20 55\n21 56\n22 57\n23 58\n24 59\n25 60\n26 61\n27 62\n28 63\n29 64\n30 65\n31 66\n32 67\n33 68\n34 69\n35 70"
},
{
"input": "72\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 37\n2 38\n3 39\n4 40\n5 41\n6 42\n7 43\n8 44\n9 45\n10 46\n11 47\n12 48\n13 49\n14 50\n15 51\n16 52\n17 53\n18 54\n19 55\n20 56\n21 57\n22 58\n23 59\n24 60\n25 61\n26 62\n27 63\n28 64\n29 65\n30 66\n31 67\n32 68\n33 69\n34 70\n35 71\n36 72"
},
{
"input": "74\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 38\n2 39\n3 40\n4 41\n5 42\n6 43\n7 44\n8 45\n9 46\n10 47\n11 48\n12 49\n13 50\n14 51\n15 52\n16 53\n17 54\n18 55\n19 56\n20 57\n21 58\n22 59\n23 60\n24 61\n25 62\n26 63\n27 64\n28 65\n29 66\n30 67\n31 68\n32 69\n33 70\n34 71\n35 72\n36 73\n37 74"
},
{
"input": "76\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 39\n2 40\n3 41\n4 42\n5 43\n6 44\n7 45\n8 46\n9 47\n10 48\n11 49\n12 50\n13 51\n14 52\n15 53\n16 54\n17 55\n18 56\n19 57\n20 58\n21 59\n22 60\n23 61\n24 62\n25 63\n26 64\n27 65\n28 66\n29 67\n30 68\n31 69\n32 70\n33 71\n34 72\n35 73\n36 74\n37 75\n38 76"
},
{
"input": "78\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 40\n2 41\n3 42\n4 43\n5 44\n6 45\n7 46\n8 47\n9 48\n10 49\n11 50\n12 51\n13 52\n14 53\n15 54\n16 55\n17 56\n18 57\n19 58\n20 59\n21 60\n22 61\n23 62\n24 63\n25 64\n26 65\n27 66\n28 67\n29 68\n30 69\n31 70\n32 71\n33 72\n34 73\n35 74\n36 75\n37 76\n38 77\n39 78"
},
{
"input": "80\nLRLRRRRLRRRRLLLLRLLRLRLLRRLRLLLRRLLLLRLLLRLRLLRRRLRRRLRLRRRRRLRLLRLLRRLLLRLRRRLL",
"output": "1 41\n2 42\n3 43\n4 44\n45 5\n46 6\n7 47\n8 48\n9 49\n50 10\n11 51\n12 52\n13 53\n14 54\n15 55\n16 56\n17 57\n18 58\n19 59\n20 60\n21 61\n62 22\n23 63\n24 64\n65 25\n26 66\n27 67\n68 28\n29 69\n30 70\n31 71\n72 32\n73 33\n34 74\n35 75\n36 76\n37 77\n38 78\n39 79\n40 80"
},
{
"input": "82\nRLRRLLRLRLRLLLRLLLRRLLRRLRRRRLLRLLLLRRRRRLLLRRRLLLLRLRRLRRRLRLLLLRRRLRLRLLLRLLLLLR",
"output": "42 1\n2 43\n44 3\n4 45\n5 46\n6 47\n48 7\n8 49\n50 9\n10 51\n11 52\n12 53\n13 54\n14 55\n56 15\n16 57\n17 58\n18 59\n60 19\n20 61\n21 62\n22 63\n64 23\n65 24\n25 66\n26 67\n27 68\n69 28\n29 70\n30 71\n31 72\n73 32\n33 74\n34 75\n35 76\n36 77\n78 37\n79 38\n80 39\n81 40\n41 82"
},
{
"input": "84\nLRLRRRRRRLLLRLRLLLLLRRLRLRLRRRLLRLLLRLRLLLRRRLRLRRLRLRLLLLLLLLRRRRRRLLLRRLRLRLLLRLRR",
"output": "1 43\n2 44\n3 45\n46 4\n5 47\n48 6\n7 49\n8 50\n51 9\n10 52\n11 53\n12 54\n55 13\n14 56\n57 15\n16 58\n17 59\n18 60\n19 61\n20 62\n21 63\n22 64\n23 65\n24 66\n25 67\n26 68\n27 69\n70 28\n71 29\n30 72\n31 73\n32 74\n33 75\n34 76\n35 77\n36 78\n79 37\n38 80\n39 81\n40 82\n41 83\n42 84"
},
{
"input": "86\nRRRLLLRLLRLLRLRLRLLLRLRLRRLLRLLLRLLLLLLRRRLRLLRLLLRRRLRLLLLRLLRLRRLLRLLLRRRLLRLRLLRLLR",
"output": "1 44\n45 2\n46 3\n4 47\n5 48\n6 49\n50 7\n8 51\n9 52\n10 53\n11 54\n12 55\n56 13\n14 57\n58 15\n16 59\n17 60\n18 61\n19 62\n20 63\n64 21\n22 65\n23 66\n24 67\n68 25\n26 69\n27 70\n28 71\n72 29\n30 73\n31 74\n32 75\n76 33\n34 77\n35 78\n36 79\n37 80\n38 81\n39 82\n40 83\n84 41\n85 42\n43 86"
},
{
"input": "88\nLLRLRLRLLLLRRRRRRLRRLLLLLRRLRRLLLLLRLRLRLLLLLRLRLRRLRLRRLRLLRRLRLLLRLLLLRRLLRRLRLRLRRLRR",
"output": "1 45\n2 46\n47 3\n4 48\n49 5\n6 50\n7 51\n8 52\n9 53\n10 54\n11 55\n12 56\n57 13\n14 58\n59 15\n60 16\n17 61\n18 62\n63 19\n20 64\n21 65\n22 66\n23 67\n24 68\n25 69\n70 26\n71 27\n28 72\n29 73\n30 74\n31 75\n32 76\n33 77\n34 78\n35 79\n36 80\n37 81\n38 82\n39 83\n40 84\n41 85\n42 86\n43 87\n44 88"
},
{
"input": "90\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 46\n2 47\n3 48\n4 49\n5 50\n6 51\n7 52\n8 53\n9 54\n10 55\n11 56\n12 57\n13 58\n14 59\n15 60\n16 61\n17 62\n18 63\n19 64\n20 65\n21 66\n22 67\n23 68\n24 69\n25 70\n26 71\n27 72\n28 73\n29 74\n30 75\n31 76\n32 77\n33 78\n34 79\n35 80\n36 81\n37 82\n38 83\n39 84\n40 85\n41 86\n42 87\n43 88\n44 89\n45 90"
},
{
"input": "92\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 47\n2 48\n3 49\n4 50\n5 51\n6 52\n7 53\n8 54\n9 55\n10 56\n11 57\n12 58\n13 59\n14 60\n15 61\n16 62\n17 63\n18 64\n19 65\n20 66\n21 67\n22 68\n23 69\n24 70\n25 71\n26 72\n27 73\n28 74\n29 75\n30 76\n31 77\n32 78\n33 79\n34 80\n35 81\n36 82\n37 83\n38 84\n39 85\n40 86\n41 87\n42 88\n43 89\n44 90\n45 91\n46 92"
},
{
"input": "94\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 48\n2 49\n3 50\n4 51\n5 52\n6 53\n7 54\n8 55\n9 56\n10 57\n11 58\n12 59\n13 60\n14 61\n15 62\n16 63\n17 64\n18 65\n19 66\n20 67\n21 68\n22 69\n23 70\n24 71\n25 72\n26 73\n27 74\n28 75\n29 76\n30 77\n31 78\n32 79\n33 80\n34 81\n35 82\n36 83\n37 84\n38 85\n39 86\n40 87\n41 88\n42 89\n43 90\n44 91\n45 92\n46 93\n47 94"
},
{
"input": "96\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 49\n2 50\n3 51\n4 52\n5 53\n6 54\n7 55\n8 56\n9 57\n10 58\n11 59\n12 60\n13 61\n14 62\n15 63\n16 64\n17 65\n18 66\n19 67\n20 68\n21 69\n22 70\n23 71\n24 72\n25 73\n26 74\n27 75\n28 76\n29 77\n30 78\n31 79\n32 80\n33 81\n34 82\n35 83\n36 84\n37 85\n38 86\n39 87\n40 88\n41 89\n42 90\n43 91\n44 92\n45 93\n46 94\n47 95\n48 96"
},
{
"input": "98\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 50\n2 51\n3 52\n4 53\n5 54\n6 55\n7 56\n8 57\n9 58\n10 59\n11 60\n12 61\n13 62\n14 63\n15 64\n16 65\n17 66\n18 67\n19 68\n20 69\n21 70\n22 71\n23 72\n24 73\n25 74\n26 75\n27 76\n28 77\n29 78\n30 79\n31 80\n32 81\n33 82\n34 83\n35 84\n36 85\n37 86\n38 87\n39 88\n40 89\n41 90\n42 91\n43 92\n44 93\n45 94\n46 95\n47 96\n48 97\n49 98"
},
{
"input": "100\nRLRRRRLLLLRRRRLRRRRRRRRLRLRRLLRRRRRRRRLRRRRLLLLRRRRLRRLRLRRRLLRRLRRLLLRLRRLLLLLLRLRLRLRRLRLRLRRRLLLR",
"output": "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n14 64\n15 65\n16 66\n17 67\n68 18\n69 19\n70 20\n21 71\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n78 28\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n86 36\n37 87\n38 88\n39 89\n40 90\n91 41\n42 92\n93 43\n44 94\n45 95\n46 96\n47 97\n98 48\n99 49\n50 100"
},
{
"input": "100\nLRLLLLRLLLLRRRRRLRRRRLRRLRRLRLLRRLRRRRLLRRRLLLRLLLRRRRLLRLRLRRLRLLRRLLRRLRRLRRRRRLRRLRLRLRLLLLLLLLRL",
"output": "1 51\n2 52\n3 53\n4 54\n5 55\n6 56\n7 57\n8 58\n9 59\n10 60\n11 61\n12 62\n63 13\n14 64\n65 15\n66 16\n17 67\n18 68\n69 19\n70 20\n21 71\n22 72\n73 23\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n91 41\n92 42\n93 43\n44 94\n45 95\n46 96\n97 47\n48 98\n49 99\n50 100"
},
{
"input": "100\nLLLRRLLRLRLLLRLLLRLRLLRRRLRRLLLRLRLRRLLRLRRRLLLRRLLRLLRRLLRRRRRLRLRRLRLRRLRLRRLLRLRLLRLLLRLLRLLLLRLL",
"output": "1 51\n2 52\n3 53\n54 4\n5 55\n6 56\n7 57\n58 8\n9 59\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n74 24\n25 75\n26 76\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n99 49\n50 100"
},
{
"input": "100\nRLLLLRRLLLLRRRRLLRLRRRLLLRLLRLLLLLRRLLLLLLRRLRRRRRLRLLRLRRRLLLRLRLRLLLRRRLLLLLRRRRRLRRLLLLRLLLRRLLLL",
"output": "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n11 61\n62 12\n13 63\n64 14\n15 65\n16 66\n17 67\n68 18\n19 69\n70 20\n21 71\n22 72\n23 73\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n93 43\n94 44\n45 95\n46 96\n97 47\n98 48\n99 49\n100 50"
},
{
"input": "100\nRLRRLRLRRLRLLRLLRRRLRRLLLLLRLRLRRRRRRRLLRRRLLRLRLLLRRRLLRRRLLRLRLLLLRRLRLLRLLRLLLLRRLRLRRLRLLLLRLRRR",
"output": "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n23 73\n24 74\n25 75\n26 76\n27 77\n28 78\n29 79\n80 30\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n93 43\n44 94\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nLRRLRLRRRRRRLRRLRRLLLLLLRRLLRRLLRLLLLLLRRRLLRLRRRLLRLLRRLRRRLLRLRLLRRLRRRLLLRRRRLLRRRLLLRRRRRLLLLLLR",
"output": "1 51\n2 52\n53 3\n4 54\n5 55\n6 56\n57 7\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n64 14\n15 65\n16 66\n67 17\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n24 74\n75 25\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n99 49\n50 100"
},
{
"input": "100\nRRLRRLRLRLRRRRLLRRLLRLRRLLRRRLLRLRRLRLRRLLLRRLLRRRRRRLLLRRRLLRRLLLLLLRLLLLLLRLLLRRRLRLLRRRRRLLRLLRRR",
"output": "1 51\n2 52\n3 53\n54 4\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n64 14\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n73 23\n74 24\n25 75\n26 76\n27 77\n78 28\n79 29\n30 80\n31 81\n32 82\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nRRLLLRLRRLRLLRRLRRRLLRRRLRRLLLLLLLLLRRRLLRLRRLRRLRRLRRLRLLLLRLLRRRLLLLRLRRRLLRRRRLRRLLRRRRLRRRLRLLLR",
"output": "1 51\n52 2\n3 53\n4 54\n5 55\n6 56\n7 57\n58 8\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n69 19\n20 70\n21 71\n72 22\n23 73\n24 74\n25 75\n76 26\n77 27\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n49 99\n50 100"
},
{
"input": "100\nLLLLLRRLRRRRRRRLLRRRRRLRRLRLRLLRLRRLLLRRRRLLRRLRLLRLLLRLRLLRRRRRRRRRLRLLLRLRLLLLLRLRRRRLRLLRLRLRLRRL",
"output": "1 51\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n17 67\n18 68\n69 19\n20 70\n71 21\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n28 78\n79 29\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n90 40\n91 41\n42 92\n43 93\n44 94\n95 45\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nLLRRRLLLRLLLLRLRLRLRRRLLLRRRLRLLRLLLRRRRRLRRLRRLRRRLRRLRRLLLRLRLLRRRRLRLRRRRRLRRLRLLRRRRLLLRRRRRLLLL",
"output": "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n70 20\n21 71\n72 22\n23 73\n24 74\n25 75\n26 76\n27 77\n78 28\n29 79\n30 80\n31 81\n32 82\n83 33\n34 84\n35 85\n36 86\n37 87\n38 88\n89 39\n90 40\n91 41\n42 92\n43 93\n44 94\n45 95\n46 96\n97 47\n48 98\n99 49\n100 50"
}
] | 1,681,049,916 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,764,800 | from sys import stdin
def input(): return stdin.readline()[:-1]
n=int(input())
s=list(input())
l=[]
r=[]
for i in range(len(s)):
if s[i]=="L":
l.append(i+1)
else:
r.append(i+1)
ans=[]
ll=len(l)
lr=len(r)
for i in range(0,min(ll,lr)):
ans.append([l[i],r[i]])
curr=i+1
if ll>=lr:
for j in range(curr,max(ll,lr),2):
ans.append([l[j],l[j+1]])
else:
for j in range(curr,max(ll,lr),2):
ans.append([r[j],r[j+1]])
for i in range(n//2):
print(ans[i][0],ans[i][1]) | Title: Lefthanders and Righthanders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave.
On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other.
Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists.
Input Specification:
The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander.
Output Specification:
Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them.
Demo Input:
['6\nLLRLLL\n', '4\nRRLL\n']
Demo Output:
['1 4\n2 5\n6 3\n', '3 1\n4 2\n']
Note:
none | ```python
from sys import stdin
def input(): return stdin.readline()[:-1]
n=int(input())
s=list(input())
l=[]
r=[]
for i in range(len(s)):
if s[i]=="L":
l.append(i+1)
else:
r.append(i+1)
ans=[]
ll=len(l)
lr=len(r)
for i in range(0,min(ll,lr)):
ans.append([l[i],r[i]])
curr=i+1
if ll>=lr:
for j in range(curr,max(ll,lr),2):
ans.append([l[j],l[j+1]])
else:
for j in range(curr,max(ll,lr),2):
ans.append([r[j],r[j+1]])
for i in range(n//2):
print(ans[i][0],ans[i][1])
``` | -1 |
|
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs *a* rubles, or in glass liter bottle, that costs *b* rubles. Also, you may return empty glass bottle and get *c* (*c*<=<<=*b*) rubles back, but you cannot return plastic bottles.
Kolya has *n* rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively. | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir. | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"output": "5"
},
{
"input": "9\n2\n4\n1",
"output": "4"
},
{
"input": "9\n2\n2\n1",
"output": "8"
},
{
"input": "9\n10\n10\n1",
"output": "0"
},
{
"input": "10\n2\n2\n1",
"output": "9"
},
{
"input": "1000000000000000000\n2\n10\n9",
"output": "999999999999999995"
},
{
"input": "501000000000000000\n300000000000000000\n301000000000000000\n100000000000000000",
"output": "2"
},
{
"input": "10\n1\n9\n8",
"output": "10"
},
{
"input": "10\n8\n8\n7",
"output": "3"
},
{
"input": "10\n5\n5\n1",
"output": "2"
},
{
"input": "29\n3\n3\n1",
"output": "14"
},
{
"input": "45\n9\n9\n8",
"output": "37"
},
{
"input": "45\n9\n9\n1",
"output": "5"
},
{
"input": "100\n10\n10\n9",
"output": "91"
},
{
"input": "179\n10\n9\n1",
"output": "22"
},
{
"input": "179\n2\n2\n1",
"output": "178"
},
{
"input": "179\n179\n179\n1",
"output": "1"
},
{
"input": "179\n59\n59\n58",
"output": "121"
},
{
"input": "500\n250\n250\n1",
"output": "2"
},
{
"input": "500\n1\n250\n1",
"output": "500"
},
{
"input": "501\n500\n500\n499",
"output": "2"
},
{
"input": "501\n450\n52\n1",
"output": "9"
},
{
"input": "501\n300\n301\n100",
"output": "2"
},
{
"input": "500\n179\n10\n1",
"output": "55"
},
{
"input": "1000\n500\n10\n9",
"output": "991"
},
{
"input": "1000\n2\n10\n9",
"output": "995"
},
{
"input": "1001\n1000\n1000\n999",
"output": "2"
},
{
"input": "10000\n10000\n10000\n1",
"output": "1"
},
{
"input": "10000\n10\n5000\n4999",
"output": "5500"
},
{
"input": "1000000000\n999999998\n999999999\n999999998",
"output": "3"
},
{
"input": "1000000000\n50\n50\n49",
"output": "999999951"
},
{
"input": "1000000000\n500\n5000\n4999",
"output": "999995010"
},
{
"input": "1000000000\n51\n100\n98",
"output": "499999952"
},
{
"input": "1000000000\n100\n51\n50",
"output": "999999950"
},
{
"input": "1000000000\n2\n5\n4",
"output": "999999998"
},
{
"input": "1000000000000000000\n999999998000000000\n999999999000000000\n999999998000000000",
"output": "3"
},
{
"input": "1000000000\n2\n2\n1",
"output": "999999999"
},
{
"input": "999999999\n2\n999999998\n1",
"output": "499999999"
},
{
"input": "999999999999999999\n2\n2\n1",
"output": "999999999999999998"
},
{
"input": "999999999999999999\n10\n10\n9",
"output": "999999999999999990"
},
{
"input": "999999999999999999\n999999999999999998\n999999999999999998\n999999999999999997",
"output": "2"
},
{
"input": "999999999999999999\n501\n501\n1",
"output": "1999999999999999"
},
{
"input": "999999999999999999\n2\n50000000000000000\n49999999999999999",
"output": "974999999999999999"
},
{
"input": "999999999999999999\n180\n180\n1",
"output": "5586592178770949"
},
{
"input": "1000000000000000000\n42\n41\n1",
"output": "24999999999999999"
},
{
"input": "1000000000000000000\n41\n40\n1",
"output": "25641025641025641"
},
{
"input": "100000000000000000\n79\n100\n25",
"output": "1333333333333333"
},
{
"input": "1\n100\n5\n4",
"output": "0"
},
{
"input": "1000000000000000000\n1000000000000000000\n10000000\n9999999",
"output": "999999999990000001"
},
{
"input": "999999999999999999\n999999999000000000\n900000000000000000\n899999999999999999",
"output": "100000000000000000"
},
{
"input": "13\n10\n15\n11",
"output": "1"
},
{
"input": "1\n1000\n5\n4",
"output": "0"
},
{
"input": "10\n100\n10\n1",
"output": "1"
},
{
"input": "3\n2\n100000\n99999",
"output": "1"
},
{
"input": "4\n2\n4\n2",
"output": "2"
},
{
"input": "5\n3\n6\n4",
"output": "1"
},
{
"input": "1\n7\n65\n49",
"output": "0"
},
{
"input": "10\n20\n100\n99",
"output": "0"
},
{
"input": "10000000000\n10000000000\n9000000000\n8999999999",
"output": "1000000001"
},
{
"input": "90\n30\n101\n100",
"output": "3"
},
{
"input": "999999999999999\n5\n500000000000000\n499999999999999",
"output": "599999999999999"
},
{
"input": "1000000000000000000\n1000000000000000000\n1000000000\n999999999",
"output": "999999999000000001"
},
{
"input": "1\n1000000000000000000\n1000000000\n999999999",
"output": "0"
},
{
"input": "100000000000000000\n100000000000000000\n1000000000\n999999999",
"output": "99999999000000001"
},
{
"input": "100000000000000009\n100\n1000000000000000\n999999999999999",
"output": "99010000000000009"
},
{
"input": "10\n20\n10\n9",
"output": "1"
},
{
"input": "10\n4\n14\n13",
"output": "2"
},
{
"input": "11\n3\n9\n7",
"output": "4"
},
{
"input": "1000000000\n5\n7\n4",
"output": "333333332"
},
{
"input": "12155\n1943\n28717\n24074",
"output": "6"
},
{
"input": "1000000000000000000\n10\n20\n5",
"output": "100000000000000000"
},
{
"input": "98\n33\n440\n314",
"output": "2"
},
{
"input": "1070252292\n57449678\n237309920\n221182550",
"output": "56"
},
{
"input": "100\n3\n102\n101",
"output": "33"
},
{
"input": "100000000000000000\n100000000000000001\n1000000000000000\n999999999999999",
"output": "99000000000000001"
},
{
"input": "66249876257975628\n302307316\n406102416\n182373516",
"output": "296116756"
},
{
"input": "10\n5\n10\n1",
"output": "2"
},
{
"input": "1000000000000000000\n10\n1000000000\n999999998",
"output": "499999999600000000"
}
] | 1,455,116,087 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | n, a, b, c = [int(input()) for i in range(4)]
res = (n - c) // (b - c)
n -= res * (b - c)
res += n // a
print(res) | Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs *a* rubles, or in glass liter bottle, that costs *b* rubles. Also, you may return empty glass bottle and get *c* (*c*<=<<=*b*) rubles back, but you cannot return plastic bottles.
Kolya has *n* rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.
Output Specification:
Print the only integer — maximum number of liters of kefir, that Kolya can drink.
Demo Input:
['10\n11\n9\n8\n', '10\n5\n6\n1\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir. | ```python
n, a, b, c = [int(input()) for i in range(4)]
res = (n - c) // (b - c)
n -= res * (b - c)
res += n // a
print(res)
``` | 0 |
|
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner. | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct. | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 2147483648\n2 1",
"output": "2"
},
{
"input": "3 2\n1 3 2",
"output": "3 "
},
{
"input": "3 3\n1 2 3",
"output": "3 "
},
{
"input": "5 2\n2 1 3 4 5",
"output": "5 "
},
{
"input": "10 2\n7 10 5 8 9 3 4 6 1 2",
"output": "10 "
},
{
"input": "100 2\n62 70 29 14 12 87 94 78 39 92 84 91 61 49 60 33 69 37 19 82 42 8 45 97 81 43 54 67 1 22 77 58 65 17 18 28 25 57 16 90 40 13 4 21 68 35 15 76 73 93 56 95 79 47 74 75 30 71 66 99 41 24 88 83 5 6 31 96 38 80 27 46 51 53 2 86 32 9 20 100 26 36 63 7 52 55 23 3 50 59 48 89 85 44 34 64 10 72 11 98",
"output": "70 "
},
{
"input": "4 10\n2 1 3 4",
"output": "4"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "10 "
},
{
"input": "10 2\n10 9 8 7 6 5 4 3 2 1",
"output": "10 "
},
{
"input": "4 1000000000000\n3 4 1 2",
"output": "4"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "91 "
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "100 "
},
{
"input": "2 1000000000000\n1 2",
"output": "2"
},
{
"input": "5 2\n1 4 3 5 2",
"output": "4 "
},
{
"input": "5 2\n1 3 2 4 5",
"output": "3 "
},
{
"input": "4 1000000000000\n3 1 2 4",
"output": "4"
},
{
"input": "4 2\n1 3 2 4",
"output": "3 "
},
{
"input": "10 3\n8 1 9 2 3 10 4 5 6 7",
"output": "9 "
},
{
"input": "5 2\n2 1 4 3 5",
"output": "4 "
},
{
"input": "3 4294967297\n2 1 3",
"output": "3"
},
{
"input": "4 4294967297\n3 2 1 4",
"output": "4"
},
{
"input": "5 4294967298\n3 2 1 4 5",
"output": "5"
},
{
"input": "10 4\n5 4 7 1 2 9 3 6 8 10",
"output": "9 "
},
{
"input": "11 21474836489\n10 1 2 3 4 5 6 7 8 9 11",
"output": "11"
}
] | 1,572,853,413 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 32 | 155 | 0 | nk = input().split()
n = int(nk[0])
k = int(nk[1])
players = [int(i) for i in input().split()]
if k>n:
print(max(players))
else:
playing = players[0:2]
queue = players[2:]
win = False
wins = 0
while wins<k:
if playing[0]>playing[1]:
wins+=1
queue.append(playing[1])
playing[1] = queue.pop(0)
else:
wins=0
playing[0], playing[1] = playing[1], playing[0]
queue.append(playing[1])
playing[1] = queue.pop(0)
print(playing[0]) | Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.
Input Specification:
The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct.
Output Specification:
Output a single integer — power of the winner.
Demo Input:
['2 2\n1 2\n', '4 2\n3 1 2 4\n', '6 2\n6 5 3 1 2 4\n', '2 10000000000\n2 1\n']
Demo Output:
['2 ', '3 ', '6 ', '2\n']
Note:
Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | ```python
nk = input().split()
n = int(nk[0])
k = int(nk[1])
players = [int(i) for i in input().split()]
if k>n:
print(max(players))
else:
playing = players[0:2]
queue = players[2:]
win = False
wins = 0
while wins<k:
if playing[0]>playing[1]:
wins+=1
queue.append(playing[1])
playing[1] = queue.pop(0)
else:
wins=0
playing[0], playing[1] = playing[1], playing[0]
queue.append(playing[1])
playing[1] = queue.pop(0)
print(playing[0])
``` | 0 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,586,506,647 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | x = input()
x1 = input()
s=""
for i in range(len(x)):
if x[i]==x1[i]:
s+='0'
else:
s+='1'
print(int(s)) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
x = input()
x1 = input()
s=""
for i in range(len(x)):
if x[i]==x1[i]:
s+='0'
else:
s+='1'
print(int(s))
``` | 0 |
748 | A | Santa Claus and a Place in a Class | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).
The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right.
Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right! | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right. | 500 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"output": "8043 2940 R"
},
{
"input": "1 1 1",
"output": "1 1 L"
},
{
"input": "1 1 2",
"output": "1 1 R"
},
{
"input": "1 10000 1",
"output": "1 1 L"
},
{
"input": "1 10000 20000",
"output": "1 10000 R"
},
{
"input": "10000 1 1",
"output": "1 1 L"
},
{
"input": "10000 1 10000",
"output": "5000 1 R"
},
{
"input": "10000 1 20000",
"output": "10000 1 R"
},
{
"input": "3 2 1",
"output": "1 1 L"
},
{
"input": "3 2 2",
"output": "1 1 R"
},
{
"input": "3 2 3",
"output": "1 2 L"
},
{
"input": "3 2 4",
"output": "1 2 R"
},
{
"input": "3 2 5",
"output": "2 1 L"
},
{
"input": "3 2 6",
"output": "2 1 R"
},
{
"input": "3 2 7",
"output": "2 2 L"
},
{
"input": "3 2 8",
"output": "2 2 R"
},
{
"input": "3 2 9",
"output": "3 1 L"
},
{
"input": "3 2 10",
"output": "3 1 R"
},
{
"input": "3 2 11",
"output": "3 2 L"
},
{
"input": "3 2 12",
"output": "3 2 R"
},
{
"input": "300 2000 1068628",
"output": "268 314 R"
},
{
"input": "300 2000 584756",
"output": "147 378 R"
},
{
"input": "300 2000 268181",
"output": "68 91 L"
},
{
"input": "10000 9999 186450844",
"output": "9324 4745 R"
},
{
"input": "10000 9999 197114268",
"output": "9857 6990 R"
},
{
"input": "10000 9999 112390396",
"output": "5621 818 R"
},
{
"input": "10000 10000 1",
"output": "1 1 L"
},
{
"input": "10000 10000 2",
"output": "1 1 R"
},
{
"input": "10000 10000 100000001",
"output": "5001 1 L"
},
{
"input": "10000 10000 199999999",
"output": "10000 10000 L"
},
{
"input": "10000 10000 200000000",
"output": "10000 10000 R"
},
{
"input": "1 2 1",
"output": "1 1 L"
},
{
"input": "1 2 2",
"output": "1 1 R"
},
{
"input": "1 2 3",
"output": "1 2 L"
},
{
"input": "1 2 4",
"output": "1 2 R"
},
{
"input": "2 1 1",
"output": "1 1 L"
},
{
"input": "2 1 2",
"output": "1 1 R"
},
{
"input": "2 1 3",
"output": "2 1 L"
},
{
"input": "2 1 4",
"output": "2 1 R"
},
{
"input": "4 3 7",
"output": "2 1 L"
},
{
"input": "1 1 1",
"output": "1 1 L"
}
] | 1,482,657,367 | 667 | Python 3 | OK | TESTS | 46 | 77 | 4,608,000 | n,m,k=[int(i) for i in input().split()]
ryad=k//(2*m)+1
if k%(2*m)==0:
ryad-=1
parta=(k-2*m*(ryad-1))//2+k%2
if k%2==0:
mesto='R'
else:
mesto='L'
print(ryad,parta,mesto) | Title: Santa Claus and a Place in a Class
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).
The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right.
Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
Input Specification:
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Output Specification:
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
Demo Input:
['4 3 9\n', '4 3 24\n', '2 4 4\n']
Demo Output:
['2 2 L\n', '4 3 R\n', '1 2 R\n']
Note:
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right. | ```python
n,m,k=[int(i) for i in input().split()]
ryad=k//(2*m)+1
if k%(2*m)==0:
ryad-=1
parta=(k-2*m*(ryad-1))//2+k%2
if k%2==0:
mesto='R'
else:
mesto='L'
print(ryad,parta,mesto)
``` | 3 |
Subsets and Splits