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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
883 | E | Field of Wonders | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows *m* words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these *m* words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length *n*, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=1000) — the number of words of length *n*, which Polycarpus knows. The following *m* lines contain the words themselves — *n*-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given *m* words. Before the current move Polycarp has told exactly the letters which are currently revealed. | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | [
"4\na**d\n2\nabcd\nacbd\n",
"5\nlo*er\n2\nlover\nloser\n",
"3\na*a\n2\naaa\naba\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. | 0 | [
{
"input": "4\na**d\n2\nabcd\nacbd",
"output": "2"
},
{
"input": "5\nlo*er\n2\nlover\nloser",
"output": "0"
},
{
"input": "3\na*a\n2\naaa\naba",
"output": "1"
},
{
"input": "1\n*\n1\na",
"output": "1"
},
{
"input": "1\n*\n1\nz",
"output": "1"
},
{
"input": "1\n*\n2\na\nz",
"output": "0"
},
{
"input": "2\n**\n1\naa",
"output": "1"
},
{
"input": "2\n**\n1\nfx",
"output": "2"
},
{
"input": "2\n**\n2\nfx\nab",
"output": "0"
},
{
"input": "2\n**\n2\nfx\naf",
"output": "1"
},
{
"input": "2\na*\n2\naa\nab",
"output": "1"
},
{
"input": "4\na*b*\n2\nabbc\nadbd",
"output": "1"
},
{
"input": "4\na*b*\n3\nabbc\nadbd\nacbe",
"output": "0"
},
{
"input": "4\na*b*\n3\nabbc\nadbd\nacbd",
"output": "1"
},
{
"input": "3\n***\n2\naaa\nbbb",
"output": "0"
},
{
"input": "3\n***\n2\naab\nabb",
"output": "2"
},
{
"input": "3\n*a*\n4\naaa\ncac\naab\nbaa",
"output": "1"
},
{
"input": "42\n*****o*******t********************oo******\n10\nvcrccobltkeidtxhsxhccaslkjhfyeqsetoowaemso\nuimjsoxifamvctkgqmrwhyjrgmlydczzqjoobnnwch\nuvmjsoqizfavctkxemrpaycngmlyemzzqjoobszwbh\nusmjsoviskzvctkljmrlmylugmlydfzzqvoobzawgh\nfeqweodinkhiatqmfokaxwcmlmbmvskssyookgcrax\ntackfosjhxeqftkgjynbbedrczegtimuvooosypczy\nxanuvoeismzmctruyplxgmfcpyrpqopyctoozlquvg\nurmjsouirdrvctkepmrwjyaxgmlyzvzzqcoobjgwih\nuymjsogivzivctkydmrgwyavgmlyphzzquoobclwhh\nkodyeoyihylgrtrdwudrsyonmuhtxaqklcoolsaclu",
"output": "18"
},
{
"input": "50\n***********************************o**************\n5\nwrubnrgpqmduhgxtlxymsmcaiimivvypkkeouspglhzkfbpzcu\nfrubkrgplrduhgjuuxdmsgeaiimavvypkkeousulbhnkebpzcu\nwrubkrgpdrduhgfanxdmsufaiimgvvypkkeouwvsshikhbpzcu\nvhyfvnnobcguishyvuswkaxhkesgatuvbkyodxdrvlwwifiimd\nwrubwrgpvaduhgfnqxtmsjqaiimcvvypkkeouiqpyhckkbpzcu",
"output": "20"
},
{
"input": "10\n**********\n10\nmvsthotcmi\nhmivtctsmo\nmmcostthiv\ntmomihtsvc\nmottsivmch\nhtomvcsmit\nsvhmotmcti\nmitotmvhcs\nvomcttmish\ncmostitvmh",
"output": "8"
},
{
"input": "20\n********************\n1\nlaizpfbafxrugjcytfbs",
"output": "16"
},
{
"input": "50\n**************************************************\n1\nqgaeytghzvvtgeitpovqozyclectzcohivbggudhiylaecbdzq",
"output": "17"
},
{
"input": "50\n**************************************************\n2\nhvjbrfkhdaobruoptrrachzuvkxvvsckycfiroipqicoqvcqpr\nuirvabciccxdvpryroisvpoqvthrpurkzhoovcfqcjbhkarkqf",
"output": "20"
},
{
"input": "26\n**************************\n10\nevfsnczuiodgbhqmlypkjatxrw\nuapqfdtoxkzynlbrehgwismvjc\nwjuyacngtzmvhqelikxoprdfbs\nyjgstlkvrhoqadxwfbiucpznem\nvebnxtrlocgkajqmwfuiszhypd\nroaqchwlpvtzxymnbkjigfedsu\noxmwaqpcendihzkutsybrjgfvl\nbnfzlwcsagxojdiyktqvruemhp\npdjahwnvmouxgqlciktzrfeysb\nbznurcyefxiapgktmqwjvsdloh",
"output": "26"
},
{
"input": "26\n**************************\n1\nayvguplhjsoiencbkxdrfwmqtz",
"output": "26"
},
{
"input": "26\n*lmnotuvwxyzjkabcdehiqfgrs\n2\nblmnotuvwxyzjkabcdehiqfgrs\nplmnotuvwxyzjkabcdehiqfgrs",
"output": "1"
},
{
"input": "16\nx*d**s******xd*u\n22\nxfdeoshogyqjxdmu\nxvdvdsnwfwakxdyu\nxfdjoshftykjxdmu\nxfdcoshfwyajxdmu\nxfdfoshkmyajxdmu\nxfdyoshpoycjxdmu\nxmdhcswqnhxjxdtu\nxxdxwsoogqzwxdcu\nxxdhhsxqzciuxdfu\nxddcmswqzksqxdhu\nxfdtoshioyvjxdmu\nxsdxmsfmgjbyxdgu\nxadfssplfnlbxdru\nxndcasykmqmbxdru\nxrdxgszaisicxdlu\nxfdfoshhmypjxdmu\nxfdioshfiyhjxdmu\nxvdzysydlmyuxdnu\nxjdbqszgkuwhxdmu\nxfdfoshjyymjxdmu\nxgdjksubrmrfxdpu\nxkdshsfszixmxdcu",
"output": "2"
},
{
"input": "3\n*vt\n2\ncvt\nqvb",
"output": "1"
},
{
"input": "3\ntv*\n2\ntvc\nbvq",
"output": "1"
},
{
"input": "41\n*z*hjcxxdgkny*tc*rmaov***fra**efs*lbi*puw\n1\nqzqhjcxxdgknyqtcqrmaovqqqfraqqefsqlbiqpuw",
"output": "1"
},
{
"input": "48\n*h*i**ag**um**fuxvmxlj*dsyt*gb*dxkzp*brnelctkq*w\n1\nohoiooagooumoofuxvmxljodsytogbodxkzpobrnelctkqow",
"output": "1"
}
] | 1,508,576,486 | 3,386 | Python 3 | WRONG_ANSWER | TESTS1 | 11 | 61 | 5,529,600 | m=int(input())
s=str(input())
n=int(input())
l=[]
for i in range(n):
s1=str(input())
l1=[]
for i in range(26):
if chr(97+i) in s1 and chr(97+i) not in s:
l1.append(chr(97+i))
if l1!=[]:
l.append(l1)
ll=[]
for i in range(26):
f=True
for j in range(len(l)):
if chr(97+i) not in l[j]:
f=False
if f:
ll.append(chr(97+i))
print(len(ll)) | Title: Field of Wonders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows *m* words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these *m* words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length *n*, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=1000) — the number of words of length *n*, which Polycarpus knows. The following *m* lines contain the words themselves — *n*-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given *m* words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output Specification:
Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Demo Input:
['4\na**d\n2\nabcd\nacbd\n', '5\nlo*er\n2\nlover\nloser\n', '3\na*a\n2\naaa\naba\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns. | ```python
m=int(input())
s=str(input())
n=int(input())
l=[]
for i in range(n):
s1=str(input())
l1=[]
for i in range(26):
if chr(97+i) in s1 and chr(97+i) not in s:
l1.append(chr(97+i))
if l1!=[]:
l.append(l1)
ll=[]
for i in range(26):
f=True
for j in range(len(l)):
if chr(97+i) not in l[j]:
f=False
if f:
ll.append(chr(97+i))
print(len(ll))
``` | 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,662,389,315 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | s = input()
upper_counter = 0
lower_counter = 0
for i in range(len(s)):
if s[i].isupper():
upper_counter +=1
elif s[i].islower():
lower_counter +=1
if upper_counter > lower_counter:
print(s.upper())
else:
print(s.lower()) | 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()
upper_counter = 0
lower_counter = 0
for i in range(len(s)):
if s[i].isupper():
upper_counter +=1
elif s[i].islower():
lower_counter +=1
if upper_counter > lower_counter:
print(s.upper())
else:
print(s.lower())
``` | 3.977 |
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "1 1 1 1 1 1",
"output": "Elephant"
},
{
"input": "9 9 9 9 9 9",
"output": "Elephant"
},
{
"input": "1 8 9 1 1 1",
"output": "Bear"
},
{
"input": "9 9 9 1 9 9",
"output": "Bear"
},
{
"input": "1 2 3 8 9 7",
"output": "Alien"
},
{
"input": "5 5 5 6 6 6",
"output": "Alien"
},
{
"input": "1 1 2 2 3 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 2",
"output": "Bear"
},
{
"input": "2 2 3 3 4 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 5",
"output": "Bear"
},
{
"input": "1 1 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 2 5 5 5 5",
"output": "Bear"
},
{
"input": "4 4 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 1 2",
"output": "Bear"
},
{
"input": "2 2 4 4 4 4",
"output": "Elephant"
},
{
"input": "4 4 4 4 4 3",
"output": "Bear"
},
{
"input": "4 4 5 6 7 8",
"output": "Alien"
},
{
"input": "4 4 4 4 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 2 2",
"output": "Elephant"
},
{
"input": "1 1 3 3 3 5",
"output": "Alien"
},
{
"input": "1 2 2 3 3 3",
"output": "Alien"
},
{
"input": "1 2 2 2 2 2",
"output": "Bear"
},
{
"input": "1 3 3 3 4 5",
"output": "Alien"
},
{
"input": "5 1 1 1 1 1",
"output": "Bear"
}
] | 1,593,140,493 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 6,656,000 | l = sorted(list(map(int, input().split())))
if l.count(4) != 4 :
print('Alien')
elif len(set(l)) == 3 :
print('Bear')
else :
print('Elephant') | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
Input Specification:
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
Output Specification:
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
Demo Input:
['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n']
Demo Output:
['Bear', 'Elephant', 'Alien']
Note:
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | ```python
l = sorted(list(map(int, input().split())))
if l.count(4) != 4 :
print('Alien')
elif len(set(l)) == 3 :
print('Bear')
else :
print('Elephant')
``` | 0 |
|
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"output": "6"
},
{
"input": "11 562314608",
"output": "39916800"
},
{
"input": "3 990639260",
"output": "6"
},
{
"input": "11 859155400",
"output": "39916800"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "5 3",
"output": "6"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "5 4",
"output": "24"
},
{
"input": "1 12",
"output": "1"
},
{
"input": "9 7",
"output": "5040"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "6 11",
"output": "720"
},
{
"input": "6 7",
"output": "720"
},
{
"input": "11 11",
"output": "39916800"
},
{
"input": "4 999832660",
"output": "24"
},
{
"input": "7 999228288",
"output": "5040"
},
{
"input": "11 999257105",
"output": "39916800"
},
{
"input": "11 999286606",
"output": "39916800"
},
{
"input": "3 999279109",
"output": "6"
},
{
"input": "999632727 11",
"output": "39916800"
},
{
"input": "999625230 7",
"output": "5040"
},
{
"input": "999617047 3",
"output": "6"
},
{
"input": "999646548 7",
"output": "5040"
},
{
"input": "999639051 3",
"output": "6"
},
{
"input": "12 12",
"output": "479001600"
},
{
"input": "12 1",
"output": "1"
},
{
"input": "1213 5",
"output": "120"
},
{
"input": "8 9",
"output": "40320"
},
{
"input": "12 9",
"output": "362880"
},
{
"input": "12 1000000000",
"output": "479001600"
},
{
"input": "1000000000 1",
"output": "1"
},
{
"input": "12 13",
"output": "479001600"
},
{
"input": "2 29845",
"output": "2"
},
{
"input": "10 21",
"output": "3628800"
},
{
"input": "12 20",
"output": "479001600"
},
{
"input": "15 12",
"output": "479001600"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000 12",
"output": "479001600"
},
{
"input": "11 30",
"output": "39916800"
},
{
"input": "17 12",
"output": "479001600"
},
{
"input": "4 19",
"output": "24"
},
{
"input": "12 15",
"output": "479001600"
},
{
"input": "20 6",
"output": "720"
},
{
"input": "10 20",
"output": "3628800"
},
{
"input": "10 10",
"output": "3628800"
},
{
"input": "22 12",
"output": "479001600"
},
{
"input": "20 12",
"output": "479001600"
},
{
"input": "12 23",
"output": "479001600"
},
{
"input": "12 22",
"output": "479001600"
},
{
"input": "18 3",
"output": "6"
},
{
"input": "14 10",
"output": "3628800"
},
{
"input": "14 12",
"output": "479001600"
},
{
"input": "8 3",
"output": "6"
},
{
"input": "5 5",
"output": "120"
}
] | 1,664,082,507 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 59 | 77 | 0 | def factorial(n):
result = 1
while (n != 0):
result = result * n
n -= 1
return result
numbers = input().split()
A, B = int(numbers[0]), int(numbers[1])
if(A <= B):
print(factorial(A))
else:
print(factorial(B)) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
Input Specification:
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Output Specification:
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
Demo Input:
['4 3\n']
Demo Output:
['6\n']
Note:
Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | ```python
def factorial(n):
result = 1
while (n != 0):
result = result * n
n -= 1
return result
numbers = input().split()
A, B = int(numbers[0]), int(numbers[1])
if(A <= B):
print(factorial(A))
else:
print(factorial(B))
``` | 3 |
|
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array. | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82",
"output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0"
},
{
"input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46",
"output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0"
},
{
"input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38",
"output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0"
},
{
"input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37",
"output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37"
},
{
"input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61",
"output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61"
},
{
"input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66",
"output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0"
},
{
"input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82",
"output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0"
},
{
"input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22",
"output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20"
},
{
"input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41",
"output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0"
},
{
"input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935",
"output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0"
},
{
"input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952",
"output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961"
},
{
"input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0",
"output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673"
},
{
"input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0",
"output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182"
},
{
"input": "5\n-1 -2 -3 -4 0",
"output": "1 -1\n2 -4 -3\n2 0 -2"
},
{
"input": "3\n-101 101 0",
"output": "1 -101\n1 101\n1 0"
},
{
"input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000",
"output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000"
},
{
"input": "4\n0 -1 -2 -3",
"output": "1 -1\n2 -3 -2\n1 0"
}
] | 1,592,741,960 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 248 | 0 | import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
n = int(input())
nums = sorted(list(map(int, input().split())))
pos = []
neg = []
s3=['0']
for i in range(n):
if(nums[i]<0):
neg.append(str(nums[i]))
elif(nums[i]>0):
pos.append(str(nums[i]))
if(len(neg)%2==0):
s1 = [neg[0]]
s2 = pos[0]
s3+=pos[1:]+neg[1:]
else:
s1 = [neg[0]]
if(not pos):
s2 = neg[1:3]
s3+=neg[3:]
elif(pos):
s2= pos
if(neg[1:]):
s3+=neg[1:]
print(len(s1), ' '.join(s1))
print(len(s2), ' '.join(s2))
print(len(s3), ' '.join(s3)) | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array.
Input Specification:
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
Output Specification:
In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
Demo Input:
['3\n-1 2 0\n', '4\n-1 -2 -3 0\n']
Demo Output:
['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n']
Note:
none | ```python
import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
n = int(input())
nums = sorted(list(map(int, input().split())))
pos = []
neg = []
s3=['0']
for i in range(n):
if(nums[i]<0):
neg.append(str(nums[i]))
elif(nums[i]>0):
pos.append(str(nums[i]))
if(len(neg)%2==0):
s1 = [neg[0]]
s2 = pos[0]
s3+=pos[1:]+neg[1:]
else:
s1 = [neg[0]]
if(not pos):
s2 = neg[1:3]
s3+=neg[3:]
elif(pos):
s2= pos
if(neg[1:]):
s3+=neg[1:]
print(len(s1), ' '.join(s1))
print(len(s2), ' '.join(s2))
print(len(s3), ' '.join(s3))
``` | 0 |
|
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
},
{
"input": "8",
"output": "1641"
},
{
"input": "9",
"output": "4920"
},
{
"input": "10",
"output": "14763"
},
{
"input": "15",
"output": "3587226"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "100",
"output": "721510432"
},
{
"input": "300",
"output": "327873818"
},
{
"input": "900",
"output": "295068084"
},
{
"input": "1500",
"output": "451187545"
},
{
"input": "3000",
"output": "645417275"
},
{
"input": "5000",
"output": "755610910"
},
{
"input": "10000",
"output": "723907367"
},
{
"input": "50000",
"output": "969527595"
},
{
"input": "90000",
"output": "548978368"
},
{
"input": "99999",
"output": "909741855"
},
{
"input": "100000",
"output": "729225554"
},
{
"input": "300000",
"output": "93822635"
},
{
"input": "800000",
"output": "178940616"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "4000000",
"output": "882155933"
},
{
"input": "9000000",
"output": "295060537"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "9999998",
"output": "576926295"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "31",
"output": "347990060"
}
] | 1,623,171,369 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 12 | 2,026 | 268,390,400 | import math
import sys
#from collections import deque, Counter, OrderedDict, defaultdict
#import heapq
#ceil,floor,log,sqrt,factorial,pow,pi,gcd
#import bisect
#from bisect import bisect_left,bisect_right
input = sys.stdin.readline
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input().strip()
return(list(s[:len(s)]))
def invr():
return(map(int,input().split()))
mx=10**9+7
n=inp()
dp=[0 for i in range(n+1)]
dp[0]=1
other=0
for i in range(1,n+1):
dp[i]=(3*other)%mx
other=(2*other+dp[i-1])%mx
print(dp[n]) | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Output Specification:
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
Demo Input:
['2\n', '4\n']
Demo Output:
['3\n', '21\n']
Note:
The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | ```python
import math
import sys
#from collections import deque, Counter, OrderedDict, defaultdict
#import heapq
#ceil,floor,log,sqrt,factorial,pow,pi,gcd
#import bisect
#from bisect import bisect_left,bisect_right
input = sys.stdin.readline
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input().strip()
return(list(s[:len(s)]))
def invr():
return(map(int,input().split()))
mx=10**9+7
n=inp()
dp=[0 for i in range(n+1)]
dp[0]=1
other=0
for i in range(1,n+1):
dp[i]=(3*other)%mx
other=(2*other+dp[i-1])%mx
print(dp[n])
``` | 0 |
|
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,628,703,226 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 218 | 20,172,800 | '''input
4
1 2 1 1
'''
n = int(input())
nl = list(map(int, input().split()))
odd = []
even = []
for it in nl:
if it%2 == 0:
even.append(it)
else:
odd.append(it)
if len(odd) == 1:
print(nl.index(odd[0])+1)
elif len(even) == 1:
print(nl.index(even[0])+1) | 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
'''input
4
1 2 1 1
'''
n = int(input())
nl = list(map(int, input().split()))
odd = []
even = []
for it in nl:
if it%2 == 0:
even.append(it)
else:
odd.append(it)
if len(odd) == 1:
print(nl.index(odd[0])+1)
elif len(even) == 1:
print(nl.index(even[0])+1)
``` | 3.907925 |
618 | B | Guess the Permutation | PROGRAMMING | 1,100 | [
"constructive algorithms"
] | null | null | Bob has a permutation of integers from 1 to *n*. Denote this permutation as *p*. The *i*-th element of *p* will be denoted as *p**i*. For all pairs of distinct integers *i*,<=*j* between 1 and *n*, he wrote the number *a**i*,<=*j*<==<=*min*(*p**i*,<=*p**j*). He writes *a**i*,<=*i*<==<=0 for all integer *i* from 1 to *n*.
Bob gave you all the values of *a**i*,<=*j* that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given. | The first line of the input will contain a single integer *n* (2<=≤<=*n*<=≤<=50).
The next *n* lines will contain the values of *a**i*,<=*j*. The *j*-th number on the *i*-th line will represent *a**i*,<=*j*. The *i*-th number on the *i*-th line will be 0. It's guaranteed that *a**i*,<=*j*<==<=*a**j*,<=*i* and there is at least one solution consistent with the information given. | Print *n* space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them. | [
"2\n0 1\n1 0\n",
"5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0\n"
] | [
"2 1\n",
"2 5 4 1 3\n"
] | In the first case, the answer can be {1, 2} or {2, 1}.
In the second case, another possible answer is {2, 4, 5, 1, 3}. | 1,000 | [
{
"input": "2\n0 1\n1 0",
"output": "2 1"
},
{
"input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0",
"output": "2 5 4 1 3"
},
{
"input": "10\n0 1 5 2 5 3 4 5 5 5\n1 0 1 1 1 1 1 1 1 1\n5 1 0 2 6 3 4 6 6 6\n2 1 2 0 2 2 2 2 2 2\n5 1 6 2 0 3 4 8 8 7\n3 1 3 2 3 0 3 3 3 3\n4 1 4 2 4 3 0 4 4 4\n5 1 6 2 8 3 4 0 9 7\n5 1 6 2 8 3 4 9 0 7\n5 1 6 2 7 3 4 7 7 0",
"output": "5 1 6 2 8 3 4 10 9 7"
},
{
"input": "4\n0 1 3 2\n1 0 1 1\n3 1 0 2\n2 1 2 0",
"output": "4 1 3 2"
},
{
"input": "7\n0 3 2 4 1 4 4\n3 0 2 3 1 3 3\n2 2 0 2 1 2 2\n4 3 2 0 1 5 5\n1 1 1 1 0 1 1\n4 3 2 5 1 0 6\n4 3 2 5 1 6 0",
"output": "4 3 2 5 1 7 6"
},
{
"input": "10\n0 4 4 1 4 4 4 2 3 4\n4 0 5 1 6 8 9 2 3 7\n4 5 0 1 5 5 5 2 3 5\n1 1 1 0 1 1 1 1 1 1\n4 6 5 1 0 6 6 2 3 6\n4 8 5 1 6 0 8 2 3 7\n4 9 5 1 6 8 0 2 3 7\n2 2 2 1 2 2 2 0 2 2\n3 3 3 1 3 3 3 2 0 3\n4 7 5 1 6 7 7 2 3 0",
"output": "4 10 5 1 6 8 9 2 3 7"
},
{
"input": "13\n0 5 5 2 5 4 5 5 3 5 5 5 1\n5 0 6 2 6 4 6 6 3 6 6 6 1\n5 6 0 2 10 4 7 10 3 8 10 9 1\n2 2 2 0 2 2 2 2 2 2 2 2 1\n5 6 10 2 0 4 7 12 3 8 11 9 1\n4 4 4 2 4 0 4 4 3 4 4 4 1\n5 6 7 2 7 4 0 7 3 7 7 7 1\n5 6 10 2 12 4 7 0 3 8 11 9 1\n3 3 3 2 3 3 3 3 0 3 3 3 1\n5 6 8 2 8 4 7 8 3 0 8 8 1\n5 6 10 2 11 4 7 11 3 8 0 9 1\n5 6 9 2 9 4 7 9 3 8 9 0 1\n1 1 1 1 1 1 1 1 1 1 1 1 0",
"output": "5 6 10 2 13 4 7 12 3 8 11 9 1"
}
] | 1,454,090,241 | 2,841 | Python 3 | OK | TESTS | 23 | 77 | 512,000 | from collections import defaultdict
def get_max_key( number_counts ):
res = 0
max_count = 1
for k,v in number_counts.items():
if v > max_count:
res = k
max_count = v
return res
if __name__ == "__main__":
n = int( input() )
res = [0]*n
thenum = n-1
for i in range(n):
ap = [int(x) for x in input().split()]
number_counts = defaultdict(int)
for j in range(n):
if ap[j]:
number_counts[ap[j]] += 1
#print(number_counts)
maxkey = get_max_key(number_counts)
if maxkey == 0:
res[i] = thenum
thenum += 1
else:
res[i] = maxkey
print(" ".join([str(x) for x in res]))
| Title: Guess the Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob has a permutation of integers from 1 to *n*. Denote this permutation as *p*. The *i*-th element of *p* will be denoted as *p**i*. For all pairs of distinct integers *i*,<=*j* between 1 and *n*, he wrote the number *a**i*,<=*j*<==<=*min*(*p**i*,<=*p**j*). He writes *a**i*,<=*i*<==<=0 for all integer *i* from 1 to *n*.
Bob gave you all the values of *a**i*,<=*j* that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.
Input Specification:
The first line of the input will contain a single integer *n* (2<=≤<=*n*<=≤<=50).
The next *n* lines will contain the values of *a**i*,<=*j*. The *j*-th number on the *i*-th line will represent *a**i*,<=*j*. The *i*-th number on the *i*-th line will be 0. It's guaranteed that *a**i*,<=*j*<==<=*a**j*,<=*i* and there is at least one solution consistent with the information given.
Output Specification:
Print *n* space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
Demo Input:
['2\n0 1\n1 0\n', '5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0\n']
Demo Output:
['2 1\n', '2 5 4 1 3\n']
Note:
In the first case, the answer can be {1, 2} or {2, 1}.
In the second case, another possible answer is {2, 4, 5, 1, 3}. | ```python
from collections import defaultdict
def get_max_key( number_counts ):
res = 0
max_count = 1
for k,v in number_counts.items():
if v > max_count:
res = k
max_count = v
return res
if __name__ == "__main__":
n = int( input() )
res = [0]*n
thenum = n-1
for i in range(n):
ap = [int(x) for x in input().split()]
number_counts = defaultdict(int)
for j in range(n):
if ap[j]:
number_counts[ap[j]] += 1
#print(number_counts)
maxkey = get_max_key(number_counts)
if maxkey == 0:
res[i] = thenum
thenum += 1
else:
res[i] = maxkey
print(" ".join([str(x) for x in res]))
``` | 3 |
|
835 | C | Star sky | PROGRAMMING | 1,600 | [
"dp",
"implementation"
] | null | null | The Cartesian coordinate system is set in the sky. There you can see *n* stars, the *i*-th has coordinates (*x**i*, *y**i*), a maximum brightness *c*, equal for all stars, and an initial brightness *s**i* (0<=≤<=*s**i*<=≤<=*c*).
Over time the stars twinkle. At moment 0 the *i*-th star has brightness *s**i*. Let at moment *t* some star has brightness *x*. Then at moment (*t*<=+<=1) this star will have brightness *x*<=+<=1, if *x*<=+<=1<=≤<=*c*, and 0, otherwise.
You want to look at the sky *q* times. In the *i*-th time you will look at the moment *t**i* and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (*x*1*i*, *y*1*i*) and the upper right — (*x*2*i*, *y*2*i*). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.
A star lies in a rectangle if it lies on its border or lies strictly inside it. | The first line contains three integers *n*, *q*, *c* (1<=≤<=*n*,<=*q*<=≤<=105, 1<=≤<=*c*<=≤<=10) — the number of the stars, the number of the views and the maximum brightness of the stars.
The next *n* lines contain the stars description. The *i*-th from these lines contains three integers *x**i*, *y**i*, *s**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=100, 0<=≤<=*s**i*<=≤<=*c*<=≤<=10) — the coordinates of *i*-th star and its initial brightness.
The next *q* lines contain the views description. The *i*-th from these lines contains five integers *t**i*, *x*1*i*, *y*1*i*, *x*2*i*, *y*2*i* (0<=≤<=*t**i*<=≤<=109, 1<=≤<=*x*1*i*<=<<=*x*2*i*<=≤<=100, 1<=≤<=*y*1*i*<=<<=*y*2*i*<=≤<=100) — the moment of the *i*-th view and the coordinates of the viewed rectangle. | For each view print the total brightness of the viewed stars. | [
"2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5\n",
"3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51\n"
] | [
"3\n0\n3\n",
"3\n3\n5\n0\n"
] | Let's consider the first example.
At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3.
At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0.
At the third view, you can see both stars. At moment 5 brightness of the first is 2, and brightness of the second is 1, so the answer is 3. | 1,250 | [
{
"input": "2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5",
"output": "3\n0\n3"
},
{
"input": "3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51",
"output": "3\n3\n5\n0"
}
] | 1,578,227,374 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 307,200 | n,q,c=map(int,input().split())
d=[]
for i in range(n):
x,y,s=map(int,input().split())
d.append([x,y,s])
for i in range(q):
t,x1,y1,x2,y2=map(int,input().split())
br=0
for j in d:
if j[0]>=x1 and j[0]<=x2 and j[1]>=y1 and j[1]<=y2:
if j[2]+t>c:
br+=t-c-j[2]
else:
br+=j[2]+t
print(br)
| Title: Star sky
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Cartesian coordinate system is set in the sky. There you can see *n* stars, the *i*-th has coordinates (*x**i*, *y**i*), a maximum brightness *c*, equal for all stars, and an initial brightness *s**i* (0<=≤<=*s**i*<=≤<=*c*).
Over time the stars twinkle. At moment 0 the *i*-th star has brightness *s**i*. Let at moment *t* some star has brightness *x*. Then at moment (*t*<=+<=1) this star will have brightness *x*<=+<=1, if *x*<=+<=1<=≤<=*c*, and 0, otherwise.
You want to look at the sky *q* times. In the *i*-th time you will look at the moment *t**i* and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (*x*1*i*, *y*1*i*) and the upper right — (*x*2*i*, *y*2*i*). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.
A star lies in a rectangle if it lies on its border or lies strictly inside it.
Input Specification:
The first line contains three integers *n*, *q*, *c* (1<=≤<=*n*,<=*q*<=≤<=105, 1<=≤<=*c*<=≤<=10) — the number of the stars, the number of the views and the maximum brightness of the stars.
The next *n* lines contain the stars description. The *i*-th from these lines contains three integers *x**i*, *y**i*, *s**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=100, 0<=≤<=*s**i*<=≤<=*c*<=≤<=10) — the coordinates of *i*-th star and its initial brightness.
The next *q* lines contain the views description. The *i*-th from these lines contains five integers *t**i*, *x*1*i*, *y*1*i*, *x*2*i*, *y*2*i* (0<=≤<=*t**i*<=≤<=109, 1<=≤<=*x*1*i*<=<<=*x*2*i*<=≤<=100, 1<=≤<=*y*1*i*<=<<=*y*2*i*<=≤<=100) — the moment of the *i*-th view and the coordinates of the viewed rectangle.
Output Specification:
For each view print the total brightness of the viewed stars.
Demo Input:
['2 3 3\n1 1 1\n3 2 0\n2 1 1 2 2\n0 2 1 4 5\n5 1 1 5 5\n', '3 4 5\n1 1 2\n2 3 0\n3 3 1\n0 1 1 100 100\n1 2 2 4 4\n2 2 1 4 7\n1 50 50 51 51\n']
Demo Output:
['3\n0\n3\n', '3\n3\n5\n0\n']
Note:
Let's consider the first example.
At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3.
At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0.
At the third view, you can see both stars. At moment 5 brightness of the first is 2, and brightness of the second is 1, so the answer is 3. | ```python
n,q,c=map(int,input().split())
d=[]
for i in range(n):
x,y,s=map(int,input().split())
d.append([x,y,s])
for i in range(q):
t,x1,y1,x2,y2=map(int,input().split())
br=0
for j in d:
if j[0]>=x1 and j[0]<=x2 and j[1]>=y1 and j[1]<=y2:
if j[2]+t>c:
br+=t-c-j[2]
else:
br+=j[2]+t
print(br)
``` | 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,618,890,895 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 62 | 0 | n = int(input())
s = input()
x = 0
z = ""
i = 0
while i < n:
if s[i] == "B":
x += 1
y = 1
while i+1 != n and s[i+1] == "B":
y += 1
i += 1
z += str(y)
z += " "
i += 1
print(x)
print(z)
| 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
n = int(input())
s = input()
x = 0
z = ""
i = 0
while i < n:
if s[i] == "B":
x += 1
y = 1
while i+1 != n and s[i+1] == "B":
y += 1
i += 1
z += str(y)
z += " "
i += 1
print(x)
print(z)
``` | 3 |
|
53 | A | Autocomplete | PROGRAMMING | 1,100 | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of *n* last visited by the user pages and the inputted part *s* are known. Your task is to complete *s* to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix *s*. | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only. | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages. | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | 500 | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszjebdoad\nchz\na",
"output": "kudljmxcse"
},
{
"input": "ntqwpa\n5\nvvepyowvn\nntqwpakay\nhh\nygiafasda\nntqwpadm",
"output": "ntqwpadm"
},
{
"input": "aflb\n6\nsaej\nujxsiijg\npp\nhgoprw\ncp\nnt",
"output": "aflb"
},
{
"input": "dzwzyj\n7\nwvixktp\ndzwzyjuhn\ndzwzyjqrbd\ndzwzyji\ndzwzyjyfys\ndzwzyjrcb\nxptb",
"output": "dzwzyji"
},
{
"input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\n1\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn",
"output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg"
},
{
"input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\n1\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb",
"output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb"
},
{
"input": "msjnqudojxtzvpc\n2\nvlxclsvqbucmbrkwwtoxek\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld",
"output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld"
}
] | 1,667,295,437 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 0 | a=input()
l=[]
for i in range(int(input())):
str=input()
if str[0:len(a)]==a:
l.append(str)
if len(l)==0:
print(a)
else:
k=l[0]
for i in l:
if len(i)<len(k):
k=i
print(k)
| Title: Autocomplete
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of *n* last visited by the user pages and the inputted part *s* are known. Your task is to complete *s* to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix *s*.
Input Specification:
The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
Output Specification:
If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' operator in the modern programming languages.
Demo Input:
['next\n2\nnextpermutation\nnextelement\n', 'find\n4\nfind\nfindfirstof\nfindit\nfand\n', 'find\n4\nfondfind\nfondfirstof\nfondit\nfand\n']
Demo Output:
['nextelement\n', 'find\n', 'find\n']
Note:
none | ```python
a=input()
l=[]
for i in range(int(input())):
str=input()
if str[0:len(a)]==a:
l.append(str)
if len(l)==0:
print(a)
else:
k=l[0]
for i in l:
if len(i)<len(k):
k=i
print(k)
``` | 0 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,658,858,115 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | from posixpath import split
lst=map(int,input().split())
max=max(lst)-1
num=6-max
if 6%num==0:
den=int(6/num)
num=1
elif 6%num==2:
den=3
num=2
else:
den=6
num=5
print("{}/{}".format(num,den))
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
from posixpath import split
lst=map(int,input().split())
max=max(lst)-1
num=6-max
if 6%num==0:
den=int(6/num)
num=1
elif 6%num==2:
den=3
num=2
else:
den=6
num=5
print("{}/{}".format(num,den))
``` | 3.954 |
0 | none | none | none | 0 | [
"none"
] | null | null | A flower shop has got *n* bouquets, and the *i*-th bouquet consists of *a**i* flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets.
Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouquet should be odd. Each of the initial bouquets can be a part of at most one large bouquet. If an initial bouquet becomes a part of a large bouquet, all its flowers are included in the large bouquet.
Determine the maximum possible number of large bouquets Vasya can make. | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of initial bouquets.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the number of flowers in each of the initial bouquets. | Print the maximum number of large bouquets Vasya can make. | [
"5\n2 3 4 2 7\n",
"6\n2 2 6 8 6 12\n",
"3\n11 4 10\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first example Vasya can make 2 large bouquets. For example, the first bouquet can contain the first and the fifth initial bouquets (the total number of flowers is then equal to 9), and the second bouquet can consist of the second and the third initial bouquets (the total number of flowers is then equal to 7). The fourth initial bouquet is unused in this scheme.
In the second example it is not possible to form a single bouquet with odd number of flowers.
In the third example Vasya can make one large bouquet. For example, he can make it using all three initial bouquets. The size of the large bouquet is then equal to 11 + 4 + 10 = 25. | 0 | [
{
"input": "5\n2 3 4 2 7",
"output": "2"
},
{
"input": "6\n2 2 6 8 6 12",
"output": "0"
},
{
"input": "3\n11 4 10",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n999999",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "4\n943543 151729 379602 589828",
"output": "2"
},
{
"input": "2\n468463 62253",
"output": "0"
},
{
"input": "3\n352987 849349 967007",
"output": "1"
},
{
"input": "20\n274039 899325 798709 157662 963297 276599 529230 80095 252956 980560 358150 82383 29856 901568 123794 275349 512273 508369 120076 170206",
"output": "10"
},
{
"input": "25\n742168 377547 485672 437223 96307 902863 759104 747933 512899 410317 588598 666688 823202 257684 520631 910066 168864 71499 899972 565350 764848 754913 929040 864132 289976",
"output": "10"
}
] | 1,521,303,687 | 2,787 | Python 3 | OK | TESTS | 49 | 140 | 14,848,000 | n = int(input())
even = 0
odd = 0
arr = input()
l = list(map(int, arr.split(' ')))
for x in l:
if (x % 2 == 0):
even += 1
else:
odd += 1
rs = min(even, odd)
even -= rs
odd -= rs
rs += int(odd / 3)
print(rs)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A flower shop has got *n* bouquets, and the *i*-th bouquet consists of *a**i* flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets.
Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouquet should be odd. Each of the initial bouquets can be a part of at most one large bouquet. If an initial bouquet becomes a part of a large bouquet, all its flowers are included in the large bouquet.
Determine the maximum possible number of large bouquets Vasya can make.
Input Specification:
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of initial bouquets.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the number of flowers in each of the initial bouquets.
Output Specification:
Print the maximum number of large bouquets Vasya can make.
Demo Input:
['5\n2 3 4 2 7\n', '6\n2 2 6 8 6 12\n', '3\n11 4 10\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first example Vasya can make 2 large bouquets. For example, the first bouquet can contain the first and the fifth initial bouquets (the total number of flowers is then equal to 9), and the second bouquet can consist of the second and the third initial bouquets (the total number of flowers is then equal to 7). The fourth initial bouquet is unused in this scheme.
In the second example it is not possible to form a single bouquet with odd number of flowers.
In the third example Vasya can make one large bouquet. For example, he can make it using all three initial bouquets. The size of the large bouquet is then equal to 11 + 4 + 10 = 25. | ```python
n = int(input())
even = 0
odd = 0
arr = input()
l = list(map(int, arr.split(' ')))
for x in l:
if (x % 2 == 0):
even += 1
else:
odd += 1
rs = min(even, odd)
even -= rs
odd -= rs
rs += int(odd / 3)
print(rs)
``` | 3 |
|
616 | B | Dinner with Emma | PROGRAMMING | 1,000 | [
"games",
"greedy"
] | null | null | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. | Print the only integer *a* — the cost of the dinner for Jack and Emma. | [
"3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n",
"3 3\n1 2 3\n2 3 1\n3 1 2\n"
] | [
"2\n",
"1\n"
] | In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | 0 | [
{
"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1",
"output": "2"
},
{
"input": "3 3\n1 2 3\n2 3 1\n3 1 2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n74 35 82 39 1 84 29 41 70 12",
"output": "1"
},
{
"input": "10 1\n44\n23\n65\n17\n48\n29\n49\n88\n91\n85",
"output": "91"
},
{
"input": "10 10\n256 72 455 45 912 506 235 68 951 92\n246 305 45 212 788 621 449 876 459 899\n732 107 230 357 370 610 997 669 61 192\n131 93 481 527 983 920 825 540 435 54\n777 682 984 20 337 480 264 137 249 502\n51 467 479 228 923 752 714 436 199 973\n3 91 612 571 631 212 751 84 886 948\n252 130 583 23 194 985 234 978 709 16\n636 991 203 469 719 540 184 902 503 652\n826 680 150 284 37 987 360 183 447 51",
"output": "184"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "2 1\n999999999\n1000000000",
"output": "1000000000"
}
] | 1,599,474,967 | 667 | PyPy 3 | OK | TESTS | 16 | 155 | 1,638,400 | import sys
n, m = map(int, input().split())
ans = 0
for _ in range(n):
ans = max(ans, min(map(int, input().split())))
print(ans)
| Title: Dinner with Emma
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to *n* and the avenues are numbered with integers from 1 to *m*. The cost of dinner in the restaurant at the intersection of the *i*-th street and the *j*-th avenue is *c**ij*.
Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue.
Output Specification:
Print the only integer *a* — the cost of the dinner for Jack and Emma.
Demo Input:
['3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n', '3 3\n1 2 3\n2 3 1\n3 1 2\n']
Demo Output:
['2\n', '1\n']
Note:
In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. | ```python
import sys
n, m = map(int, input().split())
ans = 0
for _ in range(n):
ans = max(ans, min(map(int, input().split())))
print(ans)
``` | 3 |
|
667 | B | Coat of Anticubism | PROGRAMMING | 1,100 | [
"constructive algorithms",
"geometry"
] | null | null | As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon.
Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The *i*-th rod is a segment of length *l**i*.
The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle .
Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.
Help sculptor! | The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso already has. | Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods. | [
"3\n1 2 1\n",
"5\n20 4 3 2 1\n"
] | [
"1\n",
"11\n"
] | In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.
In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}. | 1,000 | [
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n20 4 3 2 1",
"output": "11"
},
{
"input": "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086",
"output": "70407571"
},
{
"input": "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 88059371 53742651 8489205 3528194",
"output": "360142248"
},
{
"input": "19\n479740 7703374 196076708 180202968 579604 17429 16916 11989886 30832424 6384983 8937497 431 62955 48167457 898566333 29534955 1485775 848444 372839845",
"output": "2404943"
},
{
"input": "35\n306260 278 43508628 54350745 222255 842526 39010821 10627 14916465 3059978 61449 503809 2820 1609513 196062 65695 270869 15079297 2885093 189306 4682268 422616382 1642346 82340 6 2 975464673 1388191 70110665 272855 253160079 1849635 7837751 274070 10394",
"output": "34445194"
},
{
"input": "53\n1014364 40727 75774 243769 314 406417 5272684 14138 10640282 64955 2763 5667043 2121887 204672692 567643 60183 5183 11361359 2792918 199155 174809 16182540 21 392221 19434423 9140891 159733 15438 67903 3816799 616 429181 30392293 413992581 10847741 20771 16366654 1163 414283 156163 55907108 310278 95949614 185865 976650886 197610 87 61264 4586815 107764 26390852 331828 541",
"output": "25390787"
},
{
"input": "3\n1 1 1000000000",
"output": "999999999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 1000000000",
"output": "999999956"
},
{
"input": "5\n100000000 100000000 100000000 100000000 500000000",
"output": "100000001"
},
{
"input": "3\n300000000 300000000 600000000",
"output": "1"
},
{
"input": "5\n10 4 3 2 1",
"output": "1"
},
{
"input": "3\n800000000 1 1",
"output": "799999999"
},
{
"input": "3\n1000000000 1 1",
"output": "999999999"
}
] | 1,681,561,359 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 51 | 124 | 8,499,200 | n = int(input())
q = [int(x) for x in input().split()]
s = 0
m = 0
for i in range(n):
s += q[i]
m = max(m, q[i])
answer = 2*m - s + 1
print(answer) | Title: Coat of Anticubism
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon.
Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The *i*-th rod is a segment of length *l**i*.
The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle .
Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.
Help sculptor!
Input Specification:
The first line contains an integer *n* (3<=≤<=*n*<=≤<=105) — a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=≤<=*l**i*<=≤<=109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso already has.
Output Specification:
Print the only integer *z* — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods.
Demo Input:
['3\n1 2 1\n', '5\n20 4 3 2 1\n']
Demo Output:
['1\n', '11\n']
Note:
In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.
In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}. | ```python
n = int(input())
q = [int(x) for x in input().split()]
s = 0
m = 0
for i in range(n):
s += q[i]
m = max(m, q[i])
answer = 2*m - s + 1
print(answer)
``` | 3 |
|
992 | B | Nastya Studies Informatics | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.
We define a pair of integers (*a*,<=*b*) good, if *GCD*(*a*,<=*b*)<==<=*x* and *LCM*(*a*,<=*b*)<==<=*y*, where *GCD*(*a*,<=*b*) denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) of *a* and *b*, and *LCM*(*a*,<=*b*) denotes the [least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple) of *a* and *b*.
You are given two integers *x* and *y*. You are to find the number of good pairs of integers (*a*,<=*b*) such that *l*<=≤<=*a*,<=*b*<=≤<=*r*. Note that pairs (*a*,<=*b*) and (*b*,<=*a*) are considered different if *a*<=≠<=*b*. | The only line contains four integers *l*,<=*r*,<=*x*,<=*y* (1<=≤<=*l*<=≤<=*r*<=≤<=109, 1<=≤<=*x*<=≤<=*y*<=≤<=109). | In the only line print the only integer — the answer for the problem. | [
"1 2 1 2\n",
"1 12 1 12\n",
"50 100 3 30\n"
] | [
"2\n",
"4\n",
"0\n"
] | In the first example there are two suitable good pairs of integers (*a*, *b*): (1, 2) and (2, 1).
In the second example there are four suitable good pairs of integers (*a*, *b*): (1, 12), (12, 1), (3, 4) and (4, 3).
In the third example there are good pairs of integers, for example, (3, 30), but none of them fits the condition *l* ≤ *a*, *b* ≤ *r*. | 1,000 | [
{
"input": "1 2 1 2",
"output": "2"
},
{
"input": "1 12 1 12",
"output": "4"
},
{
"input": "50 100 3 30",
"output": "0"
},
{
"input": "1 1000000000 1 1000000000",
"output": "4"
},
{
"input": "1 1000000000 158260522 200224287",
"output": "0"
},
{
"input": "1 1000000000 2 755829150",
"output": "8"
},
{
"input": "1 1000000000 158260522 158260522",
"output": "1"
},
{
"input": "1 1000000000 877914575 877914575",
"output": "1"
},
{
"input": "232 380232688 116 760465376",
"output": "30"
},
{
"input": "47259 3393570 267 600661890",
"output": "30"
},
{
"input": "1 1000000000 1 672672000",
"output": "64"
},
{
"input": "1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1 1000000000 1 649209600",
"output": "32"
},
{
"input": "1 1000000000 1 682290000",
"output": "32"
},
{
"input": "1 1000000000 1 228614400",
"output": "16"
},
{
"input": "1 1000000000 1 800280000",
"output": "32"
},
{
"input": "1 1000000000 1 919987200",
"output": "16"
},
{
"input": "1 1000000000 1 456537870",
"output": "64"
},
{
"input": "1 1000000000 1 7198102",
"output": "8"
},
{
"input": "1 1000000000 1 58986263",
"output": "16"
},
{
"input": "1 1000000000 1 316465536",
"output": "16"
},
{
"input": "1 1000000000 1 9558312",
"output": "16"
},
{
"input": "1 1000000000 1 5461344",
"output": "16"
},
{
"input": "58 308939059 29 617878118",
"output": "62"
},
{
"input": "837 16262937 27 504151047",
"output": "28"
},
{
"input": "47275 402550 25 761222050",
"output": "12"
},
{
"input": "22 944623394 22 944623394",
"output": "32"
},
{
"input": "1032 8756124 12 753026664",
"output": "18"
},
{
"input": "7238 939389 11 618117962",
"output": "10"
},
{
"input": "58351 322621 23 818489477",
"output": "6"
},
{
"input": "3450 7068875 25 975504750",
"output": "86"
},
{
"input": "13266 1606792 22 968895576",
"output": "14"
},
{
"input": "21930 632925 15 925336350",
"output": "42"
},
{
"input": "2193 4224517 17 544962693",
"output": "42"
},
{
"input": "526792 39807152 22904 915564496",
"output": "8"
},
{
"input": "67728 122875524 16932 491502096",
"output": "12"
},
{
"input": "319813 63298373 24601 822878849",
"output": "6"
},
{
"input": "572464 23409136 15472 866138032",
"output": "4"
},
{
"input": "39443 809059020 19716 777638472",
"output": "12"
},
{
"input": "2544768 8906688 27072 837228672",
"output": "0"
},
{
"input": "413592 46975344 21768 892531536",
"output": "10"
},
{
"input": "11349 816231429 11349 816231429",
"output": "8"
},
{
"input": "16578 939956022 16578 939956022",
"output": "4"
},
{
"input": "2783175 6882425 21575 887832825",
"output": "2"
},
{
"input": "2862252 7077972 22188 913058388",
"output": "2"
},
{
"input": "1856828 13124976 25436 958123248",
"output": "6"
},
{
"input": "100 1000000000 158260522 158260522",
"output": "1"
},
{
"input": "100 1000000000 877914575 877914575",
"output": "1"
},
{
"input": "100 1000000000 602436426 602436426",
"output": "1"
},
{
"input": "100 1000000000 24979445 24979445",
"output": "1"
},
{
"input": "1 1000000000 18470 112519240",
"output": "4"
},
{
"input": "1 1000000000 22692 2201124",
"output": "2"
},
{
"input": "1 1000000000 24190 400949250",
"output": "16"
},
{
"input": "1 1000000000 33409 694005157",
"output": "2"
},
{
"input": "1 1000000000 24967 470827686",
"output": "16"
},
{
"input": "1 1000000000 35461 152517761",
"output": "8"
},
{
"input": "2 1000000000 158260522 200224287",
"output": "0"
},
{
"input": "2 1000000000 602436426 611751520",
"output": "0"
},
{
"input": "2 1000000000 861648772 942726551",
"output": "0"
},
{
"input": "2 1000000000 433933447 485982495",
"output": "0"
},
{
"input": "2 1000000000 262703497 480832794",
"output": "0"
},
{
"input": "2672374 422235092 1336187 844470184",
"output": "2"
},
{
"input": "1321815 935845020 1321815 935845020",
"output": "8"
},
{
"input": "29259607 69772909 2250739 907047817",
"output": "2"
},
{
"input": "11678540 172842392 2335708 864211960",
"output": "4"
},
{
"input": "297 173688298 2876112 851329152",
"output": "2"
},
{
"input": "7249 55497026 659 610467286",
"output": "28"
},
{
"input": "398520 1481490 810 728893080",
"output": "4"
},
{
"input": "2354 369467362 1177 738934724",
"output": "14"
},
{
"input": "407264 2497352 1144 889057312",
"output": "2"
},
{
"input": "321399 1651014 603 879990462",
"output": "4"
},
{
"input": "475640 486640 440 526057840",
"output": "2"
},
{
"input": "631714 179724831 1136 717625968",
"output": "0"
},
{
"input": "280476 1595832 588 761211864",
"output": "8"
},
{
"input": "10455 39598005 615 673166085",
"output": "6"
},
{
"input": "24725 19759875 575 849674625",
"output": "22"
},
{
"input": "22 158 2 1738",
"output": "2"
},
{
"input": "1 2623 1 2623",
"output": "4"
},
{
"input": "7 163677675 3 18",
"output": "0"
},
{
"input": "159 20749927 1 158",
"output": "0"
},
{
"input": "5252 477594071 1 5251",
"output": "0"
},
{
"input": "2202 449433679 3 6603",
"output": "0"
},
{
"input": "6 111 3 222",
"output": "2"
},
{
"input": "26 46 2 598",
"output": "2"
},
{
"input": "26 82 2 1066",
"output": "2"
},
{
"input": "1 2993 1 2993",
"output": "4"
},
{
"input": "17 17 1 289",
"output": "0"
},
{
"input": "177 267 3 15753",
"output": "2"
},
{
"input": "7388 22705183 1 7387",
"output": "0"
},
{
"input": "1 100 3 100",
"output": "0"
},
{
"input": "1 1000 6 1024",
"output": "0"
},
{
"input": "1 100 2 4",
"output": "2"
},
{
"input": "1 10000 2 455",
"output": "0"
},
{
"input": "1 1000000000 250000000 1000000000",
"output": "2"
},
{
"input": "3 3 1 1",
"output": "0"
},
{
"input": "1 1000000000 100000000 1000000000",
"output": "4"
},
{
"input": "5 10 3 3",
"output": "0"
},
{
"input": "1 1000 5 13",
"output": "0"
},
{
"input": "2 2 3 3",
"output": "0"
},
{
"input": "1 1000000000 499999993 999999986",
"output": "2"
},
{
"input": "1 1 1 10",
"output": "0"
},
{
"input": "1 10 10 100",
"output": "0"
},
{
"input": "1 1000 4 36",
"output": "2"
},
{
"input": "1 1000000000 10000000 20000000",
"output": "2"
},
{
"input": "100 100 5 5",
"output": "0"
},
{
"input": "3 3 3 9",
"output": "0"
},
{
"input": "36 200 24 144",
"output": "2"
},
{
"input": "1 100 3 10",
"output": "0"
}
] | 1,589,734,905 | 2,145 | PyPy 3 | OK | TESTS | 108 | 155 | 21,401,600 | l,r,x,y=map(int,input().split())
import math
def it(a):
if a<l or a>r:return(False)
return(True)
ans=0
div=set()
for i in range(1,int(y**0.5)+1):
if y%i==0 and (y//i)%x==0 and it(i*x) and it(y//i) and math.gcd(i,(y//i)//x)==1:
c=1 if i==(y//i)//x else 0
ans+=2-c
div.add(y//i)
div.add(i*x)
print(len(div)) | Title: Nastya Studies Informatics
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.
We define a pair of integers (*a*,<=*b*) good, if *GCD*(*a*,<=*b*)<==<=*x* and *LCM*(*a*,<=*b*)<==<=*y*, where *GCD*(*a*,<=*b*) denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) of *a* and *b*, and *LCM*(*a*,<=*b*) denotes the [least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple) of *a* and *b*.
You are given two integers *x* and *y*. You are to find the number of good pairs of integers (*a*,<=*b*) such that *l*<=≤<=*a*,<=*b*<=≤<=*r*. Note that pairs (*a*,<=*b*) and (*b*,<=*a*) are considered different if *a*<=≠<=*b*.
Input Specification:
The only line contains four integers *l*,<=*r*,<=*x*,<=*y* (1<=≤<=*l*<=≤<=*r*<=≤<=109, 1<=≤<=*x*<=≤<=*y*<=≤<=109).
Output Specification:
In the only line print the only integer — the answer for the problem.
Demo Input:
['1 2 1 2\n', '1 12 1 12\n', '50 100 3 30\n']
Demo Output:
['2\n', '4\n', '0\n']
Note:
In the first example there are two suitable good pairs of integers (*a*, *b*): (1, 2) and (2, 1).
In the second example there are four suitable good pairs of integers (*a*, *b*): (1, 12), (12, 1), (3, 4) and (4, 3).
In the third example there are good pairs of integers, for example, (3, 30), but none of them fits the condition *l* ≤ *a*, *b* ≤ *r*. | ```python
l,r,x,y=map(int,input().split())
import math
def it(a):
if a<l or a>r:return(False)
return(True)
ans=0
div=set()
for i in range(1,int(y**0.5)+1):
if y%i==0 and (y//i)%x==0 and it(i*x) and it(y//i) and math.gcd(i,(y//i)//x)==1:
c=1 if i==(y//i)//x else 0
ans+=2-c
div.add(y//i)
div.add(i*x)
print(len(div))
``` | 3 |
|
991 | B | Getting an A | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo.
Help Vasya — calculate the minimum amount of lab works Vasya has to redo. | The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. | Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. | [
"3\n4 4 4\n",
"4\n5 4 5 5\n",
"4\n5 3 3 5\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$. | 1,000 | [
{
"input": "3\n4 4 4",
"output": "2"
},
{
"input": "4\n5 4 5 5",
"output": "0"
},
{
"input": "4\n5 3 3 5",
"output": "1"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "4\n3 2 5 4",
"output": "2"
},
{
"input": "5\n5 4 3 2 5",
"output": "2"
},
{
"input": "8\n5 4 2 5 5 2 5 5",
"output": "1"
},
{
"input": "5\n5 5 2 5 5",
"output": "1"
},
{
"input": "6\n5 5 5 5 5 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "5"
},
{
"input": "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 3 3 5 3 2 2 4 5 5 4 5 5 4 2 3 2 2 2 2 5 3 5 2 3 4",
"output": "40"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "4\n3 2 5 5",
"output": "1"
},
{
"input": "6\n4 3 3 3 3 4",
"output": "4"
},
{
"input": "8\n3 3 5 3 3 3 5 5",
"output": "3"
},
{
"input": "10\n2 4 5 5 5 5 2 3 3 2",
"output": "3"
},
{
"input": "20\n5 2 5 2 2 2 2 2 5 2 2 5 2 5 5 2 2 5 2 2",
"output": "10"
},
{
"input": "25\n4 4 4 4 3 4 3 3 3 3 3 4 4 3 4 4 4 4 4 3 3 3 4 3 4",
"output": "13"
},
{
"input": "30\n4 2 4 2 4 2 2 4 4 4 4 2 4 4 4 2 2 2 2 4 2 4 4 4 2 4 2 4 2 2",
"output": "15"
},
{
"input": "52\n5 3 4 4 4 3 5 3 4 5 3 4 4 3 5 5 4 3 3 3 4 5 4 4 5 3 5 3 5 4 5 5 4 3 4 5 3 4 3 3 4 4 4 3 5 3 4 5 3 5 4 5",
"output": "14"
},
{
"input": "77\n5 3 2 3 2 3 2 3 5 2 2 3 3 3 3 5 3 3 2 2 2 5 5 5 5 3 2 2 5 2 3 2 2 5 2 5 3 3 2 2 5 5 2 3 3 2 3 3 3 2 5 5 2 2 3 3 5 5 2 2 5 5 3 3 5 5 2 2 5 2 2 5 5 5 2 5 2",
"output": "33"
},
{
"input": "55\n3 4 2 3 3 2 4 4 3 3 4 2 4 4 3 3 2 3 2 2 3 3 2 3 2 3 2 4 4 3 2 3 2 3 3 2 2 4 2 4 4 3 4 3 2 4 3 2 4 2 2 3 2 3 4",
"output": "34"
},
{
"input": "66\n5 4 5 5 4 4 4 4 4 2 5 5 2 4 2 2 2 5 4 4 4 4 5 2 2 5 5 2 2 4 4 2 4 2 2 5 2 5 4 5 4 5 4 4 2 5 2 4 4 4 2 2 5 5 5 5 4 4 4 4 4 2 4 5 5 5",
"output": "16"
},
{
"input": "99\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",
"output": "83"
},
{
"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": "84"
},
{
"input": "99\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",
"output": "75"
},
{
"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": "75"
},
{
"input": "99\n2 2 3 3 3 3 3 2 2 3 2 3 2 3 2 2 3 2 3 2 3 3 3 3 2 2 2 2 3 2 3 3 3 3 3 2 3 3 3 3 2 3 2 3 3 3 2 3 2 3 3 3 3 2 2 3 2 3 2 3 2 3 2 2 2 3 3 2 3 2 2 2 2 2 2 2 2 3 3 3 3 2 3 2 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3",
"output": "75"
},
{
"input": "100\n3 2 3 3 2 2 3 2 2 3 3 2 3 2 2 2 2 2 3 2 2 2 3 2 3 3 2 2 3 2 2 2 2 3 2 3 3 2 2 3 2 2 3 2 3 2 2 3 2 3 2 2 3 2 2 3 3 3 3 3 2 2 3 2 3 3 2 2 3 2 2 2 3 2 2 3 3 2 2 3 3 3 3 2 3 2 2 2 3 3 2 2 3 2 2 2 2 3 2 2",
"output": "75"
},
{
"input": "99\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",
"output": "50"
},
{
"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": "50"
},
{
"input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 4 2 2 2 4 4 2 2 2 2 4 4 4 2 2 2 4 4 2 4 2 4 2 2 4 2 4 4 4 4 4 2 2 4 4 4 2 2 2 2 4 2 4 2 2 2 2 2 2 4 4 2 4 2 2 4 2 2 2 2 2 4 2 4 2 2 4 4 4",
"output": "54"
},
{
"input": "100\n4 2 4 4 2 4 2 2 4 4 4 4 4 4 4 4 4 2 4 4 2 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 2 2 4 4 2 4 2 4 4 4 2 2 2 2 2 2 2 4 2 2 2 4 4 4 2 2 2 2 4 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 4 4 4 4 2 4 2 2 4",
"output": "50"
},
{
"input": "99\n4 3 4 4 4 4 4 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 3 4 3 3 3 3 4 3 4 4 3 4 4 3 3 4 4 4 3 3 3 4 4 3 3 4 3 4 3 4 3 4 3 3 3 3 4 3 4 4 4 4 4 4 3 4 4 3 3 3 3 3 3 3 3 4 3 3 3 4 4 4 4 4 4 3 3 3 3 4 4 4 3 3 4 3",
"output": "51"
},
{
"input": "100\n3 3 4 4 4 4 4 3 4 4 3 3 3 3 4 4 4 4 4 4 3 3 3 4 3 4 3 4 3 3 4 3 3 3 3 3 3 3 3 4 3 4 3 3 4 3 3 3 4 4 3 4 4 3 3 4 4 4 4 4 4 3 4 4 3 4 3 3 3 4 4 3 3 4 4 3 4 4 4 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 4 3 3 4",
"output": "51"
},
{
"input": "99\n3 3 4 4 4 2 4 4 3 2 3 4 4 4 2 2 2 3 2 4 4 2 4 3 2 2 2 4 2 3 4 3 4 2 3 3 4 2 3 3 2 3 4 4 3 2 4 3 4 3 3 3 3 3 4 4 3 3 4 4 2 4 3 4 3 2 3 3 3 4 4 2 4 4 2 3 4 2 3 3 3 4 2 2 3 2 4 3 2 3 3 2 3 4 2 3 3 2 3",
"output": "58"
},
{
"input": "100\n2 2 4 2 2 3 2 3 4 4 3 3 4 4 4 2 3 2 2 3 4 2 3 2 4 3 4 2 3 3 3 2 4 3 3 2 2 3 2 4 4 2 4 3 4 4 3 3 3 2 4 2 2 2 2 2 2 3 2 3 2 3 4 4 4 2 2 3 4 4 3 4 3 3 2 3 3 3 4 3 2 3 3 2 4 2 3 3 4 4 3 3 4 3 4 3 3 4 3 3",
"output": "61"
},
{
"input": "99\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",
"output": "0"
},
{
"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": "0"
},
{
"input": "99\n2 2 2 2 2 5 2 2 5 2 5 2 5 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 2 5 5 2 5 2 2 5 2 5 2 2 5 5 2 2 2 2 5 5 2 2 2 5 2 2 5 2 2 2 2 2 5 5 5 5 2 2 5 2 5 2 2 2 2 2 5 2 2 5 5 2 2 2 2 2 5 5 2 2 5 5 2 2 2 2 5 5 5 2 5",
"output": "48"
},
{
"input": "100\n5 5 2 2 2 2 2 2 5 5 2 5 2 2 2 2 5 2 5 2 5 5 2 5 5 2 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 5 5 5 2 5 5 5 5 5 5 2 2 5 2 2 5 5 5 5 5 2 5 2 5 2 2 2 5 2 5 2 5 5 2 5 5 2 2 5 2 5 5 2 5 2 2 5 2 2 2 5 2 2 2 2 5 5 2 5",
"output": "38"
},
{
"input": "99\n5 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 5 5 3 5 5 3 3 5 5 5 3 5 3 3 3 3 5 3 3 5 5 3 5 5 5 3 5 3 5 3 5 5 5 5 3 3 3 5 3 5 3 3 3 5 5 5 5 5 3 5 5 3 3 5 5 3 5 5 3 5 5 3 3 5 5 5 3 3 3 5 3 3 3",
"output": "32"
},
{
"input": "100\n3 3 3 5 3 3 3 3 3 3 5 5 5 5 3 3 3 3 5 3 3 3 3 3 5 3 5 3 3 5 5 5 5 5 5 3 3 5 3 3 5 3 5 5 5 3 5 3 3 3 3 3 3 3 3 3 3 3 5 5 3 5 3 5 5 3 5 3 3 5 3 5 5 5 5 3 5 3 3 3 5 5 5 3 3 3 5 3 5 5 5 3 3 3 5 3 5 5 3 5",
"output": "32"
},
{
"input": "99\n5 3 5 5 3 3 3 2 2 5 2 5 3 2 5 2 5 2 3 5 3 2 3 2 5 5 2 2 3 3 5 5 3 5 5 2 3 3 5 2 2 5 3 2 5 2 3 5 5 2 5 2 2 5 3 3 5 3 3 5 3 2 3 5 3 2 3 2 3 2 2 2 2 5 2 2 3 2 5 5 5 3 3 2 5 3 5 5 5 2 3 2 5 5 2 5 2 5 3",
"output": "39"
},
{
"input": "100\n3 5 3 3 5 5 3 3 2 5 5 3 3 3 2 2 3 2 5 3 2 2 3 3 3 3 2 5 3 2 3 3 5 2 2 2 3 2 3 5 5 3 2 5 2 2 5 5 3 5 5 5 2 2 5 5 3 3 2 2 2 5 3 3 2 2 3 5 3 2 3 5 5 3 2 3 5 5 3 3 2 3 5 2 5 5 5 5 5 5 3 5 3 2 3 3 2 5 2 2",
"output": "42"
},
{
"input": "99\n4 4 4 5 4 4 5 5 4 4 5 5 5 4 5 4 5 5 5 4 4 5 5 5 5 4 5 5 5 4 4 5 5 4 5 4 4 4 5 5 5 5 4 4 5 4 4 5 4 4 4 4 5 5 5 4 5 4 5 5 5 5 5 4 5 4 5 4 4 4 4 5 5 5 4 5 5 4 4 5 5 5 4 5 4 4 5 5 4 5 5 5 5 4 5 5 4 4 4",
"output": "0"
},
{
"input": "100\n4 4 5 5 5 5 5 5 4 4 5 5 4 4 5 5 4 5 4 4 4 4 4 4 4 4 5 5 5 5 5 4 4 4 4 4 5 4 4 5 4 4 4 5 5 5 4 5 5 5 5 5 5 4 4 4 4 4 4 5 5 4 5 4 4 5 4 4 4 4 5 5 4 5 5 4 4 4 5 5 5 5 4 5 5 5 4 4 5 5 5 4 5 4 5 4 4 5 5 4",
"output": "1"
},
{
"input": "99\n2 2 2 5 2 2 2 2 2 4 4 5 5 2 2 4 2 5 2 2 2 5 2 2 5 5 5 4 5 5 4 4 2 2 5 2 2 2 2 5 5 2 2 4 4 4 2 2 2 5 2 4 4 2 4 2 4 2 5 4 2 2 5 2 4 4 4 2 5 2 2 5 4 2 2 5 5 5 2 4 5 4 5 5 4 4 4 5 4 5 4 5 4 2 5 2 2 2 4",
"output": "37"
},
{
"input": "100\n4 4 5 2 2 5 4 5 2 2 2 4 2 5 4 4 2 2 4 5 2 4 2 5 5 4 2 4 4 2 2 5 4 2 5 4 5 2 5 2 4 2 5 4 5 2 2 2 5 2 5 2 5 2 2 4 4 5 5 5 5 5 5 5 4 2 2 2 4 2 2 4 5 5 4 5 4 2 2 2 2 4 2 2 5 5 4 2 2 5 4 5 5 5 4 5 5 5 2 2",
"output": "31"
},
{
"input": "99\n5 3 4 4 5 4 4 4 3 5 4 3 3 4 3 5 5 5 5 4 3 3 5 3 4 5 3 5 4 4 3 5 5 4 4 4 4 3 5 3 3 5 5 5 5 5 4 3 4 4 3 5 5 3 3 4 4 4 5 4 4 5 4 4 4 4 5 5 4 3 3 4 3 5 3 3 3 3 4 4 4 4 3 4 5 4 4 5 5 5 3 4 5 3 4 5 4 3 3",
"output": "24"
},
{
"input": "100\n5 4 4 4 5 5 5 4 5 4 4 3 3 4 4 4 5 4 5 5 3 5 5 4 5 5 5 4 4 5 3 5 3 5 3 3 5 4 4 5 5 4 5 5 3 4 5 4 4 3 4 4 3 3 5 4 5 4 5 3 4 5 3 4 5 4 3 5 4 5 4 4 4 3 4 5 3 4 3 5 3 4 4 4 3 4 4 5 3 3 4 4 5 5 4 3 4 4 3 5",
"output": "19"
},
{
"input": "99\n2 2 5 2 5 3 4 2 3 5 4 3 4 2 5 3 2 2 4 2 4 4 5 4 4 5 2 5 5 3 2 3 2 2 3 4 5 3 5 2 5 4 4 5 4 2 2 3 2 3 3 3 4 4 3 2 2 4 4 2 5 3 5 3 5 4 4 4 5 4 5 2 2 5 4 4 4 3 3 2 5 2 5 2 3 2 5 2 2 5 5 3 4 5 3 4 4 4 4",
"output": "37"
},
{
"input": "2\n5 2",
"output": "1"
},
{
"input": "5\n2 2 2 2 2",
"output": "5"
},
{
"input": "100\n2 3 2 2 2 3 2 3 3 3 3 3 2 3 3 2 2 3 3 2 3 2 3 2 3 4 4 4 3 3 3 3 3 4 4 3 3 4 3 2 3 4 3 3 3 3 2 3 4 3 4 3 3 2 4 4 2 4 4 3 3 3 3 4 3 2 3 4 3 4 4 4 4 4 3 2 2 3 4 2 4 4 4 2 2 4 2 2 3 2 2 4 4 3 4 2 3 3 2 2",
"output": "61"
},
{
"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 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": "1"
},
{
"input": "100\n5 4 3 5 3 5 4 2 3 3 4 5 4 5 5 4 2 4 2 2 5 2 5 3 4 4 4 5 5 5 3 4 4 4 3 5 3 2 5 4 3 3 3 5 2 3 4 2 5 4 3 4 5 2 2 3 4 4 2 3 3 3 2 5 2 3 4 3 3 3 2 5 4 3 4 5 4 2 5 4 5 2 2 4 2 2 5 5 4 5 2 2 2 2 5 2 4 4 4 5",
"output": "35"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "20\n4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5",
"output": "1"
}
] | 1,672,784,841 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 77 | 0 | n=int(input())
grads=list(map(int,input().split()))
grads.sort()
cnt=0
sumi=sum(grads)
if n*5 ==sum(grads) or n*5-sum(grads)==1:
print(0)
else:
for i in range(len(grads)):
grads[i]=5
cnt += 1
if sum(grads)/n==4.5 :
print(cnt)
break
if n*5-sum(grads)<=1:
print(cnt)
break
| Title: Getting an A
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo.
Help Vasya — calculate the minimum amount of lab works Vasya has to redo.
Input Specification:
The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works.
Output Specification:
Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$.
Demo Input:
['3\n4 4 4\n', '4\n5 4 5 5\n', '4\n5 3 3 5\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$. | ```python
n=int(input())
grads=list(map(int,input().split()))
grads.sort()
cnt=0
sumi=sum(grads)
if n*5 ==sum(grads) or n*5-sum(grads)==1:
print(0)
else:
for i in range(len(grads)):
grads[i]=5
cnt += 1
if sum(grads)/n==4.5 :
print(cnt)
break
if n*5-sum(grads)<=1:
print(cnt)
break
``` | 0 |
|
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps. | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "1"
},
{
"input": "99125 26876 -21414 14176 17443",
"output": "1"
},
{
"input": "8066 7339 19155 -90534 -60666",
"output": "8"
},
{
"input": "100000 -100000 -100000 100000 100000",
"output": "2"
},
{
"input": "10 20 0 41 0",
"output": "2"
},
{
"input": "25 -64 -6 -56 64",
"output": "2"
},
{
"input": "125 455 450 439 721",
"output": "2"
},
{
"input": "5 6 3 7 2",
"output": "1"
},
{
"input": "24 130 14786 3147 2140",
"output": "271"
},
{
"input": "125 -363 176 93 330",
"output": "2"
},
{
"input": "1 14 30 30 14",
"output": "12"
},
{
"input": "25 96 13 7 2",
"output": "2"
},
{
"input": "4 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "1 3 4 2 5",
"output": "1"
},
{
"input": "1 -3 3 2 6",
"output": "3"
},
{
"input": "2 7 20 13 -5",
"output": "7"
},
{
"input": "1 1 1 1 4",
"output": "2"
},
{
"input": "249 -54242 -30537 -45023 -89682",
"output": "121"
},
{
"input": "4 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "97741 23818 78751 97583 26933",
"output": "1"
},
{
"input": "56767 -29030 51625 79823 -56297",
"output": "2"
},
{
"input": "98260 13729 74998 23701 9253",
"output": "1"
},
{
"input": "67377 -80131 -90254 -57320 14102",
"output": "1"
},
{
"input": "1 100000 100000 100000 -100000",
"output": "100000"
},
{
"input": "19312 19470 82059 58064 62231",
"output": "2"
},
{
"input": "67398 -68747 -79056 -34193 29400",
"output": "1"
},
{
"input": "91099 37184 -71137 75650 -3655",
"output": "1"
},
{
"input": "46456 -2621 -23623 -98302 -99305",
"output": "2"
},
{
"input": "100 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "1 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "8 0 0 0 32",
"output": "2"
},
{
"input": "100000 100000 1 -100000 0",
"output": "2"
}
] | 1,580,452,118 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 124 | 307,200 | r,x,y,a,b=map(int,input().split())
n=(((x-a)**2+(y-b)**2)**0.5)/(2*r)
if n==int(n):
print(int(n))
else:
print(int(n+1)) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
Input Specification:
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output Specification:
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
Demo Input:
['2 0 0 0 4\n', '1 1 1 4 4\n', '4 5 6 5 6\n']
Demo Output:
['1\n', '3\n', '0\n']
Note:
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
r,x,y,a,b=map(int,input().split())
n=(((x-a)**2+(y-b)**2)**0.5)/(2*r)
if n==int(n):
print(int(n))
else:
print(int(n+1))
``` | 3 |
|
121 | A | Lucky Sum | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem. | The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. | In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2 7\n",
"7 7\n"
] | [
"33\n",
"7\n"
] | In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: *next*(7) = 7 | 500 | [
{
"input": "2 7",
"output": "33"
},
{
"input": "7 7",
"output": "7"
},
{
"input": "1 9",
"output": "125"
},
{
"input": "4 7",
"output": "25"
},
{
"input": "12 47",
"output": "1593"
},
{
"input": "6 77",
"output": "4012"
},
{
"input": "1 100",
"output": "14247"
},
{
"input": "1000000000 1000000000",
"output": "4444444444"
},
{
"input": "77 77",
"output": "77"
},
{
"input": "69 788",
"output": "452195"
},
{
"input": "474 747",
"output": "202794"
},
{
"input": "4 77777",
"output": "4070145675"
},
{
"input": "1 1000000",
"output": "1394675359387"
},
{
"input": "47 744447",
"output": "381286992761"
},
{
"input": "47444 1000000000",
"output": "1394672348253941136"
},
{
"input": "48 854888",
"output": "749733199853"
},
{
"input": "854444 985555",
"output": "582719941728"
},
{
"input": "774744 774747",
"output": "3098985"
},
{
"input": "654 987654",
"output": "1339803940266"
},
{
"input": "477777 1000000000",
"output": "1394672167300009765"
},
{
"input": "77777 777777777",
"output": "407018021649898097"
},
{
"input": "963 85555574",
"output": "7526978888069560"
},
{
"input": "47 7444",
"output": "38125896"
},
{
"input": "1 1000000000",
"output": "1394672350065645019"
},
{
"input": "474 999888555",
"output": "1394177038954402791"
},
{
"input": "777 1000000000",
"output": "1394672350065239125"
},
{
"input": "7 777777774",
"output": "407018023386632646"
},
{
"input": "369 852",
"output": "606732"
},
{
"input": "47 47",
"output": "47"
},
{
"input": "747 748",
"output": "1521"
},
{
"input": "77777440 77777444",
"output": "388887220"
},
{
"input": "987545885 999875584",
"output": "54798666661186800"
},
{
"input": "2 777777776",
"output": "407018024942188226"
},
{
"input": "1 1",
"output": "4"
},
{
"input": "1 2",
"output": "8"
},
{
"input": "999999999 1000000000",
"output": "8888888888"
},
{
"input": "777777777 1000000000",
"output": "987654325123456789"
},
{
"input": "777777778 1000000000",
"output": "987654324345679012"
},
{
"input": "5 6",
"output": "14"
},
{
"input": "49 49",
"output": "74"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "3 4",
"output": "8"
}
] | 1,622,549,495 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | n,m=map(int,input().split())
a=m-n+1
if a%2==0:
c=a//2
print(4*c+7*c)
else:
c=a//2
print(4*c+7*c+7) | Title: Lucky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem.
Input Specification:
The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits.
Output Specification:
In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*).
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
Demo Input:
['2 7\n', '7 7\n']
Demo Output:
['33\n', '7\n']
Note:
In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33
In the second sample: *next*(7) = 7 | ```python
n,m=map(int,input().split())
a=m-n+1
if a%2==0:
c=a//2
print(4*c+7*c)
else:
c=a//2
print(4*c+7*c+7)
``` | 0 |
|
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob? | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then. | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "1 5",
"output": "4"
},
{
"input": "1 6",
"output": "5"
},
{
"input": "1 7",
"output": "5"
},
{
"input": "1 8",
"output": "6"
},
{
"input": "1 9",
"output": "6"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "2 4",
"output": "2"
},
{
"input": "2 5",
"output": "3"
},
{
"input": "2 6",
"output": "3"
},
{
"input": "2 7",
"output": "4"
},
{
"input": "2 8",
"output": "4"
},
{
"input": "2 9",
"output": "4"
},
{
"input": "2 10",
"output": "4"
},
{
"input": "3 3",
"output": "1"
},
{
"input": "3 4",
"output": "1"
},
{
"input": "3 5",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "3 7",
"output": "3"
},
{
"input": "3 8",
"output": "3"
},
{
"input": "3 9",
"output": "3"
},
{
"input": "3 10",
"output": "3"
},
{
"input": "4 4",
"output": "1"
},
{
"input": "4 5",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "4 7",
"output": "2"
},
{
"input": "4 8",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "4 10",
"output": "3"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "5 6",
"output": "1"
},
{
"input": "5 7",
"output": "1"
},
{
"input": "5 8",
"output": "2"
},
{
"input": "5 9",
"output": "2"
},
{
"input": "5 10",
"output": "2"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "6 7",
"output": "1"
},
{
"input": "6 8",
"output": "1"
},
{
"input": "6 9",
"output": "2"
},
{
"input": "6 10",
"output": "2"
},
{
"input": "7 7",
"output": "1"
},
{
"input": "7 8",
"output": "1"
},
{
"input": "7 9",
"output": "1"
},
{
"input": "7 10",
"output": "1"
},
{
"input": "8 8",
"output": "1"
},
{
"input": "8 9",
"output": "1"
},
{
"input": "8 10",
"output": "1"
},
{
"input": "9 9",
"output": "1"
},
{
"input": "9 10",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "10 10",
"output": "1"
},
{
"input": "1 2",
"output": "2"
}
] | 1,695,811,724 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 5,632,000 | a,b=map(int, input().split())
for i in range(1,100):
if a <= b:
a = a * 3*i
b = b * 2*i
else:
print(i)
break | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob?
Input Specification:
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Output Specification:
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
Demo Input:
['4 7\n', '4 9\n', '1 1\n']
Demo Output:
['2\n', '3\n', '1\n']
Note:
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then. | ```python
a,b=map(int, input().split())
for i in range(1,100):
if a <= b:
a = a * 3*i
b = b * 2*i
else:
print(i)
break
``` | 0 |
|
888 | D | Almost Identity Permutations | PROGRAMMING | 1,600 | [
"combinatorics",
"dp",
"math"
] | null | null | A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*k* indices *i* (1<=≤<=*i*<=≤<=*n*) such that *p**i*<==<=*i*.
Your task is to count the number of almost identity permutations for given numbers *n* and *k*. | The first line contains two integers *n* and *k* (4<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=4). | Print the number of almost identity permutations for given *n* and *k*. | [
"4 1\n",
"4 2\n",
"5 3\n",
"5 4\n"
] | [
"1\n",
"7\n",
"31\n",
"76\n"
] | none | 0 | [
{
"input": "4 1",
"output": "1"
},
{
"input": "4 2",
"output": "7"
},
{
"input": "5 3",
"output": "31"
},
{
"input": "5 4",
"output": "76"
},
{
"input": "200 1",
"output": "1"
},
{
"input": "200 2",
"output": "19901"
},
{
"input": "200 3",
"output": "2646701"
},
{
"input": "200 4",
"output": "584811251"
},
{
"input": "400 1",
"output": "1"
},
{
"input": "400 2",
"output": "79801"
},
{
"input": "400 3",
"output": "21253401"
},
{
"input": "400 4",
"output": "9477912501"
},
{
"input": "600 1",
"output": "1"
},
{
"input": "600 2",
"output": "179701"
},
{
"input": "600 3",
"output": "71820101"
},
{
"input": "600 4",
"output": "48187303751"
},
{
"input": "800 1",
"output": "1"
},
{
"input": "800 2",
"output": "319601"
},
{
"input": "800 3",
"output": "170346801"
},
{
"input": "800 4",
"output": "152620985001"
},
{
"input": "1000 1",
"output": "1"
},
{
"input": "1000 2",
"output": "499501"
},
{
"input": "1000 3",
"output": "332833501"
},
{
"input": "1000 4",
"output": "373086956251"
},
{
"input": "4 4",
"output": "24"
}
] | 1,590,146,261 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 156 | 0 | import sys
import math
def derange(k):
ans=math.factorial(k)
z=-1
mult=1
for i in range(1,k+1):
mult += z * (1/(math.factorial(i)))
z *= -1
ans=ans*mult
#print(ans,'ans')
return int(ans)
def com(n,k):
if k==0:
return 1
if k==1:
return n
if k==2:
return n*(n-1)//2
if k==3:
return n*(n-1)*(n-2)//6
return n*(n-1)*(n-2)*(n-3)//24
n,k=map(int,sys.stdin.readline().split())
ans=0
for i in range(k+1):
x = com(n,i)*derange(i)
ans += x
print(ans) | Title: Almost Identity Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation *p* of size *n* is an array such that every integer from 1 to *n* occurs exactly once in this array.
Let's call a permutation an almost identity permutation iff there exist at least *n*<=-<=*k* indices *i* (1<=≤<=*i*<=≤<=*n*) such that *p**i*<==<=*i*.
Your task is to count the number of almost identity permutations for given numbers *n* and *k*.
Input Specification:
The first line contains two integers *n* and *k* (4<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=4).
Output Specification:
Print the number of almost identity permutations for given *n* and *k*.
Demo Input:
['4 1\n', '4 2\n', '5 3\n', '5 4\n']
Demo Output:
['1\n', '7\n', '31\n', '76\n']
Note:
none | ```python
import sys
import math
def derange(k):
ans=math.factorial(k)
z=-1
mult=1
for i in range(1,k+1):
mult += z * (1/(math.factorial(i)))
z *= -1
ans=ans*mult
#print(ans,'ans')
return int(ans)
def com(n,k):
if k==0:
return 1
if k==1:
return n
if k==2:
return n*(n-1)//2
if k==3:
return n*(n-1)*(n-2)//6
return n*(n-1)*(n-2)*(n-3)//24
n,k=map(int,sys.stdin.readline().split())
ans=0
for i in range(k+1):
x = com(n,i)*derange(i)
ans += x
print(ans)
``` | 3 |
|
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,672,159,113 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | word = str(input())
length = len(word)
upper_count = 0
lower_count = 0
for letter in word:
if letter.isupper():
upper_count += 1
for letter in word:
if letter.islower():
lower_count += 1
if upper_count>lower_count:
print(word.upper())
else:
print(word.lower()) | 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
word = str(input())
length = len(word)
upper_count = 0
lower_count = 0
for letter in word:
if letter.isupper():
upper_count += 1
for letter in word:
if letter.islower():
lower_count += 1
if upper_count>lower_count:
print(word.upper())
else:
print(word.lower())
``` | 3.977 |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
},
{
"input": "693\n970",
"output": "NO"
},
{
"input": "981\n1",
"output": "YES"
},
{
"input": "352\n276",
"output": "YES"
},
{
"input": "164\n691",
"output": "YES"
},
{
"input": "110036\n43",
"output": "YES"
},
{
"input": "100\n1000",
"output": "NO"
},
{
"input": "1000000000\n1000000000",
"output": "YES"
},
{
"input": "999999999\n999999999",
"output": "YES"
},
{
"input": "6\n4",
"output": "NO"
},
{
"input": "123456\n876543",
"output": "YES"
},
{
"input": "1234567\n9876543",
"output": "NO"
},
{
"input": "1111111\n1119111",
"output": "NO"
},
{
"input": "10502405\n40403403",
"output": "YES"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "5\n4",
"output": "YES"
},
{
"input": "1\n6",
"output": "YES"
},
{
"input": "40\n17",
"output": "NO"
},
{
"input": "35\n81",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "2081\n7450",
"output": "NO"
},
{
"input": "84355694\n373629503",
"output": "NO"
},
{
"input": "885992048\n510468672",
"output": "NO"
},
{
"input": "540144752\n647307841",
"output": "NO"
},
{
"input": "341781108\n784147010",
"output": "NO"
},
{
"input": "960440938\n572334653",
"output": "NO"
},
{
"input": "657414510\n768771903",
"output": "NO"
},
{
"input": "501871728\n725074574",
"output": "NO"
},
{
"input": "968\n851",
"output": "YES"
},
{
"input": "943\n939",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "611\n41",
"output": "YES"
},
{
"input": "737\n289",
"output": "NO"
},
{
"input": "168\n571",
"output": "YES"
},
{
"input": "868\n463",
"output": "YES"
},
{
"input": "815732007\n913882008",
"output": "NO"
},
{
"input": "459039901\n453033850",
"output": "NO"
},
{
"input": "975305404\n484601256",
"output": "NO"
}
] | 1,643,021,935 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 92 | 0 | n1 = input()
n2 = input()
withoutz1 = ""
withoutz2 = ""
for cur in n1:
if cur != "0":
withoutz1 += cur
for cur in n2:
if cur != "0":
withoutz2 += cur
res = int(n1)+int(n2)
r = ""
for cur in str(res):
if cur != "0":
r += cur
print("YES" if int(withoutz1)+int(withoutz2)==int(r) else "NO") | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
Input Specification:
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
Output Specification:
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
Demo Input:
['101\n102\n', '105\n106\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
n1 = input()
n2 = input()
withoutz1 = ""
withoutz2 = ""
for cur in n1:
if cur != "0":
withoutz1 += cur
for cur in n2:
if cur != "0":
withoutz2 += cur
res = int(n1)+int(n2)
r = ""
for cur in str(res):
if cur != "0":
r += cur
print("YES" if int(withoutz1)+int(withoutz2)==int(r) else "NO")
``` | 3.977 |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1",
"output": "YES"
},
{
"input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1",
"output": "NO"
},
{
"input": "10 3\n8 3 5 4 2 3 2 2 1",
"output": "NO"
},
{
"input": "10 9\n8 3 5 4 2 3 2 2 1",
"output": "YES"
},
{
"input": "3 2\n1 1",
"output": "YES"
},
{
"input": "3 2\n2 1",
"output": "NO"
},
{
"input": "4 2\n2 1 1",
"output": "NO"
},
{
"input": "4 4\n2 2 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 1 1",
"output": "YES"
},
{
"input": "3 3\n2 1",
"output": "YES"
},
{
"input": "4 4\n1 1 1",
"output": "YES"
},
{
"input": "8 8\n1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5 5\n1 1 1 1",
"output": "YES"
}
] | 1,665,452,823 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | '''
8 4
1 2 1 2 1 2 1
'''
n, k = map(int, input().split())
nums = list(map(int, input().split()))
def dfs(i, k):
if i == k:
return True
if i > k:
return False
return dfs(i + nums[i], k)
print(dfs(0, k - 1))
| Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
Input Specification:
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
Output Specification:
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
Demo Input:
['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | ```python
'''
8 4
1 2 1 2 1 2 1
'''
n, k = map(int, input().split())
nums = list(map(int, input().split()))
def dfs(i, k):
if i == k:
return True
if i > k:
return False
return dfs(i + nums[i], k)
print(dfs(0, k - 1))
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,652,409,952 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | inp2 = input()
h = inp2.index("h")
e = inp2.index("e")
l = inp2.index("l")
o = inp2.index("o")
print(h,e,l,o)
if h < e < l < o:
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
inp2 = input()
h = inp2.index("h")
e = inp2.index("e")
l = inp2.index("l")
o = inp2.index("o")
print(h,e,l,o)
if h < e < l < o:
print("YES")
else:
print("NO")
``` | 0 |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,681,461,803 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 77 | 0 | a,b = map(int,input().split())
l = min(a,b)
p = (max(a,b)-l)//2
print(l,p)
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
a,b = map(int,input().split())
l = min(a,b)
p = (max(a,b)-l)//2
print(l,p)
``` | 3 |
|
156 | D | Clues | PROGRAMMING | 2,500 | [
"combinatorics",
"graphs"
] | null | null | As Sherlock Holmes was investigating another crime, he found a certain number of clues. Also, he has already found direct links between some of those clues. The direct links between the clues are mutual. That is, the direct link between clues *A* and *B* and the direct link between clues *B* and *A* is the same thing. No more than one direct link can exist between two clues.
Of course Sherlock is able to find direct links between all clues. But it will take too much time and the criminals can use this extra time to hide. To solve the crime, Sherlock needs each clue to be linked to all other clues (maybe not directly, via some other clues). Clues *A* and *B* are considered linked either if there is a direct link between them or if there is a direct link between *A* and some other clue *C* which is linked to *B*.
Sherlock Holmes counted the minimum number of additional direct links that he needs to find to solve the crime. As it turns out, it equals *T*.
Please count the number of different ways to find exactly *T* direct links between the clues so that the crime is solved in the end. Two ways to find direct links are considered different if there exist two clues which have a direct link in one way and do not have a direct link in the other way.
As the number of different ways can turn out rather big, print it modulo *k*. | The first line contains three space-separated integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of clues, the number of direct clue links that Holmes has already found and the divisor for the modulo operation.
Each of next *m* lines contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*), that represent a direct link between clues. It is guaranteed that any two clues are linked by no more than one direct link. Note that the direct links between the clues are mutual. | Print the single number — the answer to the problem modulo *k*. | [
"2 0 1000000000\n",
"3 0 100\n",
"4 1 1000000000\n1 4\n"
] | [
"1\n",
"3\n",
"8\n"
] | The first sample only has two clues and Sherlock hasn't found any direct link between them yet. The only way to solve the crime is to find the link.
The second sample has three clues and Sherlock hasn't found any direct links between them. He has to find two of three possible direct links between clues to solve the crime — there are 3 ways to do it.
The third sample has four clues and the detective has already found one direct link between the first and the fourth clue. There are 8 ways to find two remaining clues to solve the crime. | 2,500 | [
{
"input": "2 0 1000000000",
"output": "1"
},
{
"input": "3 0 100",
"output": "3"
},
{
"input": "4 1 1000000000\n1 4",
"output": "8"
},
{
"input": "6 4 100000\n1 4\n4 6\n6 1\n2 5",
"output": "36"
},
{
"input": "10 0 123456789",
"output": "100000000"
},
{
"input": "10 5 1000000000\n1 2\n4 3\n5 6\n8 7\n10 9",
"output": "32000"
},
{
"input": "8 4 17\n1 2\n2 3\n3 4\n4 1",
"output": "8"
},
{
"input": "9 6 342597160\n1 2\n3 4\n4 5\n6 7\n7 8\n8 9",
"output": "216"
},
{
"input": "1 0 1",
"output": "0"
},
{
"input": "15 10 1\n1 2\n4 5\n6 3\n11 8\n8 5\n5 9\n9 1\n11 12\n12 1\n2 8",
"output": "0"
},
{
"input": "8 8 999999937\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n8 7",
"output": "1"
},
{
"input": "100000 0 1000000000",
"output": "0"
},
{
"input": "100000 0 1",
"output": "0"
},
{
"input": "9 11 498920381\n2 8\n5 4\n1 8\n8 3\n4 9\n3 6\n8 9\n1 7\n5 1\n5 6\n9 6",
"output": "1"
},
{
"input": "2 0 753780649",
"output": "1"
},
{
"input": "1 0 997185958",
"output": "1"
},
{
"input": "10 36 279447540\n10 7\n10 8\n1 8\n1 5\n4 5\n9 5\n3 9\n7 3\n10 4\n8 9\n2 10\n6 2\n4 8\n10 3\n1 4\n10 1\n10 6\n8 3\n3 6\n9 7\n10 5\n6 9\n3 1\n8 6\n4 9\n5 3\n9 10\n7 2\n2 4\n7 4\n5 6\n5 8\n7 5\n5 2\n6 7\n1 9",
"output": "1"
},
{
"input": "7 7 302838679\n5 3\n4 1\n5 4\n6 5\n1 6\n3 2\n6 4",
"output": "6"
},
{
"input": "6 1 310732484\n4 2",
"output": "432"
},
{
"input": "10 7 587143295\n1 10\n7 1\n1 8\n7 10\n8 10\n4 8\n6 8",
"output": "6000"
},
{
"input": "3 3 975373207\n1 2\n1 3\n3 2",
"output": "1"
},
{
"input": "9 33 321578376\n9 5\n6 3\n8 4\n4 1\n3 5\n2 6\n8 2\n7 6\n7 9\n8 6\n4 5\n1 6\n1 2\n5 6\n9 4\n7 8\n3 9\n9 6\n4 7\n7 2\n1 8\n4 6\n8 3\n3 7\n8 9\n5 7\n3 4\n7 1\n9 2\n5 1\n2 5\n9 1\n3 2",
"output": "1"
},
{
"input": "5 10 93196990\n1 5\n1 4\n4 2\n1 3\n3 4\n1 2\n5 2\n5 4\n5 3\n2 3",
"output": "1"
},
{
"input": "1 0 773734495",
"output": "1"
},
{
"input": "2 1 719418546\n1 2",
"output": "1"
},
{
"input": "3 2 21502109\n3 2\n1 2",
"output": "1"
},
{
"input": "9 35 480175322\n6 3\n8 6\n7 5\n7 9\n3 4\n2 8\n5 3\n4 5\n4 6\n7 1\n7 6\n2 5\n8 3\n6 9\n8 4\n8 5\n6 1\n8 1\n3 2\n5 1\n8 9\n3 1\n8 7\n5 6\n5 9\n4 9\n7 4\n2 7\n3 9\n2 4\n7 3\n9 1\n2 9\n1 4\n1 2",
"output": "1"
},
{
"input": "5 7 729985252\n2 3\n3 1\n2 5\n1 5\n1 2\n1 4\n4 3",
"output": "1"
},
{
"input": "2 1 819865995\n2 1",
"output": "1"
},
{
"input": "10 0 766953983",
"output": "100000000"
},
{
"input": "2 1 855341703\n2 1",
"output": "1"
},
{
"input": "10 30 407595309\n3 6\n6 10\n6 7\n7 10\n7 8\n3 10\n3 4\n1 4\n9 10\n8 4\n3 7\n5 1\n2 4\n6 2\n8 9\n10 5\n7 5\n10 4\n5 8\n8 2\n10 2\n1 6\n4 7\n2 3\n5 6\n8 10\n3 5\n1 8\n9 7\n1 9",
"output": "1"
},
{
"input": "1 0 21080115",
"output": "1"
},
{
"input": "57 28 776442742\n31 10\n25 28\n51 45\n14 40\n21 52\n53 51\n52 53\n4 6\n51 35\n53 15\n17 16\n40 44\n37 51\n33 43\n55 40\n42 16\n30 8\n19 45\n7 27\n31 8\n49 8\n43 44\n45 3\n16 22\n32 36\n52 36\n5 26\n2 23",
"output": "135540294"
},
{
"input": "30 70 288262020\n27 18\n5 19\n23 17\n16 17\n29 17\n1 22\n23 5\n10 13\n22 26\n14 3\n8 3\n29 9\n9 1\n3 9\n16 4\n9 22\n10 22\n20 1\n3 7\n23 19\n26 8\n24 1\n5 7\n28 29\n20 11\n16 12\n6 9\n24 29\n30 4\n5 26\n18 21\n5 21\n30 6\n12 13\n16 23\n28 14\n30 1\n7 27\n7 19\n27 17\n5 30\n30 27\n28 30\n12 28\n27 9\n30 26\n20 18\n21 16\n8 30\n4 26\n13 22\n2 14\n12 30\n4 2\n6 12\n29 25\n19 29\n14 15\n3 23\n10 28\n7 1\n21 10\n4 12\n1 14\n7 21\n21 8\n17 26\n7 6\n26 29\n9 8",
"output": "1"
},
{
"input": "99 12 832839308\n66 23\n36 5\n16 57\n70 62\n94 96\n63 33\n99 23\n63 10\n6 85\n73 23\n69 46\n72 95",
"output": "71450536"
},
{
"input": "30 18 918975816\n30 18\n23 1\n21 14\n14 8\n18 9\n23 29\n3 23\n29 19\n18 4\n27 19\n30 2\n9 10\n9 28\n16 15\n10 6\n18 12\n23 9\n19 14",
"output": "782410104"
},
{
"input": "83 33 367711297\n14 74\n26 22\n55 19\n8 70\n6 42\n53 49\n54 56\n52 17\n62 44\n78 61\n76 4\n78 30\n51 2\n31 42\n33 67\n45 41\n64 62\n15 25\n33 35\n37 20\n38 65\n65 83\n61 14\n20 67\n62 47\n7 34\n78 41\n38 83\n26 69\n54 58\n11 62\n30 55\n15 74",
"output": "131377693"
},
{
"input": "24 68 862907549\n6 9\n16 22\n11 23\n12 17\n18 2\n15 5\n5 22\n16 4\n21 9\n7 11\n19 16\n9 13\n21 20\n5 24\n7 12\n17 1\n24 21\n23 7\n16 17\n16 18\n10 13\n18 7\n8 21\n13 5\n10 18\n4 11\n21 6\n15 13\n2 1\n20 16\n11 16\n22 19\n2 4\n21 1\n6 18\n24 12\n21 19\n6 14\n22 24\n11 20\n2 19\n1 11\n24 18\n14 8\n10 24\n5 3\n11 3\n17 4\n4 20\n2 10\n12 11\n24 7\n23 16\n2 3\n19 24\n22 1\n22 4\n4 6\n3 4\n11 13\n6 5\n18 23\n4 23\n22 13\n20 5\n2 5\n2 11\n9 5",
"output": "1"
},
{
"input": "86 23 608266393\n62 78\n44 84\n42 37\n20 24\n40 36\n41 76\n14 38\n80 72\n39 52\n31 58\n71 17\n81 6\n32 65\n11 69\n43 86\n85 59\n28 77\n78 64\n15 19\n36 39\n53 49\n48 75\n33 85",
"output": "235915236"
},
{
"input": "47 51 283106191\n18 14\n30 26\n24 2\n18 41\n35 31\n16 24\n29 39\n6 12\n17 21\n7 19\n36 16\n27 39\n28 34\n22 35\n28 43\n40 5\n2 26\n18 16\n27 13\n21 6\n19 5\n35 30\n13 31\n7 10\n25 7\n44 42\n45 1\n35 47\n11 28\n47 46\n18 15\n27 16\n24 41\n10 8\n25 41\n4 40\n5 11\n24 6\n10 17\n41 38\n47 28\n8 29\n25 24\n35 37\n44 17\n24 47\n8 32\n33 11\n26 28\n23 9\n5 9",
"output": "189974"
},
{
"input": "67 2 818380264\n4 52\n15 44",
"output": "517849052"
},
{
"input": "10 45 220178113\n9 1\n8 1\n5 8\n1 5\n7 8\n6 7\n7 9\n6 2\n3 2\n1 4\n8 3\n8 9\n3 6\n4 5\n5 3\n10 4\n3 9\n9 6\n5 9\n2 9\n10 7\n1 10\n9 4\n3 10\n2 5\n7 1\n6 10\n6 5\n8 6\n8 4\n8 10\n1 6\n4 2\n9 10\n2 10\n7 3\n6 4\n7 5\n1 2\n4 3\n10 5\n4 7\n3 1\n7 2\n8 2",
"output": "1"
},
{
"input": "588 32 634894588\n535 26\n562 406\n70 368\n357 513\n108 361\n515 5\n159 56\n522 81\n169 229\n312 252\n492 43\n476 405\n524 555\n537 169\n142 149\n586 112\n7 159\n76 370\n295 376\n33 455\n278 225\n377 88\n526 308\n517 303\n300 576\n230 493\n588 525\n177 312\n356 215\n515 34\n196 236\n323 9",
"output": "478655040"
},
{
"input": "3 2 11\n1 2\n2 3",
"output": "1"
},
{
"input": "2 1 1000\n1 2",
"output": "1"
},
{
"input": "1 0 10000",
"output": "1"
},
{
"input": "5 4 100000\n1 2\n2 3\n3 4\n4 5",
"output": "1"
},
{
"input": "2 1 100000\n1 2",
"output": "1"
},
{
"input": "1 0 10",
"output": "1"
},
{
"input": "3 3 100\n1 2\n2 3\n3 1",
"output": "1"
},
{
"input": "2 1 100\n1 2",
"output": "1"
},
{
"input": "3 2 42\n1 2\n2 3",
"output": "1"
}
] | 1,665,218,479 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,m,p,k,fa[N],s[N];
int read() {
int x=0,f=1; char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-48;
return x*f;
}
int get(int x) {
return fa[x]==x?x:fa[x]=get(fa[x]);
}
int main() {
n=read(); m=read(); p=read();
for(int i=1;i<=n;i++) fa[i]=i;
while(m--) {
int x=read(),y=read();
if(get(x)!=get(y)) fa[get(x)]=get(y);
}
for(int i=1;i<=n;i++) {
if(fa[i]==i) k++;
s[get(i)]++;
}
long long ans=1;
for(int i=1;i<=n;i++) if(s[i]) ans=ans*s[i]%p;
for(int i=1;i<=k-2;i++) ans=ans*n%p;
printf("%d\n",ans);
return 0;
} | Title: Clues
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As Sherlock Holmes was investigating another crime, he found a certain number of clues. Also, he has already found direct links between some of those clues. The direct links between the clues are mutual. That is, the direct link between clues *A* and *B* and the direct link between clues *B* and *A* is the same thing. No more than one direct link can exist between two clues.
Of course Sherlock is able to find direct links between all clues. But it will take too much time and the criminals can use this extra time to hide. To solve the crime, Sherlock needs each clue to be linked to all other clues (maybe not directly, via some other clues). Clues *A* and *B* are considered linked either if there is a direct link between them or if there is a direct link between *A* and some other clue *C* which is linked to *B*.
Sherlock Holmes counted the minimum number of additional direct links that he needs to find to solve the crime. As it turns out, it equals *T*.
Please count the number of different ways to find exactly *T* direct links between the clues so that the crime is solved in the end. Two ways to find direct links are considered different if there exist two clues which have a direct link in one way and do not have a direct link in the other way.
As the number of different ways can turn out rather big, print it modulo *k*.
Input Specification:
The first line contains three space-separated integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of clues, the number of direct clue links that Holmes has already found and the divisor for the modulo operation.
Each of next *m* lines contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*), that represent a direct link between clues. It is guaranteed that any two clues are linked by no more than one direct link. Note that the direct links between the clues are mutual.
Output Specification:
Print the single number — the answer to the problem modulo *k*.
Demo Input:
['2 0 1000000000\n', '3 0 100\n', '4 1 1000000000\n1 4\n']
Demo Output:
['1\n', '3\n', '8\n']
Note:
The first sample only has two clues and Sherlock hasn't found any direct link between them yet. The only way to solve the crime is to find the link.
The second sample has three clues and Sherlock hasn't found any direct links between them. He has to find two of three possible direct links between clues to solve the crime — there are 3 ways to do it.
The third sample has four clues and the detective has already found one direct link between the first and the fourth clue. There are 8 ways to find two remaining clues to solve the crime. | ```python
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,m,p,k,fa[N],s[N];
int read() {
int x=0,f=1; char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-48;
return x*f;
}
int get(int x) {
return fa[x]==x?x:fa[x]=get(fa[x]);
}
int main() {
n=read(); m=read(); p=read();
for(int i=1;i<=n;i++) fa[i]=i;
while(m--) {
int x=read(),y=read();
if(get(x)!=get(y)) fa[get(x)]=get(y);
}
for(int i=1;i<=n;i++) {
if(fa[i]==i) k++;
s[get(i)]++;
}
long long ans=1;
for(int i=1;i<=n;i++) if(s[i]) ans=ans*s[i]%p;
for(int i=1;i<=k-2;i++) ans=ans*n%p;
printf("%d\n",ans);
return 0;
}
``` | -1 |
|
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo"
},
{
"input": "805",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1000",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1",
"output": "O"
},
{
"input": "2",
"output": "OO"
},
{
"input": "3",
"output": "OOO"
},
{
"input": "5",
"output": "OOOoO"
},
{
"input": "17",
"output": "OOOoOooOooooOoooo"
},
{
"input": "49",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo"
},
{
"input": "256",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo"
},
{
"input": "512",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "933",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "61",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo"
},
{
"input": "781",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "999",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
}
] | 1,665,831,368 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 46 | 0 | # Το σίδερο όσο το χτυπάς τόσο γίνεται ατσάλι
"""
1. Read carefully, understand the problem & its output.
2. Think about the solution using pen & paper.
3. Code the solution.
4. Test with edge cases: 0 len, empty str, identical elements.
5. Debug if needed and iterate process.
"""
n = int(input())
_set = set()
a, b = 1, 1
while a <= n:
_set.add(a)
a, b = b, a+b
name = ''
for i in range(n):
if i+1 in _set:
name += 'O'
else:
name += 'o'
print(name)
| Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
Input Specification:
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
Print Eleven's new name on the first and only line of output.
Demo Input:
['8\n', '15\n']
Demo Output:
['OOOoOooO\n', 'OOOoOooOooooOoo\n']
Note:
none | ```python
# Το σίδερο όσο το χτυπάς τόσο γίνεται ατσάλι
"""
1. Read carefully, understand the problem & its output.
2. Think about the solution using pen & paper.
3. Code the solution.
4. Test with edge cases: 0 len, empty str, identical elements.
5. Debug if needed and iterate process.
"""
n = int(input())
_set = set()
a, b = 1, 1
while a <= n:
_set.add(a)
a, b = b, a+b
name = ''
for i in range(n):
if i+1 in _set:
name += 'O'
else:
name += 'o'
print(name)
``` | 3 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,697,014,942 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | t1 = int(input())
for j in range(t1):
ch=input()
l=len(ch)
if l>10:
print(ch[0]+str(l-2)+ch[-1])
else:
print(ch)
##
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
t1 = int(input())
for j in range(t1):
ch=input()
l=len(ch)
if l>10:
print(ch[0]+str(l-2)+ch[-1])
else:
print(ch)
##
``` | 3.977 |
804 | A | Find Amir | PROGRAMMING | 1,000 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* and *j* costs and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools. | Print single integer: the minimum cost of tickets needed to visit all schools. | [
"2\n",
"10\n"
] | [
"0\n",
"4\n"
] | In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "2",
"output": "0"
},
{
"input": "10",
"output": "4"
},
{
"input": "43670",
"output": "21834"
},
{
"input": "4217",
"output": "2108"
},
{
"input": "17879",
"output": "8939"
},
{
"input": "31809",
"output": "15904"
},
{
"input": "40873",
"output": "20436"
},
{
"input": "77859",
"output": "38929"
},
{
"input": "53022",
"output": "26510"
},
{
"input": "79227",
"output": "39613"
},
{
"input": "100000",
"output": "49999"
},
{
"input": "82801",
"output": "41400"
},
{
"input": "5188",
"output": "2593"
},
{
"input": "86539",
"output": "43269"
},
{
"input": "12802",
"output": "6400"
},
{
"input": "20289",
"output": "10144"
},
{
"input": "32866",
"output": "16432"
},
{
"input": "33377",
"output": "16688"
},
{
"input": "31775",
"output": "15887"
},
{
"input": "60397",
"output": "30198"
},
{
"input": "100000",
"output": "49999"
},
{
"input": "99999",
"output": "49999"
},
{
"input": "99998",
"output": "49998"
},
{
"input": "99997",
"output": "49998"
},
{
"input": "99996",
"output": "49997"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "1"
}
] | 1,646,200,092 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 62 | 0 | n=int(input())
n-=1
print(n//2) | Title: Find Amir
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* and *j* costs and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools.
Output Specification:
Print single integer: the minimum cost of tickets needed to visit all schools.
Demo Input:
['2\n', '10\n']
Demo Output:
['0\n', '4\n']
Note:
In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n=int(input())
n-=1
print(n//2)
``` | 3 |
|
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers. | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;",
"output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server"
},
{
"input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;",
"output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm"
},
{
"input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;",
"output": "zygoumbmx 185.32.99.2; #ervbfot"
},
{
"input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;",
"output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y"
},
{
"input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;",
"output": "zbtjzzue 203.115.124.110; #tdwmshz"
},
{
"input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;",
"output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t"
},
{
"input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;",
"output": "command 11.1.1.1; #get"
},
{
"input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;",
"output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn"
},
{
"input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;",
"output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica"
},
{
"input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;",
"output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica"
},
{
"input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;",
"output": "block 255.255.255.255; #server"
},
{
"input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;",
"output": "block 22.222.30.10; #alp"
}
] | 1,686,032,023 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,867,200 | # Read input
n, m = map(int, input().split())
# Create a dictionary to store IP to name mappings
ip_to_name = {}
# Read server information and populate the dictionary
for _ in range(n):
name, ip = input().split()
ip_to_name[ip] = name
# Process the commands and add comments
for _ in range(m):
command, ip = input().split()
name = ip_to_name[ip]
print(f"{command} {ip}; #{name}")
| Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
Input Specification:
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Output Specification:
Print *m* lines, the commands in the configuration file after Dustin did his task.
Demo Input:
['2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n', '3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n']
Demo Output:
['block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n', 'redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n']
Note:
none | ```python
# Read input
n, m = map(int, input().split())
# Create a dictionary to store IP to name mappings
ip_to_name = {}
# Read server information and populate the dictionary
for _ in range(n):
name, ip = input().split()
ip_to_name[ip] = name
# Process the commands and add comments
for _ in range(m):
command, ip = input().split()
name = ip_to_name[ip]
print(f"{command} {ip}; #{name}")
``` | -1 |
|
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
},
{
"input": "5\n7 36 53 81 100",
"output": "4"
},
{
"input": "5\n100 81 53 36 7",
"output": "4"
},
{
"input": "10\n8 6 3 4 9 10 7 7 1 3",
"output": "5"
},
{
"input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862",
"output": "6"
},
{
"input": "10\n1 3 3 4 6 7 7 8 9 10",
"output": "7"
},
{
"input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137",
"output": "9"
},
{
"input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198",
"output": "5"
},
{
"input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101",
"output": "5"
},
{
"input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498",
"output": "7"
},
{
"input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679",
"output": "9"
},
{
"input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992",
"output": "57"
},
{
"input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83",
"output": "4"
},
{
"input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901",
"output": "57"
},
{
"input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100",
"output": "99"
},
{
"input": "2\n0 10000",
"output": "1"
},
{
"input": "2\n5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n10 10",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
}
] | 1,676,386,899 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 92 | 0 | n=int(input())
h=input().split()
mx=int(h[0])
mn=int(h[0])
kol=0
for i in h:
if int(i)>mx:
mx=int(i)
kol+=1
if int(i)<mn:
mn=int(i)
kol+=1
print(kol)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Output Specification:
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
Demo Input:
['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | ```python
n=int(input())
h=input().split()
mx=int(h[0])
mn=int(h[0])
kol=0
for i in h:
if int(i)>mx:
mx=int(i)
kol+=1
if int(i)<mn:
mn=int(i)
kol+=1
print(kol)
``` | 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,512,549,015 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 11,161,600 | n=int(input())
k=n
line=input().split()
line = [int(i) for i in line]
c=0
d=0
running=True
while running:
c=sum(line)
d=d+sum(line)
line.remove(min(line))
n=n-1
if n>1:
running=True
else:
running=False
break
if n==(k-1):
d=d+c
else:
d=d
c=0
print(d)
| 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())
k=n
line=input().split()
line = [int(i) for i in line]
c=0
d=0
running=True
while running:
c=sum(line)
d=d+sum(line)
line.remove(min(line))
n=n-1
if n>1:
running=True
else:
running=False
break
if n==(k-1):
d=d+c
else:
d=d
c=0
print(d)
``` | 0 |
|
900 | B | Position in Fraction | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. | The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=<<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9). | Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. | [
"1 2 0\n",
"2 3 7\n"
] | [
"2",
"-1"
] | The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/130ba579a8276fc53a1917606eee9db58817f28d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. There is no digit 7 in decimal notation of the fraction. | 1,000 | [
{
"input": "1 2 0",
"output": "2"
},
{
"input": "2 3 7",
"output": "-1"
},
{
"input": "1 100000 1",
"output": "5"
},
{
"input": "1 7 7",
"output": "6"
},
{
"input": "99999 100000 8",
"output": "-1"
},
{
"input": "44102 73848 2",
"output": "132"
},
{
"input": "7 31 3",
"output": "15"
},
{
"input": "8880 81608 9",
"output": "161"
},
{
"input": "4942 62768 5",
"output": "122"
},
{
"input": "69168 84860 4",
"output": "107"
},
{
"input": "971 1883 3",
"output": "130"
},
{
"input": "1636 3269 6",
"output": "150"
},
{
"input": "6873 7769 3",
"output": "163"
},
{
"input": "13805 15538 3",
"output": "164"
},
{
"input": "10958 21926 3",
"output": "117"
},
{
"input": "8 51 0",
"output": "10"
},
{
"input": "1 10 1",
"output": "1"
},
{
"input": "1 9 0",
"output": "-1"
},
{
"input": "53 101 6",
"output": "-1"
},
{
"input": "1 10001 9",
"output": "5"
},
{
"input": "25102 31579 2",
"output": "174"
},
{
"input": "38790 39359 0",
"output": "212"
},
{
"input": "47117 78718 0",
"output": "213"
},
{
"input": "1 57 0",
"output": "1"
},
{
"input": "1 3 0",
"output": "-1"
},
{
"input": "1 100 0",
"output": "1"
},
{
"input": "2 3 0",
"output": "-1"
},
{
"input": "99971 99989 0",
"output": "9"
},
{
"input": "567 1580 0",
"output": "6"
},
{
"input": "45 97 0",
"output": "39"
},
{
"input": "35 111 4",
"output": "-1"
},
{
"input": "1 2 5",
"output": "1"
},
{
"input": "1 7 0",
"output": "-1"
}
] | 1,516,731,950 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 77 | 6,041,600 | from decimal import *
getcontext().prec = 2048
getcontext().rounding = ROUND_DOWN
num, denom, target = [int(x) for x in input().split()]
a = Decimal(num)/Decimal(denom)
a = str(a)
a = a[a.find('.') : ]
if len(a) < 2047:
a = a + '0'
print(a.find(str(target)))
| Title: Position in Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
Input Specification:
The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=<<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9).
Output Specification:
Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Demo Input:
['1 2 0\n', '2 3 7\n']
Demo Output:
['2', '-1']
Note:
The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/130ba579a8276fc53a1917606eee9db58817f28d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. There is no digit 7 in decimal notation of the fraction. | ```python
from decimal import *
getcontext().prec = 2048
getcontext().rounding = ROUND_DOWN
num, denom, target = [int(x) for x in input().split()]
a = Decimal(num)/Decimal(denom)
a = str(a)
a = a[a.find('.') : ]
if len(a) < 2047:
a = a + '0'
print(a.find(str(target)))
``` | 3 |
|
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning. | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100. | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": "YES"
},
{
"input": "ONDOL\nJNPB\nONLNJBODP",
"output": "YES"
},
{
"input": "Y\nW\nYW",
"output": "YES"
},
{
"input": "OI\nM\nIMO",
"output": "YES"
},
{
"input": "VFQRWWWACX\nGHZJPOQUSXRAQDGOGMR\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF",
"output": "YES"
},
{
"input": "JUTCN\nPIGMZOPMEUFADQBW\nNWQGZMAIPUPOMCDUB",
"output": "NO"
},
{
"input": "Z\nO\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH",
"output": "NO"
},
{
"input": "IQ\nOQ\nQOQIGGKFNHJSGCGM",
"output": "NO"
},
{
"input": "ROUWANOPNIGTVMIITVMZ\nOQTUPZMTKUGY\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR",
"output": "YES"
},
{
"input": "OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY",
"output": "YES"
},
{
"input": "NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\nNSFQDFUMQDQWQ\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX",
"output": "YES"
},
{
"input": "IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\nNJMWRMBCNPHXTDQQNZ\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW",
"output": "YES"
},
{
"input": "SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU",
"output": "YES"
},
{
"input": "H\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK",
"output": "YES"
},
{
"input": "DSWNZRFVXQ\nPVULCZGOOU\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE",
"output": "NO"
},
{
"input": "EUHTSCENIPXLTSBMLFHD\nIZAVSZPDLXOAGESUSE\nLXAELAZ",
"output": "NO"
},
{
"input": "WYSJFEREGELSKRQRXDXCGBODEFZVSI\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI",
"output": "NO"
},
{
"input": "EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\nECGXACVKEYMCEDOTMKAUFHLHOMT",
"output": "NO"
},
{
"input": "NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY",
"output": "NO"
},
{
"input": "VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT",
"output": "NO"
},
{
"input": "PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\nFUPDLNVIHRWTEEEHOOEC\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY",
"output": "NO"
},
{
"input": "GDSLNIIKTO\nJF\nPDQYFKDTNOLI",
"output": "NO"
},
{
"input": "AHOKHEKKPJLJIIWJRCGY\nORELJCSIX\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE",
"output": "NO"
},
{
"input": "ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\nTEV\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH",
"output": "NO"
},
{
"input": "AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU",
"output": "NO"
},
{
"input": "XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\nZKIWNDGBISDB\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG",
"output": "NO"
},
{
"input": "PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\nTWRRAJLCQJTKOKWCGUH\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM",
"output": "NO"
},
{
"input": "QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\nV\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW",
"output": "NO"
},
{
"input": "XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\nLEXOPFPVPSZK\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ",
"output": "YES"
},
{
"input": "OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS",
"output": "YES"
},
{
"input": "VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\nFE\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH",
"output": "YES"
},
{
"input": "WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\nBLQZRRWP\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB",
"output": "YES"
},
{
"input": "MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP",
"output": "YES"
},
{
"input": "OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\nDJBFVRTARTFZOWN\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR",
"output": "YES"
},
{
"input": "OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\nOHBKWRFDRQUAFRCMT\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT",
"output": "YES"
},
{
"input": "OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\nMYYDQKOOYPOOUELCRIT\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH",
"output": "YES"
},
{
"input": "WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\nYOBMOVYTUATTFGJLYUQD\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG",
"output": "YES"
},
{
"input": "CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\nMUFOSEUEXEQTOVLGDSCWM\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF",
"output": "YES"
},
{
"input": "IDQRX\nWETHO\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA",
"output": "NO"
},
{
"input": "IXFDY\nJRMOU\nDF",
"output": "NO"
},
{
"input": "JPSPZ\nUGCUB\nJMZZZZZZZZ",
"output": "NO"
},
{
"input": "AC\nA\nBBA",
"output": "NO"
},
{
"input": "UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\nKZXQDWJJWRXFHKJDQHJK\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB",
"output": "NO"
},
{
"input": "PXWRXRPFLR\nPJRWWXIVHODV\nXW",
"output": "NO"
},
{
"input": "CHTAZVHGSHCVIBK\nEQINEBKXEPYJSAZIMLDF\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE",
"output": "NO"
},
{
"input": "GXPZFSELJJNDAXYRV\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH",
"output": "NO"
},
{
"input": "LFGJCJJDUTUP\nOVSBILTIYCJCRHKCIXCETJQJJ\nGIJJTJCLTJJJ",
"output": "NO"
},
{
"input": "GIO\nPRL\nPRL",
"output": "NO"
},
{
"input": "A\nB\nABC",
"output": "NO"
},
{
"input": "KKK\nKKK\nZZZZZ",
"output": "NO"
},
{
"input": "ZMYGQLDBLAPN\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA",
"output": "NO"
}
] | 1,690,795,938 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a = input("")
b = input("")
d = input("")
c = 0
dd = list(d)
for i in d:
if i in a or i in b:
c += 1
del dd[dd.index(i)]
if c == len(d) and len(d) == 0:
print("YES")
else:
print("NO")
| Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
Input Specification:
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
Output Specification:
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
Demo Input:
['SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n', 'PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n', 'BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | ```python
a = input("")
b = input("")
d = input("")
c = 0
dd = list(d)
for i in d:
if i in a or i in b:
c += 1
del dd[dd.index(i)]
if c == len(d) and len(d) == 0:
print("YES")
else:
print("NO")
``` | 0 |
|
952 | D | I'm Feeling Lucky! | PROGRAMMING | 1,800 | [
"probabilities"
] | null | null | You have one chip and one chance to play roulette. Are you feeling lucky? | none | Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares). | [] | [] | none | 0 | [
{
"input": "1",
"output": "Red"
},
{
"input": "2",
"output": "Red"
}
] | 1,648,816,286 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 61 | 0 | print(36)
| Title: I'm Feeling Lucky!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have one chip and one chance to play roulette. Are you feeling lucky?
Input Specification:
none
Output Specification:
Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares).
Note:
none | ```python
print(36)
``` | 0 |
|
961 | A | Tetris | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the $n$ columns have at least one square in them, the bottom row is being removed. You will receive $1$ point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive. | The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares.
The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. | Print one integer — the amount of points you will receive. | [
"3 9\n1 1 2 2 2 3 1 2 3\n"
] | [
"2\n"
] | In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$).
After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing one row it will look like $[1~ 2~ 0]$.
So the answer will be equal to $2$. | 0 | [
{
"input": "3 9\n1 1 2 2 2 3 1 2 3",
"output": "2"
},
{
"input": "1 7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 5\n1 1 1 2 3",
"output": "1"
},
{
"input": "4 6\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "4 6\n2 3 4 4 4 4",
"output": "0"
},
{
"input": "3 12\n1 1 1 1 2 2 2 2 3 3 3 3",
"output": "4"
},
{
"input": "8 8\n2 2 3 4 5 6 7 8",
"output": "0"
},
{
"input": "100 1\n50",
"output": "0"
},
{
"input": "2 1\n2",
"output": "0"
},
{
"input": "2 1\n1",
"output": "0"
},
{
"input": "2 4\n1 2 1 1",
"output": "1"
},
{
"input": "3 4\n3 2 2 2",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "0"
},
{
"input": "2 5\n2 1 1 2 1",
"output": "2"
},
{
"input": "15 3\n13 14 15",
"output": "0"
},
{
"input": "4 9\n1 2 3 1 2 3 1 2 3",
"output": "0"
},
{
"input": "100 3\n1 2 3",
"output": "0"
},
{
"input": "1000 10\n999 999 998 34 454 546 343 35 34 1000",
"output": "0"
},
{
"input": "4 2\n1 2",
"output": "0"
}
] | 1,539,256,574 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 124 | 0 | n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i in a:
b[i - 1] += 1
print(min(b)) | Title: Tetris
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the $n$ columns have at least one square in them, the bottom row is being removed. You will receive $1$ point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input Specification:
The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares.
The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear.
Output Specification:
Print one integer — the amount of points you will receive.
Demo Input:
['3 9\n1 1 2 2 2 3 1 2 3\n']
Demo Output:
['2\n']
Note:
In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$).
After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing one row it will look like $[1~ 2~ 0]$.
So the answer will be equal to $2$. | ```python
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i in a:
b[i - 1] += 1
print(min(b))
``` | 3 |
|
628 | B | New Skateboard | PROGRAMMING | 1,300 | [
"dp"
] | null | null | Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.
You are given a string *s* consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.
A substring of a string is a nonempty sequence of consecutive characters.
For example if string *s* is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. | The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. | Print integer *a* — the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"124\n",
"04\n",
"5810438174\n"
] | [
"4\n",
"3\n",
"9\n"
] | none | 0 | [
{
"input": "124",
"output": "4"
},
{
"input": "04",
"output": "3"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "1",
"output": "0"
},
{
"input": "039",
"output": "1"
},
{
"input": "97247",
"output": "6"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "12883340691714056185860211260984431382156326935244",
"output": "424"
},
{
"input": "2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031",
"output": "1528"
},
{
"input": "80124649014054971081213608137817466046254652492627741860478258558206397113198232823859870363821007188476405951611069347299689170240023979048198711745011542774268179055311013054073075176122755643483380248999657649211459997766221072399103579977409770898200358240970169892326442892826731631357561876251276209119521202062222947560634301788787748428236988789594458520867663257476744168528121470923031438015546006185059454402637036376247785881323277542968298682307854655591317046086531554595892680980142608",
"output": "30826"
},
{
"input": "123456",
"output": "7"
},
{
"input": "4",
"output": "1"
},
{
"input": "123",
"output": "1"
}
] | 1,570,740,280 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 483 | 4,198,400 | s=input()
a=[0]
count=0
ans=0
for i in range(1,len(s)):
p=int(s[i-1]+s[i])
#print(p)
if(p%4==0):
a.append(1)
else:
a.append(0)
#print(a)
for i in range(len(a)):
if(a[i]==1):
count=count+i
for i in s:
if(int(i)%4==0):
ans+=1
output=count+ans
#print(count)
#print(ans)
print(output) | Title: New Skateboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.
You are given a string *s* consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.
A substring of a string is a nonempty sequence of consecutive characters.
For example if string *s* is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input Specification:
The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9.
Output Specification:
Print integer *a* — the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Demo Input:
['124\n', '04\n', '5810438174\n']
Demo Output:
['4\n', '3\n', '9\n']
Note:
none | ```python
s=input()
a=[0]
count=0
ans=0
for i in range(1,len(s)):
p=int(s[i-1]+s[i])
#print(p)
if(p%4==0):
a.append(1)
else:
a.append(0)
#print(a)
for i in range(len(a)):
if(a[i]==1):
count=count+i
for i in s:
if(int(i)%4==0):
ans+=1
output=count+ans
#print(count)
#print(ans)
print(output)
``` | 3 |
|
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,673,709,298 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input(""))
a = 2
while True:
if (n - a)%2 == 0 or (n - a)% 3 == 0:
print(a,n - a)
break
if a + 1 > 3 and (a + 1)%3 == 0:
a += 1
elif a + 1 > 3 and (a + 1)%2 == 0:
a += 1
else:
a += 2 | 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
n = int(input(""))
a = 2
while True:
if (n - a)%2 == 0 or (n - a)% 3 == 0:
print(a,n - a)
break
if a + 1 > 3 and (a + 1)%3 == 0:
a += 1
elif a + 1 > 3 and (a + 1)%2 == 0:
a += 1
else:
a += 2
``` | 0 |
|
979 | C | Kuro and Walking Route | PROGRAMMING | 1,600 | [
"dfs and similar",
"trees"
] | null | null | Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$).
Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him.
Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem. | The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively.
$n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$.
It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree. | A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route. | [
"3 1 3\n1 2\n2 3\n",
"3 1 3\n1 2\n1 3\n"
] | [
"5",
"4"
] | On the first example, Kuro can choose these pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$.
Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order).
On the second example, Kuro can choose the following pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$. | 1,250 | [
{
"input": "3 1 3\n1 2\n2 3",
"output": "5"
},
{
"input": "3 1 3\n1 2\n1 3",
"output": "4"
},
{
"input": "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 2\n35 27\n39 20\n1 24\n1 53\n35 58\n39 37\n61 13\n61 16\n1 12\n32 17\n1 40\n33 47\n29 52\n1 39\n35 19\n39 50\n27 6\n26 3\n26 55\n35 31\n1 61\n1 23\n27 45\n39 7\n1 35\n39 29\n27 5\n39 32\n27 48\n35 49\n29 54\n1 46\n35 36\n31 33",
"output": "3657"
},
{
"input": "8 5 1\n5 8\n1 5\n1 3\n1 4\n5 6\n6 7\n1 2",
"output": "40"
},
{
"input": "31 29 20\n29 23\n29 18\n22 14\n29 20\n1 21\n29 10\n28 2\n1 17\n17 15\n1 11\n29 31\n28 6\n12 29\n12 26\n1 13\n22 4\n29 25\n28 22\n17 5\n28 30\n20 27\n29 8\n12 28\n1 12\n12 24\n22 7\n12 16\n12 3\n28 9\n1 19",
"output": "872"
},
{
"input": "8 6 4\n1 2\n1 4\n1 8\n1 3\n1 7\n2 6\n2 5",
"output": "55"
},
{
"input": "7 7 3\n3 2\n3 5\n3 7\n1 3\n1 4\n5 6",
"output": "36"
},
{
"input": "70 42 32\n25 50\n51 7\n39 61\n1 33\n20 5\n1 70\n1 63\n42 35\n64 16\n1 11\n39 42\n20 54\n11 14\n57 44\n1 59\n55 40\n25 3\n31 18\n38 68\n57 23\n39 57\n28 10\n39 20\n42 26\n58 6\n20 56\n57 2\n13 21\n15 69\n39 64\n1 39\n62 53\n39 13\n1 41\n22 12\n13 30\n68 67\n20 31\n51 15\n57 32\n59 34\n39 4\n31 65\n58 24\n20 55\n15 27\n25 46\n20 22\n57 49\n68 52\n39 8\n54 58\n39 28\n13 48\n15 43\n25 66\n1 29\n15 37\n31 60\n1 19\n62 38\n39 17\n64 36\n59 25\n57 45\n57 9\n11 62\n20 51\n54 47",
"output": "4827"
},
{
"input": "13 5 13\n2 5\n5 8\n1 2\n13 7\n2 3\n1 13\n13 11\n13 4\n10 6\n10 12\n7 9\n1 10",
"output": "146"
},
{
"input": "72 16 5\n1 20\n8 4\n23 19\n16 63\n45 65\n27 67\n58 21\n36 17\n20 52\n1 71\n8 59\n20 26\n28 16\n23 3\n45 42\n61 51\n6 31\n1 15\n1 11\n6 62\n43 60\n20 27\n20 32\n1 8\n68 25\n1 57\n20 70\n1 64\n1 13\n8 18\n8 46\n28 49\n8 39\n64 58\n28 47\n27 14\n8 10\n11 53\n1 24\n28 2\n72 30\n36 29\n1 45\n24 23\n1 72\n46 61\n45 56\n72 35\n11 50\n8 55\n8 28\n1 38\n61 41\n1 44\n61 40\n27 33\n72 69\n46 36\n43 66\n61 22\n45 5\n27 43\n46 12\n1 7\n16 68\n1 6\n1 9\n45 37\n27 34\n8 54\n20 48",
"output": "5108"
},
{
"input": "2 1 2\n1 2",
"output": "1"
},
{
"input": "2 1 2\n2 1",
"output": "1"
}
] | 1,549,879,987 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 819,200 | n,x,y = map(int,input().split())
from collections import defaultdict
count = 0
class Graph:
def __init__(self,x,y):
self.x = x
self.y = y
self.graph = defaultdict(list)
def addEdge(self,u,v):
self.graph[u].append(v)
def DFSUtil(self,v,visited,flag):
global count
visited[v]= True
if flag and v== self.y:
count-=1
return
if v == self.x:
flag = True
#print(visited)
for i in self.graph[v]:
if visited[i] == False:
count+=1
self.DFSUtil(i, visited,flag)
def DFS(self,v):
visited = [False]*(len(self.graph))
if v!= self.x:
self.DFSUtil(v,visited,False)
else:
self.DFSUtil(v,visited,True)
g = Graph(x-1,y-1)
for i in range(n-1):
a,b = map(int,input().split())
g.addEdge(a-1,b-1)
g.addEdge(b-1,a-1)
for i in range(n):
g.DFS(i)
print(count)
| Title: Kuro and Walking Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$).
Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him.
Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem.
Input Specification:
The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively.
$n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$.
It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.
Output Specification:
A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route.
Demo Input:
['3 1 3\n1 2\n2 3\n', '3 1 3\n1 2\n1 3\n']
Demo Output:
['5', '4']
Note:
On the first example, Kuro can choose these pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$.
Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order).
On the second example, Kuro can choose the following pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$. | ```python
n,x,y = map(int,input().split())
from collections import defaultdict
count = 0
class Graph:
def __init__(self,x,y):
self.x = x
self.y = y
self.graph = defaultdict(list)
def addEdge(self,u,v):
self.graph[u].append(v)
def DFSUtil(self,v,visited,flag):
global count
visited[v]= True
if flag and v== self.y:
count-=1
return
if v == self.x:
flag = True
#print(visited)
for i in self.graph[v]:
if visited[i] == False:
count+=1
self.DFSUtil(i, visited,flag)
def DFS(self,v):
visited = [False]*(len(self.graph))
if v!= self.x:
self.DFSUtil(v,visited,False)
else:
self.DFSUtil(v,visited,True)
g = Graph(x-1,y-1)
for i in range(n-1):
a,b = map(int,input().split())
g.addEdge(a-1,b-1)
g.addEdge(b-1,a-1)
for i in range(n):
g.DFS(i)
print(count)
``` | 0 |
|
697 | A | Pineapple Incident | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time. | The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. | Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. | [
"3 10 4\n",
"3 10 3\n",
"3 8 51\n",
"3 8 52\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52. | 500 | [
{
"input": "3 10 4",
"output": "NO"
},
{
"input": "3 10 3",
"output": "YES"
},
{
"input": "3 8 51",
"output": "YES"
},
{
"input": "3 8 52",
"output": "YES"
},
{
"input": "456947336 740144 45",
"output": "NO"
},
{
"input": "33 232603 599417964",
"output": "YES"
},
{
"input": "4363010 696782227 701145238",
"output": "YES"
},
{
"input": "9295078 2 6",
"output": "NO"
},
{
"input": "76079 281367 119938421",
"output": "YES"
},
{
"input": "93647 7 451664565",
"output": "YES"
},
{
"input": "5 18553 10908",
"output": "NO"
},
{
"input": "6 52 30",
"output": "NO"
},
{
"input": "6431 855039 352662",
"output": "NO"
},
{
"input": "749399100 103031711 761562532",
"output": "NO"
},
{
"input": "21 65767 55245",
"output": "NO"
},
{
"input": "4796601 66897 4860613",
"output": "NO"
},
{
"input": "8 6728951 860676",
"output": "NO"
},
{
"input": "914016 6 914019",
"output": "NO"
},
{
"input": "60686899 78474 60704617",
"output": "NO"
},
{
"input": "3 743604 201724",
"output": "NO"
},
{
"input": "571128 973448796 10",
"output": "NO"
},
{
"input": "688051712 67 51",
"output": "NO"
},
{
"input": "74619 213344 6432326",
"output": "NO"
},
{
"input": "6947541 698167 6",
"output": "NO"
},
{
"input": "83 6 6772861",
"output": "NO"
},
{
"input": "251132 67561 135026988",
"output": "NO"
},
{
"input": "8897216 734348516 743245732",
"output": "YES"
},
{
"input": "50 64536 153660266",
"output": "YES"
},
{
"input": "876884 55420 971613604",
"output": "YES"
},
{
"input": "0 6906451 366041903",
"output": "YES"
},
{
"input": "11750 8 446010134",
"output": "YES"
},
{
"input": "582692707 66997 925047377",
"output": "YES"
},
{
"input": "11 957526890 957526901",
"output": "YES"
},
{
"input": "556888 514614196 515171084",
"output": "YES"
},
{
"input": "6 328006 584834704",
"output": "YES"
},
{
"input": "4567998 4 204966403",
"output": "YES"
},
{
"input": "60 317278 109460971",
"output": "YES"
},
{
"input": "906385 342131991 685170368",
"output": "YES"
},
{
"input": "1 38 902410512",
"output": "YES"
},
{
"input": "29318 787017 587931018",
"output": "YES"
},
{
"input": "351416375 243431 368213115",
"output": "YES"
},
{
"input": "54 197366062 197366117",
"output": "YES"
},
{
"input": "586389 79039 850729874",
"output": "YES"
},
{
"input": "723634470 2814619 940360134",
"output": "YES"
},
{
"input": "0 2 0",
"output": "YES"
},
{
"input": "0 2 1",
"output": "NO"
},
{
"input": "0 2 2",
"output": "YES"
},
{
"input": "0 2 3",
"output": "YES"
},
{
"input": "0 2 1000000000",
"output": "YES"
},
{
"input": "0 10 23",
"output": "NO"
},
{
"input": "0 2 999999999",
"output": "YES"
},
{
"input": "10 5 11",
"output": "NO"
},
{
"input": "1 2 1000000000",
"output": "YES"
},
{
"input": "1 10 20",
"output": "NO"
},
{
"input": "1 2 999999937",
"output": "YES"
},
{
"input": "10 3 5",
"output": "NO"
},
{
"input": "3 2 5",
"output": "YES"
},
{
"input": "0 4 0",
"output": "YES"
},
{
"input": "0 215 403",
"output": "NO"
},
{
"input": "5 2 10",
"output": "YES"
},
{
"input": "0 2 900000000",
"output": "YES"
},
{
"input": "0 79 4000",
"output": "NO"
},
{
"input": "5 1000 1000",
"output": "NO"
},
{
"input": "1 5 103",
"output": "NO"
},
{
"input": "5 2 6",
"output": "NO"
},
{
"input": "120 2 1000000000",
"output": "YES"
},
{
"input": "2 2 1000000000",
"output": "YES"
},
{
"input": "5 5 13",
"output": "NO"
},
{
"input": "10 5 15",
"output": "YES"
},
{
"input": "11 2 0",
"output": "NO"
},
{
"input": "3 8 53",
"output": "NO"
},
{
"input": "2 2 4",
"output": "YES"
},
{
"input": "4 4 0",
"output": "NO"
},
{
"input": "1 2 3",
"output": "YES"
},
{
"input": "5 3 9",
"output": "YES"
},
{
"input": "5 6 19",
"output": "NO"
},
{
"input": "3 10 125",
"output": "NO"
},
{
"input": "5 3 8",
"output": "YES"
},
{
"input": "6 3 9",
"output": "YES"
},
{
"input": "0 3 5",
"output": "NO"
},
{
"input": "5 3 300000035",
"output": "YES"
},
{
"input": "5 2 7",
"output": "YES"
},
{
"input": "1 5 6",
"output": "YES"
},
{
"input": "4 2 6",
"output": "YES"
},
{
"input": "0 3 999999998",
"output": "NO"
},
{
"input": "0 10001 0",
"output": "YES"
},
{
"input": "6 5 3",
"output": "NO"
},
{
"input": "1 5 1000000000",
"output": "NO"
},
{
"input": "1 3 6",
"output": "NO"
},
{
"input": "3 3 1000000000",
"output": "YES"
},
{
"input": "3 3 4",
"output": "NO"
},
{
"input": "3 3 5",
"output": "NO"
},
{
"input": "3 3 0",
"output": "NO"
},
{
"input": "1 2 4",
"output": "YES"
},
{
"input": "5 5 10",
"output": "YES"
}
] | 1,559,619,941 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 124 | 0 | import math
t, s, x = map(int, input().split())
if x == t:
print("YES")
elif x < t + s:
print("NO")
else:
n = math.ceil((x - t - 1) / s)
d = t + n * s + 1
if d == x or x == d - 1:
print("YES")
else:
print("NO")
| Title: Pineapple Incident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time *x* (in seconds), so he asked you to tell him if it's gonna bark at that time.
Input Specification:
The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.
Output Specification:
Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output.
Demo Input:
['3 10 4\n', '3 10 3\n', '3 8 51\n', '3 8 52\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n', 'YES\n']
Note:
In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52. | ```python
import math
t, s, x = map(int, input().split())
if x == t:
print("YES")
elif x < t + s:
print("NO")
else:
n = math.ceil((x - t - 1) / s)
d = t + n * s + 1
if d == x or x == d - 1:
print("YES")
else:
print("NO")
``` | 3 |
|
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*. | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output": "I become the guy."
},
{
"input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5",
"output": "I become the guy."
},
{
"input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23",
"output": "Oh, my keyboard!"
},
{
"input": "1\n1 1\n1 1",
"output": "I become the guy."
},
{
"input": "1\n0\n1 1",
"output": "I become the guy."
},
{
"input": "1\n1 1\n0",
"output": "I become the guy."
},
{
"input": "1\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11",
"output": "I become the guy."
},
{
"input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60",
"output": "I become the guy."
},
{
"input": "2\n2 2 1\n0",
"output": "I become the guy."
},
{
"input": "2\n1 2\n2 1 2",
"output": "I become the guy."
},
{
"input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54",
"output": "Oh, my keyboard!"
},
{
"input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33",
"output": "Oh, my keyboard!"
},
{
"input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61",
"output": "I become the guy."
},
{
"input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58",
"output": "I become the guy."
},
{
"input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76",
"output": "Oh, my keyboard!"
},
{
"input": "3\n1 2\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "4\n1 2\n3 1 3 4",
"output": "I become the guy."
},
{
"input": "6\n2 1 2\n3 4 5 6",
"output": "Oh, my keyboard!"
}
] | 1,691,367,591 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
x_s = input()
y_s = input()
x = set(x_s)
y = set(y_s)
x.add('0')
x.update(y)
z = set(str(i) for i in range(n + 1))
if x == z:
print('I become the guy.')
else:
print('Oh, my keyboard!') | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input Specification:
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
Output Specification:
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
Demo Input:
['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n']
Demo Output:
['I become the guy.\n', 'Oh, my keyboard!\n']
Note:
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | ```python
n = int(input())
x_s = input()
y_s = input()
x = set(x_s)
y = set(y_s)
x.add('0')
x.update(y)
z = set(str(i) for i in range(n + 1))
if x == z:
print('I become the guy.')
else:
print('Oh, my keyboard!')
``` | 0 |
|
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*).
Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations! | The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDLLLDRDUDURRRRRUDULDDDLLUDLRLRLRLDLDUULRDUDLRRDLUDLURRDDRRDLDUDUUURUUUDRLUDUDLURDLDLLDDU",
"output": "80"
},
{
"input": "90\nRRRDUULLLRDUUDDRLDLRLUDURDRDUUURUURDDRRRURLDDDUUDRLLLULURDRDRURLDRRRRUULDULDDLLLRRLRDLLLLR",
"output": "84"
},
{
"input": "91\nRLDRLRRLLDLULULLURULLRRULUDUULLUDULDUULURUDRUDUURDULDUDDUUUDRRUUDLLRULRULURLDRDLDRURLLLRDDD",
"output": "76"
},
{
"input": "92\nRLRDDLULRLLUURRDDDLDDDLDDUURRRULLRDULDULLLUUULDUDLRLRRDRDRDDULDRLUDRDULDRURUDUULLRDRRLLDRLRR",
"output": "86"
},
{
"input": "93\nRLLURLULRURDDLUURLUDDRDLUURLRDLRRRDUULLRDRRLRLDURRDLLRDDLLLDDDLDRRURLLDRUDULDDRRULRRULRLDRDLR",
"output": "84"
},
{
"input": "94\nRDULDDDLULRDRUDRUUDUUDRRRULDRRUDURUULRDUUDLULLLUDURRDRDLUDRULRRRULUURUDDDDDUDLLRDLDRLLRUUURLUL",
"output": "86"
},
{
"input": "95\nRDLUUULLUURDDRLDLLRRRULRLRDULULRULRUDURLULDDDRLURLDRULDUDUUULLRDDURUULULLDDLDRDRLLLURLRDLLDDDDU",
"output": "86"
},
{
"input": "96\nRDDRLRLLDDULRLRURUDLRLDUDRURLLUUDLLURDLRRUURDRRUDRURLLDLLRDURDURLRLUDURULLLRDUURULUUULRRURRDLURL",
"output": "84"
},
{
"input": "97\nRURDDLRLLRULUDURDLRLLUUDURRLLUDLLLDUDRUULDRUUURURULRDLDRRLLUUUDLLLDDLLLLRLLDUDRRDLLUDLRURUDULRLUR",
"output": "82"
},
{
"input": "98\nRUDURLULLDDLLRDLLRDDLLLLRLDDDDRRRDDRRURLDRLLRUUUDLUUUDDDUDRUURLURUUDUUDRULRRULLRRLRULLULDLUURLULRD",
"output": "92"
},
{
"input": "99\nRRULLDULRRDRULLDUDRUDDDRLLUUDRDDUDURLDDRUUDRRUUURRRURDDLDUURDLRLURRDDLUDDLUDURDRUDDURLURURLRUDRURLD",
"output": "86"
},
{
"input": "100\nUDRLRRLLRRLRRRDDLLDDDLULLDDLURUURUULUDDDRDDLLRDLLUURLRDRLRRLRLLLULDUDDUURRLRDULDRDURRRRRRULDRRDLDRRL",
"output": "88"
},
{
"input": "1\nU",
"output": "0"
},
{
"input": "5\nUUULD",
"output": "2"
},
{
"input": "1\nD",
"output": "0"
},
{
"input": "5\nURLUL",
"output": "2"
},
{
"input": "5\nDDDRU",
"output": "2"
},
{
"input": "2\nLR",
"output": "2"
},
{
"input": "8\nDDRDLDUR",
"output": "4"
},
{
"input": "6\nLLLLUD",
"output": "2"
},
{
"input": "13\nRRRLLLLLLLLLL",
"output": "6"
}
] | 1,603,618,961 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 109 | 307,200 | n = int(input())
s = input()
l = 0
r = 0
u = 0
d = 0
count = 0
for i in s:
if i == 'L':
l = l+1
if i == 'R':
r = r+1
if i == 'U':
u = u+1
if i == 'D':
d = d+1
if l>=r:
count = 2*r
else:
count = 2*l
if u>=d:
count = count+2*d
else:
count = count+2*u
print(count)
| Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*).
Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!
Input Specification:
The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R.
Output Specification:
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
Demo Input:
['4\nLDUR\n', '5\nRRRUU\n', '6\nLLRRRR\n']
Demo Output:
['4\n', '0\n', '4\n']
Note:
none | ```python
n = int(input())
s = input()
l = 0
r = 0
u = 0
d = 0
count = 0
for i in s:
if i == 'L':
l = l+1
if i == 'R':
r = r+1
if i == 'U':
u = u+1
if i == 'D':
d = d+1
if l>=r:
count = 2*r
else:
count = 2*l
if u>=d:
count = count+2*d
else:
count = count+2*u
print(count)
``` | 3 |
|
17 | A | Noldbach problem | PROGRAMMING | 1,000 | [
"brute force",
"math",
"number theory"
] | A. Noldbach problem | 2 | 64 | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.
Two prime numbers are called neighboring if there are no other prime numbers between them.
You are to help Nick, and find out if he is right or wrong. | The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). | Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. | [
"27 2\n",
"45 7\n"
] | [
"YES",
"NO"
] | In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | 0 | [
{
"input": "27 2",
"output": "YES"
},
{
"input": "45 7",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "15 1",
"output": "YES"
},
{
"input": "17 1",
"output": "YES"
},
{
"input": "34 5",
"output": "NO"
},
{
"input": "37 4",
"output": "YES"
},
{
"input": "43 5",
"output": "YES"
},
{
"input": "47 7",
"output": "NO"
},
{
"input": "50 5",
"output": "YES"
},
{
"input": "57 6",
"output": "YES"
},
{
"input": "60 8",
"output": "NO"
},
{
"input": "62 7",
"output": "YES"
},
{
"input": "76 9",
"output": "NO"
},
{
"input": "69 7",
"output": "YES"
},
{
"input": "113 10",
"output": "YES"
},
{
"input": "141 11",
"output": "YES"
},
{
"input": "207 16",
"output": "NO"
},
{
"input": "231 18",
"output": "NO"
},
{
"input": "296 19",
"output": "YES"
},
{
"input": "332 20",
"output": "YES"
},
{
"input": "378 24",
"output": "NO"
},
{
"input": "428 23",
"output": "YES"
},
{
"input": "497 27",
"output": "NO"
},
{
"input": "640 32",
"output": "YES"
},
{
"input": "798 35",
"output": "YES"
},
{
"input": "802 35",
"output": "YES"
},
{
"input": "864 40",
"output": "NO"
},
{
"input": "953 44",
"output": "NO"
},
{
"input": "995 44",
"output": "YES"
},
{
"input": "1000 44",
"output": "YES"
},
{
"input": "1000 0",
"output": "YES"
},
{
"input": "1000 1000",
"output": "NO"
},
{
"input": "2 1000",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
}
] | 1,691,147,608 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 24 | 186 | 1,228,800 | n,k = map(int,input().split())
kol = 0
ans=[]
s=[ 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,911,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997]
i=13
while i<=n:
if kol>=k: break
if i in s and i%2==1:
for j in range(s.index(i)-1):
if s[j]+s[j+1]+1==i:
kol+=1
ans.append(i)
break
i+=1
if kol>=k: print('YES')
else: print('NO') | Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.
Two prime numbers are called neighboring if there are no other prime numbers between them.
You are to help Nick, and find out if he is right or wrong.
Input Specification:
The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000).
Output Specification:
Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO.
Demo Input:
['27 2\n', '45 7\n']
Demo Output:
['YES', 'NO']
Note:
In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | ```python
n,k = map(int,input().split())
kol = 0
ans=[]
s=[ 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,911,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997]
i=13
while i<=n:
if kol>=k: break
if i in s and i%2==1:
for j in range(s.index(i)-1):
if s[j]+s[j+1]+1==i:
kol+=1
ans.append(i)
break
i+=1
if kol>=k: print('YES')
else: print('NO')
``` | 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,633,801,275 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 122 | 6,963,200 | n=int(input())
a1=0
b1=0
c1=0
for i in range(n):
a,b,c=map(int, input().split())
a1+=a
b1+=b
c1+=c
if a1>0 or b1>0 or c1>0:
print('NO')
else:
print('YES') | 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())
a1=0
b1=0
c1=0
for i in range(n):
a,b,c=map(int, input().split())
a1+=a
b1+=b
c1+=c
if a1>0 or b1>0 or c1>0:
print('NO')
else:
print('YES')
``` | 0 |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,676,802,422 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 93 | 0 | # -*- coding: utf-8 -*-
"""Untitled32.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1r2sT1YOHXEcOkHEnYjqrRkDVYewH_SCi
"""
n, m, a = map(int, input().split(" "))
if m%a == 0: #false
val1 = m // a
else:
val1 = m // a + 1
if n%a == 0: #false
val2 = n // a
else:
val2 = n // a + 1
print(val1*val2) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
# -*- coding: utf-8 -*-
"""Untitled32.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1r2sT1YOHXEcOkHEnYjqrRkDVYewH_SCi
"""
n, m, a = map(int, input().split(" "))
if m%a == 0: #false
val1 = m // a
else:
val1 = m // a + 1
if n%a == 0: #false
val2 = n // a
else:
val2 = n // a + 1
print(val1*val2)
``` | 3.9535 |
400 | B | Inna and New Matrix of Candies | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"schedules"
] | null | null | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
- some dwarf in one of the chosen lines is located in the rightmost cell of his row; - some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*m*<=≤<=1000).
Next *n* lines each contain *m* characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S". | In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field. | [
"3 4\n*G*S\nG**S\n*G*S\n",
"1 3\nS*G\n"
] | [
"2\n",
"-1\n"
] | none | 1,000 | [
{
"input": "3 4\n*G*S\nG**S\n*G*S",
"output": "2"
},
{
"input": "1 3\nS*G",
"output": "-1"
},
{
"input": "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S",
"output": "9"
},
{
"input": "5 10\nG***S*****\nG****S****\n***GS*****\nG*S*******\nG***S*****",
"output": "4"
},
{
"input": "4 8\nG*S*****\n****G*S*\nG*****S*\n**G***S*",
"output": "3"
},
{
"input": "4 10\n***G****S*\n*****GS***\nG****S****\nG*******S*",
"output": "3"
},
{
"input": "1 2\nSG",
"output": "-1"
},
{
"input": "1 2\nGS",
"output": "1"
},
{
"input": "1 4\nSG**",
"output": "-1"
}
] | 1,611,579,570 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 77 | 307,200 | distance=lambda x: (x.find('S')-x.find('G'))
def main():
n,m=map(int,input().split())
s={distance(input()) for i in range(n)}
if min(s)<0: print(-1)
else: print(len(s))
main() | Title: Inna and New Matrix of Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
- some dwarf in one of the chosen lines is located in the rightmost cell of his row; - some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*m*<=≤<=1000).
Next *n* lines each contain *m* characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output Specification:
In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Demo Input:
['3 4\n*G*S\nG**S\n*G*S\n', '1 3\nS*G\n']
Demo Output:
['2\n', '-1\n']
Note:
none | ```python
distance=lambda x: (x.find('S')-x.find('G'))
def main():
n,m=map(int,input().split())
s={distance(input()) for i in range(n)}
if min(s)<0: print(-1)
else: print(len(s))
main()
``` | 3 |
|
777 | C | Alyona and Spreadsheet | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"dp",
"greedy",
"implementation",
"two pointers"
] | null | null | During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the table is sorted in non-decreasing order in the column *j* if *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from 1 to *n*<=-<=1.
Teacher gave Alyona *k* tasks. For each of the tasks two integers *l* and *r* are given and Alyona has to answer the following question: if one keeps the rows from *l* to *r* inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such *j* that *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from *l* to *r*<=-<=1 inclusive.
Alyona is too small to deal with this task and asks you to help! | The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=100<=000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following *n* lines contains *m* integers. The *j*-th integers in the *i* of these lines stands for *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=109).
The next line of the input contains an integer *k* (1<=≤<=*k*<=≤<=100<=000) — the number of task that teacher gave to Alyona.
The *i*-th of the next *k* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". | [
"5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n"
] | [
"Yes\nNo\nYes\nYes\nYes\nNo\n"
] | In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3. | 1,500 | [
{
"input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5",
"output": "Yes\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "1 1\n1\n1\n1 1",
"output": "Yes"
},
{
"input": "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n386865653\n67832626\n53360557\n17\n4 5\n4 7\n8 8\n9 9\n3 9\n8 10\n8 9\n7 9\n4 5\n2 9\n4 6\n2 4\n2 6\n4 6\n7 9\n2 4\n8 10",
"output": "No\nNo\nYes\nYes\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo"
},
{
"input": "15 1\n556231456\n573340933\n626155933\n397229387\n10255952\n376567394\n906742013\n269437009\n31298788\n712285290\n620239975\n379221898\n229140718\n95080095\n997123854\n18\n5 15\n1 12\n4 10\n2 15\n12 15\n15 15\n2 2\n15 15\n15 15\n13 13\n10 14\n3 6\n14 15\n3 6\n4 4\n14 15\n12 14\n1 9",
"output": "No\nNo\nNo\nNo\nNo\nYes\nYes\nYes\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nYes\nNo\nNo"
},
{
"input": "11 1\n501465490\n366941771\n415080944\n385243536\n445132523\n697044413\n894369800\n812743722\n23684788\n466526046\n953916313\n45\n2 4\n8 9\n7 7\n4 9\n2 9\n2 11\n4 4\n5 7\n1 2\n5 10\n4 6\n1 7\n4 4\n1 6\n4 7\n10 11\n1 8\n6 11\n8 8\n8 10\n1 1\n5 10\n9 10\n6 9\n6 11\n1 1\n9 9\n5 11\n1 2\n9 11\n2 6\n3 7\n11 11\n6 7\n11 11\n7 8\n5 8\n11 11\n5 6\n4 5\n2 6\n5 10\n9 9\n1 1\n1 1",
"output": "No\nNo\nYes\nNo\nNo\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes"
}
] | 1,488,547,748 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | from sys import stdin, stdout
int main():
n, m = map(int, stdin.readline().split())
k = []
for i in range(n):
k.append(list(map(int, stdin.readline().split())))
ans = []
BASE = [1 for i in range(m)]
ans.append(list(BASE))
for i in range(1, n):
ans.append(list(BASE))
for j in range(m):
if k[i][j] >= k[i - 1][j]:
ans[i][j] = ans[i - 1][j] + 1
else:
ans[i][j] = 1
max_ans = [0 for i in range(n)]
for i in range(n):
max_ans[i] = max(ans[i])
k = int(stdin.readline())
answer = []
for i in range(k):
l, r = map(int, stdin.readline().split())
if (max_ans[r - 1] >= (r - l + 1)):
answer.append("Yes\n")
else:
answer.append("No\n")
stdout.write(''.join(ans))
main()
| Title: Alyona and Spreadsheet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the table is sorted in non-decreasing order in the column *j* if *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from 1 to *n*<=-<=1.
Teacher gave Alyona *k* tasks. For each of the tasks two integers *l* and *r* are given and Alyona has to answer the following question: if one keeps the rows from *l* to *r* inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such *j* that *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from *l* to *r*<=-<=1 inclusive.
Alyona is too small to deal with this task and asks you to help!
Input Specification:
The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=100<=000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following *n* lines contains *m* integers. The *j*-th integers in the *i* of these lines stands for *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=109).
The next line of the input contains an integer *k* (1<=≤<=*k*<=≤<=100<=000) — the number of task that teacher gave to Alyona.
The *i*-th of the next *k* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Output Specification:
Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No".
Demo Input:
['5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n']
Demo Output:
['Yes\nNo\nYes\nYes\nYes\nNo\n']
Note:
In the sample, the whole table is not sorted in any column. However, rows 1–3 are sorted in column 1, while rows 4–5 are sorted in column 3. | ```python
from sys import stdin, stdout
int main():
n, m = map(int, stdin.readline().split())
k = []
for i in range(n):
k.append(list(map(int, stdin.readline().split())))
ans = []
BASE = [1 for i in range(m)]
ans.append(list(BASE))
for i in range(1, n):
ans.append(list(BASE))
for j in range(m):
if k[i][j] >= k[i - 1][j]:
ans[i][j] = ans[i - 1][j] + 1
else:
ans[i][j] = 1
max_ans = [0 for i in range(n)]
for i in range(n):
max_ans[i] = max(ans[i])
k = int(stdin.readline())
answer = []
for i in range(k):
l, r = map(int, stdin.readline().split())
if (max_ans[r - 1] >= (r - l + 1)):
answer.append("Yes\n")
else:
answer.append("No\n")
stdout.write(''.join(ans))
main()
``` | -1 |
|
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,668,096,047 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | nm = input().split()
all = ''
for _ in range(int(nm[0])):
all += input()
if 'C' not in all and 'M' not in all and 'Y':
print("#Black&White")
else:
print("#Color")
| 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
nm = input().split()
all = ''
for _ in range(int(nm[0])):
all += input()
if 'C' not in all and 'M' not in all and 'Y':
print("#Black&White")
else:
print("#Color")
``` | 0 |
|
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.
A position is good if two conditions hold:
- there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects.
Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ. | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan. | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction.
Therefore, there are 9 good positions in this example. | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 1\n1\n0\n0",
"output": "2"
},
{
"input": "5 7\n0 0 0 0 0 0 1\n0 0 0 0 0 0 1\n0 0 0 1 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0",
"output": "25"
},
{
"input": "10 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "5 7\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1\n0 1 1 1 1 1 1\n0 0 0 0 0 0 0\n0 1 1 1 1 0 1",
"output": "26"
},
{
"input": "10 20\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "121"
},
{
"input": "1 2\n0 1",
"output": "1"
},
{
"input": "1 2\n1 0",
"output": "1"
},
{
"input": "1 2\n1 1",
"output": "0"
},
{
"input": "2 1\n1\n0",
"output": "1"
},
{
"input": "2 1\n0\n1",
"output": "1"
},
{
"input": "2 1\n1\n1",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "4 4\n1 1 1 1\n1 0 0 1\n1 0 0 1\n1 1 1 1",
"output": "16"
}
] | 1,479,636,719 | 4,019 | Python 3 | OK | TESTS | 72 | 483 | 2,867,200 | n, m = map(int, input().split())
d = []
res = 0
for i in range(n):
s = input()
if s.count('1') != 0:
l = s.find('1')
r = s.rfind('1')
res += s[:l].count('0')
res += s[r+1:].count('0')
res += s[l+1:r].count('0') * 2
#print(res)
d.append(s)
#print(d)
for i in range(0, m * 2, 2):
ss = ''
for k in range(n):
ss += d[k][i]
if ss.count('1') != 0:
l = ss.find('1')
r = ss.rfind('1')
res += ss[:l].count('0')
res += ss[r+1:].count('0')
res += ss[l+1:r].count('0') * 2
#print(ss, res)
print(res)
| Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.
A position is good if two conditions hold:
- there is no actor in the cell the spotlight is placed to; - there is at least one actor in the direction the spotlight projects.
Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.
Input Specification:
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.
Output Specification:
Print one integer — the number of good positions for placing the spotlight.
Demo Input:
['2 4\n0 1 0 0\n1 0 1 0\n', '4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n']
Demo Output:
['9\n', '20\n']
Note:
In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and up direction; 1. the (2, 2) and right direction; 1. the (2, 4) cell and left direction.
Therefore, there are 9 good positions in this example. | ```python
n, m = map(int, input().split())
d = []
res = 0
for i in range(n):
s = input()
if s.count('1') != 0:
l = s.find('1')
r = s.rfind('1')
res += s[:l].count('0')
res += s[r+1:].count('0')
res += s[l+1:r].count('0') * 2
#print(res)
d.append(s)
#print(d)
for i in range(0, m * 2, 2):
ss = ''
for k in range(n):
ss += d[k][i]
if ss.count('1') != 0:
l = ss.find('1')
r = ss.rfind('1')
res += ss[:l].count('0')
res += ss[r+1:].count('0')
res += ss[l+1:r].count('0') * 2
#print(ss, res)
print(res)
``` | 3 |
|
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball? | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n0",
"output": "1"
},
{
"input": "2\n0",
"output": "1"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "4\n0",
"output": "2"
},
{
"input": "4\n1",
"output": "0"
},
{
"input": "5\n0",
"output": "0"
},
{
"input": "5\n1",
"output": "2"
},
{
"input": "5\n2",
"output": "1"
},
{
"input": "6\n0",
"output": "0"
},
{
"input": "6\n1",
"output": "1"
},
{
"input": "6\n2",
"output": "2"
},
{
"input": "7\n0",
"output": "1"
},
{
"input": "7\n1",
"output": "0"
},
{
"input": "7\n2",
"output": "2"
},
{
"input": "100000\n0",
"output": "2"
},
{
"input": "100000\n1",
"output": "0"
},
{
"input": "100000\n2",
"output": "1"
},
{
"input": "99999\n1",
"output": "1"
},
{
"input": "99998\n1",
"output": "2"
},
{
"input": "99997\n1",
"output": "0"
},
{
"input": "99996\n1",
"output": "1"
},
{
"input": "99995\n1",
"output": "2"
},
{
"input": "1999999995\n0",
"output": "2"
},
{
"input": "1999999995\n1",
"output": "1"
},
{
"input": "1999999995\n2",
"output": "0"
},
{
"input": "1999999996\n0",
"output": "2"
},
{
"input": "1999999996\n1",
"output": "0"
},
{
"input": "1999999996\n2",
"output": "1"
},
{
"input": "1999999997\n0",
"output": "0"
},
{
"input": "1999999997\n1",
"output": "2"
},
{
"input": "1999999997\n2",
"output": "1"
},
{
"input": "1999999998\n0",
"output": "0"
},
{
"input": "1999999998\n1",
"output": "1"
},
{
"input": "1999999998\n2",
"output": "2"
},
{
"input": "1999999999\n0",
"output": "1"
},
{
"input": "1999999999\n1",
"output": "0"
},
{
"input": "1999999999\n2",
"output": "2"
},
{
"input": "2000000000\n1",
"output": "2"
},
{
"input": "2000000000\n2",
"output": "0"
},
{
"input": "1234567890\n0",
"output": "0"
},
{
"input": "1234567890\n1",
"output": "1"
},
{
"input": "1234567890\n2",
"output": "2"
},
{
"input": "123456789\n0",
"output": "2"
},
{
"input": "123456789\n1",
"output": "1"
},
{
"input": "123456789\n2",
"output": "0"
},
{
"input": "123456790\n0",
"output": "2"
},
{
"input": "12\n2",
"output": "2"
},
{
"input": "32\n1",
"output": "2"
},
{
"input": "20\n2",
"output": "0"
},
{
"input": "10\n1",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "76994383\n1",
"output": "0"
},
{
"input": "25\n2",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "12\n0",
"output": "0"
},
{
"input": "150\n2",
"output": "2"
},
{
"input": "15\n0",
"output": "2"
},
{
"input": "21\n2",
"output": "0"
},
{
"input": "18\n2",
"output": "2"
},
{
"input": "8\n2",
"output": "0"
},
{
"input": "10\n0",
"output": "2"
},
{
"input": "16\n0",
"output": "2"
}
] | 1,590,344,404 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 139 | 0 | import math
#t=int(input())
#for x in range(t):
n=int(input())
x=int(input())
print(abs(x-(n%3)))
| Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball?
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements.
Output Specification:
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Demo Input:
['4\n2\n', '1\n1\n']
Demo Output:
['1\n', '0\n']
Note:
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | ```python
import math
#t=int(input())
#for x in range(t):
n=int(input())
x=int(input())
print(abs(x-(n%3)))
``` | 0 |
|
884 | D | Boxes And Balls | PROGRAMMING | 2,300 | [
"data structures",
"greedy"
] | null | null | Ivan has *n* different boxes. The first of them contains some balls of *n* different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*.
In order to do this, Ivan will make some turns. Each turn he does the following:
1. Ivan chooses any non-empty box and takes all balls from this box; 1. Then Ivan chooses any *k* empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into *k* non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either *k*<==<=2 or *k*<==<=3.
The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes.
Help Ivan to determine the minimum possible penalty of the game! | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*. | Print one number — the minimum possible penalty of the game. | [
"3\n1 2 3\n",
"4\n2 3 4 5\n"
] | [
"6\n",
"19\n"
] | In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6.
In the second example you make two turns:
1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14; 1. Take all the balls from the first box, choose *k* = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5.
Total penalty is 19. | 0 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "4\n2 3 4 5",
"output": "19"
},
{
"input": "6\n1 4 4 4 4 4",
"output": "38"
},
{
"input": "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158",
"output": "8176373828"
},
{
"input": "1\n10",
"output": "0"
},
{
"input": "1\n4",
"output": "0"
},
{
"input": "1\n12312",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n3 4",
"output": "7"
}
] | 1,509,726,608 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 467 | 16,486,400 | import heapq
n = input()
A = list(map(int, input().split()))
if (len(A) % 2 == 0):
A.append(0)
st = 0
heapq.heapify(A)
while (len(A) > 1):
abc = 0
a = heapq.heappop(A)
b = heapq.heappop(A)
c = heapq.heappop(A)
abc = a + b + c
st = st + abc
heapq.heappush(A, abc)
print(st) | Title: Boxes And Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has *n* different boxes. The first of them contains some balls of *n* different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*.
In order to do this, Ivan will make some turns. Each turn he does the following:
1. Ivan chooses any non-empty box and takes all balls from this box; 1. Then Ivan chooses any *k* empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into *k* non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either *k*<==<=2 or *k*<==<=3.
The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes.
Help Ivan to determine the minimum possible penalty of the game!
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*.
Output Specification:
Print one number — the minimum possible penalty of the game.
Demo Input:
['3\n1 2 3\n', '4\n2 3 4 5\n']
Demo Output:
['6\n', '19\n']
Note:
In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6.
In the second example you make two turns:
1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14; 1. Take all the balls from the first box, choose *k* = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5.
Total penalty is 19. | ```python
import heapq
n = input()
A = list(map(int, input().split()))
if (len(A) % 2 == 0):
A.append(0)
st = 0
heapq.heapify(A)
while (len(A) > 1):
abc = 0
a = heapq.heappop(A)
b = heapq.heappop(A)
c = heapq.heappop(A)
abc = a + b + c
st = st + abc
heapq.heappush(A, abc)
print(st)
``` | 3 |
|
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",
"output": "3"
},
{
"input": "1\n01",
"output": "1"
},
{
"input": "2\n01\n01",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "2"
},
{
"input": "3\n01\n01\n01",
"output": "1"
},
{
"input": "3\n10\n10\n01",
"output": "2"
},
{
"input": "3\n01\n10\n10",
"output": "2"
},
{
"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10",
"output": "55"
}
] | 1,691,884,329 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | m = int(input())
p , c = 0, 0
for _ in range(1, m):
x = int(input())
if x != p:
c += 1 ; p = x
print(c) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output Specification:
On the single line of the output print the number of groups of magnets.
Demo Input:
['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n']
Demo Output:
['3\n', '2\n']
Note:
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | ```python
m = int(input())
p , c = 0, 0
for _ in range(1, m):
x = int(input())
if x != p:
c += 1 ; p = x
print(c)
``` | 0 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,660,998,742 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | import sys
def theatreSquare(nums):
if nums[1] % nums[2] != 0:
y = nums[1] // nums[2] + 1
else:
y = nums[1] // nums[2]
if nums[0] % nums[2] != 0:
x = nums[1] // nums[2] + 1
else:
x = nums[1] // nums[2]
print (x * y)
nums = list(map(int, input().split(" ")))
theatreSquare(nums) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
import sys
def theatreSquare(nums):
if nums[1] % nums[2] != 0:
y = nums[1] // nums[2] + 1
else:
y = nums[1] // nums[2]
if nums[0] % nums[2] != 0:
x = nums[1] // nums[2] + 1
else:
x = nums[1] // nums[2]
print (x * y)
nums = list(map(int, input().split(" ")))
theatreSquare(nums)
``` | 0 |
369 | A | Valera and Plates | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally. | The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish. | Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. | [
"3 1 1\n1 2 1\n",
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"8 2 2\n1 2 1 2 1 2 1 2\n"
] | [
"1\n",
"1\n",
"0\n",
"4\n"
] | In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | 500 | [
{
"input": "3 1 1\n1 2 1",
"output": "1"
},
{
"input": "4 3 1\n1 1 1 1",
"output": "1"
},
{
"input": "3 1 2\n2 2 2",
"output": "0"
},
{
"input": "8 2 2\n1 2 1 2 1 2 1 2",
"output": "4"
},
{
"input": "2 100 100\n2 2",
"output": "0"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "233 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 1 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2",
"output": "132"
},
{
"input": "123 100 1\n2 2 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 2 1 2 2 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 1 2 1 1 1",
"output": "22"
},
{
"input": "188 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1",
"output": "87"
},
{
"input": "3 1 2\n1 1 1",
"output": "2"
},
{
"input": "3 2 2\n1 1 1",
"output": "1"
},
{
"input": "3 2 1\n1 1 1",
"output": "1"
},
{
"input": "3 1 1\n1 1 1",
"output": "2"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "2"
},
{
"input": "5 2 2\n2 2 2 2 2",
"output": "1"
},
{
"input": "5 2 1\n2 2 2 2 2",
"output": "2"
},
{
"input": "5 1 1\n2 2 2 2 2",
"output": "3"
},
{
"input": "1 1 2\n2",
"output": "0"
},
{
"input": "1 2 2\n2",
"output": "0"
},
{
"input": "1 2 1\n2",
"output": "0"
},
{
"input": "1 1 1\n2",
"output": "0"
},
{
"input": "6 3 1\n1 1 2 2 2 2",
"output": "2"
},
{
"input": "100 40 20\n2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "40"
},
{
"input": "7 5 2\n2 2 1 1 1 1 1",
"output": "0"
},
{
"input": "10 4 4\n2 2 2 2 2 2 1 1 1 1",
"output": "2"
},
{
"input": "3 2 1\n2 1 1",
"output": "0"
},
{
"input": "7 6 1\n2 1 1 1 1 1 1",
"output": "0"
},
{
"input": "7 5 1\n1 1 1 2 2 2 2",
"output": "1"
},
{
"input": "5 3 1\n1 1 2 2 2",
"output": "1"
},
{
"input": "3 1 1\n2 2 2",
"output": "1"
},
{
"input": "5 2 2\n2 2 2 2 2",
"output": "1"
},
{
"input": "3 1 3\n1 1 1",
"output": "2"
},
{
"input": "5 2 1\n1 1 2 2 2",
"output": "2"
},
{
"input": "4 3 2\n2 1 1 1",
"output": "0"
},
{
"input": "4 2 1\n1 2 2 2",
"output": "1"
},
{
"input": "14 4 7\n1 1 1 2 2 2 2 2 2 2 2 2 2 2",
"output": "3"
},
{
"input": "12 10 4\n2 2 2 2 2 2 1 1 1 1 1 1",
"output": "0"
},
{
"input": "5 3 2\n2 2 1 1 1",
"output": "0"
}
] | 1,679,325,071 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 46 | 0 | def solve():
days,bowl,plate=map(int,input().split());a=list(map(int,input().split()));ones=a.count(1);two=a.count(2);c=0
bowl-=ones;
if bowl<0:c+=abs(bowl);bowl=0
plate+=bowl;
plate-=two
if plate<0:c+=abs(plate)
print(c)
solve()
| Title: Valera and Plates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates.
When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
Input Specification:
The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish.
Output Specification:
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
Demo Input:
['3 1 1\n1 2 1\n', '4 3 1\n1 1 1 1\n', '3 1 2\n2 2 2\n', '8 2 2\n1 2 1 2 1 2 1 2\n']
Demo Output:
['1\n', '1\n', '0\n', '4\n']
Note:
In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl. | ```python
def solve():
days,bowl,plate=map(int,input().split());a=list(map(int,input().split()));ones=a.count(1);two=a.count(2);c=0
bowl-=ones;
if bowl<0:c+=abs(bowl);bowl=0
plate+=bowl;
plate-=two
if plate<0:c+=abs(plate)
print(c)
solve()
``` | 3 |
|
366 | B | Dima and To-do List | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete *k*<=-<=1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.
Overall, Dima has *n* tasks to do, each task has a unique number from 1 to *n*. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.
Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible. | The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n* is divisible by *k*. | In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do. | [
"6 2\n3 2 1 6 5 4\n",
"10 5\n1 3 5 7 9 9 4 1 8 5\n"
] | [
"1\n",
"3\n"
] | Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12.
Explanation of the second example.
In the second example *k* = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3. | 1,000 | [
{
"input": "6 2\n3 2 1 6 5 4",
"output": "1"
},
{
"input": "10 5\n1 3 5 7 9 9 4 1 8 5",
"output": "3"
},
{
"input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "10 10\n8 4 5 7 6 9 2 2 3 5",
"output": "7"
},
{
"input": "50 10\n1 2 3 4 5 6 7 8 9 10 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "4 2\n2 1 1 3",
"output": "1"
},
{
"input": "15 5\n5 5 5 5 5 1 2 3 4 5 1 2 3 4 5",
"output": "1"
},
{
"input": "20 10\n3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 6 4",
"output": "1"
}
] | 1,533,281,873 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 187 | 6,656,000 |
"""
6 2
3 2 1 6 5 4
"""
n, k = map(int, input().split())
l = [int(x) for x in input().split()]
ans = []
minn = 123456567
key = 0
for i in range(k):
j = i
summ = 0
while j < n:
summ += l[j]
j += k
if(summ < minn):
minn = summ
key = i
print(key + 1) | Title: Dima and To-do List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete *k*<=-<=1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.
Overall, Dima has *n* tasks to do, each task has a unique number from 1 to *n*. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.
Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible.
Input Specification:
The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n* is divisible by *k*.
Output Specification:
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
Demo Input:
['6 2\n3 2 1 6 5 4\n', '10 5\n1 3 5 7 9 9 4 1 8 5\n']
Demo Output:
['1\n', '3\n']
Note:
Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12.
Explanation of the second example.
In the second example *k* = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3. | ```python
"""
6 2
3 2 1 6 5 4
"""
n, k = map(int, input().split())
l = [int(x) for x in input().split()]
ans = []
minn = 123456567
key = 0
for i in range(k):
j = i
summ = 0
while j < n:
summ += l[j]
j += k
if(summ < minn):
minn = summ
key = i
print(key + 1)
``` | 3 |
|
948 | A | Protect Sheep | PROGRAMMING | 900 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog.
Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number. | First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell. | If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf.
If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs. | [
"6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n",
"1 2\nSW\n",
"5 5\n.S...\n...S.\nS....\n...S.\n.S...\n"
] | [
"Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n",
"No\n",
"Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n"
] | In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him. | 500 | [
{
"input": "1 2\nSW",
"output": "No"
},
{
"input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S",
"output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSDDSDSDS\nSSDDDDDDDS"
},
{
"input": "10 10\n....W.W.W.\n...W.....S\n.S.S...S..\nW......WSS\n.W..W.....\n.W...W....\nS..S...S.S\n...WWW..S.\n..S..S.S.S\nSS.......S",
"output": "No"
},
{
"input": "1 50\nW...S..............W.....S..S...............S...W.",
"output": "Yes\nWDDDSDDDDDDDDDDDDDDWDDDDDSDDSDDDDDDDDDDDDDDDSDDDWD"
},
{
"input": "2 4\n...S\n...W",
"output": "No"
},
{
"input": "4 2\n..\n..\n..\nSW",
"output": "No"
},
{
"input": "4 2\n..\n..\n..\nWS",
"output": "No"
},
{
"input": "2 4\n...W\n...S",
"output": "No"
},
{
"input": "50 1\nS\n.\n.\n.\n.\n.\n.\nS\n.\n.\n.\n.\n.\n.\n.\n.\nS\n.\nW\n.\nS\n.\n.\n.\n.\nS\n.\n.\n.\n.\n.\n.\n.\nW\n.\n.\n.\nW\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "Yes\nS\nD\nD\nD\nD\nD\nD\nS\nD\nD\nD\nD\nD\nD\nD\nD\nS\nD\nW\nD\nS\nD\nD\nD\nD\nS\nD\nD\nD\nD\nD\nD\nD\nW\nD\nD\nD\nW\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD\nD"
},
{
"input": "4 4\nW..S\nW..S\nW..S\nW..S",
"output": "Yes\nWDDS\nWDDS\nWDDS\nWDDS"
},
{
"input": "4 4\nSSSS\n....\n....\nWWWW",
"output": "Yes\nSSSS\nDDDD\nDDDD\nWWWW"
},
{
"input": "4 4\nWWWW\n....\n....\nSSSS",
"output": "Yes\nWWWW\nDDDD\nDDDD\nSSSS"
},
{
"input": "4 4\nS..W\nS..W\nS..W\nS..W",
"output": "Yes\nSDDW\nSDDW\nSDDW\nSDDW"
},
{
"input": "1 1\n.",
"output": "Yes\nD"
},
{
"input": "1 1\nW",
"output": "Yes\nW"
},
{
"input": "1 1\nS",
"output": "Yes\nS"
},
{
"input": "4 2\n..\n..\n.W\n.S",
"output": "No"
},
{
"input": "4 2\n..\n..\n.S\n.W",
"output": "No"
},
{
"input": "4 2\n..\n..\nW.\nS.",
"output": "No"
},
{
"input": "4 2\n..\n..\nS.\nW.",
"output": "No"
},
{
"input": "2 4\n....\n..SW",
"output": "No"
},
{
"input": "2 4\n....\n..WS",
"output": "No"
},
{
"input": "1 2\nS.",
"output": "Yes\nSD"
}
] | 1,520,697,082 | 982 | Python 3 | OK | TESTS | 98 | 124 | 8,192,000 | r, c = map(int, input().split())
pasture = []
pasture.append(list('.' * (c + 2)))
for i in range(r):
pasture.append(['.'] + list(input()) + ['.'])
pasture.append(list('.' * (c + 2)))
adj = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for i in range(1, r + 1):
for j in range(1, c + 1):
if pasture[i][j] == 'S':
if any(pasture[i + a][j + b] == 'W' for a,b in adj):
print('No')
exit()
for a,b in adj:
if pasture[i + a][j + b] == '.':
pasture[i + a][j + b] = 'D'
print('Yes')
print('\n'.join(''.join(row[1:-1]) for row in pasture[1:-1]))
| Title: Protect Sheep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog.
Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number.
Input Specification:
First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell.
Output Specification:
If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf.
If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs.
Demo Input:
['6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n', '1 2\nSW\n', '5 5\n.S...\n...S.\nS....\n...S.\n.S...\n']
Demo Output:
['Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n', 'No\n', 'Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n']
Note:
In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him. | ```python
r, c = map(int, input().split())
pasture = []
pasture.append(list('.' * (c + 2)))
for i in range(r):
pasture.append(['.'] + list(input()) + ['.'])
pasture.append(list('.' * (c + 2)))
adj = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for i in range(1, r + 1):
for j in range(1, c + 1):
if pasture[i][j] == 'S':
if any(pasture[i + a][j + b] == 'W' for a,b in adj):
print('No')
exit()
for a,b in adj:
if pasture[i + a][j + b] == '.':
pasture[i + a][j + b] = 'D'
print('Yes')
print('\n'.join(''.join(row[1:-1]) for row in pasture[1:-1]))
``` | 3 |
|
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,692,037,038 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 77 | 1,945,600 | n,m=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
i=0
j=0
qc=0
while i<len(l1) and j<len(l2):
if l1[i]<=l2[j]:
#print(i,j)
i=i+1
j=j+1
qc=qc+1
else:
j=j+1
#print(i,j)
print(n-qc)
| 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())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
i=0
j=0
qc=0
while i<len(l1) and j<len(l2):
if l1[i]<=l2[j]:
#print(i,j)
i=i+1
j=j+1
qc=qc+1
else:
j=j+1
#print(i,j)
print(n-qc)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | 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 | 0 | [
{
"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,572,110,213 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 342 | 409,600 | import collections
def breadth_first_search(graph, root):
visited = set()
visited.add(root)
queue = collections.deque([root])
while queue:
vertex = queue.popleft()
for neighbour in graph[vertex]:
if neighbour not in visited:
visited.add(neighbour)
queue.append(neighbour)
return visited
# 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 xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
N = int(input())
drifts = []
xcoord = set()
ycoord = set()
for n in range(N):
xi, yi = map(int, input().split())
sxi = 'x' + str(xi)
xcoord.add(sxi)
syi = 'y' + str(yi)
ycoord.add(syi)
drifts.append( (sxi, syi) )
graph = dict()
for v in xcoord | ycoord:
graph[v] = set()
for e in drifts:
graph[e[0]].add(e[1])
graph[e[1]].add(e[0])
# print(graph)
parts = []
seen = set()
for v in graph:
if v not in seen:
area = breadth_first_search(graph, v)
parts.append(area)
seen.update(area)
print(len(parts) - 1)
| Title: none
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
import collections
def breadth_first_search(graph, root):
visited = set()
visited.add(root)
queue = collections.deque([root])
while queue:
vertex = queue.popleft()
for neighbour in graph[vertex]:
if neighbour not in visited:
visited.add(neighbour)
queue.append(neighbour)
return visited
# 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 xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
N = int(input())
drifts = []
xcoord = set()
ycoord = set()
for n in range(N):
xi, yi = map(int, input().split())
sxi = 'x' + str(xi)
xcoord.add(sxi)
syi = 'y' + str(yi)
ycoord.add(syi)
drifts.append( (sxi, syi) )
graph = dict()
for v in xcoord | ycoord:
graph[v] = set()
for e in drifts:
graph[e[0]].add(e[1])
graph[e[1]].add(e[0])
# print(graph)
parts = []
seen = set()
for v in graph:
if v not in seen:
area = breadth_first_search(graph, v)
parts.append(area)
seen.update(area)
print(len(parts) - 1)
``` | 3 |
|
421 | A | Pasha and Hamsters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't get any apples.
Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them. | The first line contains integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly.
The next line contains *a* distinct integers — the numbers of the apples Arthur likes. The next line contains *b* distinct integers — the numbers of the apples Alexander likes.
Assume that the apples are numbered from 1 to *n*. The input is such that the answer exists. | Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them. | [
"4 2 3\n1 2\n2 3 4\n",
"5 5 2\n3 4 1 2 5\n2 3\n"
] | [
"1 1 2 2\n",
"1 1 1 1 1\n"
] | none | 500 | [
{
"input": "4 2 3\n1 2\n2 3 4",
"output": "1 1 2 2"
},
{
"input": "5 5 2\n3 4 1 2 5\n2 3",
"output": "1 1 1 1 1"
},
{
"input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 74 76 77 78 79 80 81 82 83 89 92 94 95 97 98 99 100\n2 13 22 23 25 28 30 32 33 34 35 36 41 42 43 45 47 52 54 62 73 75 84 85 86 87 88 90 91 93 96",
"output": "1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 2 1 2 1 2 2 2 2 2 1 1 1 1 2 2 2 1 2 1 2 1 1 1 1 2 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1"
},
{
"input": "100 56 44\n1 2 5 8 14 15 17 18 20 21 23 24 25 27 30 33 34 35 36 38 41 42 44 45 46 47 48 49 50 53 56 58 59 60 62 63 64 65 68 69 71 75 76 80 81 84 87 88 90 91 92 94 95 96 98 100\n3 4 6 7 9 10 11 12 13 16 19 22 26 28 29 31 32 37 39 40 43 51 52 54 55 57 61 66 67 70 72 73 74 77 78 79 82 83 85 86 89 93 97 99",
"output": "1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 2 1 1 2 1 1 2 1 1 1 2 1 2 2 1 2 2 1 1 1 1 2 1 2 2 1 1 2 1 1 1 1 1 1 1 2 2 1 2 2 1 2 1 1 1 2 1 1 1 1 2 2 1 1 2 1 2 2 2 1 1 2 2 2 1 1 2 2 1 2 2 1 1 2 1 1 1 2 1 1 1 2 1 2 1"
},
{
"input": "100 82 18\n1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 22 23 25 27 29 30 31 32 33 34 35 36 37 38 42 43 44 45 46 47 48 49 50 51 53 54 55 57 58 59 60 61 62 63 64 65 66 67 68 69 71 72 73 74 75 77 78 79 80 82 83 86 88 90 91 92 93 94 96 97 98 99 100\n12 21 24 26 28 39 40 41 52 56 70 76 81 84 85 87 89 95",
"output": "1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1"
},
{
"input": "99 72 27\n1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 20 23 25 26 28 29 30 32 33 34 35 36 39 41 42 43 44 45 46 47 50 51 52 54 55 56 58 59 60 61 62 67 70 71 72 74 75 76 77 80 81 82 84 85 86 88 90 91 92 93 94 95 96 97 98 99\n9 18 19 21 22 24 27 31 37 38 40 48 49 53 57 63 64 65 66 68 69 73 78 79 83 87 89",
"output": "1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 1 1 1 1 1 1 2 2 1 1 1 2 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 2 2 1 1 1 2 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1"
},
{
"input": "99 38 61\n1 3 10 15 16 22 23 28 31 34 35 36 37 38 39 43 44 49 50 53 56 60 63 68 69 70 72 74 75 77 80 81 83 85 96 97 98 99\n2 4 5 6 7 8 9 11 12 13 14 17 18 19 20 21 24 25 26 27 29 30 32 33 40 41 42 45 46 47 48 51 52 54 55 57 58 59 61 62 64 65 66 67 71 73 76 78 79 82 84 86 87 88 89 90 91 92 93 94 95",
"output": "1 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 2 2 2 2 2 1 1 2 2 2 2 1 2 2 1 2 2 1 1 1 1 1 1 2 2 2 1 1 2 2 2 2 1 1 2 2 1 2 2 1 2 2 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 1 1 2 1 2 2 1 1 2 1 2 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1"
},
{
"input": "99 84 15\n1 2 3 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 44 47 48 50 51 52 53 55 56 58 59 60 61 62 63 64 65 68 69 70 71 72 73 74 75 77 79 80 81 82 83 84 85 86 87 89 90 91 92 93 94 97 98 99\n4 18 33 45 46 49 54 57 66 67 76 78 88 95 96",
"output": "1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1 1"
},
{
"input": "4 3 1\n1 3 4\n2",
"output": "1 2 1 1"
},
{
"input": "4 3 1\n1 2 4\n3",
"output": "1 1 2 1"
},
{
"input": "4 2 2\n2 3\n1 4",
"output": "2 1 1 2"
},
{
"input": "4 3 1\n2 3 4\n1",
"output": "2 1 1 1"
},
{
"input": "1 1 1\n1\n1",
"output": "1"
},
{
"input": "2 1 1\n2\n1",
"output": "2 1"
},
{
"input": "2 1 1\n1\n2",
"output": "1 2"
},
{
"input": "3 3 1\n1 2 3\n1",
"output": "1 1 1"
},
{
"input": "3 3 1\n1 2 3\n3",
"output": "1 1 1"
},
{
"input": "3 2 1\n1 3\n2",
"output": "1 2 1"
},
{
"input": "100 1 100\n84\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": "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 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2"
},
{
"input": "100 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\n17",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "98 51 47\n1 2 3 4 6 7 8 10 13 15 16 18 19 21 22 23 25 26 27 29 31 32 36 37 39 40 41 43 44 48 49 50 51 52 54 56 58 59 65 66 68 79 80 84 86 88 89 90 94 95 97\n5 9 11 12 14 17 20 24 28 30 33 34 35 38 42 45 46 47 53 55 57 60 61 62 63 64 67 69 70 71 72 73 74 75 76 77 78 81 82 83 85 87 91 92 93 96 98",
"output": "1 1 1 1 2 1 1 1 2 1 2 2 1 2 1 1 2 1 1 2 1 1 1 2 1 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 1 1 2 2 2 1 1 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 1 2 1 2 1 1 1 2 2 2 1 1 2 1 2"
},
{
"input": "98 28 70\n1 13 15 16 19 27 28 40 42 43 46 53 54 57 61 63 67 68 69 71 75 76 78 80 88 93 97 98\n2 3 4 5 6 7 8 9 10 11 12 14 17 18 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 41 44 45 47 48 49 50 51 52 55 56 58 59 60 62 64 65 66 70 72 73 74 77 79 81 82 83 84 85 86 87 89 90 91 92 94 95 96",
"output": "1 2 2 2 2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 2 2 2 1 1 2 2 1 2 2 2 1 2 1 2 2 2 1 1 1 2 1 2 2 2 1 1 2 1 2 1 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1"
},
{
"input": "97 21 76\n7 10 16 17 26 30 34 39 40 42 44 46 53 54 56 64 67 72 78 79 94\n1 2 3 4 5 6 8 9 11 12 13 14 15 18 19 20 21 22 23 24 25 27 28 29 31 32 33 35 36 37 38 41 43 45 47 48 49 50 51 52 55 57 58 59 60 61 62 63 65 66 68 69 70 71 73 74 75 76 77 80 81 82 83 84 85 86 87 88 89 90 91 92 93 95 96 97",
"output": "2 2 2 2 2 2 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 2 1 1 2 1 2 1 2 1 2 2 2 2 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 2 1 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2"
},
{
"input": "97 21 76\n1 10 12 13 17 18 22 25 31 48 50 54 61 64 67 74 78 81 86 88 94\n2 3 4 5 6 7 8 9 11 14 15 16 19 20 21 23 24 26 27 28 29 30 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 49 51 52 53 55 56 57 58 59 60 62 63 65 66 68 69 70 71 72 73 75 76 77 79 80 82 83 84 85 87 89 90 91 92 93 95 96 97",
"output": "1 2 2 2 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 1 2 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 1 2 2 1 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2"
},
{
"input": "96 10 86\n2 5 31 37 68 69 80 82 90 91\n1 3 4 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 32 33 34 35 36 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 70 71 72 73 74 75 76 77 78 79 81 83 84 85 86 87 88 89 92 93 94 95 96",
"output": "2 1 2 2 1 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 2 2 2 2 2 1 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 1 1 2 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 1 1 2 2 2 2 2"
},
{
"input": "95 4 91\n58 65 70 93\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 59 60 61 62 63 64 66 67 68 69 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 94 95",
"output": "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 1 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2"
},
{
"input": "98 88 10\n1 2 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 38 39 40 41 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 62 63 64 65 66 67 68 69 71 72 73 74 75 76 77 79 80 81 83 84 85 86 87 88 89 90 92 93 94 95 96 97 98\n3 7 32 37 42 61 70 78 82 91",
"output": "1 1 2 1 1 1 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 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1"
},
{
"input": "98 96 2\n1 2 3 4 5 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\n6 7",
"output": "1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "97 97 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\n94",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "97 97 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\n20",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "96 96 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\n48",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "95 95 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\n55",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"
}
] | 1,683,517,294 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | n,a,b=map(int,input().split())
alikes=list(map(int,input().split()))
blikes=list(map(int,input().split()))
s=""
for i in range(1,n+1):
if (i in alikes):
s+="1 "
else:
s+="2 "
print(s.strip()) | Title: Pasha and Hamsters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't get any apples.
Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them.
Input Specification:
The first line contains integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly.
The next line contains *a* distinct integers — the numbers of the apples Arthur likes. The next line contains *b* distinct integers — the numbers of the apples Alexander likes.
Assume that the apples are numbered from 1 to *n*. The input is such that the answer exists.
Output Specification:
Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.
Demo Input:
['4 2 3\n1 2\n2 3 4\n', '5 5 2\n3 4 1 2 5\n2 3\n']
Demo Output:
['1 1 2 2\n', '1 1 1 1 1\n']
Note:
none | ```python
n,a,b=map(int,input().split())
alikes=list(map(int,input().split()))
blikes=list(map(int,input().split()))
s=""
for i in range(1,n+1):
if (i in alikes):
s+="1 "
else:
s+="2 "
print(s.strip())
``` | 3 |
|
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,669,369,569 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 3 | 124 | 0 | def solve():
a = int(input())
return 360 % (180 - a) == 0 and 360 // (180 - a) >= 3
for _ in range(int(input())):
print("YES" if solve() else "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
def solve():
a = int(input())
return 360 % (180 - a) == 0 and 360 // (180 - a) >= 3
for _ in range(int(input())):
print("YES" if solve() else "NO")
``` | 3 |
|
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,658,388,847 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | x = input()
l = 0
u = 0
for i in x:
if i.islower():
l += 1
elif i.isupper():
u += 1
else:
continue
if l > u:
print(x.lower())
elif l < u:
print(x.upper())
else:
print(x.lower())
| 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
x = input()
l = 0
u = 0
for i in x:
if i.islower():
l += 1
elif i.isupper():
u += 1
else:
continue
if l > u:
print(x.lower())
elif l < u:
print(x.upper())
else:
print(x.lower())
``` | 3.977 |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4",
"output": "9 2"
},
{
"input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8",
"output": "31 68"
},
{
"input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1",
"output": "15 15"
},
{
"input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2",
"output": "27 13"
},
{
"input": "4\n1 3 2 4\n4\n3 1 2 3",
"output": "8 12"
},
{
"input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2",
"output": "15 17"
}
] | 1,620,972,643 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 16,179,200 | import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
int_r = lambda: int(sys.stdin.readline())
str_r = lambda: sys.stdin.readline().strip()
intList_r = lambda: list(map(int, sys.stdin.readline().strip().split()))
strList_r = lambda: list(sys.stdin.readline().strip())
jn = lambda x, l: x.join(map(str, l))
mul = lambda: map(int, sys.stdin.readline().strip().split())
mulf = lambda: map(float, sys.stdin.readline().strip().split())
ceil = lambda x: int(x) if (x == int(x)) else int(x) + 1
ceildiv = lambda x, d: x // d if (x % d == 0) else x // d + 1
flush = lambda: stdout.flush()
outStr = lambda x: stdout.write(str(x))
mod = 1000000007
def main():
n = int_r()
arr = intList_r()
m = int_r()
query = intList_r()
V = 0
P = 0
for mi in query:
i = 0
j = n - 1
while i <= j:
# print(V, P)
if arr[i] == mi and arr[j] == mi:
V += i + 1
P += j + 1
break
elif arr[i] == mi:
V += i + 1
P += n - i
break
elif arr[j] == mi:
P += n - j
V += j + 1
break
i += 1
j -= 1
outStr("{} {}".format(V, P))
if __name__ == "__main__":
main() | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is.
Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent.
To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand.
But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Output Specification:
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Demo Input:
['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n']
Demo Output:
['1 2\n', '2 1\n', '6 6\n']
Note:
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element). | ```python
import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
int_r = lambda: int(sys.stdin.readline())
str_r = lambda: sys.stdin.readline().strip()
intList_r = lambda: list(map(int, sys.stdin.readline().strip().split()))
strList_r = lambda: list(sys.stdin.readline().strip())
jn = lambda x, l: x.join(map(str, l))
mul = lambda: map(int, sys.stdin.readline().strip().split())
mulf = lambda: map(float, sys.stdin.readline().strip().split())
ceil = lambda x: int(x) if (x == int(x)) else int(x) + 1
ceildiv = lambda x, d: x // d if (x % d == 0) else x // d + 1
flush = lambda: stdout.flush()
outStr = lambda x: stdout.write(str(x))
mod = 1000000007
def main():
n = int_r()
arr = intList_r()
m = int_r()
query = intList_r()
V = 0
P = 0
for mi in query:
i = 0
j = n - 1
while i <= j:
# print(V, P)
if arr[i] == mi and arr[j] == mi:
V += i + 1
P += j + 1
break
elif arr[i] == mi:
V += i + 1
P += n - i
break
elif arr[j] == mi:
P += n - j
V += j + 1
break
i += 1
j -= 1
outStr("{} {}".format(V, P))
if __name__ == "__main__":
main()
``` | 0 |
|
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"output": "6"
},
{
"input": "11 562314608",
"output": "39916800"
},
{
"input": "3 990639260",
"output": "6"
},
{
"input": "11 859155400",
"output": "39916800"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "5 3",
"output": "6"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "5 4",
"output": "24"
},
{
"input": "1 12",
"output": "1"
},
{
"input": "9 7",
"output": "5040"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "6 11",
"output": "720"
},
{
"input": "6 7",
"output": "720"
},
{
"input": "11 11",
"output": "39916800"
},
{
"input": "4 999832660",
"output": "24"
},
{
"input": "7 999228288",
"output": "5040"
},
{
"input": "11 999257105",
"output": "39916800"
},
{
"input": "11 999286606",
"output": "39916800"
},
{
"input": "3 999279109",
"output": "6"
},
{
"input": "999632727 11",
"output": "39916800"
},
{
"input": "999625230 7",
"output": "5040"
},
{
"input": "999617047 3",
"output": "6"
},
{
"input": "999646548 7",
"output": "5040"
},
{
"input": "999639051 3",
"output": "6"
},
{
"input": "12 12",
"output": "479001600"
},
{
"input": "12 1",
"output": "1"
},
{
"input": "1213 5",
"output": "120"
},
{
"input": "8 9",
"output": "40320"
},
{
"input": "12 9",
"output": "362880"
},
{
"input": "12 1000000000",
"output": "479001600"
},
{
"input": "1000000000 1",
"output": "1"
},
{
"input": "12 13",
"output": "479001600"
},
{
"input": "2 29845",
"output": "2"
},
{
"input": "10 21",
"output": "3628800"
},
{
"input": "12 20",
"output": "479001600"
},
{
"input": "15 12",
"output": "479001600"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000 12",
"output": "479001600"
},
{
"input": "11 30",
"output": "39916800"
},
{
"input": "17 12",
"output": "479001600"
},
{
"input": "4 19",
"output": "24"
},
{
"input": "12 15",
"output": "479001600"
},
{
"input": "20 6",
"output": "720"
},
{
"input": "10 20",
"output": "3628800"
},
{
"input": "10 10",
"output": "3628800"
},
{
"input": "22 12",
"output": "479001600"
},
{
"input": "20 12",
"output": "479001600"
},
{
"input": "12 23",
"output": "479001600"
},
{
"input": "12 22",
"output": "479001600"
},
{
"input": "18 3",
"output": "6"
},
{
"input": "14 10",
"output": "3628800"
},
{
"input": "14 12",
"output": "479001600"
},
{
"input": "8 3",
"output": "6"
},
{
"input": "5 5",
"output": "120"
}
] | 1,662,142,535 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 1,331,200 | from math import factorial
(a,b)=[int(x) for x in input().split()]
f=factorial(a)
s=factorial(b)
while s:
f,s=s,f%s
print(f) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
Input Specification:
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Output Specification:
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
Demo Input:
['4 3\n']
Demo Output:
['6\n']
Note:
Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | ```python
from math import factorial
(a,b)=[int(x) for x in input().split()]
f=factorial(a)
s=factorial(b)
while s:
f,s=s,f%s
print(f)
``` | 0 |
|
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"input": "10\n68 47 67 29 63 71 71 65 54 56",
"output": "10"
},
{
"input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92",
"output": "4"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14",
"output": "0"
},
{
"input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42",
"output": "7"
},
{
"input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99",
"output": "47"
},
{
"input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57",
"output": "50"
},
{
"input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13",
"output": "3"
},
{
"input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36",
"output": "3"
},
{
"input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73",
"output": "73"
},
{
"input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68",
"output": "7"
},
{
"input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94",
"output": "15"
},
{
"input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64",
"output": "104"
},
{
"input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97",
"output": "33"
},
{
"input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43",
"output": "145"
},
{
"input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26",
"output": "76"
},
{
"input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34",
"output": "15"
},
{
"input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81",
"output": "11"
},
{
"input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95",
"output": "13"
},
{
"input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15",
"output": "104"
},
{
"input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67",
"output": "100"
},
{
"input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32",
"output": "107"
},
{
"input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22",
"output": "50"
},
{
"input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61",
"output": "59"
},
{
"input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95",
"output": "99"
},
{
"input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "2\n100 99",
"output": "0"
},
{
"input": "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": "197"
},
{
"input": "100\n87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87",
"output": "0"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 3 2",
"output": "2"
}
] | 1,696,489,418 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n = int(input())
lst=list(map(int, input().split()))
c=0
m=min(lst)
M=max(lst)
while lst.index(m) != -1:
lst[lst.index(m)],lst[lst.index(m)+1] = lst[lst.index(m)+1], lst[lst.index(m)]
c+= 1
while list.index(M) != 0:
lst[lst.index(M)],lst[lst.index(M) +1]=lst[lst.index(M) +1], lst[lst.index(M)]
c+=1
print(c) | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
Input Specification:
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Output Specification:
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
Demo Input:
['4\n33 44 11 22\n', '7\n10 10 58 31 63 40 76\n']
Demo Output:
['2\n', '10\n']
Note:
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | ```python
n = int(input())
lst=list(map(int, input().split()))
c=0
m=min(lst)
M=max(lst)
while lst.index(m) != -1:
lst[lst.index(m)],lst[lst.index(m)+1] = lst[lst.index(m)+1], lst[lst.index(m)]
c+= 1
while list.index(M) != 0:
lst[lst.index(M)],lst[lst.index(M) +1]=lst[lst.index(M) +1], lst[lst.index(M)]
c+=1
print(c)
``` | -1 |
|
916 | A | Jamie and Alarm Snooze | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.
A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky.
Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*.
Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'.
Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00. | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60).
The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59). | Print the minimum number of times he needs to press the button. | [
"3\n11 23\n",
"5\n01 07\n"
] | [
"2\n",
"0\n"
] | In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. | 500 | [
{
"input": "3\n11 23",
"output": "2"
},
{
"input": "5\n01 07",
"output": "0"
},
{
"input": "34\n09 24",
"output": "3"
},
{
"input": "2\n14 37",
"output": "0"
},
{
"input": "14\n19 54",
"output": "9"
},
{
"input": "42\n15 44",
"output": "12"
},
{
"input": "46\n02 43",
"output": "1"
},
{
"input": "14\n06 41",
"output": "1"
},
{
"input": "26\n04 58",
"output": "26"
},
{
"input": "54\n16 47",
"output": "0"
},
{
"input": "38\n20 01",
"output": "3"
},
{
"input": "11\n02 05",
"output": "8"
},
{
"input": "55\n22 10",
"output": "5"
},
{
"input": "23\n10 08",
"output": "6"
},
{
"input": "23\n23 14",
"output": "9"
},
{
"input": "51\n03 27",
"output": "0"
},
{
"input": "35\n15 25",
"output": "13"
},
{
"input": "3\n12 15",
"output": "6"
},
{
"input": "47\n00 28",
"output": "3"
},
{
"input": "31\n13 34",
"output": "7"
},
{
"input": "59\n17 32",
"output": "0"
},
{
"input": "25\n11 03",
"output": "8"
},
{
"input": "9\n16 53",
"output": "4"
},
{
"input": "53\n04 06",
"output": "3"
},
{
"input": "37\n00 12",
"output": "5"
},
{
"input": "5\n13 10",
"output": "63"
},
{
"input": "50\n01 59",
"output": "10"
},
{
"input": "34\n06 13",
"output": "4"
},
{
"input": "2\n18 19",
"output": "1"
},
{
"input": "46\n06 16",
"output": "17"
},
{
"input": "14\n03 30",
"output": "41"
},
{
"input": "40\n13 37",
"output": "0"
},
{
"input": "24\n17 51",
"output": "0"
},
{
"input": "8\n14 57",
"output": "0"
},
{
"input": "52\n18 54",
"output": "2"
},
{
"input": "20\n15 52",
"output": "24"
},
{
"input": "20\n03 58",
"output": "30"
},
{
"input": "48\n07 11",
"output": "0"
},
{
"input": "32\n04 01",
"output": "2"
},
{
"input": "60\n08 15",
"output": "1"
},
{
"input": "44\n20 20",
"output": "4"
},
{
"input": "55\n15 35",
"output": "9"
},
{
"input": "55\n03 49",
"output": "11"
},
{
"input": "23\n16 39",
"output": "4"
},
{
"input": "7\n20 36",
"output": "7"
},
{
"input": "35\n16 42",
"output": "1"
},
{
"input": "35\n05 56",
"output": "21"
},
{
"input": "3\n17 45",
"output": "0"
},
{
"input": "47\n05 59",
"output": "6"
},
{
"input": "15\n10 13",
"output": "9"
},
{
"input": "59\n06 18",
"output": "9"
},
{
"input": "34\n17 18",
"output": "0"
},
{
"input": "18\n05 23",
"output": "2"
},
{
"input": "46\n17 21",
"output": "0"
},
{
"input": "30\n06 27",
"output": "0"
},
{
"input": "14\n18 40",
"output": "3"
},
{
"input": "58\n22 54",
"output": "6"
},
{
"input": "26\n19 44",
"output": "5"
},
{
"input": "10\n15 57",
"output": "0"
},
{
"input": "54\n20 47",
"output": "0"
},
{
"input": "22\n08 45",
"output": "3"
},
{
"input": "48\n18 08",
"output": "1"
},
{
"input": "32\n07 06",
"output": "0"
},
{
"input": "60\n19 19",
"output": "2"
},
{
"input": "45\n07 25",
"output": "0"
},
{
"input": "29\n12 39",
"output": "8"
},
{
"input": "13\n08 28",
"output": "3"
},
{
"input": "41\n21 42",
"output": "5"
},
{
"input": "41\n09 32",
"output": "3"
},
{
"input": "9\n21 45",
"output": "2"
},
{
"input": "37\n10 43",
"output": "5"
},
{
"input": "3\n20 50",
"output": "1"
},
{
"input": "47\n00 04",
"output": "1"
},
{
"input": "15\n13 10",
"output": "21"
},
{
"input": "15\n17 23",
"output": "0"
},
{
"input": "43\n22 13",
"output": "2"
},
{
"input": "27\n10 26",
"output": "6"
},
{
"input": "55\n22 24",
"output": "5"
},
{
"input": "55\n03 30",
"output": "11"
},
{
"input": "24\n23 27",
"output": "0"
},
{
"input": "52\n11 33",
"output": "3"
},
{
"input": "18\n22 48",
"output": "17"
},
{
"input": "1\n12 55",
"output": "8"
},
{
"input": "1\n04 27",
"output": "0"
},
{
"input": "1\n12 52",
"output": "5"
},
{
"input": "1\n20 16",
"output": "9"
},
{
"input": "1\n04 41",
"output": "4"
},
{
"input": "1\n20 21",
"output": "4"
},
{
"input": "1\n04 45",
"output": "8"
},
{
"input": "1\n12 18",
"output": "1"
},
{
"input": "1\n04 42",
"output": "5"
},
{
"input": "1\n02 59",
"output": "2"
},
{
"input": "1\n18 24",
"output": "7"
},
{
"input": "1\n02 04",
"output": "7"
},
{
"input": "1\n18 28",
"output": "1"
},
{
"input": "1\n18 01",
"output": "2"
},
{
"input": "1\n10 25",
"output": "8"
},
{
"input": "1\n02 49",
"output": "2"
},
{
"input": "1\n02 30",
"output": "3"
},
{
"input": "1\n18 54",
"output": "7"
},
{
"input": "1\n02 19",
"output": "2"
},
{
"input": "1\n05 25",
"output": "8"
},
{
"input": "60\n23 55",
"output": "6"
},
{
"input": "60\n08 19",
"output": "1"
},
{
"input": "60\n00 00",
"output": "7"
},
{
"input": "60\n08 24",
"output": "1"
},
{
"input": "60\n16 13",
"output": "9"
},
{
"input": "60\n08 21",
"output": "1"
},
{
"input": "60\n16 45",
"output": "9"
},
{
"input": "60\n08 26",
"output": "1"
},
{
"input": "60\n08 50",
"output": "1"
},
{
"input": "60\n05 21",
"output": "12"
},
{
"input": "60\n13 29",
"output": "6"
},
{
"input": "60\n05 18",
"output": "12"
},
{
"input": "60\n13 42",
"output": "6"
},
{
"input": "60\n05 07",
"output": "0"
},
{
"input": "60\n05 47",
"output": "0"
},
{
"input": "60\n21 55",
"output": "4"
},
{
"input": "60\n05 36",
"output": "12"
},
{
"input": "60\n21 08",
"output": "4"
},
{
"input": "60\n21 32",
"output": "4"
},
{
"input": "60\n16 31",
"output": "9"
},
{
"input": "5\n00 00",
"output": "73"
},
{
"input": "2\n06 58",
"output": "390"
},
{
"input": "60\n00 00",
"output": "7"
},
{
"input": "2\n00 00",
"output": "181"
},
{
"input": "10\n00 00",
"output": "37"
},
{
"input": "60\n01 00",
"output": "8"
},
{
"input": "12\n00 06",
"output": "31"
},
{
"input": "1\n00 01",
"output": "4"
},
{
"input": "5\n00 05",
"output": "74"
},
{
"input": "60\n01 01",
"output": "8"
},
{
"input": "11\n18 11",
"output": "2"
},
{
"input": "60\n01 15",
"output": "8"
},
{
"input": "10\n00 16",
"output": "38"
},
{
"input": "60\n00 59",
"output": "7"
},
{
"input": "30\n00 00",
"output": "13"
},
{
"input": "60\n01 05",
"output": "8"
},
{
"input": "4\n00 03",
"output": "4"
},
{
"input": "4\n00 00",
"output": "91"
},
{
"input": "60\n00 01",
"output": "7"
},
{
"input": "6\n00 03",
"output": "1"
},
{
"input": "13\n00 00",
"output": "1"
},
{
"input": "1\n18 01",
"output": "2"
},
{
"input": "5\n06 00",
"output": "145"
},
{
"input": "60\n04 08",
"output": "11"
},
{
"input": "5\n01 55",
"output": "96"
},
{
"input": "8\n00 08",
"output": "47"
},
{
"input": "23\n18 23",
"output": "2"
},
{
"input": "6\n00 06",
"output": "62"
},
{
"input": "59\n18 59",
"output": "2"
},
{
"input": "11\n00 10",
"output": "3"
},
{
"input": "10\n00 01",
"output": "37"
},
{
"input": "59\n00 00",
"output": "7"
},
{
"input": "10\n18 10",
"output": "2"
},
{
"input": "5\n00 01",
"output": "73"
},
{
"input": "1\n00 00",
"output": "3"
},
{
"input": "8\n00 14",
"output": "47"
},
{
"input": "60\n03 00",
"output": "10"
},
{
"input": "60\n00 10",
"output": "7"
},
{
"input": "5\n01 13",
"output": "87"
},
{
"input": "30\n02 43",
"output": "18"
},
{
"input": "17\n00 08",
"output": "3"
},
{
"input": "3\n00 00",
"output": "1"
},
{
"input": "60\n00 05",
"output": "7"
},
{
"input": "5\n18 05",
"output": "2"
},
{
"input": "30\n00 30",
"output": "14"
},
{
"input": "1\n00 06",
"output": "9"
},
{
"input": "55\n00 00",
"output": "7"
},
{
"input": "8\n02 08",
"output": "62"
},
{
"input": "7\n00 00",
"output": "9"
},
{
"input": "6\n08 06",
"output": "2"
},
{
"input": "48\n06 24",
"output": "16"
},
{
"input": "8\n06 58",
"output": "98"
},
{
"input": "3\n12 00",
"output": "1"
},
{
"input": "5\n01 06",
"output": "86"
},
{
"input": "2\n00 08",
"output": "185"
},
{
"input": "3\n18 03",
"output": "2"
},
{
"input": "1\n17 00",
"output": "0"
},
{
"input": "59\n00 48",
"output": "7"
},
{
"input": "5\n12 01",
"output": "49"
},
{
"input": "55\n01 25",
"output": "9"
},
{
"input": "2\n07 23",
"output": "0"
},
{
"input": "10\n01 10",
"output": "44"
},
{
"input": "2\n00 01",
"output": "2"
},
{
"input": "59\n00 01",
"output": "6"
},
{
"input": "5\n00 02",
"output": "1"
},
{
"input": "4\n01 02",
"output": "106"
},
{
"input": "5\n00 06",
"output": "74"
},
{
"input": "42\n00 08",
"output": "9"
},
{
"input": "60\n01 20",
"output": "8"
},
{
"input": "3\n06 00",
"output": "1"
},
{
"input": "4\n00 01",
"output": "1"
},
{
"input": "2\n00 06",
"output": "184"
},
{
"input": "1\n00 57",
"output": "0"
},
{
"input": "6\n00 00",
"output": "61"
},
{
"input": "5\n08 40",
"output": "9"
},
{
"input": "58\n00 55",
"output": "1"
},
{
"input": "2\n00 02",
"output": "182"
},
{
"input": "1\n08 01",
"output": "2"
},
{
"input": "10\n10 10",
"output": "14"
},
{
"input": "60\n01 11",
"output": "8"
},
{
"input": "2\n07 00",
"output": "0"
},
{
"input": "15\n00 03",
"output": "25"
},
{
"input": "6\n04 34",
"output": "106"
},
{
"input": "16\n00 16",
"output": "24"
},
{
"input": "2\n00 59",
"output": "1"
},
{
"input": "59\n00 08",
"output": "7"
},
{
"input": "10\n03 10",
"output": "56"
},
{
"input": "3\n08 03",
"output": "2"
},
{
"input": "20\n06 11",
"output": "37"
},
{
"input": "4\n01 00",
"output": "106"
},
{
"input": "38\n01 08",
"output": "12"
},
{
"input": "60\n00 06",
"output": "7"
},
{
"input": "5\n12 00",
"output": "49"
},
{
"input": "6\n01 42",
"output": "78"
},
{
"input": "4\n00 04",
"output": "92"
},
{
"input": "60\n04 05",
"output": "11"
},
{
"input": "1\n00 53",
"output": "6"
},
{
"input": "5\n08 05",
"output": "2"
},
{
"input": "60\n18 45",
"output": "1"
},
{
"input": "60\n06 23",
"output": "13"
},
{
"input": "6\n00 15",
"output": "3"
},
{
"input": "58\n00 06",
"output": "7"
},
{
"input": "2\n06 44",
"output": "383"
},
{
"input": "1\n08 00",
"output": "1"
},
{
"input": "10\n06 58",
"output": "78"
},
{
"input": "59\n00 58",
"output": "8"
},
{
"input": "1\n18 00",
"output": "1"
},
{
"input": "50\n00 42",
"output": "9"
},
{
"input": "30\n18 30",
"output": "2"
},
{
"input": "60\n21 59",
"output": "4"
},
{
"input": "2\n10 52",
"output": "87"
},
{
"input": "56\n00 00",
"output": "7"
},
{
"input": "16\n18 16",
"output": "2"
},
{
"input": "5\n01 05",
"output": "86"
},
{
"input": "5\n05 00",
"output": "133"
},
{
"input": "5\n23 59",
"output": "72"
},
{
"input": "7\n17 13",
"output": "0"
},
{
"input": "58\n00 00",
"output": "7"
},
{
"input": "15\n00 07",
"output": "0"
},
{
"input": "59\n08 00",
"output": "1"
},
{
"input": "46\n00 00",
"output": "8"
},
{
"input": "59\n01 05",
"output": "2"
},
{
"input": "2\n01 00",
"output": "211"
},
{
"input": "60\n00 24",
"output": "7"
},
{
"input": "10\n00 08",
"output": "37"
},
{
"input": "10\n00 06",
"output": "37"
},
{
"input": "60\n01 24",
"output": "8"
},
{
"input": "50\n00 10",
"output": "8"
},
{
"input": "2\n03 00",
"output": "271"
},
{
"input": "4\n19 04",
"output": "17"
},
{
"input": "25\n00 23",
"output": "16"
},
{
"input": "10\n01 01",
"output": "43"
}
] | 1,516,376,085 | 3,585 | Python 3 | OK | TESTS | 254 | 77 | 5,632,000 | def counting(hour,minu,inc):
count=0
h=hour
m=minu
x=inc
flag=1
while(flag):
if '7' in str(m) or '7' in str(h):
print(count)
flag=0
else:
if (m-x)<0:
temp=m-x
tem=60+temp
m=tem
if(h-1)<0:
h=23
else:
h-=1
count+=1
else:
m-=x
count+=1
x=int(input().strip())
h,m=[int(t) for t in input().strip().split(' ')]
counting(h,m,x) | Title: Jamie and Alarm Snooze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.
A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky.
Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*.
Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'.
Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00.
Input Specification:
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60).
The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59).
Output Specification:
Print the minimum number of times he needs to press the button.
Demo Input:
['3\n11 23\n', '5\n01 07\n']
Demo Output:
['2\n', '0\n']
Note:
In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. | ```python
def counting(hour,minu,inc):
count=0
h=hour
m=minu
x=inc
flag=1
while(flag):
if '7' in str(m) or '7' in str(h):
print(count)
flag=0
else:
if (m-x)<0:
temp=m-x
tem=60+temp
m=tem
if(h-1)<0:
h=23
else:
h-=1
count+=1
else:
m-=x
count+=1
x=int(input().strip())
h,m=[int(t) for t in input().strip().split(' ')]
counting(h,m,x)
``` | 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,631,824,823 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 6,963,200 | n = int(input())
travel = input()
lst = list(travel)
count = 0
count_ = 0
for i in range (n-1):
if lst[i] == "S" or "s" and lst[i+1] == "F" or "f":
count += 1
elif lst[i] == "F" or "f" and lst[i+1] == "S" or "s":
count_ += 1
if count > count_:
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
n = int(input())
travel = input()
lst = list(travel)
count = 0
count_ = 0
for i in range (n-1):
if lst[i] == "S" or "s" and lst[i+1] == "F" or "f":
count += 1
elif lst[i] == "F" or "f" and lst[i+1] == "S" or "s":
count_ += 1
if count > count_:
print("YES")
else:
print("NO")
``` | 0 |
|
888 | C | K-Dominant Character | PROGRAMMING | 1,400 | [
"binary search",
"implementation",
"two pointers"
] | null | null | You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* such that there exists at least one *k*-dominant character. | The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000). | Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character. | [
"abacaba\n",
"zzzzz\n",
"abcde\n"
] | [
"2\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "2"
},
{
"input": "zzzzz",
"output": "1"
},
{
"input": "abcde",
"output": "3"
},
{
"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab",
"output": "8"
},
{
"input": "daabcdabbabbacacbaacabacbcaabaacac",
"output": "4"
},
{
"input": "abghim",
"output": "4"
},
{
"input": "gfliflgfhhdkceacdljgkegmdlhcgkcmlelmbbbmdddgdeeljjhgbbffmemmmkhebgkhadkdajabcjkcgbkgbaeacdedlkklfech",
"output": "17"
},
{
"input": "a",
"output": "1"
},
{
"input": "aaabbb",
"output": "4"
},
{
"input": "ab",
"output": "2"
},
{
"input": "abbb",
"output": "2"
},
{
"input": "ob",
"output": "2"
},
{
"input": "abccba",
"output": "3"
},
{
"input": "saaaaaaaas",
"output": "2"
},
{
"input": "axxx",
"output": "2"
},
{
"input": "abcba",
"output": "2"
},
{
"input": "abb",
"output": "2"
},
{
"input": "abcdea",
"output": "4"
},
{
"input": "axcbb",
"output": "3"
},
{
"input": "tmivvdcbbfrfogjviirrximhttoskopwrcmkcborcxvr",
"output": "13"
},
{
"input": "dlchmmuateksgldkckljrovmeuniobjrelqjpnjljlvhpqrjsfklliqpufplgaelevmlcnodbllquubobecem",
"output": "15"
},
{
"input": "zx",
"output": "2"
},
{
"input": "zxz",
"output": "2"
},
{
"input": "bbhdgaefbhf",
"output": "6"
},
{
"input": "xx",
"output": "1"
},
{
"input": "zxx",
"output": "2"
},
{
"input": "cbcada",
"output": "4"
},
{
"input": "z",
"output": "1"
},
{
"input": "aab",
"output": "2"
},
{
"input": "jficc",
"output": "3"
},
{
"input": "cceeaabfba",
"output": "5"
},
{
"input": "jk",
"output": "2"
},
{
"input": "lzeznbwu",
"output": "5"
},
{
"input": "rr",
"output": "1"
}
] | 1,625,402,974 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | import math
s = input()
last_index = []
for i in range(26):
last_index.append(-1)
k = math.ceil((len(s) + 1) / 2)
for i in range(len(s)):
j = ord(s[i]) - ord('a')
if last_index[j] != -1:
k = min(k, i - last_index[j])
last_index[j] = i
print(k) | Title: K-Dominant Character
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* such that there exists at least one *k*-dominant character.
Input Specification:
The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000).
Output Specification:
Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character.
Demo Input:
['abacaba\n', 'zzzzz\n', 'abcde\n']
Demo Output:
['2\n', '1\n', '3\n']
Note:
none | ```python
import math
s = input()
last_index = []
for i in range(26):
last_index.append(-1)
k = math.ceil((len(s) + 1) / 2)
for i in range(len(s)):
j = ord(s[i]) - ord('a')
if last_index[j] != -1:
k = min(k, i - last_index[j])
last_index[j] = i
print(k)
``` | 0 |
|
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"input": "2 3",
"output": "2 0 4"
},
{
"input": "5 6",
"output": "5 0 1"
},
{
"input": "4 4",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
},
{
"input": "6 4",
"output": "1 1 4"
},
{
"input": "1 4",
"output": "2 0 4"
},
{
"input": "5 5",
"output": "0 6 0"
},
{
"input": "4 5",
"output": "4 0 2"
},
{
"input": "4 3",
"output": "3 0 3"
},
{
"input": "1 5",
"output": "2 1 3"
},
{
"input": "6 5",
"output": "1 0 5"
},
{
"input": "2 2",
"output": "0 6 0"
},
{
"input": "1 3",
"output": "1 1 4"
},
{
"input": "3 6",
"output": "4 0 2"
},
{
"input": "3 1",
"output": "4 1 1"
},
{
"input": "3 2",
"output": "4 0 2"
},
{
"input": "3 5",
"output": "3 1 2"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "6 2",
"output": "2 1 3"
},
{
"input": "4 1",
"output": "4 0 2"
},
{
"input": "5 2",
"output": "3 0 3"
},
{
"input": "4 2",
"output": "3 1 2"
},
{
"input": "2 1",
"output": "5 0 1"
},
{
"input": "6 1",
"output": "3 0 3"
},
{
"input": "4 6",
"output": "4 1 1"
},
{
"input": "2 6",
"output": "3 1 2"
},
{
"input": "3 4",
"output": "3 0 3"
},
{
"input": "1 2",
"output": "1 0 5"
},
{
"input": "6 6",
"output": "0 6 0"
},
{
"input": "5 4",
"output": "2 0 4"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
}
] | 1,567,808,031 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 140 | 102,400 | input_ = [int(i) for i in input().split()]
player_1 = input_[0]
player_2 = input_[1]
player_1_win = 0
player_2_win = 0
tie = 0
for i in range(1,7):
if abs(i - player_1) < abs(i - player_2):
player_1_win += 1
elif abs(i - player_1) > abs(i - player_2):
player_2_win += 1
else:
tie += 1
print(player_1_win, tie, player_2_win)
| Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
Input Specification:
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Output Specification:
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
Demo Input:
['2 5\n', '2 4\n']
Demo Output:
['3 0 3\n', '2 1 3\n']
Note:
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | ```python
input_ = [int(i) for i in input().split()]
player_1 = input_[0]
player_2 = input_[1]
player_1_win = 0
player_2_win = 0
tie = 0
for i in range(1,7):
if abs(i - player_1) < abs(i - player_2):
player_1_win += 1
elif abs(i - player_1) > abs(i - player_2):
player_2_win += 1
else:
tie += 1
print(player_1_win, tie, player_2_win)
``` | 3 |
|
784 | A | Numbers Joke | PROGRAMMING | 1,700 | [
"*special"
] | null | null | The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output a single integer. | The input contains a single integer *a* (1<=≤<=*a*<=≤<=30). | Output a single integer. | [
"3\n"
] | [
"27\n"
] | none | 0 | [
{
"input": "3",
"output": "27"
},
{
"input": "1",
"output": "4"
},
{
"input": "2",
"output": "22"
},
{
"input": "4",
"output": "58"
},
{
"input": "5",
"output": "85"
},
{
"input": "6",
"output": "94"
},
{
"input": "7",
"output": "121"
},
{
"input": "8",
"output": "166"
},
{
"input": "9",
"output": "202"
},
{
"input": "10",
"output": "265"
},
{
"input": "11",
"output": "274"
},
{
"input": "12",
"output": "319"
},
{
"input": "13",
"output": "346"
},
{
"input": "14",
"output": "355"
},
{
"input": "15",
"output": "378"
},
{
"input": "16",
"output": "382"
},
{
"input": "17",
"output": "391"
},
{
"input": "18",
"output": "438"
},
{
"input": "19",
"output": "454"
},
{
"input": "20",
"output": "483"
},
{
"input": "21",
"output": "517"
},
{
"input": "22",
"output": "526"
},
{
"input": "23",
"output": "535"
},
{
"input": "24",
"output": "562"
},
{
"input": "25",
"output": "576"
},
{
"input": "26",
"output": "588"
},
{
"input": "27",
"output": "627"
},
{
"input": "28",
"output": "634"
},
{
"input": "29",
"output": "636"
},
{
"input": "30",
"output": "645"
}
] | 1,527,694,965 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 77 | 6,963,200 | n=int(input())
print(int(4*((1.5*(3**.5))**(n-1)))) | Title: Numbers Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output a single integer.
Input Specification:
The input contains a single integer *a* (1<=≤<=*a*<=≤<=30).
Output Specification:
Output a single integer.
Demo Input:
['3\n']
Demo Output:
['27\n']
Note:
none | ```python
n=int(input())
print(int(4*((1.5*(3**.5))**(n-1))))
``` | 0 |
|
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1 "
},
{
"input": "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7",
"output": "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 "
},
{
"input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39",
"output": "100 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n99 98 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 \n\n\n\n\n\n\n\n\n80 79 78 77 76 75 74 73 \n72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 \n39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 "
},
{
"input": "2\n2 1",
"output": "2 \n1 "
}
] | 1,591,268,508 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | def println(li):
s = ""
to_p = sorted(li,reverse=True)
for e in to_p:
s += ' '+ str(e)
print(s.strip())
n = int(input())
a = list(map(int, input().split()))
l = [a[0]]
for i in range(n):
if i == n-1:
println(set(l))
elif a[i] < a[i+1]:
l.append(a[i])
l.append(a[i+1])
else:
println(set(l))
l = []
| Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Output Specification:
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Demo Input:
['3\n3 1 2\n', '5\n4 5 1 2 3\n']
Demo Output:
['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n']
Note:
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | ```python
def println(li):
s = ""
to_p = sorted(li,reverse=True)
for e in to_p:
s += ' '+ str(e)
print(s.strip())
n = int(input())
a = list(map(int, input().split()))
l = [a[0]]
for i in range(n):
if i == n-1:
println(set(l))
elif a[i] < a[i+1]:
l.append(a[i])
l.append(a[i+1])
else:
println(set(l))
l = []
``` | 0 |
|
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
{
"input": "20\n44444444444444444444",
"output": "YES"
},
{
"input": "2\n44",
"output": "YES"
},
{
"input": "10\n4745474547",
"output": "NO"
},
{
"input": "14\n77770004444444",
"output": "NO"
},
{
"input": "10\n4747777744",
"output": "YES"
},
{
"input": "10\n1234567890",
"output": "NO"
},
{
"input": "50\n44444444444444444444444444444444444444444444444444",
"output": "YES"
},
{
"input": "50\n44444444444444444444444444444444444444444444444447",
"output": "NO"
},
{
"input": "50\n74444444444444444444444444444444444444444444444444",
"output": "NO"
},
{
"input": "50\n07777777777777777777777777777777777777777777777770",
"output": "NO"
},
{
"input": "50\n77777777777777777777777777777777777777777777777777",
"output": "YES"
},
{
"input": "50\n44747747774474747747747447777447774747447477444474",
"output": "YES"
},
{
"input": "48\n447474444777444474747747744774447444747474774474",
"output": "YES"
},
{
"input": "32\n74474474777444474444747774474774",
"output": "YES"
},
{
"input": "40\n4747777444447747777447447747447474774777",
"output": "YES"
},
{
"input": "10\n4477477444",
"output": "YES"
},
{
"input": "18\n447747474447744747",
"output": "YES"
},
{
"input": "26\n44747744444774744774474447",
"output": "YES"
},
{
"input": "50\n44707747774474747747747447777447774747447477444474",
"output": "NO"
},
{
"input": "40\n4747777444447737777447447747447474774777",
"output": "NO"
},
{
"input": "36\n764477744747444444447747747474744444",
"output": "NO"
},
{
"input": "22\n4477407474777477744447",
"output": "NO"
},
{
"input": "32\n74274474777444474444747774474774",
"output": "NO"
},
{
"input": "16\n4744447974444747",
"output": "NO"
},
{
"input": "2\n11",
"output": "NO"
},
{
"input": "2\n22",
"output": "NO"
},
{
"input": "2\n33",
"output": "NO"
},
{
"input": "2\n74",
"output": "NO"
},
{
"input": "2\n55",
"output": "NO"
},
{
"input": "2\n66",
"output": "NO"
},
{
"input": "2\n77",
"output": "YES"
},
{
"input": "2\n88",
"output": "NO"
},
{
"input": "2\n99",
"output": "NO"
},
{
"input": "4\n4004",
"output": "NO"
},
{
"input": "14\n00077774444444",
"output": "NO"
},
{
"input": "6\n004444",
"output": "NO"
},
{
"input": "4\n0044",
"output": "NO"
},
{
"input": "14\n77771114444444",
"output": "NO"
},
{
"input": "14\n44444447777000",
"output": "NO"
},
{
"input": "6\n004774",
"output": "NO"
}
] | 1,685,630,664 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | first_sum=second_sum=0
length=int(input())
ticket=list(map(int,input()))
first=(len (ticket))//2
for i in range(first):
first_sum+=ticket[i]
for i in range(first, len(ticket)):
second_sum+=ticket[i]
def check(arg):
for char in ticket:
if char!=4 and char!=7:
return False
return True
if check(ticket)==True and first_sum==second_sum:
print('Yes')
elif check(ticket)==False:
print('No') | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
Input Specification:
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
Output Specification:
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['2\n47\n', '4\n4738\n', '4\n4774\n']
Demo Output:
['NO\n', 'NO\n', 'YES\n']
Note:
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | ```python
first_sum=second_sum=0
length=int(input())
ticket=list(map(int,input()))
first=(len (ticket))//2
for i in range(first):
first_sum+=ticket[i]
for i in range(first, len(ticket)):
second_sum+=ticket[i]
def check(arg):
for char in ticket:
if char!=4 and char!=7:
return False
return True
if check(ticket)==True and first_sum==second_sum:
print('Yes')
elif check(ticket)==False:
print('No')
``` | 0 |
|
446 | A | DZY Loves Sequences | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"two pointers"
] | null | null | DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | In a single line print the answer to the problem — the maximum length of the required subsegment. | [
"6\n7 2 3 1 5 6\n"
] | [
"5\n"
] | You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | 500 | [
{
"input": "6\n7 2 3 1 5 6",
"output": "5"
},
{
"input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422",
"output": "9"
},
{
"input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737 35005212 521595369 294702568 726956430 336465783 861021531 59961394 89018457 101513930 125898168 131176230 145174068 233665124 278722863 315634023 369133070 468703136 628175012 635723059 653377374 656478043 801979803 859484422 914544920 608413785 756898538 734575199 973594325 149798316 38664371",
"output": "19"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "2"
},
{
"input": "5\n1 2 3 4 1",
"output": "5"
},
{
"input": "10\n1 2 3 4 5 5 6 7 8 9",
"output": "6"
},
{
"input": "5\n1 1 1 1 1",
"output": "2"
},
{
"input": "5\n1 1 2 3 4",
"output": "5"
},
{
"input": "5\n1 2 3 1 6",
"output": "5"
},
{
"input": "1\n42",
"output": "1"
},
{
"input": "5\n1 2 42 3 4",
"output": "4"
},
{
"input": "5\n1 5 9 6 10",
"output": "4"
},
{
"input": "5\n5 2 3 4 5",
"output": "5"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "5\n1 2 3 3 4",
"output": "4"
},
{
"input": "8\n1 2 3 4 1 5 6 7",
"output": "5"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "3\n5 1 2",
"output": "3"
},
{
"input": "4\n1 4 3 4",
"output": "4"
},
{
"input": "6\n7 2 12 4 5 6",
"output": "5"
},
{
"input": "6\n7 2 3 1 4 5",
"output": "4"
},
{
"input": "6\n2 3 5 5 6 7",
"output": "6"
},
{
"input": "5\n2 4 7 6 8",
"output": "5"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "5\n4 1 2 3 4",
"output": "5"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6",
"output": "7"
},
{
"input": "4\n1 2 1 3",
"output": "3"
},
{
"input": "4\n4 3 1 2",
"output": "3"
},
{
"input": "6\n1 2 2 3 4 5",
"output": "5"
},
{
"input": "4\n1 1 1 2",
"output": "3"
},
{
"input": "4\n5 1 2 3",
"output": "4"
},
{
"input": "5\n9 1 2 3 4",
"output": "5"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "5\n1 3 2 4 5",
"output": "4"
},
{
"input": "6\n1 2 1 2 4 5",
"output": "5"
},
{
"input": "10\n1 1 5 3 2 9 9 7 7 6",
"output": "3"
},
{
"input": "6\n1 2 3 100000 100 101",
"output": "6"
},
{
"input": "4\n3 3 3 4",
"output": "3"
},
{
"input": "3\n4 3 5",
"output": "3"
},
{
"input": "5\n1 3 2 3 4",
"output": "4"
},
{
"input": "10\n1 2 3 4 5 10 10 11 12 13",
"output": "10"
},
{
"input": "7\n11 2 1 2 13 4 14",
"output": "5"
},
{
"input": "3\n5 1 3",
"output": "3"
},
{
"input": "4\n1 5 3 4",
"output": "4"
},
{
"input": "10\n1 2 3 4 100 6 7 8 9 10",
"output": "10"
},
{
"input": "3\n5 3 5",
"output": "3"
},
{
"input": "5\n100 100 7 8 9",
"output": "4"
},
{
"input": "5\n1 2 3 4 5",
"output": "5"
},
{
"input": "5\n1 2 4 4 5",
"output": "5"
},
{
"input": "6\n7 4 5 6 7 8",
"output": "6"
},
{
"input": "9\n3 4 1 6 3 4 5 6 7",
"output": "7"
},
{
"input": "3\n1000 1 2",
"output": "3"
},
{
"input": "3\n20 1 9",
"output": "3"
},
{
"input": "6\n7 2 3 1 4 6",
"output": "4"
},
{
"input": "3\n100 5 10",
"output": "3"
},
{
"input": "4\n2 2 2 3",
"output": "3"
},
{
"input": "6\n4 2 8 1 2 5",
"output": "4"
},
{
"input": "3\n25 1 6",
"output": "3"
},
{
"input": "10\n17 99 23 72 78 36 5 43 95 9",
"output": "5"
},
{
"input": "7\n21 16 22 21 11 13 19",
"output": "4"
},
{
"input": "5\n1 2 5 3 4",
"output": "4"
},
{
"input": "6\n2 2 2 3 4 5",
"output": "5"
},
{
"input": "5\n1 3 1 2 3",
"output": "4"
},
{
"input": "3\n81 33 64",
"output": "3"
},
{
"input": "7\n14 3 3 19 13 19 15",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 42 7 8 9",
"output": "9"
},
{
"input": "5\n2 3 7 5 6",
"output": "5"
},
{
"input": "5\n1 3 3 4 5",
"output": "5"
},
{
"input": "6\n1 5 4 3 4 5",
"output": "4"
}
] | 1,610,516,810 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++){cin>>a[i];}
vector<int> b;
vector<int> c;
b.push_back(0);
for(int i=1;i<n;i++){
if(a[i]<=a[i-1]){
c.push_back(i-1);
b.push_back(i);
}
}
c.push_back(n-1);
if(b.size()==1){
cout<<n<<endl;
return 0;
}
int ans=1;
for(int i=1;i<b.size();i++){
int i1=b[i-1];
int j1=c[i-1];
int i2=b[i];
int j2=c[i];
if(i1==j1){ans=max(ans,j2-i2+2);}
else{
if(i2==j2){ans=max(ans,j1-i1+2);}
else{
if(a[j1]+2<=a[i2+1]||a[i2]>=a[j1-1]+2){ans=max(ans,j1-i1+j2-i2+2);}
else{ans=max(ans,max(j1-i1+2,j2-i2+2));}
}
}
}
cout<<ans;
return 0;
}
| Title: DZY Loves Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a sequence *a*, consisting of *n* integers.
We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment.
Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
In a single line print the answer to the problem — the maximum length of the required subsegment.
Demo Input:
['6\n7 2 3 1 5 6\n']
Demo Output:
['5\n']
Note:
You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4. | ```python
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++){cin>>a[i];}
vector<int> b;
vector<int> c;
b.push_back(0);
for(int i=1;i<n;i++){
if(a[i]<=a[i-1]){
c.push_back(i-1);
b.push_back(i);
}
}
c.push_back(n-1);
if(b.size()==1){
cout<<n<<endl;
return 0;
}
int ans=1;
for(int i=1;i<b.size();i++){
int i1=b[i-1];
int j1=c[i-1];
int i2=b[i];
int j2=c[i];
if(i1==j1){ans=max(ans,j2-i2+2);}
else{
if(i2==j2){ans=max(ans,j1-i1+2);}
else{
if(a[j1]+2<=a[i2+1]||a[i2]>=a[j1-1]+2){ans=max(ans,j1-i1+j2-i2+2);}
else{ans=max(ans,max(j1-i1+2,j2-i2+2));}
}
}
}
cout<<ans;
return 0;
}
``` | -1 |
|
884 | C | Bertown Subway | PROGRAMMING | 1,500 | [
"dfs and similar",
"greedy",
"math"
] | null | null | The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are *n* stations in the subway. It was built according to the Bertown Transport Law:
1. For each station *i* there exists exactly one train that goes from this station. Its destination station is *p**i*, possibly *p**i*<==<=*i*; 1. For each station *i* there exists exactly one station *j* such that *p**j*<==<=*i*.
The President will consider the convenience of subway after visiting it. The convenience is the number of ordered pairs (*x*,<=*y*) such that person can start at station *x* and, after taking some subway trains (possibly zero), arrive at station *y* (1<=≤<=*x*,<=*y*<=≤<=*n*).
The mayor of Bertown thinks that if the subway is not convenient enough, then the President might consider installing a new mayor (and, of course, the current mayor doesn't want it to happen). Before President visits the city mayor has enough time to rebuild some paths of subway, thus changing the values of *p**i* for not more than two subway stations. Of course, breaking the Bertown Transport Law is really bad, so the subway must be built according to the Law even after changes.
The mayor wants to do these changes in such a way that the convenience of the subway is maximized. Help him to calculate the maximum possible convenience he can get! | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100000) — the number of stations.
The second line contains *n* integer numbers *p*1, *p*2, ..., *p**n* (1<=≤<=*p**i*<=≤<=*n*) — the current structure of the subway. All these numbers are distinct. | Print one number — the maximum possible value of convenience. | [
"3\n2 1 3\n",
"5\n1 5 4 3 2\n"
] | [
"9\n",
"17\n"
] | In the first example the mayor can change *p*<sub class="lower-index">2</sub> to 3 and *p*<sub class="lower-index">3</sub> to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3).
In the second example the mayor can change *p*<sub class="lower-index">2</sub> to 4 and *p*<sub class="lower-index">3</sub> to 5. | 0 | [
{
"input": "3\n2 1 3",
"output": "9"
},
{
"input": "5\n1 5 4 3 2",
"output": "17"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "4"
},
{
"input": "2\n2 1",
"output": "4"
},
{
"input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39",
"output": "5416"
},
{
"input": "5\n1 4 2 3 5",
"output": "17"
},
{
"input": "6\n5 3 6 1 4 2",
"output": "36"
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "82"
},
{
"input": "20\n1 6 15 9 18 17 7 8 3 19 2 13 11 12 14 4 5 20 16 10",
"output": "326"
},
{
"input": "3\n1 2 3",
"output": "5"
}
] | 1,509,116,511 | 3,411 | Python 3 | OK | TESTS | 27 | 982 | 21,401,600 | n = int(input())
data = list(map(int,input().split()))
gp = { i:i for i in range(n) }
sets = { i:[i] for i in range(n) }
for i in range(n):
u,v = i,data[i]-1
if gp[u]!= gp[v]:
temp=gp[v]
for i in sets[gp[v]]:
gp[i]=gp[u]
sets[gp[u]].append(i)
del sets[temp]
l=[]
for i in sets:
l.append(len(sets[i]))
l.sort(reverse=True)
n=len(l)
if n==1:
print(l[0]*l[0])
else:
ans=(l[0]+l[1])**2
for i in range(2,n):
ans+=l[i]**2
print(ans)
| Title: Bertown Subway
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are *n* stations in the subway. It was built according to the Bertown Transport Law:
1. For each station *i* there exists exactly one train that goes from this station. Its destination station is *p**i*, possibly *p**i*<==<=*i*; 1. For each station *i* there exists exactly one station *j* such that *p**j*<==<=*i*.
The President will consider the convenience of subway after visiting it. The convenience is the number of ordered pairs (*x*,<=*y*) such that person can start at station *x* and, after taking some subway trains (possibly zero), arrive at station *y* (1<=≤<=*x*,<=*y*<=≤<=*n*).
The mayor of Bertown thinks that if the subway is not convenient enough, then the President might consider installing a new mayor (and, of course, the current mayor doesn't want it to happen). Before President visits the city mayor has enough time to rebuild some paths of subway, thus changing the values of *p**i* for not more than two subway stations. Of course, breaking the Bertown Transport Law is really bad, so the subway must be built according to the Law even after changes.
The mayor wants to do these changes in such a way that the convenience of the subway is maximized. Help him to calculate the maximum possible convenience he can get!
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100000) — the number of stations.
The second line contains *n* integer numbers *p*1, *p*2, ..., *p**n* (1<=≤<=*p**i*<=≤<=*n*) — the current structure of the subway. All these numbers are distinct.
Output Specification:
Print one number — the maximum possible value of convenience.
Demo Input:
['3\n2 1 3\n', '5\n1 5 4 3 2\n']
Demo Output:
['9\n', '17\n']
Note:
In the first example the mayor can change *p*<sub class="lower-index">2</sub> to 3 and *p*<sub class="lower-index">3</sub> to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3).
In the second example the mayor can change *p*<sub class="lower-index">2</sub> to 4 and *p*<sub class="lower-index">3</sub> to 5. | ```python
n = int(input())
data = list(map(int,input().split()))
gp = { i:i for i in range(n) }
sets = { i:[i] for i in range(n) }
for i in range(n):
u,v = i,data[i]-1
if gp[u]!= gp[v]:
temp=gp[v]
for i in sets[gp[v]]:
gp[i]=gp[u]
sets[gp[u]].append(i)
del sets[temp]
l=[]
for i in sets:
l.append(len(sets[i]))
l.sort(reverse=True)
n=len(l)
if n==1:
print(l[0]*l[0])
else:
ans=(l[0]+l[1])**2
for i in range(2,n):
ans+=l[i]**2
print(ans)
``` | 3 |
|
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"input": "4",
"output": "Rajesh"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "10",
"output": "Penny"
},
{
"input": "534",
"output": "Rajesh"
},
{
"input": "5033",
"output": "Howard"
},
{
"input": "10010",
"output": "Howard"
},
{
"input": "500000000",
"output": "Penny"
},
{
"input": "63",
"output": "Rajesh"
},
{
"input": "841",
"output": "Leonard"
},
{
"input": "3667",
"output": "Penny"
},
{
"input": "38614",
"output": "Howard"
},
{
"input": "282798",
"output": "Rajesh"
},
{
"input": "9266286",
"output": "Rajesh"
},
{
"input": "27385966",
"output": "Leonard"
},
{
"input": "121580142",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
},
{
"input": "300",
"output": "Howard"
},
{
"input": "1745",
"output": "Leonard"
},
{
"input": "8302",
"output": "Rajesh"
},
{
"input": "184518",
"output": "Sheldon"
},
{
"input": "1154414",
"output": "Rajesh"
},
{
"input": "28643950",
"output": "Leonard"
},
{
"input": "159222638",
"output": "Howard"
},
{
"input": "24",
"output": "Penny"
},
{
"input": "505",
"output": "Penny"
},
{
"input": "4425",
"output": "Rajesh"
},
{
"input": "12079",
"output": "Sheldon"
},
{
"input": "469726",
"output": "Penny"
},
{
"input": "3961838",
"output": "Penny"
},
{
"input": "57710446",
"output": "Leonard"
},
{
"input": "80719470",
"output": "Howard"
},
{
"input": "1000000000",
"output": "Penny"
},
{
"input": "999999999",
"output": "Penny"
},
{
"input": "999999998",
"output": "Penny"
},
{
"input": "5",
"output": "Howard"
}
] | 1,606,491,193 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 140 | 0 | import math
for _ in range(1):
s=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
n=int(input())
while(n>5):
n=(n-4)//2
print(s[n-1])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.
For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.
Write a program that will print the name of a man who will drink the *n*-th can.
Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
Input Specification:
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Output Specification:
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
Demo Input:
['1\n', '6\n', '1802\n']
Demo Output:
['Sheldon\n', 'Sheldon\n', 'Penny\n']
Note:
none | ```python
import math
for _ in range(1):
s=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
n=int(input())
while(n>5):
n=(n-4)//2
print(s[n-1])
``` | 3.93 |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25",
"output": "840"
},
{
"input": "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44",
"output": "922"
},
{
"input": "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59",
"output": "674"
},
{
"input": "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82",
"output": "848"
},
{
"input": "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93",
"output": "902"
},
{
"input": "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20",
"output": "798"
},
{
"input": "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31",
"output": "632"
},
{
"input": "1\n4",
"output": "4"
},
{
"input": "2\n1 4",
"output": "4"
},
{
"input": "3\n1 2 4",
"output": "6"
},
{
"input": "2\n9 3",
"output": "12"
},
{
"input": "2\n1000000000 1001",
"output": "1000000000"
},
{
"input": "3\n1 8 4",
"output": "12"
},
{
"input": "3\n7 4 4",
"output": "8"
},
{
"input": "5\n2 3 4 5 3",
"output": "14"
},
{
"input": "2\n4 5",
"output": "4"
},
{
"input": "3\n2 4 5",
"output": "6"
},
{
"input": "3\n2 2 3",
"output": "4"
},
{
"input": "2\n2 3",
"output": "2"
},
{
"input": "4\n2 3 7 7",
"output": "16"
},
{
"input": "2\n999999999 2",
"output": "2"
},
{
"input": "2\n2 5",
"output": "2"
},
{
"input": "3\n5 3 1",
"output": "8"
},
{
"input": "4\n3 2 5 7",
"output": "14"
}
] | 1,623,999,566 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 140 | 8,601,600 | n=int(input())
l=list(map(int,input().split()))
if sum(l)%2==0:
print(sum(l))
else:
o=0
l.sort()
for i in l:
if i%2!=0:
o=i
break
print(sum(l)-o) | Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
Input Specification:
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Output Specification:
Print the maximum possible even sum that can be obtained if we use some of the given integers.
Demo Input:
['3\n1 2 3\n', '5\n999999999 999999999 999999999 999999999 999999999\n']
Demo Output:
['6', '3999999996']
Note:
In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | ```python
n=int(input())
l=list(map(int,input().split()))
if sum(l)%2==0:
print(sum(l))
else:
o=0
l.sort()
for i in l:
if i%2!=0:
o=i
break
print(sum(l)-o)
``` | 3 |
|
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",
"output": "Yes"
},
{
"input": "365289629 223844571",
"output": "No"
},
{
"input": "247579518 361164458",
"output": "No"
},
{
"input": "424836699 793451637",
"output": "No"
},
{
"input": "602093880 930771525",
"output": "No"
},
{
"input": "779351061 773124120",
"output": "Yes"
},
{
"input": "661640950 836815080",
"output": "No"
},
{
"input": "543930839 974134967",
"output": "No"
},
{
"input": "16155311 406422145",
"output": "No"
},
{
"input": "81601559 445618240",
"output": "No"
},
{
"input": "963891449 582938127",
"output": "No"
},
{
"input": "141148629 351661795",
"output": "No"
},
{
"input": "318405810 783948974",
"output": "No"
},
{
"input": "495662991 921268861",
"output": "No"
},
{
"input": "1 0",
"output": "No"
},
{
"input": "0 1",
"output": "Yes"
},
{
"input": "0 0",
"output": "No"
},
{
"input": "453462237 167520068",
"output": "Yes"
},
{
"input": "630719418 9872663",
"output": "Yes"
},
{
"input": "807976599 442159843",
"output": "No"
},
{
"input": "690266488 579479730",
"output": "No"
},
{
"input": "771581370 589752968",
"output": "No"
},
{
"input": "948838551 727072855",
"output": "No"
},
{
"input": "831128440 790763814",
"output": "No"
},
{
"input": "303352912 928083702",
"output": "No"
},
{
"input": "185642801 65403588",
"output": "Yes"
},
{
"input": "67932690 202723476",
"output": "No"
},
{
"input": "540157163 340043363",
"output": "No"
},
{
"input": "422447052 772330542",
"output": "No"
},
{
"input": "599704233 541054210",
"output": "Yes"
},
{
"input": "481994122 678374097",
"output": "No"
},
{
"input": "48564714 743566477",
"output": "No"
},
{
"input": "225821895 880886365",
"output": "No"
},
{
"input": "403079076 313173543",
"output": "Yes"
},
{
"input": "1000000000 1000000000",
"output": "No"
},
{
"input": "1 1",
"output": "No"
},
{
"input": "1 2",
"output": "Yes"
},
{
"input": "2 1",
"output": "No"
},
{
"input": "2 2",
"output": "No"
},
{
"input": "2 0",
"output": "No"
},
{
"input": "0 2",
"output": "No"
},
{
"input": "1000000000 1",
"output": "No"
},
{
"input": "777777 0",
"output": "No"
},
{
"input": "10 1",
"output": "No"
},
{
"input": "7 0",
"output": "No"
},
{
"input": "3 0",
"output": "No"
},
{
"input": "3 2",
"output": "Yes"
}
] | 1,647,356,525 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 46 | 62 | 0 | a, b = map(int,input().split())
b-=1
if(a-b>=0 and (a-b)%2==0 and not (a==2 and b==0) and a>=0 and b>=0):
print("Yes")
else:
print("No")
| Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.
Input Specification:
The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one).
Output Specification:
Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['6 3\n', '4 2\n', '1000 1001\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n']
Note:
In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | ```python
a, b = map(int,input().split())
b-=1
if(a-b>=0 and (a-b)%2==0 and not (a==2 and b==0) and a>=0 and b>=0):
print("Yes")
else:
print("No")
``` | 0 |
|
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20 1 80",
"output": "1 20 40 60 80 100 "
},
{
"input": "10\n10 8 6 7 5 3 4 2 9 1",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 "
},
{
"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 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 1 2 3 4 6 7 7 8 9 "
},
{
"input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59",
"output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 "
},
{
"input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12",
"output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 "
},
{
"input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84",
"output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 "
},
{
"input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1",
"output": "1 1 1 1 1 1 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 2 2 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 "
},
{
"input": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52",
"output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 "
},
{
"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": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 "
},
{
"input": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 2 2 2 2 2 2 2 2 2 2 2 2 2 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 "
},
{
"input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3",
"output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 "
},
{
"input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32",
"output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 "
},
{
"input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41",
"output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 "
},
{
"input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82",
"output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 "
},
{
"input": "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": "1 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 "
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "1 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 "
},
{
"input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 "
},
{
"input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 "
},
{
"input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88",
"output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 "
},
{
"input": "100\n100 51 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 51 100 "
},
{
"input": "10\n100 90 80 70 60 50 40 30 20 10",
"output": "10 20 30 40 50 60 70 80 90 100 "
},
{
"input": "1\n10",
"output": "10 "
}
] | 1,694,060,650 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 62 | 0 | def main():
n=int(input())
line=input()
line=line.split()
z=[]
s=''
for i in range(n):
z.append(int(line[i]))
z.sort()
for num in z:
s+=str(num)
s+=' '
print(s.strip())
main() | Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
Input Specification:
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output Specification:
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
Demo Input:
['4\n3 2 1 2\n', '3\n2 3 8\n']
Demo Output:
['1 2 2 3 \n', '2 3 8 \n']
Note:
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | ```python
def main():
n=int(input())
line=input()
line=line.split()
z=[]
s=''
for i in range(n):
z.append(int(line[i]))
z.sort()
for num in z:
s+=str(num)
s+=' '
print(s.strip())
main()
``` | 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,686,504,219 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | m,n=input().split()
m=int(m)
n=int(n)
ans=m*n
ans=int(ans)
print(ans)
| 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()
m=int(m)
n=int(n)
ans=m*n
ans=int(ans)
print(ans)
``` | 0 |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=<<=*p*2<=<<=...<=<<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".
String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| > |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=<<=|*x*|, *r*<=<<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=><=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".
String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z". | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
{
"input": "helloworld",
"output": "w"
},
{
"input": "zzzzzzzazz",
"output": "zzzzzzzzz"
},
{
"input": "testcase",
"output": "tt"
},
{
"input": "hahahahaha",
"output": "hhhhh"
},
{
"input": "abbbbbbbbb",
"output": "bbbbbbbbb"
},
{
"input": "zaz",
"output": "zz"
},
{
"input": "aza",
"output": "z"
},
{
"input": "dcbaedcba",
"output": "e"
},
{
"input": "abcdeabcd",
"output": "e"
},
{
"input": "edcbabcde",
"output": "ee"
},
{
"input": "aaaaaaaaab",
"output": "b"
},
{
"input": "testzzzzzz",
"output": "zzzzzz"
},
{
"input": "zzzzzzwait",
"output": "zzzzzz"
},
{
"input": "rrrrrqponm",
"output": "rrrrr"
},
{
"input": "zzyzyy",
"output": "zzz"
},
{
"input": "aababb",
"output": "bbb"
},
{
"input": "zanzibar",
"output": "zz"
},
{
"input": "hhgfedcbaa",
"output": "hh"
},
{
"input": "aabcdefghh",
"output": "hh"
},
{
"input": "aruaru",
"output": "uu"
},
{
"input": "uraura",
"output": "uu"
},
{
"input": "aru",
"output": "u"
},
{
"input": "aburvabur",
"output": "v"
},
{
"input": "ura",
"output": "u"
},
{
"input": "eurottat",
"output": "u"
},
{
"input": "referee",
"output": "rr"
},
{
"input": "joking",
"output": "o"
},
{
"input": "seriously",
"output": "y"
},
{
"input": "sets",
"output": "t"
},
{
"input": "test",
"output": "tt"
},
{
"input": "klmgameklm",
"output": "mmm"
},
{
"input": "dfkjafdkdd",
"output": "kk"
},
{
"input": "zzzzzzzzzz",
"output": "zzzzzzzzzz"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaa"
},
{
"input": "buzz",
"output": "zz"
},
{
"input": "b",
"output": "b"
},
{
"input": "y",
"output": "y"
},
{
"input": "yy",
"output": "yy"
},
{
"input": "zz",
"output": "zz"
},
{
"input": "bb",
"output": "bb"
},
{
"input": "aa",
"output": "aa"
},
{
"input": "a",
"output": "a"
},
{
"input": "z",
"output": "z"
},
{
"input": "zz",
"output": "zz"
},
{
"input": "zzazazzzaz",
"output": "zzzzzzz"
},
{
"input": "hellhellhe",
"output": "llll"
},
{
"input": "hellohello",
"output": "oo"
},
{
"input": "refer",
"output": "rr"
}
] | 1,690,125,852 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 124 | 0 | x=input()
print(max(x)*x.count(max(x))) | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=<<=*p*2<=<<=...<=<<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".
String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| > |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=<<=|*x*|, *r*<=<<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=><=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".
String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".
Input Specification:
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Output Specification:
Print the lexicographically largest palindromic subsequence of string *s*.
Demo Input:
['radar\n', 'bowwowwow\n', 'codeforces\n', 'mississipp\n']
Demo Output:
['rr\n', 'wwwww\n', 's\n', 'ssss\n']
Note:
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | ```python
x=input()
print(max(x)*x.count(max(x)))
``` | 3 |
|
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
},
{
"input": "8",
"output": "1641"
},
{
"input": "9",
"output": "4920"
},
{
"input": "10",
"output": "14763"
},
{
"input": "15",
"output": "3587226"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "100",
"output": "721510432"
},
{
"input": "300",
"output": "327873818"
},
{
"input": "900",
"output": "295068084"
},
{
"input": "1500",
"output": "451187545"
},
{
"input": "3000",
"output": "645417275"
},
{
"input": "5000",
"output": "755610910"
},
{
"input": "10000",
"output": "723907367"
},
{
"input": "50000",
"output": "969527595"
},
{
"input": "90000",
"output": "548978368"
},
{
"input": "99999",
"output": "909741855"
},
{
"input": "100000",
"output": "729225554"
},
{
"input": "300000",
"output": "93822635"
},
{
"input": "800000",
"output": "178940616"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "4000000",
"output": "882155933"
},
{
"input": "9000000",
"output": "295060537"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "9999998",
"output": "576926295"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "31",
"output": "347990060"
}
] | 1,627,038,588 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 29,081,600 | n=int(input())-1
def rec(n):
if n==0:
return 0
else:
return (3**n-rec(n-1))%1000000007
print(rec(n)) | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Output Specification:
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
Demo Input:
['2\n', '4\n']
Demo Output:
['3\n', '21\n']
Note:
The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | ```python
n=int(input())-1
def rec(n):
if n==0:
return 0
else:
return (3**n-rec(n-1))%1000000007
print(rec(n))
``` | 0 |
|
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once.
One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order). | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"output": "YES"
},
{
"input": "10 10\n7 6 4 2 5 10 8 3 9 1",
"output": "NO"
},
{
"input": "12312 0",
"output": "YES"
},
{
"input": "9817239 1\n6323187",
"output": "YES"
},
{
"input": "1 1\n1",
"output": "NO"
},
{
"input": "5 4\n4 2 5 1",
"output": "NO"
},
{
"input": "5 3\n4 3 5",
"output": "NO"
},
{
"input": "500 3\n18 62 445",
"output": "YES"
},
{
"input": "500 50\n72 474 467 241 442 437 336 234 410 120 438 164 405 177 142 114 27 20 445 235 46 176 88 488 242 391 28 414 145 92 206 334 152 343 367 254 100 243 155 348 148 450 461 483 97 34 471 69 416 362",
"output": "NO"
},
{
"input": "500 8\n365 313 338 410 482 417 325 384",
"output": "YES"
},
{
"input": "1000000000 10\n2 3 5 6 8 9 123 874 1230 1000000000",
"output": "NO"
},
{
"input": "1000000000 10\n1 2 3 5 6 8 9 123 874 1230",
"output": "NO"
},
{
"input": "10 1\n1",
"output": "NO"
},
{
"input": "10 4\n1 2 4 5",
"output": "NO"
},
{
"input": "50 20\n22 33 17 23 27 5 26 31 41 20 8 24 6 3 4 29 40 25 13 16",
"output": "NO"
},
{
"input": "50 40\n14 27 19 30 31 20 28 11 37 29 23 33 7 26 22 16 1 6 18 3 47 36 38 2 48 9 41 8 5 50 4 45 44 25 39 12 43 42 40 46",
"output": "NO"
},
{
"input": "123 12\n35 95 47 99 79 122 58 94 31 57 18 10",
"output": "YES"
},
{
"input": "10 5\n1 3 5 7 9",
"output": "NO"
},
{
"input": "100 7\n2 3 5 6 8 9 100",
"output": "NO"
},
{
"input": "100 3\n98 99 100",
"output": "NO"
},
{
"input": "100 3\n97 98 99",
"output": "NO"
},
{
"input": "100 3\n96 98 99",
"output": "YES"
},
{
"input": "10 6\n2 3 5 6 8 9",
"output": "YES"
},
{
"input": "1000000000 10\n2 4 10 18 40 42 49 58 59 60",
"output": "NO"
},
{
"input": "10 3\n1 4 6",
"output": "NO"
},
{
"input": "8 3\n2 3 4",
"output": "NO"
},
{
"input": "100 3\n4 5 6",
"output": "NO"
},
{
"input": "10 2\n10 1",
"output": "NO"
},
{
"input": "10 1\n10",
"output": "NO"
},
{
"input": "4 2\n2 3",
"output": "YES"
},
{
"input": "2 1\n1",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "4 3\n2 3 4",
"output": "NO"
},
{
"input": "5 3\n4 2 3",
"output": "NO"
}
] | 1,384,446,436 | 3,436 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 4 | 1,000 | 512,000 | n,m=map(int,input().split())
a=set(map(int,input().split()))
l=0
for i in range(n+1):
if (i in a)and(i+1 in a)and(i+2 in a):
l+=1
if (1 in a) or (n in a)or(l>0):
print('NO')
else:
print('YES')
| Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once.
One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order).
Output Specification:
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
Demo Input:
['10 5\n2 4 8 3 6\n', '10 5\n2 4 5 7 9\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n,m=map(int,input().split())
a=set(map(int,input().split()))
l=0
for i in range(n+1):
if (i in a)and(i+1 in a)and(i+2 in a):
l+=1
if (1 in a) or (n in a)or(l>0):
print('NO')
else:
print('YES')
``` | 0 |
|
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones.
Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.
Help Petya cope with this easy task. | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": ".g.g.d.v.q"
},
{
"input": "pumesz",
"output": ".p.m.s.z"
},
{
"input": "g",
"output": ".g"
},
{
"input": "zjuotps",
"output": ".z.j.t.p.s"
},
{
"input": "jzbwuehe",
"output": ".j.z.b.w.h"
},
{
"input": "tnkgwuugu",
"output": ".t.n.k.g.w.g"
},
{
"input": "kincenvizh",
"output": ".k.n.c.n.v.z.h"
},
{
"input": "xattxjenual",
"output": ".x.t.t.x.j.n.l"
},
{
"input": "ktajqhpqsvhw",
"output": ".k.t.j.q.h.p.q.s.v.h.w"
},
{
"input": "xnhcigytnqcmy",
"output": ".x.n.h.c.g.t.n.q.c.m"
},
{
"input": "jfmtbejyilxcec",
"output": ".j.f.m.t.b.j.l.x.c.c"
},
{
"input": "D",
"output": ".d"
},
{
"input": "ab",
"output": ".b"
},
{
"input": "Ab",
"output": ".b"
},
{
"input": "aB",
"output": ".b"
},
{
"input": "AB",
"output": ".b"
},
{
"input": "ba",
"output": ".b"
},
{
"input": "bA",
"output": ".b"
},
{
"input": "Ba",
"output": ".b"
},
{
"input": "BA",
"output": ".b"
},
{
"input": "aab",
"output": ".b"
},
{
"input": "baa",
"output": ".b"
},
{
"input": "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM",
"output": ".f.m.z.c.r.k.c.p.h.n.b.b.p.t.f.m.s.h.m.c.p.b.t.p.c.l.c.d.j.f.r.m.q.z.k.k.k.z.r.z.n.m.g.v.q.z.c.k.q.r.j.m.m.k.k.l.l.n.q.c.n.h.g.d.q.m"
},
{
"input": "VMBPMCmMDCLFELLIISUJDWQRXYRDGKMXJXJHXVZADRZWVWJRKFRRNSAWKKDPZZLFLNSGUNIVJFBEQsMDHSBJVDTOCSCgZWWKvZZN",
"output": ".v.m.b.p.m.c.m.m.d.c.l.f.l.l.s.j.d.w.q.r.x.r.d.g.k.m.x.j.x.j.h.x.v.z.d.r.z.w.v.w.j.r.k.f.r.r.n.s.w.k.k.d.p.z.z.l.f.l.n.s.g.n.v.j.f.b.q.s.m.d.h.s.b.j.v.d.t.c.s.c.g.z.w.w.k.v.z.z.n"
},
{
"input": "MCGFQQJNUKuAEXrLXibVjClSHjSxmlkQGTKZrRaDNDomIPOmtSgjJAjNVIVLeUGUAOHNkCBwNObVCHOWvNkLFQQbFnugYVMkJruJ",
"output": ".m.c.g.f.q.q.j.n.k.x.r.l.x.b.v.j.c.l.s.h.j.s.x.m.l.k.q.g.t.k.z.r.r.d.n.d.m.p.m.t.s.g.j.j.j.n.v.v.l.g.h.n.k.c.b.w.n.b.v.c.h.w.v.n.k.l.f.q.q.b.f.n.g.v.m.k.j.r.j"
},
{
"input": "iyaiuiwioOyzUaOtAeuEYcevvUyveuyioeeueoeiaoeiavizeeoeyYYaaAOuouueaUioueauayoiuuyiuovyOyiyoyioaoyuoyea",
"output": ".w.z.t.c.v.v.v.v.z.v"
},
{
"input": "yjnckpfyLtzwjsgpcrgCfpljnjwqzgVcufnOvhxplvflxJzqxnhrwgfJmPzifgubvspffmqrwbzivatlmdiBaddiaktdsfPwsevl",
"output": ".j.n.c.k.p.f.l.t.z.w.j.s.g.p.c.r.g.c.f.p.l.j.n.j.w.q.z.g.v.c.f.n.v.h.x.p.l.v.f.l.x.j.z.q.x.n.h.r.w.g.f.j.m.p.z.f.g.b.v.s.p.f.f.m.q.r.w.b.z.v.t.l.m.d.b.d.d.k.t.d.s.f.p.w.s.v.l"
},
{
"input": "RIIIUaAIYJOiuYIUWFPOOAIuaUEZeIooyUEUEAoIyIHYOEAlVAAIiLUAUAeiUIEiUMuuOiAgEUOIAoOUYYEYFEoOIIVeOOAOIIEg",
"output": ".r.j.w.f.p.z.h.l.v.l.m.g.f.v.g"
},
{
"input": "VBKQCFBMQHDMGNSGBQVJTGQCNHHRJMNKGKDPPSQRRVQTZNKBZGSXBPBRXPMVFTXCHZMSJVBRNFNTHBHGJLMDZJSVPZZBCCZNVLMQ",
"output": ".v.b.k.q.c.f.b.m.q.h.d.m.g.n.s.g.b.q.v.j.t.g.q.c.n.h.h.r.j.m.n.k.g.k.d.p.p.s.q.r.r.v.q.t.z.n.k.b.z.g.s.x.b.p.b.r.x.p.m.v.f.t.x.c.h.z.m.s.j.v.b.r.n.f.n.t.h.b.h.g.j.l.m.d.z.j.s.v.p.z.z.b.c.c.z.n.v.l.m.q"
},
{
"input": "iioyoaayeuyoolyiyoeuouiayiiuyTueyiaoiueyioiouyuauouayyiaeoeiiigmioiououeieeeyuyyaYyioiiooaiuouyoeoeg",
"output": ".l.t.g.m.g"
},
{
"input": "ueyiuiauuyyeueykeioouiiauzoyoeyeuyiaoaiiaaoaueyaeydaoauexuueafouiyioueeaaeyoeuaueiyiuiaeeayaioeouiuy",
"output": ".k.z.d.x.f"
},
{
"input": "FSNRBXLFQHZXGVMKLQDVHWLDSLKGKFMDRQWMWSSKPKKQBNDZRSCBLRSKCKKFFKRDMZFZGCNSMXNPMZVDLKXGNXGZQCLRTTDXLMXQ",
"output": ".f.s.n.r.b.x.l.f.q.h.z.x.g.v.m.k.l.q.d.v.h.w.l.d.s.l.k.g.k.f.m.d.r.q.w.m.w.s.s.k.p.k.k.q.b.n.d.z.r.s.c.b.l.r.s.k.c.k.k.f.f.k.r.d.m.z.f.z.g.c.n.s.m.x.n.p.m.z.v.d.l.k.x.g.n.x.g.z.q.c.l.r.t.t.d.x.l.m.x.q"
},
{
"input": "EYAYAYIOIOYOOAUOEUEUOUUYIYUUMOEOIIIAOIUOAAOIYOIOEUIERCEYYAOIOIGYUIAOYUEOEUAEAYPOYEYUUAUOAOEIYIEYUEEY",
"output": ".m.r.c.g.p"
},
{
"input": "jvvzcdcxjstbbksmqjsngxkgtttdxrljjxtwptgwwqzpvqchvgrkqlzxmptzblxhhsmrkmzzmgdfskhtmmnqzzflpmqdctvrfgtx",
"output": ".j.v.v.z.c.d.c.x.j.s.t.b.b.k.s.m.q.j.s.n.g.x.k.g.t.t.t.d.x.r.l.j.j.x.t.w.p.t.g.w.w.q.z.p.v.q.c.h.v.g.r.k.q.l.z.x.m.p.t.z.b.l.x.h.h.s.m.r.k.m.z.z.m.g.d.f.s.k.h.t.m.m.n.q.z.z.f.l.p.m.q.d.c.t.v.r.f.g.t.x"
},
{
"input": "YB",
"output": ".b"
},
{
"input": "fly",
"output": ".f.l"
},
{
"input": "YyyYYYyyYxdwdawdDAWDdaddYYYY",
"output": ".x.d.w.d.w.d.d.w.d.d.d.d"
}
] | 1,693,831,220 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | import sys
ss=(sys.stdin.readline().split()[0])
harf=['a', 'o', 'i', 'u', 'e', 'y']
ss=ss.lower()
pp='.'
adds=True
for i in range(len(ss)):
kk=ss[i] in harf
if adds==False:
pp+='.'
adds=True
if kk==True:
if adds!=True:
pp+='.'
adds=True
else:
pp+=ss[i]
adds=False
if pp[len(pp)-1]=='.':
pp=pp[0:len(pp)-1]
print(pp) | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones.
Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.
Help Petya cope with this easy task.
Input Specification:
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Output Specification:
Print the resulting string. It is guaranteed that this string is not empty.
Demo Input:
['tour\n', 'Codeforces\n', 'aBAcAba\n']
Demo Output:
['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n']
Note:
none | ```python
import sys
ss=(sys.stdin.readline().split()[0])
harf=['a', 'o', 'i', 'u', 'e', 'y']
ss=ss.lower()
pp='.'
adds=True
for i in range(len(ss)):
kk=ss[i] in harf
if adds==False:
pp+='.'
adds=True
if kk==True:
if adds!=True:
pp+='.'
adds=True
else:
pp+=ss[i]
adds=False
if pp[len(pp)-1]=='.':
pp=pp[0:len(pp)-1]
print(pp)
``` | 3 |
|
755 | E | PolandBall and White-Red graph | PROGRAMMING | 2,400 | [
"constructive algorithms",
"graphs",
"shortest paths"
] | null | null | PolandBall has an undirected simple graph consisting of *n* vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding some red edges. Then, he will add white edges in every remaining place. Therefore, the final graph will be a clique in two colors: white and red.
Colorfulness of the graph is a value *min*(*d**r*,<=*d**w*), where *d**r* is the diameter of the red subgraph and *d**w* is the diameter of white subgraph. The diameter of a graph is a largest value *d* such that shortest path between some pair of vertices in it is equal to *d*. If the graph is not connected, we consider its diameter to be -1.
PolandBall wants the final graph to be as neat as possible. He wants the final colorfulness to be equal to *k*. Can you help him and find any graph which satisfies PolandBall's requests? | The only one input line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=1000), representing graph's size and sought colorfulness. | If it's impossible to find a suitable graph, print -1.
Otherwise, you can output any graph which fulfills PolandBall's requirements. First, output *m* — the number of red edges in your graph. Then, you should output *m* lines, each containing two integers *a**i* and *b**i*, (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*) which means that there is an undirected red edge between vertices *a**i* and *b**i*. Every red edge should be printed exactly once, you can print the edges and the vertices of every edge in arbitrary order.
Remember that PolandBall's graph should remain simple, so no loops or multiple edges are allowed. | [
"4 1\n",
"5 2\n"
] | [
"-1\n",
"4\n1 2\n2 3\n3 4\n4 5\n"
] | In the first sample case, no graph can fulfill PolandBall's requirements.
In the second sample case, red graph is a path from 1 to 5. Its diameter is 4. However, white graph has diameter 2, because it consists of edges 1-3, 1-4, 1-5, 2-4, 2-5, 3-5. | 2,500 | [
{
"input": "4 1",
"output": "-1"
},
{
"input": "5 2",
"output": "4\n1 2\n2 3\n3 4\n4 5"
},
{
"input": "500 3",
"output": "123755\n1 2\n499 500\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85..."
},
{
"input": "1000 2",
"output": "999\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..."
},
{
"input": "10 2",
"output": "9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10"
},
{
"input": "590 3",
"output": "172580\n1 2\n589 590\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85..."
},
{
"input": "1000 5",
"output": "-1"
},
{
"input": "5 3",
"output": "5\n1 2\n4 5\n2 3\n2 4\n3 4"
},
{
"input": "100 49",
"output": "-1"
},
{
"input": "4 2",
"output": "-1"
},
{
"input": "4 3",
"output": "3\n1 2\n3 4\n2 3"
},
{
"input": "5 4",
"output": "-1"
},
{
"input": "5 1",
"output": "-1"
},
{
"input": "7 2",
"output": "6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7"
},
{
"input": "1000 1",
"output": "-1"
},
{
"input": "1000 3",
"output": "497505\n1 2\n999 1000\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 8..."
},
{
"input": "1000 4",
"output": "-1"
},
{
"input": "999 1",
"output": "-1"
},
{
"input": "999 2",
"output": "998\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..."
},
{
"input": "999 3",
"output": "496508\n1 2\n998 999\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85..."
},
{
"input": "999 4",
"output": "-1"
},
{
"input": "999 5",
"output": "-1"
},
{
"input": "8 2",
"output": "7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8"
},
{
"input": "9 2",
"output": "8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9"
},
{
"input": "6 3",
"output": "8\n1 2\n5 6\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5"
},
{
"input": "7 3",
"output": "12\n1 2\n6 7\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6"
},
{
"input": "8 3",
"output": "17\n1 2\n7 8\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n3 7\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7"
},
{
"input": "9 3",
"output": "23\n1 2\n8 9\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n4 8\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8"
},
{
"input": "10 3",
"output": "30\n1 2\n9 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n4 5\n4 6\n4 7\n4 8\n4 9\n5 6\n5 7\n5 8\n5 9\n6 7\n6 8\n6 9\n7 8\n7 9\n8 9"
},
{
"input": "527 2",
"output": "526\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..."
},
{
"input": "218 2",
"output": "217\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..."
},
{
"input": "565 2",
"output": "564\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..."
},
{
"input": "11 2",
"output": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11"
},
{
"input": "237 2",
"output": "236\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..."
},
{
"input": "107 2",
"output": "106\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..."
},
{
"input": "494 2",
"output": "493\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..."
},
{
"input": "40 2",
"output": "39\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40"
},
{
"input": "301 2",
"output": "300\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..."
},
{
"input": "101 2",
"output": "100\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76..."
},
{
"input": "642 3",
"output": "204482\n1 2\n641 642\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85..."
},
{
"input": "683 3",
"output": "231542\n1 2\n682 683\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85..."
},
{
"input": "750 3",
"output": "279380\n1 2\n749 750\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85..."
},
{
"input": "851 3",
"output": "359978\n1 2\n850 851\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85..."
},
{
"input": "207 3",
"output": "20912\n1 2\n206 207\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n..."
},
{
"input": "196 3",
"output": "18723\n1 2\n195 196\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n..."
},
{
"input": "706 3",
"output": "247458\n1 2\n705 706\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85..."
},
{
"input": "416 3",
"output": "85493\n1 2\n415 416\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n..."
},
{
"input": "2 1",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "2 3",
"output": "-1"
},
{
"input": "2 4",
"output": "-1"
},
{
"input": "3 1",
"output": "-1"
},
{
"input": "3 2",
"output": "-1"
},
{
"input": "3 3",
"output": "-1"
},
{
"input": "3 4",
"output": "-1"
}
] | 1,693,330,563 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1693330563.8972197")# 1693330563.897238 | Title: PolandBall and White-Red graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall has an undirected simple graph consisting of *n* vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding some red edges. Then, he will add white edges in every remaining place. Therefore, the final graph will be a clique in two colors: white and red.
Colorfulness of the graph is a value *min*(*d**r*,<=*d**w*), where *d**r* is the diameter of the red subgraph and *d**w* is the diameter of white subgraph. The diameter of a graph is a largest value *d* such that shortest path between some pair of vertices in it is equal to *d*. If the graph is not connected, we consider its diameter to be -1.
PolandBall wants the final graph to be as neat as possible. He wants the final colorfulness to be equal to *k*. Can you help him and find any graph which satisfies PolandBall's requests?
Input Specification:
The only one input line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=1000), representing graph's size and sought colorfulness.
Output Specification:
If it's impossible to find a suitable graph, print -1.
Otherwise, you can output any graph which fulfills PolandBall's requirements. First, output *m* — the number of red edges in your graph. Then, you should output *m* lines, each containing two integers *a**i* and *b**i*, (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*) which means that there is an undirected red edge between vertices *a**i* and *b**i*. Every red edge should be printed exactly once, you can print the edges and the vertices of every edge in arbitrary order.
Remember that PolandBall's graph should remain simple, so no loops or multiple edges are allowed.
Demo Input:
['4 1\n', '5 2\n']
Demo Output:
['-1\n', '4\n1 2\n2 3\n3 4\n4 5\n']
Note:
In the first sample case, no graph can fulfill PolandBall's requirements.
In the second sample case, red graph is a path from 1 to 5. Its diameter is 4. However, white graph has diameter 2, because it consists of edges 1-3, 1-4, 1-5, 2-4, 2-5, 3-5. | ```python
print("_RANDOM_GUESS_1693330563.8972197")# 1693330563.897238
``` | 0 |
|
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.
Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.
We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user. | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe reposted PoLyCaRp\n"
] | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp",
"output": "2"
},
{
"input": "1\nSoMeStRaNgEgUe reposted PoLyCaRp",
"output": "2"
},
{
"input": "1\niuNtwVf reposted POlYcarP",
"output": "2"
},
{
"input": "10\ncs reposted poLYCaRp\nAFIkDrY7Of4V7Mq reposted CS\nsoBiwyN7KOvoFUfbhux reposted aFikDry7Of4v7MQ\nvb6LbwA reposted sObIWYN7KOvoFufBHUx\nDtWKIcVwIHgj4Rcv reposted vb6lbwa\nkt reposted DTwKicvwihgJ4rCV\n75K reposted kT\njKzyxx1 reposted 75K\nuoS reposted jkZyXX1\npZJskHTCIqE3YyZ5ME reposted uoS",
"output": "11"
},
{
"input": "10\nvxrUpCXvx8Isq reposted pOLYcaRP\nICb1 reposted vXRUpCxvX8ISq\nJFMt4b8jZE7iF2m8by7y2 reposted Icb1\nqkG6ZkMIf9QRrBFQU reposted ICb1\nnawsNfcR2palIMnmKZ reposted pOlYcaRP\nKksyH reposted jFMT4b8JzE7If2M8by7y2\nwJtWwQS5FvzN0h8CxrYyL reposted NawsNfcR2paLIMnmKz\nDpBcBPYAcTXEdhldI6tPl reposted NaWSnFCr2pALiMnmkZ\nlEnwTVnlwdQg2vaIRQry reposted kKSYh\nQUVFgwllaWO reposted Wjtwwqs5FVzN0H8cxRyyl",
"output": "6"
},
{
"input": "10\nkkuLGEiHv reposted POLYcArp\n3oX1AoUqyw1eR3nCADY9hLwd reposted kkuLGeIHV\nwf97dqq5bx1dPIchCoT reposted 3OX1AOuQYW1eR3ncAdY9hLwD\nWANr8h reposted Wf97dQQ5bx1dpIcHcoT\n3Fb736lkljZK2LtSbfL reposted wANR8h\n6nq9xLOn reposted 3fB736lKlJZk2LtSbFL\nWL reposted 3Fb736lKLjZk2LTSbfl\ndvxn4Xtc6SBcvKf1 reposted wF97DQq5bX1dPiChCOt\nMCcPLIMISqxDzrj reposted 6nQ9XLOn\nxsQL4Z2Iu reposted MCcpLiMiSqxdzrj",
"output": "9"
},
{
"input": "10\nsMA4 reposted pOLyCARP\nlq3 reposted pOlycARp\nEa16LSFTQxLJnE reposted polYcARp\nkvZVZhJwXcWsnC7NA1DV2WvS reposted polYCArp\nEYqqlrjRwddI reposted pOlyCArP\nsPqQCA67Y6PBBbcaV3EhooO reposted ea16LSFTqxLJne\njjPnneZdF6WLZ3v reposted Ea16LSFTqxLjNe\nWEoi6UpnfBUx79 reposted ea16LSFtqXljNe\nqi4yra reposted eYqqlRJrWDDI\ncw7E1UCSUD reposted eYqqLRJRwDdI",
"output": "3"
}
] | 1,616,571,778 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 108 | 0 | n=int(input())
a=[]
name=set()
name.add("polycarp")
for i in range(n):
s=list(input().lower().split(" "))
a.append([s[0],s[2]])
name.add(s[0])
name.add(s[2])
name=list(name)
def idx(s):
return name.index(s)
g=[[] for i in range(len(name))]
for i in range(len(a)):
x,y=a[i]
g[idx(y)].append(idx(x))
start=idx("polycarp")
ans=-1
def dfs(node,cnt):
global ans
if len(g[node])==0:
ans=max(ans,cnt)
return
for to in g[node]:
dfs(to,cnt+1)
dfs(start,0)
print(ans+1) | Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.
Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.
We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
Output Specification:
Print a single integer — the maximum length of a repost chain.
Demo Input:
['5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n', '6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n', '1\nSoMeStRaNgEgUe reposted PoLyCaRp\n']
Demo Output:
['6\n', '2\n', '2\n']
Note:
none | ```python
n=int(input())
a=[]
name=set()
name.add("polycarp")
for i in range(n):
s=list(input().lower().split(" "))
a.append([s[0],s[2]])
name.add(s[0])
name.add(s[2])
name=list(name)
def idx(s):
return name.index(s)
g=[[] for i in range(len(name))]
for i in range(len(a)):
x,y=a[i]
g[idx(y)].append(idx(x))
start=idx("polycarp")
ans=-1
def dfs(node,cnt):
global ans
if len(g[node])==0:
ans=max(ans,cnt)
return
for to in g[node]:
dfs(to,cnt+1)
dfs(start,0)
print(ans+1)
``` | 3 |
|
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,637,836,849 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | s=input()
slist=list(s)
u=0
for ele in slist:
if ele.isupper():
u+=1
l=len(s)-u
print(l,u)
if l==u or u<l:
print(s.lower())
else:
print(s.upper())
| 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()
slist=list(s)
u=0
for ele in slist:
if ele.isupper():
u+=1
l=len(s)-u
print(l,u)
if l==u or u<l:
print(s.lower())
else:
print(s.upper())
``` | 0 |
959 | A | Mahmoud and Ehab and the even-odd game | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that:
- 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd.
If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally? | The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game. | Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise. | [
"1\n",
"2\n"
] | [
"Ehab",
"Mahmoud"
] | In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins.
In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins. | 500 | [
{
"input": "1",
"output": "Ehab"
},
{
"input": "2",
"output": "Mahmoud"
},
{
"input": "10000",
"output": "Mahmoud"
},
{
"input": "33333",
"output": "Ehab"
},
{
"input": "5",
"output": "Ehab"
},
{
"input": "1000000000",
"output": "Mahmoud"
},
{
"input": "999999999",
"output": "Ehab"
},
{
"input": "123123123",
"output": "Ehab"
},
{
"input": "22222221",
"output": "Ehab"
},
{
"input": "22222220",
"output": "Mahmoud"
},
{
"input": "3",
"output": "Ehab"
},
{
"input": "4",
"output": "Mahmoud"
},
{
"input": "6",
"output": "Mahmoud"
},
{
"input": "7",
"output": "Ehab"
},
{
"input": "8",
"output": "Mahmoud"
},
{
"input": "9",
"output": "Ehab"
},
{
"input": "10",
"output": "Mahmoud"
},
{
"input": "536870912",
"output": "Mahmoud"
},
{
"input": "536870913",
"output": "Ehab"
},
{
"input": "536870911",
"output": "Ehab"
}
] | 1,639,832,304 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 | a=["Mahmoud","Ehab"]
print(a[int(input())%2]) | Title: Mahmoud and Ehab and the even-odd game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that:
- 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd.
If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?
Input Specification:
The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game.
Output Specification:
Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.
Demo Input:
['1\n', '2\n']
Demo Output:
['Ehab', 'Mahmoud']
Note:
In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins.
In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins. | ```python
a=["Mahmoud","Ehab"]
print(a[int(input())%2])
``` | 3 |
|
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWdDCgaDvBfATIWPVSXlbcCLHPYahhxMEYUiaxoCebghJqvmRnaNHYTKLeOiaLDnATPZAOgSNfBzaxLymTGjfzvTegbXsAthTxyDTcmBUkqyGlVGZhoazQzVSoKbTFcCRvYsgSCwjGMxBfWEwMHuagTBxkz",
"output": "105"
},
{
"input": "199\no A r v H e J q k J k v w Q F p O R y R Z o a K R L Z E H t X y X N y y p b x B m r R S q i A x V S u i c L y M n N X c C W Z m S j e w C w T r I S X T D F l w o k f t X u n W w p Z r A k I Y E h s g",
"output": "1"
},
{
"input": "200\nhCyIdivIiISmmYIsCLbpKcTyHaOgTUQEwnQACXnrLdHAVFLtvliTEMlzBVzTesQbhXmcqvwPDeojglBMIjOXANfyQxCSjOJyO SIqOTnRzVzseGIDDYNtrwIusScWSuEhPyEmgQIVEzXofRptjeMzzhtUQxJgcUWILUhEaaRmYRBVsjoqgmyPIKwSajdlNPccOOtWrez",
"output": "50"
},
{
"input": "1\ne",
"output": "0"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "200\nABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU VWXYZABCDE KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KZ",
"output": "10"
},
{
"input": "200\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "200"
},
{
"input": "200\nffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "24\nHarbour Space UniversitY",
"output": "2"
},
{
"input": "5\naA AA",
"output": "2"
},
{
"input": "10\nas AS ASDA",
"output": "4"
},
{
"input": "10\nas AS ASDZ",
"output": "4"
},
{
"input": "3\na A",
"output": "1"
},
{
"input": "24\nHarbour space UniversitY",
"output": "2"
},
{
"input": "10\nas AS ASAa",
"output": "3"
},
{
"input": "15\naAb ABCDFGRHTJS",
"output": "11"
},
{
"input": "53\nsdfAZEZR AZE dfdf dsdRFGSDF ZZDZSD dfsd ERBGF dsfsdfR",
"output": "6"
},
{
"input": "10\nABC ABc AB",
"output": "3"
},
{
"input": "10\nA c de CDE",
"output": "3"
},
{
"input": "4\nA AB",
"output": "2"
},
{
"input": "18\nHARbour Space UNIV",
"output": "4"
},
{
"input": "13\na b c d e f A",
"output": "1"
},
{
"input": "6\nA B CA",
"output": "2"
},
{
"input": "4\naa A",
"output": "1"
},
{
"input": "3\nA a",
"output": "1"
}
] | 1,618,665,361 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 0 | n = int(input())
s = input().split()
mx = 0
for i in s:
k = 0
for j in i:
if j.isupper():
k += 1
mx = max(mx, k)
print(mx) | Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Output Specification:
Print one integer number — volume of text.
Demo Input:
['7\nNonZERO\n', '24\nthis is zero answer text\n', '24\nHarbour Space University\n']
Demo Output:
['5\n', '0\n', '1\n']
Note:
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | ```python
n = int(input())
s = input().split()
mx = 0
for i in s:
k = 0
for j in i:
if j.isupper():
k += 1
mx = max(mx, k)
print(mx)
``` | 3 |
|
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,647,870,691 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | a, b = map(int, input().split())
res = a
while a >= b:
quo = a // b
res += quo
rem = a % b
a = quo + rem
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 = map(int, input().split())
res = a
while a >= b:
quo = a // b
res += quo
rem = a % b
a = quo + rem
print(res)
``` | 3 |
|
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan. | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*. | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"input": "100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 97 6 21 68 61 87 54 8 91 37 12 76 61 57 9 100 45 44 88 5 71 98 98 26 45 37 87 34 50 33 60 64 77",
"output": "87"
},
{
"input": "100 5\n15 91 86 53 18 52 26 89 8 4 5 100 11 64 88 91 35 57 67 72 71 71 69 73 97 23 11 1 59 86 37 82 6 67 71 11 7 31 11 68 21 43 89 54 27 10 3 33 8 57 79 26 90 81 6 28 24 7 33 50 24 13 27 85 4 93 14 62 37 67 33 40 7 48 41 4 14 9 95 10 64 62 7 93 23 6 28 27 97 64 26 83 70 0 97 74 11 82 70 93",
"output": "84"
},
{
"input": "6 100\n10 9 8 7 6 5",
"output": "0"
},
{
"input": "100 9\n66 71 37 41 23 38 77 11 74 13 51 26 93 56 81 17 12 70 85 37 54 100 14 99 12 83 44 16 99 65 13 48 92 32 69 33 100 57 58 88 25 45 44 85 5 41 82 15 37 18 21 45 3 68 33 9 52 64 8 73 32 41 87 99 26 26 47 24 79 93 9 44 11 34 85 26 14 61 49 38 25 65 49 81 29 82 28 23 2 64 38 13 77 68 67 23 58 57 83 46",
"output": "78"
},
{
"input": "100 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",
"output": "0"
},
{
"input": "43 65\n32 58 59 75 85 18 57 100 69 0 36 38 79 95 82 47 7 55 28 88 27 88 63 71 80 86 67 53 69 37 99 54 81 19 55 12 2 17 84 77 25 26 62",
"output": "4"
},
{
"input": "12 64\n14 87 40 24 32 36 4 41 38 77 68 71",
"output": "0"
},
{
"input": "75 94\n80 92 25 48 78 17 69 52 79 73 12 15 59 55 25 61 96 27 98 43 30 43 36 94 67 54 86 99 100 61 65 8 65 19 18 21 75 31 2 98 55 87 14 1 17 97 94 11 57 29 34 71 76 67 45 0 78 29 86 82 29 23 77 100 48 43 65 62 88 34 7 28 13 1 1",
"output": "0"
},
{
"input": "59 27\n76 61 24 66 48 18 69 84 21 8 64 90 19 71 36 90 9 36 30 37 99 37 100 56 9 79 55 37 54 63 11 11 49 71 91 70 14 100 10 44 52 23 21 19 96 13 93 66 52 79 76 5 62 6 90 35 94 7 27",
"output": "63"
},
{
"input": "86 54\n41 84 16 5 20 79 73 13 23 24 42 73 70 80 69 71 33 44 62 29 86 88 40 64 61 55 58 19 16 23 84 100 38 91 89 98 47 50 55 87 12 94 2 12 0 1 4 26 50 96 68 34 94 80 8 22 60 3 72 84 65 89 44 52 50 9 24 34 81 28 56 17 38 85 78 90 62 60 1 40 91 2 7 41 84 22",
"output": "38"
},
{
"input": "37 2\n65 36 92 92 92 76 63 56 15 95 75 26 15 4 73 50 41 92 26 20 19 100 63 55 25 75 61 96 35 0 14 6 96 3 28 41 83",
"output": "91"
},
{
"input": "19 4\n85 2 56 70 33 75 89 60 100 81 42 28 18 92 29 96 49 23 14",
"output": "79"
},
{
"input": "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24",
"output": "91"
},
{
"input": "67 0\n40 48 15 46 90 7 65 52 24 15 42 81 2 6 71 94 32 18 97 67 83 98 48 51 10 47 8 68 36 46 65 75 90 30 62 9 5 35 80 60 69 58 62 68 58 73 80 9 22 46 56 64 44 11 93 73 62 54 15 20 17 69 16 33 85 62 49",
"output": "83"
},
{
"input": "96 0\n38 97 82 43 80 40 1 99 50 94 81 63 92 13 57 24 4 10 25 32 79 56 96 19 25 14 69 56 66 22 23 78 87 76 37 30 75 77 61 64 35 64 62 32 44 62 6 84 91 44 99 5 71 19 17 12 35 52 1 14 35 18 8 36 54 42 4 67 80 11 88 44 34 35 12 38 66 42 4 90 45 10 1 44 37 96 23 28 100 90 75 17 27 67 51 70",
"output": "94"
},
{
"input": "14 14\n87 63 62 31 59 47 40 89 92 43 80 30 99 42",
"output": "43"
},
{
"input": "12 0\n100 1 100 2 100 3 100 4 100 5 100 0",
"output": "100"
},
{
"input": "3 1\n1 2 3",
"output": "0"
},
{
"input": "3 2\n3 3 3",
"output": "0"
},
{
"input": "3 3\n3 2 1",
"output": "0"
},
{
"input": "3 100\n1 2 3",
"output": "0"
},
{
"input": "2 100\n0 0",
"output": "0"
},
{
"input": "2 90\n10 5",
"output": "0"
},
{
"input": "2 5\n5 4",
"output": "0"
},
{
"input": "3 1\n19 20 1",
"output": "18"
},
{
"input": "5 1\n5 10 7 4 20",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "0"
}
] | 1,390,577,945 | 245 | Python 3 | OK | TESTS | 32 | 109 | 409,600 | n, c = map(int, input().split())
arr = [int(i) for i in input().split()]
i, r = 0, 0
for i in range(n - 1):
if arr[i] - arr[i + 1] - c > r:
r = arr[i] - arr[i + 1] - c
print(r)
| Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
Input Specification:
The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['5 1\n5 10 7 3 20\n', '6 2\n100 1 10 40 10 40\n', '3 0\n1 2 3\n']
Demo Output:
['3\n', '97\n', '0\n']
Note:
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. | ```python
n, c = map(int, input().split())
arr = [int(i) for i in input().split()]
i, r = 0, 0
for i in range(n - 1):
if arr[i] - arr[i + 1] - c > r:
r = arr[i] - arr[i + 1] - c
print(r)
``` | 3 |
|
799 | B | T-shirt buying | PROGRAMMING | 1,400 | [
"data structures",
"implementation"
] | null | null | A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt and *b**i* is back color of the *i*-th t-shirt. All values *p**i* are distinct, and values *a**i* and *b**i* are integers from 1 to 3.
*m* buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the *j*-th buyer we know his favorite color *c**j*.
A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won't buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.
You are to compute the prices each buyer will pay for t-shirts. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of t-shirts.
The following line contains sequence of integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1<=000<=000<=000), where *p**i* equals to the price of the *i*-th t-shirt.
The following line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3), where *a**i* equals to the front color of the *i*-th t-shirt.
The following line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=3), where *b**i* equals to the back color of the *i*-th t-shirt.
The next line contains single integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of buyers.
The following line contains sequence *c*1,<=*c*2,<=...,<=*c**m* (1<=≤<=*c**j*<=≤<=3), where *c**j* equals to the favorite color of the *j*-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served. | Print to the first line *m* integers — the *j*-th integer should be equal to the price of the t-shirt which the *j*-th buyer will buy. If the *j*-th buyer won't buy anything, print -1. | [
"5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1\n",
"2\n1000000000 1\n1 1\n1 2\n2\n2 1\n"
] | [
"200 400 300 500 911 -1 \n",
"1 1000000000 \n"
] | none | 1,000 | [
{
"input": "5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1",
"output": "200 400 300 500 911 -1 "
},
{
"input": "2\n1000000000 1\n1 1\n1 2\n2\n2 1",
"output": "1 1000000000 "
},
{
"input": "10\n251034796 163562337 995167403 531046374 341924810 828969071 971837553 183763940 857690534 687685084\n3 2 1 3 2 3 1 3 2 1\n2 3 3 1 2 3 2 3 3 2\n10\n1 3 2 3 2 3 3 1 2 3",
"output": "531046374 163562337 251034796 183763940 341924810 828969071 857690534 687685084 971837553 995167403 "
},
{
"input": "20\n414468312 20329584 106106409 584924603 666547477 670032002 726095027 276840253 368277336 940941705 531635095 213813062 440421387 959075599 240727854 495316522 838268432 786936631 586382273 806443734\n3 1 2 3 3 2 2 1 3 2 3 2 3 3 3 2 1 3 1 2\n3 1 2 2 2 2 3 1 2 3 2 1 1 2 3 1 2 3 3 2\n40\n1 1 2 1 3 2 3 1 3 3 1 2 3 1 1 1 2 3 3 1 3 1 3 1 2 2 3 3 1 2 1 2 3 2 2 1 2 1 2 2",
"output": "20329584 213813062 106106409 276840253 240727854 368277336 414468312 440421387 531635095 584924603 495316522 666547477 586382273 838268432 -1 -1 670032002 726095027 786936631 -1 940941705 -1 959075599 -1 806443734 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 "
},
{
"input": "1\n529469903\n1\n3\n1\n3",
"output": "529469903 "
}
] | 1,616,184,854 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 307,200 | def F2():
n = int(input())
p = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
m = int(input())
c = [int(x) for x in input().split()]
ans = []
found = False
for i in range(m):
found = False
if p:
mini = min(p)
ind = p.index(mini)
temp = list(p)
while(not found):
if (not p) or (not temp):
ans.append(-1)
found = True
break
elif (c[0] == a[ind]) or (c[0] == b[ind]):
ans.append(mini)
a.pop(ind)
b.pop(ind)
c.pop(0)
p.pop(ind)
found = True
break
else:
temp.remove(mini)
if temp:
mini = min(temp)
ind = p.index(mini)
for i in ans:
print(i, end=" ")
if __name__ == '__main__':
F2()
| Title: T-shirt buying
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new pack of *n* t-shirts came to a shop. Each of the t-shirts is characterized by three integers *p**i*, *a**i* and *b**i*, where *p**i* is the price of the *i*-th t-shirt, *a**i* is front color of the *i*-th t-shirt and *b**i* is back color of the *i*-th t-shirt. All values *p**i* are distinct, and values *a**i* and *b**i* are integers from 1 to 3.
*m* buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the *j*-th buyer we know his favorite color *c**j*.
A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won't buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.
You are to compute the prices each buyer will pay for t-shirts.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of t-shirts.
The following line contains sequence of integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1<=000<=000<=000), where *p**i* equals to the price of the *i*-th t-shirt.
The following line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3), where *a**i* equals to the front color of the *i*-th t-shirt.
The following line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=3), where *b**i* equals to the back color of the *i*-th t-shirt.
The next line contains single integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of buyers.
The following line contains sequence *c*1,<=*c*2,<=...,<=*c**m* (1<=≤<=*c**j*<=≤<=3), where *c**j* equals to the favorite color of the *j*-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served.
Output Specification:
Print to the first line *m* integers — the *j*-th integer should be equal to the price of the t-shirt which the *j*-th buyer will buy. If the *j*-th buyer won't buy anything, print -1.
Demo Input:
['5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1\n', '2\n1000000000 1\n1 1\n1 2\n2\n2 1\n']
Demo Output:
['200 400 300 500 911 -1 \n', '1 1000000000 \n']
Note:
none | ```python
def F2():
n = int(input())
p = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
m = int(input())
c = [int(x) for x in input().split()]
ans = []
found = False
for i in range(m):
found = False
if p:
mini = min(p)
ind = p.index(mini)
temp = list(p)
while(not found):
if (not p) or (not temp):
ans.append(-1)
found = True
break
elif (c[0] == a[ind]) or (c[0] == b[ind]):
ans.append(mini)
a.pop(ind)
b.pop(ind)
c.pop(0)
p.pop(ind)
found = True
break
else:
temp.remove(mini)
if temp:
mini = min(temp)
ind = p.index(mini)
for i in ans:
print(i, end=" ")
if __name__ == '__main__':
F2()
``` | 0 |
|
174 | A | Problem About Equation | PROGRAMMING | 1,100 | [
"math"
] | null | null | A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
- there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal. | The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug. | Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma. | [
"5 50\n1 2 3 4 5\n",
"2 2\n1 100\n"
] | [
"12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n",
"-1\n"
] | none | 500 | [
{
"input": "5 50\n1 2 3 4 5",
"output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000"
},
{
"input": "2 2\n1 100",
"output": "-1"
},
{
"input": "2 2\n1 1",
"output": "1.000000\n1.000000"
},
{
"input": "3 2\n1 2 1",
"output": "1.000000\n0.000000\n1.000000"
},
{
"input": "3 5\n1 2 1",
"output": "2.000000\n1.000000\n2.000000"
},
{
"input": "10 95\n0 0 0 0 0 1 1 1 1 1",
"output": "10.000000\n10.000000\n10.000000\n10.000000\n10.000000\n9.000000\n9.000000\n9.000000\n9.000000\n9.000000"
},
{
"input": "3 5\n1 2 3",
"output": "2.666667\n1.666667\n0.666667"
},
{
"input": "3 5\n1 3 2",
"output": "2.666667\n0.666667\n1.666667"
},
{
"input": "3 5\n2 1 3",
"output": "1.666667\n2.666667\n0.666667"
},
{
"input": "3 5\n2 3 1",
"output": "1.666667\n0.666667\n2.666667"
},
{
"input": "3 5\n3 1 2",
"output": "0.666667\n2.666667\n1.666667"
},
{
"input": "3 5\n3 2 1",
"output": "0.666667\n1.666667\n2.666667"
},
{
"input": "2 1\n1 1",
"output": "0.500000\n0.500000"
},
{
"input": "2 1\n2 2",
"output": "0.500000\n0.500000"
},
{
"input": "3 2\n2 1 2",
"output": "0.333333\n1.333333\n0.333333"
},
{
"input": "3 3\n2 2 1",
"output": "0.666667\n0.666667\n1.666667"
},
{
"input": "3 3\n3 1 2",
"output": "0.000000\n2.000000\n1.000000"
},
{
"input": "100 100\n37 97 75 52 33 29 51 22 33 37 45 96 96 60 82 58 86 71 28 73 38 50 6 6 90 17 26 76 13 41 100 47 17 93 4 1 56 16 41 74 25 17 69 61 39 37 96 73 49 93 52 14 62 24 91 30 9 97 52 100 6 16 85 8 12 26 10 3 94 63 80 27 29 78 9 48 79 64 60 18 98 75 81 35 24 81 2 100 23 70 21 60 98 38 29 29 58 37 49 72",
"output": "-1"
},
{
"input": "100 100\n1 3 7 7 9 5 9 3 7 8 10 1 3 10 10 6 1 3 10 4 3 9 4 9 5 4 9 2 8 7 4 3 3 3 5 10 8 9 10 1 9 2 4 8 3 10 9 2 3 9 8 2 4 4 4 7 1 1 7 3 7 8 9 5 1 2 6 7 1 10 9 10 5 10 1 10 5 2 4 3 10 1 6 5 6 7 8 9 3 8 6 10 8 7 2 3 8 6 3 6",
"output": "-1"
},
{
"input": "100 61\n81 80 83 72 87 76 91 92 77 93 77 94 76 73 71 88 88 76 87 73 89 73 85 81 79 90 76 73 82 93 79 93 71 75 72 71 78 85 92 89 88 93 74 87 71 94 74 87 85 89 90 93 86 94 92 87 90 91 75 73 90 84 92 94 92 79 74 85 74 74 89 76 84 84 84 83 86 84 82 71 76 74 83 81 89 73 73 74 71 77 90 94 73 94 73 75 93 89 84 92",
"output": "-1"
},
{
"input": "100 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": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..."
},
{
"input": "100 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": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..."
},
{
"input": "100 100\n99 100 99 100 100 100 99 99 99 100 100 100 99 100 99 100 100 100 100 100 99 99 99 99 100 99 100 99 100 99 99 100 100 100 100 100 99 99 99 100 99 99 100 99 100 99 100 99 99 99 99 100 100 99 99 99 100 100 99 100 100 100 99 99 100 100 100 100 100 100 99 99 99 99 99 100 99 99 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 100 99 100 100 100 100 99",
"output": "1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0..."
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100",
"output": "0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0..."
},
{
"input": "100 100\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99",
"output": "1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n0.020000\n1.020000\n1..."
},
{
"input": "10 100\n52 52 51 52 52 52 51 51 52 52",
"output": "9.700000\n9.700000\n10.700000\n9.700000\n9.700000\n9.700000\n10.700000\n10.700000\n9.700000\n9.700000"
},
{
"input": "10 100\n13 13 13 13 12 13 12 13 12 12",
"output": "9.600000\n9.600000\n9.600000\n9.600000\n10.600000\n9.600000\n10.600000\n9.600000\n10.600000\n10.600000"
},
{
"input": "10 100\n50 51 47 51 48 46 49 51 46 51",
"output": "9.000000\n8.000000\n12.000000\n8.000000\n11.000000\n13.000000\n10.000000\n8.000000\n13.000000\n8.000000"
},
{
"input": "10 100\n13 13 9 12 12 11 13 8 10 13",
"output": "8.400000\n8.400000\n12.400000\n9.400000\n9.400000\n10.400000\n8.400000\n13.400000\n11.400000\n8.400000"
},
{
"input": "93 91\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",
"output": "0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0..."
},
{
"input": "93 97\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",
"output": "1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1..."
},
{
"input": "91 99\n99 100 100 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 99 100 99 100 100 100 100 100 99 99 100 99 100 99 99 100 100 100 100 99 99 100 100 100 99 100 100 99 100 100 99 100 99 99 99 100 99 99 99 100 99 100 99 100 99 100 99 99 100 100 100 100 99 100 99 100 99 99 100 100 99 100 100 100 100 99 99 100 100 99 99 100 99",
"output": "1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1..."
},
{
"input": "99 98\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n1.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0..."
},
{
"input": "98 99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99",
"output": "1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1..."
},
{
"input": "13 97\n52 52 51 51 52 52 51 52 51 51 52 52 52",
"output": "7.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n8.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n7.076923"
},
{
"input": "17 99\n13 13 12 13 11 12 12 12 13 13 11 13 13 13 13 12 13",
"output": "5.294118\n5.294118\n6.294118\n5.294118\n7.294118\n6.294118\n6.294118\n6.294118\n5.294118\n5.294118\n7.294118\n5.294118\n5.294118\n5.294118\n5.294118\n6.294118\n5.294118"
},
{
"input": "9 91\n52 51 50 52 52 51 50 48 51",
"output": "8.888889\n9.888889\n10.888889\n8.888889\n8.888889\n9.888889\n10.888889\n12.888889\n9.888889"
},
{
"input": "17 91\n13 13 13 13 12 12 13 13 12 13 12 13 10 12 13 13 12",
"output": "4.823529\n4.823529\n4.823529\n4.823529\n5.823529\n5.823529\n4.823529\n4.823529\n5.823529\n4.823529\n5.823529\n4.823529\n7.823529\n5.823529\n4.823529\n4.823529\n5.823529"
},
{
"input": "2 3\n1 1",
"output": "1.500000\n1.500000"
},
{
"input": "2 90\n0 89",
"output": "89.500000\n0.500000"
},
{
"input": "4 17\n3 4 8 1",
"output": "5.250000\n4.250000\n0.250000\n7.250000"
},
{
"input": "2 9\n5 5",
"output": "4.500000\n4.500000"
},
{
"input": "7 28\n1 3 9 10 9 6 10",
"output": "9.857143\n7.857143\n1.857143\n0.857143\n1.857143\n4.857143\n0.857143"
},
{
"input": "5 11\n1 2 3 4 5",
"output": "4.200000\n3.200000\n2.200000\n1.200000\n0.200000"
},
{
"input": "2 1\n1 1",
"output": "0.500000\n0.500000"
},
{
"input": "5 3\n1 1 1 1 1",
"output": "0.600000\n0.600000\n0.600000\n0.600000\n0.600000"
},
{
"input": "3 1\n100 100 100",
"output": "0.333333\n0.333333\n0.333333"
},
{
"input": "5 50\n2 2 3 2 2",
"output": "10.200000\n10.200000\n9.200000\n10.200000\n10.200000"
},
{
"input": "3 3\n2 2 3",
"output": "1.333333\n1.333333\n0.333333"
},
{
"input": "2 52\n2 100",
"output": "-1"
},
{
"input": "3 2\n2 2 3",
"output": "1.000000\n1.000000\n0.000000"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "0.200000\n0.200000\n0.200000\n0.200000\n0.200000"
},
{
"input": "2 4\n1 2",
"output": "2.500000\n1.500000"
},
{
"input": "5 49\n1 2 3 4 5",
"output": "11.800000\n10.800000\n9.800000\n8.800000\n7.800000"
}
] | 1,644,810,401 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | m=input()
l1=list(map(int,m.split()))
n=input()
l2=list(map(int,n.split()))
s1=sum(l2)
if(s1>l1[1]):
print("-1")
else:
d=(s1+l1[1])/l1[0]
for item in l2:
print("{:.6f}".format(d-item))
| Title: Problem About Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
- there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal.
Input Specification:
The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug.
Output Specification:
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Demo Input:
['5 50\n1 2 3 4 5\n', '2 2\n1 100\n']
Demo Output:
['12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n', '-1\n']
Note:
none | ```python
m=input()
l1=list(map(int,m.split()))
n=input()
l2=list(map(int,n.split()))
s1=sum(l2)
if(s1>l1[1]):
print("-1")
else:
d=(s1+l1[1])/l1[0]
for item in l2:
print("{:.6f}".format(d-item))
``` | 0 |
|
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number).
Your task is to find out if a given integer is a triangular number. | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO"
},
{
"input": "8",
"output": "NO"
},
{
"input": "12",
"output": "NO"
},
{
"input": "10",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "9",
"output": "NO"
},
{
"input": "14",
"output": "NO"
},
{
"input": "15",
"output": "YES"
},
{
"input": "16",
"output": "NO"
},
{
"input": "20",
"output": "NO"
},
{
"input": "21",
"output": "YES"
},
{
"input": "22",
"output": "NO"
},
{
"input": "121",
"output": "NO"
},
{
"input": "135",
"output": "NO"
},
{
"input": "136",
"output": "YES"
},
{
"input": "137",
"output": "NO"
},
{
"input": "152",
"output": "NO"
},
{
"input": "153",
"output": "YES"
},
{
"input": "154",
"output": "NO"
},
{
"input": "171",
"output": "YES"
},
{
"input": "189",
"output": "NO"
},
{
"input": "190",
"output": "YES"
},
{
"input": "191",
"output": "NO"
},
{
"input": "210",
"output": "YES"
},
{
"input": "211",
"output": "NO"
},
{
"input": "231",
"output": "YES"
},
{
"input": "232",
"output": "NO"
},
{
"input": "252",
"output": "NO"
},
{
"input": "253",
"output": "YES"
},
{
"input": "254",
"output": "NO"
},
{
"input": "275",
"output": "NO"
},
{
"input": "276",
"output": "YES"
},
{
"input": "277",
"output": "NO"
},
{
"input": "299",
"output": "NO"
},
{
"input": "300",
"output": "YES"
},
{
"input": "301",
"output": "NO"
},
{
"input": "324",
"output": "NO"
},
{
"input": "325",
"output": "YES"
},
{
"input": "326",
"output": "NO"
},
{
"input": "350",
"output": "NO"
},
{
"input": "351",
"output": "YES"
},
{
"input": "352",
"output": "NO"
},
{
"input": "377",
"output": "NO"
},
{
"input": "378",
"output": "YES"
},
{
"input": "406",
"output": "YES"
},
{
"input": "434",
"output": "NO"
},
{
"input": "435",
"output": "YES"
},
{
"input": "464",
"output": "NO"
},
{
"input": "465",
"output": "YES"
},
{
"input": "495",
"output": "NO"
},
{
"input": "496",
"output": "YES"
},
{
"input": "497",
"output": "NO"
},
{
"input": "331",
"output": "NO"
},
{
"input": "413",
"output": "NO"
},
{
"input": "177",
"output": "NO"
},
{
"input": "122",
"output": "NO"
},
{
"input": "478",
"output": "NO"
},
{
"input": "188",
"output": "NO"
},
{
"input": "21",
"output": "YES"
},
{
"input": "474",
"output": "NO"
},
{
"input": "21",
"output": "YES"
},
{
"input": "48",
"output": "NO"
},
{
"input": "498",
"output": "NO"
},
{
"input": "499",
"output": "NO"
},
{
"input": "500",
"output": "NO"
}
] | 1,695,900,707 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | n = int(input())
while n%2==0: n/=2
print("YES" if n==1 else "NO") | Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number).
Your task is to find out if a given integer is a triangular number.
Input Specification:
The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer.
Output Specification:
If the given integer is a triangular number output YES, otherwise output NO.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
n = int(input())
while n%2==0: n/=2
print("YES" if n==1 else "NO")
``` | 0 |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence. | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"input": "2 2\n20 10",
"output": "1"
},
{
"input": "2 1\n20 1",
"output": "2"
},
{
"input": "3 1\n1 2 3",
"output": "1"
},
{
"input": "3 1\n2 1 3",
"output": "2"
},
{
"input": "3 1\n3 2 1",
"output": "3"
},
{
"input": "3 2\n1 2 3",
"output": "1"
},
{
"input": "3 2\n3 2 1",
"output": "2"
},
{
"input": "3 3\n1 2 3",
"output": "1"
},
{
"input": "4 2\n9 8 11 7",
"output": "1"
},
{
"input": "4 2\n10 1 2 3",
"output": "2"
},
{
"input": "6 3\n56 56 56 2 1 2",
"output": "4"
},
{
"input": "8 3\n1 1 1 1 2 60 90 1",
"output": "1"
},
{
"input": "4 1\n1 5 2 2",
"output": "1"
},
{
"input": "4 2\n4 6 7 4",
"output": "1"
},
{
"input": "10 4\n1 1 1 4 4 4 4 4 4 3",
"output": "1"
},
{
"input": "6 3\n1 2 1 3 1 1",
"output": "1"
},
{
"input": "5 2\n100 100 100 1 1",
"output": "4"
}
] | 1,687,579,214 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n,k = map(int,input().split())
l = list(map(int,input().split()))
s = 0
p = 0
for i in range(k):
s += l[i]
m = s
for i in range(n-k):
if m > s:
m = s
p = i+1
s = s - l[i] + l[i+k]
print(p) | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
Input Specification:
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
Output Specification:
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
Demo Input:
['7 3\n1 2 6 1 1 7 1\n']
Demo Output:
['3\n']
Note:
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | ```python
n,k = map(int,input().split())
l = list(map(int,input().split()))
s = 0
p = 0
for i in range(k):
s += l[i]
m = s
for i in range(n-k):
if m > s:
m = s
p = i+1
s = s - l[i] + l[i+k]
print(p)
``` | 0 |
|
305 | A | Strange Addition | PROGRAMMING | 1,600 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*.
Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? | The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers.
The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100). | In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers.
If there are multiple solutions, print any of them. You can print the numbers in any order. | [
"4\n100 10 1 0\n",
"3\n2 70 3\n"
] | [
"4\n0 1 10 100 ",
"2\n2 70 "
] | none | 500 | [
{
"input": "4\n100 10 1 0",
"output": "4\n0 1 10 100 "
},
{
"input": "3\n2 70 3",
"output": "2\n2 70 "
},
{
"input": "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29",
"output": "4\n0 6 30 100 "
},
{
"input": "50\n20 67 96 6 75 12 37 46 38 86 83 22 10 8 21 2 93 9 81 49 69 52 63 62 70 92 97 40 47 99 16 85 48 77 39 100 28 5 11 44 89 1 19 42 35 27 7 14 88 33",
"output": "3\n1 10 100 "
},
{
"input": "2\n1 2",
"output": "1\n1 "
},
{
"input": "73\n39 66 3 59 40 93 72 34 95 79 83 65 99 57 48 44 82 76 31 21 64 19 53 75 37 16 43 5 47 24 15 22 20 55 45 74 42 10 61 49 23 80 35 62 2 9 67 97 51 81 1 70 88 63 33 25 68 13 69 71 73 6 18 52 41 38 96 46 92 85 14 36 100",
"output": "3\n1 10 100 "
},
{
"input": "15\n74 90 73 47 36 44 81 21 66 92 2 38 62 72 49",
"output": "2\n2 90 "
},
{
"input": "96\n17 10 0 85 57 78 15 99 55 6 7 88 12 95 58 19 47 18 96 82 21 80 97 77 46 31 54 70 23 60 59 100 66 92 51 14 91 25 16 27 44 4 35 98 8 52 24 5 81 29 73 13 61 56 45 75 49 71 94 48 3 76 32 65 72 1 84 36 86 40 83 50 22 33 41 11 26 93 90 43 39 79 89 9 64 68 42 74 87 2 62 34 20 63 67 37",
"output": "4\n0 1 10 100 "
},
{
"input": "5\n23 75 38 47 70",
"output": "1\n23 "
},
{
"input": "12\n89 61 45 92 22 3 94 66 48 21 54 14",
"output": "1\n3 "
},
{
"input": "1\n99",
"output": "1\n99 "
},
{
"input": "1\n0",
"output": "1\n0 "
},
{
"input": "2\n100 1",
"output": "2\n1 100 "
},
{
"input": "3\n1 100 99",
"output": "2\n1 100 "
},
{
"input": "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": "3\n1 10 100 "
},
{
"input": "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 100 0",
"output": "4\n0 1 10 100 "
},
{
"input": "99\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",
"output": "2\n1 10 "
},
{
"input": "2\n5 6",
"output": "1\n5 "
},
{
"input": "81\n11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 58 59 61 62 63 64 65 66 67 68 69 71 72 73 74 75 76 77 78 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 97 98 99",
"output": "1\n11 "
},
{
"input": "3\n99 10 6",
"output": "2\n6 10 "
},
{
"input": "4\n11 10 100 3",
"output": "3\n3 10 100 "
},
{
"input": "2\n99 6",
"output": "1\n6 "
},
{
"input": "3\n23 0 100",
"output": "3\n0 23 100 "
},
{
"input": "2\n43 0",
"output": "2\n0 43 "
},
{
"input": "4\n99 0 100 6",
"output": "3\n0 6 100 "
},
{
"input": "1\n100",
"output": "1\n100 "
},
{
"input": "2\n0 100",
"output": "2\n0 100 "
},
{
"input": "3\n0 100 10",
"output": "3\n0 10 100 "
},
{
"input": "3\n0 100 12",
"output": "3\n0 12 100 "
},
{
"input": "3\n0 100 1",
"output": "3\n0 1 100 "
},
{
"input": "4\n0 100 10 1",
"output": "4\n0 1 10 100 "
},
{
"input": "4\n0 100 10 99",
"output": "3\n0 10 100 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "2\n10 12",
"output": "1\n10 "
},
{
"input": "2\n90 9",
"output": "2\n9 90 "
}
] | 1,543,240,964 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | import math
n = int(input())
a = input().split()
res = []
c = 0
for i in a :
if i[-1] == '0' :
c += 1
res.append(i)
if c >= math.ceil(n/2) :
print(n)
print(*a)
else :
print(c*2)
k = []
t = 0
while len(k) != c :
if a[t] not in res :
k.append(a[t])
t += 1
res += k
print(*res) | Title: Strange Addition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*.
Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
Input Specification:
The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers.
The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100).
Output Specification:
In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers.
If there are multiple solutions, print any of them. You can print the numbers in any order.
Demo Input:
['4\n100 10 1 0\n', '3\n2 70 3\n']
Demo Output:
['4\n0 1 10 100 ', '2\n2 70 ']
Note:
none | ```python
import math
n = int(input())
a = input().split()
res = []
c = 0
for i in a :
if i[-1] == '0' :
c += 1
res.append(i)
if c >= math.ceil(n/2) :
print(n)
print(*a)
else :
print(c*2)
k = []
t = 0
while len(k) != c :
if a[t] not in res :
k.append(a[t])
t += 1
res += k
print(*res)
``` | 0 |
|
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126",
"output": "12"
},
{
"input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 942 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 801 71 375 320 395 1059 116 222 931 444 582 74 677 655 88 173 686 491 661 186 114 832 615 814 791 464 517 850",
"output": "36"
},
{
"input": "2 6 8\n2 1",
"output": "0"
},
{
"input": "5 15 16\n7 11 5 12 8",
"output": "2"
},
{
"input": "15 759966 759967\n890397 182209 878577 548548 759966 812923 759966 860479 200595 381358 299175 339368 759966 907668 69574",
"output": "4"
},
{
"input": "5 234613 716125\n642626 494941 234613 234613 234613",
"output": "0"
},
{
"input": "50 48547 567054\n529808 597004 242355 559114 78865 537318 631455 733020 655072 645093 309010 855034 306058 625046 524574 834944 27330 664392 443637 821584 338013 490702 289520 675471 885846 258814 134220 571301 84875 94132 200425 928833 375166 521232 317961 175315 947093 89971 322071 174033 48547 998535 954205 704114 943163 438900 48547 538422 48547 48547",
"output": "0"
},
{
"input": "5 10 20\n10 10 10 10 1",
"output": "1"
},
{
"input": "5 10 11\n10 10 10 10 1",
"output": "2"
},
{
"input": "3 10 10\n4 3 3",
"output": "0"
},
{
"input": "3 5 5\n5 5 5",
"output": "1"
},
{
"input": "3 4 14\n5 5 5",
"output": "0"
},
{
"input": "2 7 10\n1234 1234",
"output": "0"
},
{
"input": "1 5 6\n10",
"output": "0"
},
{
"input": "3 4 6\n1 2 3",
"output": "0"
},
{
"input": "5 10 12\n13 13 13 13 13",
"output": "0"
},
{
"input": "3 4 5\n5 7 9",
"output": "0"
},
{
"input": "3 10 100\n5 5 5",
"output": "0"
},
{
"input": "5 1 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "5 5 5\n5 5 5 5 5",
"output": "2"
},
{
"input": "2 2 5\n5 5",
"output": "0"
},
{
"input": "3 1 4\n2 2 2",
"output": "0"
}
] | 1,694,753,360 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 12,800,000 | #!/bin/env python3
n, b, d = input().split()
n = int(n)
b = int(b)
d = int(d)
a = [int(x) for x in input().split()]
s = [x for x in a if x < b]
print(sum(s) // d)
| Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.
The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?
Input Specification:
The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000<=000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.
Output Specification:
Print one integer — the number of times Kolya will have to empty the waste section.
Demo Input:
['2 7 10\n5 6\n', '1 5 10\n7\n', '3 10 10\n5 7 7\n', '1 1 1\n1\n']
Demo Output:
['1\n', '0\n', '1\n', '0\n']
Note:
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | ```python
#!/bin/env python3
n, b, d = input().split()
n = int(n)
b = int(b)
d = int(d)
a = [int(x) for x in input().split()]
s = [x for x in a if x < b]
print(sum(s) // d)
``` | 0 |
|
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
"input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46",
"output": "46 0"
},
{
"input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100",
"output": "700 0"
},
{
"input": "1 0\n- 526403222",
"output": "0 1"
},
{
"input": "1 897986543\n- 371188251",
"output": "526798292 0"
},
{
"input": "1 0\n+ 1",
"output": "1 0"
},
{
"input": "1 0\n- 1",
"output": "0 1"
},
{
"input": "1 10\n+ 10",
"output": "20 0"
},
{
"input": "1 3\n- 5",
"output": "3 1"
},
{
"input": "1 0\n- 5",
"output": "0 1"
},
{
"input": "1 0\n+ 5",
"output": "5 0"
}
] | 1,677,922,833 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | distressedPeople = 0
peopleInQueue, iceCreams = input().split()
peopleInQueue = int(peopleInQueue)
iceCreams = int(iceCreams)
for i in range(peopleInQueue):
plusOrMinus, value = input().split()
value = int(value)
if(plusOrMinus == '+'):
iceCreams += value
elif(plusOrMinus == '-'):
if(iceCreams >= value):
iceCreams -= value
else:
distressedPeople += 1
print(iceCreams, distressedPeople)
| Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input Specification:
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Output Specification:
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
Demo Input:
['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n']
Demo Output:
['22 1\n', '3 2\n']
Note:
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | ```python
distressedPeople = 0
peopleInQueue, iceCreams = input().split()
peopleInQueue = int(peopleInQueue)
iceCreams = int(iceCreams)
for i in range(peopleInQueue):
plusOrMinus, value = input().split()
value = int(value)
if(plusOrMinus == '+'):
iceCreams += value
elif(plusOrMinus == '-'):
if(iceCreams >= value):
iceCreams -= value
else:
distressedPeople += 1
print(iceCreams, distressedPeople)
``` | 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,635,263,010 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 156 | 17,715,200 | pack = int(input())
cookies = list(map(int, input(). split()))
kol = 0
summa = sum(cookies)
for i in cookies:
if (summa - i) % 2 == 0:
kol += 1
print(kol) | 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
pack = int(input())
cookies = list(map(int, input(). split()))
kol = 0
summa = sum(cookies)
for i in cookies:
if (summa - i) % 2 == 0:
kol += 1
print(kol)
``` | 3 |
|
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist. | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50",
"output": "49"
},
{
"input": "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2",
"output": "-1"
},
{
"input": "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90",
"output": "46"
},
{
"input": "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66",
"output": "14"
},
{
"input": "1 1\n4\n9",
"output": "8"
},
{
"input": "1 1\n2\n4",
"output": "-1"
},
{
"input": "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58",
"output": "-1"
},
{
"input": "1 1\n50\n100",
"output": "-1"
},
{
"input": "1 1\n49\n100",
"output": "98"
},
{
"input": "1 1\n100\n100",
"output": "-1"
},
{
"input": "1 1\n99\n100",
"output": "-1"
},
{
"input": "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100",
"output": "99"
},
{
"input": "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2",
"output": "-1"
},
{
"input": "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75",
"output": "2"
},
{
"input": "3 3\n2 3 4\n8 9 10",
"output": "4"
},
{
"input": "2 1\n2 3\n15",
"output": "4"
},
{
"input": "2 1\n2 4\n4",
"output": "-1"
},
{
"input": "2 3\n4 5\n10 11 12",
"output": "8"
},
{
"input": "3 1\n2 3 3\n5",
"output": "4"
},
{
"input": "2 1\n9 10\n100",
"output": "18"
},
{
"input": "3 3\n3 12 15\n7 8 9",
"output": "-1"
},
{
"input": "2 2\n3 5\n7 8",
"output": "6"
},
{
"input": "3 3\n4 5 6\n10 11 12",
"output": "8"
},
{
"input": "3 5\n2 3 3\n6 6 6 6 2",
"output": "-1"
},
{
"input": "3 6\n4 5 3\n8 9 7 10 7 11",
"output": "6"
},
{
"input": "3 6\n4 5 2\n8 9 6 10 7 4",
"output": "-1"
},
{
"input": "2 1\n4 6\n10",
"output": "8"
},
{
"input": "1 2\n1\n3 1",
"output": "-1"
},
{
"input": "2 1\n5 6\n20",
"output": "10"
},
{
"input": "2 1\n1 5\n5",
"output": "-1"
},
{
"input": "3 2\n10 20 30\n30 40",
"output": "-1"
},
{
"input": "2 2\n5 6\n7 100",
"output": "-1"
},
{
"input": "2 1\n2 5\n7",
"output": "5"
},
{
"input": "1 1\n5\n20",
"output": "10"
},
{
"input": "2 1\n10 11\n100",
"output": "20"
},
{
"input": "1 1\n1\n10",
"output": "2"
},
{
"input": "1 1\n10\n100",
"output": "20"
}
] | 1,454,700,480 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 154 | 0 | n, m = map(int, input().split())
g = list(map(int, input().split()))
b = min(list(map(int, input().split())))
g_max = max(g)
g_min = min(g)
print(g_max if g_min*2<=g_max and g_max<b else (g_min*2 if g_min*2<b else -1)) | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
Input Specification:
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
Output Specification:
If there is a valid TL value, print it. Otherwise, print -1.
Demo Input:
['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n']
Demo Output:
['5', '-1\n']
Note:
none | ```python
n, m = map(int, input().split())
g = list(map(int, input().split()))
b = min(list(map(int, input().split())))
g_max = max(g)
g_min = min(g)
print(g_max if g_min*2<=g_max and g_max<b else (g_min*2 if g_min*2<b else -1))
``` | 0 |
|
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,650,276,577 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 93 | 1,638,400 | seq = input()
l = len(seq)
subsequences = 0
for Q1 in range(l):
for A in range(Q1,l):
for Q2 in range(A,l):
if seq[Q1] == 'Q' and seq[A] == 'A' and seq[Q2] == 'Q':
subsequences += 1
print(subsequences)
| 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
seq = input()
l = len(seq)
subsequences = 0
for Q1 in range(l):
for A in range(Q1,l):
for Q2 in range(A,l):
if seq[Q1] == 'Q' and seq[A] == 'A' and seq[Q2] == 'Q':
subsequences += 1
print(subsequences)
``` | 3 |
Subsets and Splits