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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
"input": "oops",
"output": "oops"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "a"
},
{
"input": "aA",
"output": "Aa"
},
{
"input": "Zz",
"output": "Zz"
},
{
"input": "Az",
"output": "Az"
},
{
"input": "zA",
"output": "Za"
},
{
"input": "AAA",
"output": "aaa"
},
{
"input": "AAa",
"output": "AAa"
},
{
"input": "AaR",
"output": "AaR"
},
{
"input": "Tdr",
"output": "Tdr"
},
{
"input": "aTF",
"output": "Atf"
},
{
"input": "fYd",
"output": "fYd"
},
{
"input": "dsA",
"output": "dsA"
},
{
"input": "fru",
"output": "fru"
},
{
"input": "hYBKF",
"output": "Hybkf"
},
{
"input": "XweAR",
"output": "XweAR"
},
{
"input": "mogqx",
"output": "mogqx"
},
{
"input": "eOhEi",
"output": "eOhEi"
},
{
"input": "nkdku",
"output": "nkdku"
},
{
"input": "zcnko",
"output": "zcnko"
},
{
"input": "lcccd",
"output": "lcccd"
},
{
"input": "vwmvg",
"output": "vwmvg"
},
{
"input": "lvchf",
"output": "lvchf"
},
{
"input": "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO",
"output": "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo"
},
{
"input": "OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG",
"output": "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg"
},
{
"input": "IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS",
"output": "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ",
"output": "Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq"
},
{
"input": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR",
"output": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR"
},
{
"input": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE",
"output": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE"
},
{
"input": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ",
"output": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ"
},
{
"input": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm",
"output": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm"
},
{
"input": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm",
"output": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm"
},
{
"input": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg",
"output": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg"
},
{
"input": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc",
"output": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc"
},
{
"input": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv",
"output": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv"
},
{
"input": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect",
"output": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect"
},
{
"input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE",
"output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype"
},
{
"input": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu",
"output": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu"
},
{
"input": "aBACABa",
"output": "aBACABa"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAaa",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAaa"
},
{
"input": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
{
"input": "dDDDDDDDDDDDDD",
"output": "Dddddddddddddd"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "z",
"output": "Z"
},
{
"input": "AZ",
"output": "az"
},
{
"input": "Z",
"output": "z"
},
{
"input": "aAAAA",
"output": "Aaaaa"
},
{
"input": "F",
"output": "f"
}
] | 1,694,537,967 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 46 | 0 | inp = input()
if inp[0]==inp[0].lower() and inp[1:]==inp[1:].upper():
print(inp.title())
elif inp==inp.upper():
print(inp.lower())
else:
print(inp) | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
- either it only contains uppercase letters; - or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input Specification:
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output Specification:
Print the result of the given word's processing.
Demo Input:
['cAPS\n', 'Lock\n']
Demo Output:
['Caps', 'Lock\n']
Note:
none | ```python
inp = input()
if inp[0]==inp[0].lower() and inp[1:]==inp[1:].upper():
print(inp.title())
elif inp==inp.upper():
print(inp.lower())
else:
print(inp)
``` | 3 |
|
46 | B | T-shirts from Sponsor | PROGRAMMING | 1,100 | [
"implementation"
] | B. T-shirts from Sponsor | 2 | 256 | One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not exactly paper the walls with the oversupply). After considerable brain racking and some pre-estimating, the sponsor representatives ordered a certain number of T-shirts of sizes S, M, L, XL and XXL. The T-shirts turned out to bring good luck, that's why on the contest day there built up a line of *K* participants willing to get one. Every contestant is characterized by his/her desired T-shirt size (so it happens that for all the participants it is also one of the sizes S, M, L, XL and XXL). The participants come up to get a T-shirt one by one and try to choose the most suitable one, choosing it like this. If there is still a T-shirt of the optimal size left, that he/she takes it without further ado. Otherwise the contestant would prefer to choose a T-shirt with the size as close to the optimal one as possible (the distance between neighboring sizes is considered equal to one). If the variant of choice is not unique, the contestant will take a T-shirt of a bigger size (in case he/she grows more). For example, for a person whose optimal size is L the preference list looks like this: L, XL, M, XXL, S. Using the data on how many T-shirts of every size had been ordered by the organizers, on the size of contestants in the line determine who got a T-shirt of what size. | The first line contains five non-negative integers *N**S*,<=*N**M*,<=*N**L*,<=*N**XL*,<=*N**XXL* not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer *K* (1<=≤<=*K*<=≤<=1000) which represents the number of participants. The next *K* lines contain the optimal T-shirt sizes for the contestants. The sizes are given in the order in which the participants stand in the line. It is guaranteed that *N**S*<=+<=*N**M*<=+<=*N**L*<=+<=*N**XL*<=+<=*N**XXL*<=≥<=*K*. | For each contestant, print a line containing the size of the T-shirt he/she got. | [
"1 0 2 0 1\n3\nXL\nXXL\nM\n"
] | [
"XXL\nL\nL\n"
] | none | 0 | [
{
"input": "1 0 2 0 1\n3\nXL\nXXL\nM",
"output": "XXL\nL\nL"
},
{
"input": "0 0 0 0 1\n1\nS",
"output": "XXL"
},
{
"input": "1 0 1 0 1\n1\nS",
"output": "S"
},
{
"input": "1 0 0 0 1\n2\nS\nL",
"output": "S\nXXL"
},
{
"input": "1 1 1 1 1\n2\nXL\nM",
"output": "XL\nM"
},
{
"input": "1 0 1 1 1\n3\nS\nXXL\nL",
"output": "S\nXXL\nL"
},
{
"input": "1 0 2 1 1\n4\nS\nXXL\nL\nM",
"output": "S\nXXL\nL\nL"
},
{
"input": "1 0 3 0 1\n5\nS\nS\nS\nXL\nL",
"output": "S\nL\nL\nXXL\nL"
},
{
"input": "2 1 0 1 3\n4\nXL\nM\nS\nS",
"output": "XL\nM\nS\nS"
},
{
"input": "2 2 0 2 1\n6\nS\nXXL\nM\nXL\nXXL\nXL",
"output": "S\nXXL\nM\nXL\nXL\nM"
},
{
"input": "3 1 1 4 1\n10\nXL\nL\nL\nXXL\nXXL\nXL\nL\nXXL\nS\nM",
"output": "XL\nL\nXL\nXXL\nXL\nXL\nM\nS\nS\nS"
},
{
"input": "14 3 1 0 2\n10\nS\nXL\nM\nXL\nS\nXXL\nL\nXXL\nS\nL",
"output": "S\nXXL\nM\nXXL\nS\nL\nM\nM\nS\nS"
},
{
"input": "44 314 100 272 270\n10\nXXL\nXL\nXXL\nXXL\nS\nS\nS\nS\nL\nL",
"output": "XXL\nXL\nXXL\nXXL\nS\nS\nS\nS\nL\nL"
},
{
"input": "2 22 11 9 6\n20\nXL\nXXL\nXL\nL\nXL\nXXL\nXXL\nL\nS\nL\nXXL\nXL\nXXL\nXXL\nL\nM\nL\nS\nS\nXL",
"output": "XL\nXXL\nXL\nL\nXL\nXXL\nXXL\nL\nS\nL\nXXL\nXL\nXXL\nXXL\nL\nM\nL\nS\nM\nXL"
},
{
"input": "13 0 2 4 41\n20\nS\nXXL\nXXL\nL\nXXL\nM\nL\nM\nXXL\nM\nXXL\nL\nXXL\nXL\nM\nXL\nXL\nL\nL\nM",
"output": "S\nXXL\nXXL\nL\nXXL\nL\nXL\nS\nXXL\nS\nXXL\nXL\nXXL\nXL\nS\nXL\nXXL\nXXL\nXXL\nS"
},
{
"input": "5 7 2 9 7\n30\nS\nM\nS\nXL\nXXL\nL\nXL\nL\nL\nXXL\nS\nM\nXXL\nXXL\nS\nL\nXL\nS\nL\nXXL\nXXL\nS\nM\nM\nM\nXXL\nS\nXXL\nS\nL",
"output": "S\nM\nS\nXL\nXXL\nL\nXL\nL\nXL\nXXL\nS\nM\nXXL\nXXL\nS\nXL\nXL\nS\nXL\nXXL\nXXL\nM\nM\nM\nM\nXXL\nM\nXL\nXL\nXL"
},
{
"input": "3 17 3 21 16\n50\nL\nXL\nXXL\nM\nXXL\nXL\nM\nS\nXL\nXXL\nXL\nM\nS\nS\nM\nS\nXXL\nXXL\nXL\nM\nL\nS\nXL\nS\nM\nS\nL\nXL\nM\nXL\nL\nXL\nXL\nL\nL\nM\nXL\nS\nXXL\nL\nL\nM\nL\nS\nM\nL\nXXL\nXL\nS\nL",
"output": "L\nXL\nXXL\nM\nXXL\nXL\nM\nS\nXL\nXXL\nXL\nM\nS\nS\nM\nM\nXXL\nXXL\nXL\nM\nL\nM\nXL\nM\nM\nM\nL\nXL\nM\nXL\nXL\nXL\nXL\nXL\nXL\nM\nXL\nM\nXXL\nXL\nXL\nM\nXL\nM\nM\nXL\nXXL\nXL\nM\nXL"
},
{
"input": "2 36 4 48 10\n50\nXXL\nXXL\nS\nXXL\nXL\nXL\nS\nL\nXXL\nS\nXL\nXL\nS\nXXL\nS\nS\nS\nL\nM\nM\nXXL\nS\nS\nM\nXXL\nXL\nL\nS\nM\nXL\nXL\nS\nXXL\nM\nL\nXXL\nXL\nXXL\nXXL\nXL\nL\nL\nXXL\nXL\nXXL\nL\nL\nL\nS\nXL",
"output": "XXL\nXXL\nS\nXXL\nXL\nXL\nS\nL\nXXL\nM\nXL\nXL\nM\nXXL\nM\nM\nM\nL\nM\nM\nXXL\nM\nM\nM\nXXL\nXL\nL\nM\nM\nXL\nXL\nM\nXXL\nM\nL\nXXL\nXL\nXXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nM\nXL"
},
{
"input": "450 65 82 309 94\n50\nM\nXL\nXL\nXL\nM\nM\nS\nXL\nXXL\nXL\nM\nXL\nS\nXXL\nS\nXL\nM\nXL\nM\nS\nS\nM\nXL\nS\nL\nS\nXL\nXL\nL\nL\nXL\nXL\nXL\nXXL\nXXL\nL\nXXL\nM\nXXL\nM\nXXL\nXL\nM\nXL\nL\nS\nXL\nS\nM\nXXL",
"output": "M\nXL\nXL\nXL\nM\nM\nS\nXL\nXXL\nXL\nM\nXL\nS\nXXL\nS\nXL\nM\nXL\nM\nS\nS\nM\nXL\nS\nL\nS\nXL\nXL\nL\nL\nXL\nXL\nXL\nXXL\nXXL\nL\nXXL\nM\nXXL\nM\nXXL\nXL\nM\nXL\nL\nS\nXL\nS\nM\nXXL"
},
{
"input": "200 910 49 294 547\n50\nXXL\nL\nXXL\nS\nXL\nXXL\nL\nXXL\nM\nM\nM\nM\nXXL\nS\nXXL\nXL\nL\nXXL\nL\nL\nXL\nXL\nXL\nXL\nS\nXL\nL\nXXL\nM\nXXL\nS\nXXL\nS\nXXL\nS\nS\nL\nS\nL\nXL\nXXL\nL\nL\nS\nS\nS\nS\nXXL\nXL\nXXL",
"output": "XXL\nL\nXXL\nS\nXL\nXXL\nL\nXXL\nM\nM\nM\nM\nXXL\nS\nXXL\nXL\nL\nXXL\nL\nL\nXL\nXL\nXL\nXL\nS\nXL\nL\nXXL\nM\nXXL\nS\nXXL\nS\nXXL\nS\nS\nL\nS\nL\nXL\nXXL\nL\nL\nS\nS\nS\nS\nXXL\nXL\nXXL"
},
{
"input": "85 80 1 27 7\n100\nXXL\nM\nM\nS\nL\nL\nXL\nM\nXXL\nXXL\nXL\nL\nM\nXL\nM\nXL\nXL\nS\nM\nS\nXXL\nXL\nL\nM\nS\nXL\nS\nXL\nS\nXL\nS\nM\nXXL\nL\nM\nXL\nM\nS\nL\nM\nXXL\nL\nXXL\nS\nM\nS\nM\nL\nXXL\nXXL\nM\nS\nS\nL\nXXL\nM\nXXL\nM\nS\nM\nXXL\nM\nM\nXL\nXXL\nL\nXXL\nXL\nXXL\nS\nL\nL\nS\nS\nS\nL\nM\nL\nXXL\nL\nL\nXXL\nS\nS\nS\nXL\nXXL\nXL\nS\nL\nXXL\nS\nS\nM\nL\nXXL\nXL\nXL\nL\nXXL",
"output": "XXL\nM\nM\nS\nL\nXL\nXL\nM\nXXL\nXXL\nXL\nXL\nM\nXL\nM\nXL\nXL\nS\nM\nS\nXXL\nXL\nXL\nM\nS\nXL\nS\nXL\nS\nXL\nS\nM\nXXL\nXL\nM\nXL\nM\nS\nXL\nM\nXXL\nXL\nXXL\nS\nM\nS\nM\nXL\nXL\nXL\nM\nS\nS\nXL\nXL\nM\nXL\nM\nS\nM\nXL\nM\nM\nXL\nXL\nXL\nXL\nM\nM\nS\nM\nM\nS\nS\nS\nM\nM\nM\nM\nM\nM\nM\nS\nS\nS\nM\nM\nM\nS\nM\nM\nS\nS\nM\nM\nM\nM\nM\nM\nM"
},
{
"input": "302 143 40 63 452\n100\nXXL\nM\nXL\nS\nXXL\nS\nL\nXL\nXL\nXL\nXXL\nS\nXXL\nS\nXXL\nXL\nXL\nXXL\nXL\nXXL\nM\nS\nS\nS\nS\nXXL\nS\nL\nXL\nXXL\nXXL\nS\nXXL\nL\nXXL\nM\nS\nL\nL\nXL\nXL\nS\nXL\nL\nXL\nM\nXL\nL\nM\nS\nXL\nXXL\nXL\nL\nXL\nXL\nXL\nM\nM\nXL\nL\nS\nS\nXL\nS\nXXL\nXXL\nXL\nS\nXL\nXXL\nS\nS\nL\nL\nXXL\nXL\nL\nXL\nM\nS\nM\nM\nXL\nXXL\nS\nXL\nXL\nM\nXL\nXXL\nXXL\nXL\nL\nS\nM\nXXL\nM\nL\nXXL",
"output": "XXL\nM\nXL\nS\nXXL\nS\nL\nXL\nXL\nXL\nXXL\nS\nXXL\nS\nXXL\nXL\nXL\nXXL\nXL\nXXL\nM\nS\nS\nS\nS\nXXL\nS\nL\nXL\nXXL\nXXL\nS\nXXL\nL\nXXL\nM\nS\nL\nL\nXL\nXL\nS\nXL\nL\nXL\nM\nXL\nL\nM\nS\nXL\nXXL\nXL\nL\nXL\nXL\nXL\nM\nM\nXL\nL\nS\nS\nXL\nS\nXXL\nXXL\nXL\nS\nXL\nXXL\nS\nS\nL\nL\nXXL\nXL\nL\nXL\nM\nS\nM\nM\nXL\nXXL\nS\nXL\nXL\nM\nXL\nXXL\nXXL\nXL\nL\nS\nM\nXXL\nM\nL\nXXL"
}
] | 1,584,081,021 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 2,000 | 307,200 | n=list(map(int,input().split()))
dic={}
dic['S']=n[0]
dic['M']=n[1]
dic['L']=n[2]
dic['XL']=n[3]
dic['XXL']=n[4]
lista=['S','M','L','XL','XXL']
k=int(input())
for i in range(k):
size=input()
if dic[size]!=0:
dic[size]=dic[size]-1
print(size)
else:
flag=0
ind=lista.index(size)
while(flag!=1):
if(ind==0 or ind==4):
if ind==4:
ind=ind-1
elif ind==0:
ind=ind+1
if dic[lista[ind]]!=0:
flag=1
dic[lista[ind]]-=1
print(lista[ind])
break
else:
ind=ind+1
if dic[lista[ind]]!=0:
flag=1
dic[lista[ind]]-=1
print(lista[ind])
break
else:
ind=ind-2
if dic[lista[ind]]!=0:
flag=1
dic[lista[ind]]-=1
print(lista[ind])
break
| Title: T-shirts from Sponsor
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not exactly paper the walls with the oversupply). After considerable brain racking and some pre-estimating, the sponsor representatives ordered a certain number of T-shirts of sizes S, M, L, XL and XXL. The T-shirts turned out to bring good luck, that's why on the contest day there built up a line of *K* participants willing to get one. Every contestant is characterized by his/her desired T-shirt size (so it happens that for all the participants it is also one of the sizes S, M, L, XL and XXL). The participants come up to get a T-shirt one by one and try to choose the most suitable one, choosing it like this. If there is still a T-shirt of the optimal size left, that he/she takes it without further ado. Otherwise the contestant would prefer to choose a T-shirt with the size as close to the optimal one as possible (the distance between neighboring sizes is considered equal to one). If the variant of choice is not unique, the contestant will take a T-shirt of a bigger size (in case he/she grows more). For example, for a person whose optimal size is L the preference list looks like this: L, XL, M, XXL, S. Using the data on how many T-shirts of every size had been ordered by the organizers, on the size of contestants in the line determine who got a T-shirt of what size.
Input Specification:
The first line contains five non-negative integers *N**S*,<=*N**M*,<=*N**L*,<=*N**XL*,<=*N**XXL* not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer *K* (1<=≤<=*K*<=≤<=1000) which represents the number of participants. The next *K* lines contain the optimal T-shirt sizes for the contestants. The sizes are given in the order in which the participants stand in the line. It is guaranteed that *N**S*<=+<=*N**M*<=+<=*N**L*<=+<=*N**XL*<=+<=*N**XXL*<=≥<=*K*.
Output Specification:
For each contestant, print a line containing the size of the T-shirt he/she got.
Demo Input:
['1 0 2 0 1\n3\nXL\nXXL\nM\n']
Demo Output:
['XXL\nL\nL\n']
Note:
none | ```python
n=list(map(int,input().split()))
dic={}
dic['S']=n[0]
dic['M']=n[1]
dic['L']=n[2]
dic['XL']=n[3]
dic['XXL']=n[4]
lista=['S','M','L','XL','XXL']
k=int(input())
for i in range(k):
size=input()
if dic[size]!=0:
dic[size]=dic[size]-1
print(size)
else:
flag=0
ind=lista.index(size)
while(flag!=1):
if(ind==0 or ind==4):
if ind==4:
ind=ind-1
elif ind==0:
ind=ind+1
if dic[lista[ind]]!=0:
flag=1
dic[lista[ind]]-=1
print(lista[ind])
break
else:
ind=ind+1
if dic[lista[ind]]!=0:
flag=1
dic[lista[ind]]-=1
print(lista[ind])
break
else:
ind=ind-2
if dic[lista[ind]]!=0:
flag=1
dic[lista[ind]]-=1
print(lista[ind])
break
``` | 0 |
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
},
{
"input": "4\n5 4 5 4",
"output": "-1"
},
{
"input": "7\n3 4 5 5 5 1 2",
"output": "2"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "5\n5 4 1 2 3",
"output": "-1"
},
{
"input": "4\n6 1 2 7",
"output": "-1"
},
{
"input": "5\n4 5 6 2 3",
"output": "2"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "4\n1 2 2 1",
"output": "1"
},
{
"input": "9\n4 5 6 7 1 2 3 4 10",
"output": "-1"
},
{
"input": "7\n2 3 4 1 2 3 4",
"output": "-1"
},
{
"input": "6\n1 2 1 2 1 2",
"output": "-1"
},
{
"input": "3\n3 2 1",
"output": "-1"
},
{
"input": "4\n1 4 4 1",
"output": "1"
},
{
"input": "5\n1 2 1 1 1",
"output": "3"
},
{
"input": "5\n4 6 7 3 5",
"output": "-1"
},
{
"input": "4\n2 3 1 4",
"output": "-1"
},
{
"input": "5\n5 4 3 2 1",
"output": "-1"
},
{
"input": "4\n2 4 1 4",
"output": "-1"
},
{
"input": "6\n4 5 6 1 2 7",
"output": "-1"
},
{
"input": "6\n1 2 3 1 1 1",
"output": "3"
},
{
"input": "5\n1 3 3 3 1",
"output": "1"
},
{
"input": "6\n5 6 7 5 5 5",
"output": "3"
},
{
"input": "5\n3 4 2 1 2",
"output": "-1"
},
{
"input": "3\n3 4 2",
"output": "1"
},
{
"input": "6\n1 1 2 2 1 1",
"output": "2"
},
{
"input": "4\n2 3 4 2",
"output": "1"
},
{
"input": "5\n3 5 7 7 3",
"output": "1"
},
{
"input": "4\n1 1 4 1",
"output": "1"
},
{
"input": "7\n1 5 6 1 1 1 1",
"output": "4"
},
{
"input": "5\n7 8 6 7 8",
"output": "-1"
},
{
"input": "4\n2 4 1 3",
"output": "-1"
}
] | 1,604,695,412 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 307,200 | import sys
n=int(input())
a=list(map(int,sys.stdin.readline().split()))
f=-1
j=1
while j<n:
if a[j]<a[j-1]:
if f==-1:
f=j
else:
f=-2
break
j=j+1
if f==-2:
print(-1)
elif f==-1:
print(0)
else:
print(n-f) | Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
Demo Input:
['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['1\n', '-1\n', '0\n']
Note:
none | ```python
import sys
n=int(input())
a=list(map(int,sys.stdin.readline().split()))
f=-1
j=1
while j<n:
if a[j]<a[j-1]:
if f==-1:
f=j
else:
f=-2
break
j=j+1
if f==-2:
print(-1)
elif f==-1:
print(0)
else:
print(n-f)
``` | 0 |
|
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output": "1"
},
{
"input": "86",
"output": "2"
},
{
"input": "2",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "34",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "28",
"output": "2"
},
{
"input": "23",
"output": "1"
},
{
"input": "57",
"output": "2"
},
{
"input": "29",
"output": "2"
},
{
"input": "353869285",
"output": "3"
},
{
"input": "549548646",
"output": "2"
},
{
"input": "858893424",
"output": "2"
},
{
"input": "644818852",
"output": "3"
},
{
"input": "360322525",
"output": "3"
},
{
"input": "122937520",
"output": "2"
},
{
"input": "288403032",
"output": "2"
},
{
"input": "677257481",
"output": "3"
},
{
"input": "58059561",
"output": "3"
},
{
"input": "211288847",
"output": "2"
},
{
"input": "339900034079539584",
"output": "2"
},
{
"input": "784084029310269952",
"output": "3"
},
{
"input": "774730557264864000",
"output": "3"
},
{
"input": "478233807148352256",
"output": "3"
},
{
"input": "165646874056812544",
"output": "3"
},
{
"input": "477533739511673792",
"output": "3"
},
{
"input": "660119944377002240",
"output": "3"
},
{
"input": "448375218506078080",
"output": "3"
},
{
"input": "77213334785795616",
"output": "3"
},
{
"input": "165767221702271872",
"output": "3"
},
{
"input": "1",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561",
"output": "3"
},
{
"input": "9",
"output": "0"
}
] | 1,659,867,232 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 186 | 2,150,400 | from collections import Counter
def transform(s):
c = Counter(s)
val = 0
for k in c:
val += (ord(k)-ord('0'))*c[k]
return str(val)
s = input()
count = 0
while(len(s)>=2):
s = transform(s)
count+=1
print(count)
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
Input Specification:
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Output Specification:
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Demo Input:
['0\n', '10\n', '991\n']
Demo Output:
['0\n', '1\n', '3\n']
Note:
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | ```python
from collections import Counter
def transform(s):
c = Counter(s)
val = 0
for k in c:
val += (ord(k)-ord('0'))*c[k]
return str(val)
s = input()
count = 0
while(len(s)>=2):
s = transform(s)
count+=1
print(count)
``` | 3.949631 |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
"output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000"
},
{
"input": "2\n-1000000000 1000000000",
"output": "2000000000 2000000000\n2000000000 2000000000"
},
{
"input": "10\n1 10 12 15 59 68 130 912 1239 9123",
"output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122"
},
{
"input": "5\n-2 -1 0 1 2",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "5\n-2 -1 0 1 3",
"output": "1 5\n1 4\n1 3\n1 3\n2 5"
},
{
"input": "3\n-10000 1 10000",
"output": "10001 20000\n9999 10001\n9999 20000"
},
{
"input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706",
"output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010"
},
{
"input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124",
"output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524"
},
{
"input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292",
"output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307"
},
{
"input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986",
"output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14"
},
{
"input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886",
"output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..."
},
{
"input": "3\n-1000000000 999999999 1000000000",
"output": "1999999999 2000000000\n1 1999999999\n1 2000000000"
}
] | 1,653,831,078 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 6,656,000 | n = int(input())
res = []
coordinate = [int(_) for _ in input().split()]
for i in coordinate:
for j in range(len(coordinate)):
res.append(abs(i - (coordinate[j])))
res.remove(0)
print(min(res) , max(res))
res = [] | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Output Specification:
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
Demo Input:
['4\n-5 -2 2 7\n', '2\n-1 1\n']
Demo Output:
['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n']
Note:
none | ```python
n = int(input())
res = []
coordinate = [int(_) for _ in input().split()]
for i in coordinate:
for j in range(len(coordinate)):
res.append(abs(i - (coordinate[j])))
res.remove(0)
print(min(res) , max(res))
res = []
``` | 0 |
|
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 539 896 668 36 896",
"output": "YES"
},
{
"input": "7\n674 712 674 674 674 674 674",
"output": "NO"
},
{
"input": "8\n742 742 742 742 742 289 742 742",
"output": "NO"
},
{
"input": "9\n730 351 806 806 806 630 85 757 967",
"output": "YES"
},
{
"input": "10\n324 539 83 440 834 640 440 440 440 440",
"output": "YES"
},
{
"input": "7\n925 830 925 98 987 162 356",
"output": "YES"
},
{
"input": "68\n575 32 53 351 151 942 725 967 431 108 192 8 338 458 288 754 384 946 910 210 759 222 589 423 947 507 31 414 169 901 592 763 656 411 360 625 538 549 484 596 42 603 351 292 837 375 21 597 22 349 200 669 485 282 735 54 1000 419 939 901 789 128 468 729 894 649 484 808",
"output": "YES"
},
{
"input": "22\n618 814 515 310 617 936 452 601 250 520 557 799 304 225 9 845 610 990 703 196 486 94",
"output": "YES"
},
{
"input": "44\n459 581 449 449 449 449 449 449 449 623 449 449 449 449 449 449 449 449 889 449 203 273 329 449 449 449 449 449 449 845 882 323 22 449 449 893 449 449 449 449 449 870 449 402",
"output": "NO"
},
{
"input": "90\n424 3 586 183 286 89 427 618 758 833 933 170 155 722 190 977 330 369 693 426 556 435 550 442 513 146 61 719 754 140 424 280 997 688 530 550 438 867 950 194 196 298 417 287 106 489 283 456 735 115 702 317 672 787 264 314 356 186 54 913 809 833 946 314 757 322 559 647 983 482 145 197 223 130 162 536 451 174 467 45 660 293 440 254 25 155 511 746 650 187",
"output": "YES"
},
{
"input": "14\n959 203 478 315 788 788 373 834 488 519 774 764 193 103",
"output": "YES"
},
{
"input": "81\n544 528 528 528 528 4 506 528 32 528 528 528 528 528 528 528 528 975 528 528 528 528 528 528 528 528 528 528 528 528 528 20 528 528 528 528 528 528 528 528 852 528 528 120 528 528 61 11 528 528 528 228 528 165 883 528 488 475 628 528 528 528 528 528 528 597 528 528 528 528 528 528 528 528 528 528 528 412 528 521 925",
"output": "NO"
},
{
"input": "89\n354 356 352 355 355 355 352 354 354 352 355 356 355 352 354 356 354 355 355 354 353 352 352 355 355 356 352 352 353 356 352 353 354 352 355 352 353 353 353 354 353 354 354 353 356 353 353 354 354 354 354 353 352 353 355 356 356 352 356 354 353 352 355 354 356 356 356 354 354 356 354 355 354 355 353 352 354 355 352 355 355 354 356 353 353 352 356 352 353",
"output": "YES"
},
{
"input": "71\n284 284 285 285 285 284 285 284 284 285 284 285 284 284 285 284 285 285 285 285 284 284 285 285 284 284 284 285 284 285 284 285 285 284 284 284 285 284 284 285 285 285 284 284 285 284 285 285 284 285 285 284 285 284 284 284 285 285 284 285 284 285 285 285 285 284 284 285 285 284 285",
"output": "NO"
},
{
"input": "28\n602 216 214 825 814 760 814 28 76 814 814 288 814 814 222 707 11 490 814 543 914 705 814 751 976 814 814 99",
"output": "YES"
},
{
"input": "48\n546 547 914 263 986 945 914 914 509 871 324 914 153 571 914 914 914 528 970 566 544 914 914 914 410 914 914 589 609 222 914 889 691 844 621 68 914 36 914 39 630 749 914 258 945 914 727 26",
"output": "YES"
},
{
"input": "56\n516 76 516 197 516 427 174 516 706 813 94 37 516 815 516 516 937 483 16 516 842 516 638 691 516 635 516 516 453 263 516 516 635 257 125 214 29 81 516 51 362 516 677 516 903 516 949 654 221 924 516 879 516 516 972 516",
"output": "YES"
},
{
"input": "46\n314 723 314 314 314 235 314 314 314 314 270 314 59 972 314 216 816 40 314 314 314 314 314 314 314 381 314 314 314 314 314 314 314 789 314 957 114 942 314 314 29 314 314 72 314 314",
"output": "NO"
},
{
"input": "72\n169 169 169 599 694 81 250 529 865 406 817 169 667 169 965 169 169 663 65 169 903 169 942 763 169 807 169 603 169 169 13 169 169 810 169 291 169 169 169 169 169 169 169 713 169 440 169 169 169 169 169 480 169 169 867 169 169 169 169 169 169 169 169 393 169 169 459 169 99 169 601 800",
"output": "NO"
},
{
"input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317 316 317 316 316 316 317 316 317 317 316 317 316 316 316 316 316 316 317 316 317 317 317 317 317 317 316 316 316 317 316 317 316 317 316 317 317 316 317 316 317 317 316 317 316 317 316 317 316 316 316 317 317 317 317 317 316 317 317 316 316 316 316 317 317 316 317 316 316 316 316 316 316 317 316 316 317 317 317 317 317 317 317 317 317 316 316 317",
"output": "NO"
},
{
"input": "100\n510 510 510 162 969 32 510 511 510 510 911 183 496 875 903 461 510 510 123 578 510 510 510 510 510 755 510 673 510 510 763 510 510 909 510 435 487 959 807 510 368 788 557 448 284 332 510 949 510 510 777 112 857 926 487 510 510 510 678 510 510 197 829 427 698 704 409 509 510 238 314 851 510 651 510 455 682 510 714 635 973 510 443 878 510 510 510 591 510 24 596 510 43 183 510 510 671 652 214 784",
"output": "YES"
},
{
"input": "100\n476 477 474 476 476 475 473 476 474 475 473 477 476 476 474 476 474 475 476 477 473 473 473 474 474 476 473 473 476 476 475 476 473 474 473 473 477 475 475 475 476 475 477 477 477 476 475 475 475 473 476 477 475 476 477 473 474 477 473 475 476 476 474 477 476 474 473 477 473 475 477 473 476 474 477 473 475 477 473 476 476 475 476 475 474 473 477 473 475 473 477 473 473 474 475 473 477 476 477 474",
"output": "YES"
},
{
"input": "100\n498 498 498 498 498 499 498 499 499 499 498 498 498 498 499 498 499 499 498 499 498 498 498 499 499 499 498 498 499 499 498 498 498 499 498 499 498 498 498 499 498 499 498 498 498 498 499 498 498 499 498 498 499 498 499 499 498 499 499 499 498 498 498 498 499 498 499 498 499 499 499 499 498 498 499 499 498 499 499 498 498 499 499 498 498 499 499 499 498 498 499 498 498 498 499 499 499 498 498 499",
"output": "NO"
},
{
"input": "100\n858 53 816 816 816 816 816 816 816 181 816 816 816 816 579 879 816 948 171 816 816 150 866 816 816 816 897 816 816 816 816 816 816 706 816 539 816 816 816 816 816 816 423 487 816 615 254 816 816 816 816 83 816 816 816 816 816 816 816 816 816 816 816 136 775 999 816 816 816 644 816 816 816 816 927 816 802 816 856 816 816 816 816 816 816 816 816 816 816 700 816 816 816 816 982 477 816 891 806 816",
"output": "NO"
},
{
"input": "100\n167 169 169 167 169 169 167 167 167 167 168 166 170 170 169 170 170 170 169 168 166 167 170 169 167 169 168 169 166 170 166 167 170 166 166 167 169 166 166 169 166 167 168 168 170 167 168 166 168 170 167 168 167 169 169 166 168 167 170 168 167 169 168 169 166 168 168 169 169 166 170 168 167 169 170 168 167 169 168 167 168 168 166 169 170 170 166 166 167 170 167 168 167 167 169 169 166 166 169 167",
"output": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "YES"
},
{
"input": "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "YES"
},
{
"input": "2\n1 1",
"output": "NO"
},
{
"input": "1\n1000",
"output": "YES"
},
{
"input": "12\n2 2 4 4 4 4 6 6 6 6 6 6",
"output": "YES"
}
] | 1,556,129,213 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 248 | 0 | n = int(input())
a = list(map(int, input().split()))
ok = True
for val in a:
if a.count(val) > (n+1)//2:
ok = False
break
print('YES' if ok else 'NO') | Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
Output Specification:
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
Demo Input:
['1\n1\n', '3\n1 1 2\n', '4\n7 7 7 7\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | ```python
n = int(input())
a = list(map(int, input().split()))
ok = True
for val in a:
if a.count(val) > (n+1)//2:
ok = False
break
print('YES' if ok else 'NO')
``` | 3 |
|
117 | A | Elevator | PROGRAMMING | 1,300 | [
"implementation",
"math"
] | null | null | And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All *n* participants who have made it to the finals found themselves in a huge *m*-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator?".
The hotel's elevator moves between floors according to one never changing scheme. Initially (at the moment of time 0) the elevator is located on the 1-st floor, then it moves to the 2-nd floor, then — to the 3-rd floor and so on until it reaches the *m*-th floor. After that the elevator moves to floor *m*<=-<=1, then to floor *m*<=-<=2, and so on until it reaches the first floor. This process is repeated infinitely. We know that the elevator has infinite capacity; we also know that on every floor people get on the elevator immediately. Moving between the floors takes a unit of time.
For each of the *n* participant you are given *s**i*, which represents the floor where the *i*-th participant starts, *f**i*, which represents the floor the *i*-th participant wants to reach, and *t**i*, which represents the time when the *i*-th participant starts on the floor *s**i*.
For each participant print the minimum time of his/her arrival to the floor *f**i*.
If the elevator stops on the floor *s**i* at the time *t**i*, then the *i*-th participant can enter the elevator immediately. If the participant starts on the floor *s**i* and that's the floor he wanted to reach initially (*s**i*<==<=*f**i*), then the time of arrival to the floor *f**i* for this participant is considered equal to *t**i*. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*<=≤<=105,<=2<=≤<=*m*<=≤<=108).
Next *n* lines contain information about the participants in the form of three space-separated integers *s**i* *f**i* *t**i* (1<=≤<=*s**i*,<=*f**i*<=≤<=*m*,<=0<=≤<=*t**i*<=≤<=108), described in the problem statement. | Print *n* lines each containing one integer — the time of the arrival for each participant to the required floor. | [
"7 4\n2 4 3\n1 2 0\n2 2 0\n1 2 1\n4 3 5\n1 2 2\n4 2 0\n",
"5 5\n1 5 4\n1 3 1\n1 3 4\n3 1 5\n4 2 5\n"
] | [
"9\n1\n0\n7\n10\n7\n5\n",
"12\n10\n10\n8\n7\n"
] | Let's consider the first sample. The first participant starts at floor *s* = 2 by the time equal to *t* = 3. To get to the floor *f* = 4, he has to wait until the time equals 7, that's the time when the elevator will go upwards for the second time. Then the first participant should get on the elevator and go two floors up. In this case the first participant gets to the floor *f* at time equal to 9. The second participant starts at the time *t* = 0 on the floor *s* = 1, enters the elevator immediately, and arrives to the floor *f* = 2. The third participant doesn't wait for the elevator, because he needs to arrive to the same floor where he starts. | 500 | [
{
"input": "7 4\n2 4 3\n1 2 0\n2 2 0\n1 2 1\n4 3 5\n1 2 2\n4 2 0",
"output": "9\n1\n0\n7\n10\n7\n5"
},
{
"input": "5 5\n1 5 4\n1 3 1\n1 3 4\n3 1 5\n4 2 5",
"output": "12\n10\n10\n8\n7"
},
{
"input": "5 5\n1 3 4\n4 4 2\n3 2 1\n2 4 0\n1 5 3",
"output": "10\n2\n7\n3\n12"
},
{
"input": "8 5\n2 2 91\n5 1 97\n5 1 36\n5 4 19\n2 5 50\n4 2 1\n1 4 9\n3 2 32",
"output": "91\n104\n40\n21\n60\n7\n19\n39"
},
{
"input": "7 5\n2 2 85\n4 3 76\n4 1 17\n5 4 70\n2 5 3\n3 3 14\n3 1 51",
"output": "85\n78\n24\n77\n12\n14\n56"
},
{
"input": "5 2\n1 2 0\n2 1 1\n2 2 0\n2 2 5\n2 1 4",
"output": "1\n2\n0\n5\n6"
},
{
"input": "1 2\n1 1 3",
"output": "3"
},
{
"input": "2 2\n2 2 3\n2 1 5",
"output": "3\n6"
},
{
"input": "3 4\n2 4 7\n3 3 1\n2 2 9",
"output": "9\n1\n9"
},
{
"input": "2 100000000\n2 1 3\n99999999 100000000 100000000",
"output": "199999998\n299999997"
}
] | 1,622,755,120 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n,m = map(int, input().split())
floors = list(range(1,m+1))+list(range(m-1,1,-1))
for _ in range(n):
s,f,t = map(int, input().split())
floor = floors[t%(2*m-2)]
up = t%(2*m-2)<m-1
if(floor==s):
time=0
elif(floor>s):
if(up):
time = (floor-s)+2*(m-floor)
else:
time = (floor-s)
else:
if(up):
time = (s-floor)
else:
time = (s-floor)+2*(floor-1)
if(s==f):
print(t)
elif(s<f):
if(up):
print(time+t+(f-s))
else:
print(time+t+(f-s)+(2*s-2))
else:
if(up):
print(time+t+(s-f)+(2*(m-s)))
else:
print(time+t+(s-f))
| Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All *n* participants who have made it to the finals found themselves in a huge *m*-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator?".
The hotel's elevator moves between floors according to one never changing scheme. Initially (at the moment of time 0) the elevator is located on the 1-st floor, then it moves to the 2-nd floor, then — to the 3-rd floor and so on until it reaches the *m*-th floor. After that the elevator moves to floor *m*<=-<=1, then to floor *m*<=-<=2, and so on until it reaches the first floor. This process is repeated infinitely. We know that the elevator has infinite capacity; we also know that on every floor people get on the elevator immediately. Moving between the floors takes a unit of time.
For each of the *n* participant you are given *s**i*, which represents the floor where the *i*-th participant starts, *f**i*, which represents the floor the *i*-th participant wants to reach, and *t**i*, which represents the time when the *i*-th participant starts on the floor *s**i*.
For each participant print the minimum time of his/her arrival to the floor *f**i*.
If the elevator stops on the floor *s**i* at the time *t**i*, then the *i*-th participant can enter the elevator immediately. If the participant starts on the floor *s**i* and that's the floor he wanted to reach initially (*s**i*<==<=*f**i*), then the time of arrival to the floor *f**i* for this participant is considered equal to *t**i*.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*<=≤<=105,<=2<=≤<=*m*<=≤<=108).
Next *n* lines contain information about the participants in the form of three space-separated integers *s**i* *f**i* *t**i* (1<=≤<=*s**i*,<=*f**i*<=≤<=*m*,<=0<=≤<=*t**i*<=≤<=108), described in the problem statement.
Output Specification:
Print *n* lines each containing one integer — the time of the arrival for each participant to the required floor.
Demo Input:
['7 4\n2 4 3\n1 2 0\n2 2 0\n1 2 1\n4 3 5\n1 2 2\n4 2 0\n', '5 5\n1 5 4\n1 3 1\n1 3 4\n3 1 5\n4 2 5\n']
Demo Output:
['9\n1\n0\n7\n10\n7\n5\n', '12\n10\n10\n8\n7\n']
Note:
Let's consider the first sample. The first participant starts at floor *s* = 2 by the time equal to *t* = 3. To get to the floor *f* = 4, he has to wait until the time equals 7, that's the time when the elevator will go upwards for the second time. Then the first participant should get on the elevator and go two floors up. In this case the first participant gets to the floor *f* at time equal to 9. The second participant starts at the time *t* = 0 on the floor *s* = 1, enters the elevator immediately, and arrives to the floor *f* = 2. The third participant doesn't wait for the elevator, because he needs to arrive to the same floor where he starts. | ```python
n,m = map(int, input().split())
floors = list(range(1,m+1))+list(range(m-1,1,-1))
for _ in range(n):
s,f,t = map(int, input().split())
floor = floors[t%(2*m-2)]
up = t%(2*m-2)<m-1
if(floor==s):
time=0
elif(floor>s):
if(up):
time = (floor-s)+2*(m-floor)
else:
time = (floor-s)
else:
if(up):
time = (s-floor)
else:
time = (s-floor)+2*(floor-1)
if(s==f):
print(t)
elif(s<f):
if(up):
print(time+t+(f-s))
else:
print(time+t+(f-s)+(2*s-2))
else:
if(up):
print(time+t+(s-f)+(2*(m-s)))
else:
print(time+t+(s-f))
``` | 0 |
|
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
{
"input": "8",
"output": "2 4 7 3 8 6 5"
},
{
"input": "9",
"output": "2 4 7 2 7 4 2 1"
},
{
"input": "2",
"output": "2"
},
{
"input": "11",
"output": "2 4 7 11 5 11 7 4 2 1"
},
{
"input": "12",
"output": "2 4 7 11 4 10 5 1 10 8 7"
},
{
"input": "13",
"output": "2 4 7 11 3 9 3 11 7 4 2 1"
},
{
"input": "20",
"output": "2 4 7 11 16 2 9 17 6 16 7 19 12 6 1 17 14 12 11"
},
{
"input": "25",
"output": "2 4 7 11 16 22 4 12 21 6 17 4 17 6 21 12 4 22 16 11 7 4 2 1"
},
{
"input": "30",
"output": "2 4 7 11 16 22 29 7 16 26 7 19 2 16 1 17 4 22 11 1 22 14 7 1 26 22 19 17 16"
},
{
"input": "35",
"output": "2 4 7 11 16 22 29 2 11 21 32 9 22 1 16 32 14 32 16 1 22 9 32 21 11 2 29 22 16 11 7 4 2 1"
},
{
"input": "40",
"output": "2 4 7 11 16 22 29 37 6 16 27 39 12 26 1 17 34 12 31 11 32 14 37 21 6 32 19 7 36 26 17 9 2 36 31 27 24 22 21"
},
{
"input": "45",
"output": "2 4 7 11 16 22 29 37 1 11 22 34 2 16 31 2 19 37 11 31 7 29 7 31 11 37 19 2 31 16 2 34 22 11 1 37 29 22 16 11 7 4 2 1"
},
{
"input": "50",
"output": "2 4 7 11 16 22 29 37 46 6 17 29 42 6 21 37 4 22 41 11 32 4 27 1 26 2 29 7 36 16 47 29 12 46 31 17 4 42 31 21 12 4 47 41 36 32 29 27 26"
},
{
"input": "55",
"output": "2 4 7 11 16 22 29 37 46 1 12 24 37 51 11 27 44 7 26 46 12 34 2 26 51 22 49 22 51 26 2 34 12 46 26 7 44 27 11 51 37 24 12 1 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "60",
"output": "2 4 7 11 16 22 29 37 46 56 7 19 32 46 1 17 34 52 11 31 52 14 37 1 26 52 19 47 16 46 17 49 22 56 31 7 44 22 1 41 22 4 47 31 16 2 49 37 26 16 7 59 52 46 41 37 34 32 31"
},
{
"input": "65",
"output": "2 4 7 11 16 22 29 37 46 56 2 14 27 41 56 7 24 42 61 16 37 59 17 41 1 27 54 17 46 11 42 9 42 11 46 17 54 27 1 41 17 59 37 16 61 42 24 7 56 41 27 14 2 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "70",
"output": "2 4 7 11 16 22 29 37 46 56 67 9 22 36 51 67 14 32 51 1 22 44 67 21 46 2 29 57 16 46 7 39 2 36 1 37 4 42 11 51 22 64 37 11 56 32 9 57 36 16 67 49 32 16 1 57 44 32 21 11 2 64 57 51 46 42 39 37 36"
},
{
"input": "75",
"output": "2 4 7 11 16 22 29 37 46 56 67 4 17 31 46 62 4 22 41 61 7 29 52 1 26 52 4 32 61 16 47 4 37 71 31 67 29 67 31 71 37 4 47 16 61 32 4 52 26 1 52 29 7 61 41 22 4 62 46 31 17 4 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "80",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 12 26 41 57 74 12 31 51 72 14 37 61 6 32 59 7 36 66 17 49 2 36 71 27 64 22 61 21 62 24 67 31 76 42 9 57 26 76 47 19 72 46 21 77 54 32 11 71 52 34 17 1 66 52 39 27 16 6 77 69 62 56 51 47 44 42 41"
},
{
"input": "85",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 7 21 36 52 69 2 21 41 62 84 22 46 71 12 39 67 11 41 72 19 52 1 36 72 24 62 16 56 12 54 12 56 16 62 24 72 36 1 52 19 72 41 11 67 39 12 71 46 22 84 62 41 21 2 69 52 36 21 7 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "90",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 2 16 31 47 64 82 11 31 52 74 7 31 56 82 19 47 76 16 47 79 22 56 1 37 74 22 61 11 52 4 47 1 46 2 49 7 56 16 67 29 82 46 11 67 34 2 61 31 2 64 37 11 76 52 29 7 76 56 37 19 2 76 61 47 34 22 11 1 82 74 67 61 56 52 49 47 46"
},
{
"input": "95",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 11 26 42 59 77 1 21 42 64 87 16 41 67 94 27 56 86 22 54 87 26 61 2 39 77 21 61 7 49 92 41 86 37 84 37 86 41 92 49 7 61 21 77 39 2 61 26 87 54 22 86 56 27 94 67 41 16 87 64 42 21 1 77 59 42 26 11 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "96",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 10 25 41 58 76 95 19 40 62 85 13 38 64 91 23 52 82 17 49 82 20 55 91 32 70 13 53 94 40 83 31 76 26 73 25 74 28 79 35 88 46 5 61 22 80 43 7 68 34 1 65 34 4 71 43 16 86 61 37 14 88 67 47 28 10 89 73 58 44 31 19 8 94 85 77 70 64 59 55 52 50 49"
},
{
"input": "97",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 9 24 40 57 75 94 17 38 60 83 10 35 61 88 19 48 78 12 44 77 14 49 85 25 63 5 45 86 31 74 21 66 15 62 13 62 15 66 21 74 31 86 45 5 63 25 85 49 14 77 44 12 78 48 19 88 61 35 10 83 60 38 17 94 75 57 40 24 9 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "98",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 8 23 39 56 74 93 15 36 58 81 7 32 58 85 15 44 74 7 39 72 8 43 79 18 56 95 37 78 22 65 11 56 4 51 1 50 2 53 7 60 16 71 29 86 46 7 67 30 92 57 23 88 56 25 93 64 36 9 81 56 32 9 85 64 44 25 7 88 72 57 43 30 18 7 95 86 78 71 65 60 56 53 51 50"
},
{
"input": "99",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 7 22 38 55 73 92 13 34 56 79 4 29 55 82 11 40 70 2 34 67 2 37 73 11 49 88 29 70 13 56 1 46 92 40 88 38 88 40 92 46 1 56 13 70 29 88 49 11 73 37 2 67 34 2 70 40 11 82 55 29 4 79 56 34 13 92 73 55 38 22 7 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "100",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 6 21 37 54 72 91 11 32 54 77 1 26 52 79 7 36 66 97 29 62 96 31 67 4 42 81 21 62 4 47 91 36 82 29 77 26 76 27 79 32 86 41 97 54 12 71 31 92 54 17 81 46 12 79 47 16 86 57 29 2 76 51 27 4 82 61 41 22 4 87 71 56 42 29 17 6 96 87 79 72 66 61 57 54 52 51"
}
] | 1,589,469,218 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 218 | 6,656,000 | n = int(input())
q = []
c = 1
i = 1
for _ in range(1,n):
i = i+c if i+c <= n else i+c-n
q.append(i)
c+=1
print(*q) | Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle.
Output Specification:
In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
Demo Input:
['10\n', '3\n']
Demo Output:
['2 4 7 1 6 2 9 7 6\n', '2 1\n']
Note:
none | ```python
n = int(input())
q = []
c = 1
i = 1
for _ in range(1,n):
i = i+c if i+c <= n else i+c-n
q.append(i)
c+=1
print(*q)
``` | 3.933102 |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern. | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########"
},
{
"input": "3 5",
"output": "#####\n....#\n#####"
},
{
"input": "3 6",
"output": "######\n.....#\n######"
},
{
"input": "7 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "7 4",
"output": "####\n...#\n####\n#...\n####\n...#\n####"
},
{
"input": "49 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "43 27",
"output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................."
},
{
"input": "11 15",
"output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############"
},
{
"input": "11 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "19 3",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###"
},
{
"input": "23 50",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................."
},
{
"input": "49 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "33 43",
"output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................."
},
{
"input": "33 44",
"output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......."
},
{
"input": "45 45",
"output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..."
},
{
"input": "45 49",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..."
},
{
"input": "45 3",
"output": "###\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#..\n###"
},
{
"input": "45 4",
"output": "####\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#...\n####"
},
{
"input": "5 4",
"output": "####\n...#\n####\n#...\n####"
},
{
"input": "5 5",
"output": "#####\n....#\n#####\n#....\n#####"
},
{
"input": "5 6",
"output": "######\n.....#\n######\n#.....\n######"
},
{
"input": "7 5",
"output": "#####\n....#\n#####\n#....\n#####\n....#\n#####"
},
{
"input": "7 6",
"output": "######\n.....#\n######\n#.....\n######\n.....#\n######"
},
{
"input": "7 7",
"output": "#######\n......#\n#######\n#......\n#######\n......#\n#######"
}
] | 1,685,371,669 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | def f(n,m):
snake = ""
for i in range(1,n+1):
if i%2 != 0:
snake += "#"*m+"\n"
elif i%4 == 0:
snake += "#"+(m-1)*"."+"\n"
else:
snake += (m-1)*"."+"#"+"\n"
return snake
ai = input()
ai = [int(i) for i in ai.split(" ")]
print(f(ai[0],ai[1]))
| Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern.
Input Specification:
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number.
Output Specification:
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
Demo Input:
['3 3\n', '3 4\n', '5 3\n', '9 9\n']
Demo Output:
['###\n..#\n###\n', '####\n...#\n####\n', '###\n..#\n###\n#..\n###\n', '#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n']
Note:
none | ```python
def f(n,m):
snake = ""
for i in range(1,n+1):
if i%2 != 0:
snake += "#"*m+"\n"
elif i%4 == 0:
snake += "#"+(m-1)*"."+"\n"
else:
snake += (m-1)*"."+"#"+"\n"
return snake
ai = input()
ai = [int(i) for i in ai.split(" ")]
print(f(ai[0],ai[1]))
``` | 3 |
|
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not. | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
"output": "YES"
},
{
"input": "o vetus stagnum\n rana de ripa salit\n ac sonant aquae",
"output": "NO"
},
{
"input": " furuike ya\nkawazu tobikomu\nmizu no oto ",
"output": "YES"
},
{
"input": " noch da leich\na stamperl zum aufwaerma\n da pfarrer kimmt a ",
"output": "NO"
},
{
"input": " sommerfuglene \n hvorfor bruge mange ord\n et kan gore det",
"output": "YES"
},
{
"input": " ab der mittagszeit\n ist es etwas schattiger\n ein wolkenhimmel",
"output": "NO"
},
{
"input": "tornando a vederli\ni fiori di ciliegio la sera\nson divenuti frutti",
"output": "NO"
},
{
"input": "kutaburete\nyado karu koro ya\nfuji no hana",
"output": "YES"
},
{
"input": " beginnings of poetry\n the rice planting songs \n of the interior",
"output": "NO"
},
{
"input": " door zomerregens\n zijn de kraanvogelpoten\n korter geworden",
"output": "NO"
},
{
"input": " derevo na srub\na ptitsi bezzabotno\n gnezdishko tam vyut",
"output": "YES"
},
{
"input": "writing in the dark\nunaware that my pen\nhas run out of ink",
"output": "NO"
},
{
"input": "kusaaiu\nuieueua\nuo efaa",
"output": "YES"
},
{
"input": "v\nh\np",
"output": "NO"
},
{
"input": "i\ni\nu",
"output": "NO"
},
{
"input": "awmio eoj\nabdoolceegood\nwaadeuoy",
"output": "YES"
},
{
"input": "xzpnhhnqsjpxdboqojixmofawhdjcfbscq\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\nimtqryscsahrxpic agfjh wvpmczjjdrnwj mcggxcdo",
"output": "YES"
},
{
"input": "wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr",
"output": "YES"
},
{
"input": "nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\nvcczq hddzd cvefmhxwxxyqcwkr fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd",
"output": "YES"
},
{
"input": "rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn yciktbsbyscfypx x xhkxnfpdp\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch ",
"output": "YES"
},
{
"input": "brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs",
"output": "YES"
},
{
"input": "nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\nnnebeaoiraga\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn",
"output": "NO"
},
{
"input": "lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl",
"output": "NO"
},
{
"input": "yxcboqmpwoevrdhvpxfzqmammak\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt dtzcvnvwp\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr",
"output": "NO"
},
{
"input": "qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf",
"output": "NO"
},
{
"input": "g rguhqhcrzmuqthtmwzhfyhpmqzzosa\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\npcwbliftjcvuzrsqiswohi",
"output": "NO"
},
{
"input": " ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu",
"output": "NO"
},
{
"input": "ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt",
"output": "NO"
},
{
"input": "ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo",
"output": "NO"
},
{
"input": "mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau",
"output": "NO"
},
{
"input": "ab\na\na",
"output": "NO"
},
{
"input": "on codeforcs\nbeta round is runnineg\na rustling of keys",
"output": "NO"
},
{
"input": "coooooooooooooooood\nd\nd",
"output": "NO"
},
{
"input": "on codeforces \nbeta round is runninog\n a rustling of keys",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaa\na\na",
"output": "NO"
},
{
"input": "aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"output": "YES"
},
{
"input": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"output": "NO"
},
{
"input": "aaaaaa\naaaaaa\naaaaa",
"output": "NO"
}
] | 1,603,702,384 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 280 | 819,200 | import math
import sys
import re
s1 = input().strip()
s2 = input().strip()
s3 = input().strip()
v1 = s1.count('a') + s1.count('e') + s1.count('i') + s1.count('o') + s1.count('u')
v2 = s2.count('a') + s2.count('e') + s2.count('i') + s2.count('o') + s2.count('u')
v3 = s3.count('a') + s3.count('e') + s3.count('i') + s3.count('o') + s3.count('u')
if v1 != 5 or v2 != 7 or v3 != 5:
print('NO')
else:
print('YES') | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not.
Input Specification:
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Output Specification:
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
Demo Input:
['on codeforces \nbeta round is running\n a rustling of keys \n', 'how many gallons\nof edo s rain did you drink\n cuckoo\n']
Demo Output:
['YES', 'NO']
Note:
none | ```python
import math
import sys
import re
s1 = input().strip()
s2 = input().strip()
s3 = input().strip()
v1 = s1.count('a') + s1.count('e') + s1.count('i') + s1.count('o') + s1.count('u')
v2 = s2.count('a') + s2.count('e') + s2.count('i') + s2.count('o') + s2.count('u')
v3 = s3.count('a') + s3.count('e') + s3.count('i') + s3.count('o') + s3.count('u')
if v1 != 5 or v2 != 7 or v3 != 5:
print('NO')
else:
print('YES')
``` | 3.928474 |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{
"input": "24 54 37\n60 63 6\n1 84 26",
"output": "110\n101\n011"
},
{
"input": "23 10 40\n15 6 40\n92 80 77",
"output": "101\n100\n000"
},
{
"input": "62 74 80\n95 74 93\n2 47 95",
"output": "010\n001\n110"
},
{
"input": "80 83 48\n26 0 66\n47 76 37",
"output": "000\n000\n010"
},
{
"input": "32 15 65\n7 54 36\n5 51 3",
"output": "111\n101\n001"
},
{
"input": "22 97 12\n71 8 24\n100 21 64",
"output": "100\n001\n100"
},
{
"input": "46 37 13\n87 0 50\n90 8 55",
"output": "111\n011\n000"
},
{
"input": "57 43 58\n20 82 83\n66 16 52",
"output": "111\n010\n110"
},
{
"input": "45 56 93\n47 51 59\n18 51 63",
"output": "101\n011\n100"
},
{
"input": "47 66 67\n14 1 37\n27 81 69",
"output": "001\n001\n110"
},
{
"input": "26 69 69\n85 18 23\n14 22 74",
"output": "110\n001\n010"
},
{
"input": "10 70 65\n94 27 25\n74 66 30",
"output": "111\n010\n100"
},
{
"input": "97 1 74\n15 99 1\n88 68 86",
"output": "001\n011\n000"
},
{
"input": "36 48 42\n45 41 66\n26 64 1",
"output": "001\n111\n010"
},
{
"input": "52 81 97\n29 77 71\n66 11 2",
"output": "100\n100\n111"
},
{
"input": "18 66 33\n19 49 49\n48 46 26",
"output": "011\n100\n000"
},
{
"input": "68 79 52\n51 39 100\n29 14 26",
"output": "110\n000\n111"
},
{
"input": "91 69 77\n91 26 64\n91 88 57",
"output": "001\n011\n110"
},
{
"input": "16 69 64\n48 21 80\n81 51 51",
"output": "010\n101\n111"
},
{
"input": "96 14 2\n100 18 12\n65 34 89",
"output": "111\n010\n010"
},
{
"input": "93 95 90\n8 59 42\n53 13 19",
"output": "100\n001\n111"
},
{
"input": "71 84 18\n100 19 67\n9 76 15",
"output": "010\n010\n001"
},
{
"input": "38 93 85\n21 88 64\n4 96 25",
"output": "111\n011\n000"
},
{
"input": "75 20 20\n60 5 78\n77 4 69",
"output": "011\n001\n000"
},
{
"input": "65 70 96\n19 6 83\n33 37 82",
"output": "100\n000\n011"
},
{
"input": "11 13 60\n17 13 46\n42 21 39",
"output": "000\n011\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 0",
"output": "111\n111\n111"
},
{
"input": "0 0 0\n0 1 0\n0 0 0",
"output": "101\n000\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 1",
"output": "111\n110\n100"
}
] | 1,644,227,281 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
a1=(a+b+d+1)%2
b1=(a+c+e+1)%2
c1=(b+c+f+1)%2
d1=(a+g+e+d+1)%2
e1=(d+b+f+h+e+1)%2
f1=(c+e+i+f+1)%2
g1=(d+h+g+1)%2
h1=(g+e+i+h+1)%2
i1=(h+f+i+1)%2
print(a1,b1,c1,sep="")
print(d1,e1,f1,sep="")
print(g1,h1,i1,sep="")
| Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
Input Specification:
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Output Specification:
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
Demo Input:
['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n']
Demo Output:
['001\n010\n100\n', '010\n011\n100\n']
Note:
none | ```python
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
a1=(a+b+d+1)%2
b1=(a+c+e+1)%2
c1=(b+c+f+1)%2
d1=(a+g+e+d+1)%2
e1=(d+b+f+h+e+1)%2
f1=(c+e+i+f+1)%2
g1=(d+h+g+1)%2
h1=(g+e+i+h+1)%2
i1=(h+f+i+1)%2
print(a1,b1,c1,sep="")
print(d1,e1,f1,sep="")
print(g1,h1,i1,sep="")
``` | 0 |
|
746 | A | Compote | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.
Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. | The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has. | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | 500 | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
},
{
"input": "1\n1\n4",
"output": "0"
},
{
"input": "1\n2\n3",
"output": "0"
},
{
"input": "1\n1000\n1000",
"output": "7"
},
{
"input": "1000\n1\n1000",
"output": "0"
},
{
"input": "1000\n2\n1000",
"output": "7"
},
{
"input": "1000\n500\n1000",
"output": "1750"
},
{
"input": "1000\n1000\n4",
"output": "7"
},
{
"input": "1000\n1000\n3",
"output": "0"
},
{
"input": "4\n8\n12",
"output": "21"
},
{
"input": "10\n20\n40",
"output": "70"
},
{
"input": "100\n200\n399",
"output": "693"
},
{
"input": "200\n400\n800",
"output": "1400"
},
{
"input": "199\n400\n800",
"output": "1393"
},
{
"input": "201\n400\n800",
"output": "1400"
},
{
"input": "200\n399\n800",
"output": "1393"
},
{
"input": "200\n401\n800",
"output": "1400"
},
{
"input": "200\n400\n799",
"output": "1393"
},
{
"input": "200\n400\n801",
"output": "1400"
},
{
"input": "139\n252\n871",
"output": "882"
},
{
"input": "109\n346\n811",
"output": "763"
},
{
"input": "237\n487\n517",
"output": "903"
},
{
"input": "161\n331\n725",
"output": "1127"
},
{
"input": "39\n471\n665",
"output": "273"
},
{
"input": "9\n270\n879",
"output": "63"
},
{
"input": "137\n422\n812",
"output": "959"
},
{
"input": "15\n313\n525",
"output": "105"
},
{
"input": "189\n407\n966",
"output": "1323"
},
{
"input": "18\n268\n538",
"output": "126"
},
{
"input": "146\n421\n978",
"output": "1022"
},
{
"input": "70\n311\n685",
"output": "490"
},
{
"input": "244\n405\n625",
"output": "1092"
},
{
"input": "168\n454\n832",
"output": "1176"
},
{
"input": "46\n344\n772",
"output": "322"
},
{
"input": "174\n438\n987",
"output": "1218"
},
{
"input": "144\n387\n693",
"output": "1008"
},
{
"input": "22\n481\n633",
"output": "154"
},
{
"input": "196\n280\n848",
"output": "980"
},
{
"input": "190\n454\n699",
"output": "1218"
},
{
"input": "231\n464\n928",
"output": "1617"
},
{
"input": "151\n308\n616",
"output": "1057"
},
{
"input": "88\n182\n364",
"output": "616"
},
{
"input": "12\n26\n52",
"output": "84"
},
{
"input": "204\n412\n824",
"output": "1428"
},
{
"input": "127\n256\n512",
"output": "889"
},
{
"input": "224\n446\n896",
"output": "1561"
},
{
"input": "146\n291\n584",
"output": "1015"
},
{
"input": "83\n164\n332",
"output": "574"
},
{
"input": "20\n38\n80",
"output": "133"
},
{
"input": "198\n393\n792",
"output": "1372"
},
{
"input": "120\n239\n480",
"output": "833"
},
{
"input": "208\n416\n831",
"output": "1449"
},
{
"input": "130\n260\n517",
"output": "903"
},
{
"input": "67\n134\n267",
"output": "462"
},
{
"input": "245\n490\n979",
"output": "1708"
},
{
"input": "182\n364\n727",
"output": "1267"
},
{
"input": "104\n208\n413",
"output": "721"
},
{
"input": "10\n2\n100",
"output": "7"
},
{
"input": "2\n100\n100",
"output": "14"
},
{
"input": "2\n3\n8",
"output": "7"
},
{
"input": "1\n2\n8",
"output": "7"
},
{
"input": "1\n2\n200",
"output": "7"
},
{
"input": "5\n4\n16",
"output": "14"
},
{
"input": "1\n10\n10",
"output": "7"
},
{
"input": "1\n4\n8",
"output": "7"
},
{
"input": "100\n4\n1000",
"output": "14"
},
{
"input": "2\n6\n12",
"output": "14"
},
{
"input": "10\n7\n4",
"output": "7"
},
{
"input": "2\n10\n100",
"output": "14"
},
{
"input": "2\n3\n4",
"output": "7"
},
{
"input": "1\n2\n999",
"output": "7"
},
{
"input": "1\n10\n20",
"output": "7"
},
{
"input": "100\n18\n20",
"output": "35"
},
{
"input": "100\n1\n100",
"output": "0"
},
{
"input": "3\n7\n80",
"output": "21"
},
{
"input": "2\n8\n24",
"output": "14"
},
{
"input": "1\n100\n100",
"output": "7"
},
{
"input": "2\n1\n8",
"output": "0"
},
{
"input": "10\n5\n23",
"output": "14"
}
] | 1,644,643,450 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | maxLem = int( input( ) )
maxAppl = int( input( ) )
maxPea = int( input( ) )
if maxLem > maxAppl // 2:
maxLem = maxAppl // 2
else:
maxAppl = maxLem * 2
if maxLem > maxPea // 4:
maxLem = maxPea // 4
maxAppl = maxPea // 2
else:
maxPea = maxLem * 2
print( maxPea % 4 + maxAppl + maxLem )
| Title: Compote
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.
Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.
Input Specification:
The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has.
Output Specification:
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
Demo Input:
['2\n5\n7\n', '4\n7\n13\n', '2\n3\n2\n']
Demo Output:
['7\n', '21\n', '0\n']
Note:
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | ```python
maxLem = int( input( ) )
maxAppl = int( input( ) )
maxPea = int( input( ) )
if maxLem > maxAppl // 2:
maxLem = maxAppl // 2
else:
maxAppl = maxLem * 2
if maxLem > maxPea // 4:
maxLem = maxPea // 4
maxAppl = maxPea // 2
else:
maxPea = maxLem * 2
print( maxPea % 4 + maxAppl + maxLem )
``` | 0 |
|
721 | B | Passwords | PROGRAMMING | 1,100 | [
"implementation",
"math",
"sortings",
"strings"
] | null | null | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds). | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords. | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | [
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] | [
"1 15\n",
"3 4\n"
] | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all. | 1,000 | [
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": "1 7"
},
{
"input": "2 2\nabc\nAbc\nabc",
"output": "1 2"
},
{
"input": "2 1\nab\nabc\nab",
"output": "1 1"
},
{
"input": "2 2\nab\nabc\nab",
"output": "1 1"
},
{
"input": "2 1\nab\nabc\nabc",
"output": "7 7"
},
{
"input": "2 2\nab\nabc\nabc",
"output": "2 2"
},
{
"input": "10 3\nOIbV1igi\no\nZS\nQM\n9woLzI\nWreboD\nQ7yl\nA5Rb\nS9Lno72TkP\nfT97o\no",
"output": "1 1"
},
{
"input": "10 3\nHJZNMsT\nLaPcH2C\nlrhqIO\n9cxw\noTC1XwjW\nGHL9Ul6\nUyIs\nPuzwgR4ZKa\nyIByoKR5\nd3QA\nPuzwgR4ZKa",
"output": "25 25"
},
{
"input": "20 5\nvSyC787KlIL8kZ2Uv5sw\nWKWOP\n7i8J3E8EByIq\nNW2VyGweL\nmyR2sRNu\nmXusPP0\nf4jgGxra\n4wHRzRhOCpEt\npPz9kybGb\nOtSpePCRoG5nkjZ2VxRy\nwHYsSttWbJkg\nKBOP9\nQfiOiFyHPPsw3GHo8J8\nxB8\nqCpehZEeEhdq\niOLjICK6\nQ91\nHmCsfMGTFKoFFnv238c\nJKjhg\ngkEUh\nKBOP9",
"output": "3 11"
},
{
"input": "15 2\nw6S9WyU\nMVh\nkgUhQHW\nhGQNOF\nUuym\n7rGQA\nBM8vLPRB\n9E\nDs32U\no\nz1aV2C5T\n8\nzSXjrqQ\n1FO\n3kIt\nBM8vLPRB",
"output": "44 50"
},
{
"input": "20 2\ni\n5Rp6\nE4vsr\nSY\nORXx\nh13C\nk6tzC\ne\nN\nKQf4C\nWZcdL\ndiA3v\n0InQT\nuJkAr\nGCamp\nBuIRd\nY\nM\nxZYx7\n0a5A\nWZcdL",
"output": "36 65"
},
{
"input": "20 2\naWLQ6\nSgQ9r\nHcPdj\n2BNaO\n3TjNb\nnvwFM\nqsKt7\nFnb6N\nLoc0p\njxuLq\nBKAjf\nEKgZB\nBfOSa\nsMIvr\nuIWcR\nIura3\nLAqSf\ntXq3G\n8rQ8I\n8otAO\nsMIvr",
"output": "1 65"
},
{
"input": "20 15\n0ZpQugVlN7\nm0SlKGnohN\nRFXTqhNGcn\n1qm2ZbB\nQXtJWdf78P\nbc2vH\nP21dty2Z1P\nm2c71LFhCk\n23EuP1Dvh3\nanwri5RhQN\n55v6HYv288\n1u5uKOjM5r\n6vg0GC1\nDAPYiA3ns1\nUZaaJ3Gmnk\nwB44x7V4Zi\n4hgB2oyU8P\npYFQpy8gGK\ndbz\nBv\n55v6HYv288",
"output": "6 25"
},
{
"input": "3 1\na\nb\naa\naa",
"output": "13 13"
},
{
"input": "6 3\nab\nac\nad\nabc\nabd\nabe\nabc",
"output": "9 11"
},
{
"input": "4 2\n1\n2\n11\n22\n22",
"output": "8 9"
},
{
"input": "2 1\n1\n12\n12",
"output": "7 7"
},
{
"input": "3 1\nab\nabc\nabd\nabc",
"output": "7 13"
},
{
"input": "2 1\na\nab\nab",
"output": "7 7"
},
{
"input": "5 2\na\nb\nc\nab\naa\naa",
"output": "9 15"
},
{
"input": "6 1\n1\n2\n11\n22\n111\n2222\n22",
"output": "13 19"
},
{
"input": "3 1\n1\n2\n11\n11",
"output": "13 13"
},
{
"input": "10 4\na\nb\nc\nd\ne\nf\nab\ncd\nac\nad\nac",
"output": "12 20"
},
{
"input": "4 2\na\nb\nc\nd\na",
"output": "1 9"
},
{
"input": "4 1\n1\n2\n3\n4\n4",
"output": "1 19"
},
{
"input": "5 1\na\nb\nc\nd\nef\nef",
"output": "25 25"
},
{
"input": "6 4\n1\n2\n22\n33\n44\n555\n555",
"output": "11 11"
},
{
"input": "5 2\na\nb\nc\nd\nab\nab",
"output": "15 15"
},
{
"input": "6 2\n1\n2\n3\n4\n5\n23\n23",
"output": "16 16"
},
{
"input": "4 2\na\nb\naa\nbb\naa",
"output": "8 9"
},
{
"input": "5 4\na\nbb\ncc\ndd\nee\nbb",
"output": "2 10"
},
{
"input": "4 1\na\nb\nc\nab\nab",
"output": "19 19"
},
{
"input": "7 100\na\nb\nc\nd\ne\ng\nab\nab",
"output": "7 7"
},
{
"input": "6 1\na\nb\nc\nd\ne\naa\naa",
"output": "31 31"
},
{
"input": "4 1\na\nas\nasd\nasde\nasde",
"output": "19 19"
},
{
"input": "5 2\n1\n2\n3\n11\n22\n22",
"output": "9 15"
},
{
"input": "10 2\na\nb\nc\nd\nee\nff\ngg\nhh\nii\njj\nii",
"output": "15 30"
},
{
"input": "3 1\na\nab\nbc\nab",
"output": "7 13"
},
{
"input": "6 4\na\nb\nc\nbb\nbc\ncc\ncc",
"output": "4 11"
}
] | 1,613,749,602 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 77 | 0 | n,k=map(int,input().split())
lst={}
cntless=0
cnts=0
for i in range(n):
s=input()
lst[s]=len(s)
psd=input()
lenf=len(psd)
for i in lst.values():
if(i<lenf):
cntless=cntless+1
elif(i==lenf):
cnts=cnts+1
#print(cntless)
#print(cnts)
if(cntless>k):
totalb=(((cntless+1)-k)-1)*5+cntless+1
else:
totalb=cntless+1
if((cnts+cntless)>k):
totalw=(((cntless+cnts)-k)-1)*5+cntless+cnts
else:
totalw=cntless+cnts
print(totalb,totalw,sep=' ')
| Title: Passwords
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password *k* times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his *n* passwords.
Output Specification:
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
Demo Input:
['5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n', '4 100\n11\n22\n1\n2\n22\n']
Demo Output:
['1 15\n', '3 4\n']
Note:
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all. | ```python
n,k=map(int,input().split())
lst={}
cntless=0
cnts=0
for i in range(n):
s=input()
lst[s]=len(s)
psd=input()
lenf=len(psd)
for i in lst.values():
if(i<lenf):
cntless=cntless+1
elif(i==lenf):
cnts=cnts+1
#print(cntless)
#print(cnts)
if(cntless>k):
totalb=(((cntless+1)-k)-1)*5+cntless+1
else:
totalb=cntless+1
if((cnts+cntless)>k):
totalw=(((cntless+cnts)-k)-1)*5+cntless+cnts
else:
totalw=cntless+cnts
print(totalb,totalw,sep=' ')
``` | 0 |
|
628 | D | Magic Numbers | PROGRAMMING | 2,200 | [
"dp"
] | null | null | Consider the decimal presentation of an integer. Let's call a number d-magic if digit *d* appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [*a*,<=*b*] that are multiple of *m*. Because the answer can be very huge you should only find its value modulo 109<=+<=7 (so you should find the remainder after dividing by 109<=+<=7). | The first line contains two integers *m*,<=*d* (1<=≤<=*m*<=≤<=2000, 0<=≤<=*d*<=≤<=9) — the parameters from the problem statement.
The second line contains positive integer *a* in decimal presentation (without leading zeroes).
The third line contains positive integer *b* in decimal presentation (without leading zeroes).
It is guaranteed that *a*<=≤<=*b*, the number of digits in *a* and *b* are the same and don't exceed 2000. | Print the only integer *a* — the remainder after dividing by 109<=+<=7 of the number of d-magic numbers in segment [*a*,<=*b*] that are multiple of *m*. | [
"2 6\n10\n99\n",
"2 0\n1\n9\n",
"19 7\n1000\n9999\n"
] | [
"8\n",
"4\n",
"6\n"
] | The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747. | 0 | [
{
"input": "2 6\n10\n99",
"output": "8"
},
{
"input": "2 0\n1\n9",
"output": "4"
},
{
"input": "19 7\n1000\n9999",
"output": "6"
},
{
"input": "9 4\n33\n52",
"output": "0"
},
{
"input": "10 8\n18\n59",
"output": "0"
},
{
"input": "43 3\n587\n850",
"output": "1"
},
{
"input": "65 3\n3436\n3632",
"output": "0"
},
{
"input": "850 8\n55735\n94089",
"output": "0"
},
{
"input": "590 6\n428671\n715453",
"output": "0"
},
{
"input": "1053 8\n1539368\n3362621",
"output": "0"
},
{
"input": "477 9\n3062053\n6465858",
"output": "6"
},
{
"input": "1901 9\n1941695\n3314270",
"output": "0"
},
{
"input": "29 0\n1649127\n6241670",
"output": "126"
},
{
"input": "566 3\n6372451659957700362854162843720623142601337360014410221724168092176479911659703538545016668832338549\n7969973326176891147525183958122002014921396842270051000646823226374743898663307171214245111949604186",
"output": "0"
},
{
"input": "1286 5\n1886373541983002858974907276497223649072414883083336663541044958378875954171855070620868427474284001\n4050983123791059817478363830631049287126338893626273758612677264947268375965600848751800494833017145",
"output": "0"
},
{
"input": "2 5\n1762712\n8121765",
"output": "2025"
},
{
"input": "2 2\n12\n12",
"output": "1"
},
{
"input": "2 0\n10\n10",
"output": "1"
},
{
"input": "2 6\n46\n46",
"output": "1"
},
{
"input": "2 0\n10\n20",
"output": "2"
},
{
"input": "2 9\n10000000000\n99999999999",
"output": "262440"
},
{
"input": "10 2\n12300\n99900",
"output": "70"
},
{
"input": "5 5\n5\n5",
"output": "0"
},
{
"input": "1 2\n113548484131315415454546546467913135484841313154154\n895458414564646646487131313118761454584145646466464",
"output": "970729981"
},
{
"input": "2 2\n12\n14",
"output": "1"
},
{
"input": "2 2\n2934\n4323",
"output": "18"
},
{
"input": "2 4\n1\n9",
"output": "3"
},
{
"input": "1 0\n10\n20",
"output": "2"
},
{
"input": "7 7\n7\n7",
"output": "0"
},
{
"input": "2 1\n143\n413",
"output": "12"
},
{
"input": "1 4\n1\n9",
"output": "8"
},
{
"input": "2 6\n36\n36",
"output": "1"
},
{
"input": "4 4\n24344\n48880",
"output": "29"
},
{
"input": "2 0\n1000\n9999",
"output": "81"
},
{
"input": "3 9\n39\n39",
"output": "1"
},
{
"input": "3 9\n10\n99",
"output": "2"
},
{
"input": "1 0\n10000\n99999",
"output": "729"
},
{
"input": "3 2\n681563\n828242",
"output": "48"
},
{
"input": "1 5\n454\n667",
"output": "14"
},
{
"input": "2 0\n2\n9",
"output": "4"
},
{
"input": "2 6\n7\n9",
"output": "1"
},
{
"input": "10 7\n1\n1",
"output": "0"
},
{
"input": "6 0\n1\n6",
"output": "1"
},
{
"input": "6 2\n22\n95",
"output": "2"
},
{
"input": "28 1\n102\n898",
"output": "2"
},
{
"input": "1 0\n1\n9",
"output": "9"
},
{
"input": "1 1\n1\n9",
"output": "8"
},
{
"input": "3 9\n10\n69",
"output": "2"
},
{
"input": "1 0\n1\n1",
"output": "1"
}
] | 1,588,258,956 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 307,200 | m,i=map(int,input().split(' '))
a=int(input())
b=int(input())
dem=0
t=a//m
if(t*m!=a): t+=1
while(True):
tes = t*m
s = str(tes)
for j in range(len(s)):
if(j%2==1 and s[j]!=str(i)): break
elif(j%2==0 and s[j]==str(i)): break
else: dem+=1
t+=1
if(t*m>b): break
print(dem) | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the decimal presentation of an integer. Let's call a number d-magic if digit *d* appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [*a*,<=*b*] that are multiple of *m*. Because the answer can be very huge you should only find its value modulo 109<=+<=7 (so you should find the remainder after dividing by 109<=+<=7).
Input Specification:
The first line contains two integers *m*,<=*d* (1<=≤<=*m*<=≤<=2000, 0<=≤<=*d*<=≤<=9) — the parameters from the problem statement.
The second line contains positive integer *a* in decimal presentation (without leading zeroes).
The third line contains positive integer *b* in decimal presentation (without leading zeroes).
It is guaranteed that *a*<=≤<=*b*, the number of digits in *a* and *b* are the same and don't exceed 2000.
Output Specification:
Print the only integer *a* — the remainder after dividing by 109<=+<=7 of the number of d-magic numbers in segment [*a*,<=*b*] that are multiple of *m*.
Demo Input:
['2 6\n10\n99\n', '2 0\n1\n9\n', '19 7\n1000\n9999\n']
Demo Output:
['8\n', '4\n', '6\n']
Note:
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747. | ```python
m,i=map(int,input().split(' '))
a=int(input())
b=int(input())
dem=0
t=a//m
if(t*m!=a): t+=1
while(True):
tes = t*m
s = str(tes)
for j in range(len(s)):
if(j%2==1 and s[j]!=str(i)): break
elif(j%2==0 and s[j]==str(i)): break
else: dem+=1
t+=1
if(t*m>b): break
print(dem)
``` | 0 |
|
735 | C | Tennis Championship | PROGRAMMING | 1,600 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help. | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament. | Print the maximum number of games in which the winner of the tournament can take part. | [
"2\n",
"3\n",
"4\n",
"10\n"
] | [
"1\n",
"2\n",
"2\n",
"4\n"
] | In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners. | 1,750 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "1000",
"output": "14"
},
{
"input": "2500",
"output": "15"
},
{
"input": "690000",
"output": "27"
},
{
"input": "3000000000",
"output": "45"
},
{
"input": "123456789123456789",
"output": "81"
},
{
"input": "5",
"output": "3"
},
{
"input": "143",
"output": "9"
},
{
"input": "144",
"output": "10"
},
{
"input": "145",
"output": "10"
},
{
"input": "232",
"output": "10"
},
{
"input": "233",
"output": "11"
},
{
"input": "234",
"output": "11"
},
{
"input": "679891637638612257",
"output": "84"
},
{
"input": "679891637638612258",
"output": "85"
},
{
"input": "679891637638612259",
"output": "85"
},
{
"input": "1000000000000000000",
"output": "85"
},
{
"input": "10235439547",
"output": "47"
},
{
"input": "1240723548",
"output": "43"
},
{
"input": "92353046212453",
"output": "66"
},
{
"input": "192403205846532",
"output": "68"
},
{
"input": "13925230525389",
"output": "62"
},
{
"input": "12048230592523",
"output": "62"
},
{
"input": "19204385325853",
"output": "63"
},
{
"input": "902353283921",
"output": "56"
},
{
"input": "793056859214355",
"output": "70"
},
{
"input": "982045466234565",
"output": "71"
},
{
"input": "126743950353465",
"output": "67"
},
{
"input": "12405430465",
"output": "47"
},
{
"input": "10238439257768",
"output": "61"
},
{
"input": "1728493055346",
"output": "58"
},
{
"input": "927553829046",
"output": "56"
},
{
"input": "62735129403",
"output": "51"
},
{
"input": "71624823950223",
"output": "65"
},
{
"input": "8902353464851212",
"output": "75"
},
{
"input": "61824012598535",
"output": "65"
},
{
"input": "1294902504603347",
"output": "71"
},
{
"input": "6",
"output": "3"
},
{
"input": "7",
"output": "3"
},
{
"input": "8",
"output": "4"
},
{
"input": "9",
"output": "4"
},
{
"input": "11",
"output": "4"
},
{
"input": "12",
"output": "4"
},
{
"input": "13",
"output": "5"
},
{
"input": "14",
"output": "5"
},
{
"input": "15",
"output": "5"
},
{
"input": "16",
"output": "5"
},
{
"input": "17",
"output": "5"
},
{
"input": "18",
"output": "5"
},
{
"input": "19",
"output": "5"
},
{
"input": "20",
"output": "5"
},
{
"input": "21",
"output": "6"
},
{
"input": "22",
"output": "6"
},
{
"input": "23",
"output": "6"
},
{
"input": "355687428096000",
"output": "69"
},
{
"input": "576460752303423488",
"output": "84"
},
{
"input": "32212254719",
"output": "49"
},
{
"input": "26388279066623",
"output": "63"
},
{
"input": "618473717761",
"output": "56"
},
{
"input": "262406072477",
"output": "54"
}
] | 1,481,170,882 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 62 | 4,608,000 | n = int(input())
a, b = 1, 1
ans = 0
while a + b <= n:
a = a + b
a, b = b, a
ans += 1
print(ans) | Title: Tennis Championship
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1018) — the number of players to participate in the tournament.
Output Specification:
Print the maximum number of games in which the winner of the tournament can take part.
Demo Input:
['2\n', '3\n', '4\n', '10\n']
Demo Output:
['1\n', '2\n', '2\n', '4\n']
Note:
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners. | ```python
n = int(input())
a, b = 1, 1
ans = 0
while a + b <= n:
a = a + b
a, b = b, a
ans += 1
print(ans)
``` | 3 |
|
868 | B | Race Against Time | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.
The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds.
Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.
Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).
Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face. | Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2).
Misha's position and the target time do not coincide with the position of any hand. | Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"12 30 45 3 11\n",
"12 0 1 12 1\n",
"3 47 0 4 9\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. | 500 | [
{
"input": "12 30 45 3 11",
"output": "NO"
},
{
"input": "12 0 1 12 1",
"output": "YES"
},
{
"input": "3 47 0 4 9",
"output": "YES"
},
{
"input": "10 22 59 6 10",
"output": "YES"
},
{
"input": "3 1 13 12 3",
"output": "NO"
},
{
"input": "11 19 28 9 10",
"output": "YES"
},
{
"input": "9 38 22 6 1",
"output": "NO"
},
{
"input": "5 41 11 5 8",
"output": "NO"
},
{
"input": "11 2 53 10 4",
"output": "YES"
},
{
"input": "9 41 17 10 1",
"output": "YES"
},
{
"input": "6 54 48 12 6",
"output": "YES"
},
{
"input": "12 55 9 5 1",
"output": "NO"
},
{
"input": "8 55 35 9 3",
"output": "NO"
},
{
"input": "3 21 34 3 10",
"output": "YES"
},
{
"input": "2 52 1 12 3",
"output": "NO"
},
{
"input": "7 17 11 1 7",
"output": "NO"
},
{
"input": "11 6 37 6 4",
"output": "YES"
},
{
"input": "9 6 22 8 1",
"output": "NO"
},
{
"input": "3 10 5 5 9",
"output": "YES"
},
{
"input": "7 12 22 11 2",
"output": "YES"
},
{
"input": "7 19 4 7 3",
"output": "NO"
},
{
"input": "11 36 21 4 6",
"output": "NO"
},
{
"input": "10 32 49 1 3",
"output": "YES"
},
{
"input": "1 9 43 11 3",
"output": "NO"
},
{
"input": "1 8 33 4 8",
"output": "NO"
},
{
"input": "3 0 33 9 4",
"output": "NO"
},
{
"input": "7 15 9 10 3",
"output": "NO"
},
{
"input": "8 3 57 11 1",
"output": "NO"
},
{
"input": "1 33 49 5 9",
"output": "NO"
},
{
"input": "3 40 0 5 7",
"output": "YES"
},
{
"input": "5 50 9 2 7",
"output": "NO"
},
{
"input": "10 0 52 6 1",
"output": "YES"
},
{
"input": "3 10 4 1 11",
"output": "NO"
},
{
"input": "2 41 53 4 6",
"output": "YES"
},
{
"input": "10 29 30 4 7",
"output": "NO"
},
{
"input": "5 13 54 9 11",
"output": "NO"
},
{
"input": "1 0 23 3 9",
"output": "NO"
},
{
"input": "1 0 41 12 1",
"output": "NO"
},
{
"input": "6 30 30 3 9",
"output": "YES"
},
{
"input": "3 7 32 11 10",
"output": "YES"
},
{
"input": "1 0 25 12 4",
"output": "NO"
},
{
"input": "12 0 0 5 6",
"output": "YES"
},
{
"input": "1 5 4 3 2",
"output": "YES"
},
{
"input": "6 30 30 9 10",
"output": "YES"
},
{
"input": "6 0 0 2 8",
"output": "NO"
},
{
"input": "10 50 59 9 10",
"output": "YES"
},
{
"input": "12 59 59 12 6",
"output": "NO"
},
{
"input": "3 0 30 3 4",
"output": "NO"
},
{
"input": "2 10 10 1 11",
"output": "YES"
},
{
"input": "10 5 30 1 12",
"output": "YES"
},
{
"input": "5 29 31 5 10",
"output": "YES"
},
{
"input": "5 2 2 11 2",
"output": "NO"
},
{
"input": "5 15 46 3 10",
"output": "YES"
},
{
"input": "1 30 50 1 2",
"output": "NO"
},
{
"input": "5 26 14 1 12",
"output": "YES"
},
{
"input": "1 58 43 12 1",
"output": "YES"
},
{
"input": "12 0 12 11 1",
"output": "NO"
},
{
"input": "6 52 41 6 5",
"output": "YES"
},
{
"input": "5 8 2 1 3",
"output": "NO"
},
{
"input": "2 0 0 1 3",
"output": "NO"
},
{
"input": "1 5 6 2 1",
"output": "YES"
},
{
"input": "9 5 5 11 12",
"output": "YES"
},
{
"input": "12 5 19 3 4",
"output": "NO"
},
{
"input": "6 14 59 1 3",
"output": "NO"
},
{
"input": "10 38 34 4 12",
"output": "YES"
},
{
"input": "2 54 14 2 12",
"output": "YES"
},
{
"input": "5 31 0 6 7",
"output": "NO"
},
{
"input": "6 15 30 3 9",
"output": "YES"
},
{
"input": "3 54 41 8 10",
"output": "NO"
},
{
"input": "3 39 10 10 12",
"output": "YES"
},
{
"input": "1 11 50 1 2",
"output": "NO"
},
{
"input": "5 40 24 8 1",
"output": "NO"
},
{
"input": "9 5 59 1 3",
"output": "NO"
},
{
"input": "5 0 0 6 7",
"output": "YES"
},
{
"input": "4 40 59 6 8",
"output": "YES"
},
{
"input": "10 13 55 12 1",
"output": "YES"
},
{
"input": "6 50 0 5 6",
"output": "YES"
},
{
"input": "7 59 3 7 4",
"output": "YES"
},
{
"input": "6 0 1 6 7",
"output": "NO"
},
{
"input": "6 15 55 3 5",
"output": "NO"
},
{
"input": "12 9 55 10 2",
"output": "YES"
},
{
"input": "2 0 1 11 2",
"output": "NO"
},
{
"input": "8 45 17 12 9",
"output": "NO"
},
{
"input": "5 30 31 11 3",
"output": "YES"
},
{
"input": "6 43 0 10 6",
"output": "NO"
},
{
"input": "6 30 30 1 11",
"output": "YES"
},
{
"input": "11 59 59 11 12",
"output": "YES"
},
{
"input": "5 45 35 9 5",
"output": "NO"
},
{
"input": "2 43 4 9 7",
"output": "NO"
},
{
"input": "12 30 50 6 9",
"output": "NO"
},
{
"input": "1 10 1 2 3",
"output": "NO"
},
{
"input": "10 5 55 9 1",
"output": "NO"
},
{
"input": "1 59 59 2 3",
"output": "YES"
},
{
"input": "1 49 14 10 3",
"output": "NO"
},
{
"input": "3 15 15 2 4",
"output": "YES"
},
{
"input": "10 5 55 1 5",
"output": "NO"
},
{
"input": "6 33 45 12 6",
"output": "YES"
},
{
"input": "1 20 20 11 1",
"output": "YES"
},
{
"input": "2 30 45 1 11",
"output": "YES"
},
{
"input": "1 55 1 11 10",
"output": "YES"
},
{
"input": "3 0 1 11 1",
"output": "NO"
},
{
"input": "1 5 6 1 12",
"output": "YES"
},
{
"input": "12 10 5 11 4",
"output": "YES"
},
{
"input": "6 5 59 12 1",
"output": "YES"
},
{
"input": "12 0 20 11 12",
"output": "YES"
},
{
"input": "3 25 30 4 5",
"output": "YES"
},
{
"input": "2 15 18 11 1",
"output": "YES"
},
{
"input": "12 5 48 11 9",
"output": "NO"
},
{
"input": "6 30 30 10 2",
"output": "YES"
},
{
"input": "1 0 11 1 2",
"output": "NO"
},
{
"input": "10 0 1 10 11",
"output": "NO"
},
{
"input": "3 30 45 10 1",
"output": "YES"
},
{
"input": "11 21 56 3 12",
"output": "YES"
},
{
"input": "3 16 16 3 4",
"output": "YES"
},
{
"input": "11 55 55 1 12",
"output": "YES"
},
{
"input": "12 12 12 11 12",
"output": "YES"
},
{
"input": "3 5 1 1 2",
"output": "NO"
},
{
"input": "3 30 45 10 11",
"output": "YES"
},
{
"input": "10 0 1 9 10",
"output": "YES"
},
{
"input": "3 0 5 3 6",
"output": "NO"
},
{
"input": "1 1 49 1 10",
"output": "NO"
},
{
"input": "9 45 15 11 12",
"output": "YES"
},
{
"input": "12 15 59 3 8",
"output": "NO"
},
{
"input": "5 0 5 3 6",
"output": "NO"
},
{
"input": "3 30 45 1 2",
"output": "YES"
},
{
"input": "2 10 11 2 4",
"output": "YES"
},
{
"input": "2 10 10 4 3",
"output": "YES"
},
{
"input": "3 30 59 1 2",
"output": "YES"
},
{
"input": "11 59 59 12 11",
"output": "YES"
},
{
"input": "10 25 50 5 6",
"output": "NO"
},
{
"input": "6 30 30 9 3",
"output": "YES"
},
{
"input": "8 14 40 12 3",
"output": "NO"
},
{
"input": "2 10 10 1 6",
"output": "YES"
}
] | 1,507,228,683 | 2,162 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | h,m,s,t1,t2=map(int,input().split(' '))
m=m/5+12
s=s/5+12
a=min(t1,t2)
b=max(t1,t2)
if a!=12:
a+=12
if b!=12:
b+=12
if h!=12:
h+=12
l=[h,m,s]
ans=0
for i in l:
if i>=a and i<=b:
ans+=1
if ans==0 or ans==3:
print("YES")
else:
print("NO") | Title: Race Against Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.
The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds.
Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction.
Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).
Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face.
Input Specification:
Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≤<=*h*<=≤<=12, 0<=≤<=*m*,<=*s*<=≤<=59, 1<=≤<=*t*1,<=*t*2<=≤<=12, *t*1<=≠<=*t*2).
Misha's position and the target time do not coincide with the position of any hand.
Output Specification:
Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['12 30 45 3 11\n', '12 0 1 12 1\n', '3 47 0 4 9\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n']
Note:
The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same. | ```python
h,m,s,t1,t2=map(int,input().split(' '))
m=m/5+12
s=s/5+12
a=min(t1,t2)
b=max(t1,t2)
if a!=12:
a+=12
if b!=12:
b+=12
if h!=12:
h+=12
l=[h,m,s]
ans=0
for i in l:
if i>=a and i<=b:
ans+=1
if ans==0 or ans==3:
print("YES")
else:
print("NO")
``` | 0 |
|
747 | A | Display Size | PROGRAMMING | 800 | [
"brute force",
"math"
] | null | null | A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have. | Print two integers — the number of rows and columns on the display. | [
"8\n",
"64\n",
"5\n",
"999999\n"
] | [
"2 4\n",
"8 8\n",
"1 5\n",
"999 1001\n"
] | In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels. | 500 | [
{
"input": "8",
"output": "2 4"
},
{
"input": "64",
"output": "8 8"
},
{
"input": "5",
"output": "1 5"
},
{
"input": "999999",
"output": "999 1001"
},
{
"input": "716539",
"output": "97 7387"
},
{
"input": "1",
"output": "1 1"
},
{
"input": "2",
"output": "1 2"
},
{
"input": "3",
"output": "1 3"
},
{
"input": "4",
"output": "2 2"
},
{
"input": "6",
"output": "2 3"
},
{
"input": "7",
"output": "1 7"
},
{
"input": "9",
"output": "3 3"
},
{
"input": "10",
"output": "2 5"
},
{
"input": "11",
"output": "1 11"
},
{
"input": "12",
"output": "3 4"
},
{
"input": "15",
"output": "3 5"
},
{
"input": "100",
"output": "10 10"
},
{
"input": "101",
"output": "1 101"
},
{
"input": "169",
"output": "13 13"
},
{
"input": "179",
"output": "1 179"
},
{
"input": "190",
"output": "10 19"
},
{
"input": "1000",
"output": "25 40"
},
{
"input": "10000",
"output": "100 100"
},
{
"input": "10001",
"output": "73 137"
},
{
"input": "100000",
"output": "250 400"
},
{
"input": "100001",
"output": "11 9091"
},
{
"input": "1000000",
"output": "1000 1000"
},
{
"input": "999983",
"output": "1 999983"
},
{
"input": "524288",
"output": "512 1024"
},
{
"input": "954493",
"output": "971 983"
},
{
"input": "966289",
"output": "983 983"
},
{
"input": "944663",
"output": "961 983"
},
{
"input": "912673",
"output": "97 9409"
},
{
"input": "732641",
"output": "679 1079"
},
{
"input": "232897",
"output": "343 679"
},
{
"input": "16807",
"output": "49 343"
},
{
"input": "999958",
"output": "2 499979"
},
{
"input": "990151",
"output": "1 990151"
},
{
"input": "997002",
"output": "998 999"
},
{
"input": "20",
"output": "4 5"
},
{
"input": "20261",
"output": "1 20261"
},
{
"input": "999123",
"output": "3 333041"
},
{
"input": "901841",
"output": "1 901841"
}
] | 1,587,390,050 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 155 | 0 | from math import sqrt
num = int(input())
for factor in range(int(sqrt(num)), 0, -1):
if num % factor == 0:
print(factor, num//factor)
break
| Title: Display Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have.
Output Specification:
Print two integers — the number of rows and columns on the display.
Demo Input:
['8\n', '64\n', '5\n', '999999\n']
Demo Output:
['2 4\n', '8 8\n', '1 5\n', '999 1001\n']
Note:
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels. | ```python
from math import sqrt
num = int(input())
for factor in range(int(sqrt(num)), 0, -1):
if num % factor == 0:
print(factor, num//factor)
break
``` | 3 |
|
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible. | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"input": "1 1 20",
"output": "Yes"
},
{
"input": "12 14 19",
"output": "No"
},
{
"input": "15 12 26",
"output": "No"
},
{
"input": "2 4 8",
"output": "Yes"
},
{
"input": "4 5 30",
"output": "Yes"
},
{
"input": "4 5 48",
"output": "Yes"
},
{
"input": "2 17 105",
"output": "Yes"
},
{
"input": "10 25 282",
"output": "No"
},
{
"input": "6 34 323",
"output": "No"
},
{
"input": "2 47 464",
"output": "Yes"
},
{
"input": "4 53 113",
"output": "Yes"
},
{
"input": "6 64 546",
"output": "Yes"
},
{
"input": "1 78 725",
"output": "Yes"
},
{
"input": "1 84 811",
"output": "Yes"
},
{
"input": "3 100 441",
"output": "Yes"
},
{
"input": "20 5 57",
"output": "No"
},
{
"input": "14 19 143",
"output": "No"
},
{
"input": "17 23 248",
"output": "No"
},
{
"input": "11 34 383",
"output": "Yes"
},
{
"input": "20 47 568",
"output": "Yes"
},
{
"input": "16 58 410",
"output": "Yes"
},
{
"input": "11 70 1199",
"output": "Yes"
},
{
"input": "16 78 712",
"output": "Yes"
},
{
"input": "20 84 562",
"output": "No"
},
{
"input": "19 100 836",
"output": "Yes"
},
{
"input": "23 10 58",
"output": "No"
},
{
"input": "25 17 448",
"output": "Yes"
},
{
"input": "22 24 866",
"output": "Yes"
},
{
"input": "24 35 67",
"output": "No"
},
{
"input": "29 47 264",
"output": "Yes"
},
{
"input": "23 56 45",
"output": "No"
},
{
"input": "25 66 1183",
"output": "Yes"
},
{
"input": "21 71 657",
"output": "Yes"
},
{
"input": "29 81 629",
"output": "No"
},
{
"input": "23 95 2226",
"output": "Yes"
},
{
"input": "32 4 62",
"output": "No"
},
{
"input": "37 15 789",
"output": "Yes"
},
{
"input": "39 24 999",
"output": "Yes"
},
{
"input": "38 32 865",
"output": "No"
},
{
"input": "32 50 205",
"output": "No"
},
{
"input": "31 57 1362",
"output": "Yes"
},
{
"input": "38 68 1870",
"output": "Yes"
},
{
"input": "36 76 549",
"output": "No"
},
{
"input": "35 84 1257",
"output": "No"
},
{
"input": "39 92 2753",
"output": "Yes"
},
{
"input": "44 1 287",
"output": "Yes"
},
{
"input": "42 12 830",
"output": "No"
},
{
"input": "42 27 9",
"output": "No"
},
{
"input": "49 40 1422",
"output": "No"
},
{
"input": "44 42 2005",
"output": "No"
},
{
"input": "50 55 2479",
"output": "No"
},
{
"input": "48 65 917",
"output": "No"
},
{
"input": "45 78 152",
"output": "No"
},
{
"input": "43 90 4096",
"output": "Yes"
},
{
"input": "43 94 4316",
"output": "Yes"
},
{
"input": "60 7 526",
"output": "Yes"
},
{
"input": "53 11 735",
"output": "Yes"
},
{
"input": "52 27 609",
"output": "Yes"
},
{
"input": "57 32 992",
"output": "Yes"
},
{
"input": "52 49 421",
"output": "No"
},
{
"input": "57 52 2634",
"output": "Yes"
},
{
"input": "54 67 3181",
"output": "Yes"
},
{
"input": "52 73 638",
"output": "No"
},
{
"input": "57 84 3470",
"output": "No"
},
{
"input": "52 100 5582",
"output": "No"
},
{
"input": "62 1 501",
"output": "Yes"
},
{
"input": "63 17 858",
"output": "Yes"
},
{
"input": "70 24 1784",
"output": "Yes"
},
{
"input": "65 32 1391",
"output": "Yes"
},
{
"input": "62 50 2775",
"output": "No"
},
{
"input": "62 58 88",
"output": "No"
},
{
"input": "66 68 3112",
"output": "Yes"
},
{
"input": "61 71 1643",
"output": "No"
},
{
"input": "69 81 3880",
"output": "No"
},
{
"input": "63 100 1960",
"output": "Yes"
},
{
"input": "73 6 431",
"output": "Yes"
},
{
"input": "75 19 736",
"output": "Yes"
},
{
"input": "78 25 247",
"output": "No"
},
{
"input": "79 36 2854",
"output": "Yes"
},
{
"input": "80 43 1864",
"output": "Yes"
},
{
"input": "76 55 2196",
"output": "Yes"
},
{
"input": "76 69 4122",
"output": "Yes"
},
{
"input": "76 76 4905",
"output": "No"
},
{
"input": "75 89 3056",
"output": "Yes"
},
{
"input": "73 100 3111",
"output": "Yes"
},
{
"input": "84 9 530",
"output": "No"
},
{
"input": "82 18 633",
"output": "No"
},
{
"input": "85 29 2533",
"output": "Yes"
},
{
"input": "89 38 2879",
"output": "Yes"
},
{
"input": "89 49 2200",
"output": "Yes"
},
{
"input": "88 60 4140",
"output": "Yes"
},
{
"input": "82 68 1299",
"output": "No"
},
{
"input": "90 76 2207",
"output": "No"
},
{
"input": "83 84 4923",
"output": "Yes"
},
{
"input": "89 99 7969",
"output": "Yes"
},
{
"input": "94 9 168",
"output": "No"
},
{
"input": "91 20 1009",
"output": "No"
},
{
"input": "93 23 2872",
"output": "Yes"
},
{
"input": "97 31 3761",
"output": "Yes"
},
{
"input": "99 46 1341",
"output": "Yes"
},
{
"input": "98 51 2845",
"output": "No"
},
{
"input": "93 66 3412",
"output": "No"
},
{
"input": "95 76 3724",
"output": "Yes"
},
{
"input": "91 87 6237",
"output": "Yes"
},
{
"input": "98 97 7886",
"output": "Yes"
},
{
"input": "12 17 15",
"output": "No"
},
{
"input": "93 94 95",
"output": "No"
},
{
"input": "27 43 27",
"output": "Yes"
},
{
"input": "17 43 68",
"output": "Yes"
},
{
"input": "44 12 12",
"output": "Yes"
},
{
"input": "44 50 150",
"output": "Yes"
},
{
"input": "1 1 10000",
"output": "Yes"
},
{
"input": "2 3 10000",
"output": "Yes"
},
{
"input": "100 1 10",
"output": "Yes"
},
{
"input": "3 2 1",
"output": "No"
},
{
"input": "1 1 1",
"output": "Yes"
},
{
"input": "9 9 10000",
"output": "No"
},
{
"input": "2 3 9995",
"output": "Yes"
},
{
"input": "3 5 4",
"output": "No"
},
{
"input": "99 98 100",
"output": "No"
},
{
"input": "6 10 2",
"output": "No"
},
{
"input": "1 6 5",
"output": "Yes"
},
{
"input": "1 4 3",
"output": "Yes"
},
{
"input": "3 2 3",
"output": "Yes"
},
{
"input": "1 7 6",
"output": "Yes"
},
{
"input": "2 3 9871",
"output": "Yes"
},
{
"input": "10 5 5",
"output": "Yes"
},
{
"input": "10 8 2",
"output": "No"
}
] | 1,655,140,354 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 64 | 62 | 0 | a, b, c = map(int, input().split())
ans = 0
for x in range(1,c//a +1):
if (c - a*x)%b == 0:
print("Yes")
ans = 1
break
if ans == 0:
print("No") | Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible.
Input Specification:
The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Output Specification:
Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise.
Demo Input:
['4 6 15\n', '3 2 7\n', '6 11 6\n']
Demo Output:
['No\n', 'Yes\n', 'Yes\n']
Note:
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | ```python
a, b, c = map(int, input().split())
ans = 0
for x in range(1,c//a +1):
if (c - a*x)%b == 0:
print("Yes")
ans = 1
break
if ans == 0:
print("No")
``` | 0 |
|
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "10000220"
},
{
"input": ".",
"output": "0"
},
{
"input": "-.",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "..",
"output": "00"
},
{
"input": "--.",
"output": "20"
},
{
"input": ".--.",
"output": "020"
},
{
"input": ".-.-..",
"output": "0110"
},
{
"input": "----.-.",
"output": "2201"
},
{
"input": "-..--.-.",
"output": "10201"
},
{
"input": "..--..--.",
"output": "0020020"
},
{
"input": "-.-.---.--..-..-.-.-..-..-.--.",
"output": "112120010111010120"
},
{
"input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.",
"output": "21112220010101011012011011221011"
},
{
"input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------",
"output": "11020111110111222212021020002022111100201121222020012022110010222"
},
{
"input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..",
"output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110"
},
{
"input": ".-..-.-.---.-----.--.---...-.--.-.-....-..",
"output": "01011212212021001201100010"
},
{
"input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..",
"output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210"
},
{
"input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.",
"output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220"
},
{
"input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----",
"output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122"
},
{
"input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..",
"output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110"
},
{
"input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.",
"output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020"
},
{
"input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..",
"output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200"
},
{
"input": "-.---...----...--.--...-.--.----",
"output": "121002200020200012022"
},
{
"input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.",
"output": "202020212012111010201021100001021221200011222112012201012220"
}
] | 1,685,100,561 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | n = list(input())
ans = []
i = 0
while i != len(n):
if n[i] == '.':
ans.append('0')
i += 1
elif n[i + 1] == '-':
ans.append('2')
i += 2
else:
ans.append('1')
i += 2
print(''.join(ans)) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input Specification:
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output Specification:
Output the decoded ternary number. It can have leading zeroes.
Demo Input:
['.-.--\n', '--.\n', '-..-.--\n']
Demo Output:
['012', '20', '1012']
Note:
none | ```python
n = list(input())
ans = []
i = 0
while i != len(n):
if n[i] == '.':
ans.append('0')
i += 1
elif n[i + 1] == '-':
ans.append('2')
i += 2
else:
ans.append('1')
i += 2
print(''.join(ans))
``` | 3.977 |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "499999999"
},
{
"input": "1924704072",
"output": "481176017"
},
{
"input": "73740586",
"output": "18435146"
},
{
"input": "1925088820",
"output": "481272204"
},
{
"input": "593070992",
"output": "148267747"
},
{
"input": "1925473570",
"output": "481368392"
},
{
"input": "629490186",
"output": "157372546"
},
{
"input": "1980649112",
"output": "495162277"
},
{
"input": "36661322",
"output": "9165330"
},
{
"input": "1943590793",
"output": "0"
},
{
"input": "71207034",
"output": "17801758"
},
{
"input": "1757577394",
"output": "439394348"
},
{
"input": "168305294",
"output": "42076323"
},
{
"input": "1934896224",
"output": "483724055"
},
{
"input": "297149088",
"output": "74287271"
},
{
"input": "1898001634",
"output": "474500408"
},
{
"input": "176409698",
"output": "44102424"
},
{
"input": "1873025522",
"output": "468256380"
},
{
"input": "5714762",
"output": "1428690"
},
{
"input": "1829551192",
"output": "457387797"
},
{
"input": "16269438",
"output": "4067359"
},
{
"input": "1663283390",
"output": "415820847"
},
{
"input": "42549941",
"output": "0"
},
{
"input": "1967345604",
"output": "491836400"
},
{
"input": "854000",
"output": "213499"
},
{
"input": "1995886626",
"output": "498971656"
},
{
"input": "10330019",
"output": "0"
},
{
"input": "1996193634",
"output": "499048408"
},
{
"input": "9605180",
"output": "2401294"
},
{
"input": "1996459740",
"output": "499114934"
},
{
"input": "32691948",
"output": "8172986"
},
{
"input": "1975903308",
"output": "493975826"
},
{
"input": "1976637136",
"output": "494159283"
},
{
"input": "29803038",
"output": "7450759"
},
{
"input": "1977979692",
"output": "494494922"
},
{
"input": "1978595336",
"output": "494648833"
},
{
"input": "27379344",
"output": "6844835"
},
{
"input": "1979729912",
"output": "494932477"
},
{
"input": "1980253780",
"output": "495063444"
},
{
"input": "1980751584",
"output": "495187895"
},
{
"input": "53224878",
"output": "13306219"
},
{
"input": "5",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "0"
},
{
"input": "10",
"output": "2"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "2"
},
{
"input": "13",
"output": "0"
},
{
"input": "14",
"output": "3"
},
{
"input": "15",
"output": "0"
},
{
"input": "16",
"output": "3"
},
{
"input": "17",
"output": "0"
},
{
"input": "18",
"output": "4"
},
{
"input": "19",
"output": "0"
},
{
"input": "21",
"output": "0"
},
{
"input": "22",
"output": "5"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "5"
},
{
"input": "25",
"output": "0"
},
{
"input": "26",
"output": "6"
},
{
"input": "27",
"output": "0"
},
{
"input": "28",
"output": "6"
},
{
"input": "29",
"output": "0"
},
{
"input": "30",
"output": "7"
},
{
"input": "111",
"output": "0"
},
{
"input": "55",
"output": "0"
},
{
"input": "105",
"output": "0"
},
{
"input": "199",
"output": "0"
},
{
"input": "151",
"output": "0"
}
] | 1,503,598,275 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 0 | n=int(input())
a=0
b=1
count=0
while a!=b or a<b:
a += 1
b = int((n - (2 * a)) / 2)
if a<b:
count+=1
else:
break
print(count) | Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
Output Specification:
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
Demo Input:
['6\n', '20\n']
Demo Output:
['1\n', '4\n']
Note:
There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | ```python
n=int(input())
a=0
b=1
count=0
while a!=b or a<b:
a += 1
b = int((n - (2 * a)) / 2)
if a<b:
count+=1
else:
break
print(count)
``` | 0 |
|
14 | A | Letter | PROGRAMMING | 800 | [
"implementation"
] | A. Letter | 1 | 64 | A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides. | The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square. | Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. | [
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] | [
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] | none | 0 | [
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input": "5 1\n.\n*\n.\n.\n.",
"output": "*"
},
{
"input": "1 6\n*****.",
"output": "*****"
},
{
"input": "2 2\n..\n*.",
"output": "*"
},
{
"input": "8 2\n..\n..\n..\n..\n..\n*.\n..\n..",
"output": "*"
},
{
"input": "50 1\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.\n.\n.\n.\n.\n.\n.\n.",
"output": "*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*"
},
{
"input": "2 1\n*\n.",
"output": "*"
},
{
"input": "5 1\n*\n*\n*\n*\n*",
"output": "*\n*\n*\n*\n*"
},
{
"input": "2 2\n*.\n..",
"output": "*"
},
{
"input": "3 4\n...*\n*...\n..*.",
"output": "...*\n*...\n..*."
},
{
"input": "8 2\n**\n**\n**\n**\n**\n**\n**\n**",
"output": "**\n**\n**\n**\n**\n**\n**\n**"
},
{
"input": "50 1\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*\n*\n.\n.\n.\n.\n.\n.",
"output": "*\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*"
}
] | 1,644,226,417 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 154 | 1,331,200 | def main():
n, m = list(map(int, input().split()))
arr = []
for _ in range(n):
arr.append(input())
mn_i, mx_i, mx_j, mn_j = n, -1, -1, m
for i in range(n):
for j in range(m):
if arr[i][j] == "*":
mn_i = min(mn_i, i)
mx_i = max(mx_i, i)
mn_j = min(mn_j, j)
mx_j = max(mx_j, j)
for i in range(mn_i, mx_i + 1):
print(arr[i][mn_j : mx_j + 1])
if __name__ == "__main__":
main()
| Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input Specification:
The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output Specification:
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Demo Input:
['6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n', '3 3\n***\n*.*\n***\n']
Demo Output:
['***\n*..\n***\n*..\n***\n', '***\n*.*\n***\n']
Note:
none | ```python
def main():
n, m = list(map(int, input().split()))
arr = []
for _ in range(n):
arr.append(input())
mn_i, mx_i, mx_j, mn_j = n, -1, -1, m
for i in range(n):
for j in range(m):
if arr[i][j] == "*":
mn_i = min(mn_i, i)
mx_i = max(mx_i, i)
mn_j = min(mn_j, j)
mx_j = max(mx_j, j)
for i in range(mn_i, mx_i + 1):
print(arr[i][mn_j : mx_j + 1])
if __name__ == "__main__":
main()
``` | 3.913082 |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use. | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "1"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111",
"output": "10"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "8\n10101010",
"output": "10000"
},
{
"input": "2\n10",
"output": "10"
},
{
"input": "3\n111",
"output": "1"
},
{
"input": "5\n11100",
"output": "100"
},
{
"input": "2\n11",
"output": "1"
},
{
"input": "3\n110",
"output": "10"
},
{
"input": "50\n10010010000000000000000000000000000000001000000000",
"output": "10000000000000000000000000000000000000000000000"
}
] | 1,578,585,442 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | a=input;a();k=a();print(k[0]+"0"*k.count("0")) | Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
Input Specification:
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Output Specification:
Print one string — the minimum correct string that you can obtain from the given one.
Demo Input:
['4\n1001\n', '1\n1\n']
Demo Output:
['100\n', '1\n']
Note:
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use. | ```python
a=input;a();k=a();print(k[0]+"0"*k.count("0"))
``` | 0 |
|
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.
Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$
The sum of an empty array is $0$.
Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible. | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": "9"
}
] | 1,593,703,244 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 436 | 38,400,000 | n=int(input())
arr=list(map(int,input().split()))
cum=[0]*(n+1)
for i in range(n-1,-1,-1):
cum[i]=cum[i+1]+arr[i]
ma=0
s={0}
ss=0
for i in range(n-1):
ss+=arr[i]
s.add(ss)
if cum[i+1] in s:
ma=max(ma,cum[i+1])
print(ma)
| Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.
Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$
The sum of an empty array is $0$.
Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$.
Output Specification:
Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$).
Demo Input:
['5\n1 3 1 1 4\n', '5\n1 3 2 1 4\n', '3\n4 1 2\n']
Demo Output:
['5\n', '4\n', '0\n']
Note:
In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | ```python
n=int(input())
arr=list(map(int,input().split()))
cum=[0]*(n+1)
for i in range(n-1,-1,-1):
cum[i]=cum[i+1]+arr[i]
ma=0
s={0}
ss=0
for i in range(n-1):
ss+=arr[i]
s.add(ss)
if cum[i+1] in s:
ma=max(ma,cum[i+1])
print(ma)
``` | 3 |
|
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.
Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$
The sum of an empty array is $0$.
Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible. | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": "9"
}
] | 1,595,613,611 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 249 | 23,449,600 | a=int(input())
z=list(map(int,input().split()))
i=0;j=a-1
s,s1,s2=0,0,0
while(i<=j):
if s1==s2:
s=s1
s2+=z[j]
j-=1
elif s1>s2:s2+=z[j];j-=1
else:s1+=z[i];i+=1
if s1==s2:print(max(s1,s))
else:print(s) | Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.
Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$
The sum of an empty array is $0$.
Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$.
Output Specification:
Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$).
Demo Input:
['5\n1 3 1 1 4\n', '5\n1 3 2 1 4\n', '3\n4 1 2\n']
Demo Output:
['5\n', '4\n', '0\n']
Note:
In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | ```python
a=int(input())
z=list(map(int,input().split()))
i=0;j=a-1
s,s1,s2=0,0,0
while(i<=j):
if s1==s2:
s=s1
s2+=z[j]
j-=1
elif s1>s2:s2+=z[j];j-=1
else:s1+=z[i];i+=1
if s1==s2:print(max(s1,s))
else:print(s)
``` | 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,535,077,266 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 0 | '''
5 1
5 10 7 3 20
outputCopy
3
'''
nod, extra = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
maxp = max(arr)
for i in range(1, nod):
maxp = max(maxp, (arr[i-1] - arr[i] - extra))
print(maxp)
| 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
'''
5 1
5 10 7 3 20
outputCopy
3
'''
nod, extra = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
maxp = max(arr)
for i in range(1, nod):
maxp = max(maxp, (arr[i-1] - arr[i] - extra))
print(maxp)
``` | 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,647,379,500 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 93 | 2,252,800 |
def free_ice_cream():
n,ice_cream = map(int,input().split())
num_distressed = 0
for _ in range(n):
operation,amount = input().split()
amount = int(amount)
if operation == '+':
ice_cream += amount
else:
if amount > ice_cream:
num_distressed += 1
else:
ice_cream -= amount
print(ice_cream,num_distressed)
free_ice_cream()
| 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
def free_ice_cream():
n,ice_cream = map(int,input().split())
num_distressed = 0
for _ in range(n):
operation,amount = input().split()
amount = int(amount)
if operation == '+':
ice_cream += amount
else:
if amount > ice_cream:
num_distressed += 1
else:
ice_cream -= amount
print(ice_cream,num_distressed)
free_ice_cream()
``` | 3 |
|
990 | B | Micro-World | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$.
The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i > a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i > a_j$ and $a_i \le a_j + K$. The swallow operations go one after another.
For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish.
Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope. | The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$.
The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. | Print the only integer — minimal possible number of bacteria can remain. | [
"7 1\n101 53 42 102 101 55 54\n",
"6 5\n20 15 10 15 20 25\n",
"7 1000000\n1 1 1 1 1 1 1\n"
] | [
"3\n",
"1\n",
"7\n"
] | The first example is clarified in the problem statement.
In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$.
In the third example no bacteria can swallow any other bacteria. | 0 | [
{
"input": "7 1\n101 53 42 102 101 55 54",
"output": "3"
},
{
"input": "6 5\n20 15 10 15 20 25",
"output": "1"
},
{
"input": "7 1000000\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 4\n8",
"output": "1"
},
{
"input": "10 1\n1 2 3 5 6 8 10 11 9 4",
"output": "2"
},
{
"input": "9 2\n1 6 1 5 5 8 6 8 7",
"output": "4"
},
{
"input": "15 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15"
},
{
"input": "2 1000000\n1 1000000",
"output": "1"
},
{
"input": "7 2\n1 5 5 8 9 8 8",
"output": "4"
},
{
"input": "10 1\n2 6 3 4 2 4 4 3 2 1",
"output": "4"
},
{
"input": "4 1\n2 2 1 1",
"output": "2"
},
{
"input": "10 1\n6 3 1 3 6 4 1 3 6 4",
"output": "7"
},
{
"input": "2 1\n1 1",
"output": "2"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "8 2\n3 13 9 8 3 13 9 14",
"output": "5"
},
{
"input": "8 1000000\n1 1 5 1000000 1000000 2 2 2",
"output": "2"
},
{
"input": "2 1\n999152 999153",
"output": "1"
}
] | 1,601,389,852 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 358 | 14,643,200 | n,k=map(int,input().split())
a=sorted(map(int,input().split()))
r,l=0,1
for i in range(1,n):
if a[i]==a[i-1]:l+=1
elif a[i]-a[i-1]<=k:r+=l;l=1
print(n-r) | Title: Micro-World
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$.
The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i > a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i > a_j$ and $a_i \le a_j + K$. The swallow operations go one after another.
For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish.
Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.
Input Specification:
The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$.
The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have.
Output Specification:
Print the only integer — minimal possible number of bacteria can remain.
Demo Input:
['7 1\n101 53 42 102 101 55 54\n', '6 5\n20 15 10 15 20 25\n', '7 1000000\n1 1 1 1 1 1 1\n']
Demo Output:
['3\n', '1\n', '7\n']
Note:
The first example is clarified in the problem statement.
In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$.
In the third example no bacteria can swallow any other bacteria. | ```python
n,k=map(int,input().split())
a=sorted(map(int,input().split()))
r,l=0,1
for i in range(1,n):
if a[i]==a[i-1]:l+=1
elif a[i]-a[i-1]<=k:r+=l;l=1
print(n-r)
``` | 0 |
|
7 | A | Kalevitch and Chess | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms"
] | A. Kalevitch and Chess | 2 | 64 | A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.
As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.
Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.
It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task. | The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black.
It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row). | Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. | [
"WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n",
"WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n"
] | [
"3\n",
"1\n"
] | none | 0 | [
{
"input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW",
"output": "3"
},
{
"input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "1"
},
{
"input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "0"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "8"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBW",
"output": "14"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "14"
},
{
"input": "BBBBBBBB\nWBBBWBBW\nBBBBBBBB\nWBBBWBBW\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW",
"output": "9"
},
{
"input": "BBBBBBBB\nWBBWWWBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB",
"output": "9"
},
{
"input": "BBBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB",
"output": "8"
},
{
"input": "WWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "8"
},
{
"input": "BBBBBBBB\nWBWWBBBW\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nBBBBBBBB",
"output": "7"
},
{
"input": "WBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW",
"output": "9"
},
{
"input": "BBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "11"
},
{
"input": "WWBWBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nWWBWBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB",
"output": "10"
},
{
"input": "WBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nBBBBBBBB\nWBBWBBBW\nWBBWBBBW",
"output": "6"
},
{
"input": "BBBWBBBW\nBBBWBBBW\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB\nBBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB",
"output": "9"
},
{
"input": "BBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "9"
},
{
"input": "WBBBBBWB\nBBBBBBBB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nBBBBBBBB",
"output": "8"
},
{
"input": "WBBBWWBW\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nWBBBWWBW\nWBBBWWBW",
"output": "6"
},
{
"input": "WBBBBWBB\nBBBBBBBB\nBBBBBBBB\nWBBBBWBB\nWBBBBWBB\nBBBBBBBB\nWBBBBWBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB",
"output": "11"
},
{
"input": "BBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW",
"output": "9"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB",
"output": "9"
},
{
"input": "BWBBBWWB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB",
"output": "10"
},
{
"input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB",
"output": "12"
},
{
"input": "BWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB",
"output": "7"
},
{
"input": "WWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB\nWWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB",
"output": "6"
},
{
"input": "BWBBWWWW\nBWBBWWWW\nBWBBWWWW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWWWW\nBBBBBBBB",
"output": "7"
}
] | 1,667,411,584 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#include <math.h>
#include<stdint.h>
#include<cstdint>
#include <algorithm>
using namespace std;
//------------------ The code has been written by Tashvik Srivastava ------------------//
#define GODSPEED ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define TEST int t; cin>>t; for(int i = 0;i<t;i++)
#define NoTEST int t = 1; while(t--)
#define inp(v) for (int i = 0; i < n; ++i) {cin>>tp;v.push_back(tp);}
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define popb pop_back
#define forn(i, x, n) for (ll i = x; i < n; i++)
#define fornb(i, n, x) for (ll i = n; i >=x; i--)
#define endl "\n"
#define unt uint32_t
#define bins(x , y , z) binary_search(x , y , z)
#define c(x) __builtin_ctz(x)
const int MAX = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
int t,n,m,q,u,v,T,a,i[200200];
//______________________________________________________________________________________________
//____________________________________________________________________________________________
int remove0(int n);
int ispalin(string S);
//first try (time taken about 15 min)
//best case complexity of O(n)
int findd(std::vector<int> v , int n , int x);
//------------------------------------------------------------------------------------------------------------------
//to find if given sum is sum of pairs in an array
int FindPairSum(std::vector<int> A, int N, int SUM)
{
int i = 0;int j = N - 1;
while (i < j) {if (A[i] + A[j] == SUM) return 1;
else if (A[i] + A[j] < SUM) i++;
else j--;
}
return 0;
}
//-------------------------------------------------------------------------------------------------------------------
//to find sum of all vectors in an array
int vecsum(std::vector<int> v , int n)
{
int sum = 0;
forn(i,0,n)
{
sum+=v[i];
}
return sum;
}
//------------------------------------------------------------------------------------------------------------------
//tpix sum vector
vector<int> tpixsum(std::vector<int> v , int n)
{
std::vector<int> r;
r[0]=v[0];
for (int i = 1; i < n; ++i)
{
/* code */
r[i]=r[i-1]+v[i];
}
return r;
}
//------------------------------------------------------------------------------------------------------------------
//returns gcd
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
//------------------------------------------------------------------------------------------------------------------
//returns lcm
long long lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
//------------------------------------------------------------------------------------------------------------------
ll isSorted(vector<ll> A)
{
ll n = A.size();
forn(i, 0, n - 1)
{
if (A[i] > A[i + 1])
return 0;
}
return 1;
}
//------------------------------------------------------------------------------------------------------------------
long long int printPair(std::vector<ll> arr, ll n, ll sum)
{
ll cnt = 0; // Initialize result
// Consider all possible pairs and check
// their sums
bool *visited=new bool[n]();
for (ll i = 0; i < n; i++){
if(visited[i]) continue;
for (ll j = i + 1; j < n; j++){
if(visited[j]) continue;
if (arr[i] + arr[j] == sum){
cnt++;
visited[j]=true;
break;
}
}
}
return cnt;
}
//------------------------------------------------------------------------------------------------------------------
set<long long> prim(int n)
{
n++;
bool *arr=new bool[n];
for(int i=0;i<n;i++)
arr[i]=true;
set<long long> se;
for(int i=2;i*i<n;i++)
if(arr[i])
for(int k=i*i;k<n;k+=i)
arr[k]=false;
for(int i=2;i<n;i++)
if(arr[i])
se.insert(i);
return se;
}
//------------------------------------------------------------------------------------------------------------------
bool check_eqvec(std::vector<int> arr, int n)
{
bool flag = false;
for(int i = 0; i < n - 1; i++)
{
if(arr[i] != arr[i + 1])
flag = true;
}
return flag;
}
//------------------------------------------------------------------------------------------------------------------
void remove(std::vector<ll> v)
{
auto end = v.end();
for (auto it = v.begin(); it != end; ++it) {
end = std::remove(it + 1, end, *it);
}
v.erase(end, v.end());
}
//------------------------------------------------------------------------------------------------------------------
//RETURNS A SET OF DIVISORS OF N
set<int64_t> printDivisors(int64_t n)
{
// Vector to store half of the divisors
set<int64_t> v;
for (int i = 1; i <= sqrt(n); i++)
{
if (n % i == 0)
{
// check if divisors are equal
if (n / i == i)
{
// printf("%d ", i);
v.insert(i);
}
else
{
// printf("%d ", i);
v.insert(i);
// push the second divisor in the vector
v.insert(n / i);
}
}
}
return v;
// // The vector will be printed in reverse
// for (int i = v.size() - 1; i >= 0; i--)
// printf("%d ", v[i]);
}
//------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------
struct hashFunction
{
size_t operator()(const pair<int ,
int> &x) const
{
return x.first ^ x.second;
}
};
//------------------------------------------------------------------------------------------------------------------
int cntdig(int n)
{
int cnt = 0 ;
while(n!=0)
{
n/=10;
cnt++;
}
return cnt;
}
//------------------------------------------------------------------------------------------------------------------
bool isPowerOfTwo(int n)
{
if(n==0)
return false;
return (ceil(log2(n)) == floor(log2(n)));
}
//-------------------------------------------------------------------------------------
int Search(int arr[], int l, int r, int x)
{
if (r >= l)
{
int mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return Search(arr, l, mid - 1, x);
return Search(arr, mid + 1, r, x);
}
return -1;
}
//-------------------------------------------------------------------------------------
ll sum_nat(int n)
{
return n * 1ll * (n + 1) / 2;
}
//-------------------------------------------------------------------------------------
bool check_sqr(long double x)
{
if(x>=0)
{
ll sr = sqrt(x);
return(sr*sr==x);
}
return false;
}
//-------------------------------------------------------------------------------------
bool check_even(int n)
{
if(n & 1)
return 0;
else
return 1;
}
//-------------------------------------------------------------------------------------
int count1bits(uint32_t n)
{ // counts number of ones in a bitmask
return bitset < 32 > (n).count();
}
//-------------------------------------------------------------------------------------
double getroot(int n , int m )
{
/*
// Using Binary Search
double low = 1 , high = m, eps = 1e-6;
while((high - low)>eps)
{
double mid = (low+high)/2;
if(pow(mid , n)<m) low = mid;
else high = mid;
}
*/
return pow(m , (double)(1.0/(double)n));
}
//-------------------------------------------------------------------------------------
int factorial( int n)
{
if (n == 0 || n == 1)
return 1;
return n * factorial(n - 1);
}
//-------------------------------------------------------------------------------------
int f(int x){
cin>>u>>v;
u=min(u,v);
a+=!(i[u]+=x)-(i[u]==1&x==1);
}
//-------------------------------------------------------------------------------------
bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
//-------------------------------------------------------------------------------------
//solve function
bool helper(deque<int> &a,int k)
{
int i=1;
while(i<=k)
{
sort(a.begin(),a.end());
if(a[0]>k-i+1)
{
return false;
}
int ind=a.size();
for(int j=a.size()-1;j>=0;--j)
{
if(a[j]<=k-i+1)
{
ind=j;
break;
}
}
a.erase(a.begin()+ind);
a[0]+=k-i+1;
i++;
}
return true;
}
void solve()
{
/* ll n;
cin>>n;
string str;
cin>>str;
int cnt = 0;
for(auto &it : str)
{
if(it == 'Q')
cnt++;
else
cnt--;
if(cnt < 0)
cnt = 0;
}
if(cnt == 0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
*/
// ll a , k;
// cin>>a>>k;
// vector<int> v;
// for (int i = 2; i <= n; i++) {
// bool flag = 1;
// for (int j = 2; j <= i / 2; ++j) {
// if (i % j == 0) {
// flag = 0;
// break;
// }
// }
// if (flag == 1)
// v.push_back(i);
// }
// for(int i = 0;i<v.size()-1;i++)
// {
// if( (v[i]+v[i+1]+1)%2 == 0 )
// {
// cout<<"YES"<<endl;
// return;
// }
// }
// cout<<"NO"<<endl;
string s;
int r = 0 , c = 0;
int x = 8;
int res = 0 , tmp = INT_MAX;
while(x--)
{
cin>>s;
int cnt = 0;
for(auto &it : s)
if(it == 'B')
cnt++;
if(cnt == 8)
res++;
tmp = min(cnt , tmp);
}
if(res == 8)
cout<<8<<endl;
else
cout<<res+tmp<<endl;
}
//------------------------------------------------------------------------------------------------------------------
int main()
{
GODSPEED
NoTEST
solve();
}
| Title: Kalevitch and Chess
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.
As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.
Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.
It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.
Input Specification:
The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black.
It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).
Output Specification:
Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.
Demo Input:
['WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n', 'WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
#include <bits/stdc++.h>
#include <math.h>
#include<stdint.h>
#include<cstdint>
#include <algorithm>
using namespace std;
//------------------ The code has been written by Tashvik Srivastava ------------------//
#define GODSPEED ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define TEST int t; cin>>t; for(int i = 0;i<t;i++)
#define NoTEST int t = 1; while(t--)
#define inp(v) for (int i = 0; i < n; ++i) {cin>>tp;v.push_back(tp);}
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define popb pop_back
#define forn(i, x, n) for (ll i = x; i < n; i++)
#define fornb(i, n, x) for (ll i = n; i >=x; i--)
#define endl "\n"
#define unt uint32_t
#define bins(x , y , z) binary_search(x , y , z)
#define c(x) __builtin_ctz(x)
const int MAX = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
int t,n,m,q,u,v,T,a,i[200200];
//______________________________________________________________________________________________
//____________________________________________________________________________________________
int remove0(int n);
int ispalin(string S);
//first try (time taken about 15 min)
//best case complexity of O(n)
int findd(std::vector<int> v , int n , int x);
//------------------------------------------------------------------------------------------------------------------
//to find if given sum is sum of pairs in an array
int FindPairSum(std::vector<int> A, int N, int SUM)
{
int i = 0;int j = N - 1;
while (i < j) {if (A[i] + A[j] == SUM) return 1;
else if (A[i] + A[j] < SUM) i++;
else j--;
}
return 0;
}
//-------------------------------------------------------------------------------------------------------------------
//to find sum of all vectors in an array
int vecsum(std::vector<int> v , int n)
{
int sum = 0;
forn(i,0,n)
{
sum+=v[i];
}
return sum;
}
//------------------------------------------------------------------------------------------------------------------
//tpix sum vector
vector<int> tpixsum(std::vector<int> v , int n)
{
std::vector<int> r;
r[0]=v[0];
for (int i = 1; i < n; ++i)
{
/* code */
r[i]=r[i-1]+v[i];
}
return r;
}
//------------------------------------------------------------------------------------------------------------------
//returns gcd
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
//------------------------------------------------------------------------------------------------------------------
//returns lcm
long long lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
//------------------------------------------------------------------------------------------------------------------
ll isSorted(vector<ll> A)
{
ll n = A.size();
forn(i, 0, n - 1)
{
if (A[i] > A[i + 1])
return 0;
}
return 1;
}
//------------------------------------------------------------------------------------------------------------------
long long int printPair(std::vector<ll> arr, ll n, ll sum)
{
ll cnt = 0; // Initialize result
// Consider all possible pairs and check
// their sums
bool *visited=new bool[n]();
for (ll i = 0; i < n; i++){
if(visited[i]) continue;
for (ll j = i + 1; j < n; j++){
if(visited[j]) continue;
if (arr[i] + arr[j] == sum){
cnt++;
visited[j]=true;
break;
}
}
}
return cnt;
}
//------------------------------------------------------------------------------------------------------------------
set<long long> prim(int n)
{
n++;
bool *arr=new bool[n];
for(int i=0;i<n;i++)
arr[i]=true;
set<long long> se;
for(int i=2;i*i<n;i++)
if(arr[i])
for(int k=i*i;k<n;k+=i)
arr[k]=false;
for(int i=2;i<n;i++)
if(arr[i])
se.insert(i);
return se;
}
//------------------------------------------------------------------------------------------------------------------
bool check_eqvec(std::vector<int> arr, int n)
{
bool flag = false;
for(int i = 0; i < n - 1; i++)
{
if(arr[i] != arr[i + 1])
flag = true;
}
return flag;
}
//------------------------------------------------------------------------------------------------------------------
void remove(std::vector<ll> v)
{
auto end = v.end();
for (auto it = v.begin(); it != end; ++it) {
end = std::remove(it + 1, end, *it);
}
v.erase(end, v.end());
}
//------------------------------------------------------------------------------------------------------------------
//RETURNS A SET OF DIVISORS OF N
set<int64_t> printDivisors(int64_t n)
{
// Vector to store half of the divisors
set<int64_t> v;
for (int i = 1; i <= sqrt(n); i++)
{
if (n % i == 0)
{
// check if divisors are equal
if (n / i == i)
{
// printf("%d ", i);
v.insert(i);
}
else
{
// printf("%d ", i);
v.insert(i);
// push the second divisor in the vector
v.insert(n / i);
}
}
}
return v;
// // The vector will be printed in reverse
// for (int i = v.size() - 1; i >= 0; i--)
// printf("%d ", v[i]);
}
//------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------
struct hashFunction
{
size_t operator()(const pair<int ,
int> &x) const
{
return x.first ^ x.second;
}
};
//------------------------------------------------------------------------------------------------------------------
int cntdig(int n)
{
int cnt = 0 ;
while(n!=0)
{
n/=10;
cnt++;
}
return cnt;
}
//------------------------------------------------------------------------------------------------------------------
bool isPowerOfTwo(int n)
{
if(n==0)
return false;
return (ceil(log2(n)) == floor(log2(n)));
}
//-------------------------------------------------------------------------------------
int Search(int arr[], int l, int r, int x)
{
if (r >= l)
{
int mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return Search(arr, l, mid - 1, x);
return Search(arr, mid + 1, r, x);
}
return -1;
}
//-------------------------------------------------------------------------------------
ll sum_nat(int n)
{
return n * 1ll * (n + 1) / 2;
}
//-------------------------------------------------------------------------------------
bool check_sqr(long double x)
{
if(x>=0)
{
ll sr = sqrt(x);
return(sr*sr==x);
}
return false;
}
//-------------------------------------------------------------------------------------
bool check_even(int n)
{
if(n & 1)
return 0;
else
return 1;
}
//-------------------------------------------------------------------------------------
int count1bits(uint32_t n)
{ // counts number of ones in a bitmask
return bitset < 32 > (n).count();
}
//-------------------------------------------------------------------------------------
double getroot(int n , int m )
{
/*
// Using Binary Search
double low = 1 , high = m, eps = 1e-6;
while((high - low)>eps)
{
double mid = (low+high)/2;
if(pow(mid , n)<m) low = mid;
else high = mid;
}
*/
return pow(m , (double)(1.0/(double)n));
}
//-------------------------------------------------------------------------------------
int factorial( int n)
{
if (n == 0 || n == 1)
return 1;
return n * factorial(n - 1);
}
//-------------------------------------------------------------------------------------
int f(int x){
cin>>u>>v;
u=min(u,v);
a+=!(i[u]+=x)-(i[u]==1&x==1);
}
//-------------------------------------------------------------------------------------
bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
//-------------------------------------------------------------------------------------
//solve function
bool helper(deque<int> &a,int k)
{
int i=1;
while(i<=k)
{
sort(a.begin(),a.end());
if(a[0]>k-i+1)
{
return false;
}
int ind=a.size();
for(int j=a.size()-1;j>=0;--j)
{
if(a[j]<=k-i+1)
{
ind=j;
break;
}
}
a.erase(a.begin()+ind);
a[0]+=k-i+1;
i++;
}
return true;
}
void solve()
{
/* ll n;
cin>>n;
string str;
cin>>str;
int cnt = 0;
for(auto &it : str)
{
if(it == 'Q')
cnt++;
else
cnt--;
if(cnt < 0)
cnt = 0;
}
if(cnt == 0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
*/
// ll a , k;
// cin>>a>>k;
// vector<int> v;
// for (int i = 2; i <= n; i++) {
// bool flag = 1;
// for (int j = 2; j <= i / 2; ++j) {
// if (i % j == 0) {
// flag = 0;
// break;
// }
// }
// if (flag == 1)
// v.push_back(i);
// }
// for(int i = 0;i<v.size()-1;i++)
// {
// if( (v[i]+v[i+1]+1)%2 == 0 )
// {
// cout<<"YES"<<endl;
// return;
// }
// }
// cout<<"NO"<<endl;
string s;
int r = 0 , c = 0;
int x = 8;
int res = 0 , tmp = INT_MAX;
while(x--)
{
cin>>s;
int cnt = 0;
for(auto &it : s)
if(it == 'B')
cnt++;
if(cnt == 8)
res++;
tmp = min(cnt , tmp);
}
if(res == 8)
cout<<8<<endl;
else
cout<<res+tmp<<endl;
}
//------------------------------------------------------------------------------------------------------------------
int main()
{
GODSPEED
NoTEST
solve();
}
``` | -1 |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "499999999"
},
{
"input": "1924704072",
"output": "481176017"
},
{
"input": "73740586",
"output": "18435146"
},
{
"input": "1925088820",
"output": "481272204"
},
{
"input": "593070992",
"output": "148267747"
},
{
"input": "1925473570",
"output": "481368392"
},
{
"input": "629490186",
"output": "157372546"
},
{
"input": "1980649112",
"output": "495162277"
},
{
"input": "36661322",
"output": "9165330"
},
{
"input": "1943590793",
"output": "0"
},
{
"input": "71207034",
"output": "17801758"
},
{
"input": "1757577394",
"output": "439394348"
},
{
"input": "168305294",
"output": "42076323"
},
{
"input": "1934896224",
"output": "483724055"
},
{
"input": "297149088",
"output": "74287271"
},
{
"input": "1898001634",
"output": "474500408"
},
{
"input": "176409698",
"output": "44102424"
},
{
"input": "1873025522",
"output": "468256380"
},
{
"input": "5714762",
"output": "1428690"
},
{
"input": "1829551192",
"output": "457387797"
},
{
"input": "16269438",
"output": "4067359"
},
{
"input": "1663283390",
"output": "415820847"
},
{
"input": "42549941",
"output": "0"
},
{
"input": "1967345604",
"output": "491836400"
},
{
"input": "854000",
"output": "213499"
},
{
"input": "1995886626",
"output": "498971656"
},
{
"input": "10330019",
"output": "0"
},
{
"input": "1996193634",
"output": "499048408"
},
{
"input": "9605180",
"output": "2401294"
},
{
"input": "1996459740",
"output": "499114934"
},
{
"input": "32691948",
"output": "8172986"
},
{
"input": "1975903308",
"output": "493975826"
},
{
"input": "1976637136",
"output": "494159283"
},
{
"input": "29803038",
"output": "7450759"
},
{
"input": "1977979692",
"output": "494494922"
},
{
"input": "1978595336",
"output": "494648833"
},
{
"input": "27379344",
"output": "6844835"
},
{
"input": "1979729912",
"output": "494932477"
},
{
"input": "1980253780",
"output": "495063444"
},
{
"input": "1980751584",
"output": "495187895"
},
{
"input": "53224878",
"output": "13306219"
},
{
"input": "5",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "0"
},
{
"input": "10",
"output": "2"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "2"
},
{
"input": "13",
"output": "0"
},
{
"input": "14",
"output": "3"
},
{
"input": "15",
"output": "0"
},
{
"input": "16",
"output": "3"
},
{
"input": "17",
"output": "0"
},
{
"input": "18",
"output": "4"
},
{
"input": "19",
"output": "0"
},
{
"input": "21",
"output": "0"
},
{
"input": "22",
"output": "5"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "5"
},
{
"input": "25",
"output": "0"
},
{
"input": "26",
"output": "6"
},
{
"input": "27",
"output": "0"
},
{
"input": "28",
"output": "6"
},
{
"input": "29",
"output": "0"
},
{
"input": "30",
"output": "7"
},
{
"input": "111",
"output": "0"
},
{
"input": "55",
"output": "0"
},
{
"input": "105",
"output": "0"
},
{
"input": "199",
"output": "0"
},
{
"input": "151",
"output": "0"
}
] | 1,541,531,110 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 0 | x = int(input())
a = [0,0,0,0]
res = 0
de = 1
for i in range(4):
a[0] = de
a[1] = de
a[2] = de
for j in range (x):
a[2] = (x/2)-(de+j)
a[3] = (x/2)-(de+j)
if(a[0]>=a[2]):
break
if sum(a) == x:
res += 1
de+=1
print(res) | Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
Output Specification:
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
Demo Input:
['6\n', '20\n']
Demo Output:
['1\n', '4\n']
Note:
There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | ```python
x = int(input())
a = [0,0,0,0]
res = 0
de = 1
for i in range(4):
a[0] = de
a[1] = de
a[2] = de
for j in range (x):
a[2] = (x/2)-(de+j)
a[3] = (x/2)-(de+j)
if(a[0]>=a[2]):
break
if sum(a) == x:
res += 1
de+=1
print(res)
``` | 0 |
|
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "100"
},
{
"input": "9 3\n9 5 2 3 7 1 8 4 6",
"output": "7"
},
{
"input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58",
"output": "16"
},
{
"input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54",
"output": "48"
},
{
"input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1",
"output": "44"
},
{
"input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3",
"output": "46"
},
{
"input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78",
"output": "40"
},
{
"input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69",
"output": "11"
},
{
"input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95",
"output": "50"
},
{
"input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9",
"output": "86"
},
{
"input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7",
"output": "93"
},
{
"input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42",
"output": "77"
},
{
"input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48",
"output": "97"
},
{
"input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78",
"output": "20"
},
{
"input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41",
"output": "97"
},
{
"input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82",
"output": "51"
},
{
"input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58",
"output": "97"
},
{
"input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88",
"output": "47"
},
{
"input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51",
"output": "98"
},
{
"input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67",
"output": "94"
},
{
"input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19",
"output": "95"
},
{
"input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49",
"output": "88"
},
{
"input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1",
"output": "99"
},
{
"input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95",
"output": "100"
},
{
"input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15",
"output": "98"
},
{
"input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16",
"output": "100"
},
{
"input": "1 3\n5",
"output": "1"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 3\n4 2",
"output": "1"
},
{
"input": "2 5\n99 97",
"output": "2"
},
{
"input": "3 4\n7 5 2",
"output": "2"
},
{
"input": "3 50\n47 86 51",
"output": "3"
},
{
"input": "5 100\n82 100 85 1 37",
"output": "5"
},
{
"input": "5 20\n40 39 21 5 20",
"output": "3"
},
{
"input": "1 27\n81",
"output": "1"
},
{
"input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1",
"output": "7"
},
{
"input": "2 1\n100 2",
"output": "1"
},
{
"input": "2 2\n6 4",
"output": "1"
},
{
"input": "5 2\n6 4 4 1 1",
"output": "1"
},
{
"input": "1 4\n3",
"output": "1"
},
{
"input": "3 2\n1 5 3",
"output": "2"
},
{
"input": "3 1\n3 2 2",
"output": "1"
},
{
"input": "3 1\n2 3 2",
"output": "2"
},
{
"input": "5 1\n5 1 1 1 1",
"output": "1"
},
{
"input": "2 3\n7 4",
"output": "1"
}
] | 1,682,790,497 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | n, m=map(int, input().split(" "))
p=0
mx=0
a=list(map(int, input().split(" ")))
for i in range(n):
if (a[i]+m-1)//m>=mx:
p=i
mx=(a[i]+m-1)//m
print(p+1)
# Sat Apr 29 2023 20:48:17 GMT+0300 (Moscow Standard Time)
| Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
Output a single integer, representing the number of the last child.
Demo Input:
['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n']
Demo Output:
['4\n', '6\n']
Note:
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | ```python
n, m=map(int, input().split(" "))
p=0
mx=0
a=list(map(int, input().split(" ")))
for i in range(n):
if (a[i]+m-1)//m>=mx:
p=i
mx=(a[i]+m-1)//m
print(p+1)
# Sat Apr 29 2023 20:48:17 GMT+0300 (Moscow Standard Time)
``` | 3 |
|
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,696,608,564 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 15 | 62 | 0 | a, n, m = map(int, input().split())
s = a*((m*(m+1))//2)
if s-n <= 0:
print(0)
else:
print(s-n)
| Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
a, n, m = map(int, input().split())
s = a*((m*(m+1))//2)
if s-n <= 0:
print(0)
else:
print(s-n)
``` | 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,681,983,384 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 312 | 0 | s1=input()
s2=input()
s3=input()
s1sort = sorted(s1)
s2sort = sorted(s2)
s3sort = sorted(s3)
# print(s1sort)
s4 = s1sort+s2sort
s4sort=sorted(s4)
# print(s3sort)
# print(s4)
# print(s4)
ans=1
if len(s3)!=len(s4):
print("NO")
exit()
else:
for i in range(0,len(s4)):
if s3sort[i]==s4sort[i]:
continue
else:
ans=-1
break
if ans==1:
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
s1=input()
s2=input()
s3=input()
s1sort = sorted(s1)
s2sort = sorted(s2)
s3sort = sorted(s3)
# print(s1sort)
s4 = s1sort+s2sort
s4sort=sorted(s4)
# print(s3sort)
# print(s4)
# print(s4)
ans=1
if len(s3)!=len(s4):
print("NO")
exit()
else:
for i in range(0,len(s4)):
if s3sort[i]==s4sort[i]:
continue
else:
ans=-1
break
if ans==1:
print("YES")
else:
print("NO")
``` | 3 |
|
165 | A | Supercentral Point | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=<<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=<<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=><=*y*
We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set. | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different. | Print the only number — the number of supercentral points of the given set. | [
"8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n",
"5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n"
] | [
"2\n",
"1\n"
] | In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | 500 | [
{
"input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3",
"output": "2"
},
{
"input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0",
"output": "1"
},
{
"input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1",
"output": "1"
},
{
"input": "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -973\n125 301\n916 414\n-748 -808\n-651 301\n-734 301\n-307 897\n-651 -550\n-651 414\n125 -808\n-748 -550\n916 -808",
"output": "7"
},
{
"input": "1\n487 550",
"output": "0"
},
{
"input": "10\n990 -396\n990 736\n990 646\n990 -102\n990 -570\n990 155\n990 528\n990 489\n990 268\n990 676",
"output": "0"
},
{
"input": "30\n507 836\n525 836\n-779 196\n507 -814\n525 -814\n525 42\n525 196\n525 -136\n-779 311\n507 -360\n525 300\n507 578\n507 311\n-779 836\n507 300\n525 -360\n525 311\n-779 -360\n-779 578\n-779 300\n507 42\n525 578\n-779 379\n507 196\n525 379\n507 379\n-779 -814\n-779 42\n-779 -136\n507 -136",
"output": "8"
},
{
"input": "25\n890 -756\n890 -188\n-37 -756\n-37 853\n523 998\n-261 853\n-351 853\n-351 -188\n523 -756\n-261 -188\n-37 998\n523 -212\n-351 998\n-37 -188\n-351 -756\n-37 -212\n890 998\n890 -212\n523 853\n-351 -212\n-261 -212\n-261 998\n-261 -756\n890 853\n523 -188",
"output": "9"
},
{
"input": "21\n-813 -11\n486 254\n685 254\n-708 254\n-55 -11\n-671 -191\n486 -11\n-671 -11\n685 -11\n685 -191\n486 -191\n-55 254\n-708 -11\n-813 254\n-708 -191\n41 -11\n-671 254\n-813 -191\n41 254\n-55 -191\n41 -191",
"output": "5"
},
{
"input": "4\n1 0\n2 0\n1 1\n1 -1",
"output": "0"
}
] | 1,631,696,100 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 186 | 6,963,200 | n = int(input())
p= []
for i in range(n):
xy= list(map(int,input().split()))
p.append(xy)
c=0
for i in range(n):
low=up=right=left=0
for j in range(n):
if p[i][0]==p[j][0]:
if p[i][1]>p[j][1]:
low=1
if p[i][1]<p[j][1]:
up=1
if p[i][1]==p[j][1]:
if p[i][0]>p[j][0]:
left=1
if p[i][0]<p[j][0]:
right=1
if low&up&left&right:
c+=1
print(c)
| Title: Supercentral Point
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*):
- point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=><=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=<<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=<<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=><=*y*
We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input Specification:
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output Specification:
Print the only number — the number of supercentral points of the given set.
Demo Input:
['8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n', '5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0). | ```python
n = int(input())
p= []
for i in range(n):
xy= list(map(int,input().split()))
p.append(xy)
c=0
for i in range(n):
low=up=right=left=0
for j in range(n):
if p[i][0]==p[j][0]:
if p[i][1]>p[j][1]:
low=1
if p[i][1]<p[j][1]:
up=1
if p[i][1]==p[j][1]:
if p[i][0]>p[j][0]:
left=1
if p[i][0]<p[j][0]:
right=1
if low&up&left&right:
c+=1
print(c)
``` | 3 |
|
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.
Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$
The sum of an empty array is $0$.
Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible. | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": "9"
}
] | 1,622,301,125 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 717 | 36,044,800 | #t=int(input())
import math
def binarySearch (arr, l, r, x):
# Check base case
if r >= l:
mid = l + (r - l) // 2
# If element is present at the middle itself
if arr[mid] == x:
return mid
# If element is smaller than mid, then it
# can only be present in left subarray
elif arr[mid] > x:
return binarySearch(arr, l, mid-1, x)
# Else the element can only be present
# in right subarray
else:
return binarySearch(arr, mid + 1, r, x)
else:
# Element is not present in the array
return -1
#for _ in range(t):
n=int(input())
arr=list(map(int,input().split()))
i=-1
s=0
back=[0]
while i>-n:
s+=arr[i]
back.append(s)
i-=1
i=0
s=0
front=[0]
while i<n-1:
s+=arr[i]
front.append(s)
i+=1
ans=0
for i in range(n):
if binarySearch(back,0,n-1,front[i])!=-1 and binarySearch(back,0,n-1,front[i])+i<=n:
ans=front[i]
print(ans)
| Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array.
Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:
$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$
The sum of an empty array is $0$.
Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$.
Output Specification:
Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$).
Demo Input:
['5\n1 3 1 1 4\n', '5\n1 3 2 1 4\n', '3\n4 1 2\n']
Demo Output:
['5\n', '4\n', '0\n']
Note:
In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | ```python
#t=int(input())
import math
def binarySearch (arr, l, r, x):
# Check base case
if r >= l:
mid = l + (r - l) // 2
# If element is present at the middle itself
if arr[mid] == x:
return mid
# If element is smaller than mid, then it
# can only be present in left subarray
elif arr[mid] > x:
return binarySearch(arr, l, mid-1, x)
# Else the element can only be present
# in right subarray
else:
return binarySearch(arr, mid + 1, r, x)
else:
# Element is not present in the array
return -1
#for _ in range(t):
n=int(input())
arr=list(map(int,input().split()))
i=-1
s=0
back=[0]
while i>-n:
s+=arr[i]
back.append(s)
i-=1
i=0
s=0
front=[0]
while i<n-1:
s+=arr[i]
front.append(s)
i+=1
ans=0
for i in range(n):
if binarySearch(back,0,n-1,front[i])!=-1 and binarySearch(back,0,n-1,front[i])+i<=n:
ans=front[i]
print(ans)
``` | 3 |
|
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him. | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt",
"output": "NO"
},
{
"input": "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo\nooooososooooo\noooosooosoooo\nooosooooosooo\noosooooooosoo\nosoooooooooso\nsooooooooooos",
"output": "YES"
},
{
"input": "3\naaa\naaa\naaa",
"output": "NO"
},
{
"input": "3\naca\noec\nzba",
"output": "NO"
},
{
"input": "15\nrxeeeeeeeeeeeer\nereeeeeeeeeeere\needeeeeeeeeeoee\neeereeeeeeeewee\neeeereeeeebeeee\nqeeeereeejedyee\neeeeeerereeeeee\neeeeeeereeeeeee\neeeeeerereeeeze\neeeeereeereeeee\neeeereeeeegeeee\neeereeeeeeereee\neereeeeeeqeeved\ncreeeeeeceeeere\nreeerneeeeeeeer",
"output": "NO"
},
{
"input": "5\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx",
"output": "NO"
},
{
"input": "5\nxxxxx\nxxxxx\nxoxxx\nxxxxx\nxxxxx",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxxxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxoox\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\nxxaxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "5\noxxxo\nxoxox\noxoxx\nxoxox\noxxxo",
"output": "NO"
},
{
"input": "3\nxxx\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxx\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxxx",
"output": "NO"
},
{
"input": "3\nxax\nxxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naaa\nxax",
"output": "NO"
},
{
"input": "3\naax\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxaa\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\naax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxaa",
"output": "NO"
},
{
"input": "3\nxfx\naxa\nxax",
"output": "NO"
},
{
"input": "3\nxax\nafa\nxax",
"output": "NO"
},
{
"input": "3\nxax\naxa\nxaf",
"output": "NO"
},
{
"input": "3\nxox\nxxx\nxxx",
"output": "NO"
},
{
"input": "3\naxa\naax\nxxa",
"output": "NO"
},
{
"input": "3\nxox\noxx\nxox",
"output": "NO"
},
{
"input": "3\nxox\nooo\nxox",
"output": "NO"
},
{
"input": "3\naaa\naab\nbbb",
"output": "NO"
},
{
"input": "3\nxxx\nsxs\nxsx",
"output": "NO"
},
{
"input": "5\nabbba\nbabab\nbbbbb\nbaaab\nabbba",
"output": "NO"
},
{
"input": "5\nabaaa\nbbbbb\nbbabb\nbabab\nabbba",
"output": "NO"
},
{
"input": "5\nxoxox\noxoxo\nooxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nxox\noxx\nxxx",
"output": "NO"
},
{
"input": "5\nxoooo\noxooo\nooxoo\noooxo\noooox",
"output": "NO"
},
{
"input": "5\nxoooo\noxoxx\nooxoo\noxoxo\noxoox",
"output": "NO"
},
{
"input": "3\naaa\nbab\naba",
"output": "NO"
}
] | 1,693,662,228 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | n =int(input())
d = []
for i in range(n):
d.append(input())
diag = d[0][0]
non_diag = d[0][1]
for i in range(n):
for j in range(n):
if (i==j and d[i][j] != diag) or (i!=j and i!=abs(j-n+1) and d[i][j] != non_diag) or \
(i==abs(j-n+1) and d[i][j] != diag):
#print(d[i][j],i,j)
print('NO')
exit()
print('YES') | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Output Specification:
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
Demo Input:
['5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n', '3\nwsw\nsws\nwsw\n', '3\nxpx\npxp\nxpe\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
none | ```python
n =int(input())
d = []
for i in range(n):
d.append(input())
diag = d[0][0]
non_diag = d[0][1]
for i in range(n):
for j in range(n):
if (i==j and d[i][j] != diag) or (i!=j and i!=abs(j-n+1) and d[i][j] != non_diag) or \
(i==abs(j-n+1) and d[i][j] != diag):
#print(d[i][j],i,j)
print('NO')
exit()
print('YES')
``` | 0 |
|
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into? | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow",
"output": "49"
},
{
"input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "50"
},
{
"input": "ijvxljt",
"output": "7"
},
{
"input": "fyhcncnchyf",
"output": "10"
},
{
"input": "ffffffffffff",
"output": "0"
},
{
"input": "fyhcncfsepqj",
"output": "12"
},
{
"input": "ybejrrlbcinttnicblrrjeby",
"output": "23"
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyy",
"output": "0"
},
{
"input": "ybejrrlbcintahovgjddrqatv",
"output": "25"
},
{
"input": "oftmhcmclgyqaojljoaqyglcmchmtfo",
"output": "30"
},
{
"input": "oooooooooooooooooooooooooooooooo",
"output": "0"
},
{
"input": "oftmhcmclgyqaojllbotztajglsmcilv",
"output": "32"
},
{
"input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg",
"output": "35"
},
{
"input": "gggggggggggggggggggggggggggggggggggg",
"output": "0"
},
{
"input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk",
"output": "36"
},
{
"input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf",
"output": "40"
},
{
"input": "fffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy",
"output": "43"
},
{
"input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "0"
},
{
"input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy",
"output": "49"
},
{
"input": "a",
"output": "0"
},
{
"input": "abca",
"output": "4"
},
{
"input": "aaaaabaaaaa",
"output": "10"
},
{
"input": "aba",
"output": "2"
},
{
"input": "asaa",
"output": "4"
},
{
"input": "aabaa",
"output": "4"
},
{
"input": "aabbaa",
"output": "5"
},
{
"input": "abcdaaa",
"output": "7"
},
{
"input": "aaholaa",
"output": "7"
},
{
"input": "abcdefghijka",
"output": "12"
},
{
"input": "aaadcba",
"output": "7"
},
{
"input": "aaaabaaaa",
"output": "8"
},
{
"input": "abaa",
"output": "4"
},
{
"input": "abcbaa",
"output": "6"
},
{
"input": "ab",
"output": "2"
},
{
"input": "l",
"output": "0"
},
{
"input": "aaaabcaaaa",
"output": "10"
},
{
"input": "abbaaaaaabba",
"output": "11"
},
{
"input": "abaaa",
"output": "5"
},
{
"input": "baa",
"output": "3"
},
{
"input": "aaaaaaabbba",
"output": "11"
},
{
"input": "ccbcc",
"output": "4"
},
{
"input": "bbbaaab",
"output": "7"
},
{
"input": "abaaaaaaaa",
"output": "10"
},
{
"input": "abaaba",
"output": "5"
},
{
"input": "aabsdfaaaa",
"output": "10"
},
{
"input": "aaaba",
"output": "5"
},
{
"input": "aaabaaa",
"output": "6"
},
{
"input": "baaabbb",
"output": "7"
},
{
"input": "ccbbabbcc",
"output": "8"
},
{
"input": "cabc",
"output": "4"
},
{
"input": "aabcd",
"output": "5"
},
{
"input": "abcdea",
"output": "6"
},
{
"input": "bbabb",
"output": "4"
},
{
"input": "aaaaabababaaaaa",
"output": "14"
},
{
"input": "bbabbb",
"output": "6"
},
{
"input": "aababd",
"output": "6"
},
{
"input": "abaaaa",
"output": "6"
},
{
"input": "aaaaaaaabbba",
"output": "12"
},
{
"input": "aabca",
"output": "5"
},
{
"input": "aaabccbaaa",
"output": "9"
},
{
"input": "aaaaaaaaaaaaaaaaaaaab",
"output": "21"
},
{
"input": "babb",
"output": "4"
},
{
"input": "abcaa",
"output": "5"
},
{
"input": "qwqq",
"output": "4"
},
{
"input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa",
"output": "48"
},
{
"input": "aaab",
"output": "4"
},
{
"input": "aaaaaabaaaaa",
"output": "12"
},
{
"input": "wwuww",
"output": "4"
},
{
"input": "aaaaabcbaaaaa",
"output": "12"
},
{
"input": "aaabbbaaa",
"output": "8"
},
{
"input": "aabcbaa",
"output": "6"
},
{
"input": "abccdefccba",
"output": "11"
},
{
"input": "aabbcbbaa",
"output": "8"
},
{
"input": "aaaabbaaaa",
"output": "9"
},
{
"input": "aabcda",
"output": "6"
},
{
"input": "abbca",
"output": "5"
},
{
"input": "aaaaaabbaaa",
"output": "11"
},
{
"input": "sssssspssssss",
"output": "12"
},
{
"input": "sdnmsdcs",
"output": "8"
},
{
"input": "aaabbbccbbbaaa",
"output": "13"
},
{
"input": "cbdbdc",
"output": "6"
},
{
"input": "abb",
"output": "3"
},
{
"input": "abcdefaaaa",
"output": "10"
},
{
"input": "abbbaaa",
"output": "7"
},
{
"input": "v",
"output": "0"
},
{
"input": "abccbba",
"output": "7"
},
{
"input": "axyza",
"output": "5"
},
{
"input": "abcdefgaaaa",
"output": "11"
},
{
"input": "aaabcdaaa",
"output": "9"
},
{
"input": "aaaacaaaa",
"output": "8"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa",
"output": "42"
},
{
"input": "abbbaa",
"output": "6"
},
{
"input": "abcdee",
"output": "6"
},
{
"input": "oom",
"output": "3"
},
{
"input": "aabcaa",
"output": "6"
},
{
"input": "abba",
"output": "3"
},
{
"input": "aaca",
"output": "4"
},
{
"input": "aacbca",
"output": "6"
},
{
"input": "ababa",
"output": "4"
},
{
"input": "abcda",
"output": "5"
},
{
"input": "cccaaccc",
"output": "7"
},
{
"input": "aaabcda",
"output": "7"
},
{
"input": "aa",
"output": "0"
},
{
"input": "aabaaaa",
"output": "7"
},
{
"input": "abbaaaa",
"output": "7"
},
{
"input": "aaabcbaaa",
"output": "8"
},
{
"input": "aabba",
"output": "5"
},
{
"input": "xyxx",
"output": "4"
},
{
"input": "aaaaaaaaaaaabc",
"output": "14"
},
{
"input": "bbaaaabb",
"output": "7"
},
{
"input": "aaabaa",
"output": "6"
},
{
"input": "sssssabsssss",
"output": "12"
},
{
"input": "bbbaaaabbb",
"output": "9"
},
{
"input": "abbbbaaaa",
"output": "9"
},
{
"input": "wwufuww",
"output": "6"
},
{
"input": "oowoo",
"output": "4"
},
{
"input": "cccaccc",
"output": "6"
},
{
"input": "aaa",
"output": "0"
},
{
"input": "bbbcc",
"output": "5"
},
{
"input": "abcdef",
"output": "6"
},
{
"input": "abbba",
"output": "4"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaba",
"output": "4"
},
{
"input": "azbyaaa",
"output": "7"
},
{
"input": "oooooiooooo",
"output": "10"
},
{
"input": "aabbbbbaaaaaa",
"output": "13"
}
] | 1,645,086,285 | 2,147,483,647 | Python 3 | OK | TESTS | 133 | 46 | 0 | i = input()
if len(set(i)) == 1:
print(0)
else:
print(len(i) - (i == i[::-1]))
| Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into?
Input Specification:
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
Output Specification:
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
Demo Input:
['mew\n', 'wuffuw\n', 'qqqqqqqq\n']
Demo Output:
['3\n', '5\n', '0\n']
Note:
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | ```python
i = input()
if len(set(i)) == 1:
print(0)
else:
print(len(i) - (i == i[::-1]))
``` | 3 |
|
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1",
"output": "3"
},
{
"input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4",
"output": "4"
},
{
"input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1",
"output": "3"
},
{
"input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0",
"output": "5"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "6 3\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "1 4\n1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "2 3\n0 0",
"output": "0"
}
] | 1,668,081,538 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n = int(input().split())
for i in n :
if i <=5:
print (len(n))//3 | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
Input Specification:
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | ```python
n = int(input().split())
for i in n :
if i <=5:
print (len(n))//3
``` | -1 |
|
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support? | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1",
"output": "174"
},
{
"input": "4\n1000000000 99999999 1000000000 1000000000",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "6\n1 1 3 3 2 2",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "4\n1 1 2 5",
"output": "1"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n1 1 1 1 5",
"output": "0"
},
{
"input": "5\n1 1 2 3 3",
"output": "1"
},
{
"input": "3\n1 1 3",
"output": "0"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "5\n1 5 3 5 1",
"output": "1"
},
{
"input": "7\n1 2 2 2 2 2 3",
"output": "5"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "9\n2 2 2 3 4 5 6 6 6",
"output": "3"
},
{
"input": "10\n1 1 1 2 3 3 3 3 3 3",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n0 0 1",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "0"
},
{
"input": "5\n2 2 2 2 2",
"output": "0"
},
{
"input": "5\n5 5 5 5 5",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "1"
},
{
"input": "5\n1 2 3 3 3",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "0"
},
{
"input": "6\n1 1 1 1 1 2",
"output": "0"
},
{
"input": "5\n1 1 2 4 4",
"output": "1"
},
{
"input": "3\n999999 5999999 9999999",
"output": "1"
},
{
"input": "4\n1 1 5 5",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 4 4 4",
"output": "3"
},
{
"input": "5\n1 3 4 5 1",
"output": "2"
},
{
"input": "5\n3 3 3 3 3",
"output": "0"
},
{
"input": "5\n1 1 2 2 2",
"output": "0"
},
{
"input": "5\n2 1 1 1 3",
"output": "1"
},
{
"input": "5\n0 0 0 1 2",
"output": "1"
},
{
"input": "4\n2 2 2 3",
"output": "0"
},
{
"input": "7\n1 1 1 1 5 5 5",
"output": "0"
},
{
"input": "5\n1 2 3 4 4",
"output": "2"
},
{
"input": "2\n5 4",
"output": "0"
},
{
"input": "4\n5 5 5 5",
"output": "0"
},
{
"input": "5\n1 1 1 5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "4\n1 2 2 2",
"output": "0"
},
{
"input": "8\n1000000000 1000000000 1000000000 999999999 999999999 999999999 999999998 999999998",
"output": "3"
},
{
"input": "5\n1 1 3 4 4",
"output": "1"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "2"
},
{
"input": "4\n1 1 1 1",
"output": "0"
},
{
"input": "9\n1 2 3 4 1 5 6 7 8",
"output": "6"
},
{
"input": "8\n5 4 4 6 6 4 4 3",
"output": "5"
},
{
"input": "8\n4 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "7\n4 3 3 3 3 3 3",
"output": "0"
},
{
"input": "6\n4 3 3 3 3 3",
"output": "0"
},
{
"input": "5\n4 3 3 3 3",
"output": "0"
}
] | 1,656,998,557 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 124 | 8,396,800 | n = int(input())
a = list(map(int, input().split()))
a.sort()
b = list({i for i in a})
while b[0] in a:
a.remove(b[0])
while b[len(b)-1] in a:
a.remove(b[len(b)-1])
print(len(a)) | Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
Input Specification:
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards.
Output Specification:
Output a single integer representing the number of stewards which Jon will feed.
Demo Input:
['2\n1 5\n', '3\n1 2 5\n']
Demo Output:
['0', '1']
Note:
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = list({i for i in a})
while b[0] in a:
a.remove(b[0])
while b[len(b)-1] in a:
a.remove(b[len(b)-1])
print(len(a))
``` | 0 |
|
740 | B | Alyona and flowers | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.
For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then:
- the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays.
Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!
Alyona can choose any number of the subarrays, even 0 or all suggested by her mother. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
Each subarray can encounter more than once. | Print single integer — the maximum possible value added to the Alyona's happiness. | [
"5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n",
"4 3\n1 2 3 4\n1 3\n2 4\n1 1\n",
"2 2\n-1 -2\n1 1\n1 2\n"
] | [
"7\n",
"16\n",
"0\n"
] | The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | 1,000 | [
{
"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4",
"output": "7"
},
{
"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1",
"output": "16"
},
{
"input": "2 2\n-1 -2\n1 1\n1 2",
"output": "0"
},
{
"input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5",
"output": "8"
},
{
"input": "8 3\n5 -4 -2 5 3 -4 -2 6\n3 8\n4 6\n2 3",
"output": "10"
},
{
"input": "10 10\n0 0 0 0 0 0 0 0 0 0\n5 9\n1 9\n5 7\n3 8\n1 6\n1 9\n1 6\n6 9\n1 10\n3 8",
"output": "0"
},
{
"input": "3 6\n0 0 0\n1 1\n1 1\n1 3\n3 3\n2 3\n1 2",
"output": "0"
},
{
"input": "3 3\n1 -1 3\n1 2\n2 3\n1 3",
"output": "5"
},
{
"input": "6 8\n0 6 -5 8 -3 -2\n6 6\n2 3\n5 6\n4 6\n3 4\n2 5\n3 3\n5 6",
"output": "13"
},
{
"input": "10 4\n6 5 5 -1 0 5 0 -3 5 -4\n3 6\n4 9\n1 6\n1 4",
"output": "50"
},
{
"input": "9 1\n-1 -1 -1 -1 2 -1 2 0 0\n2 5",
"output": "0"
},
{
"input": "3 8\n3 4 4\n1 2\n1 3\n2 3\n1 2\n2 2\n1 1\n2 3\n1 3",
"output": "59"
},
{
"input": "3 8\n6 7 -1\n1 1\n1 3\n2 2\n1 3\n1 3\n1 1\n2 3\n2 3",
"output": "67"
},
{
"input": "53 7\n-43 57 92 97 85 -29 28 -8 -37 -47 51 -53 -95 -50 -39 -87 43 36 60 -95 93 8 67 -22 -78 -46 99 93 27 -72 -84 77 96 -47 1 -12 21 -98 -34 -88 57 -43 5 -15 20 -66 61 -29 30 -85 52 53 82\n15 26\n34 43\n37 41\n22 34\n19 43\n2 15\n13 35",
"output": "170"
},
{
"input": "20 42\n61 86 5 -87 -33 51 -79 17 -3 65 -42 74 -94 40 -35 22 58 81 -75 5\n3 6\n12 13\n3 16\n3 16\n5 7\n5 16\n2 15\n6 18\n4 18\n10 17\n14 16\n4 15\n4 11\n13 20\n5 6\n5 15\n16 17\n3 14\n9 10\n5 19\n5 14\n2 4\n17 20\n10 11\n5 18\n10 11\n1 14\n1 6\n1 10\n8 16\n11 14\n12 20\n11 13\n4 5\n2 13\n1 5\n11 15\n1 18\n3 8\n8 20\n1 4\n10 13",
"output": "1502"
},
{
"input": "64 19\n-47 13 19 51 -25 72 38 32 54 7 -49 -50 -59 73 45 -87 -15 -72 -32 -10 -7 47 -34 35 48 -73 79 25 -80 -34 4 77 60 30 61 -25 23 17 -73 -73 69 29 -50 -55 53 15 -33 7 -46 -5 85 -86 77 -51 87 -69 -64 -24 -64 29 -20 -58 11 -26\n6 53\n13 28\n15 47\n20 52\n12 22\n6 49\n31 54\n2 39\n32 49\n27 64\n22 63\n33 48\n49 58\n39 47\n6 29\n21 44\n24 59\n20 24\n39 54",
"output": "804"
},
{
"input": "1 10\n-46\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "10 7\n44 18 9 -22 -23 7 -25 -2 15 35\n6 8\n6 7\n3 3\n2 6\n9 10\n2 2\n1 5",
"output": "103"
},
{
"input": "4 3\n10 -2 68 35\n4 4\n1 1\n1 3",
"output": "121"
},
{
"input": "3 6\n27 -31 -81\n2 3\n2 3\n1 1\n1 2\n1 2\n2 2",
"output": "27"
},
{
"input": "7 3\n-24 -12 16 -43 -30 31 16\n3 6\n3 4\n1 7",
"output": "0"
},
{
"input": "10 7\n-33 -24 -86 -20 5 -91 38 -12 -90 -67\n7 8\n7 10\n4 7\n1 3\n6 10\n6 6\n3 5",
"output": "26"
},
{
"input": "4 4\n95 35 96 -27\n3 4\n3 3\n4 4\n3 3",
"output": "261"
},
{
"input": "7 7\n-33 26 -25 44 -20 -50 33\n4 6\n4 4\n3 7\n5 7\n1 4\n2 5\n4 6",
"output": "81"
},
{
"input": "5 3\n-35 -39 93 59 -4\n2 2\n2 3\n2 5",
"output": "163"
},
{
"input": "3 7\n0 0 0\n1 2\n1 2\n2 3\n3 3\n1 3\n1 2\n2 3",
"output": "0"
},
{
"input": "8 2\n17 32 30 -6 -39 -15 33 74\n6 6\n8 8",
"output": "74"
},
{
"input": "8 1\n-20 -15 21 -21 1 -12 -7 9\n4 7",
"output": "0"
},
{
"input": "7 9\n-23 -4 -44 -47 -35 47 25\n1 6\n3 5\n4 7\n6 7\n2 4\n2 3\n2 7\n1 2\n5 5",
"output": "72"
},
{
"input": "8 8\n0 6 -25 -15 29 -24 31 23\n2 8\n5 5\n3 3\n2 8\n6 6\n3 6\n3 4\n2 4",
"output": "79"
},
{
"input": "4 3\n-39 -63 9 -16\n1 4\n1 3\n2 4",
"output": "0"
},
{
"input": "9 1\n-3 -13 -13 -19 -4 -11 8 -11 -3\n9 9",
"output": "0"
},
{
"input": "9 6\n25 18 -62 0 33 62 -23 4 -15\n7 9\n2 3\n1 4\n2 6\n1 6\n2 3",
"output": "127"
},
{
"input": "4 5\n-12 39 8 -12\n1 4\n3 4\n1 3\n1 3\n2 3",
"output": "140"
},
{
"input": "3 9\n-9 7 3\n1 2\n1 1\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n3 3",
"output": "22"
},
{
"input": "10 7\n0 4 3 3 -2 -2 -4 -2 -3 -2\n5 6\n1 10\n2 10\n7 10\n1 1\n6 7\n3 4",
"output": "6"
},
{
"input": "86 30\n16 -12 11 16 8 14 7 -29 18 30 -32 -10 20 29 -14 -21 23 -19 -15 17 -2 25 -22 2 26 15 -7 -12 -4 -28 21 -4 -2 22 28 -32 9 -20 23 38 -21 21 37 -13 -30 25 31 6 18 29 29 29 27 38 -15 -32 32 -7 -8 -33 -11 24 23 -19 -36 -36 -18 9 -1 32 -34 -26 1 -1 -16 -14 17 -17 15 -24 38 5 -27 -12 8 -38\n60 66\n29 48\n32 51\n38 77\n17 79\n23 74\n39 50\n14 29\n26 76\n9 76\n2 67\n23 48\n17 68\n33 75\n59 78\n46 78\n9 69\n16 83\n18 21\n17 34\n24 61\n15 79\n4 31\n62 63\n46 76\n79 82\n25 39\n5 81\n19 77\n26 71",
"output": "3076"
},
{
"input": "33 17\n11 6 -19 14 23 -23 21 15 29 19 13 -18 -19 20 16 -10 26 -22 3 17 13 -10 19 22 -5 21 12 6 28 -13 -27 25 6\n4 17\n12 16\n9 17\n25 30\n31 32\n4 28\n11 24\n16 19\n3 27\n7 17\n1 16\n15 28\n30 33\n9 31\n14 30\n13 23\n27 27",
"output": "1366"
},
{
"input": "16 44\n32 23 -27 -2 -10 -42 32 -14 -13 4 9 -2 19 35 16 22\n6 12\n8 11\n13 15\n12 12\n3 10\n9 13\n7 15\n2 11\n1 13\n5 6\n9 14\n3 16\n10 13\n3 15\n6 10\n14 16\n4 5\n7 10\n5 14\n1 16\n2 5\n1 6\n9 10\n4 7\n4 12\n2 5\n7 10\n7 9\n2 8\n9 10\n4 10\n7 12\n10 11\n6 6\n15 15\n8 12\n9 10\n3 3\n4 15\n10 12\n7 16\n4 14\n14 16\n5 6",
"output": "777"
},
{
"input": "63 24\n-23 -46 0 33 24 13 39 -6 -4 49 19 -18 -11 -38 0 -3 -33 -17 -4 -44 -22 -12 -16 42 16 -10 7 37 -6 16 -41 -18 -20 51 -49 28 -14 -22 -37 -7 -50 31 -41 -47 18 -8 -39 -29 35 -32 14 -29 44 -29 -19 -25 -47 -8 16 11 20 12 38\n21 61\n35 61\n29 61\n21 34\n12 48\n32 33\n9 27\n4 42\n4 60\n37 61\n19 44\n46 60\n51 53\n31 34\n23 32\n5 29\n43 59\n7 31\n29 48\n15 50\n19 51\n7 28\n17 41\n1 62",
"output": "82"
},
{
"input": "6 51\n45 -33 -17 -48 2 2\n2 5\n1 1\n1 3\n5 5\n4 6\n1 2\n2 3\n3 4\n1 6\n4 6\n3 5\n1 5\n2 2\n2 6\n4 6\n1 5\n1 5\n1 5\n1 6\n6 6\n3 5\n6 6\n1 6\n3 4\n3 3\n2 4\n3 3\n1 4\n2 4\n5 6\n4 5\n2 4\n1 5\n1 2\n4 5\n1 5\n5 6\n2 2\n3 4\n1 3\n1 2\n2 5\n3 6\n4 6\n3 4\n2 4\n1 4\n1 1\n4 6\n3 5\n1 4",
"output": "140"
},
{
"input": "3 5\n2 -1 3\n2 3\n2 3\n2 3\n2 3\n1 2",
"output": "9"
},
{
"input": "4 30\n1 1 1 1\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4\n1 4",
"output": "120"
}
] | 1,614,683,949 | 2,147,483,647 | PyPy 3 | OK | TESTS | 53 | 108 | 0 | n,m=map(int,input().split())
arr=list(map(int,input().split()))
pre=[0]*n
pre[0]=arr[0]
re=0
for i in range(1,n):
pre[i]=pre[i-1]+arr[i]
for i in range(m):
x,y=map(int,input().split())
curr=0
if(x==1):
curr=pre[y-1]
else:
curr=pre[y-1]-pre[x-2]
if(curr>0):
re+=curr
print(re) | Title: Alyona and flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.
For example, consider the case when the mother has 5 flowers, and their moods are equal to 1,<=<=-<=2,<=1,<=3,<=<=-<=4. Suppose the mother suggested subarrays (1,<=<=-<=2), (3,<=<=-<=4), (1,<=3), (1,<=<=-<=2,<=1,<=3). Then if the girl chooses the third and the fourth subarrays then:
- the first flower adds 1·1<==<=1 to the girl's happiness, because he is in one of chosen subarrays, - the second flower adds (<=-<=2)·1<==<=<=-<=2, because he is in one of chosen subarrays, - the third flower adds 1·2<==<=2, because he is in two of chosen subarrays, - the fourth flower adds 3·2<==<=6, because he is in two of chosen subarrays, - the fifth flower adds (<=-<=4)·0<==<=0, because he is in no chosen subarrays.
Thus, in total 1<=+<=(<=-<=2)<=+<=2<=+<=6<=+<=0<==<=7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!
Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the subarrays suggested by the mother. The *i*-th of these lines contain two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) denoting the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
Each subarray can encounter more than once.
Output Specification:
Print single integer — the maximum possible value added to the Alyona's happiness.
Demo Input:
['5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n', '4 3\n1 2 3 4\n1 3\n2 4\n1 1\n', '2 2\n-1 -2\n1 1\n1 2\n']
Demo Output:
['7\n', '16\n', '0\n']
Note:
The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | ```python
n,m=map(int,input().split())
arr=list(map(int,input().split()))
pre=[0]*n
pre[0]=arr[0]
re=0
for i in range(1,n):
pre[i]=pre[i-1]+arr[i]
for i in range(m):
x,y=map(int,input().split())
curr=0
if(x==1):
curr=pre[y-1]
else:
curr=pre[y-1]-pre[x-2]
if(curr>0):
re+=curr
print(re)
``` | 3 |
|
755 | B | PolandBall and Game | PROGRAMMING | 1,100 | [
"binary search",
"data structures",
"games",
"greedy",
"sortings",
"strings"
] | null | null | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally? | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players.
Each word is non-empty and consists of no more than 500 lowercase English alphabet letters. | In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | [
"5 1\npolandball\nis\na\ncool\ncharacter\nnope\n",
"2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n",
"1 2\na\na\nb\n"
] | [
"YES",
"YES",
"NO"
] | In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | 1,000 | [
{
"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope",
"output": "YES"
},
{
"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska",
"output": "YES"
},
{
"input": "1 2\na\na\nb",
"output": "NO"
},
{
"input": "2 2\na\nb\nb\nc",
"output": "YES"
},
{
"input": "2 1\nc\na\na",
"output": "YES"
},
{
"input": "3 3\nab\nbc\ncd\ncd\ndf\nfg",
"output": "YES"
},
{
"input": "3 3\nc\na\nb\na\nd\ng",
"output": "YES"
},
{
"input": "1 1\naa\naa",
"output": "YES"
},
{
"input": "2 1\na\nb\na",
"output": "YES"
},
{
"input": "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny",
"output": "YES"
},
{
"input": "3 2\na\nb\nc\nd\ne",
"output": "YES"
}
] | 1,646,276,845 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 3,276,800 | from collections import defaultdict
def solve(poland, enemy):
n = len(poland)
m = len(enemy)
if n < m:
print("NO")
return
if n > m:
print("YES")
return
d = defaultdict(int)
for word in poland:
d[word] += 1
for word in enemy:
d[word] += 1
intersection = [word for word in d if d[word] == 2]
for idx, word in enumerate(intersection):
if idx % 2 == 0:
enemy.remove(word)
else:
poland.remove(word)
if len(poland) > len(enemy):
print("YES")
else:
print("NO")
return
if __name__ == '__main__':
enemy = set()
n, m = list(map(lambda x: int(x), input().split()))
poland = {input() for _ in range(n)}
enemy = {input() for _ in range(n)}
solve(poland, enemy) | Title: PolandBall and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
Input Specification:
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players.
Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
Output Specification:
In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
Demo Input:
['5 1\npolandball\nis\na\ncool\ncharacter\nnope\n', '2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n', '1 2\na\na\nb\n']
Demo Output:
['YES', 'YES', 'NO']
Note:
In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | ```python
from collections import defaultdict
def solve(poland, enemy):
n = len(poland)
m = len(enemy)
if n < m:
print("NO")
return
if n > m:
print("YES")
return
d = defaultdict(int)
for word in poland:
d[word] += 1
for word in enemy:
d[word] += 1
intersection = [word for word in d if d[word] == 2]
for idx, word in enumerate(intersection):
if idx % 2 == 0:
enemy.remove(word)
else:
poland.remove(word)
if len(poland) > len(enemy):
print("YES")
else:
print("NO")
return
if __name__ == '__main__':
enemy = set()
n, m = list(map(lambda x: int(x), input().split()))
poland = {input() for _ in range(n)}
enemy = {input() for _ in range(n)}
solve(poland, enemy)
``` | -1 |
|
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*. | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "100000",
"output": "50000\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "7",
"output": "3\n2 2 3"
},
{
"input": "4",
"output": "2\n2 2"
},
{
"input": "8",
"output": "4\n2 2 2 2"
},
{
"input": "9",
"output": "4\n2 2 2 3"
},
{
"input": "99995",
"output": "49997\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99996",
"output": "49998\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "10",
"output": "5\n2 2 2 2 2"
},
{
"input": "11",
"output": "5\n2 2 2 2 3"
},
{
"input": "99997",
"output": "49998\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99998",
"output": "49999\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "12",
"output": "6\n2 2 2 2 2 2"
},
{
"input": "13",
"output": "6\n2 2 2 2 2 3"
},
{
"input": "99993",
"output": "49996\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99994",
"output": "49997\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "14",
"output": "7\n2 2 2 2 2 2 2"
},
{
"input": "15",
"output": "7\n2 2 2 2 2 2 3"
},
{
"input": "53",
"output": "26\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 3"
},
{
"input": "57",
"output": "28\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 3"
},
{
"input": "61",
"output": "30\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 3"
},
{
"input": "774",
"output": "387\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "202",
"output": "101\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 2"
},
{
"input": "530",
"output": "265\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "7166",
"output": "3583\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "9294",
"output": "4647\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "2422",
"output": "1211\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "15326",
"output": "7663\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "11454",
"output": "5727\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "14878",
"output": "7439\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "90672",
"output": "45336\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "99544",
"output": "49772\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "90472",
"output": "45236\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "23",
"output": "11\n2 2 2 2 2 2 2 2 2 2 3"
},
{
"input": "93",
"output": "46\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 3"
},
{
"input": "19",
"output": "9\n2 2 2 2 2 2 2 2 3"
},
{
"input": "11110",
"output": "5555\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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,674,535,769 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 62 | 4,096,000 | n=int(input())
out=[]
if n&1:
n-=3
out.append(3)
for _ in range(n//2):
out.append(2)
print(len(out))
print(' '.join(map(str,out))) | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*.
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
Output Specification:
The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
Demo Input:
['5\n', '6\n']
Demo Output:
['2\n2 3\n', '3\n2 2 2\n']
Note:
none | ```python
n=int(input())
out=[]
if n&1:
n-=3
out.append(3)
for _ in range(n//2):
out.append(2)
print(len(out))
print(' '.join(map(str,out)))
``` | 3 |
|
268 | C | Beautiful Sets of Points | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation"
] | null | null | Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions:
1. The coordinates of each point in the set are integers. 1. For any two points from the set, the distance between them is a non-integer.
Consider all points (*x*,<=*y*) which satisfy the inequations: 0<=≤<=*x*<=≤<=*n*; 0<=≤<=*y*<=≤<=*m*; *x*<=+<=*y*<=><=0. Choose their subset of maximum size such that it is also a beautiful set of points. | The single line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). | In the first line print a single integer — the size *k* of the found beautiful set. In each of the next *k* lines print a pair of space-separated integers — the *x*- and *y*- coordinates, respectively, of a point from the set.
If there are several optimal solutions, you may print any of them. | [
"2 2\n",
"4 3\n"
] | [
"3\n0 1\n1 2\n2 0\n",
"4\n0 3\n2 1\n3 0\n4 2\n"
] | Consider the first sample. The distance between points (0, 1) and (1, 2) equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bfe16f27ebc966df6f10ba356a1547b6e7242dd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (0, 1) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (1, 2) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. | 1,500 | [
{
"input": "2 2",
"output": "3\n0 1\n1 2\n2 0"
},
{
"input": "4 3",
"output": "4\n0 3\n2 1\n3 0\n4 2"
},
{
"input": "21 21",
"output": "22\n21 0\n20 1\n19 2\n18 3\n17 4\n16 5\n15 6\n14 7\n13 8\n12 9\n11 10\n10 11\n9 12\n8 13\n7 14\n6 15\n5 16\n4 17\n3 18\n2 19\n1 20\n0 21"
},
{
"input": "10 1",
"output": "2\n1 0\n0 1"
},
{
"input": "4 4",
"output": "5\n4 0\n3 1\n2 2\n1 3\n0 4"
},
{
"input": "1 1",
"output": "2\n1 0\n0 1"
},
{
"input": "5 5",
"output": "6\n5 0\n4 1\n3 2\n2 3\n1 4\n0 5"
},
{
"input": "100 100",
"output": "101\n100 0\n99 1\n98 2\n97 3\n96 4\n95 5\n94 6\n93 7\n92 8\n91 9\n90 10\n89 11\n88 12\n87 13\n86 14\n85 15\n84 16\n83 17\n82 18\n81 19\n80 20\n79 21\n78 22\n77 23\n76 24\n75 25\n74 26\n73 27\n72 28\n71 29\n70 30\n69 31\n68 32\n67 33\n66 34\n65 35\n64 36\n63 37\n62 38\n61 39\n60 40\n59 41\n58 42\n57 43\n56 44\n55 45\n54 46\n53 47\n52 48\n51 49\n50 50\n49 51\n48 52\n47 53\n46 54\n45 55\n44 56\n43 57\n42 58\n41 59\n40 60\n39 61\n38 62\n37 63\n36 64\n35 65\n34 66\n33 67\n32 68\n31 69\n30 70\n29 71\n28 72\n27 7..."
},
{
"input": "96 96",
"output": "97\n96 0\n95 1\n94 2\n93 3\n92 4\n91 5\n90 6\n89 7\n88 8\n87 9\n86 10\n85 11\n84 12\n83 13\n82 14\n81 15\n80 16\n79 17\n78 18\n77 19\n76 20\n75 21\n74 22\n73 23\n72 24\n71 25\n70 26\n69 27\n68 28\n67 29\n66 30\n65 31\n64 32\n63 33\n62 34\n61 35\n60 36\n59 37\n58 38\n57 39\n56 40\n55 41\n54 42\n53 43\n52 44\n51 45\n50 46\n49 47\n48 48\n47 49\n46 50\n45 51\n44 52\n43 53\n42 54\n41 55\n40 56\n39 57\n38 58\n37 59\n36 60\n35 61\n34 62\n33 63\n32 64\n31 65\n30 66\n29 67\n28 68\n27 69\n26 70\n25 71\n24 72\n23 73\n..."
},
{
"input": "99 100",
"output": "100\n99 0\n98 1\n97 2\n96 3\n95 4\n94 5\n93 6\n92 7\n91 8\n90 9\n89 10\n88 11\n87 12\n86 13\n85 14\n84 15\n83 16\n82 17\n81 18\n80 19\n79 20\n78 21\n77 22\n76 23\n75 24\n74 25\n73 26\n72 27\n71 28\n70 29\n69 30\n68 31\n67 32\n66 33\n65 34\n64 35\n63 36\n62 37\n61 38\n60 39\n59 40\n58 41\n57 42\n56 43\n55 44\n54 45\n53 46\n52 47\n51 48\n50 49\n49 50\n48 51\n47 52\n46 53\n45 54\n44 55\n43 56\n42 57\n41 58\n40 59\n39 60\n38 61\n37 62\n36 63\n35 64\n34 65\n33 66\n32 67\n31 68\n30 69\n29 70\n28 71\n27 72\n26 73..."
},
{
"input": "67 58",
"output": "59\n58 0\n57 1\n56 2\n55 3\n54 4\n53 5\n52 6\n51 7\n50 8\n49 9\n48 10\n47 11\n46 12\n45 13\n44 14\n43 15\n42 16\n41 17\n40 18\n39 19\n38 20\n37 21\n36 22\n35 23\n34 24\n33 25\n32 26\n31 27\n30 28\n29 29\n28 30\n27 31\n26 32\n25 33\n24 34\n23 35\n22 36\n21 37\n20 38\n19 39\n18 40\n17 41\n16 42\n15 43\n14 44\n13 45\n12 46\n11 47\n10 48\n9 49\n8 50\n7 51\n6 52\n5 53\n4 54\n3 55\n2 56\n1 57\n0 58"
},
{
"input": "67 59",
"output": "60\n59 0\n58 1\n57 2\n56 3\n55 4\n54 5\n53 6\n52 7\n51 8\n50 9\n49 10\n48 11\n47 12\n46 13\n45 14\n44 15\n43 16\n42 17\n41 18\n40 19\n39 20\n38 21\n37 22\n36 23\n35 24\n34 25\n33 26\n32 27\n31 28\n30 29\n29 30\n28 31\n27 32\n26 33\n25 34\n24 35\n23 36\n22 37\n21 38\n20 39\n19 40\n18 41\n17 42\n16 43\n15 44\n14 45\n13 46\n12 47\n11 48\n10 49\n9 50\n8 51\n7 52\n6 53\n5 54\n4 55\n3 56\n2 57\n1 58\n0 59"
},
{
"input": "80 91",
"output": "81\n80 0\n79 1\n78 2\n77 3\n76 4\n75 5\n74 6\n73 7\n72 8\n71 9\n70 10\n69 11\n68 12\n67 13\n66 14\n65 15\n64 16\n63 17\n62 18\n61 19\n60 20\n59 21\n58 22\n57 23\n56 24\n55 25\n54 26\n53 27\n52 28\n51 29\n50 30\n49 31\n48 32\n47 33\n46 34\n45 35\n44 36\n43 37\n42 38\n41 39\n40 40\n39 41\n38 42\n37 43\n36 44\n35 45\n34 46\n33 47\n32 48\n31 49\n30 50\n29 51\n28 52\n27 53\n26 54\n25 55\n24 56\n23 57\n22 58\n21 59\n20 60\n19 61\n18 62\n17 63\n16 64\n15 65\n14 66\n13 67\n12 68\n11 69\n10 70\n9 71\n8 72\n7 73\n6 ..."
},
{
"input": "100 11",
"output": "12\n11 0\n10 1\n9 2\n8 3\n7 4\n6 5\n5 6\n4 7\n3 8\n2 9\n1 10\n0 11"
},
{
"input": "16 55",
"output": "17\n16 0\n15 1\n14 2\n13 3\n12 4\n11 5\n10 6\n9 7\n8 8\n7 9\n6 10\n5 11\n4 12\n3 13\n2 14\n1 15\n0 16"
},
{
"input": "13 71",
"output": "14\n13 0\n12 1\n11 2\n10 3\n9 4\n8 5\n7 6\n6 7\n5 8\n4 9\n3 10\n2 11\n1 12\n0 13"
},
{
"input": "30 40",
"output": "31\n30 0\n29 1\n28 2\n27 3\n26 4\n25 5\n24 6\n23 7\n22 8\n21 9\n20 10\n19 11\n18 12\n17 13\n16 14\n15 15\n14 16\n13 17\n12 18\n11 19\n10 20\n9 21\n8 22\n7 23\n6 24\n5 25\n4 26\n3 27\n2 28\n1 29\n0 30"
},
{
"input": "77 77",
"output": "78\n77 0\n76 1\n75 2\n74 3\n73 4\n72 5\n71 6\n70 7\n69 8\n68 9\n67 10\n66 11\n65 12\n64 13\n63 14\n62 15\n61 16\n60 17\n59 18\n58 19\n57 20\n56 21\n55 22\n54 23\n53 24\n52 25\n51 26\n50 27\n49 28\n48 29\n47 30\n46 31\n45 32\n44 33\n43 34\n42 35\n41 36\n40 37\n39 38\n38 39\n37 40\n36 41\n35 42\n34 43\n33 44\n32 45\n31 46\n30 47\n29 48\n28 49\n27 50\n26 51\n25 52\n24 53\n23 54\n22 55\n21 56\n20 57\n19 58\n18 59\n17 60\n16 61\n15 62\n14 63\n13 64\n12 65\n11 66\n10 67\n9 68\n8 69\n7 70\n6 71\n5 72\n4 73\n3 74\n..."
},
{
"input": "6 6",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "37 42",
"output": "38\n37 0\n36 1\n35 2\n34 3\n33 4\n32 5\n31 6\n30 7\n29 8\n28 9\n27 10\n26 11\n25 12\n24 13\n23 14\n22 15\n21 16\n20 17\n19 18\n18 19\n17 20\n16 21\n15 22\n14 23\n13 24\n12 25\n11 26\n10 27\n9 28\n8 29\n7 30\n6 31\n5 32\n4 33\n3 34\n2 35\n1 36\n0 37"
},
{
"input": "88 88",
"output": "89\n88 0\n87 1\n86 2\n85 3\n84 4\n83 5\n82 6\n81 7\n80 8\n79 9\n78 10\n77 11\n76 12\n75 13\n74 14\n73 15\n72 16\n71 17\n70 18\n69 19\n68 20\n67 21\n66 22\n65 23\n64 24\n63 25\n62 26\n61 27\n60 28\n59 29\n58 30\n57 31\n56 32\n55 33\n54 34\n53 35\n52 36\n51 37\n50 38\n49 39\n48 40\n47 41\n46 42\n45 43\n44 44\n43 45\n42 46\n41 47\n40 48\n39 49\n38 50\n37 51\n36 52\n35 53\n34 54\n33 55\n32 56\n31 57\n30 58\n29 59\n28 60\n27 61\n26 62\n25 63\n24 64\n23 65\n22 66\n21 67\n20 68\n19 69\n18 70\n17 71\n16 72\n15 73\n..."
},
{
"input": "95 99",
"output": "96\n95 0\n94 1\n93 2\n92 3\n91 4\n90 5\n89 6\n88 7\n87 8\n86 9\n85 10\n84 11\n83 12\n82 13\n81 14\n80 15\n79 16\n78 17\n77 18\n76 19\n75 20\n74 21\n73 22\n72 23\n71 24\n70 25\n69 26\n68 27\n67 28\n66 29\n65 30\n64 31\n63 32\n62 33\n61 34\n60 35\n59 36\n58 37\n57 38\n56 39\n55 40\n54 41\n53 42\n52 43\n51 44\n50 45\n49 46\n48 47\n47 48\n46 49\n45 50\n44 51\n43 52\n42 53\n41 54\n40 55\n39 56\n38 57\n37 58\n36 59\n35 60\n34 61\n33 62\n32 63\n31 64\n30 65\n29 66\n28 67\n27 68\n26 69\n25 70\n24 71\n23 72\n22 73\n..."
},
{
"input": "93 70",
"output": "71\n70 0\n69 1\n68 2\n67 3\n66 4\n65 5\n64 6\n63 7\n62 8\n61 9\n60 10\n59 11\n58 12\n57 13\n56 14\n55 15\n54 16\n53 17\n52 18\n51 19\n50 20\n49 21\n48 22\n47 23\n46 24\n45 25\n44 26\n43 27\n42 28\n41 29\n40 30\n39 31\n38 32\n37 33\n36 34\n35 35\n34 36\n33 37\n32 38\n31 39\n30 40\n29 41\n28 42\n27 43\n26 44\n25 45\n24 46\n23 47\n22 48\n21 49\n20 50\n19 51\n18 52\n17 53\n16 54\n15 55\n14 56\n13 57\n12 58\n11 59\n10 60\n9 61\n8 62\n7 63\n6 64\n5 65\n4 66\n3 67\n2 68\n1 69\n0 70"
},
{
"input": "4 6",
"output": "5\n4 0\n3 1\n2 2\n1 3\n0 4"
},
{
"input": "1 4",
"output": "2\n1 0\n0 1"
},
{
"input": "2 10",
"output": "3\n2 0\n1 1\n0 2"
},
{
"input": "6 7",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "28 28",
"output": "29\n28 0\n27 1\n26 2\n25 3\n24 4\n23 5\n22 6\n21 7\n20 8\n19 9\n18 10\n17 11\n16 12\n15 13\n14 14\n13 15\n12 16\n11 17\n10 18\n9 19\n8 20\n7 21\n6 22\n5 23\n4 24\n3 25\n2 26\n1 27\n0 28"
},
{
"input": "10 6",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "85 48",
"output": "49\n48 0\n47 1\n46 2\n45 3\n44 4\n43 5\n42 6\n41 7\n40 8\n39 9\n38 10\n37 11\n36 12\n35 13\n34 14\n33 15\n32 16\n31 17\n30 18\n29 19\n28 20\n27 21\n26 22\n25 23\n24 24\n23 25\n22 26\n21 27\n20 28\n19 29\n18 30\n17 31\n16 32\n15 33\n14 34\n13 35\n12 36\n11 37\n10 38\n9 39\n8 40\n7 41\n6 42\n5 43\n4 44\n3 45\n2 46\n1 47\n0 48"
},
{
"input": "9 6",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "2 6",
"output": "3\n2 0\n1 1\n0 2"
},
{
"input": "6 4",
"output": "5\n4 0\n3 1\n2 2\n1 3\n0 4"
},
{
"input": "6 10",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "16 5",
"output": "6\n5 0\n4 1\n3 2\n2 3\n1 4\n0 5"
},
{
"input": "7 6",
"output": "7\n6 0\n5 1\n4 2\n3 3\n2 4\n1 5\n0 6"
},
{
"input": "3 4",
"output": "4\n3 0\n2 1\n1 2\n0 3"
},
{
"input": "13 18",
"output": "14\n13 0\n12 1\n11 2\n10 3\n9 4\n8 5\n7 6\n6 7\n5 8\n4 9\n3 10\n2 11\n1 12\n0 13"
},
{
"input": "5 100",
"output": "6\n5 0\n4 1\n3 2\n2 3\n1 4\n0 5"
},
{
"input": "11 9",
"output": "10\n9 0\n8 1\n7 2\n6 3\n5 4\n4 5\n3 6\n2 7\n1 8\n0 9"
},
{
"input": "13 13",
"output": "14\n13 0\n12 1\n11 2\n10 3\n9 4\n8 5\n7 6\n6 7\n5 8\n4 9\n3 10\n2 11\n1 12\n0 13"
},
{
"input": "1 5",
"output": "2\n1 0\n0 1"
},
{
"input": "3 19",
"output": "4\n3 0\n2 1\n1 2\n0 3"
},
{
"input": "10 10",
"output": "11\n10 0\n9 1\n8 2\n7 3\n6 4\n5 5\n4 6\n3 7\n2 8\n1 9\n0 10"
},
{
"input": "3 7",
"output": "4\n3 0\n2 1\n1 2\n0 3"
},
{
"input": "98 76",
"output": "77\n76 0\n75 1\n74 2\n73 3\n72 4\n71 5\n70 6\n69 7\n68 8\n67 9\n66 10\n65 11\n64 12\n63 13\n62 14\n61 15\n60 16\n59 17\n58 18\n57 19\n56 20\n55 21\n54 22\n53 23\n52 24\n51 25\n50 26\n49 27\n48 28\n47 29\n46 30\n45 31\n44 32\n43 33\n42 34\n41 35\n40 36\n39 37\n38 38\n37 39\n36 40\n35 41\n34 42\n33 43\n32 44\n31 45\n30 46\n29 47\n28 48\n27 49\n26 50\n25 51\n24 52\n23 53\n22 54\n21 55\n20 56\n19 57\n18 58\n17 59\n16 60\n15 61\n14 62\n13 63\n12 64\n11 65\n10 66\n9 67\n8 68\n7 69\n6 70\n5 71\n4 72\n3 73\n2 74\n..."
},
{
"input": "10 100",
"output": "11\n10 0\n9 1\n8 2\n7 3\n6 4\n5 5\n4 6\n3 7\n2 8\n1 9\n0 10"
}
] | 1,672,303,109 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n,m=map(int,input().split())
max_=min(m,n)+1
ans=[]
for i in range(min(n,m)+1):
ans.append([i,max_-i])
# print(ans)
print(max_)
for i in ans:
print(*i) | Title: Beautiful Sets of Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions:
1. The coordinates of each point in the set are integers. 1. For any two points from the set, the distance between them is a non-integer.
Consider all points (*x*,<=*y*) which satisfy the inequations: 0<=≤<=*x*<=≤<=*n*; 0<=≤<=*y*<=≤<=*m*; *x*<=+<=*y*<=><=0. Choose their subset of maximum size such that it is also a beautiful set of points.
Input Specification:
The single line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Output Specification:
In the first line print a single integer — the size *k* of the found beautiful set. In each of the next *k* lines print a pair of space-separated integers — the *x*- and *y*- coordinates, respectively, of a point from the set.
If there are several optimal solutions, you may print any of them.
Demo Input:
['2 2\n', '4 3\n']
Demo Output:
['3\n0 1\n1 2\n2 0\n', '4\n0 3\n2 1\n3 0\n4 2\n']
Note:
Consider the first sample. The distance between points (0, 1) and (1, 2) equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bfe16f27ebc966df6f10ba356a1547b6e7242dd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (0, 1) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>, between (1, 2) and (2, 0) — <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/23d63d8a57cddda72562a512c05111054cd85870.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution. | ```python
n,m=map(int,input().split())
max_=min(m,n)+1
ans=[]
for i in range(min(n,m)+1):
ans.append([i,max_-i])
# print(ans)
print(max_)
for i in ans:
print(*i)
``` | 0 |
|
820 | B | Mister B and Angle in Polygon | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"math"
] | null | null | On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices *v*1, *v*2, *v*3 such that the angle (where *v*2 is the vertex of the angle, and *v*1 and *v*3 lie on its sides) is as close as possible to *a*. In other words, the value should be minimum possible.
If there are many optimal solutions, Mister B should be satisfied with any of them. | First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees. | Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order. | [
"3 15\n",
"4 67\n",
"4 68\n"
] | [
"1 2 3\n",
"2 1 3\n",
"4 1 2\n"
] | In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1".
In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1". | 1,000 | [
{
"input": "3 15",
"output": "2 1 3"
},
{
"input": "4 67",
"output": "2 1 3"
},
{
"input": "4 68",
"output": "2 1 4"
},
{
"input": "3 1",
"output": "2 1 3"
},
{
"input": "3 180",
"output": "2 1 3"
},
{
"input": "100000 1",
"output": "2 1 558"
},
{
"input": "100000 180",
"output": "2 1 100000"
},
{
"input": "100000 42",
"output": "2 1 23335"
},
{
"input": "100000 123",
"output": "2 1 68335"
},
{
"input": "5 1",
"output": "2 1 3"
},
{
"input": "5 36",
"output": "2 1 3"
},
{
"input": "5 54",
"output": "2 1 3"
},
{
"input": "5 55",
"output": "2 1 4"
},
{
"input": "5 70",
"output": "2 1 4"
},
{
"input": "5 89",
"output": "2 1 4"
},
{
"input": "5 90",
"output": "2 1 4"
},
{
"input": "5 91",
"output": "2 1 5"
},
{
"input": "5 111",
"output": "2 1 5"
},
{
"input": "5 126",
"output": "2 1 5"
},
{
"input": "5 127",
"output": "2 1 5"
},
{
"input": "5 141",
"output": "2 1 5"
},
{
"input": "5 162",
"output": "2 1 5"
},
{
"input": "5 180",
"output": "2 1 5"
},
{
"input": "6 46",
"output": "2 1 4"
},
{
"input": "6 33",
"output": "2 1 3"
},
{
"input": "13 4",
"output": "2 1 3"
},
{
"input": "23 11",
"output": "2 1 3"
},
{
"input": "11 119",
"output": "2 1 9"
},
{
"input": "13 117",
"output": "2 1 10"
},
{
"input": "18 174",
"output": "2 1 18"
},
{
"input": "8509 139",
"output": "2 1 6573"
},
{
"input": "29770 76",
"output": "2 1 12572"
},
{
"input": "59115 40",
"output": "2 1 13139"
},
{
"input": "68459 88",
"output": "2 1 33471"
},
{
"input": "85100 129",
"output": "2 1 60990"
},
{
"input": "100000 13",
"output": "2 1 7224"
},
{
"input": "100000 35",
"output": "2 1 19446"
},
{
"input": "100000 49",
"output": "2 1 27224"
},
{
"input": "100000 71",
"output": "2 1 39446"
},
{
"input": "100000 79",
"output": "2 1 43891"
},
{
"input": "100000 101",
"output": "2 1 56113"
},
{
"input": "100000 109",
"output": "2 1 60558"
},
{
"input": "100000 143",
"output": "2 1 79446"
},
{
"input": "100000 148",
"output": "2 1 82224"
},
{
"input": "100000 176",
"output": "2 1 97780"
},
{
"input": "4 16",
"output": "2 1 3"
}
] | 1,498,577,410 | 3,310 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 46 | 5,529,600 | n,a = map(int,input().split())
k = round(n * a / 180)
if k == 0:
k = 1
print(1,2+k,1+k) | Title: Mister B and Angle in Polygon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices *v*1, *v*2, *v*3 such that the angle (where *v*2 is the vertex of the angle, and *v*1 and *v*3 lie on its sides) is as close as possible to *a*. In other words, the value should be minimum possible.
If there are many optimal solutions, Mister B should be satisfied with any of them.
Input Specification:
First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees.
Output Specification:
Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order.
Demo Input:
['3 15\n', '4 67\n', '4 68\n']
Demo Output:
['1 2 3\n', '2 1 3\n', '4 1 2\n']
Note:
In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1".
In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1". | ```python
n,a = map(int,input().split())
k = round(n * a / 180)
if k == 0:
k = 1
print(1,2+k,1+k)
``` | 0 |
|
438 | D | The Child and Sequence | PROGRAMMING | 2,300 | [
"data structures",
"math"
] | null | null | At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks.
Fortunately, Picks remembers how to repair the sequence. Initially he should create an integer array *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Then he should perform a sequence of *m* operations. An operation can be one of the following:
1. Print operation *l*,<=*r*. Picks should write down the value of . 1. Modulo operation *l*,<=*r*,<=*x*. Picks should perform assignment *a*[*i*]<==<=*a*[*i*] *mod* *x* for each *i* (*l*<=≤<=*i*<=≤<=*r*). 1. Set operation *k*,<=*x*. Picks should set the value of *a*[*k*] to *x* (in other words perform an assignment *a*[*k*]<==<=*x*).
Can you help Picks to perform the whole sequence of operations? | The first line of input contains two integer: *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers, separated by space: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109) — initial value of array elements.
Each of the next *m* lines begins with a number *type* .
- If *type*<==<=1, there will be two integers more in the line: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), which correspond the operation 1. - If *type*<==<=2, there will be three integers more in the line: *l*,<=*r*,<=*x* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*x*<=≤<=109), which correspond the operation 2. - If *type*<==<=3, there will be two integers more in the line: *k*,<=*x* (1<=≤<=*k*<=≤<=*n*; 1<=≤<=*x*<=≤<=109), which correspond the operation 3. | For each operation 1, please print a line containing the answer. Notice that the answer may exceed the 32-bit integer. | [
"5 5\n1 2 3 4 5\n2 3 5 4\n3 3 5\n1 2 5\n2 1 3 3\n1 1 3\n",
"10 10\n6 9 6 7 6 1 10 10 9 5\n1 3 9\n2 7 10 9\n2 5 10 8\n1 4 7\n3 3 7\n2 7 9 9\n1 2 4\n1 6 6\n1 5 9\n3 1 10\n"
] | [
"8\n5\n",
"49\n15\n23\n1\n9\n"
] | Consider the first testcase:
- At first, *a* = {1, 2, 3, 4, 5}. - After operation 1, *a* = {1, 2, 3, 0, 1}. - After operation 2, *a* = {1, 2, 5, 0, 1}. - At operation 3, 2 + 5 + 0 + 1 = 8. - After operation 4, *a* = {1, 2, 2, 0, 1}. <li> At operation 5, 1 + 2 + 2 = 5. <ul> | 2,000 | [
{
"input": "5 5\n1 2 3 4 5\n2 3 5 4\n3 3 5\n1 2 5\n2 1 3 3\n1 1 3",
"output": "8\n5"
},
{
"input": "10 10\n6 9 6 7 6 1 10 10 9 5\n1 3 9\n2 7 10 9\n2 5 10 8\n1 4 7\n3 3 7\n2 7 9 9\n1 2 4\n1 6 6\n1 5 9\n3 1 10",
"output": "49\n15\n23\n1\n9"
},
{
"input": "1 1\n1\n1 1 1",
"output": "1"
},
{
"input": "1 1\n1000000000\n1 1 1",
"output": "1000000000"
}
] | 1,689,604,341 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689604341.0350192")# 1689604341.0350392 | Title: The Child and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks.
Fortunately, Picks remembers how to repair the sequence. Initially he should create an integer array *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Then he should perform a sequence of *m* operations. An operation can be one of the following:
1. Print operation *l*,<=*r*. Picks should write down the value of . 1. Modulo operation *l*,<=*r*,<=*x*. Picks should perform assignment *a*[*i*]<==<=*a*[*i*] *mod* *x* for each *i* (*l*<=≤<=*i*<=≤<=*r*). 1. Set operation *k*,<=*x*. Picks should set the value of *a*[*k*] to *x* (in other words perform an assignment *a*[*k*]<==<=*x*).
Can you help Picks to perform the whole sequence of operations?
Input Specification:
The first line of input contains two integer: *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers, separated by space: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109) — initial value of array elements.
Each of the next *m* lines begins with a number *type* .
- If *type*<==<=1, there will be two integers more in the line: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), which correspond the operation 1. - If *type*<==<=2, there will be three integers more in the line: *l*,<=*r*,<=*x* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*x*<=≤<=109), which correspond the operation 2. - If *type*<==<=3, there will be two integers more in the line: *k*,<=*x* (1<=≤<=*k*<=≤<=*n*; 1<=≤<=*x*<=≤<=109), which correspond the operation 3.
Output Specification:
For each operation 1, please print a line containing the answer. Notice that the answer may exceed the 32-bit integer.
Demo Input:
['5 5\n1 2 3 4 5\n2 3 5 4\n3 3 5\n1 2 5\n2 1 3 3\n1 1 3\n', '10 10\n6 9 6 7 6 1 10 10 9 5\n1 3 9\n2 7 10 9\n2 5 10 8\n1 4 7\n3 3 7\n2 7 9 9\n1 2 4\n1 6 6\n1 5 9\n3 1 10\n']
Demo Output:
['8\n5\n', '49\n15\n23\n1\n9\n']
Note:
Consider the first testcase:
- At first, *a* = {1, 2, 3, 4, 5}. - After operation 1, *a* = {1, 2, 3, 0, 1}. - After operation 2, *a* = {1, 2, 5, 0, 1}. - At operation 3, 2 + 5 + 0 + 1 = 8. - After operation 4, *a* = {1, 2, 2, 0, 1}. <li> At operation 5, 1 + 2 + 2 = 5. <ul> | ```python
print("_RANDOM_GUESS_1689604341.0350192")# 1689604341.0350392
``` | 0 |
|
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,608,268,878 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 312 | 0 | n = int(input())
arr_n = list(map(int, input().strip().split()))
fr = n + 1
rem = sum(arr_n) % fr
count = 0
for x in range(1,6):
if (rem + x) % fr != 1:
count += 1
print(count) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
n = int(input())
arr_n = list(map(int, input().strip().split()))
fr = n + 1
rem = sum(arr_n) % fr
count = 0
for x in range(1,6):
if (rem + x) % fr != 1:
count += 1
print(count)
``` | 3 |
|
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book.
Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.
Print the maximum number of books Valera can read. | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book. | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4"
},
{
"input": "7 13\n6 8 14 9 4 11 10",
"output": "2"
},
{
"input": "10 15\n10 9 1 1 5 10 5 3 7 2",
"output": "3"
},
{
"input": "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4",
"output": "6"
},
{
"input": "30 60\n16 13 22 38 13 35 17 17 20 38 12 19 9 22 20 3 35 34 34 21 35 40 22 3 27 19 12 4 8 19",
"output": "4"
},
{
"input": "100 100\n75 92 18 6 81 67 7 92 100 65 82 32 50 67 85 31 80 91 84 63 39 52 92 81 1 98 24 12 43 48 17 86 51 72 48 95 45 50 12 66 19 79 49 89 34 1 97 75 20 33 96 27 42 23 73 71 93 1 85 19 66 14 17 61 20 39 36 33 42 61 56 64 23 91 80 99 40 74 13 18 98 85 74 39 62 84 46 74 50 23 38 11 79 14 9 25 66 100 25 52",
"output": "3"
},
{
"input": "10 1\n4418 7528 8170 1736 1317 3205 8183 4995 8039 4708",
"output": "0"
},
{
"input": "50 2\n124 214 63 73 996 760 38 571 451 300 970 1 706 937 837 494 619 88 851 411 957 990 842 613 821 649 627 34 693 678 734 116 816 985 705 940 499 493 922 967 854 439 112 644 961 438 189 572 655 550",
"output": "1"
}
] | 1,692,175,534 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | def main():
N, M = map(int, input().split())
hotel_values = list(map(int, input().split()))
max_total_value = 0
current_total_value = 0
left_pointer = 0
for right_pointer in range(N):
current_total_value += hotel_values[right_pointer]
while current_total_value > M:
current_total_value -= hotel_values[left_pointer]
left_pointer += 1
if current_total_value > max_total_value:
max_total_value = current_total_value
print(max_total_value)
if __name__ == "__main__":
main()
| Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book.
Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.
Print the maximum number of books Valera can read.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book.
Output Specification:
Print a single integer — the maximum number of books Valera can read.
Demo Input:
['4 5\n3 1 2 1\n', '3 3\n2 2 3\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
def main():
N, M = map(int, input().split())
hotel_values = list(map(int, input().split()))
max_total_value = 0
current_total_value = 0
left_pointer = 0
for right_pointer in range(N):
current_total_value += hotel_values[right_pointer]
while current_total_value > M:
current_total_value -= hotel_values[left_pointer]
left_pointer += 1
if current_total_value > max_total_value:
max_total_value = current_total_value
print(max_total_value)
if __name__ == "__main__":
main()
``` | 0 |
|
962 | C | Make a Square | PROGRAMMING | 1,400 | [
"brute force",
"implementation",
"math"
] | null | null | You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible.
An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$. | The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes. | If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it. | [
"8314\n",
"625\n",
"333\n"
] | [
"2\n",
"0\n",
"-1\n"
] | In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$.
In the second example the given $625$ is the square of the integer $25$, so you should not delete anything.
In the third example it is impossible to make the square from $333$, so the answer is -1. | 0 | [
{
"input": "8314",
"output": "2"
},
{
"input": "625",
"output": "0"
},
{
"input": "333",
"output": "-1"
},
{
"input": "1881388645",
"output": "6"
},
{
"input": "1059472069",
"output": "3"
},
{
"input": "1354124829",
"output": "4"
},
{
"input": "149723943",
"output": "4"
},
{
"input": "101",
"output": "2"
},
{
"input": "1999967841",
"output": "0"
},
{
"input": "2000000000",
"output": "-1"
},
{
"input": "1999431225",
"output": "0"
},
{
"input": "30",
"output": "-1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "3081",
"output": "2"
},
{
"input": "10",
"output": "1"
},
{
"input": "2003064",
"output": "3"
},
{
"input": "701",
"output": "2"
},
{
"input": "1234567891",
"output": "4"
},
{
"input": "10625",
"output": "2"
},
{
"input": "13579",
"output": "4"
},
{
"input": "1999999999",
"output": "9"
},
{
"input": "150000",
"output": "1"
},
{
"input": "8010902",
"output": "3"
},
{
"input": "20100",
"output": "2"
},
{
"input": "40404",
"output": "2"
},
{
"input": "70000729",
"output": "5"
},
{
"input": "1899933124",
"output": "5"
},
{
"input": "1999999081",
"output": "8"
},
{
"input": "326700",
"output": "2"
},
{
"input": "1",
"output": "0"
},
{
"input": "1000000990",
"output": "3"
},
{
"input": "10000",
"output": "0"
},
{
"input": "100001",
"output": "1"
},
{
"input": "1410065408",
"output": "7"
},
{
"input": "1409865409",
"output": "5"
},
{
"input": "1000050001",
"output": "3"
},
{
"input": "1044435556",
"output": "2"
},
{
"input": "520993450",
"output": "6"
},
{
"input": "131073",
"output": "5"
},
{
"input": "500040004",
"output": "6"
},
{
"input": "237555493",
"output": "7"
},
{
"input": "1120671621",
"output": "5"
},
{
"input": "298755045",
"output": "5"
},
{
"input": "1476838469",
"output": "5"
},
{
"input": "654921893",
"output": "4"
},
{
"input": "1538038021",
"output": "4"
},
{
"input": "716121445",
"output": "6"
},
{
"input": "1894204869",
"output": "5"
},
{
"input": "1800098866",
"output": "7"
},
{
"input": "890665277",
"output": "8"
},
{
"input": "1686264392",
"output": "6"
},
{
"input": "1336639314",
"output": "6"
},
{
"input": "132238429",
"output": "5"
},
{
"input": "927837544",
"output": "4"
},
{
"input": "18403955",
"output": "4"
},
{
"input": "1668778878",
"output": "8"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "-1"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "-1"
},
{
"input": "7",
"output": "-1"
},
{
"input": "8",
"output": "-1"
},
{
"input": "9",
"output": "0"
},
{
"input": "11",
"output": "1"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "14",
"output": "1"
},
{
"input": "15",
"output": "1"
},
{
"input": "16",
"output": "0"
}
] | 1,524,559,210 | 2,110 | Python 3 | WRONG_ANSWER | TESTS | 3 | 249 | 7,065,600 | def get_list(func=None):
if not func:
return input().split()
return list(map(func, input().split()))
def edit_dist(A, a):
""" Calculate the edit distance from A to a. """
if len(A) < len(a):
return -1
if len(a) == 1:
if a in A:
return len(A) - 1
else:
return -1
mind = float('inf')
for i, ch in enumerate(A):
if ch == a[0]:
d = edit_dist(A[i+1:], a[1:])
if d != -1:
mind = min(mind, d)
return mind
# print(edit_dist("625", "625"))
n = input()
mind = float('inf')
for i in range(1, int(10**4.5)):
s = str(i**2)
d = edit_dist(n, s)
if d != -1:
mind = min(mind, d)
if mind > 100:
print(-1)
else:
print(mind)
| Title: Make a Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible.
An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes.
Output Specification:
If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it.
Demo Input:
['8314\n', '625\n', '333\n']
Demo Output:
['2\n', '0\n', '-1\n']
Note:
In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$.
In the second example the given $625$ is the square of the integer $25$, so you should not delete anything.
In the third example it is impossible to make the square from $333$, so the answer is -1. | ```python
def get_list(func=None):
if not func:
return input().split()
return list(map(func, input().split()))
def edit_dist(A, a):
""" Calculate the edit distance from A to a. """
if len(A) < len(a):
return -1
if len(a) == 1:
if a in A:
return len(A) - 1
else:
return -1
mind = float('inf')
for i, ch in enumerate(A):
if ch == a[0]:
d = edit_dist(A[i+1:], a[1:])
if d != -1:
mind = min(mind, d)
return mind
# print(edit_dist("625", "625"))
n = input()
mind = float('inf')
for i in range(1, int(10**4.5)):
s = str(i**2)
d = edit_dist(n, s)
if d != -1:
mind = min(mind, d)
if mind > 100:
print(-1)
else:
print(mind)
``` | 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,579,645,577 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 372 | 0 | n = int(input())
a = []
b = []
c = []
for i in range(n):
s = list(map(int,input().split()))
a.append(s[0])
b.append(s[1])
c.append(s[2])
if sum(a)==0 and sum(b)==0 and sum(c)==0:
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n = int(input())
a = []
b = []
c = []
for i in range(n):
s = list(map(int,input().split()))
a.append(s[0])
b.append(s[1])
c.append(s[2])
if sum(a)==0 and sum(b)==0 and sum(c)==0:
print('YES')
else:
print('NO')
``` | 3.907 |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 594 622 834 922",
"output": "17"
},
{
"input": "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000",
"output": "3"
},
{
"input": "2\nRL\n0 1000000000",
"output": "500000000"
},
{
"input": "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134 9082",
"output": "108"
},
{
"input": "14\nRLLRRLRLLRLLLR\n698 2900 3476 3724 3772 3948 4320 4798 5680 6578 7754 8034 8300 8418",
"output": "88"
},
{
"input": "16\nRRLLLRLRLLLLRLLR\n222 306 968 1060 1636 1782 2314 2710 3728 4608 5088 6790 6910 7156 7418 7668",
"output": "123"
},
{
"input": "18\nRLRLLRRRLLLRLRRLRL\n1692 2028 2966 3008 3632 4890 5124 5838 6596 6598 6890 8294 8314 8752 8868 9396 9616 9808",
"output": "10"
},
{
"input": "20\nRLLLLLLLRRRRLRRLRRLR\n380 902 1400 1834 2180 2366 2562 2596 2702 2816 3222 3238 3742 5434 6480 7220 7410 8752 9708 9970",
"output": "252"
},
{
"input": "22\nLRRRRRRRRRRRLLRRRRRLRL\n1790 2150 2178 2456 2736 3282 3622 4114 4490 4772 5204 5240 5720 5840 5910 5912 6586 7920 8584 9404 9734 9830",
"output": "48"
},
{
"input": "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720",
"output": "27"
},
{
"input": "26\nRLLLLLLLRLRRLRLRLRLRLLLRRR\n908 1826 2472 2474 2728 3654 3716 3718 3810 3928 4058 4418 4700 5024 5768 6006 6128 6386 6968 7040 7452 7774 7822 8726 9338 9402",
"output": "59"
},
{
"input": "28\nRRLRLRRRRRRLLLRRLRRLLLRRLLLR\n156 172 1120 1362 2512 3326 3718 4804 4990 5810 6242 6756 6812 6890 6974 7014 7088 7724 8136 8596 8770 8840 9244 9250 9270 9372 9400 9626",
"output": "10"
},
{
"input": "30\nRLLRLRLLRRRLRRRLLLLLLRRRLRRLRL\n128 610 1680 2436 2896 2994 3008 3358 3392 4020 4298 4582 4712 4728 5136 5900 6088 6232 6282 6858 6934 7186 7224 7256 7614 8802 8872 9170 9384 9794",
"output": "7"
},
{
"input": "10\nLLLLRRRRRR\n0 2 4 6 8 10 12 14 16 18",
"output": "-1"
},
{
"input": "5\nLLLLL\n0 10 20 30 40",
"output": "-1"
},
{
"input": "6\nRRRRRR\n40 50 60 70 80 100",
"output": "-1"
},
{
"input": "1\nR\n0",
"output": "-1"
},
{
"input": "2\nRL\n2 1000000000",
"output": "499999999"
},
{
"input": "2\nRL\n0 400000",
"output": "200000"
},
{
"input": "2\nRL\n0 200002",
"output": "100001"
},
{
"input": "2\nRL\n2 20000000",
"output": "9999999"
},
{
"input": "4\nLLRL\n2 4 10 100",
"output": "45"
},
{
"input": "4\nRLRL\n2 10 12 14",
"output": "1"
},
{
"input": "2\nRL\n0 100000000",
"output": "50000000"
},
{
"input": "2\nRL\n2 600002",
"output": "300000"
},
{
"input": "1\nL\n0",
"output": "-1"
},
{
"input": "2\nRL\n0 600000",
"output": "300000"
},
{
"input": "5\nRRRRR\n0 2 4 6 8",
"output": "-1"
},
{
"input": "2\nRL\n2 200000000",
"output": "99999999"
},
{
"input": "2\nRL\n0 267382766",
"output": "133691383"
},
{
"input": "3\nRRL\n4 8 999999998",
"output": "499999995"
},
{
"input": "2\nRL\n0 2",
"output": "1"
},
{
"input": "2\nRL\n2 400002",
"output": "200000"
},
{
"input": "2\nLL\n2 4",
"output": "-1"
},
{
"input": "2\nLL\n0 2",
"output": "-1"
},
{
"input": "2\nRL\n0 100000",
"output": "50000"
},
{
"input": "2\nRL\n2 200000020",
"output": "100000009"
},
{
"input": "2\nRL\n2000000 4000000",
"output": "1000000"
},
{
"input": "2\nRL\n0 199998",
"output": "99999"
},
{
"input": "3\nLRR\n40 50 60",
"output": "-1"
},
{
"input": "2\nRL\n200 400400",
"output": "200100"
},
{
"input": "2\nRL\n2 400004",
"output": "200001"
},
{
"input": "2\nRL\n0 200000000",
"output": "100000000"
}
] | 1,669,872,829 | 2,147,483,647 | PyPy 3 | OK | TESTS | 85 | 264 | 18,636,800 | import sys
input = sys.stdin.readline
n = int(input())
s = input()
a = list(map(int, input().split()))
ans = 1e10
for i in range(n-1):
if s[i] == 'R' and s[i+1] == 'L':
ans = min(ans, (a[i+1] - a[i])//2)
if ans != 1e10:
print(ans)
else:
print(-1)
| Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output Specification:
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Demo Input:
['4\nRLRL\n2 4 6 10\n', '3\nLLR\n40 50 60\n']
Demo Output:
['1\n', '-1\n']
Note:
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | ```python
import sys
input = sys.stdin.readline
n = int(input())
s = input()
a = list(map(int, input().split()))
ans = 1e10
for i in range(n-1):
if s[i] == 'R' and s[i+1] == 'L':
ans = min(ans, (a[i+1] - a[i])//2)
if ans != 1e10:
print(ans)
else:
print(-1)
``` | 3 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,603,338,481 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 140 | 0 | n1=input();n2=input();lis1=list(n1);lis2=list(n2)
i = 0
res = []
while(i!=len(lis1)):
if lis1[i] == lis2[i]:
res.append(0)
else:
res.append(1)
i=i+1
print(*res, sep='') | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
n1=input();n2=input();lis1=list(n1);lis2=list(n2)
i = 0
res = []
while(i!=len(lis1)):
if lis1[i] == lis2[i]:
res.append(0)
else:
res.append(1)
i=i+1
print(*res, sep='')
``` | 3.965 |
964 | B | Messages | PROGRAMMING | 1,300 | [
"math"
] | null | null | There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0.
Also, each minute Vasya's bank account receives *C*·*k*, where *k* is the amount of received but unread messages.
Vasya's messages are very important to him, and because of that he wants to have all messages read after *T* minutes.
Determine the maximum amount of money Vasya's bank account can hold after *T* minutes. | The first line contains five integers *n*, *A*, *B*, *C* and *T* (1<=≤<=*n*,<=*A*,<=*B*,<=*C*,<=*T*<=≤<=1000).
The second string contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=*T*). | Output one integer — the answer to the problem. | [
"4 5 5 3 5\n1 5 5 4\n",
"5 3 1 1 3\n2 2 2 1 1\n",
"5 5 3 4 5\n1 2 3 4 5\n"
] | [
"20\n",
"15\n",
"35\n"
] | In the first sample the messages must be read immediately after receiving, Vasya receives *A* points for each message, *n*·*A* = 20 in total.
In the second sample the messages can be read at any integer moment.
In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at the corresponding minutes, he gets 40 points for them. When reading messages, he receives (5 - 4·3) + (5 - 3·3) + (5 - 2·3) + (5 - 1·3) + 5 = - 5 points. This is 35 in total. | 1,000 | [
{
"input": "4 5 5 3 5\n1 5 5 4",
"output": "20"
},
{
"input": "5 3 1 1 3\n2 2 2 1 1",
"output": "15"
},
{
"input": "5 5 3 4 5\n1 2 3 4 5",
"output": "35"
},
{
"input": "1 6 4 3 9\n2",
"output": "6"
},
{
"input": "10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3",
"output": "90"
},
{
"input": "44 464 748 420 366\n278 109 293 161 336 9 194 203 13 226 303 303 300 131 134 47 235 110 263 67 185 337 360 253 270 97 162 190 143 267 18 311 329 138 322 167 324 33 3 104 290 260 349 89",
"output": "20416"
},
{
"input": "80 652 254 207 837\n455 540 278 38 19 781 686 110 733 40 434 581 77 381 818 236 444 615 302 251 762 676 771 483 767 479 326 214 316 551 544 95 157 828 813 201 103 502 751 410 84 733 431 90 261 326 731 374 730 748 303 83 302 673 50 822 46 590 248 751 345 579 689 616 331 593 428 344 754 777 178 80 602 268 776 234 637 780 712 539",
"output": "52160"
},
{
"input": "62 661 912 575 6\n3 5 6 6 5 6 6 6 3 2 3 1 4 3 2 5 3 6 1 4 2 5 1 2 6 4 6 6 5 5 4 3 4 1 4 2 4 4 2 6 4 6 3 5 3 4 1 5 3 6 5 6 4 1 2 1 6 5 5 4 2 3",
"output": "40982"
},
{
"input": "49 175 330 522 242\n109 81 215 5 134 185 60 242 154 148 14 221 146 229 45 120 142 43 202 176 231 105 212 69 109 219 58 103 53 211 128 138 157 95 96 122 69 109 35 46 122 118 132 135 224 150 178 134 28",
"output": "1083967"
},
{
"input": "27 27 15 395 590\n165 244 497 107 546 551 232 177 428 237 209 186 135 162 511 514 408 132 11 364 16 482 279 246 30 103 152",
"output": "3347009"
},
{
"input": "108 576 610 844 573\n242 134 45 515 430 354 405 179 174 366 155 4 300 176 96 36 508 70 75 316 118 563 55 340 128 214 138 511 507 437 454 478 341 443 421 573 270 362 208 107 256 471 436 378 336 507 383 352 450 411 297 34 179 551 119 524 141 288 387 9 283 241 304 214 503 559 416 447 495 61 169 228 479 568 368 441 467 401 467 542 370 243 371 315 65 67 161 383 19 144 283 5 369 242 122 396 276 488 401 387 256 128 87 425 124 226 335 238",
"output": "6976440"
},
{
"input": "67 145 951 829 192\n2 155 41 125 20 70 43 47 120 190 141 8 37 183 72 141 52 168 185 71 36 12 31 3 151 98 95 82 148 110 64 10 67 54 176 130 116 5 61 90 24 43 156 49 70 186 165 109 56 11 148 119 139 120 138 124 3 159 75 173 4 101 190 64 90 176 176",
"output": "9715"
},
{
"input": "67 322 317 647 99\n68 33 75 39 10 60 93 40 77 71 90 14 67 26 54 87 91 67 60 76 83 7 20 47 39 79 54 43 35 9 19 39 77 56 83 31 95 15 40 37 56 88 7 89 11 49 72 48 85 95 50 78 12 1 81 53 94 97 9 26 78 62 57 23 18 19 4",
"output": "1066024"
},
{
"input": "32 2 74 772 674\n598 426 358 191 471 667 412 44 183 358 436 654 572 489 79 191 374 33 1 627 154 132 101 236 443 112 77 93 553 53 260 498",
"output": "8161080"
},
{
"input": "111 907 98 340 279\n187 200 223 12 179 57 81 195 250 139 2 190 21 91 145 251 113 41 18 55 235 123 99 154 179 81 59 20 145 244 131 210 76 6 198 43 71 267 60 92 101 265 55 63 231 232 74 233 246 265 102 92 78 111 107 37 51 135 38 62 156 112 70 37 227 25 111 263 175 114 4 128 50 276 226 119 130 33 134 38 48 229 108 88 53 142 233 86 214 173 136 68 2 202 132 49 73 205 208 224 99 96 116 5 74 179 63 197 58 68 50",
"output": "4297441"
}
] | 1,524,380,399 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 93 | 7,372,800 | n, A, B, C, T = list(map(int, input().split()))
t = list(map(int, input().split()))
t.sort()
if C-B > 0:
res = sum(map(lambda x: A+(C-B)*(T-x), t))
else:
res = A*len(t)
print(res)
| Title: Messages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0.
Also, each minute Vasya's bank account receives *C*·*k*, where *k* is the amount of received but unread messages.
Vasya's messages are very important to him, and because of that he wants to have all messages read after *T* minutes.
Determine the maximum amount of money Vasya's bank account can hold after *T* minutes.
Input Specification:
The first line contains five integers *n*, *A*, *B*, *C* and *T* (1<=≤<=*n*,<=*A*,<=*B*,<=*C*,<=*T*<=≤<=1000).
The second string contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=*T*).
Output Specification:
Output one integer — the answer to the problem.
Demo Input:
['4 5 5 3 5\n1 5 5 4\n', '5 3 1 1 3\n2 2 2 1 1\n', '5 5 3 4 5\n1 2 3 4 5\n']
Demo Output:
['20\n', '15\n', '35\n']
Note:
In the first sample the messages must be read immediately after receiving, Vasya receives *A* points for each message, *n*·*A* = 20 in total.
In the second sample the messages can be read at any integer moment.
In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at the corresponding minutes, he gets 40 points for them. When reading messages, he receives (5 - 4·3) + (5 - 3·3) + (5 - 2·3) + (5 - 1·3) + 5 = - 5 points. This is 35 in total. | ```python
n, A, B, C, T = list(map(int, input().split()))
t = list(map(int, input().split()))
t.sort()
if C-B > 0:
res = sum(map(lambda x: A+(C-B)*(T-x), t))
else:
res = A*len(t)
print(res)
``` | 3 |
|
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
"output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000"
},
{
"input": "2\n-1000000000 1000000000",
"output": "2000000000 2000000000\n2000000000 2000000000"
},
{
"input": "10\n1 10 12 15 59 68 130 912 1239 9123",
"output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122"
},
{
"input": "5\n-2 -1 0 1 2",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "5\n-2 -1 0 1 3",
"output": "1 5\n1 4\n1 3\n1 3\n2 5"
},
{
"input": "3\n-10000 1 10000",
"output": "10001 20000\n9999 10001\n9999 20000"
},
{
"input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706",
"output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010"
},
{
"input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124",
"output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524"
},
{
"input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292",
"output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307"
},
{
"input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986",
"output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14"
},
{
"input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886",
"output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..."
},
{
"input": "3\n-1000000000 999999999 1000000000",
"output": "1999999999 2000000000\n1 1999999999\n1 2000000000"
}
] | 1,630,528,209 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 390 | 32,358,400 | n = int(input())
x = [int(x) for x in input().split()]
number_leftmost = x[0]
number_rightmost = x[-1]
# print(farthest_left, farthest_right)
chota_bhai = [0]*n
chota_bhai[0] = abs(x[0]-x[1])
chota_bhai[-1] = abs(x[-1]-x[-2])
for i in range(1,n-1):
chota_bhai[i] = min(abs(x[i]-x[i-1]), abs(x[i+1]-x[i]))
mota_bhai = [0]*n
mota_bhai[0] = abs(number_leftmost-number_rightmost)
mota_bhai[-1] = mota_bhai[0]
for i in range(1,n-1):
mota_bhai[i] = max(abs(x[i]-number_rightmost), abs(x[i]-number_leftmost))
for i in range(n):
print(chota_bhai[i], mota_bhai[i])
| Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Output Specification:
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
Demo Input:
['4\n-5 -2 2 7\n', '2\n-1 1\n']
Demo Output:
['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n']
Note:
none | ```python
n = int(input())
x = [int(x) for x in input().split()]
number_leftmost = x[0]
number_rightmost = x[-1]
# print(farthest_left, farthest_right)
chota_bhai = [0]*n
chota_bhai[0] = abs(x[0]-x[1])
chota_bhai[-1] = abs(x[-1]-x[-2])
for i in range(1,n-1):
chota_bhai[i] = min(abs(x[i]-x[i-1]), abs(x[i+1]-x[i]))
mota_bhai = [0]*n
mota_bhai[0] = abs(number_leftmost-number_rightmost)
mota_bhai[-1] = mota_bhai[0]
for i in range(1,n-1):
mota_bhai[i] = max(abs(x[i]-number_rightmost), abs(x[i]-number_leftmost))
for i in range(n):
print(chota_bhai[i], mota_bhai[i])
``` | 3 |
|
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | 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.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "480",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "49",
"output": "YES"
},
{
"input": "56",
"output": "YES"
},
{
"input": "124",
"output": "YES"
},
{
"input": "1000",
"output": "YES"
},
{
"input": "999",
"output": "NO"
},
{
"input": "298",
"output": "NO"
},
{
"input": "274",
"output": "NO"
},
{
"input": "998",
"output": "NO"
},
{
"input": "42",
"output": "YES"
},
{
"input": "788",
"output": "YES"
},
{
"input": "70",
"output": "YES"
},
{
"input": "444",
"output": "YES"
},
{
"input": "777",
"output": "YES"
},
{
"input": "799",
"output": "YES"
},
{
"input": "25",
"output": "NO"
},
{
"input": "882",
"output": "YES"
},
{
"input": "88",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "YES"
},
{
"input": "94",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "141",
"output": "YES"
}
] | 1,694,523,524 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 25 | 122 | 0 | s = input()
t = int(s)
count = 0
slist = list(s)
arr = ['1', '2', '3', '5', '6', '8', '9', '0']
for i in range(len(slist)):
if slist[i] in arr:
count += 1
if count > 0:
if (t%4 == 0 or t%7 == 0):
print("YES")
else:
print("NO")
else:
print("YES") | Title: Lucky Division
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.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
Output Specification:
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['47\n', '16\n', '78\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | ```python
s = input()
t = int(s)
count = 0
slist = list(s)
arr = ['1', '2', '3', '5', '6', '8', '9', '0']
for i in range(len(slist)):
if slist[i] in arr:
count += 1
if count > 0:
if (t%4 == 0 or t%7 == 0):
print("YES")
else:
print("NO")
else:
print("YES")
``` | 0 |
|
177 | A1 | Good Matrix Elements | PROGRAMMING | 800 | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it.
Help the Smart Beaver count the sum of good elements of the given matrix. | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 points are:
- 1<=≤<=*n*<=≤<=101 | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | 30 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
"output": "756"
},
{
"input": "3\n19 7 16\n12 15 5\n15 15 5",
"output": "109"
},
{
"input": "3\n36 4 33\n11 46 32\n20 49 34",
"output": "265"
},
{
"input": "3\n79 91 74\n33 82 22\n18 28 54",
"output": "481"
},
{
"input": "5\n7 0 8 1 7\n5 1 1 0 4\n4 2 8 1 6\n1 2 3 2 7\n6 0 1 9 6",
"output": "65"
},
{
"input": "5\n27 20 28 11 17\n25 21 1 20 14\n14 22 28 1 6\n1 2 23 2 7\n6 0 1 29 6",
"output": "225"
},
{
"input": "5\n57 50 58 41 17\n25 21 1 50 44\n44 22 28 31 36\n31 32 23 32 37\n6 0 31 59 6",
"output": "495"
},
{
"input": "5\n57 80 28 41 47\n85 51 61 50 74\n44 82 28 31 36\n31 32 23 32 37\n66 60 31 59 6",
"output": "705"
},
{
"input": "5\n13 58 10 17 43\n61 73 100 0 9\n52 38 16 22 96\n11 4 14 67 62\n70 89 7 98 83",
"output": "708"
},
{
"input": "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n0 1 0 1 0\n0 0 0 0 1\n0 0 5 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "5"
},
{
"input": "5\n0 0 0 0 1\n0 1 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "3\n0 0 0\n0 0 0\n0 0 0",
"output": "0"
}
] | 1,561,674,736 | 2,147,483,647 | Python 3 | OK | TESTS1 | 17 | 248 | 0 | n = int(input())
a = [0] * n
res = 0
for i in range(n):
a[i] = list(map(int, input().split()))
res += sum(a[n//2][:n])
t = 0
for _ in range(n//2):
res += (a[t][t] + a[t][n-t-1] + a[t][n//2])
res += (a[n-t-1][t] + a[n-t-1][n-t-1] + a[n-t-1][n//2])
t += 1
print(res) | Title: Good Matrix Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input Specification:
The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 points are:
- 1<=≤<=*n*<=≤<=101
Output Specification:
Print a single integer — the sum of good matrix elements.
Demo Input:
['3\n1 2 3\n4 5 6\n7 8 9\n', '5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n']
Demo Output:
['45\n', '17\n']
Note:
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | ```python
n = int(input())
a = [0] * n
res = 0
for i in range(n):
a[i] = list(map(int, input().split()))
res += sum(a[n//2][:n])
t = 0
for _ in range(n//2):
res += (a[t][t] + a[t][n-t-1] + a[t][n//2])
res += (a[n-t-1][t] + a[n-t-1][n-t-1] + a[n-t-1][n//2])
t += 1
print(res)
``` | 3 |
|
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,591,038,718 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | n=int(input())
a=list(map(int,input().split(" ")))
m=sum(a)
c=0
for x in range(1,6):
if (m+x)%(n+1)!=1:
c+=1
print(c) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
n=int(input())
a=list(map(int,input().split(" ")))
m=sum(a)
c=0
for x in range(1,6):
if (m+x)%(n+1)!=1:
c+=1
print(c)
``` | 3 |
|
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "10000220"
},
{
"input": ".",
"output": "0"
},
{
"input": "-.",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "..",
"output": "00"
},
{
"input": "--.",
"output": "20"
},
{
"input": ".--.",
"output": "020"
},
{
"input": ".-.-..",
"output": "0110"
},
{
"input": "----.-.",
"output": "2201"
},
{
"input": "-..--.-.",
"output": "10201"
},
{
"input": "..--..--.",
"output": "0020020"
},
{
"input": "-.-.---.--..-..-.-.-..-..-.--.",
"output": "112120010111010120"
},
{
"input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.",
"output": "21112220010101011012011011221011"
},
{
"input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------",
"output": "11020111110111222212021020002022111100201121222020012022110010222"
},
{
"input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..",
"output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110"
},
{
"input": ".-..-.-.---.-----.--.---...-.--.-.-....-..",
"output": "01011212212021001201100010"
},
{
"input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..",
"output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210"
},
{
"input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.",
"output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220"
},
{
"input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----",
"output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122"
},
{
"input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..",
"output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110"
},
{
"input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.",
"output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020"
},
{
"input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..",
"output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200"
},
{
"input": "-.---...----...--.--...-.--.----",
"output": "121002200020200012022"
},
{
"input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.",
"output": "202020212012111010201021100001021221200011222112012201012220"
}
] | 1,619,460,617 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | code = input()
i = 0
ans = ""
while i < (len(code)):
if(code[i] == '.'):
ans += '0'
i+=1
else:
if(i < len(code) and code[i+1] == '.'):
ans+= '1'
else:
ans += '2'
i+=2
print(ans)
| Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input Specification:
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output Specification:
Output the decoded ternary number. It can have leading zeroes.
Demo Input:
['.-.--\n', '--.\n', '-..-.--\n']
Demo Output:
['012', '20', '1012']
Note:
none | ```python
code = input()
i = 0
ans = ""
while i < (len(code)):
if(code[i] == '.'):
ans += '0'
i+=1
else:
if(i < len(code) and code[i+1] == '.'):
ans+= '1'
else:
ans += '2'
i+=2
print(ans)
``` | 3.969 |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.
Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "172.7875959474"
},
{
"input": "1\n1000",
"output": "3141592.6535897931"
},
{
"input": "8\n8 1 7 2 6 3 5 4",
"output": "113.0973355292"
},
{
"input": "100\n1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 953 952 951 950 949 948 947 946 945 944 943 942 941 940 939 938 937 936 935 934 933 932 931 930 929 928 927 926 925 924 923 922 921 920 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901",
"output": "298608.3817237098"
},
{
"input": "6\n109 683 214 392 678 10",
"output": "397266.9574170437"
},
{
"input": "2\n151 400",
"output": "431023.3704798660"
},
{
"input": "6\n258 877 696 425 663 934",
"output": "823521.3902487604"
},
{
"input": "9\n635 707 108 234 52 180 910 203 782",
"output": "1100144.9065826489"
},
{
"input": "8\n885 879 891 428 522 176 135 983",
"output": "895488.9947571954"
},
{
"input": "3\n269 918 721",
"output": "1241695.6467754442"
},
{
"input": "7\n920 570 681 428 866 935 795",
"output": "1469640.1849419588"
},
{
"input": "2\n517 331",
"output": "495517.1260654109"
},
{
"input": "2\n457 898",
"output": "1877274.3981158488"
},
{
"input": "8\n872 704 973 612 183 274 739 253",
"output": "1780774.0965755312"
},
{
"input": "74\n652 446 173 457 760 847 670 25 196 775 998 279 656 809 883 148 969 884 792 502 641 800 663 938 362 339 545 608 107 184 834 666 149 458 864 72 199 658 618 987 126 723 806 643 689 958 626 904 944 415 427 498 628 331 636 261 281 276 478 220 513 595 510 384 354 561 469 462 799 449 747 109 903 456",
"output": "1510006.5089479341"
},
{
"input": "76\n986 504 673 158 87 332 124 218 714 235 212 122 878 370 938 81 686 323 386 348 410 468 875 107 50 960 82 834 234 663 651 422 794 633 294 771 945 607 146 913 950 858 297 88 882 725 247 872 645 749 799 987 115 394 380 382 971 429 593 426 652 353 351 233 868 598 889 116 71 376 916 464 414 976 138 903",
"output": "1528494.7817143100"
},
{
"input": "70\n12 347 748 962 514 686 192 159 990 4 10 788 602 542 946 215 523 727 799 717 955 796 529 465 897 103 181 515 495 153 710 179 747 145 16 585 943 998 923 708 156 399 770 547 775 285 9 68 713 722 570 143 913 416 663 624 925 218 64 237 797 138 942 213 188 818 780 840 480 758",
"output": "1741821.4892636713"
},
{
"input": "26\n656 508 45 189 561 366 96 486 547 386 703 570 780 689 264 26 11 74 466 76 421 48 982 886 215 650",
"output": "1818821.9252031571"
},
{
"input": "52\n270 658 808 249 293 707 700 78 791 167 92 772 807 502 830 991 945 102 968 376 556 578 326 980 688 368 280 853 646 256 666 638 424 737 321 996 925 405 199 680 953 541 716 481 727 143 577 919 892 355 346 298",
"output": "1272941.9273080483"
},
{
"input": "77\n482 532 200 748 692 697 171 863 586 547 301 149 326 812 147 698 303 691 527 805 681 387 619 947 598 453 167 799 840 508 893 688 643 974 998 341 804 230 538 669 271 404 477 759 943 596 949 235 880 160 151 660 832 82 969 539 708 889 258 81 224 655 790 144 462 582 646 256 445 52 456 920 67 819 631 484 534",
"output": "2045673.1891262225"
},
{
"input": "27\n167 464 924 575 775 97 944 390 297 315 668 296 533 829 851 406 702 366 848 512 71 197 321 900 544 529 116",
"output": "1573959.9105970615"
},
{
"input": "38\n488 830 887 566 720 267 583 102 65 200 884 220 263 858 510 481 316 804 754 568 412 166 374 869 356 977 145 421 500 58 664 252 745 70 381 927 670 772",
"output": "1479184.3434235646"
},
{
"input": "64\n591 387 732 260 840 397 563 136 571 876 831 953 799 493 579 13 559 872 53 678 256 232 969 993 847 14 837 365 547 997 604 199 834 529 306 443 739 49 19 276 343 835 904 588 900 870 439 576 975 955 518 117 131 347 800 83 432 882 869 709 32 950 314 450",
"output": "1258248.6984672088"
},
{
"input": "37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637",
"output": "1495219.0323274869"
},
{
"input": "97\n768 569 306 968 437 779 227 561 412 60 44 807 234 645 169 858 580 396 343 145 842 723 416 80 456 247 81 150 297 116 760 964 312 558 101 850 549 650 299 868 121 435 579 705 118 424 302 812 970 397 659 565 916 183 933 459 6 593 518 717 326 305 744 470 75 981 824 221 294 324 194 293 251 446 481 215 338 861 528 829 921 945 540 89 450 178 24 460 990 392 148 219 934 615 932 340 937",
"output": "1577239.7333274092"
},
{
"input": "94\n145 703 874 425 277 652 239 496 458 658 339 842 564 699 893 352 625 980 432 121 798 872 499 859 850 721 414 825 543 843 304 111 342 45 219 311 50 748 465 902 781 822 504 985 919 656 280 310 917 438 464 527 491 713 906 329 635 777 223 810 501 535 156 252 806 112 971 719 103 443 165 98 579 554 244 996 221 560 301 51 977 422 314 858 528 772 448 626 185 194 536 66 577 677",
"output": "1624269.3753516484"
},
{
"input": "97\n976 166 649 81 611 927 480 231 998 711 874 91 969 521 531 414 993 790 317 981 9 261 437 332 173 573 904 777 882 990 658 878 965 64 870 896 271 732 431 53 761 943 418 602 708 949 930 130 512 240 363 458 673 319 131 784 224 48 919 126 208 212 911 59 677 535 450 273 479 423 79 807 336 18 72 290 724 28 123 605 287 228 350 897 250 392 885 655 746 417 643 114 813 378 355 635 905",
"output": "1615601.7212203942"
},
{
"input": "91\n493 996 842 9 748 178 1 807 841 519 796 998 84 670 778 143 707 208 165 893 154 943 336 150 761 881 434 112 833 55 412 682 552 945 758 189 209 600 354 325 440 844 410 20 136 665 88 791 688 17 539 821 133 236 94 606 483 446 429 60 960 476 915 134 137 852 754 908 276 482 117 252 297 903 981 203 829 811 471 135 188 667 710 393 370 302 874 872 551 457 692",
"output": "1806742.5014501044"
},
{
"input": "95\n936 736 17 967 229 607 589 291 242 244 29 698 800 566 630 667 90 416 11 94 812 838 668 520 678 111 490 823 199 973 681 676 683 721 262 896 682 713 402 691 874 44 95 704 56 322 822 887 639 433 406 35 988 61 176 496 501 947 440 384 372 959 577 370 754 802 1 945 427 116 746 408 308 391 397 730 493 183 203 871 831 862 461 565 310 344 504 378 785 137 279 123 475 138 415",
"output": "1611115.5269110680"
},
{
"input": "90\n643 197 42 218 582 27 66 704 195 445 641 675 285 639 503 686 242 327 57 955 848 287 819 992 756 749 363 48 648 736 580 117 752 921 923 372 114 313 202 337 64 497 399 25 883 331 24 871 917 8 517 486 323 529 325 92 891 406 864 402 263 773 931 253 625 31 17 271 140 131 232 586 893 525 846 54 294 562 600 801 214 55 768 683 389 738 314 284 328 804",
"output": "1569819.2914796301"
},
{
"input": "98\n29 211 984 75 333 96 840 21 352 168 332 433 130 944 215 210 620 442 363 877 91 491 513 955 53 82 351 19 998 706 702 738 770 453 344 117 893 590 723 662 757 16 87 546 312 669 568 931 224 374 927 225 751 962 651 587 361 250 256 240 282 600 95 64 384 589 813 783 39 918 412 648 506 283 886 926 443 173 946 241 310 33 622 565 261 360 547 339 943 367 354 25 479 743 385 485 896 741",
"output": "2042921.1539616778"
},
{
"input": "93\n957 395 826 67 185 4 455 880 683 654 463 84 258 878 553 592 124 585 9 133 20 609 43 452 725 125 801 537 700 685 771 155 566 376 19 690 383 352 174 208 177 416 304 1000 533 481 87 509 358 233 681 22 507 659 36 859 952 259 138 271 594 779 576 782 119 69 608 758 283 616 640 523 710 751 34 106 774 92 874 568 864 660 998 992 474 679 180 409 15 297 990 689 501",
"output": "1310703.8710041976"
},
{
"input": "97\n70 611 20 30 904 636 583 262 255 501 604 660 212 128 199 138 545 576 506 528 12 410 77 888 783 972 431 188 338 485 148 793 907 678 281 922 976 680 252 724 253 920 177 361 721 798 960 572 99 622 712 466 608 49 612 345 266 751 63 594 40 695 532 789 520 930 825 929 48 59 405 135 109 735 508 186 495 772 375 587 201 324 447 610 230 947 855 318 856 956 313 810 931 175 668 183 688",
"output": "1686117.9099228707"
},
{
"input": "96\n292 235 391 180 840 172 218 997 166 287 329 20 886 325 400 471 182 356 448 337 417 319 58 106 366 764 393 614 90 831 924 314 667 532 64 874 3 434 350 352 733 795 78 640 967 63 47 879 635 272 145 569 468 792 153 761 770 878 281 467 209 208 298 37 700 18 334 93 5 750 412 779 523 517 360 649 447 328 311 653 57 578 767 460 647 663 50 670 151 13 511 580 625 907 227 89",
"output": "1419726.5608617242"
},
{
"input": "100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 639 638 260 419 8 142 403 298 204 169 887 388 241 983 885 267 643 943 417 237 452 562 6 839 149 742 832 896 100 831 712 754 679 743 135 222 445 680 210 955 220 63 960 487 514 824 481 584 441 997 795 290 10 45 510 678 844 503 407 945 850 84 858 934 500 320 936 663 736 592 161 670 606 465 864 969 293 863 868 393 899 744",
"output": "1556458.0979239127"
},
{
"input": "100\n321 200 758 415 190 710 920 992 873 898 814 259 359 66 971 210 838 545 663 652 684 277 36 756 963 459 335 484 462 982 532 423 131 703 307 229 391 938 253 847 542 975 635 928 220 980 222 567 557 181 366 824 900 180 107 979 112 564 525 413 300 422 876 615 737 343 902 8 654 628 469 913 967 785 893 314 909 215 912 262 20 709 363 915 997 954 986 454 596 124 74 159 660 550 787 418 895 786 293 50",
"output": "1775109.8050211088"
},
{
"input": "100\n859 113 290 762 701 63 188 431 810 485 671 673 99 658 194 227 511 435 941 212 551 124 89 222 42 321 657 815 898 171 216 482 707 567 724 491 414 942 820 351 48 653 685 312 586 24 20 627 602 498 533 173 463 262 621 466 119 299 580 964 510 987 40 698 521 998 847 651 746 215 808 563 785 837 631 772 404 923 682 244 232 214 390 350 968 771 517 900 70 543 934 554 681 368 642 575 891 728 478 317",
"output": "1447969.4788174964"
},
{
"input": "100\n941 283 349 457 52 837 299 284 796 305 893 624 101 972 738 204 121 70 17 704 836 791 95 111 162 952 472 724 733 580 878 177 705 804 11 211 463 417 288 409 410 485 896 755 921 267 164 656 505 765 539 439 535 19 991 689 220 474 114 944 884 144 926 849 486 566 117 35 749 499 797 303 362 905 690 890 976 66 590 183 234 683 39 297 769 787 376 541 571 759 495 200 261 352 73 493 831 442 273 339",
"output": "1597889.4218394549"
},
{
"input": "100\n110 868 147 888 291 282 916 542 917 337 235 595 498 621 814 249 261 713 445 666 142 275 319 49 900 543 333 606 487 670 620 769 852 258 230 867 603 491 714 839 879 37 21 74 590 190 397 506 499 967 152 862 200 107 145 23 614 167 857 475 79 598 270 906 626 116 89 59 651 846 723 201 50 699 522 408 634 132 226 414 824 764 513 586 526 238 556 162 667 173 684 415 527 743 10 442 552 274 350 822",
"output": "1567230.6191330721"
},
{
"input": "100\n901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000",
"output": "298608.3817237098"
}
] | 1,368,135,612 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 78 | 0 | from math import pi
input()
lst = [int(x) for x in input().split()]
lst.sort(reverse=True)
area = 0
l = len(lst)
for i in range(0, l, 2):
area += lst[i]*lst[i]
for i in range(1, l, 2):
area -= lst[i]*lst[i]
print(area*pi)
| Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.
Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different.
Output Specification:
Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4.
Demo Input:
['1\n1\n', '3\n1 4 2\n']
Demo Output:
['3.1415926536\n', '40.8407044967\n']
Note:
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π | ```python
from math import pi
input()
lst = [int(x) for x in input().split()]
lst.sort(reverse=True)
area = 0
l = len(lst)
for i in range(0, l, 2):
area += lst[i]*lst[i]
for i in range(1, l, 2):
area -= lst[i]*lst[i]
print(area*pi)
``` | 3 |
|
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"input": "24 22 9235",
"output": "34"
},
{
"input": "74 8 417",
"output": "1"
},
{
"input": "972 1 203",
"output": "0"
},
{
"input": "550 1 754",
"output": "1"
},
{
"input": "860 1 884",
"output": "1"
},
{
"input": "358 2 809",
"output": "2"
},
{
"input": "33 27 216",
"output": "0"
},
{
"input": "2940 1 9311",
"output": "3"
},
{
"input": "4624 1 1953",
"output": "0"
},
{
"input": "2696 2 7345",
"output": "2"
},
{
"input": "3443 2 6701",
"output": "0"
},
{
"input": "3 613 2275",
"output": "1"
},
{
"input": "1 10000 10000",
"output": "1"
},
{
"input": "10000 1 10000",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1 10000",
"output": "10000"
},
{
"input": "34 27 10000",
"output": "10"
},
{
"input": "2 2 9999",
"output": "4999"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "6 4 36",
"output": "3"
},
{
"input": "33 6 3005",
"output": "45"
},
{
"input": "5 1 20",
"output": "4"
},
{
"input": "1 2 10",
"output": "5"
},
{
"input": "2 1 100",
"output": "50"
},
{
"input": "10 20 10000",
"output": "500"
},
{
"input": "8 12 12",
"output": "0"
}
] | 1,523,354,212 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 374 | 30,822,400 | from fractions import gcd
n, m, z = [int(i) for i in input().split()]
c = int((n / gcd(n, m)) * m)
print(z // c) | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
Input Specification:
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Output Specification:
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
Demo Input:
['1 1 10\n', '1 2 5\n', '2 3 9\n']
Demo Output:
['10\n', '2\n', '1\n']
Note:
Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | ```python
from fractions import gcd
n, m, z = [int(i) for i in input().split()]
c = int((n / gcd(n, m)) * m)
print(z // c)
``` | 3 |
|
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,693,674,225 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | import math
def calculate_flagstones(n, m, a):
length_flagstones = math.ceil(n / a)
width_flagstones = math.ceil(m / a)
total_flagstones = length_flagstones * width_flagstones
return total_flagstones
n, m, a = map(int, input().split())
print(calculate_flagstones(n, m, a)) | 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 math
def calculate_flagstones(n, m, a):
length_flagstones = math.ceil(n / a)
width_flagstones = math.ceil(m / a)
total_flagstones = length_flagstones * width_flagstones
return total_flagstones
n, m, a = map(int, input().split())
print(calculate_flagstones(n, m, a))
``` | 3.9845 |
331 | C1 | The Great Julya Calendar | PROGRAMMING | 1,100 | [
"dp"
] | null | null | Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!"
Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero. | The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3). | Print a single integer — the minimum number of subtractions that turns the magic number to a zero. | [
"24\n"
] | [
"5"
] | In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: | 20 | [
{
"input": "24",
"output": "5"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "31",
"output": "6"
},
{
"input": "701",
"output": "116"
},
{
"input": "222",
"output": "39"
},
{
"input": "156",
"output": "28"
},
{
"input": "12343",
"output": "1778"
},
{
"input": "7984",
"output": "1178"
},
{
"input": "1000000",
"output": "128207"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "11",
"output": "3"
},
{
"input": "77",
"output": "14"
},
{
"input": "216",
"output": "37"
},
{
"input": "1468",
"output": "233"
},
{
"input": "1995",
"output": "305"
},
{
"input": "11010",
"output": "1568"
},
{
"input": "47320",
"output": "6746"
},
{
"input": "258634",
"output": "35024"
}
] | 1,580,534,097 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS1 | 12 | 2,000 | 11,673,600 | n=int(input())
def ispres(x,num):
dig={i:0 for i in range(10)}
m=num
while m>0:
d=m%10
dig[d]+=1
m=m//10
if dig[x]!=0:
return True
return False
dp=[999999 for _ in range(n+1)]
for j in range(1,10):
if ispres(j,n):
dp[n-j]=1
for i in range(n,-1,-1):
for k in range(1,10):
#print(i+k,ispres(k,i+k))
if i+k<=n and ispres(k,i+k):
dp[i]=min(dp[i],dp[i+k]+1)
if dp[0]==999999:
print(0)
exit(0)
print(dp[0])
| Title: The Great Julya Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!"
Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.
Input Specification:
The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3).
Output Specification:
Print a single integer — the minimum number of subtractions that turns the magic number to a zero.
Demo Input:
['24\n']
Demo Output:
['5']
Note:
In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: | ```python
n=int(input())
def ispres(x,num):
dig={i:0 for i in range(10)}
m=num
while m>0:
d=m%10
dig[d]+=1
m=m//10
if dig[x]!=0:
return True
return False
dp=[999999 for _ in range(n+1)]
for j in range(1,10):
if ispres(j,n):
dp[n-j]=1
for i in range(n,-1,-1):
for k in range(1,10):
#print(i+k,ispres(k,i+k))
if i+k<=n and ispres(k,i+k):
dp[i]=min(dp[i],dp[i+k]+1)
if dp[0]==999999:
print(0)
exit(0)
print(dp[0])
``` | 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,673,975,847 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 124 | 614,400 | import fileinput
import operator
from itertools import islice, starmap
def main() -> None:
"""Main function"""
with fileinput.input() as f:
n = int(next(f))
v = (0, 0, 0)
for line in islice(f, n):
w = tuple(map(int, line.split()))
v = tuple(starmap(operator.add, zip(v, w)))
print("YES" if v == (0, 0, 0) else "NO")
if __name__ == "__main__":
main() | 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
import fileinput
import operator
from itertools import islice, starmap
def main() -> None:
"""Main function"""
with fileinput.input() as f:
n = int(next(f))
v = (0, 0, 0)
for line in islice(f, n):
w = tuple(map(int, line.split()))
v = tuple(starmap(operator.add, zip(v, w)))
print("YES" if v == (0, 0, 0) else "NO")
if __name__ == "__main__":
main()
``` | 3.967856 |
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,655,206,909 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | a,b = map(int,input().split())
w1 = 0
d = 0
w2 = 0
for i in range(1,7):
if abs(a-i) < abs(b-i):
w1 += 1
elif a-i == b-i:
d += 1
else:
w2 += 1
print(w1,d,w2) | 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
a,b = map(int,input().split())
w1 = 0
d = 0
w2 = 0
for i in range(1,7):
if abs(a-i) < abs(b-i):
w1 += 1
elif a-i == b-i:
d += 1
else:
w2 += 1
print(w1,d,w2)
``` | 0 |
|
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR",
"output": "67"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURUUUUUUUUUUUUUUUUUUUUU",
"output": "99"
},
{
"input": "3\nRUR",
"output": "2"
},
{
"input": "1\nR",
"output": "1"
},
{
"input": "5\nRURUU",
"output": "3"
},
{
"input": "1\nU",
"output": "1"
},
{
"input": "2\nUR",
"output": "1"
},
{
"input": "23\nUUUUUUUUUUUUUUUUUUUUUUU",
"output": "23"
}
] | 1,638,583,178 | 2,147,483,647 | PyPy 3 | OK | TESTS | 11 | 78 | 0 | n=int(input())
s=input()
c=[]
for i in range(n):
c.append(s[i])
for i in range(n-1):
if c[i]=="U" and c[i+1]=="R":
c[i]="D"
c[i+1]="D"
if c[i]=="R" and c[i+1]=="U":
c[i]="D"
c[i+1]="D"
print(n-((c.count("D"))//2))
| Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left.
Your problem is to print the minimum possible length of the sequence of moves after the replacements.
Input Specification:
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Output Specification:
Print the minimum possible length of the sequence of moves after all replacements are done.
Demo Input:
['5\nRUURU\n', '17\nUUURRRRRUUURURUUU\n']
Demo Output:
['3\n', '13\n']
Note:
In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | ```python
n=int(input())
s=input()
c=[]
for i in range(n):
c.append(s[i])
for i in range(n-1):
if c[i]=="U" and c[i+1]=="R":
c[i]="D"
c[i+1]="D"
if c[i]=="R" and c[i+1]=="U":
c[i]="D"
c[i+1]="D"
print(n-((c.count("D"))//2))
``` | 3 |
|
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task. | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement. | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
},
{
"input": "12 17\n10 19\n13 16",
"output": "-1"
},
{
"input": "11 11\n17 5\n12 10",
"output": "9 2\n8 3"
},
{
"input": "12 11\n11 12\n16 7",
"output": "-1"
},
{
"input": "5 9\n7 7\n8 6",
"output": "3 2\n4 5"
},
{
"input": "10 7\n4 13\n11 6",
"output": "-1"
},
{
"input": "18 10\n16 12\n12 16",
"output": "-1"
},
{
"input": "13 6\n10 9\n6 13",
"output": "-1"
},
{
"input": "14 16\n16 14\n18 12",
"output": "-1"
},
{
"input": "16 10\n16 10\n12 14",
"output": "-1"
},
{
"input": "11 9\n12 8\n11 9",
"output": "-1"
},
{
"input": "5 14\n10 9\n10 9",
"output": "-1"
},
{
"input": "2 4\n1 5\n3 3",
"output": "-1"
},
{
"input": "17 16\n14 19\n18 15",
"output": "-1"
},
{
"input": "12 12\n14 10\n16 8",
"output": "9 3\n5 7"
},
{
"input": "15 11\n16 10\n9 17",
"output": "7 8\n9 2"
},
{
"input": "8 10\n9 9\n13 5",
"output": "6 2\n3 7"
},
{
"input": "13 7\n10 10\n5 15",
"output": "4 9\n6 1"
},
{
"input": "14 11\n9 16\n16 9",
"output": "-1"
},
{
"input": "12 8\n14 6\n8 12",
"output": "-1"
},
{
"input": "10 6\n6 10\n4 12",
"output": "-1"
},
{
"input": "10 8\n10 8\n4 14",
"output": "-1"
},
{
"input": "14 13\n9 18\n14 13",
"output": "-1"
},
{
"input": "9 14\n8 15\n8 15",
"output": "-1"
},
{
"input": "3 8\n2 9\n6 5",
"output": "-1"
},
{
"input": "14 17\n18 13\n15 16",
"output": "-1"
},
{
"input": "16 14\n15 15\n17 13",
"output": "9 7\n6 8"
},
{
"input": "14 11\n16 9\n13 12",
"output": "9 5\n7 4"
},
{
"input": "13 10\n11 12\n7 16",
"output": "4 9\n7 3"
},
{
"input": "14 8\n11 11\n13 9",
"output": "8 6\n3 5"
},
{
"input": "12 11\n13 10\n10 13",
"output": "-1"
},
{
"input": "6 5\n2 9\n5 6",
"output": "-1"
},
{
"input": "7 8\n8 7\n12 3",
"output": "-1"
},
{
"input": "7 11\n7 11\n6 12",
"output": "-1"
},
{
"input": "8 5\n11 2\n8 5",
"output": "-1"
},
{
"input": "10 16\n14 12\n14 12",
"output": "-1"
},
{
"input": "7 9\n4 12\n5 11",
"output": "-1"
},
{
"input": "11 13\n19 5\n12 12",
"output": "-1"
},
{
"input": "8 12\n5 15\n11 9",
"output": "2 6\n3 9"
},
{
"input": "16 5\n13 8\n10 11",
"output": "9 7\n4 1"
},
{
"input": "3 14\n8 9\n10 7",
"output": "2 1\n6 8"
},
{
"input": "12 14\n11 15\n9 17",
"output": "3 9\n8 6"
},
{
"input": "13 7\n9 11\n14 6",
"output": "8 5\n1 6"
},
{
"input": "13 8\n15 6\n11 10",
"output": "9 4\n6 2"
},
{
"input": "9 6\n5 10\n3 12",
"output": "1 8\n4 2"
},
{
"input": "12 7\n5 14\n8 11",
"output": "3 9\n2 5"
},
{
"input": "9 12\n3 17\n10 10",
"output": "-1"
},
{
"input": "3 8\n4 6\n5 5",
"output": "-1"
}
] | 1,682,349,806 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 92 | 0 | row1 , row2 = map(int,input().split())
col1 , col2 = map(int,input().split())
dia1 , dia2 = map(int,input().split())
message=1
b1 , b2 = 0,0
b3 , b4 = 0,0
for a in range(1,10):
b1 = a
for b in range(1,10):
b2 = b
for c in range(1,10):
b3 = c
for d in range(1,10):
b4 = d
if b1!=b2 and b1!=b3 and b1!=b4 and b2!=b3 and b2!=b4 and b3!=b4:
if b1+b4==dia1 and b1+b2==row1 and b1+b3==col1 and b2+b4==col2 and b2+b3==dia2 and b3+b4==row2:
print(b1,b2)
print(b3,b4)
message=0
if message==1:
print(-1) | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input Specification:
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
Output Specification:
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Demo Input:
['3 7\n4 6\n5 5\n', '11 10\n13 8\n5 16\n', '1 2\n3 4\n5 6\n', '10 10\n10 10\n10 10\n']
Demo Output:
['1 2\n3 4\n', '4 7\n9 1\n', '-1\n', '-1\n']
Note:
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | ```python
row1 , row2 = map(int,input().split())
col1 , col2 = map(int,input().split())
dia1 , dia2 = map(int,input().split())
message=1
b1 , b2 = 0,0
b3 , b4 = 0,0
for a in range(1,10):
b1 = a
for b in range(1,10):
b2 = b
for c in range(1,10):
b3 = c
for d in range(1,10):
b4 = d
if b1!=b2 and b1!=b3 and b1!=b4 and b2!=b3 and b2!=b4 and b3!=b4:
if b1+b4==dia1 and b1+b2==row1 and b1+b3==col1 and b2+b4==col2 and b2+b3==dia2 and b3+b4==row2:
print(b1,b2)
print(b3,b4)
message=0
if message==1:
print(-1)
``` | 3 |
|
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*. | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
},
{
"input": "12\n4773\n325\n377\n192\n780\n881\n816\n839\n223\n215\n125\n952\n8",
"output": "7"
},
{
"input": "15\n7758\n182\n272\n763\n910\n24\n359\n583\n890\n735\n819\n66\n992\n440\n496\n227",
"output": "15"
},
{
"input": "30\n70\n6\n2\n10\n4\n7\n10\n5\n1\n8\n10\n4\n3\n5\n9\n3\n6\n6\n4\n2\n6\n5\n10\n1\n9\n7\n2\n1\n10\n7\n5",
"output": "8"
},
{
"input": "40\n15705\n702\n722\n105\n873\n417\n477\n794\n300\n869\n496\n572\n232\n456\n298\n473\n584\n486\n713\n934\n121\n303\n956\n934\n840\n358\n201\n861\n497\n131\n312\n957\n96\n914\n509\n60\n300\n722\n658\n820\n103",
"output": "21"
},
{
"input": "50\n18239\n300\n151\n770\n9\n200\n52\n247\n753\n523\n263\n744\n463\n540\n244\n608\n569\n771\n32\n425\n777\n624\n761\n628\n124\n405\n396\n726\n626\n679\n237\n229\n49\n512\n18\n671\n290\n768\n632\n739\n18\n136\n413\n117\n83\n413\n452\n767\n664\n203\n404",
"output": "31"
},
{
"input": "70\n149\n5\n3\n3\n4\n6\n1\n2\n9\n8\n3\n1\n8\n4\n4\n3\n6\n10\n7\n1\n10\n8\n4\n9\n3\n8\n3\n2\n5\n1\n8\n6\n9\n10\n4\n8\n6\n9\n9\n9\n3\n4\n2\n2\n5\n8\n9\n1\n10\n3\n4\n3\n1\n9\n3\n5\n1\n3\n7\n6\n9\n8\n9\n1\n7\n4\n4\n2\n3\n5\n7",
"output": "17"
},
{
"input": "70\n2731\n26\n75\n86\n94\n37\n25\n32\n35\n92\n1\n51\n73\n53\n66\n16\n80\n15\n81\n100\n87\n55\n48\n30\n71\n39\n87\n77\n25\n70\n22\n75\n23\n97\n16\n75\n95\n61\n61\n28\n10\n78\n54\n80\n51\n25\n24\n90\n58\n4\n77\n40\n54\n53\n47\n62\n30\n38\n71\n97\n71\n60\n58\n1\n21\n15\n55\n99\n34\n88\n99",
"output": "35"
},
{
"input": "70\n28625\n34\n132\n181\n232\n593\n413\n862\n887\n808\n18\n35\n89\n356\n640\n339\n280\n975\n82\n345\n398\n948\n372\n91\n755\n75\n153\n948\n603\n35\n694\n722\n293\n363\n884\n264\n813\n175\n169\n646\n138\n449\n488\n828\n417\n134\n84\n763\n288\n845\n801\n556\n972\n332\n564\n934\n699\n842\n942\n644\n203\n406\n140\n37\n9\n423\n546\n675\n491\n113\n587",
"output": "45"
},
{
"input": "80\n248\n3\n9\n4\n5\n10\n7\n2\n6\n2\n2\n8\n2\n1\n3\n7\n9\n2\n8\n4\n4\n8\n5\n4\n4\n10\n2\n1\n4\n8\n4\n10\n1\n2\n10\n2\n3\n3\n1\n1\n8\n9\n5\n10\n2\n8\n10\n5\n3\n6\n1\n7\n8\n9\n10\n5\n10\n10\n2\n10\n1\n2\n4\n1\n9\n4\n7\n10\n8\n5\n8\n1\n4\n2\n2\n3\n9\n9\n9\n10\n6",
"output": "27"
},
{
"input": "80\n2993\n18\n14\n73\n38\n14\n73\n77\n18\n81\n6\n96\n65\n77\n86\n76\n8\n16\n81\n83\n83\n34\n69\n58\n15\n19\n1\n16\n57\n95\n35\n5\n49\n8\n15\n47\n84\n99\n94\n93\n55\n43\n47\n51\n61\n57\n13\n7\n92\n14\n4\n83\n100\n60\n75\n41\n95\n74\n40\n1\n4\n95\n68\n59\n65\n15\n15\n75\n85\n46\n77\n26\n30\n51\n64\n75\n40\n22\n88\n68\n24",
"output": "38"
},
{
"input": "80\n37947\n117\n569\n702\n272\n573\n629\n90\n337\n673\n589\n576\n205\n11\n284\n645\n719\n777\n271\n567\n466\n251\n402\n3\n97\n288\n699\n208\n173\n530\n782\n266\n395\n957\n159\n463\n43\n316\n603\n197\n386\n132\n799\n778\n905\n784\n71\n851\n963\n883\n705\n454\n275\n425\n727\n223\n4\n870\n833\n431\n463\n85\n505\n800\n41\n954\n981\n242\n578\n336\n48\n858\n702\n349\n929\n646\n528\n993\n506\n274\n227",
"output": "70"
},
{
"input": "90\n413\n5\n8\n10\n7\n5\n7\n5\n7\n1\n7\n8\n4\n3\n9\n4\n1\n10\n3\n1\n10\n9\n3\n1\n8\n4\n7\n5\n2\n9\n3\n10\n10\n3\n6\n3\n3\n10\n7\n5\n1\n1\n2\n4\n8\n2\n5\n5\n3\n9\n5\n5\n3\n10\n2\n3\n8\n5\n9\n1\n3\n6\n5\n9\n2\n3\n7\n10\n3\n4\n4\n1\n5\n9\n2\n6\n9\n1\n1\n9\n9\n7\n7\n7\n8\n4\n5\n3\n4\n6\n9",
"output": "59"
},
{
"input": "90\n4226\n33\n43\n83\n46\n75\n14\n88\n36\n8\n25\n47\n4\n96\n19\n33\n49\n65\n17\n59\n72\n1\n55\n94\n92\n27\n33\n39\n14\n62\n79\n12\n89\n22\n86\n13\n19\n77\n53\n96\n74\n24\n25\n17\n64\n71\n81\n87\n52\n72\n55\n49\n74\n36\n65\n86\n91\n33\n61\n97\n38\n87\n61\n14\n73\n95\n43\n67\n42\n67\n22\n12\n62\n32\n96\n24\n49\n82\n46\n89\n36\n75\n91\n11\n10\n9\n33\n86\n28\n75\n39",
"output": "64"
},
{
"input": "90\n40579\n448\n977\n607\n745\n268\n826\n479\n59\n330\n609\n43\n301\n970\n726\n172\n632\n600\n181\n712\n195\n491\n312\n849\n722\n679\n682\n780\n131\n404\n293\n387\n567\n660\n54\n339\n111\n833\n612\n911\n869\n356\n884\n635\n126\n639\n712\n473\n663\n773\n435\n32\n973\n484\n662\n464\n699\n274\n919\n95\n904\n253\n589\n543\n454\n250\n349\n237\n829\n511\n536\n36\n45\n152\n626\n384\n199\n877\n941\n84\n781\n115\n20\n52\n726\n751\n920\n291\n571\n6\n199",
"output": "64"
},
{
"input": "100\n66\n7\n9\n10\n5\n2\n8\n6\n5\n4\n10\n10\n6\n5\n2\n2\n1\n1\n5\n8\n7\n8\n10\n5\n6\n6\n5\n9\n9\n6\n3\n8\n7\n10\n5\n9\n6\n7\n3\n5\n8\n6\n8\n9\n1\n1\n1\n2\n4\n5\n5\n1\n1\n2\n6\n7\n1\n5\n8\n7\n2\n1\n7\n10\n9\n10\n2\n4\n10\n4\n10\n10\n5\n3\n9\n1\n2\n1\n10\n5\n1\n7\n4\n4\n5\n7\n6\n10\n4\n7\n3\n4\n3\n6\n2\n5\n2\n4\n9\n5\n3",
"output": "7"
},
{
"input": "100\n4862\n20\n47\n85\n47\n76\n38\n48\n93\n91\n81\n31\n51\n23\n60\n59\n3\n73\n72\n57\n67\n54\n9\n42\n5\n32\n46\n72\n79\n95\n61\n79\n88\n33\n52\n97\n10\n3\n20\n79\n82\n93\n90\n38\n80\n18\n21\n43\n60\n73\n34\n75\n65\n10\n84\n100\n29\n94\n56\n22\n59\n95\n46\n22\n57\n69\n67\n90\n11\n10\n61\n27\n2\n48\n69\n86\n91\n69\n76\n36\n71\n18\n54\n90\n74\n69\n50\n46\n8\n5\n41\n96\n5\n14\n55\n85\n39\n6\n79\n75\n87",
"output": "70"
},
{
"input": "100\n45570\n14\n881\n678\n687\n993\n413\n760\n451\n426\n787\n503\n343\n234\n530\n294\n725\n941\n524\n574\n441\n798\n399\n360\n609\n376\n525\n229\n995\n478\n347\n47\n23\n468\n525\n749\n601\n235\n89\n995\n489\n1\n239\n415\n122\n671\n128\n357\n886\n401\n964\n212\n968\n210\n130\n871\n360\n661\n844\n414\n187\n21\n824\n266\n713\n126\n496\n916\n37\n193\n755\n894\n641\n300\n170\n176\n383\n488\n627\n61\n897\n33\n242\n419\n881\n698\n107\n391\n418\n774\n905\n87\n5\n896\n835\n318\n373\n916\n393\n91\n460",
"output": "78"
},
{
"input": "100\n522\n1\n5\n2\n4\n2\n6\n3\n4\n2\n10\n10\n6\n7\n9\n7\n1\n7\n2\n5\n3\n1\n5\n2\n3\n5\n1\n7\n10\n10\n4\n4\n10\n9\n10\n6\n2\n8\n2\n6\n10\n9\n2\n7\n5\n9\n4\n6\n10\n7\n3\n1\n1\n9\n5\n10\n9\n2\n8\n3\n7\n5\n4\n7\n5\n9\n10\n6\n2\n9\n2\n5\n10\n1\n7\n7\n10\n5\n6\n2\n9\n4\n7\n10\n10\n8\n3\n4\n9\n3\n6\n9\n10\n2\n9\n9\n3\n4\n1\n10\n2",
"output": "74"
},
{
"input": "100\n32294\n414\n116\n131\n649\n130\n476\n630\n605\n213\n117\n757\n42\n109\n85\n127\n635\n629\n994\n410\n764\n204\n161\n231\n577\n116\n936\n537\n565\n571\n317\n722\n819\n229\n284\n487\n649\n304\n628\n727\n816\n854\n91\n111\n549\n87\n374\n417\n3\n868\n882\n168\n743\n77\n534\n781\n75\n956\n910\n734\n507\n568\n802\n946\n891\n659\n116\n678\n375\n380\n430\n627\n873\n350\n930\n285\n6\n183\n96\n517\n81\n794\n235\n360\n551\n6\n28\n799\n226\n996\n894\n981\n551\n60\n40\n460\n479\n161\n318\n952\n433",
"output": "42"
},
{
"input": "100\n178\n71\n23\n84\n98\n8\n14\n4\n42\n56\n83\n87\n28\n22\n32\n50\n5\n96\n90\n1\n59\n74\n56\n96\n77\n88\n71\n38\n62\n36\n85\n1\n97\n98\n98\n32\n99\n42\n6\n81\n20\n49\n57\n71\n66\n9\n45\n41\n29\n28\n32\n68\n38\n29\n35\n29\n19\n27\n76\n85\n68\n68\n41\n32\n78\n72\n38\n19\n55\n83\n83\n25\n46\n62\n48\n26\n53\n14\n39\n31\n94\n84\n22\n39\n34\n96\n63\n37\n42\n6\n78\n76\n64\n16\n26\n6\n79\n53\n24\n29\n63",
"output": "2"
},
{
"input": "100\n885\n226\n266\n321\n72\n719\n29\n121\n533\n85\n672\n225\n830\n783\n822\n30\n791\n618\n166\n487\n922\n434\n814\n473\n5\n741\n947\n910\n305\n998\n49\n945\n588\n868\n809\n803\n168\n280\n614\n434\n634\n538\n591\n437\n540\n445\n313\n177\n171\n799\n778\n55\n617\n554\n583\n611\n12\n94\n599\n182\n765\n556\n965\n542\n35\n460\n177\n313\n485\n744\n384\n21\n52\n879\n792\n411\n614\n811\n565\n695\n428\n587\n631\n794\n461\n258\n193\n696\n936\n646\n756\n267\n55\n690\n730\n742\n734\n988\n235\n762\n440",
"output": "1"
},
{
"input": "100\n29\n9\n2\n10\n8\n6\n7\n7\n3\n3\n10\n4\n5\n2\n5\n1\n6\n3\n2\n5\n10\n10\n9\n1\n4\n5\n2\n2\n3\n1\n2\n2\n9\n6\n9\n7\n8\n8\n1\n5\n5\n3\n1\n5\n6\n1\n9\n2\n3\n8\n10\n8\n3\n2\n7\n1\n2\n1\n2\n8\n10\n5\n2\n3\n1\n10\n7\n1\n7\n4\n9\n6\n6\n4\n7\n1\n2\n7\n7\n9\n9\n7\n10\n4\n10\n8\n2\n1\n5\n5\n10\n5\n8\n1\n5\n6\n5\n1\n5\n6\n8",
"output": "3"
},
{
"input": "100\n644\n94\n69\n43\n36\n54\n93\n30\n74\n56\n95\n70\n49\n11\n36\n57\n30\n59\n3\n52\n59\n90\n82\n39\n67\n32\n8\n80\n64\n8\n65\n51\n48\n89\n90\n35\n4\n54\n66\n96\n68\n90\n30\n4\n13\n97\n41\n90\n85\n17\n45\n94\n31\n58\n4\n39\n76\n95\n92\n59\n67\n46\n96\n55\n82\n64\n20\n20\n83\n46\n37\n15\n60\n37\n79\n45\n47\n63\n73\n76\n31\n52\n36\n32\n49\n26\n61\n91\n31\n25\n62\n90\n65\n65\n5\n94\n7\n15\n97\n88\n68",
"output": "7"
},
{
"input": "100\n1756\n98\n229\n158\n281\n16\n169\n149\n239\n235\n182\n147\n215\n49\n270\n194\n242\n295\n289\n249\n19\n12\n144\n157\n92\n270\n122\n212\n97\n152\n14\n42\n12\n198\n98\n295\n154\n229\n191\n294\n5\n156\n43\n185\n184\n20\n125\n23\n10\n257\n244\n264\n79\n46\n277\n13\n22\n97\n212\n77\n293\n20\n51\n17\n109\n37\n68\n117\n51\n248\n10\n149\n179\n192\n239\n161\n13\n173\n297\n73\n43\n109\n288\n198\n81\n70\n254\n187\n277\n1\n295\n113\n95\n291\n293\n119\n205\n191\n37\n34\n116",
"output": "6"
},
{
"input": "100\n20562\n721\n452\n11\n703\n376\n183\n197\n203\n406\n642\n346\n446\n256\n760\n201\n360\n702\n707\n388\n779\n653\n610\n497\n768\n670\n134\n780\n306\n661\n180\n259\n256\n362\n6\n121\n415\n747\n170\n67\n439\n728\n193\n622\n481\n38\n225\n343\n303\n253\n436\n305\n68\n794\n247\n291\n600\n750\n188\n199\n757\n28\n776\n749\n253\n351\n53\n629\n129\n578\n209\n89\n651\n262\n638\n353\n469\n31\n144\n460\n176\n535\n562\n366\n639\n234\n577\n364\n761\n617\n303\n450\n778\n311\n289\n221\n274\n239\n626\n194\n36",
"output": "30"
},
{
"input": "100\n32630\n548\n21\n756\n138\n56\n719\n97\n86\n599\n531\n464\n137\n737\n239\n626\n179\n170\n271\n335\n178\n298\n597\n616\n104\n190\n216\n333\n606\n621\n310\n70\n286\n593\n655\n472\n556\n77\n625\n744\n395\n487\n762\n316\n469\n258\n475\n596\n651\n180\n737\n101\n511\n708\n163\n713\n475\n557\n649\n705\n583\n97\n447\n119\n91\n372\n194\n394\n667\n384\n635\n611\n746\n758\n613\n54\n508\n405\n188\n570\n254\n28\n599\n767\n115\n737\n194\n148\n686\n705\n236\n762\n613\n770\n633\n401\n773\n448\n274\n141\n718",
"output": "52"
},
{
"input": "1\n1\n1",
"output": "1"
}
] | 1,591,077,012 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | n = int(input())
m = int(input())
l = []
for i in range(n):
s = int(input())
l.append(s)
a =0
while(m>0):
a+=1
k = max(l)
c = l.index(k)
m -=k
l.pop(c)
if(m<=0):
break
print(a) | Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
Input Specification:
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*.
Output Specification:
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
Demo Input:
['3\n5\n2\n1\n3\n', '3\n6\n2\n3\n2\n', '2\n5\n5\n10\n']
Demo Output:
['2\n', '3\n', '1\n']
Note:
In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | ```python
n = int(input())
m = int(input())
l = []
for i in range(n):
s = int(input())
l.append(s)
a =0
while(m>0):
a+=1
k = max(l)
c = l.index(k)
m -=k
l.pop(c)
if(m<=0):
break
print(a)
``` | 3 |
|
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input": "1\nqvwli hz",
"output": "1"
},
{
"input": "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab",
"output": "2"
},
{
"input": "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syded",
"output": "3"
},
{
"input": "17\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw",
"output": "1"
},
{
"input": "18\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nb d\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp",
"output": "2"
},
{
"input": "13\nsvpzwtwn rykzfdce\nqweiyeck jkreouy\nhk nnli\ntwxrnbbdt vtuv\nxokqjtylly sz\nesdt dbfidjslq\ng ybqgomvw\nxcpfjmf zcqvz\nifajadhj invzueip\nvdemdnxifb hckwebmi\nsdpnhipam wvowzavh\nuqdlfskhgo vunbpghae\ne dtigwnb",
"output": "13"
},
{
"input": "20\nm vkfh\nvptikamead mvx\nitu mf\nklruxckw aqega\nekqkd enjllwol\ncc uybfdh\nimrfdngvo u\ne uh\ntwt jsslcfuogk\nbljwqsag tuqbdn\nqcv q\nasx gzhvwwmajj\nqcv q\nekqkd enjllwol\nasx gzhvwwmajj\nks vv\nkzyfi cn\ncc uybfdh\nitu mf\ncjbjhtbyvk vatwfmux",
"output": "15"
},
{
"input": "2\nab ab\na bab",
"output": "2"
}
] | 1,668,048,773 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 92 | 1,331,200 | l = int(input())
lis = []
co = 0
for i in range(l):
s,c = map(str,input().split())
if len(s) <= 10 and len(s)>=1 and len(c) <= 10 and len(c)>=1 :
sum = s+c
lis.append(sum)
for j in range(len(lis)):
for k in range(j+1,len(lis)):
if lis[j] == lis[k]:
co += 1
sm = l - co
if sm == 0:
print(sm+1)
else:
print(sm)
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output Specification:
Output the single number — the number of Alyona's leaves.
Demo Input:
['5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n', '3\noak yellow\noak yellow\noak yellow\n']
Demo Output:
['4\n', '1\n']
Note:
none | ```python
l = int(input())
lis = []
co = 0
for i in range(l):
s,c = map(str,input().split())
if len(s) <= 10 and len(s)>=1 and len(c) <= 10 and len(c)>=1 :
sum = s+c
lis.append(sum)
for j in range(len(lis)):
for k in range(j+1,len(lis)):
if lis[j] == lis[k]:
co += 1
sm = l - co
if sm == 0:
print(sm+1)
else:
print(sm)
``` | 0 |
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs *a* rubles, or in glass liter bottle, that costs *b* rubles. Also, you may return empty glass bottle and get *c* (*c*<=<<=*b*) rubles back, but you cannot return plastic bottles.
Kolya has *n* rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively. | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir. | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"output": "5"
},
{
"input": "9\n2\n4\n1",
"output": "4"
},
{
"input": "9\n2\n2\n1",
"output": "8"
},
{
"input": "9\n10\n10\n1",
"output": "0"
},
{
"input": "10\n2\n2\n1",
"output": "9"
},
{
"input": "1000000000000000000\n2\n10\n9",
"output": "999999999999999995"
},
{
"input": "501000000000000000\n300000000000000000\n301000000000000000\n100000000000000000",
"output": "2"
},
{
"input": "10\n1\n9\n8",
"output": "10"
},
{
"input": "10\n8\n8\n7",
"output": "3"
},
{
"input": "10\n5\n5\n1",
"output": "2"
},
{
"input": "29\n3\n3\n1",
"output": "14"
},
{
"input": "45\n9\n9\n8",
"output": "37"
},
{
"input": "45\n9\n9\n1",
"output": "5"
},
{
"input": "100\n10\n10\n9",
"output": "91"
},
{
"input": "179\n10\n9\n1",
"output": "22"
},
{
"input": "179\n2\n2\n1",
"output": "178"
},
{
"input": "179\n179\n179\n1",
"output": "1"
},
{
"input": "179\n59\n59\n58",
"output": "121"
},
{
"input": "500\n250\n250\n1",
"output": "2"
},
{
"input": "500\n1\n250\n1",
"output": "500"
},
{
"input": "501\n500\n500\n499",
"output": "2"
},
{
"input": "501\n450\n52\n1",
"output": "9"
},
{
"input": "501\n300\n301\n100",
"output": "2"
},
{
"input": "500\n179\n10\n1",
"output": "55"
},
{
"input": "1000\n500\n10\n9",
"output": "991"
},
{
"input": "1000\n2\n10\n9",
"output": "995"
},
{
"input": "1001\n1000\n1000\n999",
"output": "2"
},
{
"input": "10000\n10000\n10000\n1",
"output": "1"
},
{
"input": "10000\n10\n5000\n4999",
"output": "5500"
},
{
"input": "1000000000\n999999998\n999999999\n999999998",
"output": "3"
},
{
"input": "1000000000\n50\n50\n49",
"output": "999999951"
},
{
"input": "1000000000\n500\n5000\n4999",
"output": "999995010"
},
{
"input": "1000000000\n51\n100\n98",
"output": "499999952"
},
{
"input": "1000000000\n100\n51\n50",
"output": "999999950"
},
{
"input": "1000000000\n2\n5\n4",
"output": "999999998"
},
{
"input": "1000000000000000000\n999999998000000000\n999999999000000000\n999999998000000000",
"output": "3"
},
{
"input": "1000000000\n2\n2\n1",
"output": "999999999"
},
{
"input": "999999999\n2\n999999998\n1",
"output": "499999999"
},
{
"input": "999999999999999999\n2\n2\n1",
"output": "999999999999999998"
},
{
"input": "999999999999999999\n10\n10\n9",
"output": "999999999999999990"
},
{
"input": "999999999999999999\n999999999999999998\n999999999999999998\n999999999999999997",
"output": "2"
},
{
"input": "999999999999999999\n501\n501\n1",
"output": "1999999999999999"
},
{
"input": "999999999999999999\n2\n50000000000000000\n49999999999999999",
"output": "974999999999999999"
},
{
"input": "999999999999999999\n180\n180\n1",
"output": "5586592178770949"
},
{
"input": "1000000000000000000\n42\n41\n1",
"output": "24999999999999999"
},
{
"input": "1000000000000000000\n41\n40\n1",
"output": "25641025641025641"
},
{
"input": "100000000000000000\n79\n100\n25",
"output": "1333333333333333"
},
{
"input": "1\n100\n5\n4",
"output": "0"
},
{
"input": "1000000000000000000\n1000000000000000000\n10000000\n9999999",
"output": "999999999990000001"
},
{
"input": "999999999999999999\n999999999000000000\n900000000000000000\n899999999999999999",
"output": "100000000000000000"
},
{
"input": "13\n10\n15\n11",
"output": "1"
},
{
"input": "1\n1000\n5\n4",
"output": "0"
},
{
"input": "10\n100\n10\n1",
"output": "1"
},
{
"input": "3\n2\n100000\n99999",
"output": "1"
},
{
"input": "4\n2\n4\n2",
"output": "2"
},
{
"input": "5\n3\n6\n4",
"output": "1"
},
{
"input": "1\n7\n65\n49",
"output": "0"
},
{
"input": "10\n20\n100\n99",
"output": "0"
},
{
"input": "10000000000\n10000000000\n9000000000\n8999999999",
"output": "1000000001"
},
{
"input": "90\n30\n101\n100",
"output": "3"
},
{
"input": "999999999999999\n5\n500000000000000\n499999999999999",
"output": "599999999999999"
},
{
"input": "1000000000000000000\n1000000000000000000\n1000000000\n999999999",
"output": "999999999000000001"
},
{
"input": "1\n1000000000000000000\n1000000000\n999999999",
"output": "0"
},
{
"input": "100000000000000000\n100000000000000000\n1000000000\n999999999",
"output": "99999999000000001"
},
{
"input": "100000000000000009\n100\n1000000000000000\n999999999999999",
"output": "99010000000000009"
},
{
"input": "10\n20\n10\n9",
"output": "1"
},
{
"input": "10\n4\n14\n13",
"output": "2"
},
{
"input": "11\n3\n9\n7",
"output": "4"
},
{
"input": "1000000000\n5\n7\n4",
"output": "333333332"
},
{
"input": "12155\n1943\n28717\n24074",
"output": "6"
},
{
"input": "1000000000000000000\n10\n20\n5",
"output": "100000000000000000"
},
{
"input": "98\n33\n440\n314",
"output": "2"
},
{
"input": "1070252292\n57449678\n237309920\n221182550",
"output": "56"
},
{
"input": "100\n3\n102\n101",
"output": "33"
},
{
"input": "100000000000000000\n100000000000000001\n1000000000000000\n999999999999999",
"output": "99000000000000001"
},
{
"input": "66249876257975628\n302307316\n406102416\n182373516",
"output": "296116756"
},
{
"input": "10\n5\n10\n1",
"output": "2"
},
{
"input": "1000000000000000000\n10\n1000000000\n999999998",
"output": "499999999600000000"
}
] | 1,454,917,449 | 6,549 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 0 | __author__ = 'Admin'
n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
if b - c < a:
ans = (n - b + 1) // (b - c)
else:
ans = n // a
print(ans) | Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs *a* rubles, or in glass liter bottle, that costs *b* rubles. Also, you may return empty glass bottle and get *c* (*c*<=<<=*b*) rubles back, but you cannot return plastic bottles.
Kolya has *n* rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.
Output Specification:
Print the only integer — maximum number of liters of kefir, that Kolya can drink.
Demo Input:
['10\n11\n9\n8\n', '10\n5\n6\n1\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir. | ```python
__author__ = 'Admin'
n = int(input())
a = int(input())
b = int(input())
c = int(input())
ans = 0
if b - c < a:
ans = (n - b + 1) // (b - c)
else:
ans = n // a
print(ans)
``` | 0 |
|
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,691,905,973 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | def can_divide_watermelon(w):
if w % 2 == 0 and w > 2:
return "YES"
else:
return "NO"
weight = int(input("Enter the weight of the watermelon: "))
print(can_divide_watermelon(weight))
| Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input Specification:
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Output Specification:
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Demo Input:
['8\n']
Demo Output:
['YES\n']
Note:
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | ```python
def can_divide_watermelon(w):
if w % 2 == 0 and w > 2:
return "YES"
else:
return "NO"
weight = int(input("Enter the weight of the watermelon: "))
print(can_divide_watermelon(weight))
``` | 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,673,033,681 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 124 | 0 | n=int(input())
a=list(map(int,input().split()))
for i in range(1,n):
if a[i-1]%2!=a[i]%2:
if i>=2:
l=a[i-2]
else:
l=a[i+1]
if l%2!=a[i-1]%2:
print(i)
else:
print(i+1)
break | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n=int(input())
a=list(map(int,input().split()))
for i in range(1,n):
if a[i-1]%2!=a[i]%2:
if i>=2:
l=a[i-2]
else:
l=a[i+1]
if l%2!=a[i-1]%2:
print(i)
else:
print(i+1)
break
``` | 3.969 |
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,683,479,404 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 46 | 0 | n,m=map(int,input().split())
array=[]
for i in range(n):
array.append(list(input().split()))
for l in array:
if('C' in l or 'M' in l or 'G' in l or 'Y' in l):
print("#Color")
exit(0)
print("#Black&White")
exit(0) | 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
n,m=map(int,input().split())
array=[]
for i in range(n):
array.append(list(input().split()))
for l in array:
if('C' in l or 'M' in l or 'G' in l or 'Y' in l):
print("#Color")
exit(0)
print("#Black&White")
exit(0)
``` | 0 |
|
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{
"input": "1022 584 112",
"output": "380"
},
{
"input": "66 174 319",
"output": "184"
},
{
"input": "912 276 1748",
"output": "444"
},
{
"input": "65 156 60",
"output": "120"
},
{
"input": "1 10000 10000",
"output": "40008"
},
{
"input": "1485 55 27",
"output": "332"
},
{
"input": "152 108 4104",
"output": "528"
},
{
"input": "1656 6900 1350",
"output": "740"
},
{
"input": "12 14 42",
"output": "60"
},
{
"input": "615 18 1230",
"output": "856"
},
{
"input": "680 60 408",
"output": "336"
},
{
"input": "644 966 6",
"output": "1308"
},
{
"input": "1 432 432",
"output": "1736"
},
{
"input": "2239 2239 1",
"output": "8964"
},
{
"input": "4106 8212 2",
"output": "16436"
},
{
"input": "10000 10000 10000",
"output": "1200"
},
{
"input": "3623 3623 1",
"output": "14500"
},
{
"input": "9801 9801 9801",
"output": "1188"
},
{
"input": "10000 1 10000",
"output": "40008"
},
{
"input": "9 9 9",
"output": "36"
},
{
"input": "9801 9702 9702",
"output": "1184"
}
] | 1,619,619,756 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 124 | 0 | from itertools import permutations
def solve(arr):
perm = permutations(arr)
for i in list(perm):
v = (i[1]*i[2]/i[0])**.5
if v.is_integer() :
return int(4*v + 4*i[1]//v + 4*i[2]//v)
def main():
arr = list(map(int, input().split(" ")))
print(solve(arr))
main() | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input Specification:
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output Specification:
Print a single number — the sum of all edges of the parallelepiped.
Demo Input:
['1 1 1\n', '4 6 6\n']
Demo Output:
['12\n', '28\n']
Note:
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | ```python
from itertools import permutations
def solve(arr):
perm = permutations(arr)
for i in list(perm):
v = (i[1]*i[2]/i[0])**.5
if v.is_integer() :
return int(4*v + 4*i[1]//v + 4*i[2]//v)
def main():
arr = list(map(int, input().split(" ")))
print(solve(arr))
main()
``` | 3 |
|
285 | C | Building Permutation | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You have a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"2\n3 0\n",
"3\n-1 -1 2\n"
] | [
"2\n",
"6\n"
] | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | 1,500 | [
{
"input": "2\n3 0",
"output": "2"
},
{
"input": "3\n-1 -1 2",
"output": "6"
},
{
"input": "5\n-3 5 -3 3 3",
"output": "10"
},
{
"input": "10\n9 6 -2 4 1 1 1 9 6 2",
"output": "18"
},
{
"input": "9\n2 0 0 6 5 4 1 9 3",
"output": "15"
},
{
"input": "100\n-77 57 -95 -23 53 -28 82 -83 38 -73 85 28 25 6 -43 4 -10 -30 -9 -92 14 34 -93 61 36 -100 90 -68 28 16 100 -3 97 30 36 -55 62 -62 53 74 -50 -23 67 11 22 -30 -19 83 7 84 43 90 -65 -75 -15 97 90 15 66 2 13 -91 91 -44 46 51 51 -58 95 77 20 30 76 79 91 60 76 2 82 42 -93 94 -57 88 65 -95 -66 100 -9 33 -67 54 -99 97 53 13 54 66 60 -48",
"output": "3459"
}
] | 1,611,476,233 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 436 | 24,473,600 | def solve (n,seq) :
seq.sort()
start = 1
moves = 0
while start <= n :
if seq[start-1] != start :
moves += abs(seq[start-1] - start)
start += 1
return moves
n = int(input())
seq = list(map(int,input().split()))
print (solve(n,seq))
| Title: Building Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You have a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single number — the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Demo Input:
['2\n3 0\n', '3\n-1 -1 2\n']
Demo Output:
['2\n', '6\n']
Note:
In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | ```python
def solve (n,seq) :
seq.sort()
start = 1
moves = 0
while start <= n :
if seq[start-1] != start :
moves += abs(seq[start-1] - start)
start += 1
return moves
n = int(input())
seq = list(map(int,input().split()))
print (solve(n,seq))
``` | 3 |
|
9 | D | How many trees? | PROGRAMMING | 1,900 | [
"combinatorics",
"divide and conquer",
"dp"
] | D. How many trees? | 1 | 64 | In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with *n* nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to *n*. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than *h*. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you? | The input data contains two space-separated positive integer numbers *n* and *h* (*n*<=≤<=35, *h*<=≤<=*n*). | Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018. | [
"3 2\n",
"3 3\n"
] | [
"5",
"4"
] | none | 0 | [
{
"input": "3 2",
"output": "5"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "27 11",
"output": "61162698256896"
},
{
"input": "32 27",
"output": "22643872890880"
},
{
"input": "4 1",
"output": "14"
},
{
"input": "9 1",
"output": "4862"
},
{
"input": "33 4",
"output": "212336130412243110"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "8 5",
"output": "1336"
},
{
"input": "12 8",
"output": "127200"
},
{
"input": "15 5",
"output": "9694844"
},
{
"input": "19 18",
"output": "2424832"
},
{
"input": "23 17",
"output": "19649347584"
},
{
"input": "27 15",
"output": "25162319484928"
},
{
"input": "29 14",
"output": "577801978306560"
},
{
"input": "33 18",
"output": "54307238601375744"
},
{
"input": "7 7",
"output": "64"
},
{
"input": "23 21",
"output": "275251200"
},
{
"input": "7 3",
"output": "429"
},
{
"input": "21 18",
"output": "211156992"
},
{
"input": "4 1",
"output": "14"
},
{
"input": "21 12",
"output": "12153990144"
},
{
"input": "35 13",
"output": "2690352397519398400"
},
{
"input": "19 2",
"output": "1767263190"
},
{
"input": "33 26",
"output": "434871797284864"
},
{
"input": "16 9",
"output": "25607552"
},
{
"input": "16 14",
"output": "1032192"
},
{
"input": "10 2",
"output": "16796"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "33 17",
"output": "75307983624118272"
},
{
"input": "27 25",
"output": "6081740800"
},
{
"input": "20 14",
"output": "1094473728"
},
{
"input": "16 11",
"output": "11819008"
},
{
"input": "10 10",
"output": "512"
},
{
"input": "4 3",
"output": "14"
},
{
"input": "33 21",
"output": "14830955929665536"
},
{
"input": "24 20",
"output": "8171945984"
},
{
"input": "30 16",
"output": "1375710400053248"
},
{
"input": "3 2",
"output": "5"
},
{
"input": "9 4",
"output": "4862"
},
{
"input": "16 5",
"output": "35357670"
},
{
"input": "22 22",
"output": "2097152"
},
{
"input": "28 23",
"output": "739948625920"
},
{
"input": "34 1",
"output": "812944042149730764"
},
{
"input": "7 4",
"output": "428"
},
{
"input": "14 11",
"output": "488448"
},
{
"input": "35 1",
"output": "3116285494907301262"
},
{
"input": "35 35",
"output": "17179869184"
}
] | 1,505,727,052 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 154 | 4,608,000 | n, h = map(int, input().split())
t = s = [1] * (n + 1)
for m in range(1, n + 1): s[m] = sum(s[m - 1 - k] * s[k] for k in range(m))
for j in range(h): t = [sum((s[k] - t[k]) * t[m - 1 - k] + s[m - 1 - k] * t[k] for k in range(m)) for m in range(n + 1)]
print(t[n]) | Title: How many trees?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...
For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.
However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.
This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with *n* nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to *n*. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).
In Hexadecimal's game all the trees are different, but the height of each is not lower than *h*. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?
Input Specification:
The input data contains two space-separated positive integer numbers *n* and *h* (*n*<=≤<=35, *h*<=≤<=*n*).
Output Specification:
Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.
Demo Input:
['3 2\n', '3 3\n']
Demo Output:
['5', '4']
Note:
none | ```python
n, h = map(int, input().split())
t = s = [1] * (n + 1)
for m in range(1, n + 1): s[m] = sum(s[m - 1 - k] * s[k] for k in range(m))
for j in range(h): t = [sum((s[k] - t[k]) * t[m - 1 - k] + s[m - 1 - k] * t[k] for k in range(m)) for m in range(n + 1)]
print(t[n])
``` | 3.888668 |
56 | A | Bar | PROGRAMMING | 1,000 | [
"implementation"
] | A. Bar | 2 | 256 | According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol. | Print a single number which is the number of people Vasya should check to guarantee the law enforcement. | [
"5\n18\nVODKA\nCOKE\n19\n17\n"
] | [
"2\n"
] | In the sample test the second and fifth clients should be checked. | 500 | [
{
"input": "5\n18\nVODKA\nCOKE\n19\n17",
"output": "2"
},
{
"input": "2\n2\nGIN",
"output": "2"
},
{
"input": "3\nWHISKEY\n3\nGIN",
"output": "3"
},
{
"input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWINWJW",
"output": "1"
},
{
"input": "4\nSAKE\nSAKE\n13\n2",
"output": "4"
},
{
"input": "2\n0\n17",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
}
] | 1,664,956,784 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 6,041,600 | cnt=0
alc=['ABSINTH','BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
for i in range(n):
x=input()
if not x.isdigit() and x in alc:
cnt+=1
if x.isdigit() and int(x)<18:
cnt+=1
print(cnt) | Title: Bar
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?
The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators.
Only the drinks from the list given above should be considered alcohol.
Output Specification:
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
Demo Input:
['5\n18\nVODKA\nCOKE\n19\n17\n']
Demo Output:
['2\n']
Note:
In the sample test the second and fifth clients should be checked. | ```python
cnt=0
alc=['ABSINTH','BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
for i in range(n):
x=input()
if not x.isdigit() and x in alc:
cnt+=1
if x.isdigit() and int(x)<18:
cnt+=1
print(cnt)
``` | -1 |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him. | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length. | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 5 6 11",
"output": "TRIANGLE"
},
{
"input": "1 1 1 1",
"output": "TRIANGLE"
},
{
"input": "10 20 30 40",
"output": "TRIANGLE"
},
{
"input": "45 25 5 15",
"output": "IMPOSSIBLE"
},
{
"input": "20 5 8 13",
"output": "TRIANGLE"
},
{
"input": "10 30 7 20",
"output": "SEGMENT"
},
{
"input": "3 2 3 2",
"output": "TRIANGLE"
},
{
"input": "70 10 100 30",
"output": "SEGMENT"
},
{
"input": "4 8 16 2",
"output": "IMPOSSIBLE"
},
{
"input": "3 3 3 10",
"output": "TRIANGLE"
},
{
"input": "1 5 5 5",
"output": "TRIANGLE"
},
{
"input": "13 25 12 1",
"output": "SEGMENT"
},
{
"input": "10 100 7 3",
"output": "SEGMENT"
},
{
"input": "50 1 50 100",
"output": "TRIANGLE"
},
{
"input": "50 1 100 49",
"output": "SEGMENT"
},
{
"input": "49 51 100 1",
"output": "SEGMENT"
},
{
"input": "5 11 2 25",
"output": "IMPOSSIBLE"
},
{
"input": "91 50 9 40",
"output": "IMPOSSIBLE"
},
{
"input": "27 53 7 97",
"output": "IMPOSSIBLE"
},
{
"input": "51 90 24 8",
"output": "IMPOSSIBLE"
},
{
"input": "3 5 1 1",
"output": "IMPOSSIBLE"
},
{
"input": "13 49 69 15",
"output": "IMPOSSIBLE"
},
{
"input": "16 99 9 35",
"output": "IMPOSSIBLE"
},
{
"input": "27 6 18 53",
"output": "IMPOSSIBLE"
},
{
"input": "57 88 17 8",
"output": "IMPOSSIBLE"
},
{
"input": "95 20 21 43",
"output": "IMPOSSIBLE"
},
{
"input": "6 19 32 61",
"output": "IMPOSSIBLE"
},
{
"input": "100 21 30 65",
"output": "IMPOSSIBLE"
},
{
"input": "85 16 61 9",
"output": "IMPOSSIBLE"
},
{
"input": "5 6 19 82",
"output": "IMPOSSIBLE"
},
{
"input": "1 5 1 3",
"output": "IMPOSSIBLE"
},
{
"input": "65 10 36 17",
"output": "IMPOSSIBLE"
},
{
"input": "81 64 9 7",
"output": "IMPOSSIBLE"
},
{
"input": "11 30 79 43",
"output": "IMPOSSIBLE"
},
{
"input": "1 1 5 3",
"output": "IMPOSSIBLE"
},
{
"input": "21 94 61 31",
"output": "IMPOSSIBLE"
},
{
"input": "49 24 9 74",
"output": "IMPOSSIBLE"
},
{
"input": "11 19 5 77",
"output": "IMPOSSIBLE"
},
{
"input": "52 10 19 71",
"output": "SEGMENT"
},
{
"input": "2 3 7 10",
"output": "SEGMENT"
},
{
"input": "1 2 6 3",
"output": "SEGMENT"
},
{
"input": "2 6 1 8",
"output": "SEGMENT"
},
{
"input": "1 2 4 1",
"output": "SEGMENT"
},
{
"input": "4 10 6 2",
"output": "SEGMENT"
},
{
"input": "2 10 7 3",
"output": "SEGMENT"
},
{
"input": "5 2 3 9",
"output": "SEGMENT"
},
{
"input": "6 1 4 10",
"output": "SEGMENT"
},
{
"input": "10 6 4 1",
"output": "SEGMENT"
},
{
"input": "3 2 9 1",
"output": "SEGMENT"
},
{
"input": "22 80 29 7",
"output": "SEGMENT"
},
{
"input": "2 6 3 9",
"output": "SEGMENT"
},
{
"input": "3 1 2 1",
"output": "SEGMENT"
},
{
"input": "3 4 7 1",
"output": "SEGMENT"
},
{
"input": "8 4 3 1",
"output": "SEGMENT"
},
{
"input": "2 8 3 5",
"output": "SEGMENT"
},
{
"input": "4 1 2 1",
"output": "SEGMENT"
},
{
"input": "8 1 3 2",
"output": "SEGMENT"
},
{
"input": "6 2 1 8",
"output": "SEGMENT"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "3 6 3 3",
"output": "TRIANGLE"
},
{
"input": "4 10 4 4",
"output": "TRIANGLE"
},
{
"input": "1 1 2 1",
"output": "TRIANGLE"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "5 4 5 5",
"output": "TRIANGLE"
},
{
"input": "8 7 8 8",
"output": "TRIANGLE"
},
{
"input": "3 3 3 1",
"output": "TRIANGLE"
},
{
"input": "1 1 6 6",
"output": "TRIANGLE"
},
{
"input": "1 9 1 9",
"output": "TRIANGLE"
},
{
"input": "7 2 2 7",
"output": "TRIANGLE"
},
{
"input": "7 2 3 2",
"output": "TRIANGLE"
},
{
"input": "4 4 10 10",
"output": "TRIANGLE"
},
{
"input": "7 7 10 7",
"output": "TRIANGLE"
},
{
"input": "4 4 4 5",
"output": "TRIANGLE"
},
{
"input": "1 10 9 2",
"output": "TRIANGLE"
},
{
"input": "1 8 2 7",
"output": "TRIANGLE"
},
{
"input": "4 3 2 8",
"output": "TRIANGLE"
},
{
"input": "5 9 5 3",
"output": "TRIANGLE"
},
{
"input": "4 10 3 5",
"output": "TRIANGLE"
}
] | 1,602,385,892 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 218 | 307,200 | a,b,c,d=map(int,input().split())
o=max(a,b,c,d)
if (a>=b and a>=c and a<b+c) or (a>=b and a>=d and a<b+d) or (a>=d and a>=c and a<c+d) or (b>=a and b>=c and b<a+c) or (b>=a and b>=d and b<a+d) or (b>=c and b>=d and b<c+d) or (c>=a and c>=d and c<a+d) or (c>=a and c>=b and c<a+b)or (c>=b and c>=d and c<b+d) or (d>=a and d>=b and d<a+b) or (d>=a and d>=c and d<a+c) or (d>=c and d>=b and d<c+b):
print('TRIANGLE')
elif 2*o<a+b+c+d:
print('SEGMENT')
else :
print('IMPOSSIBLE')
| Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input Specification:
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output Specification:
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Demo Input:
['4 2 1 3\n', '7 2 2 4\n', '3 5 9 1\n']
Demo Output:
['TRIANGLE\n', 'SEGMENT\n', 'IMPOSSIBLE\n']
Note:
none | ```python
a,b,c,d=map(int,input().split())
o=max(a,b,c,d)
if (a>=b and a>=c and a<b+c) or (a>=b and a>=d and a<b+d) or (a>=d and a>=c and a<c+d) or (b>=a and b>=c and b<a+c) or (b>=a and b>=d and b<a+d) or (b>=c and b>=d and b<c+d) or (c>=a and c>=d and c<a+d) or (c>=a and c>=b and c<a+b)or (c>=b and c>=d and c<b+d) or (d>=a and d>=b and d<a+b) or (d>=a and d>=c and d<a+c) or (d>=c and d>=b and d<c+b):
print('TRIANGLE')
elif 2*o<a+b+c+d:
print('SEGMENT')
else :
print('IMPOSSIBLE')
``` | 0 |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,695,992,478 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | def odd_even(n, k):
if n%2 == 0:
if k <= n//2:
res = 2*k - 1
else:
res = 2*(k - n//2)
else:
if k <= n//2 + 1:
res = 2*k - 1
else:
res = 2*(k - n//2 - 1)
return res
n, k = map(int, input().split())
print(even_odd(n, k))
| Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
Input Specification:
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the number that will stand at the position number *k* after Volodya's manipulations.
Demo Input:
['10 3\n', '7 7\n']
Demo Output:
['5', '6']
Note:
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | ```python
def odd_even(n, k):
if n%2 == 0:
if k <= n//2:
res = 2*k - 1
else:
res = 2*(k - n//2)
else:
if k <= n//2 + 1:
res = 2*k - 1
else:
res = 2*(k - n//2 - 1)
return res
n, k = map(int, input().split())
print(even_odd(n, k))
``` | -1 |
|
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
"output": "21223442"
},
{
"input": "91730629",
"output": "91230320"
},
{
"input": "420062703497",
"output": "420032203402"
},
{
"input": "332711047202",
"output": "332211042202"
},
{
"input": "3395184971407775",
"output": "3304114021402224"
},
{
"input": "8464062628894325",
"output": "1434032321104324"
},
{
"input": "164324828731963982",
"output": "134324121231033012"
},
{
"input": "384979173822804784",
"output": "314020123122104214"
},
{
"input": "41312150450968417",
"output": "41312140440031412"
},
{
"input": "2156",
"output": "2143"
},
{
"input": "1932",
"output": "1032"
},
{
"input": "5902",
"output": "4002"
},
{
"input": "5728",
"output": "4221"
},
{
"input": "8537",
"output": "1432"
},
{
"input": "55403857",
"output": "44403142"
},
{
"input": "270739",
"output": "220230"
},
{
"input": "28746918",
"output": "21243011"
},
{
"input": "10279211",
"output": "10220211"
},
{
"input": "40289679",
"output": "40210320"
},
{
"input": "545203238506",
"output": "444203231403"
},
{
"input": "461117063340",
"output": "431112033340"
},
{
"input": "658492686568",
"output": "341402313431"
},
{
"input": "857373361868",
"output": "142323331131"
},
{
"input": "429325660016",
"output": "420324330013"
},
{
"input": "9894448650287940",
"output": "9104441340212040"
},
{
"input": "6354510839296263",
"output": "3344410130203233"
},
{
"input": "6873575462224593",
"output": "3123424432224403"
},
{
"input": "4237951492601449",
"output": "4232041402301440"
},
{
"input": "2680352384836991",
"output": "2310342314133001"
},
{
"input": "606187734191890310",
"output": "303112234101100310"
},
{
"input": "351499943576823355",
"output": "341400043423123344"
},
{
"input": "180593481782177068",
"output": "110403411212122031"
},
{
"input": "999999999999999999",
"output": "900000000000000000"
},
{
"input": "1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "9999",
"output": "9000"
},
{
"input": "99",
"output": "90"
},
{
"input": "9991",
"output": "9001"
}
] | 1,695,577,743 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 31 | 0 | a = int(input())
t = 0
b = a
c = 1
r = 0
while a > 0:
t = a % 10
if t > 4 and t != 9:
r = b % c
b //= c
b -= t
t = 9 - t
b += t
b *= c
b += r
elif t == 9 and b // c >= 10:
r = b % c
b //= c
b -= t
t = 9 - t
b += t
b *= c
b += r
a //= 10
c *= 10
print(b)
| Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
Input Specification:
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Output Specification:
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
Demo Input:
['27\n', '4545\n']
Demo Output:
['22\n', '4444\n']
Note:
none | ```python
a = int(input())
t = 0
b = a
c = 1
r = 0
while a > 0:
t = a % 10
if t > 4 and t != 9:
r = b % c
b //= c
b -= t
t = 9 - t
b += t
b *= c
b += r
elif t == 9 and b // c >= 10:
r = b % c
b //= c
b -= t
t = 9 - t
b += t
b *= c
b += r
a //= 10
c *= 10
print(b)
``` | 3 |
|
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n1 2 3 3 4",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "2"
},
{
"input": "11\n1 2 3 1 2 3 2 1 2 3 4",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "1\n1234394",
"output": "1"
}
] | 1,687,970,079 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 78 | 12,800,000 | from sys import stdin
len_l = int(stdin.readline()[:-1])
l = list(map(int, list(input().split(" "))))
prev = 0
best = 0
res = 0
for elem in l:
if prev < elem:
res += 1
prev = elem
else:
best = max(best, res)
prev = elem
res = 1
print(max(best, res)) | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Input Specification:
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the maximum length of an increasing subarray of the given array.
Demo Input:
['5\n1 7 2 11 15\n', '6\n100 100 100 100 100 100\n', '3\n1 2 3\n']
Demo Output:
['3\n', '1\n', '3\n']
Note:
none | ```python
from sys import stdin
len_l = int(stdin.readline()[:-1])
l = list(map(int, list(input().split(" "))))
prev = 0
best = 0
res = 0
for elem in l:
if prev < elem:
res += 1
prev = elem
else:
best = max(best, res)
prev = elem
res = 1
print(max(best, res))
``` | 3 |
|
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,590,214,216 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 139 | 0 | p=input()
#
r=[]
for k in range (0,len(p),1):
r.append(p[k])
#r.pop(0,3)
#del r[0:3]
#ss=[]
l=0;
for i in range (0,len(p),1):
k=0;
if((r[k]=="h")&(l==0)):
#ss.append("h")
l=1;
elif((r[k]=="e")&(l==1)):
#ss.append("e")
l=2;
elif((r[k]=="l")&(l==2)):
#ss.append("l")
l=3;
elif((r[k]=="l")&(l==3)):
#ss.append("l")
l=4;
elif((r[k]=="o")&(l==4)):
#ss.append("o")
l=5;
r.pop(0)
if(l==5):
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
p=input()
#
r=[]
for k in range (0,len(p),1):
r.append(p[k])
#r.pop(0,3)
#del r[0:3]
#ss=[]
l=0;
for i in range (0,len(p),1):
k=0;
if((r[k]=="h")&(l==0)):
#ss.append("h")
l=1;
elif((r[k]=="e")&(l==1)):
#ss.append("e")
l=2;
elif((r[k]=="l")&(l==2)):
#ss.append("l")
l=3;
elif((r[k]=="l")&(l==3)):
#ss.append("l")
l=4;
elif((r[k]=="o")&(l==4)):
#ss.append("o")
l=5;
r.pop(0)
if(l==5):
print("YES")
else:
print("NO")
``` | 3.9305 |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,610,567,997 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 |
n = int(input().strip())
a = list(map(int, input().strip().split()))
t = sum(a)
k = t%(n+1)
# if k == 1:
# print(1)
if k == 0:
print(2)
else:
print(1)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
n = int(input().strip())
a = list(map(int, input().strip().split()))
t = sum(a)
k = t%(n+1)
# if k == 1:
# print(1)
if k == 0:
print(2)
else:
print(1)
``` | 0 |
|
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days? | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697681824",
"output": "14"
},
{
"input": "41313494",
"output": "14"
},
{
"input": "673935585",
"output": "13"
},
{
"input": "117422204",
"output": "19"
},
{
"input": "954746654",
"output": "15"
},
{
"input": "536838144",
"output": "14"
},
{
"input": "1000000000",
"output": "13"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "1"
},
{
"input": "6",
"output": "2"
},
{
"input": "7",
"output": "3"
},
{
"input": "9",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "999999999",
"output": "21"
},
{
"input": "999999998",
"output": "20"
},
{
"input": "999999997",
"output": "20"
},
{
"input": "999999996",
"output": "19"
},
{
"input": "999999995",
"output": "20"
},
{
"input": "999999994",
"output": "19"
},
{
"input": "999999993",
"output": "19"
},
{
"input": "999999992",
"output": "18"
},
{
"input": "999999991",
"output": "20"
},
{
"input": "999999990",
"output": "19"
},
{
"input": "536870910",
"output": "28"
},
{
"input": "536870912",
"output": "1"
},
{
"input": "536870913",
"output": "2"
},
{
"input": "536870914",
"output": "2"
},
{
"input": "22",
"output": "3"
},
{
"input": "14",
"output": "3"
}
] | 1,668,879,857 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | bacterias = int(input())
# bacterias = 8
bacteriasBowl = 0
intermediateResult = bacterias
# print("IR",intermediateResult)
counter = 1
while intermediateResult > 1:
try:
if intermediateResult % 2 == 0:
intermediateResult = intermediateResult/2
# print("irOdd", intermediateResult)
else:
intermediateResult = intermediateResult//2 - 1
# print("irEven", intermediateResult)
counter += 1
except:
break
print(counter) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the minimum number of bacteria you need to put into the box across those days?
Input Specification:
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
Output Specification:
The only line containing one integer: the answer.
Demo Input:
['5\n', '8\n']
Demo Output:
['2\n', '1\n']
Note:
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1. | ```python
bacterias = int(input())
# bacterias = 8
bacteriasBowl = 0
intermediateResult = bacterias
# print("IR",intermediateResult)
counter = 1
while intermediateResult > 1:
try:
if intermediateResult % 2 == 0:
intermediateResult = intermediateResult/2
# print("irOdd", intermediateResult)
else:
intermediateResult = intermediateResult//2 - 1
# print("irEven", intermediateResult)
counter += 1
except:
break
print(counter)
``` | 0 |
|
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).
You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions.
It is guaranteed that the result will be positive integer number. | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"output": "130"
},
{
"input": "900000000 16",
"output": "1"
},
{
"input": "909090909 50",
"output": "3"
},
{
"input": "1001 2",
"output": "100"
},
{
"input": "5 2",
"output": "3"
},
{
"input": "2 1",
"output": "1"
}
] | 1,695,387,089 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 31 | 0 | value = list(map(int, input().split(' ')))
n = value[0]
k = value[1]
while k > 0:
if n % 10 == 0:
n = n // 10
k -= 1
else:
if k > (n % 10):
k -= n % 10
n -= n % 10
else:
n -= k
k = 0
print(n) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).
You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions.
It is guaranteed that the result will be positive integer number.
Input Specification:
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly.
Output Specification:
Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number.
Demo Input:
['512 4\n', '1000000000 9\n']
Demo Output:
['50\n', '1\n']
Note:
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | ```python
value = list(map(int, input().split(' ')))
n = value[0]
k = value[1]
while k > 0:
if n % 10 == 0:
n = n // 10
k -= 1
else:
if k > (n % 10):
k -= n % 10
n -= n % 10
else:
n -= k
k = 0
print(n)
``` | 3 |
|
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,694,516,383 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | def main():
n = int(input())
s = input()
cnt = 0
for i in range(1, len(s)):
pre = s[i - 1]
if pre == s[i]:
cnt += 1
print(cnt)
if __name__ == '__main__':
main() | 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
def main():
n = int(input())
s = input()
cnt = 0
for i in range(1, len(s)):
pre = s[i - 1]
if pre == s[i]:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
``` | -1 |
|
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order. | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
{
"input": "CACCBAA.BC",
"output": "Yes"
},
{
"input": ".CAACCBBA.CBB.AC..BABCCBCCB..B.BC..CBC.CA.CC.C.CC.B.A.CC.BBCCBB..ACAACAC.CBCCB.AABAAC.CBCC.BA..CCBC.",
"output": "Yes"
},
{
"input": "A",
"output": "No"
},
{
"input": "..",
"output": "No"
},
{
"input": "BC",
"output": "No"
},
{
"input": "CAB",
"output": "Yes"
},
{
"input": "A.CB",
"output": "No"
},
{
"input": "B.ACAA.CA..CBCBBAA.B.CCBCB.CAC.ABC...BC.BCCC.BC.CB",
"output": "Yes"
},
{
"input": "B.B...CC.B..CCCB.CB..CBCB..CBCC.CCBC.B.CB..CA.C.C.",
"output": "No"
},
{
"input": "AA.CBAABABCCC..B..B.ABBABAB.B.B.CCA..CB.B...A..CBC",
"output": "Yes"
},
{
"input": "CA.ABB.CC.B.C.BBBABAAB.BBBAACACAAA.C.AACA.AAC.C.BCCB.CCBC.C..CCACA.CBCCB.CCAABAAB.AACAA..A.AAA.",
"output": "No"
},
{
"input": "CBC...AC.BBBB.BBABABA.CAAACC.AAABB..A.BA..BC.CBBBC.BBBBCCCAA.ACCBB.AB.C.BA..CC..AAAC...AB.A.AAABBA.A",
"output": "No"
},
{
"input": "CC.AAAC.BA.BBB.AABABBCCAA.A.CBCCB.B.BC.ABCBCBBAA.CACA.CCCA.CB.CCB.A.BCCCB...C.A.BCCBC..B.ABABB.C.BCB",
"output": "Yes"
},
{
"input": "CCC..A..CACACCA.CA.ABAAB.BBA..C.AAA...ACB.ACA.CA.B.AB.A..C.BC.BC.A.C....ABBCCACCCBCC.BBBAA.ACCACB.BB",
"output": "Yes"
},
{
"input": "BC.ABACAACC..AC.A..CCCAABBCCACAC.AA.CC.BAABABABBCBB.BA..C.C.C.A.BBA.C..BC.ACACCC.AAAACCCCC.AAC.AC.AB",
"output": "Yes"
},
{
"input": "ACAC.BAA.C..CAAC..ABBAACC..BAA...CC...ACCBBCA.BAABABAACCAC.A.BBCACCC..BCB.BABAAAACCBCB.BCAABBC.C.BBB",
"output": "Yes"
},
{
"input": "CCAC.BCBC.A.ABBAB.C.C.BC.CCABBCBCCBC..B.AA.C.BC...B..BAA.ACCCCBBB.AAAACA.CAACCB.CCB.CC.BCCAB.BBBBABB",
"output": "Yes"
},
{
"input": ".AACAA.AAAAC.BBBB.BC...CCACCACAAA.A..CCA..BCC.AB.ABAAB..AABA...B.C.CBAB.BAAB.A.C.AAC.BBBA.ACAAA.BB.C",
"output": "Yes"
},
{
"input": "CC.ACCC.BCCCCAA.BBAACB.ABABAAAA.A.CBAB.CBACBBC..C.CA.AAA..AA..ABBB.A.C..CBBCAAACC.B..CC.AC..CAABACB.",
"output": "Yes"
},
{
"input": ".BAB.",
"output": "No"
},
{
"input": "BBBBBBBBB",
"output": "No"
},
{
"input": "..AAC..",
"output": "No"
},
{
"input": ".AAABBBCCC.",
"output": "No"
},
{
"input": "AAABC",
"output": "Yes"
},
{
"input": "BBB",
"output": "No"
},
{
"input": "AAAAABABAAAAA",
"output": "No"
},
{
"input": "AABBCC",
"output": "No"
},
{
"input": ".BA",
"output": "No"
},
{
"input": "CAAAAB",
"output": "No"
}
] | 1,528,984,103 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 78 | 0 | a = input()
length = len(a)
for i in range(length-2):
dilim = a[i:i+3]
if ('A' in dilim and 'B' in dilim and 'C' in dilim):
print('Yes')
exit()
print('No')
| Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input Specification:
The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output Specification:
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['.BAC.\n', 'AA..CB\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | ```python
a = input()
length = len(a)
for i in range(length-2):
dilim = a[i:i+3]
if ('A' in dilim and 'B' in dilim and 'C' in dilim):
print('Yes')
exit()
print('No')
``` | 3 |
|
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,681,436,459 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 93 | 0 | import math
n,m,a = [int (i) for i in input().split()]
result = math.ceil(n/a)*math.ceil(m/a)
print(result)
| 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 math
n,m,a = [int (i) for i in input().split()]
result = math.ceil(n/a)*math.ceil(m/a)
print(result)
``` | 3.9535 |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11. | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481 554 1000 821",
"output": "15"
},
{
"input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396",
"output": "144"
},
{
"input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366",
"output": "145"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19",
"output": "63"
},
{
"input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386",
"output": "31"
},
{
"input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518",
"output": "75"
},
{
"input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397",
"output": "41"
},
{
"input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118",
"output": "116"
}
] | 1,691,924,185 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n,h=map(int,input().split())
heights=list(map(int,input().split()))
total_width=0
for height in heights:
if height<=h:
total_width+=1
else:
total_width+=2
print(total_width)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
Input Specification:
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Output Specification:
Print a single integer — the minimum possible valid width of the road.
Demo Input:
['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n']
Demo Output:
['4\n', '6\n', '11\n']
Note:
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11. | ```python
n,h=map(int,input().split())
heights=list(map(int,input().split()))
total_width=0
for height in heights:
if height<=h:
total_width+=1
else:
total_width+=2
print(total_width)
``` | 3 |
|
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,619,424,856 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = input()
b = input()
c = 0
d = 0
e = []
for x in b:
if x == "B":
if d == 0:
c+=1
d+=1
else:
if d !=0:
1.append(str(b))
if b > 0:
1.append(str(b))
print(c)
print(" .join(1))
| 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
a = input()
b = input()
c = 0
d = 0
e = []
for x in b:
if x == "B":
if d == 0:
c+=1
d+=1
else:
if d !=0:
1.append(str(b))
if b > 0:
1.append(str(b))
print(c)
print(" .join(1))
``` | -1 |
|
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,690,352,240 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | t = int(input())
for i in range(t):
s = input()
n = len(s)
if n <= 10:
print(s)
else:
print(s[0] + str(n-2) + s[n-1]) | 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
t = int(input())
for i in range(t):
s = input()
n = len(s)
if n <= 10:
print(s)
else:
print(s[0] + str(n-2) + s[n-1])
``` | 3.977 |
671 | A | Recycling Bottles | PROGRAMMING | 1,800 | [
"dp",
"geometry",
"greedy",
"implementation"
] | null | null | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are *n* bottles on the ground, the *i*-th bottle is located at position (*x**i*,<=*y**i*). Both Adil and Bera can carry only one bottle at once each.
For both Adil and Bera the process looks as follows:
1. Choose to stop or to continue to collect bottles. 1. If the choice was to continue then choose some bottle and walk towards it. 1. Pick this bottle and walk to the recycling bin. 1. Go to step 1.
Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles.
They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin. | First line of the input contains six integers *a**x*, *a**y*, *b**x*, *b**y*, *t**x* and *t**y* (0<=≤<=*a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*t**x*,<=*t**y*<=≤<=109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of bottles on the ground.
Then follow *n* lines, each of them contains two integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=109) — position of the *i*-th bottle.
It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct. | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . | [
"3 1 1 2 0 0\n3\n1 1\n2 1\n2 3\n",
"5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3\n"
] | [
"11.084259940083\n",
"33.121375178000\n"
] | Consider the first sample.
Adil will use the following path: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/37eea809c04afe04f2670475cc5b21df4a90afd1.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Bera will use the following path: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/08e917ff238fec015f897516a95529b6d9aed5c7.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Adil's path will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f58aa00f71a0b723b5de3c8e56ce41dc8afec7f8.png" style="max-width: 100.0%;max-height: 100.0%;"/> units long, while Bera's path will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3615db76a2cdd77d711b73d2894f03bdd52af736.png" style="max-width: 100.0%;max-height: 100.0%;"/> units long. | 500 | [
{
"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3",
"output": "11.084259940083"
},
{
"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3",
"output": "33.121375178000"
},
{
"input": "107 50 116 37 104 118\n12\n16 78\n95 113\n112 84\n5 88\n54 85\n112 80\n19 98\n25 14\n48 76\n95 70\n77 94\n38 32",
"output": "1576.895607473206"
},
{
"input": "446799 395535 281981 494983 755701 57488\n20\n770380 454998\n147325 211816\n818964 223521\n408463 253399\n49120 253709\n478114 283776\n909705 631953\n303154 889956\n126532 258846\n597028 708070\n147061 192478\n39515 879057\n911737 878857\n26966 701951\n616099 715301\n998385 735514\n277633 346417\n642301 188888\n617247 256225\n668067 352814",
"output": "22423982.398765542000"
},
{
"input": "0 0 214409724 980408402 975413181 157577991\n4\n390610378 473484159\n920351980 785918656\n706277914 753279807\n159291646 213569247",
"output": "4854671149.842136400000"
},
{
"input": "214409724 980408402 0 0 975413181 157577991\n4\n390610378 473484159\n920351980 785918656\n706277914 753279807\n159291646 213569247",
"output": "4854671149.842136400000"
},
{
"input": "383677880 965754167 658001115 941943959 0 0\n10\n9412 5230\n4896 7518\n3635 6202\n2365 1525\n241 1398\n7004 5166\n1294 9162\n3898 6706\n6135 8199\n4195 4410",
"output": "1039303750.884648200000"
},
{
"input": "825153337 326797826 774256604 103765336 0 0\n21\n6537 9734\n3998 8433\n560 7638\n1937 2557\n3487 244\n8299 4519\n73 9952\n2858 3719\n9267 5675\n9584 7636\n9234 1049\n7415 6018\n7653 9345\n7752 9628\n7476 8917\n7207 2352\n2602 4612\n1971 3307\n5530 3694\n2393 8573\n7506 9810",
"output": "781520533.726828810000"
},
{
"input": "214409724 980408402 975413181 157577991 0 0\n4\n3721 6099\n5225 4247\n940 340\n8612 7341",
"output": "988090959.937532070000"
},
{
"input": "235810013 344493922 0 0 975204641 211157253\n18\n977686151 621301932\n408277582 166435161\n595105725 194278844\n967498841 705149530\n551735395 659209387\n492239556 317614998\n741520864 843275770\n585383143 903832112\n272581169 285871890\n339100580 134101148\n920610054 824829107\n657996186 852771589\n948065129 573712142\n615254670 698346010\n365251531 883011553\n304877602 625498272\n418150850 280945187\n731399551 643859052",
"output": "20756961047.556908000000"
},
{
"input": "0 0 1 1 2 2\n1\n1 3",
"output": "3.414213562373"
},
{
"input": "10000 1000 151 121 10 10\n2\n1 1\n2 2",
"output": "227.449066182313"
},
{
"input": "5 5 10 10 15 15\n2\n1 1\n11 11",
"output": "32.526911934581"
},
{
"input": "1000000 1000000 1 1 0 0\n1\n2 2",
"output": "4.242640687119"
},
{
"input": "100 0 0 1 0 0\n2\n1 1\n1 2",
"output": "6.478708664619"
},
{
"input": "0 0 1000000000 1000000000 1 1\n2\n0 1\n1 0",
"output": "4.000000000000"
},
{
"input": "1000 1000 0 0 1 1\n1\n2 2",
"output": "4.242640687119"
},
{
"input": "1 0 1000000 0 0 0\n2\n1 1\n2 2",
"output": "7.892922226992"
},
{
"input": "3 0 100 100 0 0\n2\n1 0\n2 0",
"output": "5.000000000000"
},
{
"input": "0 100 0 101 0 0\n1\n0 99",
"output": "100.000000000000"
},
{
"input": "1000 1000 3 3 0 0\n2\n1 0\n0 1",
"output": "6.605551275464"
},
{
"input": "0 5 0 6 0 7\n1\n0 100",
"output": "187.000000000000"
},
{
"input": "1 1 1000000 1000000 0 0\n2\n1 2\n2 1",
"output": "7.708203932499"
},
{
"input": "1 0 10000000 1000000 0 0\n2\n1 1\n2 2",
"output": "7.892922226992"
},
{
"input": "2 2 10 2 6 5\n2\n6 2\n5 5",
"output": "9.000000000000"
},
{
"input": "100000001 100000001 100000000 100000000 1 1\n1\n1 0",
"output": "141421356.530202720000"
},
{
"input": "1000 1000 1001 1001 0 0\n2\n1 1\n2 2",
"output": "1417.041989497841"
},
{
"input": "1000000000 1000000000 999999999 999999999 1 1\n4\n1 2\n1 3\n2 2\n2 3",
"output": "1414213568.487842800000"
},
{
"input": "0 100 1 1 1 0\n2\n2 1\n0 1",
"output": "5.242640687119"
},
{
"input": "0 100 0 1 0 0\n5\n0 2\n0 3\n0 4\n0 5\n0 6",
"output": "39.000000000000"
},
{
"input": "100 0 0 100 0 0\n2\n0 1\n1 0",
"output": "102.000000000000"
},
{
"input": "0 0 1000000 1000000 0 1\n2\n1 1\n2 2",
"output": "6.886349517373"
},
{
"input": "0 0 1000 1000 1 0\n2\n1 1\n1 2",
"output": "6.236067977500"
},
{
"input": "1 0 100000 100000 0 0\n1\n2 0",
"output": "3.000000000000"
},
{
"input": "5 5 5 4 4 5\n2\n3 4\n3 5",
"output": "5.414213562373"
},
{
"input": "10000 10000 9000 9000 0 0\n3\n1 1\n2 2\n3 3",
"output": "12736.407342732093"
},
{
"input": "1 1 1000 1000 0 0\n3\n2 2\n3 3\n4 4",
"output": "24.041630560343"
},
{
"input": "7 0 8 0 0 0\n2\n1 0\n1 1",
"output": "9.496976092671"
},
{
"input": "1 3 3 3 2 1\n2\n2 3\n3 1",
"output": "5.000000000000"
},
{
"input": "1 2 3 4 5 6\n1\n1 1",
"output": "7.403124237433"
},
{
"input": "1000000000 1000000000 0 0 1 1\n5\n2 2\n2 3\n2 4\n2 5\n2 6",
"output": "33.294904485247"
},
{
"input": "2 1 1 2 0 0\n1\n1 1",
"output": "2.414213562373"
},
{
"input": "1 0 100000 0 0 0\n2\n1 1\n2 2",
"output": "7.892922226992"
},
{
"input": "0 100 1 100 1 0\n2\n2 1\n0 1",
"output": "103.242640687119"
},
{
"input": "0 0 2 0 1 5\n2\n1 0\n1 20",
"output": "36.000000000000"
},
{
"input": "1000 1000 999 999 0 0\n2\n1 0\n0 1",
"output": "1415.092419071783"
},
{
"input": "5 0 1000 1000 2 0\n2\n4 0\n6 7",
"output": "19.124515496597"
},
{
"input": "10000 0 1000000 0 0 0\n2\n1 1\n2 2",
"output": "10003.657054289499"
},
{
"input": "0 100 0 101 0 0\n2\n0 1\n0 2",
"output": "102.000000000000"
},
{
"input": "0 0 10000 10000 1 0\n2\n2 0\n3 0",
"output": "7.000000000000"
},
{
"input": "3 1 1 2 0 0\n1\n1 1",
"output": "2.414213562373"
},
{
"input": "1000 0 0 1000 0 0\n2\n1 0\n0 1",
"output": "1002.000000000000"
},
{
"input": "1 1 1000000 1000000 0 0\n2\n2 1\n1 2",
"output": "7.708203932499"
},
{
"input": "1000 1000 2000 2000 1 1\n3\n2 2\n1 2\n3 3",
"output": "1417.627775935468"
},
{
"input": "0 0 1000000000 1000000000 1 1\n4\n2 2\n3 3\n4 4\n5 5",
"output": "29.698484809835"
},
{
"input": "10000000 1 2 1 1 1\n3\n1 3\n1 4\n1 5",
"output": "18.123105625618"
},
{
"input": "3 7 5 7 4 4\n2\n4 6\n4 0",
"output": "11.414213562373"
},
{
"input": "0 0 3 0 1 5\n2\n1 0\n1 20",
"output": "36.000000000000"
},
{
"input": "0 0 0 1 1000 3\n2\n1000 2\n1000 1",
"output": "1004.000000000000"
},
{
"input": "1000000000 0 0 1 0 0\n2\n0 2\n0 3",
"output": "9.000000000000"
},
{
"input": "0 1000000000 1000000000 0 0 0\n1\n1 1",
"output": "1000000000.414213500000"
},
{
"input": "1000 1000 1000 1001 0 0\n2\n0 1\n1 1",
"output": "1416.213562373095"
},
{
"input": "1002 0 1001 0 0 0\n1\n1000 0",
"output": "1001.000000000000"
},
{
"input": "1002 0 1001 0 0 0\n2\n2 0\n1 0",
"output": "1003.000000000000"
},
{
"input": "3 0 0 100 0 0\n2\n1 0\n2 0",
"output": "5.000000000000"
},
{
"input": "10 10 0 0 0 1\n2\n1 0\n1 1",
"output": "4.414213562373"
},
{
"input": "1000 1000 1001 1001 0 0\n2\n0 1\n1 1",
"output": "1416.213562373095"
},
{
"input": "0 100 0 200 0 0\n2\n0 1\n0 2",
"output": "102.000000000000"
},
{
"input": "100 100 0 0 1 1\n1\n2 2",
"output": "4.242640687119"
},
{
"input": "123123 154345 123123 123123 2 2\n3\n3 3\n4 4\n5 5",
"output": "174127.873294312070"
},
{
"input": "0 1 0 2 0 0\n1\n1 0",
"output": "2.414213562373"
},
{
"input": "1 2 3 4 1000 1000\n1\n156 608",
"output": "1553.668251715911"
},
{
"input": "0 0 10 0 5 0\n3\n4 1\n5 1\n6 1",
"output": "10.365746312737"
},
{
"input": "0 0 0 1 1000000000 999999999\n1\n1000000000 1000000000",
"output": "1414213562.665988200000"
},
{
"input": "1231231 2342342 123124 123151 12315 12312\n1\n354345 234234",
"output": "664238.053973730540"
},
{
"input": "0 0 1000000 0 1 1\n2\n0 1\n3 0",
"output": "6.472135955000"
},
{
"input": "1000 1000 2000 2000 1 1\n1\n2 2",
"output": "1412.799348810722"
},
{
"input": "10 20 10 0 10 10\n2\n10 11\n10 9",
"output": "12.000000000000"
},
{
"input": "1000000000 1 1 1000000000 0 0\n1\n2 2",
"output": "1000000000.828427200000"
},
{
"input": "0 0 1000 1000 1 0\n2\n2 0\n3 0",
"output": "7.000000000000"
},
{
"input": "1000 0 100000000 100000000 0 0\n2\n999 0\n1100 0",
"output": "3198.000000000000"
},
{
"input": "2 2 1000000000 1000000000 0 0\n3\n1 1\n5 5\n100 100",
"output": "296.984848098350"
},
{
"input": "2 0 4 0 0 0\n1\n3 0",
"output": "4.000000000000"
},
{
"input": "2 2 1000 1000 0 0\n2\n1 1\n1 2",
"output": "6.064495102246"
},
{
"input": "0 0 1000000000 1000000000 0 1\n3\n1 0\n2 0\n3 0",
"output": "13.210904837709"
},
{
"input": "1 10000 10000 1 0 0\n2\n1 100\n100 1",
"output": "10200.014999625020"
},
{
"input": "5 0 6 0 0 0\n2\n2 0\n0 2",
"output": "9.000000000000"
},
{
"input": "2 4 1000000000 1000000000 0 0\n4\n2 3\n2 1\n3 2\n1 2",
"output": "20.760925736391"
},
{
"input": "0 100 1 1 0 0\n2\n0 1\n3 1",
"output": "7.162277660168"
},
{
"input": "0 0 10 0 8 2\n1\n6 0",
"output": "6.828427124746"
},
{
"input": "0 9 0 8 0 1\n1\n0 0",
"output": "9.000000000000"
},
{
"input": "100 0 0 100 0 0\n2\n40 0\n0 40",
"output": "180.000000000000"
},
{
"input": "0 0 0 1 1000 3\n2\n1000 1\n1000 2",
"output": "1004.000000000000"
},
{
"input": "1 1 123123 123123 2 2\n3\n3 3\n4 4\n5 5",
"output": "18.384776310850"
},
{
"input": "999999999 999999999 1000000000 1000000000 1 1\n1\n1 0",
"output": "1414213561.251774800000"
},
{
"input": "3 2 1 1 0 0\n1\n2 2",
"output": "3.828427124746"
},
{
"input": "0 0 1 1 100 100\n2\n101 101\n102 102",
"output": "148.492424049175"
},
{
"input": "1 15 4 10 1 1\n2\n1 10\n4 5",
"output": "22.000000000000"
},
{
"input": "100 0 0 100 0 0\n2\n60 0\n0 40",
"output": "180.000000000000"
},
{
"input": "0 0 0 1000 1 0\n4\n0 1\n0 2\n0 3\n0 4",
"output": "21.457116088945"
},
{
"input": "0 0 100 0 3 0\n1\n2 0",
"output": "3.000000000000"
},
{
"input": "0 0 100 0 98 2\n1\n98 0",
"output": "4.000000000000"
},
{
"input": "1 1 2 2 3 3\n1\n0 0",
"output": "5.656854249492"
},
{
"input": "2 2 1 1 0 0\n1\n1 2",
"output": "3.236067977500"
},
{
"input": "10000000 1 2 1 1 1\n3\n1 40\n1 20\n1 5",
"output": "124.012818406262"
},
{
"input": "1000 1000 1001 1000 0 0\n3\n1 1\n1 2\n1 3",
"output": "1421.848684511914"
},
{
"input": "10000 10000 9999 9999 0 0\n3\n0 1\n0 2\n0 3",
"output": "14147.600248963827"
}
] | 1,498,888,563 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 93 | 23,142,400 | ax,ay,bx,by,tx,ty=map(int,input().split())
od=[]
co=[]
objects=int(input())
for i in range(objects):
x,y=map(int,input().split())
od.append(((tx-x)**2+(ty-y)**2)**0.5)
co.append([x,y])
asaved=[0,0]
asaved2=[0,0]
for i in range(objects):
x=co[i][0]
y=co[i][1]
saved=od[i]-((ax-x)**2+(ay-y)**2)**0.5
if saved>asaved[0]:
asaved2[0]=asaved[0]
asaved2[1]=asaved[1]
asaved[0]=saved
asaved[1]=i
elif saved==asaved[0]:
asaved2[0]=asaved[0]
asaved2[1]=asaved[1]
asaved[1]=i
bsaved=[0,0]
bsaved2=[0,0]
for i in range(objects):
x=co[i][0]
y=co[i][1]
saved=od[i]-((bx-x)**2+(by-y)**2)**0.5
if saved>bsaved[0]:
bsaved2[1]=bsaved[1]
bsaved2[0]=bsaved[0]
bsaved[0]=saved
bsaved[1]=i
elif saved==bsaved[0]:
bsaved2[1]=bsaved[1]
bsaved2[0]=bsaved[0]
bsaved[1]=i
tot=2*sum(od)
if bsaved[1]==asaved[1]:
if bsaved2[0]>asaved2[0]:
tot-=asaved[0]+bsaved2[0]
else:
tot-=asaved2[0]+bsaved[0]
else:
tot-=asaved[0]+bsaved[0]
print(tot)
| Title: Recycling Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are *n* bottles on the ground, the *i*-th bottle is located at position (*x**i*,<=*y**i*). Both Adil and Bera can carry only one bottle at once each.
For both Adil and Bera the process looks as follows:
1. Choose to stop or to continue to collect bottles. 1. If the choice was to continue then choose some bottle and walk towards it. 1. Pick this bottle and walk to the recycling bin. 1. Go to step 1.
Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles.
They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.
Input Specification:
First line of the input contains six integers *a**x*, *a**y*, *b**x*, *b**y*, *t**x* and *t**y* (0<=≤<=*a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*t**x*,<=*t**y*<=≤<=109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of bottles on the ground.
Then follow *n* lines, each of them contains two integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=109) — position of the *i*-th bottle.
It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.
Output Specification:
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
Demo Input:
['3 1 1 2 0 0\n3\n1 1\n2 1\n2 3\n', '5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3\n']
Demo Output:
['11.084259940083\n', '33.121375178000\n']
Note:
Consider the first sample.
Adil will use the following path: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/37eea809c04afe04f2670475cc5b21df4a90afd1.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Bera will use the following path: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/08e917ff238fec015f897516a95529b6d9aed5c7.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Adil's path will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f58aa00f71a0b723b5de3c8e56ce41dc8afec7f8.png" style="max-width: 100.0%;max-height: 100.0%;"/> units long, while Bera's path will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3615db76a2cdd77d711b73d2894f03bdd52af736.png" style="max-width: 100.0%;max-height: 100.0%;"/> units long. | ```python
ax,ay,bx,by,tx,ty=map(int,input().split())
od=[]
co=[]
objects=int(input())
for i in range(objects):
x,y=map(int,input().split())
od.append(((tx-x)**2+(ty-y)**2)**0.5)
co.append([x,y])
asaved=[0,0]
asaved2=[0,0]
for i in range(objects):
x=co[i][0]
y=co[i][1]
saved=od[i]-((ax-x)**2+(ay-y)**2)**0.5
if saved>asaved[0]:
asaved2[0]=asaved[0]
asaved2[1]=asaved[1]
asaved[0]=saved
asaved[1]=i
elif saved==asaved[0]:
asaved2[0]=asaved[0]
asaved2[1]=asaved[1]
asaved[1]=i
bsaved=[0,0]
bsaved2=[0,0]
for i in range(objects):
x=co[i][0]
y=co[i][1]
saved=od[i]-((bx-x)**2+(by-y)**2)**0.5
if saved>bsaved[0]:
bsaved2[1]=bsaved[1]
bsaved2[0]=bsaved[0]
bsaved[0]=saved
bsaved[1]=i
elif saved==bsaved[0]:
bsaved2[1]=bsaved[1]
bsaved2[0]=bsaved[0]
bsaved[1]=i
tot=2*sum(od)
if bsaved[1]==asaved[1]:
if bsaved2[0]>asaved2[0]:
tot-=asaved[0]+bsaved2[0]
else:
tot-=asaved2[0]+bsaved[0]
else:
tot-=asaved[0]+bsaved[0]
print(tot)
``` | 0 |
|
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).
Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different. | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{
"input": "6\n5083 3289 7708 5362 9031 7458",
"output": "5 7708"
},
{
"input": "7\n9038 6222 3392 1706 3778 1807 2657",
"output": "1 6222"
},
{
"input": "8\n7062 2194 4481 3864 7470 1814 8091 733",
"output": "7 7470"
},
{
"input": "9\n2678 5659 9199 2628 7906 7496 4524 2663 3408",
"output": "3 7906"
},
{
"input": "2\n3458 1504",
"output": "1 1504"
},
{
"input": "50\n9237 3904 407 9052 6657 9229 9752 3888 7732 2512 4614 1055 2355 7108 6506 6849 2529 8862 159 8630 7906 7941 960 8470 333 8659 54 9475 3163 5625 6393 6814 2656 3388 169 7918 4881 8468 9983 6281 6340 280 5108 2996 101 7617 3313 8172 326 1991",
"output": "39 9752"
},
{
"input": "100\n2515 3324 7975 6171 4240 1217 4829 5203 8603 6900 3031 4699 4732 6070 4221 3228 6497 7359 9130 4346 4619 1109 3945 5442 3271 16 9711 2045 6410 2301 3406 8125 6003 1892 1260 9661 3940 6692 4708 7027 4930 6925 1979 5361 4263 3144 867 8639 6230 5562 9714 3676 4231 3347 4733 4920 4881 3431 1059 7313 8912 3038 9308 72 9583 7009 3034 7425 2398 6141 3245 2495 2933 6710 8289 9806 1226 8393 7349 6462 1618 9613 3546 6012 2964 9995 1578 210 2123 4874 1252 8625 348 8020 803 7244 9080 5088 706 2602",
"output": "86 9806"
},
{
"input": "2\n2 1",
"output": "1 1"
},
{
"input": "2\n1 2",
"output": "2 1"
},
{
"input": "3\n10 20 30",
"output": "3 20"
},
{
"input": "3\n10 30 20",
"output": "2 20"
},
{
"input": "3\n20 10 30",
"output": "3 20"
},
{
"input": "3\n20 30 10",
"output": "2 20"
},
{
"input": "3\n30 10 20",
"output": "1 20"
},
{
"input": "3\n30 20 10",
"output": "1 20"
},
{
"input": "2\n1 10000",
"output": "2 1"
},
{
"input": "2\n10000 999",
"output": "1 999"
},
{
"input": "3\n3 4 1",
"output": "2 3"
},
{
"input": "6\n1 2 24 6 5 7",
"output": "3 7"
}
] | 1,596,180,077 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 140 | 20,172,800 | n=int(input())
lst=list(map(int,input().split()))
q=lst.index(max(lst))+1
lst.sort()
p=lst[-2]
print(q,p) | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).
Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.
Input Specification:
The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder.
Output Specification:
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
Demo Input:
['2\n5 7\n', '3\n10 2 8\n', '6\n3 8 2 9 4 14\n']
Demo Output:
['2 5\n', '1 8\n', '6 9\n']
Note:
none | ```python
n=int(input())
lst=list(map(int,input().split()))
q=lst.index(max(lst))+1
lst.sort()
p=lst[-2]
print(q,p)
``` | 3 |
|
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,653,226,271 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | import math
m,n,a=map(int,input().split())
d=math.ceil(m/a)+math.ceil(n/a)
print(d)
| 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 math
m,n,a=map(int,input().split())
d=math.ceil(m/a)+math.ceil(n/a)
print(d)
``` | 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,473,801,605 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 154 | 0 | a = input()
b = list(map(int,input().split()))
c = []
d = []
for i in b:
if i/2 == i//2:
c.append(i)
else:
d.append(i)
if len(c) == 1:
print(b.index(c[0])+1)
else:
print(b.index(d[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
a = input()
b = list(map(int,input().split()))
c = []
d = []
for i in b:
if i/2 == i//2:
c.append(i)
else:
d.append(i)
if len(c) == 1:
print(b.index(c[0])+1)
else:
print(b.index(d[0])+1)
``` | 3.9615 |
559 | A | Gerald's Hexagon | PROGRAMMING | 1,600 | [
"brute force",
"geometry",
"math"
] | null | null | Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. | The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. | Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. | [
"1 1 1 1 1 1\n",
"1 2 1 2 1 2\n"
] | [
"6\n",
"13\n"
] | This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 500 | [
{
"input": "1 1 1 1 1 1",
"output": "6"
},
{
"input": "1 2 1 2 1 2",
"output": "13"
},
{
"input": "2 4 5 3 3 6",
"output": "83"
},
{
"input": "45 19 48 18 46 21",
"output": "6099"
},
{
"input": "66 6 65 6 66 5",
"output": "5832"
},
{
"input": "7 5 4 8 4 5",
"output": "175"
},
{
"input": "3 2 1 4 1 2",
"output": "25"
},
{
"input": "7 1 7 3 5 3",
"output": "102"
},
{
"input": "9 2 9 3 8 3",
"output": "174"
},
{
"input": "1 6 1 5 2 5",
"output": "58"
},
{
"input": "41 64 48 61 44 68",
"output": "17488"
},
{
"input": "1 59 2 59 1 60",
"output": "3838"
},
{
"input": "30 36 36 32 34 38",
"output": "7052"
},
{
"input": "50 40 46 38 52 34",
"output": "11176"
},
{
"input": "4 60 4 60 4 60",
"output": "4576"
},
{
"input": "718 466 729 470 714 481",
"output": "2102808"
},
{
"input": "131 425 143 461 95 473",
"output": "441966"
},
{
"input": "125 7 128 8 124 11",
"output": "20215"
},
{
"input": "677 303 685 288 692 296",
"output": "1365807"
},
{
"input": "1 577 7 576 2 582",
"output": "342171"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "6000000"
},
{
"input": "1 1 1000 1 1 1000",
"output": "4002"
},
{
"input": "1000 1000 1 1000 1000 1",
"output": "2004000"
},
{
"input": "1000 1 1000 999 2 999",
"output": "2003997"
},
{
"input": "1 1000 1 1 1000 1",
"output": "4002"
},
{
"input": "888 888 888 887 889 887",
"output": "4729487"
}
] | 1,559,806,849 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 | def input_ints():
return list(map(int, input().split()))
def output_list(v):
print(' '.join(str(x) for x in v))
def main():
a = input_ints()
ans = 0
x = a[0]
for i in range(a[1] + a[2]):
d = 0
d += (1 if i < a[1] else -1)
d += (1 if i < a[5] else -1)
d //= 2
ans += 2 * x + d
x += d
print(ans)
if __name__ == '__main__':
main()
| Title: Gerald's Hexagon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.
Input Specification:
The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.
Output Specification:
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
Demo Input:
['1 1 1 1 1 1\n', '1 2 1 2 1 2\n']
Demo Output:
['6\n', '13\n']
Note:
This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
def input_ints():
return list(map(int, input().split()))
def output_list(v):
print(' '.join(str(x) for x in v))
def main():
a = input_ints()
ans = 0
x = a[0]
for i in range(a[1] + a[2]):
d = 0
d += (1 if i < a[1] else -1)
d += (1 if i < a[5] else -1)
d //= 2
ans += 2 * x + d
x += d
print(ans)
if __name__ == '__main__':
main()
``` | 3 |
|
478 | C | Table Decorations | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values *r*, *g* and *b* will find the maximum number *t* of tables, that can be decorated in the required manner. | The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space. | Print a single integer *t* — the maximum number of tables that can be decorated in the required manner. | [
"5 4 3\n",
"1 1 1\n",
"2 3 3\n"
] | [
"4\n",
"1\n",
"2\n"
] | In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively. | 1,500 | [
{
"input": "5 4 3",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "0 3 3",
"output": "2"
},
{
"input": "4 0 4",
"output": "2"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "100 99 56",
"output": "85"
},
{
"input": "1000 1000 1002",
"output": "1000"
},
{
"input": "0 1 1000000000",
"output": "1"
},
{
"input": "500000000 1000000000 500000000",
"output": "666666666"
},
{
"input": "1000000000 2000000000 1000000000",
"output": "1333333333"
},
{
"input": "2000000000 2000000000 2000000000",
"output": "2000000000"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "1 2000000000 1000000000",
"output": "1000000000"
},
{
"input": "1585222789 1889821127 2000000000",
"output": "1825014638"
},
{
"input": "10000 7500 7500",
"output": "8333"
},
{
"input": "150000 75000 75000",
"output": "100000"
},
{
"input": "999288131 55884921 109298382",
"output": "165183303"
},
{
"input": "100500 100500 3",
"output": "67001"
},
{
"input": "1463615122 1988383731 837331500",
"output": "1429776784"
},
{
"input": "1938 8999 1882",
"output": "3820"
},
{
"input": "45 33 76",
"output": "51"
},
{
"input": "100000 1 2",
"output": "3"
},
{
"input": "198488 50 18",
"output": "68"
},
{
"input": "82728372 939848 100139442",
"output": "61269220"
},
{
"input": "99 5747 5298",
"output": "3714"
},
{
"input": "3 5 2",
"output": "3"
},
{
"input": "7511 7512 7513",
"output": "7512"
},
{
"input": "1234567890 123456789 987654321",
"output": "781893000"
},
{
"input": "500000000 2000000000 500000000",
"output": "1000000000"
},
{
"input": "500000002 2000000000 500000001",
"output": "1000000001"
},
{
"input": "520000000 1000000033 501000000",
"output": "673666677"
},
{
"input": "10000 1000 100000",
"output": "11000"
},
{
"input": "2000000000 500000000 499999999",
"output": "999999999"
},
{
"input": "1999999999 500000000 500000000",
"output": "999999999"
},
{
"input": "1 1 9",
"output": "2"
},
{
"input": "3 0 0",
"output": "0"
},
{
"input": "6 1 1",
"output": "2"
},
{
"input": "2000000000 1999999999 1999999999",
"output": "1999999999"
},
{
"input": "3 4 9",
"output": "5"
},
{
"input": "3 3 6",
"output": "4"
}
] | 1,678,147,829 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 14 | 62 | 0 | a = list(map(int , input().split()))
a.sort()
print((sum(a)//3 if (a[2] <= a[1] + a[0]) else a[1] + a[0])) | Title: Table Decorations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values *r*, *g* and *b* will find the maximum number *t* of tables, that can be decorated in the required manner.
Input Specification:
The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
Output Specification:
Print a single integer *t* — the maximum number of tables that can be decorated in the required manner.
Demo Input:
['5 4 3\n', '1 1 1\n', '2 3 3\n']
Demo Output:
['4\n', '1\n', '2\n']
Note:
In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively. | ```python
a = list(map(int , input().split()))
a.sort()
print((sum(a)//3 if (a[2] <= a[1] + a[0]) else a[1] + a[0]))
``` | 0 |
|
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula .
The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=<<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances. | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
"input": "2\n315 845\n-669 -762",
"output": "0"
},
{
"input": "3\n8911 7861\n-6888 7861\n8911 7861",
"output": "3"
},
{
"input": "2\n-1 1000000000\n0 -1",
"output": "0"
},
{
"input": "2\n1000000000 0\n-7 1",
"output": "0"
},
{
"input": "2\n1 4\n2 1",
"output": "0"
},
{
"input": "2\n1 0\n0 2333333",
"output": "0"
},
{
"input": "2\n2 1\n1 2",
"output": "0"
},
{
"input": "2\n1 1000000000\n2 -1000000000",
"output": "0"
},
{
"input": "2\n0 1000000000\n1 -7",
"output": "0"
},
{
"input": "2\n1 0\n0 19990213",
"output": "0"
}
] | 1,518,216,250 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 5,632,000 | def choose2(n):
return n*(n-1)//2
xs = set()
ys = set()
ps = set()
n = int(input())
p = []
for _ in range(n):
x, y = [int(x) for x in input().split()]
xs.add(x)
ys.add(y)
ps.add((x,y))
rep_x = (n-len(xs)+1)
rep_y = (n-len(ys)+1)
rep_p = (n-len(ps)+1)
n_rep = choose2(rep_x)+choose2(rep_y)-choose2(rep_p)
print(n_rep) | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula .
The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=<<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
Input Specification:
The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide.
Output Specification:
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Demo Input:
['3\n1 1\n7 5\n1 5\n', '6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n']
Demo Output:
['2\n', '11\n']
Note:
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances. | ```python
def choose2(n):
return n*(n-1)//2
xs = set()
ys = set()
ps = set()
n = int(input())
p = []
for _ in range(n):
x, y = [int(x) for x in input().split()]
xs.add(x)
ys.add(y)
ps.add((x,y))
rep_x = (n-len(xs)+1)
rep_y = (n-len(ys)+1)
rep_p = (n-len(ps)+1)
n_rep = choose2(rep_x)+choose2(rep_y)-choose2(rep_p)
print(n_rep)
``` | 0 |
|
955 | A | Feed the cat | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs *C* roubles and decreases hunger by *N* points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.
Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero. | The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102). | Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . | [
"19 00\n255 1 100 1\n",
"17 41\n1000 6 15 11\n"
] | [
"25200.0000\n",
"1365.0000\n"
] | In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles. | 500 | [
{
"input": "19 00\n255 1 100 1",
"output": "25200.0000"
},
{
"input": "17 41\n1000 6 15 11",
"output": "1365.0000"
},
{
"input": "16 34\n61066 14 50 59",
"output": "43360.0000"
},
{
"input": "18 18\n23331 86 87 41",
"output": "49590.0000"
},
{
"input": "10 48\n68438 8 18 29",
"output": "36187.2000"
},
{
"input": "08 05\n63677 9 83 25",
"output": "186252.0000"
},
{
"input": "00 00\n100000 100 100 100",
"output": "100000.0000"
},
{
"input": "20 55\n100000 100 100 100",
"output": "80000.0000"
},
{
"input": "23 59\n100000 100 100 100",
"output": "80000.0000"
},
{
"input": "00 00\n1 100 100 100",
"output": "100.0000"
},
{
"input": "21 26\n33193 54 97 66",
"output": "39032.8000"
},
{
"input": "20 45\n33756 24 21 1",
"output": "567100.8000"
},
{
"input": "14 33\n92062 59 89 72",
"output": "110146.4000"
},
{
"input": "01 24\n92730 5 35 29",
"output": "94920.0000"
},
{
"input": "20 58\n93398 43 86 99",
"output": "64947.2000"
},
{
"input": "23 04\n37170 81 32 64",
"output": "14873.6000"
},
{
"input": "01 38\n70542 27 74 26",
"output": "200836.0000"
},
{
"input": "04 28\n38505 65 25 95",
"output": "10150.0000"
},
{
"input": "00 10\n33077 21 40 22",
"output": "60160.0000"
},
{
"input": "10 44\n66449 67 90 83",
"output": "72090.0000"
},
{
"input": "05 51\n10220 5 33 48",
"output": "7029.0000"
},
{
"input": "20 19\n68886 28 48 94",
"output": "28147.2000"
},
{
"input": "01 49\n11621 55 78 46",
"output": "19734.0000"
},
{
"input": "21 28\n78549 91 4 98",
"output": "2566.4000"
},
{
"input": "18 06\n88580 22 35 59",
"output": "43232.0000"
},
{
"input": "22 28\n55507 53 61 11",
"output": "246293.6000"
},
{
"input": "18 58\n22434 84 91 59",
"output": "34143.2000"
},
{
"input": "15 36\n32466 27 22 15",
"output": "46464.0000"
},
{
"input": "17 31\n9603 53 73 74",
"output": "9490.0000"
},
{
"input": "14 53\n76530 92 4 22",
"output": "13916.0000"
},
{
"input": "18 31\n10753 23 30 74",
"output": "4152.0000"
},
{
"input": "17 43\n16290 46 90 94",
"output": "15660.0000"
},
{
"input": "18 38\n3652 11 53 94",
"output": "2067.0000"
},
{
"input": "19 57\n3 4 7 6",
"output": "7.0000"
}
] | 1,522,237,906 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 78 | 7,372,800 | from math import ceil
H,M=input().split()
h,d,c,n=input().split()
H,M,h,d,c,n=int(H),int(M),int(h),int(d),int(c),int(n)
if H<20:
print(min(ceil(h/n)*c,ceil((h+d*(1200-H*60-M))/n)*0.8*c))
else:
print(ceil(h/n)*0.8*c) | Title: Feed the cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs *C* roubles and decreases hunger by *N* points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.
Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero.
Input Specification:
The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102).
Output Specification:
Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
Demo Input:
['19 00\n255 1 100 1\n', '17 41\n1000 6 15 11\n']
Demo Output:
['25200.0000\n', '1365.0000\n']
Note:
In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles. | ```python
from math import ceil
H,M=input().split()
h,d,c,n=input().split()
H,M,h,d,c,n=int(H),int(M),int(h),int(d),int(c),int(n)
if H<20:
print(min(ceil(h/n)*c,ceil((h+d*(1200-H*60-M))/n)*0.8*c))
else:
print(ceil(h/n)*0.8*c)
``` | 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,587,919,152 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 108 | 0 | n=int(input())
stroka=input()
SF=0
FS=0
plusiki=0
while plusiki<n-1:
if stroka[plusiki]=='S' and stroka[plusiki+1]=='F':
SF=SF+1
if stroka[plusiki]=='F' and stroka[plusiki+1]=='S':
FS=FS+1
plusiki=plusiki+1
if SF>FS:
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())
stroka=input()
SF=0
FS=0
plusiki=0
while plusiki<n-1:
if stroka[plusiki]=='S' and stroka[plusiki+1]=='F':
SF=SF+1
if stroka[plusiki]=='F' and stroka[plusiki+1]=='S':
FS=FS+1
plusiki=plusiki+1
if SF>FS:
print('YES')
else:
print('NO')
``` | 3 |
|
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -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": "13"
},
{
"input": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 1,687,782,009 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | n=int(input())
l=[int(i) for i in input().split()]
x=l[0]
count=0
c=0
if l[0]==-1:
count+=1
for i in range(1,len(l)):
if l[i]==-1:
if c>0:
c-=1
else:
count+=1
else:
c+=i
print(count) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input Specification:
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output Specification:
Print a single integer, the number of crimes which will go untreated.
Demo Input:
['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n']
Demo Output:
['2\n', '1\n', '8\n']
Note:
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | ```python
n=int(input())
l=[int(i) for i in input().split()]
x=l[0]
count=0
c=0
if l[0]==-1:
count+=1
for i in range(1,len(l)):
if l[i]==-1:
if c>0:
c-=1
else:
count+=1
else:
c+=i
print(count)
``` | 0 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,695,225,728 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | x = input
y = input
y = y [ : : -1 ]
if x ==y:
print("yes")
else :
print ("no")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
x = input
y = input
y = y [ : : -1 ]
if x ==y:
print("yes")
else :
print ("no")
``` | -1 |
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv",
"output": "NO"
},
{
"input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "YES"
},
{
"input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod",
"output": "NO"
},
{
"input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl",
"output": "YES"
},
{
"input": "18 6\njzwtnkvmscqhmdlsxy",
"output": "YES"
},
{
"input": "21 2\nfscegcqgzesefghhwcexs",
"output": "NO"
},
{
"input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc",
"output": "YES"
},
{
"input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd",
"output": "YES"
},
{
"input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv",
"output": "YES"
},
{
"input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul",
"output": "YES"
},
{
"input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii",
"output": "NO"
},
{
"input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq",
"output": "YES"
},
{
"input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb",
"output": "YES"
},
{
"input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc",
"output": "YES"
},
{
"input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab",
"output": "YES"
},
{
"input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia",
"output": "NO"
},
{
"input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf",
"output": "YES"
},
{
"input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb",
"output": "YES"
},
{
"input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa",
"output": "NO"
},
{
"input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo",
"output": "YES"
},
{
"input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib",
"output": "YES"
},
{
"input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf",
"output": "YES"
},
{
"input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci",
"output": "YES"
},
{
"input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn",
"output": "YES"
},
{
"input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev",
"output": "YES"
},
{
"input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss",
"output": "YES"
},
{
"input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs",
"output": "NO"
},
{
"input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc",
"output": "NO"
},
{
"input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi",
"output": "NO"
},
{
"input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah",
"output": "NO"
},
{
"input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka",
"output": "YES"
},
{
"input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq",
"output": "YES"
},
{
"input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb",
"output": "YES"
},
{
"input": "14 5\nfssmmsfffmfmmm",
"output": "NO"
},
{
"input": "2 1\nff",
"output": "NO"
},
{
"input": "2 1\nhw",
"output": "YES"
},
{
"input": "2 2\nss",
"output": "YES"
},
{
"input": "1 1\nl",
"output": "YES"
},
{
"input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp",
"output": "YES"
},
{
"input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj",
"output": "YES"
},
{
"input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj",
"output": "YES"
},
{
"input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "YES"
},
{
"input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq",
"output": "YES"
},
{
"input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt",
"output": "YES"
},
{
"input": "1 2\na",
"output": "YES"
},
{
"input": "3 1\nabb",
"output": "NO"
},
{
"input": "2 1\naa",
"output": "NO"
},
{
"input": "2 1\nab",
"output": "YES"
},
{
"input": "6 2\naaaaaa",
"output": "NO"
},
{
"input": "8 4\naaaaaaaa",
"output": "NO"
},
{
"input": "4 2\naaaa",
"output": "NO"
},
{
"input": "4 3\naaaa",
"output": "NO"
},
{
"input": "1 3\na",
"output": "YES"
},
{
"input": "4 3\nzzzz",
"output": "NO"
},
{
"input": "4 1\naaaa",
"output": "NO"
},
{
"input": "3 4\nabc",
"output": "YES"
},
{
"input": "2 5\nab",
"output": "YES"
},
{
"input": "2 4\nab",
"output": "YES"
},
{
"input": "1 10\na",
"output": "YES"
},
{
"input": "5 2\nzzzzz",
"output": "NO"
},
{
"input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO"
},
{
"input": "4 1\nabab",
"output": "NO"
},
{
"input": "4 1\nabcb",
"output": "NO"
},
{
"input": "4 2\nabbb",
"output": "NO"
},
{
"input": "5 2\nabccc",
"output": "NO"
},
{
"input": "2 3\nab",
"output": "YES"
},
{
"input": "4 3\nbbbs",
"output": "YES"
},
{
"input": "10 2\nazzzzzzzzz",
"output": "NO"
},
{
"input": "1 2\nb",
"output": "YES"
},
{
"input": "1 3\nb",
"output": "YES"
},
{
"input": "4 5\nabcd",
"output": "YES"
},
{
"input": "4 6\naabb",
"output": "YES"
},
{
"input": "5 2\naaaab",
"output": "NO"
},
{
"input": "3 5\naaa",
"output": "YES"
},
{
"input": "5 3\nazzzz",
"output": "NO"
},
{
"input": "4 100\naabb",
"output": "YES"
},
{
"input": "3 10\naaa",
"output": "YES"
},
{
"input": "3 4\naaa",
"output": "YES"
},
{
"input": "12 5\naaaaabbbbbbb",
"output": "NO"
},
{
"input": "5 2\naabbb",
"output": "NO"
},
{
"input": "10 5\nzzzzzzzzzz",
"output": "NO"
},
{
"input": "2 4\naa",
"output": "YES"
},
{
"input": "1 5\na",
"output": "YES"
},
{
"input": "10 5\naaaaaaaaaa",
"output": "NO"
},
{
"input": "6 3\naaaaaa",
"output": "NO"
},
{
"input": "7 1\nabcdeee",
"output": "NO"
},
{
"input": "18 3\naaaaaabbbbbbcccccc",
"output": "NO"
},
{
"input": "8 2\naabbccdd",
"output": "YES"
},
{
"input": "4 2\nzzzz",
"output": "NO"
},
{
"input": "4 2\nabaa",
"output": "NO"
},
{
"input": "3 2\naaa",
"output": "NO"
},
{
"input": "3 1\nzzz",
"output": "NO"
},
{
"input": "5 4\nzzzzz",
"output": "NO"
},
{
"input": "6 2\naabbbc",
"output": "NO"
},
{
"input": "3 6\naaa",
"output": "YES"
},
{
"input": "2 1\nzz",
"output": "NO"
},
{
"input": "10 3\naaaeeeeeee",
"output": "NO"
},
{
"input": "4 5\naabb",
"output": "YES"
},
{
"input": "3 1\naaa",
"output": "NO"
},
{
"input": "5 2\naazzz",
"output": "NO"
},
{
"input": "6 2\nabbbbc",
"output": "NO"
},
{
"input": "4 2\nxxxx",
"output": "NO"
},
{
"input": "6 3\nzzzzzz",
"output": "NO"
},
{
"input": "3 2\nabb",
"output": "YES"
},
{
"input": "3 2\nzzz",
"output": "NO"
},
{
"input": "6 5\nzzzzzz",
"output": "NO"
},
{
"input": "6 3\nbcaaaa",
"output": "NO"
},
{
"input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "3 6\nabc",
"output": "YES"
}
] | 1,623,923,671 | 2,147,483,647 | Python 3 | OK | TESTS | 114 | 62 | 0 | n, k = map(int, input().split())
s, a = input(), []
b = [x for x in s]
for i in set(b):
a.append(s.count(i))
print("YES" if k >= max(a) else "NO") | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons.
Output Specification:
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Demo Input:
['4 2\naabb\n', '6 3\naacaab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | ```python
n, k = map(int, input().split())
s, a = input(), []
b = [x for x in s]
for i in set(b):
a.append(s.count(i))
print("YES" if k >= max(a) else "NO")
``` | 3 |