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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed? | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": "2"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n2\n-1",
"output": "2"
},
{
"input": "2\n-1\n-1",
"output": "1"
},
{
"input": "3\n2\n-1\n1",
"output": "3"
},
{
"input": "3\n-1\n-1\n-1",
"output": "1"
},
{
"input": "5\n4\n5\n1\n-1\n4",
"output": "3"
},
{
"input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7",
"output": "4"
},
{
"input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4",
"output": "5"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1",
"output": "2"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1",
"output": "1"
},
{
"input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11",
"output": "12"
},
{
"input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2",
"output": "11"
},
{
"input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6",
"output": "6"
},
{
"input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1",
"output": "3"
},
{
"input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1",
"output": "2"
},
{
"input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1",
"output": "3"
},
{
"input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8",
"output": "5"
},
{
"input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10",
"output": "6"
},
{
"input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1",
"output": "4"
},
{
"input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9",
"output": "4"
},
{
"input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8",
"output": "3"
},
{
"input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11",
"output": "7"
},
{
"input": "7\n7\n6\n-1\n-1\n4\n4\n-1",
"output": "3"
},
{
"input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34",
"output": "6"
},
{
"input": "5\n2\n3\n4\n5\n-1",
"output": "5"
}
] | 1,689,788,716 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 124 | 1,740,800 | import sys
def input(): return sys.stdin.readline().strip()
def getints(): return map(int,sys.stdin.readline().strip().split())
q = int(input())
l = [0]*(q+1)
for x in range(1,q+1):
n = int(input())
if n == -1: l[x] = 1
else: l[x] = l[n]+1
print(max(l)) | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Output Specification:
Print a single integer denoting the minimum number of groups that will be formed in the party.
Demo Input:
['5\n-1\n1\n2\n1\n-1\n']
Demo Output:
['3\n']
Note:
For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | ```python
import sys
def input(): return sys.stdin.readline().strip()
def getints(): return map(int,sys.stdin.readline().strip().split())
q = int(input())
l = [0]*(q+1)
for x in range(1,q+1):
n = int(input())
if n == -1: l[x] = 1
else: l[x] = l[n]+1
print(max(l))
``` | 0 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,656,246,735 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 186 | 17,715,200 | s=input()
countup=0
countlo=0
if(len(s)<=100):
for i in range(0,len(s),1):
if(s[i]>='a' and s[i]<='z'):
countlo+=1
else:
countup+=1
if(countlo==countup):
print(s.lower())
elif(countlo>countup):
print(s.lower())
else:
print(s.upper())
else:
exit | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
s=input()
countup=0
countlo=0
if(len(s)<=100):
for i in range(0,len(s),1):
if(s[i]>='a' and s[i]<='z'):
countlo+=1
else:
countup+=1
if(countlo==countup):
print(s.lower())
elif(countlo>countup):
print(s.lower())
else:
print(s.upper())
else:
exit
``` | 3.920503 |
811 | B | Vladik and Complicated Book | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation *P* from position *l* to position *r* inclusive, because she loves the order. For every of such sorting Vladik knows number *x* — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has *p**x* changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in permutation are distinct.
Each of the next *m* lines contains three space-separated integers *l**i*, *r**i*, *x**i* (1<=≤<=*l**i*<=≤<=*x**i*<=≤<=*r**i*<=≤<=*n*) — left and right borders of sorted subsegment in *i*-th sorting and position that is interesting to Vladik. | For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | [
"5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n",
"6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n"
] | [
"Yes\nNo\nYes\nYes\nNo\n",
"Yes\nNo\nYes\nNo\nYes\n"
] | Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes". 1. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No". | 1,000 | [
{
"input": "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo"
},
{
"input": "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3",
"output": "Yes\nNo\nYes\nNo\nYes"
},
{
"input": "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 2\n6 8 7\n1 1 1\n7 9 9\n2 9 4",
"output": "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo"
},
{
"input": "20 20\n18 17 2 3 16 15 1 9 12 8 20 11 13 14 4 5 19 7 10 6\n13 15 15\n1 1 1\n2 2 2\n11 14 13\n10 11 10\n2 8 6\n12 18 16\n4 8 8\n2 2 2\n5 11 11\n4 9 9\n5 6 6\n3 20 12\n8 8 8\n6 16 11\n9 18 18\n8 18 17\n1 1 1\n2 6 5\n1 4 3",
"output": "No\nYes\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "5 10\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo\nYes\nNo\nYes\nYes\nNo"
}
] | 1,607,582,147 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 614,400 | import sys
def func(l,r,x):
count = 0
for i in range(l,r+1):
if a[x]>a[i]:
count += 1
return count
n,m = map(int,sys.stdin.readline().split())
a = [int(x) for x in sys.stdin.readline().split()]
for i in range(m):
l,r,x = [int(v)-1 for v in sys.stdin.readline().split()]
if x==func(l,r,x)+l:
sys.stdout.write('Yes\n')
else:
sys.stdout.write('No\n') | Title: Vladik and Complicated Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation *P* from position *l* to position *r* inclusive, because she loves the order. For every of such sorting Vladik knows number *x* — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has *p**x* changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input Specification:
First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in permutation are distinct.
Each of the next *m* lines contains three space-separated integers *l**i*, *r**i*, *x**i* (1<=≤<=*l**i*<=≤<=*x**i*<=≤<=*r**i*<=≤<=*n*) — left and right borders of sorted subsegment in *i*-th sorting and position that is interesting to Vladik.
Output Specification:
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Demo Input:
['5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n', '6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n']
Demo Output:
['Yes\nNo\nYes\nYes\nNo\n', 'Yes\nNo\nYes\nNo\nYes\n']
Note:
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes". 1. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No". | ```python
import sys
def func(l,r,x):
count = 0
for i in range(l,r+1):
if a[x]>a[i]:
count += 1
return count
n,m = map(int,sys.stdin.readline().split())
a = [int(x) for x in sys.stdin.readline().split()]
for i in range(m):
l,r,x = [int(v)-1 for v in sys.stdin.readline().split()]
if x==func(l,r,x)+l:
sys.stdout.write('Yes\n')
else:
sys.stdout.write('No\n')
``` | 0 |
|
644 | C | Hostname Aliases | PROGRAMMING | 2,100 | [
"*special",
"binary search",
"data structures",
"implementation",
"sortings",
"strings"
] | null | null | There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where:
- <hostname> — server name (consists of words and maybe some dots separating them), - /<path> — optional part, where <path> consists of words separated by slashes.
We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.
Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.
Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of page queries. Then follow *n* lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where:
- <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. - <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20.
Addresses are not guaranteed to be distinct. | First print *k* — the number of groups of server names that correspond to one website. You should count only groups of size greater than one.
Next *k* lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order. | [
"10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n",
"14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a\n"
] | [
"1\nhttp://abacaba.de http://abacaba.ru \n",
"2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc \n"
] | none | 1,500 | [
{
"input": "10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test",
"output": "1\nhttp://abacaba.de http://abacaba.ru "
},
{
"input": "14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a",
"output": "2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc "
},
{
"input": "10\nhttp://tqr.ekdb.nh/w\nhttp://p.ulz/ifw\nhttp://w.gw.dw.xn/kpe\nhttp://byt.mqii.zkv/j/xt\nhttp://ovquj.rbgrlw/k..\nhttp://bv.plu.e.dslg/j/xt\nhttp://udgci.ufgi.gwbd.s/\nhttp://l.oh.ne.o.r/.vo\nhttp://l.oh.ne.o.r/w\nhttp://tqr.ekdb.nh/.vo",
"output": "2\nhttp://l.oh.ne.o.r http://tqr.ekdb.nh \nhttp://bv.plu.e.dslg http://byt.mqii.zkv "
},
{
"input": "12\nhttp://ickght.ck/mr\nhttp://a.exhel/.b\nhttp://a.exhel/\nhttp://ti.cdm/\nhttp://ti.cdm/x/wd/lm.h.\nhttp://ickght.ck/a\nhttp://ickght.ck\nhttp://c.gcnk.d/.b\nhttp://c.gcnk.d/x/wd/lm.h.\nhttp://ti.cdm/.b\nhttp://a.exhel/x/wd/lm.h.\nhttp://c.gcnk.d/",
"output": "1\nhttp://a.exhel http://c.gcnk.d http://ti.cdm "
},
{
"input": "14\nhttp://jr/kgb\nhttp://ps.p.t.jeua.x.a.q.t\nhttp://gsqqs.n/t/\nhttp://w.afwsnuc.ff.km/cohox/u.\nhttp://u.s.wbumkuqm/\nhttp://u.s.wbumkuqm/cohox/u.\nhttp://nq.dzjkjcwv.f.s/bvm/\nhttp://zoy.shgg\nhttp://gsqqs.n\nhttp://u.s.wbumkuqm/b.pd.\nhttp://w.afwsnuc.ff.km/\nhttp://w.afwsnuc.ff.km/b.pd.\nhttp://nq.dzjkjcwv.f.s/n\nhttp://nq.dzjkjcwv.f.s/ldbw",
"output": "2\nhttp://ps.p.t.jeua.x.a.q.t http://zoy.shgg \nhttp://u.s.wbumkuqm http://w.afwsnuc.ff.km "
},
{
"input": "15\nhttp://l.edzplwqsij.rw/\nhttp://m.e.mehd.acsoinzm/s\nhttp://yg.ttahn.xin.obgez/ap/\nhttp://qqbb.pqkaqcncodxmaae\nhttp://lzi.a.flkp.lnn.k/o/qfr.cp\nhttp://lzi.a.flkp.lnn.k/f\nhttp://p.ngu.gkoq/.szinwwi\nhttp://qqbb.pqkaqcncodxmaae/od\nhttp://qqbb.pqkaqcncodxmaae\nhttp://wsxvmi.qpe.fihtgdvi/e./\nhttp://p.ngu.gkoq/zfoh\nhttp://m.e.mehd.acsoinzm/xp\nhttp://c.gy.p.h.tkrxt.jnsjt/j\nhttp://wsxvmi.qpe.fihtgdvi/grkag.z\nhttp://p.ngu.gkoq/t",
"output": "0"
},
{
"input": "15\nhttp://w.hhjvdn.mmu/.ca.p\nhttp://m.p.p.lar/\nhttp://lgmjun.r.kogpr.ijn/./t\nhttp://bapchpl.mcw.a.lob/d/ym/./g.q\nhttp://uxnjfnjp.kxr.ss.e.uu/jwo./hjl/\nhttp://fd.ezw.ykbb.xhl.t/\nhttp://i.xcb.kr/.ca.p\nhttp://jofec.ry.fht.gt\nhttp://qeo.gghwe.lcr/d/ym/./g.q\nhttp://gt\nhttp://gjvifpf.d/d/ym/./g.q\nhttp://oba\nhttp://rjs.qwd/v/hi\nhttp://fgkj/\nhttp://ivun.naumc.l/.ca.p",
"output": "4\nhttp://gt http://jofec.ry.fht.gt http://oba \nhttp://fd.ezw.ykbb.xhl.t http://fgkj http://m.p.p.lar \nhttp://i.xcb.kr http://ivun.naumc.l http://w.hhjvdn.mmu \nhttp://bapchpl.mcw.a.lob http://gjvifpf.d http://qeo.gghwe.lcr "
},
{
"input": "20\nhttp://gjwr/xsoiagp/\nhttp://gdnmu/j\nhttp://yfygudx.e.aqa.ezh/j\nhttp://mpjxue.cuvipq/\nhttp://a/\nhttp://kr/..n/c.\nhttp://a/xsoiagp/\nhttp://kr/z\nhttp://kr/v.cv/rk/k\nhttp://lvhpz\nhttp://qv.v.jqzhq\nhttp://y.no/\nhttp://kr/n\nhttp://y.no/xsoiagp/\nhttp://kr/ebe/z/\nhttp://olsvbxxw.win.n/j\nhttp://p.ct/j\nhttp://mpjxue.cuvipq/xsoiagp/\nhttp://kr/j\nhttp://gjwr/",
"output": "3\nhttp://lvhpz http://qv.v.jqzhq \nhttp://a http://gjwr http://mpjxue.cuvipq http://y.no \nhttp://gdnmu http://olsvbxxw.win.n http://p.ct http://yfygudx.e.aqa.ezh "
},
{
"input": "1\nhttp://a",
"output": "0"
},
{
"input": "3\nhttp://abacaba.com/test\nhttp://abacaba.de/test\nhttp://abacaba.de/test",
"output": "1\nhttp://abacaba.com http://abacaba.de "
}
] | 1,458,297,502 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
d={}; D={}; ans=[]
for _ in range(n): s=input()+'/'; t=s.find('/',7); d[s[:t]]=d.get(s[:t],set())|{s[t:]}
for k in d: t=frozenset(d[k]); D[t]=D.get(t,[])+[k]
[ans+=[D[k]] for k in D if len(D[k])>1]
print(len(ans))
print('\n'.join(map(' '.join,ans))) | Title: Hostname Aliases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where:
- <hostname> — server name (consists of words and maybe some dots separating them), - /<path> — optional part, where <path> consists of words separated by slashes.
We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.
Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.
Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of page queries. Then follow *n* lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where:
- <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20. - <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20.
Addresses are not guaranteed to be distinct.
Output Specification:
First print *k* — the number of groups of server names that correspond to one website. You should count only groups of size greater than one.
Next *k* lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order.
Demo Input:
['10\nhttp://abacaba.ru/test\nhttp://abacaba.ru/\nhttp://abacaba.com\nhttp://abacaba.com/test\nhttp://abacaba.de/\nhttp://abacaba.ru/test\nhttp://abacaba.de/test\nhttp://abacaba.com/\nhttp://abacaba.com/t\nhttp://abacaba.com/test\n', '14\nhttp://c\nhttp://ccc.bbbb/aba..b\nhttp://cba.com\nhttp://a.c/aba..b/a\nhttp://abc/\nhttp://a.c/\nhttp://ccc.bbbb\nhttp://ab.ac.bc.aa/\nhttp://a.a.a/\nhttp://ccc.bbbb/\nhttp://cba.com/\nhttp://cba.com/aba..b\nhttp://a.a.a/aba..b/a\nhttp://abc/aba..b/a\n']
Demo Output:
['1\nhttp://abacaba.de http://abacaba.ru \n', '2\nhttp://cba.com http://ccc.bbbb \nhttp://a.a.a http://a.c http://abc \n']
Note:
none | ```python
n=int(input())
d={}; D={}; ans=[]
for _ in range(n): s=input()+'/'; t=s.find('/',7); d[s[:t]]=d.get(s[:t],set())|{s[t:]}
for k in d: t=frozenset(d[k]); D[t]=D.get(t,[])+[k]
[ans+=[D[k]] for k in D if len(D[k])>1]
print(len(ans))
print('\n'.join(map(' '.join,ans)))
``` | -1 |
|
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 1,692,292,432 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 0 | p = input()
c=0
for i in range(len(p)-1):
if p[i] == p[i+1]:
c+=1
if c>=7:
print("YES")
else:
print("NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
Input Specification:
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Output Specification:
Print "YES" if the situation is dangerous. Otherwise, print "NO".
Demo Input:
['001001\n', '1000000001\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
p = input()
c=0
for i in range(len(p)-1):
if p[i] == p[i+1]:
c+=1
if c>=7:
print("YES")
else:
print("NO")
``` | 0 |
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20 1 80",
"output": "1 20 40 60 80 100 "
},
{
"input": "10\n10 8 6 7 5 3 4 2 9 1",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100 "
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 1 2 3 4 6 7 7 8 9 "
},
{
"input": "20\n53 32 64 20 41 97 50 20 66 68 22 60 74 61 97 54 80 30 72 59",
"output": "20 20 22 30 32 41 50 53 54 59 60 61 64 66 68 72 74 80 97 97 "
},
{
"input": "30\n7 17 4 18 16 12 14 10 1 13 2 16 13 17 8 16 13 14 9 17 17 5 13 5 1 7 6 20 18 12",
"output": "1 1 2 4 5 5 6 7 7 8 9 10 12 12 13 13 13 13 14 14 16 16 16 17 17 17 17 18 18 20 "
},
{
"input": "40\n22 58 68 58 48 53 52 1 16 78 75 17 63 15 36 32 78 75 49 14 42 46 66 54 49 82 40 43 46 55 12 73 5 45 61 60 1 11 31 84",
"output": "1 1 5 11 12 14 15 16 17 22 31 32 36 40 42 43 45 46 46 48 49 49 52 53 54 55 58 58 60 61 63 66 68 73 75 75 78 78 82 84 "
},
{
"input": "70\n1 3 3 1 3 3 1 1 1 3 3 2 3 3 1 1 1 2 3 1 3 2 3 3 3 2 2 3 1 3 3 2 1 1 2 1 2 1 2 2 1 1 1 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3 3 3 1 1 3 3 1 1 1 1 3 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "90\n17 75 51 30 100 5 50 95 51 73 66 5 7 76 43 49 23 55 3 24 95 79 10 11 44 93 17 99 53 66 82 66 63 76 19 4 51 71 75 43 27 5 24 19 48 7 91 15 55 21 7 6 27 10 2 91 64 58 18 21 16 71 90 88 21 20 6 6 95 85 11 7 40 65 52 49 92 98 46 88 17 48 85 96 77 46 100 34 67 52",
"output": "2 3 4 5 5 5 6 6 6 7 7 7 7 10 10 11 11 15 16 17 17 17 18 19 19 20 21 21 21 23 24 24 27 27 30 34 40 43 43 44 46 46 48 48 49 49 50 51 51 51 52 52 53 55 55 58 63 64 65 66 66 66 67 71 71 73 75 75 76 76 77 79 82 85 85 88 88 90 91 91 92 93 95 95 95 96 98 99 100 100 "
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n2 1 1 1 3 2 3 3 2 3 3 1 3 3 1 3 3 1 1 1 2 3 1 2 3 1 2 3 3 1 3 1 1 2 3 2 3 3 2 3 3 1 2 2 1 2 3 2 3 2 2 1 1 3 1 3 2 1 3 1 3 1 3 1 1 3 3 3 2 3 2 2 2 2 1 3 3 3 1 2 1 2 3 2 1 3 1 3 2 1 3 1 2 1 2 3 1 3 2 3",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "100\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6",
"output": "1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "100\n12 10 5 11 13 12 14 13 7 15 15 12 13 19 12 18 14 10 10 3 1 10 16 11 19 8 10 15 5 10 12 16 11 13 11 15 14 12 16 8 11 8 15 2 18 2 14 13 15 20 8 8 4 12 14 7 10 3 9 1 7 19 6 7 2 14 8 20 7 17 18 20 3 18 18 9 6 10 4 1 4 19 9 13 3 3 12 11 11 20 8 2 13 6 7 12 1 4 17 3",
"output": "1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 8 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 "
},
{
"input": "100\n5 13 1 40 30 10 23 32 33 12 6 4 15 29 31 17 23 5 36 31 32 38 24 11 34 39 19 21 6 19 31 35 1 15 6 29 22 15 17 15 1 17 2 34 20 8 27 2 29 26 13 9 22 27 27 3 20 40 4 40 33 29 36 30 35 16 19 28 26 11 36 24 29 5 40 10 38 34 33 23 34 39 31 7 10 31 22 6 36 24 14 31 34 23 2 4 26 16 2 32",
"output": "1 1 1 2 2 2 2 3 4 4 4 5 5 5 6 6 6 6 7 8 9 10 10 10 11 11 12 13 13 14 15 15 15 15 16 16 17 17 17 19 19 19 20 20 21 22 22 22 23 23 23 23 24 24 24 26 26 26 27 27 27 28 29 29 29 29 29 30 30 31 31 31 31 31 31 32 32 32 33 33 33 34 34 34 34 34 35 35 36 36 36 36 38 38 39 39 40 40 40 40 "
},
{
"input": "100\n72 44 34 74 9 60 26 37 55 77 74 69 28 66 54 55 8 36 57 31 31 48 32 66 40 70 77 43 64 28 37 10 21 58 51 32 60 28 51 52 28 35 7 33 1 68 38 70 57 71 8 20 42 57 59 4 58 10 17 47 22 48 16 3 76 67 32 37 64 47 33 41 75 69 2 76 39 9 27 75 20 21 52 25 71 21 11 29 38 10 3 1 45 55 63 36 27 7 59 41",
"output": "1 1 2 3 3 4 7 7 8 8 9 9 10 10 10 11 16 17 20 20 21 21 21 22 25 26 27 27 28 28 28 28 29 31 31 32 32 32 33 33 34 35 36 36 37 37 37 38 38 39 40 41 41 42 43 44 45 47 47 48 48 51 51 52 52 54 55 55 55 57 57 57 58 58 59 59 60 60 63 64 64 66 66 67 68 69 69 70 70 71 71 72 74 74 75 75 76 76 77 77 "
},
{
"input": "100\n75 18 61 10 56 53 42 57 79 80 31 2 50 45 54 99 84 52 71 21 86 3 19 98 14 37 40 62 63 68 5 10 87 8 81 85 52 52 57 94 2 7 56 96 19 76 1 13 81 6 80 47 22 59 99 32 9 5 36 88 98 91 70 70 12 93 12 22 85 1 97 48 94 16 84 84 51 34 62 7 68 51 30 2 37 82 4 7 27 1 80 9 61 16 59 55 12 96 94 82",
"output": "1 1 1 2 2 2 3 4 5 5 6 7 7 7 8 9 9 10 10 12 12 12 13 14 16 16 18 19 19 21 22 22 27 30 31 32 34 36 37 37 40 42 45 47 48 50 51 51 52 52 52 53 54 55 56 56 57 57 59 59 61 61 62 62 63 68 68 70 70 71 75 76 79 80 80 80 81 81 82 82 84 84 84 85 85 86 87 88 91 93 94 94 94 96 96 97 98 98 99 99 "
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50",
"output": "50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 "
},
{
"input": "49\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 "
},
{
"input": "30\n1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88",
"output": "1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 "
},
{
"input": "100\n100 51 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 51 100 "
},
{
"input": "10\n100 90 80 70 60 50 40 30 20 10",
"output": "10 20 30 40 50 60 70 80 90 100 "
},
{
"input": "1\n10",
"output": "10 "
}
] | 1,686,386,241 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 62 | 0 |
n = int(input())
columns = list(map(int, input().split()))
columns.sort()
output = ' '.join(map(str, columns))
print(output)
| Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.
Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch!
Input Specification:
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output Specification:
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
Demo Input:
['4\n3 2 1 2\n', '3\n2 3 8\n']
Demo Output:
['1 2 2 3 \n', '2 3 8 \n']
Note:
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not change the heights of the columns. | ```python
n = int(input())
columns = list(map(int, input().split()))
columns.sort()
output = ' '.join(map(str, columns))
print(output)
``` | 3 |
|
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894",
"output": "894"
},
{
"input": "6058 8581",
"output": "8581"
},
{
"input": "97259 41764",
"output": "125292"
},
{
"input": "453145 333625",
"output": "667250"
},
{
"input": "2233224 4394826",
"output": "4394826"
},
{
"input": "76770926 13350712",
"output": "80104272"
},
{
"input": "687355301 142098087",
"output": "710490435"
},
{
"input": "1000000000 999999999",
"output": "1999999998"
},
{
"input": "1000000000 1000000000",
"output": "2000000000"
},
{
"input": "999999999 1000000000",
"output": "1000000000"
},
{
"input": "1000000000 1",
"output": "1000000001"
},
{
"input": "1000000000 2",
"output": "1000000002"
},
{
"input": "999999999 1",
"output": "1000000000"
},
{
"input": "100000000 1",
"output": "100000001"
},
{
"input": "999999999 500000000",
"output": "1000000000"
},
{
"input": "999999990 10",
"output": "1000000000"
},
{
"input": "1000000000 999999997",
"output": "1999999994"
},
{
"input": "999999999 2",
"output": "1000000000"
},
{
"input": "999999984 1",
"output": "999999985"
},
{
"input": "999999983 1",
"output": "999999984"
},
{
"input": "666666666 1",
"output": "666666667"
},
{
"input": "1000000000 990000000",
"output": "1980000000"
},
{
"input": "41 48",
"output": "48"
},
{
"input": "123456 2",
"output": "123458"
},
{
"input": "111 111",
"output": "222"
},
{
"input": "878787 1",
"output": "878788"
},
{
"input": "121 1",
"output": "122"
},
{
"input": "114514 114514",
"output": "229028"
},
{
"input": "500000001 1000000000",
"output": "1000000000"
},
{
"input": "999999997 1",
"output": "999999998"
},
{
"input": "100000000 10",
"output": "100000010"
}
] | 1,695,468,911 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n,k=map(int,input.split())
for i in range(n,k+1):
if(n%i==0):
x=i
break;
print(x) | Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Output Specification:
Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*.
Demo Input:
['5 3\n', '25 13\n', '26 13\n']
Demo Output:
['6\n', '26\n', '39\n']
Note:
none | ```python
n,k=map(int,input.split())
for i in range(n,k+1):
if(n%i==0):
x=i
break;
print(x)
``` | -1 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,646,634,868 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n=int(input())
a1=0
a2=0
a3=0
for x in range(n):
a,b,c=map(int,input().split())
a1=a1+a
a2=a2+b
a3=a3+c
if a1==0 and a2==0 and a3==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())
a1=0
a2=0
a3=0
for x in range(n):
a,b,c=map(int,input().split())
a1=a1+a
a2=a2+b
a3=a3+c
if a1==0 and a2==0 and a3==0:
print("YES")
else:
print('NO')
``` | 3.977 |
225 | A | Dice Tower | PROGRAMMING | 1,100 | [
"constructive algorithms",
"greedy"
] | null | null | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice and Bob play dice. Alice has built a tower from *n* dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).
Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=6; *a**i*<=≠<=*b**i*) — the numbers Bob sees on the two sidelong faces of the *i*-th dice in the tower.
Consider the dice in the tower indexed from top to bottom from 1 to *n*. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input. | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | [
"3\n6\n3 2\n5 4\n2 4\n",
"3\n3\n2 6\n4 1\n5 3\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "3\n6\n3 2\n5 4\n2 4",
"output": "YES"
},
{
"input": "3\n3\n2 6\n4 1\n5 3",
"output": "NO"
},
{
"input": "1\n3\n2 1",
"output": "YES"
},
{
"input": "2\n2\n3 1\n1 5",
"output": "NO"
},
{
"input": "3\n2\n1 4\n5 3\n6 4",
"output": "NO"
},
{
"input": "4\n3\n5 6\n1 3\n1 5\n4 1",
"output": "NO"
},
{
"input": "2\n2\n3 1\n1 3",
"output": "YES"
},
{
"input": "3\n2\n1 4\n3 1\n4 6",
"output": "YES"
},
{
"input": "4\n3\n5 6\n1 5\n5 1\n1 5",
"output": "YES"
},
{
"input": "5\n1\n2 3\n5 3\n5 4\n5 1\n3 5",
"output": "NO"
},
{
"input": "10\n5\n1 3\n2 3\n6 5\n6 5\n4 5\n1 3\n1 2\n3 2\n4 2\n1 2",
"output": "NO"
},
{
"input": "15\n4\n2 1\n2 4\n6 4\n5 3\n4 1\n4 2\n6 3\n4 5\n3 5\n2 6\n5 6\n1 5\n3 5\n6 4\n3 2",
"output": "NO"
},
{
"input": "20\n6\n3 2\n4 6\n3 6\n6 4\n5 1\n1 5\n2 6\n1 2\n1 4\n5 3\n2 3\n6 2\n5 4\n2 6\n1 3\n4 6\n4 5\n6 3\n3 1\n6 2",
"output": "NO"
},
{
"input": "25\n4\n1 2\n4 1\n3 5\n2 1\n3 5\n6 5\n3 5\n5 6\n1 2\n2 4\n6 2\n2 3\n2 4\n6 5\n2 3\n6 3\n2 3\n1 3\n2 1\n3 1\n5 6\n3 1\n6 4\n3 6\n2 3",
"output": "NO"
},
{
"input": "100\n3\n6 5\n5 1\n3 2\n1 5\n3 6\n5 4\n2 6\n4 1\n6 3\n4 5\n1 5\n1 4\n4 2\n2 6\n5 4\n4 1\n1 3\n6 5\n5 1\n2 1\n2 4\n2 1\n3 6\n4 1\n6 3\n2 3\n5 1\n2 6\n6 4\n3 5\n4 1\n6 5\n1 5\n1 5\n2 3\n4 1\n5 3\n6 4\n1 3\n5 3\n4 1\n1 4\n2 1\n6 2\n1 5\n6 2\n6 2\n4 5\n4 2\n5 6\n6 3\n1 3\n2 3\n5 4\n6 5\n3 1\n1 2\n4 1\n1 3\n1 3\n6 5\n4 6\n3 1\n2 1\n2 3\n3 2\n4 1\n1 5\n4 1\n6 3\n1 5\n4 5\n4 2\n4 5\n2 6\n2 1\n3 5\n4 6\n4 2\n4 5\n2 4\n3 1\n6 4\n5 6\n3 1\n1 4\n4 5\n6 3\n6 3\n2 1\n5 1\n3 6\n3 5\n2 1\n4 6\n4 2\n5 6\n3 1\n3 5\n3 6",
"output": "NO"
},
{
"input": "99\n3\n2 1\n6 2\n3 6\n1 3\n5 1\n2 6\n4 6\n6 4\n6 4\n6 5\n3 6\n2 6\n1 5\n2 3\n4 6\n1 4\n4 1\n2 3\n4 5\n4 1\n5 1\n1 2\n6 5\n4 6\n6 5\n6 2\n3 6\n6 4\n2 1\n3 1\n2 1\n6 2\n3 5\n4 1\n5 3\n3 1\n1 5\n3 6\n6 2\n1 5\n2 1\n5 1\n4 1\n2 6\n5 4\n4 2\n2 1\n1 5\n1 3\n4 6\n4 6\n4 5\n2 3\n6 2\n3 2\n2 1\n4 6\n6 2\n3 5\n3 6\n3 1\n2 3\n2 1\n3 6\n6 5\n6 3\n1 2\n5 1\n1 4\n6 2\n5 3\n1 3\n5 4\n2 3\n6 3\n1 5\n1 2\n2 6\n5 6\n5 6\n3 5\n3 1\n4 6\n3 1\n4 5\n4 2\n3 5\n6 2\n2 4\n4 6\n6 2\n4 2\n2 3\n2 4\n1 5\n1 4\n3 5\n1 2\n4 5",
"output": "NO"
},
{
"input": "98\n6\n4 2\n1 2\n3 2\n2 1\n2 1\n3 2\n2 3\n6 5\n4 6\n1 5\n4 5\n5 1\n6 5\n1 4\n1 2\n2 4\n6 5\n4 5\n4 6\n3 1\n2 3\n4 1\n4 2\n6 5\n3 2\n4 2\n5 1\n2 4\n1 3\n4 5\n3 2\n1 2\n3 1\n3 2\n3 6\n6 4\n3 6\n3 5\n4 6\n6 5\n3 5\n3 2\n4 2\n6 4\n1 3\n2 4\n5 3\n2 3\n1 3\n5 6\n5 3\n5 3\n4 6\n4 6\n3 6\n4 1\n6 5\n6 2\n1 5\n2 1\n6 2\n5 4\n6 3\n1 5\n2 3\n2 6\n5 6\n2 6\n5 1\n3 2\n6 2\n6 2\n1 2\n2 1\n3 5\n2 1\n4 6\n1 4\n4 5\n3 2\n3 2\n5 4\n1 3\n5 1\n2 3\n6 2\n2 6\n1 5\n5 1\n5 4\n5 1\n5 4\n2 1\n6 5\n1 4\n6 5\n1 2\n3 5",
"output": "NO"
},
{
"input": "97\n3\n2 1\n6 5\n4 1\n6 5\n3 2\n1 2\n6 3\n6 4\n6 3\n1 3\n1 3\n3 1\n3 6\n3 2\n5 6\n4 2\n3 6\n1 5\n2 6\n3 2\n6 2\n2 1\n2 4\n1 3\n3 1\n2 6\n3 6\n4 6\n6 2\n5 1\n6 3\n2 6\n3 6\n2 4\n4 5\n6 5\n4 1\n5 6\n6 2\n5 4\n5 1\n6 5\n1 4\n2 1\n4 5\n4 5\n4 1\n5 4\n1 4\n2 6\n2 6\n1 5\n5 6\n3 2\n2 3\n1 4\n4 1\n3 6\n6 2\n5 3\n6 2\n4 5\n6 2\n2 6\n6 5\n1 4\n2 6\n3 5\n2 6\n4 1\n4 5\n1 3\n4 2\n3 2\n1 2\n5 6\n1 5\n3 5\n2 1\n1 2\n1 2\n6 4\n5 1\n1 2\n2 4\n6 3\n4 5\n1 5\n4 2\n5 1\n3 1\n6 4\n4 2\n1 5\n4 6\n2 1\n2 6",
"output": "NO"
},
{
"input": "96\n4\n1 5\n1 5\n4 6\n1 2\n4 2\n3 2\n4 6\n6 4\n6 3\n6 2\n4 1\n6 4\n5 1\n2 4\n5 6\n6 5\n3 2\n6 2\n3 1\n1 4\n3 2\n6 2\n2 4\n1 3\n5 4\n1 3\n6 2\n6 2\n5 6\n1 4\n4 2\n6 2\n3 1\n6 5\n3 1\n4 2\n6 3\n3 2\n3 6\n1 3\n5 6\n6 4\n1 4\n5 4\n2 6\n3 5\n5 4\n5 1\n2 4\n1 5\n1 3\n1 2\n1 3\n6 4\n6 3\n4 5\n4 1\n3 6\n1 2\n6 4\n1 2\n2 3\n2 1\n4 6\n1 3\n5 1\n4 5\n5 4\n6 3\n2 6\n5 1\n6 2\n3 1\n3 1\n5 4\n3 1\n5 6\n2 6\n5 6\n4 2\n6 5\n3 2\n6 5\n2 3\n6 4\n6 2\n1 2\n4 1\n1 2\n6 3\n2 1\n5 1\n6 5\n5 4\n4 5\n1 2",
"output": "NO"
},
{
"input": "5\n1\n2 3\n3 5\n4 5\n5 4\n5 3",
"output": "YES"
},
{
"input": "10\n5\n1 3\n3 1\n6 3\n6 3\n4 6\n3 1\n1 4\n3 1\n4 6\n1 3",
"output": "YES"
},
{
"input": "15\n4\n2 1\n2 6\n6 5\n5 1\n1 5\n2 1\n6 5\n5 1\n5 1\n6 2\n6 5\n5 1\n5 1\n6 5\n2 6",
"output": "YES"
},
{
"input": "20\n6\n3 2\n4 2\n3 5\n4 2\n5 3\n5 4\n2 3\n2 3\n4 5\n3 5\n3 2\n2 4\n4 5\n2 4\n3 2\n4 2\n5 4\n3 2\n3 5\n2 4",
"output": "YES"
},
{
"input": "25\n4\n1 2\n1 5\n5 6\n1 2\n5 1\n5 6\n5 1\n6 5\n2 1\n2 6\n2 6\n2 6\n2 6\n5 6\n2 6\n6 5\n2 1\n1 5\n1 2\n1 2\n6 5\n1 2\n6 5\n6 2\n2 6",
"output": "YES"
},
{
"input": "100\n3\n6 5\n1 5\n2 1\n5 1\n6 5\n5 1\n6 2\n1 2\n6 5\n5 1\n5 1\n1 5\n2 6\n6 2\n5 6\n1 2\n1 5\n5 6\n1 5\n1 2\n2 6\n1 2\n6 2\n1 5\n6 2\n2 6\n1 5\n6 2\n6 5\n5 6\n1 5\n5 6\n5 1\n5 1\n2 1\n1 2\n5 6\n6 5\n1 5\n5 1\n1 2\n1 5\n1 2\n2 6\n5 1\n2 6\n2 6\n5 6\n2 6\n6 5\n6 5\n1 5\n2 1\n5 6\n5 6\n1 2\n2 1\n1 2\n1 2\n1 2\n5 6\n6 2\n1 5\n1 2\n2 1\n2 6\n1 2\n5 1\n1 5\n6 5\n5 1\n5 1\n2 6\n5 6\n6 2\n1 2\n5 1\n6 2\n2 1\n5 6\n2 1\n1 5\n6 5\n6 5\n1 2\n1 2\n5 1\n6 2\n6 2\n1 2\n1 5\n6 5\n5 6\n1 2\n6 5\n2 1\n6 5\n1 5\n5 6\n6 5",
"output": "YES"
},
{
"input": "99\n3\n2 1\n2 6\n6 2\n1 5\n1 5\n6 2\n6 5\n6 5\n6 2\n5 6\n6 5\n6 2\n5 1\n2 6\n6 5\n1 5\n1 5\n2 6\n5 1\n1 5\n1 5\n2 1\n5 6\n6 5\n5 6\n2 6\n6 2\n6 5\n1 2\n1 2\n1 2\n2 6\n5 6\n1 2\n5 6\n1 2\n5 1\n6 5\n2 6\n5 1\n1 2\n1 5\n1 5\n6 2\n5 1\n2 6\n1 2\n5 1\n1 5\n6 5\n6 5\n5 6\n2 1\n2 6\n2 6\n1 2\n6 2\n2 6\n5 6\n6 5\n1 5\n2 1\n1 2\n6 2\n5 6\n6 5\n2 1\n1 5\n1 5\n2 6\n5 1\n1 2\n5 6\n2 1\n6 5\n5 1\n2 1\n6 2\n6 5\n6 5\n5 6\n1 2\n6 5\n1 2\n5 1\n2 1\n5 1\n2 6\n2 1\n6 2\n2 6\n2 6\n2 1\n2 1\n5 1\n1 5\n5 6\n2 1\n5 6",
"output": "YES"
},
{
"input": "98\n6\n4 2\n2 3\n2 3\n2 3\n2 3\n2 3\n3 2\n5 4\n4 2\n5 4\n5 4\n5 4\n5 3\n4 5\n2 3\n4 2\n5 3\n5 4\n4 5\n3 5\n3 2\n4 2\n2 4\n5 4\n2 3\n2 4\n5 4\n4 2\n3 5\n5 4\n2 3\n2 4\n3 5\n2 3\n3 5\n4 2\n3 5\n5 3\n4 2\n5 3\n5 3\n2 3\n2 4\n4 5\n3 2\n4 2\n3 5\n3 2\n3 5\n5 4\n3 5\n3 5\n4 2\n4 2\n3 2\n4 5\n5 4\n2 3\n5 4\n2 4\n2 3\n4 5\n3 5\n5 4\n3 2\n2 3\n5 3\n2 3\n5 3\n2 3\n2 3\n2 4\n2 3\n2 3\n5 3\n2 3\n4 2\n4 2\n5 4\n2 3\n2 3\n4 5\n3 2\n5 3\n3 2\n2 4\n2 4\n5 3\n5 4\n4 5\n5 3\n4 5\n2 4\n5 3\n4 2\n5 4\n2 4\n5 3",
"output": "YES"
},
{
"input": "97\n3\n2 1\n5 6\n1 2\n5 6\n2 6\n2 1\n6 2\n6 5\n6 2\n1 5\n1 2\n1 2\n6 2\n2 6\n6 5\n2 6\n6 5\n5 1\n6 2\n2 6\n2 6\n1 2\n2 6\n1 2\n1 5\n6 2\n6 5\n6 5\n2 6\n1 5\n6 5\n6 2\n6 2\n2 6\n5 6\n5 6\n1 5\n6 5\n2 6\n5 6\n1 5\n5 6\n1 5\n1 2\n5 1\n5 1\n1 5\n5 1\n1 5\n6 2\n6 2\n5 1\n6 5\n2 1\n2 6\n1 5\n1 5\n6 2\n2 6\n5 6\n2 6\n5 6\n2 6\n6 2\n5 6\n1 2\n6 2\n5 6\n6 2\n1 5\n5 6\n1 5\n2 6\n2 6\n2 1\n6 5\n5 1\n5 1\n1 2\n2 1\n2 1\n6 2\n1 5\n2 1\n2 1\n6 2\n5 1\n5 1\n2 6\n1 5\n1 2\n6 2\n2 6\n5 1\n6 5\n1 2\n6 2",
"output": "YES"
},
{
"input": "96\n4\n1 5\n5 1\n6 5\n2 1\n2 1\n2 6\n6 5\n6 5\n6 2\n2 6\n1 5\n6 5\n1 5\n2 6\n6 5\n5 6\n2 1\n2 6\n1 2\n1 5\n2 6\n2 6\n2 1\n1 5\n5 1\n1 2\n2 6\n2 6\n6 5\n1 5\n2 1\n2 6\n1 2\n5 6\n1 5\n2 6\n6 2\n2 6\n6 5\n1 5\n6 5\n6 5\n1 5\n5 1\n6 2\n5 1\n5 1\n1 5\n2 6\n5 1\n1 5\n2 1\n1 2\n6 2\n6 2\n5 6\n1 5\n6 5\n2 1\n6 5\n2 1\n2 1\n1 2\n6 2\n1 2\n1 5\n5 1\n5 6\n6 5\n6 2\n1 5\n2 6\n1 2\n1 2\n5 1\n1 5\n6 5\n6 2\n6 5\n2 6\n5 6\n2 1\n5 6\n2 1\n6 5\n2 6\n2 1\n1 5\n2 1\n6 2\n1 2\n1 5\n5 6\n5 1\n5 6\n2 1",
"output": "YES"
},
{
"input": "3\n6\n3 2\n5 4\n2 6",
"output": "NO"
},
{
"input": "4\n1\n2 3\n2 3\n2 3\n1 3",
"output": "NO"
},
{
"input": "2\n6\n3 2\n6 4",
"output": "NO"
},
{
"input": "3\n6\n3 2\n5 6\n2 4",
"output": "NO"
},
{
"input": "2\n5\n6 3\n4 5",
"output": "NO"
},
{
"input": "2\n6\n3 2\n6 5",
"output": "NO"
},
{
"input": "2\n1\n3 2\n1 2",
"output": "NO"
},
{
"input": "2\n3\n5 1\n3 5",
"output": "NO"
},
{
"input": "2\n1\n2 3\n1 2",
"output": "NO"
},
{
"input": "2\n1\n2 3\n2 1",
"output": "NO"
},
{
"input": "3\n1\n4 5\n4 1\n4 5",
"output": "NO"
},
{
"input": "2\n4\n2 6\n5 4",
"output": "NO"
},
{
"input": "2\n6\n3 2\n6 2",
"output": "NO"
},
{
"input": "2\n3\n2 1\n3 5",
"output": "NO"
},
{
"input": "2\n3\n1 2\n3 1",
"output": "NO"
},
{
"input": "2\n3\n2 6\n5 3",
"output": "NO"
},
{
"input": "3\n3\n1 2\n3 2\n3 1",
"output": "NO"
},
{
"input": "3\n5\n3 1\n1 3\n2 3",
"output": "NO"
},
{
"input": "2\n6\n2 4\n6 5",
"output": "NO"
},
{
"input": "2\n6\n4 5\n6 5",
"output": "NO"
},
{
"input": "2\n6\n3 5\n3 6",
"output": "NO"
},
{
"input": "2\n4\n1 2\n4 5",
"output": "NO"
},
{
"input": "2\n3\n2 6\n3 1",
"output": "NO"
}
] | 1,377,816,254 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 124 | 0 | import sys
f = sys.stdin
#f = open("input.txt", "r")
n = int(f.readline().strip())
u = int(f.readline().strip())
a, b = [], []
for i in f:
a.append(int(i.split()[0]))
b.append(int(i.split()[1]))
c = [[1, 2, 3, 4, 5, 6] for i in range(n)]
for i in range(n):
c[i].remove(a[i])
c[i].remove(b[i])
c[i].remove(7-a[i])
c[i].remove(7-b[i])
for i in range(n-1):
if c[i] != c[i+1]:
print("NO")
break
else:
print("YES") | Title: Dice Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice and Bob play dice. Alice has built a tower from *n* dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).
Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=6; *a**i*<=≠<=*b**i*) — the numbers Bob sees on the two sidelong faces of the *i*-th dice in the tower.
Consider the dice in the tower indexed from top to bottom from 1 to *n*. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input.
Output Specification:
Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).
Demo Input:
['3\n6\n3 2\n5 4\n2 4\n', '3\n3\n2 6\n4 1\n5 3\n']
Demo Output:
['YES', 'NO']
Note:
none | ```python
import sys
f = sys.stdin
#f = open("input.txt", "r")
n = int(f.readline().strip())
u = int(f.readline().strip())
a, b = [], []
for i in f:
a.append(int(i.split()[0]))
b.append(int(i.split()[1]))
c = [[1, 2, 3, 4, 5, 6] for i in range(n)]
for i in range(n):
c[i].remove(a[i])
c[i].remove(b[i])
c[i].remove(7-a[i])
c[i].remove(7-b[i])
for i in range(n-1):
if c[i] != c[i+1]:
print("NO")
break
else:
print("YES")
``` | 3 |
|
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during the *i*-th minute of the lecture then *t**i* will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — *a**i* during the *i*-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for *k* minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and *n*<=-<=*k*<=+<=1. If you use it on some minute *i* then Mishka will be awake during minutes *j* such that and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theorems lecturer tells during the *i*-th minute.
The third line of the input contains *n* integer numbers *t*1,<=*t*2,<=... *t**n* (0<=≤<=*t**i*<=≤<=1) — type of Mishka's behavior at the *i*-th minute of the lecture. | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "20"
},
{
"input": "5 2\n1 2 3 4 20\n0 0 0 1 0",
"output": "24"
},
{
"input": "3 1\n1 2 3\n0 0 1",
"output": "5"
},
{
"input": "4 2\n4 5 6 8\n1 0 1 0",
"output": "18"
},
{
"input": "6 3\n1 3 5 2 1 15\n1 1 0 1 0 0",
"output": "22"
},
{
"input": "5 5\n1 2 3 4 5\n1 1 1 0 1",
"output": "15"
},
{
"input": "3 3\n3 3 3\n1 0 1",
"output": "9"
},
{
"input": "5 5\n500 44 3 4 50\n1 0 0 0 0",
"output": "601"
},
{
"input": "2 2\n3 2\n1 0",
"output": "5"
},
{
"input": "7 6\n4 9 1 7 1 8 4\n0 0 0 1 0 1 0",
"output": "30"
},
{
"input": "4 3\n6 5 9 6\n1 1 0 1",
"output": "26"
},
{
"input": "2 1\n3 2\n0 0",
"output": "3"
},
{
"input": "1 1\n10\n0",
"output": "10"
},
{
"input": "2 1\n3 2\n1 0",
"output": "5"
},
{
"input": "4 2\n3 6 7 2\n0 0 1 1",
"output": "18"
},
{
"input": "10 5\n3 5 9 2 5 9 3 8 8 1\n0 1 1 1 0 1 0 0 0 0",
"output": "49"
},
{
"input": "10 4\n9 5 6 4 3 9 5 1 10 7\n0 0 0 0 0 0 1 0 0 1",
"output": "36"
},
{
"input": "9 8\n3 3 7 7 1 9 10 7 1\n1 1 1 1 1 1 1 1 1",
"output": "48"
},
{
"input": "2 1\n3 4\n0 0",
"output": "4"
},
{
"input": "2 1\n3 2\n0 1",
"output": "5"
},
{
"input": "10 1\n6 6 8 7 6 6 3 2 5 6\n0 0 1 0 0 1 0 1 1 1",
"output": "34"
},
{
"input": "3 2\n10 10 6\n0 0 0",
"output": "20"
},
{
"input": "6 3\n1 3 5 2 5 4\n1 1 1 1 1 1",
"output": "20"
},
{
"input": "10 5\n1 1 1 1 1 1 1 1 10000 1\n1 1 1 1 1 1 1 1 0 1",
"output": "10009"
}
] | 1,666,453,201 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 6,348,800 | n,k = map(int, input().split())
a = list(map(int, input().split()))
sleep = list(map(int, input().split()))
max_sum = 0
max_sum_index = 0
len_a = len(a)
for i in range(len_a):
sv = sleep[i]
if sv == 0:
s = sum(a[i:i+k])
if s > max_sum:
max_sum = s
max_sum_index = i
for i in range(max_sum_index, max_sum_index+k):
sleep[i] = 1
total = 0
for i in range(len_a):
if sleep[i] == 1:
total += a[i]
print(total)
| Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during the *i*-th minute of the lecture then *t**i* will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — *a**i* during the *i*-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for *k* minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and *n*<=-<=*k*<=+<=1. If you use it on some minute *i* then Mishka will be awake during minutes *j* such that and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Input Specification:
The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theorems lecturer tells during the *i*-th minute.
The third line of the input contains *n* integer numbers *t*1,<=*t*2,<=... *t**n* (0<=≤<=*t**i*<=≤<=1) — type of Mishka's behavior at the *i*-th minute of the lecture.
Output Specification:
Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Demo Input:
['6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n']
Demo Output:
['16\n']
Note:
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | ```python
n,k = map(int, input().split())
a = list(map(int, input().split()))
sleep = list(map(int, input().split()))
max_sum = 0
max_sum_index = 0
len_a = len(a)
for i in range(len_a):
sv = sleep[i]
if sv == 0:
s = sum(a[i:i+k])
if s > max_sum:
max_sum = s
max_sum_index = i
for i in range(max_sum_index, max_sum_index+k):
sleep[i] = 1
total = 0
for i in range(len_a):
if sleep[i] == 1:
total += a[i]
print(total)
``` | 0 |
|
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",
"output": "3"
},
{
"input": "1\n01",
"output": "1"
},
{
"input": "2\n01\n01",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "2"
},
{
"input": "3\n01\n01\n01",
"output": "1"
},
{
"input": "3\n10\n10\n01",
"output": "2"
},
{
"input": "3\n01\n10\n10",
"output": "2"
},
{
"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10",
"output": "55"
}
] | 1,691,490,172 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n=int (input)
a=[int(i) for i in input().split()]
cnt=1
for i in range(1,n):
if a[i] != a[i-1]:
cnt+=1
print(cnt)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output Specification:
On the single line of the output print the number of groups of magnets.
Demo Input:
['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n']
Demo Output:
['3\n', '2\n']
Note:
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | ```python
n=int (input)
a=[int(i) for i in input().split()]
cnt=1
for i in range(1,n):
if a[i] != a[i-1]:
cnt+=1
print(cnt)
``` | -1 |
|
25 | B | Phone numbers | PROGRAMMING | 1,100 | [
"implementation"
] | B. Phone numbers | 2 | 256 | Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | [
"6\n549871\n",
"7\n1198733\n"
] | [
"54-98-71",
"11-987-33\n"
] | none | 0 | [
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "081"
},
{
"input": "4\n3811",
"output": "38-11"
},
{
"input": "5\n21583",
"output": "215-83"
},
{
"input": "8\n33408349",
"output": "33-40-83-49"
},
{
"input": "9\n988808426",
"output": "988-80-84-26"
},
{
"input": "10\n0180990956",
"output": "01-80-99-09-56"
},
{
"input": "15\n433488906230138",
"output": "433-48-89-06-23-01-38"
},
{
"input": "22\n7135498415686025907059",
"output": "71-35-49-84-15-68-60-25-90-70-59"
},
{
"input": "49\n2429965524999668169991253653390090510755018570235",
"output": "242-99-65-52-49-99-66-81-69-99-12-53-65-33-90-09-05-10-75-50-18-57-02-35"
},
{
"input": "72\n491925337784111770500147619881727525570039735507439360627744863794794290",
"output": "49-19-25-33-77-84-11-17-70-50-01-47-61-98-81-72-75-25-57-00-39-73-55-07-43-93-60-62-77-44-86-37-94-79-42-90"
},
{
"input": "95\n32543414456047900690980198395035321172843693417425457554204776648220562494524275489599199209210",
"output": "325-43-41-44-56-04-79-00-69-09-80-19-83-95-03-53-21-17-28-43-69-34-17-42-54-57-55-42-04-77-66-48-22-05-62-49-45-24-27-54-89-59-91-99-20-92-10"
},
{
"input": "97\n9362344595153688016434451101547661156123505108492010669557671355055642365998461003851354321478898",
"output": "936-23-44-59-51-53-68-80-16-43-44-51-10-15-47-66-11-56-12-35-05-10-84-92-01-06-69-55-76-71-35-50-55-64-23-65-99-84-61-00-38-51-35-43-21-47-88-98"
},
{
"input": "98\n65521815795893886057122984634320900545031770769333931308009346017867969790810907868670369236928568",
"output": "65-52-18-15-79-58-93-88-60-57-12-29-84-63-43-20-90-05-45-03-17-70-76-93-33-93-13-08-00-93-46-01-78-67-96-97-90-81-09-07-86-86-70-36-92-36-92-85-68"
},
{
"input": "99\n455213856470326729480192345541970106407563996625458559297407682539801838244443866898560852503660390",
"output": "455-21-38-56-47-03-26-72-94-80-19-23-45-54-19-70-10-64-07-56-39-96-62-54-58-55-92-97-40-76-82-53-98-01-83-82-44-44-38-66-89-85-60-85-25-03-66-03-90"
},
{
"input": "100\n4004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224",
"output": "40-04-22-31-24-94-27-30-64-02-35-38-32-44-43-82-57-61-45-81-53-43-20-35-60-60-98-72-41-65-97-84-24-95-51-11-01-65-03-47-19-44-33-27-65-95-10-64-42-24"
}
] | 1,677,595,127 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 186 | 0 | n = int(input())
s = str(input())
flag = 3
if n % 2 == 0:
flag = 2
res = []
curr = 0
for i in range(len(s)):
if curr == 3 and flag == 3:
flag = 2
res.append("-")
res.append(s[i])
curr = 1
else:
res.append(s[i])
curr += 1
if flag != 3 and curr == 2 and i < len(s) - 1:
res.append("-")
curr = 0
print("".join(res)) | Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups.
Output Specification:
Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.
Demo Input:
['6\n549871\n', '7\n1198733\n']
Demo Output:
['54-98-71', '11-987-33\n']
Note:
none | ```python
n = int(input())
s = str(input())
flag = 3
if n % 2 == 0:
flag = 2
res = []
curr = 0
for i in range(len(s)):
if curr == 3 and flag == 3:
flag = 2
res.append("-")
res.append(s[i])
curr = 1
else:
res.append(s[i])
curr += 1
if flag != 3 and curr == 2 and i < len(s) - 1:
res.append("-")
curr = 0
print("".join(res))
``` | 3.9535 |
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,961,145 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | a = input()
b = a.upper()
if a == b:
print(a[0]+a[1:len(a)].lower())
elif a == a[0]+b[1:len(a)]:
print(a[0].upper()+a[1:len(a)].lower())
else:
print(a) | 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
a = input()
b = a.upper()
if a == b:
print(a[0]+a[1:len(a)].lower())
elif a == a[0]+b[1:len(a)]:
print(a[0].upper()+a[1:len(a)].lower())
else:
print(a)
``` | 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,301,710 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 7,065,600 | def main():
print(sqrt(2))
hh, mm = map(int, input().split())
h, d, c, n = map(int, input().split())
needTime = max(0, 1200 - (60 * hh + mm))
needCnt = (h + n - 1) // n
res = min(needCnt * c, (needCnt + needTime * d) * 0.8 * c)
print(res)
main() | 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
def main():
print(sqrt(2))
hh, mm = map(int, input().split())
h, d, c, n = map(int, input().split())
needTime = max(0, 1200 - (60 * hh + mm))
needCnt = (h + n - 1) // n
res = min(needCnt * c, (needCnt + needTime * d) * 0.8 * c)
print(res)
main()
``` | -1 |
|
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 1,675,683,305 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 0 | a=input()
c_zero =0
c_one =0
i= 0
while i+1<len(a):
# for i in range(len(a)):
if a[i] =="1" and a[i+1]=="1":
c_one+=1
elif a[i]=="0" and a[i+1] =="0":
c_zero+=1
i+=1
if c_one>=7:
print("YES")
elif c_zero>=7:
print("YES")
else:
print("NO")
# print(c_one)
# print(c_zero)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
Input Specification:
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Output Specification:
Print "YES" if the situation is dangerous. Otherwise, print "NO".
Demo Input:
['001001\n', '1000000001\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
a=input()
c_zero =0
c_one =0
i= 0
while i+1<len(a):
# for i in range(len(a)):
if a[i] =="1" and a[i+1]=="1":
c_one+=1
elif a[i]=="0" and a[i+1] =="0":
c_zero+=1
i+=1
if c_one>=7:
print("YES")
elif c_zero>=7:
print("YES")
else:
print("NO")
# print(c_one)
# print(c_zero)
``` | 0 |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip.
You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
"input": "0 0 0 0\n4132",
"output": "0"
},
{
"input": "3163 5778 83 7640\n11141442444",
"output": "64270"
},
{
"input": "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442",
"output": "420780"
},
{
"input": "0 0 0 0\n1",
"output": "0"
},
{
"input": "1 2 3 4\n4",
"output": "4"
},
{
"input": "2343 7653 1242 5432\n1",
"output": "2343"
},
{
"input": "2343 7653 1242 5432\n2",
"output": "7653"
},
{
"input": "2343 7653 1242 5432\n3",
"output": "1242"
},
{
"input": "2343 7653 1242 5432\n4",
"output": "5432"
},
{
"input": "1 2 3 4\n123412",
"output": "13"
},
{
"input": "50 50 50 50\n11111111111111111111111111111111111111111111111111111",
"output": "2650"
},
{
"input": "1 2 3 4\n11111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "1 2 3 4\n23123231321231231231231231221232123121312321",
"output": "87"
},
{
"input": "1 2 3 4\n1111111111111222222222233333333333444444444444444",
"output": "126"
},
{
"input": "2 3 1 4\n121321232412342112312313213123123412131231231232",
"output": "105"
}
] | 1,697,703,526 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 62 | 2,355,200 | a = list(map(int, input().split()))
s = input()
s = [int(c) for c in s]
c = 0
for i in range(len(s)):
c += a[s[i] - 1]
print(c) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip.
You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
Input Specification:
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Output Specification:
Print a single integer — the total number of calories that Jury wastes.
Demo Input:
['1 2 3 4\n123214\n', '1 5 3 2\n11221\n']
Demo Output:
['13\n', '13\n']
Note:
none | ```python
a = list(map(int, input().split()))
s = input()
s = [int(c) for c in s]
c = 0
for i in range(len(s)):
c += a[s[i] - 1]
print(c)
``` | 3 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,676,146,493 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m,n= map(int,input().split())
area=m*n
no_of_squares=area//2
print(no_of_squares)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
m,n= map(int,input().split())
area=m*n
no_of_squares=area//2
print(no_of_squares)
``` | 3.977 |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,696,234,679 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | a, b = sorted(list(map(int, input().split())))
m = a
p = (b-a)//2
print(m, p) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
a, b = sorted(list(map(int, input().split())))
m = a
p = (b-a)//2
print(m, p)
``` | 3 |
|
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24",
"output": "644 500"
},
{
"input": "1\n3",
"output": "3 0"
},
{
"input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646",
"output": "6848 6568"
},
{
"input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727",
"output": "9562 9561"
},
{
"input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12",
"output": "315 315"
},
{
"input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304",
"output": "3238 2222"
},
{
"input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325",
"output": "5246 4864"
},
{
"input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71",
"output": "8147 7807"
},
{
"input": "1\n1",
"output": "1 0"
}
] | 1,693,500,783 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 0 | n=int(input())
l=list(map(int,input().split()))
sums=0
sumd=0
for i in range(1,n+1):
if(i%2!=0):
if(l[0]>=l[len(l)-1]):
sums+=l[0]
l.remove(l[0])
else:
sums+=l[len(l)-1]
l.remove(l[len(l)-1])
else:
if(l[0]>=l[len(l)-1]):
sumd+=l[0]
l.remove(l[0])
else:
sumd+=l[len(l)-1]
l.remove(l[len(l)-1])
print(sums,sumd) | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output Specification:
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Demo Input:
['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n']
Demo Output:
['12 5\n', '16 12\n']
Note:
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | ```python
n=int(input())
l=list(map(int,input().split()))
sums=0
sumd=0
for i in range(1,n+1):
if(i%2!=0):
if(l[0]>=l[len(l)-1]):
sums+=l[0]
l.remove(l[0])
else:
sums+=l[len(l)-1]
l.remove(l[len(l)-1])
else:
if(l[0]>=l[len(l)-1]):
sumd+=l[0]
l.remove(l[0])
else:
sumd+=l[len(l)-1]
l.remove(l[len(l)-1])
print(sums,sumd)
``` | 3 |
|
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
"output": "-1"
},
{
"input": "20",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 "
},
{
"input": "8",
"output": "2 1 4 3 6 5 8 7 "
},
{
"input": "9",
"output": "-1"
},
{
"input": "10",
"output": "2 1 4 3 6 5 8 7 10 9 "
},
{
"input": "11",
"output": "-1"
},
{
"input": "21",
"output": "-1"
},
{
"input": "50",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 "
},
{
"input": "51",
"output": "-1"
},
{
"input": "52",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 "
},
{
"input": "84",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 "
},
{
"input": "86",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 "
},
{
"input": "100",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 "
},
{
"input": "98",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 "
},
{
"input": "96",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 "
},
{
"input": "33",
"output": "-1"
},
{
"input": "34",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 "
},
{
"input": "36",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 "
},
{
"input": "38",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 "
},
{
"input": "40",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 "
},
{
"input": "42",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 "
},
{
"input": "44",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 "
},
{
"input": "46",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 "
},
{
"input": "48",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 "
}
] | 1,667,938,828 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 124 | 614,400 | ### MAVERICK ###
import os, sys, math, heapq, itertools, bisect
from collections import deque,defaultdict, OrderedDict
ii = lambda : int(input())
si = lambda : input()
mi = lambda : map(int,input().strip().split(" "))
msi = lambda : map(str,input().strip().split(" "))
li = lambda : list(mi())
lsi = lambda : list(msi())
iseven = lambda num : num%2==0
isodd = lambda num : num%2==1
lower_alphabets = "abcdefghijklmnopqrstuvwxyz"
upper_alphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
store,dick,c,s,flag = [],{},0,0,False
postive_inf = math.inf
negative_inf = -math.inf
isint = lambda num : isinstance(num, int)
isfloat = lambda num : isinstance(num, float)
def swap(array,a,b)->None:temp=array[b];array[b]=array[a];array[a]=temp
def flush()->None:
global store,dick,c,s,flag
store,dick,c,s,flag = [],{},0,0,False
def debug(*var) -> None:
try: import master; master.debug(*var)
except (ModuleNotFoundError,FileNotFoundError): pass
try: import master; master.read()
except (ModuleNotFoundError,FileNotFoundError): pass
#dick1 = OrderedDict(sorted(dick1.items()))
#pageNum = 2
#os.startfile(f'https://codeforces.com/problemset/page/{pageNum}?order=BY_RATING_ASC')
n = ii()
if n==1:
print(-1)
else:
l = [i for i in range(1,n+1)]
first = l[0]
idx = 1
while idx < n:
try:
l[idx-1]=l[idx]
idx+=1
except IndexError: break
l[-1] = first
print(*l)
| Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
Input Specification:
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
Output Specification:
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
Demo Input:
['1\n', '2\n', '4\n']
Demo Output:
['-1\n', '2 1 \n', '2 1 4 3 \n']
Note:
none | ```python
### MAVERICK ###
import os, sys, math, heapq, itertools, bisect
from collections import deque,defaultdict, OrderedDict
ii = lambda : int(input())
si = lambda : input()
mi = lambda : map(int,input().strip().split(" "))
msi = lambda : map(str,input().strip().split(" "))
li = lambda : list(mi())
lsi = lambda : list(msi())
iseven = lambda num : num%2==0
isodd = lambda num : num%2==1
lower_alphabets = "abcdefghijklmnopqrstuvwxyz"
upper_alphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
store,dick,c,s,flag = [],{},0,0,False
postive_inf = math.inf
negative_inf = -math.inf
isint = lambda num : isinstance(num, int)
isfloat = lambda num : isinstance(num, float)
def swap(array,a,b)->None:temp=array[b];array[b]=array[a];array[a]=temp
def flush()->None:
global store,dick,c,s,flag
store,dick,c,s,flag = [],{},0,0,False
def debug(*var) -> None:
try: import master; master.debug(*var)
except (ModuleNotFoundError,FileNotFoundError): pass
try: import master; master.read()
except (ModuleNotFoundError,FileNotFoundError): pass
#dick1 = OrderedDict(sorted(dick1.items()))
#pageNum = 2
#os.startfile(f'https://codeforces.com/problemset/page/{pageNum}?order=BY_RATING_ASC')
n = ii()
if n==1:
print(-1)
else:
l = [i for i in range(1,n+1)]
first = l[0]
idx = 1
while idx < n:
try:
l[idx-1]=l[idx]
idx+=1
except IndexError: break
l[-1] = first
print(*l)
``` | 0 |
|
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,651,160,243 | 143 | PyPy 3 | OK | TESTS | 37 | 92 | 0 | def process(S):
n = len(S)
for i in range(n-2):
if S[i] != '.' and S[i+1] != '.' and S[i+2] != '.' and S[i] != S[i+1] and S[i] != S[i+2] and S[i+1] != S[i+2]:
print('Yes')
return
print('No')
S = input()
process(S) | 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
def process(S):
n = len(S)
for i in range(n-2):
if S[i] != '.' and S[i+1] != '.' and S[i+2] != '.' and S[i] != S[i+1] and S[i] != S[i+2] and S[i+1] != S[i+2]:
print('Yes')
return
print('No')
S = input()
process(S)
``` | 3 |
|
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,559,704,149 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | # -*- coding: cp949 -*-
#Get integer
Num = input()
NumList = input().split()
evenFlag = 0
for i in range(int(Num)):
if int(NumList[i])%2 == 0: #EvenNumber
if i == 0:
evenflag = 1
# print("¦��")
else:
if evenFlag != 0:
# print("Ȧ��")
print(i)
break
else:
continue
else: # oddNumber
if i == 0:
evenflag = 0
# print("Ȧ��")
else:
if evenFlag != 1:
# print("¦��")
print(i)
break
else:
continue
| 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
# -*- coding: cp949 -*-
#Get integer
Num = input()
NumList = input().split()
evenFlag = 0
for i in range(int(Num)):
if int(NumList[i])%2 == 0: #EvenNumber
if i == 0:
evenflag = 1
# print("¦��")
else:
if evenFlag != 0:
# print("Ȧ��")
print(i)
break
else:
continue
else: # oddNumber
if i == 0:
evenflag = 0
# print("Ȧ��")
else:
if evenFlag != 1:
# print("¦��")
print(i)
break
else:
continue
``` | 0 |
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,698,733,933 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
ans=''
if n%2:
ans+=str(3)+' '
n-=3
ans+='2 '*(n//2)
print(ans[:len(ans)-1]) | 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())
ans=''
if n%2:
ans+=str(3)+' '
n-=3
ans+='2 '*(n//2)
print(ans[:len(ans)-1])
``` | 0 |
|
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,664,643,957 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print(0 if (n:=int(input())) % 4 else (n - 1) // 4)
| 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
print(0 if (n:=int(input())) % 4 else (n - 1) // 4)
``` | 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,694,499,702 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 154 | 0 | chir = input()
vanG = input()
if vanG==chir[::-1]:
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
chir = input()
vanG = input()
if vanG==chir[::-1]:
print("YES")
else:
print("NO")
``` | 3.9615 |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43",
"output": "NO"
},
{
"input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "YES"
},
{
"input": "5\n2 1 4 5 3",
"output": "YES"
},
{
"input": "5\n5 4 5 5 2",
"output": "YES"
}
] | 1,625,116,600 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 77 | 0 | n=int(input())
f=[int(f) for f in input().split()]
triangle=0
for i in range(0,len(f)-1):
f1=f[i]
f2=f[f1-1]
f3=f[f2-1]
if f[f3-1]==f[i]:
triangle+=1
break
print("YES") if triangle>0 else print("NO") | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output Specification:
Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case.
Demo Input:
['5\n2 4 5 1 3\n', '5\n5 5 5 5 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | ```python
n=int(input())
f=[int(f) for f in input().split()]
triangle=0
for i in range(0,len(f)-1):
f1=f[i]
f2=f[f1-1]
f3=f[f2-1]
if f[f3-1]==f[i]:
triangle+=1
break
print("YES") if triangle>0 else print("NO")
``` | 3 |
|
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
"output": "QCCYXL"
},
{
"input": "3\nAZID\nEERWBC\nEERWBC",
"output": "EERWBC"
},
{
"input": "3\nHNCGYL\nHNCGYL\nHNCGYL",
"output": "HNCGYL"
},
{
"input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG",
"output": "ZZWZTG"
},
{
"input": "4\nA\nA\nKUDLJMXCSE\nA",
"output": "A"
},
{
"input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW",
"output": "PHBTW"
},
{
"input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN",
"output": "PKUZYTFYWN"
},
{
"input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH",
"output": "HH"
},
{
"input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW",
"output": "W"
},
{
"input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP",
"output": "XBCP"
},
{
"input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS",
"output": "PYPAS"
},
{
"input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC",
"output": "NC"
},
{
"input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI",
"output": "VOCI"
},
{
"input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA",
"output": "HA"
},
{
"input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS",
"output": "G"
},
{
"input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL",
"output": "WL"
}
] | 1,514,085,607 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 29 | 122 | 5,529,600 | n=int(input())
lst=[]
for i in range(n):
lst.append(input())
a1=lst[0]
for i in range(n-1):
if lst[i+1]!=lst[i]:
a2=lst[i+1]
num=0
for i in range(n):
if lst[i]==a1:
num+=1
if num>n/2:
ans=a1
else:
ans=a2
print(ans)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output Specification:
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Demo Input:
['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n']
Demo Output:
['ABC\n', 'A\n']
Note:
none | ```python
n=int(input())
lst=[]
for i in range(n):
lst.append(input())
a1=lst[0]
for i in range(n-1):
if lst[i+1]!=lst[i]:
a2=lst[i+1]
num=0
for i in range(n):
if lst[i]==a1:
num+=1
if num>n/2:
ans=a1
else:
ans=a2
print(ans)
``` | 0 |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed. | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move. | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
"output": "9"
},
{
"input": "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2",
"output": "5"
},
{
"input": "518 518 10\n37 97\n47 278\n17 467\n158 66\n483 351\n83 123\n285 219\n513 187\n380 75\n304 352",
"output": "0"
},
{
"input": "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "1 5 5\n1 1\n1 2\n1 3\n1 4\n1 5",
"output": "0"
},
{
"input": "5 1 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "0"
},
{
"input": "1 1 1\n1 1",
"output": "0"
},
{
"input": "10 10 4\n5 9\n6 9\n6 10\n5 10",
"output": "4"
},
{
"input": "1000 1000 4\n999 999\n999 1000\n1000 999\n1000 1000",
"output": "4"
},
{
"input": "2 3 5\n2 3\n1 3\n1 2\n1 1\n2 2",
"output": "5"
},
{
"input": "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000",
"output": "4"
}
] | 1,668,166,584 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 576 | 8,704,000 | #10_2.py
m, n, k = map(int,input().split())
c = [[0]*(n+1) for i in range(m+1)]
color = [[0]*(n+1) for i in range(m+1)]
dx = [-1,-1,0,0]
dy = [-1,0,-1,0]
flag = False
for cnt in range(k):
i, j = map(int,input().split())
if flag:
continue
if c[i][j]:
continue
c[i][j] = 1
for l in range(4):
ii = i + dx[l]
jj = j + dy[l]
color[ii][jj] += 1
if color[ii][jj] == 4:
print(cnt+1)
flag = True
break
if flag == False:
print(0)
| Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
Input Specification:
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
Output Specification:
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
Demo Input:
['2 2 4\n1 1\n1 2\n2 1\n2 2\n', '2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n', '5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n']
Demo Output:
['4\n', '5\n', '0\n']
Note:
none | ```python
#10_2.py
m, n, k = map(int,input().split())
c = [[0]*(n+1) for i in range(m+1)]
color = [[0]*(n+1) for i in range(m+1)]
dx = [-1,-1,0,0]
dy = [-1,0,-1,0]
flag = False
for cnt in range(k):
i, j = map(int,input().split())
if flag:
continue
if c[i][j]:
continue
c[i][j] = 1
for l in range(4):
ii = i + dx[l]
jj = j + dy[l]
color[ii][jj] += 1
if color[ii][jj] == 4:
print(cnt+1)
flag = True
break
if flag == False:
print(0)
``` | 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,669,299,724 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | x,y,z=map(int,input().split())
if x%z==0:
x=x//z
else:
x=x//z+1
if y%z==0:
y=y//z
else:
y=y//z+1
print(x*y) | 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
x,y,z=map(int,input().split())
if x%z==0:
x=x//z
else:
x=x//z+1
if y%z==0:
y=y//z
else:
y=y//z+1
print(x*y)
``` | 3.977 |
0 | none | none | none | 0 | [
"none"
] | null | null | A couple of friends, Axel and Marston are travelling across the country of Bitland. There are *n* towns in Bitland, with some pairs of towns connected by one-directional roads. Each road in Bitland is either a pedestrian road or a bike road. There can be multiple roads between any pair of towns, and may even be a road from a town to itself. However, no pair of roads shares the starting and the destination towns along with their types simultaneously.
The friends are now located in the town 1 and are planning the travel route. Axel enjoys walking, while Marston prefers biking. In order to choose a route diverse and equally interesting for both friends, they have agreed upon the following procedure for choosing the road types during the travel:
- The route starts with a pedestrian route.- Suppose that a beginning of the route is written in a string *s* of letters P (pedestrain road) and B (biking road). Then, the string is appended to *s*, where stands for the string *s* with each character changed to opposite (that is, all pedestrian roads changed to bike roads, and vice versa).
In the first few steps the route will look as follows: P, PB, PBBP, PBBPBPPB, PBBPBPPBBPPBPBBP, and so on.
After that the friends start travelling from the town 1 via Bitlandian roads, choosing the next road according to the next character of their route type each time. If it is impossible to choose the next road, the friends terminate their travel and fly home instead.
Help the friends to find the longest possible route that can be travelled along roads of Bitland according to the road types choosing procedure described above. If there is such a route with more than 1018 roads in it, print -1 instead. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=500, 0<=≤<=*m*<=≤<=2*n*2) — the number of towns and roads in Bitland respectively.
Next *m* lines describe the roads. *i*-th of these lines contains three integers *v**i*, *u**i* and *t**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*, 0<=≤<=*t**i*<=≤<=1), where *v**i* and *u**i* denote start and destination towns indices of the *i*-th road, and *t**i* decribes the type of *i*-th road (0 for a pedestrian road, 1 for a bike road). It is guaranteed that for each pair of distinct indices *i*, *j* such that 1<=≤<=*i*,<=*j*<=≤<=*m*, either *v**i*<=≠<=*v**j*, or *u**i*<=≠<=*u**j*, or *t**i*<=≠<=*t**j* holds. | If it is possible to find a route with length strictly greater than 1018, print -1. Otherwise, print the maximum length of a suitable path. | [
"2 2\n1 2 0\n2 2 1\n",
"2 3\n1 2 0\n2 2 1\n2 2 0\n"
] | [
"3\n",
"-1\n"
] | In the first sample we can obtain a route of length 3 by travelling along the road 1 from town 1 to town 2, and then following the road 2 twice from town 2 to itself.
In the second sample we can obtain an arbitrarily long route by travelling the road 1 first, and then choosing road 2 or 3 depending on the necessary type. | 0 | [] | 1,488,728,316 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
bitset <500> d[500][61][2];
vector <vector <long long> > res(500, vector <long long>(2, -1));
long long dfs(int u, int rev) {
if (res[u][rev] != -1) {
return res[u][rev];
}
int st = 60;
while (st >= 0 && !d[u][st][rev].any()) {
st--;
}
if (st == -1) {
res[u][rev] = 0;
return 0;
}
for (int j = 0; j < 500; j++) {
if (d[u][st][rev].test(j)) {
res[u][rev] = max(res[u][rev], (1LL << st) + dfs(j, 1 - rev));
}
}
return res[u][rev];
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b, t;
cin >> a >> b >> t;
a--, b--;
if (t == 0) {
d[a][0][0].set(b);
} else {
d[a][0][1].set(b);
}
}
for (int st = 1; st <= 60; st++) {
for (int i = 0; i < n; i++) {
for (int rev = 0; rev < 2; rev++) {
for (int j = 0; j < n; j++) {
if (d[i][st - 1][rev].test(j)) {
d[i][st][rev] |= d[j][st - 1][1 - rev];
}
}
}
}
}
if (d[0][60][0].any()) {
cout << "-1\n";
return 0;
}
int st;
for (st = 0; st <= 60; st++) {
if (!d[0][st][0].any()) {
break;
}
}
st--;
if (st == -1) {
cout << "0\n";
return 0;
}
cout << dfs(0, 0) << '\n';
return 0;
}
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A couple of friends, Axel and Marston are travelling across the country of Bitland. There are *n* towns in Bitland, with some pairs of towns connected by one-directional roads. Each road in Bitland is either a pedestrian road or a bike road. There can be multiple roads between any pair of towns, and may even be a road from a town to itself. However, no pair of roads shares the starting and the destination towns along with their types simultaneously.
The friends are now located in the town 1 and are planning the travel route. Axel enjoys walking, while Marston prefers biking. In order to choose a route diverse and equally interesting for both friends, they have agreed upon the following procedure for choosing the road types during the travel:
- The route starts with a pedestrian route.- Suppose that a beginning of the route is written in a string *s* of letters P (pedestrain road) and B (biking road). Then, the string is appended to *s*, where stands for the string *s* with each character changed to opposite (that is, all pedestrian roads changed to bike roads, and vice versa).
In the first few steps the route will look as follows: P, PB, PBBP, PBBPBPPB, PBBPBPPBBPPBPBBP, and so on.
After that the friends start travelling from the town 1 via Bitlandian roads, choosing the next road according to the next character of their route type each time. If it is impossible to choose the next road, the friends terminate their travel and fly home instead.
Help the friends to find the longest possible route that can be travelled along roads of Bitland according to the road types choosing procedure described above. If there is such a route with more than 1018 roads in it, print -1 instead.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=500, 0<=≤<=*m*<=≤<=2*n*2) — the number of towns and roads in Bitland respectively.
Next *m* lines describe the roads. *i*-th of these lines contains three integers *v**i*, *u**i* and *t**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*, 0<=≤<=*t**i*<=≤<=1), where *v**i* and *u**i* denote start and destination towns indices of the *i*-th road, and *t**i* decribes the type of *i*-th road (0 for a pedestrian road, 1 for a bike road). It is guaranteed that for each pair of distinct indices *i*, *j* such that 1<=≤<=*i*,<=*j*<=≤<=*m*, either *v**i*<=≠<=*v**j*, or *u**i*<=≠<=*u**j*, or *t**i*<=≠<=*t**j* holds.
Output Specification:
If it is possible to find a route with length strictly greater than 1018, print -1. Otherwise, print the maximum length of a suitable path.
Demo Input:
['2 2\n1 2 0\n2 2 1\n', '2 3\n1 2 0\n2 2 1\n2 2 0\n']
Demo Output:
['3\n', '-1\n']
Note:
In the first sample we can obtain a route of length 3 by travelling along the road 1 from town 1 to town 2, and then following the road 2 twice from town 2 to itself.
In the second sample we can obtain an arbitrarily long route by travelling the road 1 first, and then choosing road 2 or 3 depending on the necessary type. | ```python
#include <bits/stdc++.h>
using namespace std;
bitset <500> d[500][61][2];
vector <vector <long long> > res(500, vector <long long>(2, -1));
long long dfs(int u, int rev) {
if (res[u][rev] != -1) {
return res[u][rev];
}
int st = 60;
while (st >= 0 && !d[u][st][rev].any()) {
st--;
}
if (st == -1) {
res[u][rev] = 0;
return 0;
}
for (int j = 0; j < 500; j++) {
if (d[u][st][rev].test(j)) {
res[u][rev] = max(res[u][rev], (1LL << st) + dfs(j, 1 - rev));
}
}
return res[u][rev];
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b, t;
cin >> a >> b >> t;
a--, b--;
if (t == 0) {
d[a][0][0].set(b);
} else {
d[a][0][1].set(b);
}
}
for (int st = 1; st <= 60; st++) {
for (int i = 0; i < n; i++) {
for (int rev = 0; rev < 2; rev++) {
for (int j = 0; j < n; j++) {
if (d[i][st - 1][rev].test(j)) {
d[i][st][rev] |= d[j][st - 1][1 - rev];
}
}
}
}
}
if (d[0][60][0].any()) {
cout << "-1\n";
return 0;
}
int st;
for (st = 0; st <= 60; st++) {
if (!d[0][st][0].any()) {
break;
}
}
st--;
if (st == -1) {
cout << "0\n";
return 0;
}
cout << dfs(0, 0) << '\n';
return 0;
}
``` | -1 |
|
1,011 | B | Planning The Expedition | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.
Formally, for each participant $j$ Natasha should select his food type $b_j$ and each day $j$-th participant will eat one food package of type $b_j$. The values $b_j$ for different participants may be different.
What is the maximum possible number of days the expedition can last, following the requirements above? | The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available.
The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food package. | Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0. | [
"4 10\n1 5 2 1 1 1 2 5 7 2\n",
"100 1\n1\n",
"2 5\n5 4 3 2 1\n",
"3 9\n42 42 42 42 42 42 42 42 42\n"
] | [
"2\n",
"0\n",
"1\n",
"3\n"
] | In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of type $1$, two packages of type $2$ and two packages of type $5$).
In the second example, there are $100$ participants and only $1$ food package. In this case, the expedition can't last even $1$ day. | 1,000 | [
{
"input": "4 10\n1 5 2 1 1 1 2 5 7 2",
"output": "2"
},
{
"input": "100 1\n1",
"output": "0"
},
{
"input": "2 5\n5 4 3 2 1",
"output": "1"
},
{
"input": "3 9\n42 42 42 42 42 42 42 42 42",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "4 100\n84 99 66 69 86 94 89 96 98 93 93 82 87 93 91 100 69 99 93 81 99 84 75 100 86 88 98 100 84 96 44 70 94 91 85 78 86 79 45 88 91 78 98 94 81 87 93 72 96 88 96 97 96 62 86 72 94 84 80 98 88 90 93 73 73 98 78 50 91 96 97 82 85 90 87 41 97 82 97 77 100 100 92 83 98 81 70 81 74 78 84 79 98 98 55 99 97 99 79 98",
"output": "5"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "6 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "15"
},
{
"input": "1 1\n59",
"output": "1"
},
{
"input": "1 50\n39 1 46 21 23 28 100 32 63 63 18 15 40 29 34 49 56 74 47 42 96 97 59 62 76 62 69 61 36 21 66 18 92 58 63 85 5 6 77 75 91 66 38 10 66 43 20 74 37 83",
"output": "3"
},
{
"input": "1 100\n83 72 21 55 49 5 61 60 87 21 89 88 3 75 49 81 36 25 50 61 96 19 36 55 48 8 97 69 50 24 23 39 26 25 41 90 69 20 19 62 38 52 60 6 66 31 9 45 36 12 69 94 22 60 91 65 35 58 13 85 33 87 83 11 95 20 20 85 13 21 57 69 17 94 78 37 59 45 60 7 64 51 60 89 91 22 6 58 95 96 51 53 89 22 28 16 27 56 1 54",
"output": "5"
},
{
"input": "50 1\n75",
"output": "0"
},
{
"input": "50 50\n85 20 12 73 52 78 70 95 88 43 31 88 81 41 80 99 16 11 97 11 21 44 2 34 47 38 87 2 32 47 97 93 52 14 35 37 97 48 58 19 52 55 97 72 17 25 16 85 90 58",
"output": "1"
},
{
"input": "50 100\n2 37 74 32 99 75 73 86 67 33 62 30 15 21 51 41 73 75 67 39 90 10 56 74 72 26 38 65 75 55 46 99 34 49 92 82 11 100 15 71 75 12 22 56 47 74 20 98 59 65 14 76 1 40 89 36 43 93 83 73 75 100 50 95 27 10 72 51 25 69 15 3 57 60 84 99 31 44 12 61 69 95 51 31 28 36 57 35 31 52 44 19 79 12 27 27 7 81 68 1",
"output": "1"
},
{
"input": "100 1\n26",
"output": "0"
},
{
"input": "100 50\n8 82 62 11 85 57 5 32 99 92 77 2 61 86 8 88 10 28 83 4 68 79 8 64 56 98 4 88 22 54 30 60 62 79 72 38 17 28 32 16 62 26 56 44 72 33 22 84 77 45",
"output": "0"
},
{
"input": "100 100\n13 88 64 65 78 10 61 97 16 32 76 9 60 1 40 35 90 61 60 85 26 16 38 36 33 95 24 55 82 88 13 9 47 34 94 2 90 74 11 81 46 70 94 11 55 32 19 36 97 16 17 35 38 82 89 16 74 94 97 79 9 94 88 12 28 2 4 25 72 95 49 31 88 82 6 77 70 98 90 57 57 33 38 61 26 75 2 66 22 44 13 35 16 4 33 16 12 66 32 86",
"output": "1"
},
{
"input": "34 64\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "53 98\n1 1 2 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 2 1 2 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 1 1 2 2 1 2 1 2 1 2 1 1 2 2 2 1 1 2 1 2 1 1 1 1 2 2 2 2 2 1 1 2 2 2 1 1",
"output": "1"
},
{
"input": "17 8\n2 5 3 4 3 2 2 2",
"output": "0"
},
{
"input": "24 77\n8 6 10 4 6 6 4 10 9 7 7 5 5 4 6 7 10 6 3 4 6 6 4 9 4 6 2 5 3 4 4 1 4 6 6 8 1 1 6 4 6 2 5 7 7 2 4 4 10 1 10 9 2 3 8 1 10 4 3 9 3 8 3 5 6 3 4 9 5 3 4 1 1 6 1 2 1",
"output": "2"
},
{
"input": "65 74\n7 19 2 38 28 44 34 49 14 13 30 22 11 4 4 12 8 1 40 8 34 31 44 38 21 35 13 7 19 32 37 5 36 26 7 2 15 11 47 45 48 2 49 10 10 42 42 31 50 24 29 34 31 38 39 48 43 47 32 46 10 1 33 21 12 50 13 44 38 11 41 41 10 7",
"output": "1"
},
{
"input": "37 71\n50 93 15 80 82 23 35 90 70 73 55 23 23 6 86 63 38 70 38 52 88 34 25 75 32 19 6 98 31 38 21 8 66 8 59 71 7 80 69 23 17 70 6 40 72 5 48 59 18 1 48 91 17 41 11 27 53 95 87 31 62 94 94 60 38 99 70 50 81 86 44",
"output": "1"
},
{
"input": "35 4\n100 100 100 100",
"output": "0"
},
{
"input": "68 12\n100 100 100 99 99 100 100 100 99 99 99 99",
"output": "0"
},
{
"input": "91 33\n97 100 96 96 97 100 97 97 96 96 99 99 98 97 97 99 99 98 100 96 96 99 100 96 97 100 97 97 99 98 96 98 97",
"output": "0"
},
{
"input": "59 72\n99 96 96 93 94 97 93 96 100 99 93 99 96 92 92 97 93 100 92 100 91 96 99 100 97 98 93 93 96 100 97 99 100 100 91 93 96 91 93 100 95 96 92 97 91 91 99 100 91 95 95 100 92 93 98 93 95 92 95 100 91 95 99 95 92 91 100 93 98 98 96 99",
"output": "1"
},
{
"input": "9 35\n95 54 78 94 56 63 68 73 61 85 73 62 61 94 67 91 66 54 89 69 92 60 91 87 63 62 85 70 62 68 97 88 96 55 62",
"output": "2"
},
{
"input": "99 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "1 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",
"output": "50"
}
] | 1,686,101,624 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | people_quantity, food_package_quantity = map(int, input().split())
food_type_sequence = list(map(int, input().split()))
food_type_quantity_sequence = [0]*101
for i in food_type_sequence:
food_type_quantity_sequence[i] += 1
# For d days, maximum how many people can go?
for day in range(food_package_quantity, -1, -1):
max_people_possible = 0
if day == 0:
print(0)
break
for food_type_quantity in food_type_quantity_sequence:
max_people_possible += food_type_quantity // day
if max_people_possible >= people_quantity:
print(day)
break | Title: Planning The Expedition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.
Formally, for each participant $j$ Natasha should select his food type $b_j$ and each day $j$-th participant will eat one food package of type $b_j$. The values $b_j$ for different participants may be different.
What is the maximum possible number of days the expedition can last, following the requirements above?
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available.
The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food package.
Output Specification:
Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.
Demo Input:
['4 10\n1 5 2 1 1 1 2 5 7 2\n', '100 1\n1\n', '2 5\n5 4 3 2 1\n', '3 9\n42 42 42 42 42 42 42 42 42\n']
Demo Output:
['2\n', '0\n', '1\n', '3\n']
Note:
In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of type $1$, two packages of type $2$ and two packages of type $5$).
In the second example, there are $100$ participants and only $1$ food package. In this case, the expedition can't last even $1$ day. | ```python
people_quantity, food_package_quantity = map(int, input().split())
food_type_sequence = list(map(int, input().split()))
food_type_quantity_sequence = [0]*101
for i in food_type_sequence:
food_type_quantity_sequence[i] += 1
# For d days, maximum how many people can go?
for day in range(food_package_quantity, -1, -1):
max_people_possible = 0
if day == 0:
print(0)
break
for food_type_quantity in food_type_quantity_sequence:
max_people_possible += food_type_quantity // day
if max_people_possible >= people_quantity:
print(day)
break
``` | 3 |
|
299 | B | Ksusha the Squirrel | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".". | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "YES"
},
{
"input": "2 100000\n..",
"output": "YES"
},
{
"input": "3 1\n.#.",
"output": "NO"
},
{
"input": "3 2\n.#.",
"output": "YES"
},
{
"input": "3 10000\n.#.",
"output": "YES"
}
] | 1,589,110,566 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 218 | 7,782,400 | n,k=tuple(map(int,input().split()))
st=input()
s="#"*k
if s in st:
print("NO")
else:
print("YES") | Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)?
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".".
Output Specification:
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
Demo Input:
['2 1\n..\n', '5 2\n.#.#.\n', '7 3\n.#.###.\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
n,k=tuple(map(int,input().split()))
st=input()
s="#"*k
if s in st:
print("NO")
else:
print("YES")
``` | 3 |
|
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,085,435 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 32 | 93 | 7,372,800 | import math
numbers = list(map(int, input().split()))
hh = numbers[0]
mm = numbers[1]
numbers = list(map(int, input().split()))
H = numbers[0]
D = numbers[1]
C = numbers[2]
N = numbers[3]
def func(hh, mm, H, D, C, N):
minute = hh * 60 + mm
if minute >= 1200:
return C * math.ceil(H / N) * 0.8
else:
t = 1200 - H / (4 * D)
if minute <= t:
return C * math.ceil(H / N)
else:
return C * math.ceil((H + (1200 - minute) * D) / N) * 0.8
#z = func(17, 41, 1000, 6, 15, 11)
z = func(hh, mm, H, D, C, N)
print("%.4f" % z) | 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
import math
numbers = list(map(int, input().split()))
hh = numbers[0]
mm = numbers[1]
numbers = list(map(int, input().split()))
H = numbers[0]
D = numbers[1]
C = numbers[2]
N = numbers[3]
def func(hh, mm, H, D, C, N):
minute = hh * 60 + mm
if minute >= 1200:
return C * math.ceil(H / N) * 0.8
else:
t = 1200 - H / (4 * D)
if minute <= t:
return C * math.ceil(H / N)
else:
return C * math.ceil((H + (1200 - minute) * D) / N) * 0.8
#z = func(17, 41, 1000, 6, 15, 11)
z = func(hh, mm, H, D, C, N)
print("%.4f" % z)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 0 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
"input": "353 313 327 470 597 31",
"output": "NO"
},
{
"input": "835 638 673 624 232 266",
"output": "NO"
},
{
"input": "936 342 19 398 247 874",
"output": "NO"
},
{
"input": "417 666 978 553 271 488",
"output": "NO"
},
{
"input": "71 66 124 199 67 147",
"output": "YES"
},
{
"input": "54 26 0 171 239 12",
"output": "YES"
},
{
"input": "72 8 186 92 267 69",
"output": "YES"
},
{
"input": "180 179 188 50 75 214",
"output": "YES"
},
{
"input": "16 169 110 136 404 277",
"output": "YES"
},
{
"input": "101 400 9 200 300 10",
"output": "YES"
},
{
"input": "101 400 200 9 300 10",
"output": "YES"
},
{
"input": "101 200 400 9 300 10",
"output": "YES"
},
{
"input": "101 400 200 300 9 10",
"output": "YES"
},
{
"input": "101 200 400 300 9 10",
"output": "YES"
},
{
"input": "4 4 4 4 5 4",
"output": "NO"
},
{
"input": "2 2 2 2 2 1",
"output": "NO"
},
{
"input": "1000 1000 999 1000 1000 1000",
"output": "NO"
},
{
"input": "129 1 10 29 8 111",
"output": "NO"
},
{
"input": "1000 1000 1000 999 999 1000",
"output": "YES"
},
{
"input": "101 200 300 400 9 10",
"output": "YES"
},
{
"input": "101 400 200 300 10 9",
"output": "YES"
},
{
"input": "101 200 400 300 10 9",
"output": "YES"
},
{
"input": "101 200 300 400 10 9",
"output": "YES"
},
{
"input": "101 200 300 10 400 9",
"output": "YES"
},
{
"input": "1 1 1 1 1 5",
"output": "NO"
},
{
"input": "8 1 1 3 3 0",
"output": "NO"
},
{
"input": "1 1 2 2 3 3",
"output": "YES"
},
{
"input": "1 2 2 5 2 5",
"output": "NO"
},
{
"input": "1 2 3 6 6 6",
"output": "NO"
},
{
"input": "36 91 7 86 51 89",
"output": "NO"
},
{
"input": "10 1 1 1 23 24",
"output": "NO"
},
{
"input": "1 1 1 10 23 24",
"output": "NO"
},
{
"input": "20 10 1 2 3 44",
"output": "NO"
},
{
"input": "7 0 14 11 8 6",
"output": "NO"
},
{
"input": "100 496 1 1 1 1",
"output": "NO"
},
{
"input": "5 4 2 5 11 3",
"output": "NO"
},
{
"input": "1 3 7 8 8 9",
"output": "YES"
},
{
"input": "1 3 4 5 18 19",
"output": "YES"
},
{
"input": "5 5 1 2 2 15",
"output": "NO"
},
{
"input": "2 1 0 0 0 5",
"output": "NO"
},
{
"input": "1 6 6 1 20 2",
"output": "NO"
},
{
"input": "2 10 0 0 0 0",
"output": "NO"
},
{
"input": "1 1 3 1 1 11",
"output": "NO"
},
{
"input": "10 10 1 1 1 37",
"output": "NO"
},
{
"input": "1 1 0 0 0 4",
"output": "NO"
},
{
"input": "1 1 10 1 1 28",
"output": "NO"
},
{
"input": "1 5 5 5 6 8",
"output": "YES"
},
{
"input": "0 2 3 4 4 5",
"output": "YES"
}
] | 1,510,504,261 | 1,561 | Python 3 | OK | TESTS | 53 | 62 | 0 | # cook your dish here
# from math import *
#for _ in range(int(input().strip())):
l=[int(x) for x in input().split()]
s=sum(l)
flag=0
for i in range(1,2**6):
cnt=0
s2=0
for j in range(6):
if (1<<j) & i :
cnt+=1
s2+=l[j]
if cnt==3 and s2==(s//2):
flag=1
break
if flag==1:
break
if s%2==1:
flag=0
if flag:
print("yes")
else:
print("no") | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
Input Specification:
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Output Specification:
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['1 3 2 1 2 1\n', '1 1 1 1 1 99\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | ```python
# cook your dish here
# from math import *
#for _ in range(int(input().strip())):
l=[int(x) for x in input().split()]
s=sum(l)
flag=0
for i in range(1,2**6):
cnt=0
s2=0
for j in range(6):
if (1<<j) & i :
cnt+=1
s2+=l[j]
if cnt==3 and s2==(s//2):
flag=1
break
if flag==1:
break
if s%2==1:
flag=0
if flag:
print("yes")
else:
print("no")
``` | 3 |
|
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,692,463,734 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | z = list(map(int, input().split()))
n = z[0]
a = z[1]
def calculate_value(position):
if position % 2 == 1:
return position
else:
return position - 1
answer = calculate_value(a)
print(answer)
| 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
z = list(map(int, input().split()))
n = z[0]
a = z[1]
def calculate_value(position):
if position % 2 == 1:
return position
else:
return position - 1
answer = calculate_value(a)
print(answer)
``` | 0 |
|
295 | B | Greg and Graph | PROGRAMMING | 1,700 | [
"dp",
"graphs",
"shortest paths"
] | null | null | Greg has a weighed directed graph, consisting of *n* vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game:
- The game consists of *n* steps. - On the *i*-th step Greg removes vertex number *x**i* from the graph. As Greg removes a vertex, he also removes all the edges that go in and out of this vertex. - Before executing each step, Greg wants to know the sum of lengths of the shortest paths between all pairs of the remaining vertices. The shortest path can go through any remaining vertex. In other words, if we assume that *d*(*i*,<=*v*,<=*u*) is the shortest path between vertices *v* and *u* in the graph that formed before deleting vertex *x**i*, then Greg wants to know the value of the following sum: .
Help Greg, print the value of the required sum before each step. | The first line contains integer *n* (1<=≤<=*n*<=≤<=500) — the number of vertices in the graph.
Next *n* lines contain *n* integers each — the graph adjacency matrix: the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*a**ij*<=≤<=105,<=*a**ii*<==<=0) represents the weight of the edge that goes from vertex *i* to vertex *j*.
The next line contains *n* distinct integers: *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=*n*) — the vertices that Greg deletes. | Print *n* integers — the *i*-th number equals the required sum before the *i*-th step.
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 of the %I64d specifier. | [
"1\n0\n1\n",
"2\n0 5\n4 0\n1 2\n",
"4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3\n"
] | [
"0 ",
"9 0 ",
"17 23 404 0 "
] | none | 1,000 | [
{
"input": "1\n0\n1",
"output": "0 "
},
{
"input": "2\n0 5\n4 0\n1 2",
"output": "9 0 "
},
{
"input": "4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3",
"output": "17 23 404 0 "
},
{
"input": "4\n0 57148 51001 13357\n71125 0 98369 67226\n49388 90852 0 66291\n39573 38165 97007 0\n2 3 1 4",
"output": "723897 306638 52930 0 "
},
{
"input": "5\n0 27799 15529 16434 44291\n47134 0 90227 26873 52252\n41605 21269 0 9135 55784\n70744 17563 79061 0 73981\n70529 35681 91073 52031 0\n5 2 3 1 4",
"output": "896203 429762 232508 87178 0 "
},
{
"input": "6\n0 72137 71041 29217 96749 46417\n40199 0 55907 57677 68590 78796\n83463 50721 0 30963 31779 28646\n94529 47831 98222 0 61665 73941\n24397 66286 2971 81613 0 52501\n26285 3381 51438 45360 20160 0\n6 3 2 4 5 1",
"output": "1321441 1030477 698557 345837 121146 0 "
},
{
"input": "7\n0 34385 31901 51111 10191 14089 95685\n11396 0 8701 33277 1481 517 46253\n51313 2255 0 5948 66085 37201 65310\n21105 60985 10748 0 89271 42883 77345\n34686 29401 73565 47795 0 13793 66997\n70279 49576 62900 40002 70943 0 89601\n65045 1681 28239 12023 40414 89585 0\n3 5 7 6 1 2 4",
"output": "1108867 1016339 729930 407114 206764 94262 0 "
},
{
"input": "8\n0 74961 47889 4733 72876 21399 63105 48239\n15623 0 9680 89133 57989 63401 26001 29608\n42369 82390 0 32866 46171 11871 67489 54070\n23425 80027 18270 0 28105 42657 40876 29267\n78793 18701 7655 94798 0 88885 71424 86914\n44835 76636 11553 46031 13617 0 16971 51915\n33037 53719 43116 52806 56897 71241 0 11629\n2119 62373 93265 69513 5770 90751 36619 0\n3 7 6 5 8 1 2 4",
"output": "1450303 1188349 900316 531281 383344 219125 169160 0 "
},
{
"input": "9\n0 85236 27579 82251 69479 24737 87917 15149 52311\n59640 0 74687 34711 3685 30121 4961 7552 83399\n33376 68733 0 81357 18042 74297 15466 29476 5865\n7493 5601 3321 0 20263 55901 45756 55361 87633\n26751 17161 76681 40376 0 39745 50717 56887 90055\n18885 76353 47089 43601 21561 0 60571 33551 53753\n74595 877 71853 93156 97499 70876 0 22713 63961\n67725 25309 56358 92376 40641 35433 39781 0 97482\n81818 12561 85961 81445 3941 76799 31701 43725 0\n6 2 9 3 5 7 1 4 8",
"output": "2106523 1533575 1645151 1255230 946667 618567 287636 147737 0 "
}
] | 1,682,876,182 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | INF = 10**18
# Função que implementa o algoritmo de Floyd-Warshall para encontrar todos os menores caminhos
# Recebe como entrada uma matriz de adjacência do grafo
# Retorna uma matriz com os menores caminhos entre todos os pares de vértices
def floyd_warshall(matrix):
n = len(matrix)
dist = [[INF]*n for _ in range(n)]
for i in range(n):
for j in range(n):
if matrix[i][j] != 0:
dist[i][j] = matrix[i][j]
elif i == j:
dist[i][j] = 0
for k in range(n):
for i in range(n):
for j in range(n):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
return dist
# Lê a entrada
n = int(input())
matrix = []
for i in range(n):
linha = list(map(int, input().split()))
matrix.append(linha)
# Executa o algoritmo de Floyd-Warshall para encontrar todos os menores caminhos
dist = floyd_warshall(matrix)
# Lê a sequência de vértices que serão removidos
removidos = list(map(int, input().split()))
# Calcula as somas dos menores caminhos que não passam por cada vértice removido
resultado = []
for k in range(n-1, -1, -1): # Percorre os vértices removidos em ordem reversa
r = removidos[k]-1 # Índice do vértice na matriz de adjacência
for i in range(n):
for j in range(n):
# Se o caminho i -> r -> j é menor do que o caminho i -> j, então o vértice r faz parte do caminho i -> j
if dist[i][r] != INF and dist[r][j] != INF and dist[i][r] + dist[r][j] == dist[i][j]:
matrix[i][j] = 0 # Remove a aresta i -> j
dist = floyd_warshall(matrix) # Recalcula os menores caminhos após a remoção da aresta
s = 0
for i in range(n):
for j in range(i+1, n):
s += dist[i][j] # Soma todos os menores caminhos
resultado.append(s)
# Imprime a resposta em ordem reversa
for r in reversed(resultado):
print(r, end=' ')
print()
| Title: Greg and Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg has a weighed directed graph, consisting of *n* vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game:
- The game consists of *n* steps. - On the *i*-th step Greg removes vertex number *x**i* from the graph. As Greg removes a vertex, he also removes all the edges that go in and out of this vertex. - Before executing each step, Greg wants to know the sum of lengths of the shortest paths between all pairs of the remaining vertices. The shortest path can go through any remaining vertex. In other words, if we assume that *d*(*i*,<=*v*,<=*u*) is the shortest path between vertices *v* and *u* in the graph that formed before deleting vertex *x**i*, then Greg wants to know the value of the following sum: .
Help Greg, print the value of the required sum before each step.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=500) — the number of vertices in the graph.
Next *n* lines contain *n* integers each — the graph adjacency matrix: the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*a**ij*<=≤<=105,<=*a**ii*<==<=0) represents the weight of the edge that goes from vertex *i* to vertex *j*.
The next line contains *n* distinct integers: *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=*n*) — the vertices that Greg deletes.
Output Specification:
Print *n* integers — the *i*-th number equals the required sum before the *i*-th step.
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 of the %I64d specifier.
Demo Input:
['1\n0\n1\n', '2\n0 5\n4 0\n1 2\n', '4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3\n']
Demo Output:
['0 ', '9 0 ', '17 23 404 0 ']
Note:
none | ```python
INF = 10**18
# Função que implementa o algoritmo de Floyd-Warshall para encontrar todos os menores caminhos
# Recebe como entrada uma matriz de adjacência do grafo
# Retorna uma matriz com os menores caminhos entre todos os pares de vértices
def floyd_warshall(matrix):
n = len(matrix)
dist = [[INF]*n for _ in range(n)]
for i in range(n):
for j in range(n):
if matrix[i][j] != 0:
dist[i][j] = matrix[i][j]
elif i == j:
dist[i][j] = 0
for k in range(n):
for i in range(n):
for j in range(n):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
return dist
# Lê a entrada
n = int(input())
matrix = []
for i in range(n):
linha = list(map(int, input().split()))
matrix.append(linha)
# Executa o algoritmo de Floyd-Warshall para encontrar todos os menores caminhos
dist = floyd_warshall(matrix)
# Lê a sequência de vértices que serão removidos
removidos = list(map(int, input().split()))
# Calcula as somas dos menores caminhos que não passam por cada vértice removido
resultado = []
for k in range(n-1, -1, -1): # Percorre os vértices removidos em ordem reversa
r = removidos[k]-1 # Índice do vértice na matriz de adjacência
for i in range(n):
for j in range(n):
# Se o caminho i -> r -> j é menor do que o caminho i -> j, então o vértice r faz parte do caminho i -> j
if dist[i][r] != INF and dist[r][j] != INF and dist[i][r] + dist[r][j] == dist[i][j]:
matrix[i][j] = 0 # Remove a aresta i -> j
dist = floyd_warshall(matrix) # Recalcula os menores caminhos após a remoção da aresta
s = 0
for i in range(n):
for j in range(i+1, n):
s += dist[i][j] # Soma todos os menores caminhos
resultado.append(s)
# Imprime a resposta em ordem reversa
for r in reversed(resultado):
print(r, end=' ')
print()
``` | 0 |
|
63 | B | Settlers' Training | PROGRAMMING | 1,200 | [
"implementation"
] | B. Settlers' Training | 2 | 256 | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.
Every soldier has a rank — some natural number from 1 to *k*. 1 stands for a private and *k* stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.
To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the *n* soldiers are present.
At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank *k* are present, exactly one soldier increases his rank by one.
You know the ranks of all *n* soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank *k*. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains *n* numbers in the non-decreasing order. The *i*-th of them, *a**i*, represents the rank of the *i*-th soldier in the defense building (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=*k*). | Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank. | [
"4 4\n1 2 2 3\n",
"4 3\n1 1 1 1\n"
] | [
"4",
"5"
] | In the first example the ranks will be raised in the following manner:
1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4
Thus totals to 4 training sessions that require 4 golden coins. | 1,000 | [
{
"input": "4 4\n1 2 2 3",
"output": "4"
},
{
"input": "4 3\n1 1 1 1",
"output": "5"
},
{
"input": "3 3\n1 2 3",
"output": "2"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 5\n1",
"output": "4"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "2 6\n2 5",
"output": "4"
},
{
"input": "6 10\n1 1 3 4 9 9",
"output": "10"
},
{
"input": "7 7\n1 1 1 1 1 1 7",
"output": "11"
},
{
"input": "10 10\n1 1 1 3 3 4 7 8 8 8",
"output": "11"
},
{
"input": "10 13\n1 1 1 1 1 1 1 1 1 1",
"output": "21"
},
{
"input": "10 13\n2 6 6 7 9 9 9 10 12 12",
"output": "11"
},
{
"input": "17 9\n2 3 4 5 5 5 5 5 6 6 7 7 8 8 8 8 8",
"output": "17"
},
{
"input": "18 24\n3 3 3 4 5 7 8 8 9 9 9 9 10 10 11 11 11 11",
"output": "30"
},
{
"input": "23 2\n1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2",
"output": "12"
},
{
"input": "37 42\n1 1 1 1 1 2 2 2 2 2 3 4 4 4 4 5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8",
"output": "70"
},
{
"input": "44 50\n38 38 38 38 38 38 38 39 39 39 39 39 39 39 40 40 40 40 40 41 41 41 41 41 41 41 42 42 42 43 43 43 44 44 44 44 45 45 45 46 46 46 46 46",
"output": "47"
},
{
"input": "57 100\n2 2 4 7 8 10 12 12 14 15 16 18 19 21 21 22 25 26 26 33 38 40 44 44 44 45 47 47 50 51 51 54 54 54 54 55 56 58 61 65 67 68 68 70 74 75 78 79 83 86 89 90 92 95 96 96 97",
"output": "99"
},
{
"input": "78 10\n8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9",
"output": "78"
},
{
"input": "96 78\n20 20 20 20 20 21 21 21 22 23 23 24 24 25 25 27 28 29 30 30 30 32 32 32 33 33 33 33 34 34 35 36 37 37 39 39 41 41 41 41 42 42 43 43 43 44 44 45 46 46 48 48 49 50 51 51 51 52 53 55 55 56 56 56 56 57 58 59 60 61 61 61 62 62 62 63 63 64 64 64 65 65 65 66 66 67 68 69 71 72 72 73 73 75 75 75",
"output": "98"
},
{
"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "198"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100 100\n1 1 4 4 5 5 7 9 10 10 11 11 12 12 12 13 14 15 16 16 16 17 18 18 19 20 22 25 26 27 29 32 33 34 34 35 35 35 36 36 37 37 38 39 39 40 41 42 44 44 46 47 47 47 47 50 53 53 53 55 56 56 57 57 58 58 59 59 62 64 64 64 64 68 68 68 69 70 70 71 74 77 77 77 79 80 80 81 84 86 88 88 91 93 94 96 96 99 99 99",
"output": "108"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 8 8 8 8 8 9 9 9 9 9 9 9 10 10 10 10 10 11 11 11 11 11 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15",
"output": "184"
},
{
"input": "100 100\n20 20 20 21 21 21 21 21 22 23 23 23 23 23 23 24 24 25 25 26 26 26 26 26 27 27 27 27 28 28 28 28 29 29 29 29 29 30 30 30 30 31 32 32 34 34 34 34 34 34 34 34 35 35 35 36 36 37 37 37 37 37 37 38 38 38 39 40 41 41 42 42 42 42 42 43 43 43 44 44 44 44 44 45 45 45 45 45 46 46 46 46 46 47 47 47 48 48 48 50",
"output": "150"
},
{
"input": "100 2\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "59"
},
{
"input": "30 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 49",
"output": "77"
},
{
"input": "40 20\n5 5 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 20 20 20 20 20 20 20 20 20 20",
"output": "31"
},
{
"input": "81 90\n1 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90",
"output": "89"
},
{
"input": "100 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13",
"output": "106"
},
{
"input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 100",
"output": "197"
},
{
"input": "100 100\n49 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 51",
"output": "148"
},
{
"input": "1 100\n1",
"output": "99"
},
{
"input": "4 3\n1 1 2 2",
"output": "4"
},
{
"input": "10 100\n98 99 99 99 99 99 99 100 100 100",
"output": "7"
},
{
"input": "5 100\n1 2 2 100 100",
"output": "100"
}
] | 1,654,795,922 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 124 | 102,400 | from collections import Counter
n,k = map(int,input().split())
arr = list(map(int,input().split()))
dit = Counter(arr)
ans = 0
while len(dit) != 1 or k not in dit:
ans+=1
new = {}
for e in dit:
if e != k:
if e+1 in new:
new[e+1] +=1
else:
new[e+1] = 1
if dit[e]>1:
if e in new:
new[e]+=dit[e]-1
else:
new[e] = dit[e]-1
dit = new
# print(dit)
print(ans) | Title: Settlers' Training
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.
Every soldier has a rank — some natural number from 1 to *k*. 1 stands for a private and *k* stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.
To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the *n* soldiers are present.
At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank *k* are present, exactly one soldier increases his rank by one.
You know the ranks of all *n* soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank *k*.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains *n* numbers in the non-decreasing order. The *i*-th of them, *a**i*, represents the rank of the *i*-th soldier in the defense building (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=*k*).
Output Specification:
Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.
Demo Input:
['4 4\n1 2 2 3\n', '4 3\n1 1 1 1\n']
Demo Output:
['4', '5']
Note:
In the first example the ranks will be raised in the following manner:
1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4
Thus totals to 4 training sessions that require 4 golden coins. | ```python
from collections import Counter
n,k = map(int,input().split())
arr = list(map(int,input().split()))
dit = Counter(arr)
ans = 0
while len(dit) != 1 or k not in dit:
ans+=1
new = {}
for e in dit:
if e != k:
if e+1 in new:
new[e+1] +=1
else:
new[e+1] = 1
if dit[e]>1:
if e in new:
new[e]+=dit[e]-1
else:
new[e] = dit[e]-1
dit = new
# print(dit)
print(ans)
``` | 3.968809 |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,692,693,572 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n, k = map(int, input().split())
o, e = (n // 2) + (n % 2), (n // 2)
if k <= o:
print((2 * k) - 1)
else:
print(2 * 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
n, k = map(int, input().split())
o, e = (n // 2) + (n % 2), (n // 2)
if k <= o:
print((2 * k) - 1)
else:
print(2 * k)
``` | 0 |
|
6 | E | Exposition | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"dsu",
"trees",
"two pointers"
] | E. Exposition | 1 | 64 | There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than *k* millimeters.
The library has *n* volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is *h**i*. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. | The first line of the input data contains two integer numbers separated by a space *n* (1<=≤<=*n*<=≤<=105) and *k* (0<=≤<=*k*<=≤<=106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains *n* integer numbers separated by a space. Each number *h**i* (1<=≤<=*h**i*<=≤<=106) is the height of the *i*-th book in millimeters. | In the first line of the output data print two numbers *a* and *b* (separate them by a space), where *a* is the maximum amount of books the organizers can include into the exposition, and *b* — the amount of the time periods, during which Berlbury published *a* books, and the height difference between the lowest and the highest among these books is not more than *k* milllimeters.
In each of the following *b* lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. | [
"3 3\n14 12 10\n",
"2 0\n10 10\n",
"4 5\n8 19 10 13\n"
] | [
"2 2\n1 2\n2 3\n",
"2 1\n1 2\n",
"2 1\n3 4\n"
] | none | 0 | [
{
"input": "3 3\n14 12 10",
"output": "2 2\n1 2\n2 3"
},
{
"input": "2 0\n10 10",
"output": "2 1\n1 2"
},
{
"input": "4 5\n8 19 10 13",
"output": "2 1\n3 4"
},
{
"input": "1 1\n1",
"output": "1 1\n1 1"
},
{
"input": "2 10\n35 45",
"output": "2 1\n1 2"
},
{
"input": "4 8\n89 33 54 75",
"output": "1 4\n1 1\n2 2\n3 3\n4 4"
},
{
"input": "5 1\n9 6 8 7 5",
"output": "2 1\n3 4"
},
{
"input": "3 3\n3 8 6",
"output": "2 1\n2 3"
},
{
"input": "4 1000000\n100001 1 200001 300001",
"output": "4 1\n1 4"
},
{
"input": "4 1000\n11497 9999 10730 12280",
"output": "2 1\n2 3"
},
{
"input": "3 0\n1000000 1000000 1000000",
"output": "3 1\n1 3"
},
{
"input": "4 50\n165 182 157 132",
"output": "4 1\n1 4"
},
{
"input": "5 173\n350 250 200 300 400",
"output": "4 1\n1 4"
},
{
"input": "4 0\n1 1 1 1",
"output": "4 1\n1 4"
},
{
"input": "2 1000000\n1 1000000",
"output": "2 1\n1 2"
},
{
"input": "7 14\n28 28 29 35 25 29 28",
"output": "7 1\n1 7"
},
{
"input": "10 163\n7541 2535 5883 5775 2821 5962 4489 5548 2852 4595",
"output": "2 1\n3 4"
},
{
"input": "15 793\n98580 27440 3719 73977 34819 64092 89939 75329 72884 66502 17464 73662 6666 47984 45348",
"output": "1 15\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15"
},
{
"input": "28 543\n1921 1700 1363 2580 2693 3144 2269 908 3863 3750 2151 3039 1581 3395 1133 1804 1464 2040 2372 2475 1240 800 3521 3270 2815 1026 3625 2930",
"output": "3 1\n18 20"
},
{
"input": "55 1000\n2612 1306 4300 1790 3173 9493 7209 7763 8563 4534 7466 1281 4483 6863 3787 7292 3957 8775 7221 4016 5743 6556 2070 2119 4795 9094 1913 2077 8786 4520 1865 2357 7871 3288 8231 5808 9383 9820 9974 3056 5343 2169 5177 6299 5805 8132 9315 6747 5226 3531 1206 4073 8290 1423 6720",
"output": "3 1\n37 39"
}
] | 1,459,575,357 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 23 | 1,500 | 5,427,200 | import math
from collections import deque
line=input().split()
a=int(line[0])
b=int(line[1])
line=input().split()
h=deque()
for i in range(a):
h.append(int(line[i]))
ans=[]
books=1
for i in range(a):
c=0
maxi=h[i]
mini=h[i]
for j in range(a-i):
if h[i+j]>maxi:
maxi=h[i+j]
if h[i+j]<mini:
mini=h[i+j]
if abs(maxi-mini)>b:
break
else:
c+=1
if c>books:
ans.clear()
books=c
if c==books:
#print(i,j,c)
tem=[]
tem.append(str(i+1))
tem.append(str(i+c))
ans.append(tem)
print(books,len(ans))
for i in range(len(ans)):
print(" ".join(ans[i]))
| Title: Exposition
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than *k* millimeters.
The library has *n* volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is *h**i*. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.
Input Specification:
The first line of the input data contains two integer numbers separated by a space *n* (1<=≤<=*n*<=≤<=105) and *k* (0<=≤<=*k*<=≤<=106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains *n* integer numbers separated by a space. Each number *h**i* (1<=≤<=*h**i*<=≤<=106) is the height of the *i*-th book in millimeters.
Output Specification:
In the first line of the output data print two numbers *a* and *b* (separate them by a space), where *a* is the maximum amount of books the organizers can include into the exposition, and *b* — the amount of the time periods, during which Berlbury published *a* books, and the height difference between the lowest and the highest among these books is not more than *k* milllimeters.
In each of the following *b* lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.
Demo Input:
['3 3\n14 12 10\n', '2 0\n10 10\n', '4 5\n8 19 10 13\n']
Demo Output:
['2 2\n1 2\n2 3\n', '2 1\n1 2\n', '2 1\n3 4\n']
Note:
none | ```python
import math
from collections import deque
line=input().split()
a=int(line[0])
b=int(line[1])
line=input().split()
h=deque()
for i in range(a):
h.append(int(line[i]))
ans=[]
books=1
for i in range(a):
c=0
maxi=h[i]
mini=h[i]
for j in range(a-i):
if h[i+j]>maxi:
maxi=h[i+j]
if h[i+j]<mini:
mini=h[i+j]
if abs(maxi-mini)>b:
break
else:
c+=1
if c>books:
ans.clear()
books=c
if c==books:
#print(i,j,c)
tem=[]
tem.append(str(i+1))
tem.append(str(i+c))
ans.append(tem)
print(books,len(ans))
for i in range(len(ans)):
print(" ".join(ans[i]))
``` | 0 |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players alternate turns.
The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.
You want to know what number will be left on the board after $n - 1$ turns if both players make optimal moves. | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"output": "53"
},
{
"input": "1\n124",
"output": "124"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 1 1000",
"output": "1"
},
{
"input": "2\n322 322",
"output": "322"
},
{
"input": "3\n9 92 12",
"output": "12"
},
{
"input": "3\n1 2 2",
"output": "2"
}
] | 1,596,354,365 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 6,963,200 | t_moves=int(input())
moves=t_moves-1
a=list(map(int, input().split()))
a.sort()
i=0;j=t_moves-1
while moves:
if moves==1:
j-=1
moves-=1
else:
j-=1;i+=1
moves-=2
print(a[j]) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players alternate turns.
The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.
You want to know what number will be left on the board after $n - 1$ turns if both players make optimal moves.
Input Specification:
The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Output Specification:
Print one number that will be left on the board.
Demo Input:
['3\n2 1 3\n', '3\n2 2 2\n']
Demo Output:
['2', '2']
Note:
In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | ```python
t_moves=int(input())
moves=t_moves-1
a=list(map(int, input().split()))
a.sort()
i=0;j=t_moves-1
while moves:
if moves==1:
j-=1
moves-=1
else:
j-=1;i+=1
moves-=2
print(a[j])
``` | 3 |
|
769 | A | Year of University Entrance | PROGRAMMING | 800 | [
"*special",
"implementation",
"sortings"
] | null | null | There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than *x* from the year of university entrance of this student, where *x* — some non-negative integer. A value *x* is not given, but it can be uniquely determined from the available data. Note that students don't join other groups.
You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. | The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member.
It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. | Print the year of Igor's university entrance. | [
"3\n2014 2016 2015\n",
"1\n2050\n"
] | [
"2015\n",
"2050\n"
] | In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.
In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance. | 500 | [
{
"input": "3\n2014 2016 2015",
"output": "2015"
},
{
"input": "1\n2050",
"output": "2050"
},
{
"input": "1\n2010",
"output": "2010"
},
{
"input": "1\n2011",
"output": "2011"
},
{
"input": "3\n2010 2011 2012",
"output": "2011"
},
{
"input": "3\n2049 2047 2048",
"output": "2048"
},
{
"input": "5\n2043 2042 2041 2044 2040",
"output": "2042"
},
{
"input": "5\n2012 2013 2014 2015 2016",
"output": "2014"
},
{
"input": "1\n2045",
"output": "2045"
},
{
"input": "1\n2046",
"output": "2046"
},
{
"input": "1\n2099",
"output": "2099"
},
{
"input": "1\n2100",
"output": "2100"
},
{
"input": "3\n2011 2010 2012",
"output": "2011"
},
{
"input": "3\n2011 2012 2010",
"output": "2011"
},
{
"input": "3\n2012 2011 2010",
"output": "2011"
},
{
"input": "3\n2010 2012 2011",
"output": "2011"
},
{
"input": "3\n2012 2010 2011",
"output": "2011"
},
{
"input": "3\n2047 2048 2049",
"output": "2048"
},
{
"input": "3\n2047 2049 2048",
"output": "2048"
},
{
"input": "3\n2048 2047 2049",
"output": "2048"
},
{
"input": "3\n2048 2049 2047",
"output": "2048"
},
{
"input": "3\n2049 2048 2047",
"output": "2048"
},
{
"input": "5\n2011 2014 2012 2013 2010",
"output": "2012"
},
{
"input": "5\n2014 2013 2011 2012 2015",
"output": "2013"
},
{
"input": "5\n2021 2023 2024 2020 2022",
"output": "2022"
},
{
"input": "5\n2081 2079 2078 2080 2077",
"output": "2079"
},
{
"input": "5\n2095 2099 2097 2096 2098",
"output": "2097"
},
{
"input": "5\n2097 2099 2100 2098 2096",
"output": "2098"
},
{
"input": "5\n2012 2010 2014 2011 2013",
"output": "2012"
},
{
"input": "5\n2012 2011 2013 2015 2014",
"output": "2013"
},
{
"input": "5\n2023 2024 2022 2021 2020",
"output": "2022"
},
{
"input": "5\n2077 2078 2080 2079 2081",
"output": "2079"
},
{
"input": "5\n2099 2096 2095 2097 2098",
"output": "2097"
},
{
"input": "5\n2097 2100 2098 2096 2099",
"output": "2098"
},
{
"input": "5\n2011 2014 2013 2010 2012",
"output": "2012"
},
{
"input": "5\n2013 2011 2015 2012 2014",
"output": "2013"
},
{
"input": "5\n2024 2020 2021 2023 2022",
"output": "2022"
},
{
"input": "5\n2079 2080 2077 2081 2078",
"output": "2079"
},
{
"input": "5\n2095 2097 2096 2098 2099",
"output": "2097"
},
{
"input": "5\n2099 2096 2100 2097 2098",
"output": "2098"
},
{
"input": "5\n2034 2033 2036 2032 2035",
"output": "2034"
},
{
"input": "5\n2030 2031 2033 2032 2029",
"output": "2031"
},
{
"input": "5\n2093 2092 2094 2096 2095",
"output": "2094"
},
{
"input": "5\n2012 2015 2014 2013 2011",
"output": "2013"
},
{
"input": "5\n2056 2057 2058 2059 2060",
"output": "2058"
}
] | 1,636,371,012 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 4,300,800 | n = int(input())
g = list(map(int, input().split()))
print(sum(g) // n)
| Title: Year of University Entrance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than *x* from the year of university entrance of this student, where *x* — some non-negative integer. A value *x* is not given, but it can be uniquely determined from the available data. Note that students don't join other groups.
You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance.
Input Specification:
The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member.
It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly.
Output Specification:
Print the year of Igor's university entrance.
Demo Input:
['3\n2014 2016 2015\n', '1\n2050\n']
Demo Output:
['2015\n', '2050\n']
Note:
In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.
In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance. | ```python
n = int(input())
g = list(map(int, input().split()))
print(sum(g) // n)
``` | 3 |
|
580 | C | Kefa and Park | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.
The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than *m* consecutive vertices with cats.
Your task is to help Kefa count the number of restaurants where he can go. | The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=*n*) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then vertex *i* has no cat), or equals to 1 (then vertex *i* has a cat).
Next *n*<=-<=1 lines contains the edges of the tree in the format "*x**i* *y**i*" (without the quotes) (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*), where *x**i* and *y**i* are the vertices of the tree, connected by an edge.
It is guaranteed that the given set of edges specifies a tree. | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats. | [
"4 1\n1 1 0 0\n1 2\n1 3\n1 4\n",
"7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n"
] | [
"2\n",
"2\n"
] | Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.
Note to the first sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/785114b4b3f5336f02078c25750f87c5a1d0b4be.png" style="max-width: 100.0%;max-height: 100.0%;"/> The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.
Note to the second sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/e5c07640680c837aec99126d94287872e69aa09a.png" style="max-width: 100.0%;max-height: 100.0%;"/> The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | 1,500 | [
{
"input": "4 1\n1 1 0 0\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7",
"output": "2"
},
{
"input": "3 2\n1 1 1\n1 2\n2 3",
"output": "0"
},
{
"input": "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5",
"output": "1"
},
{
"input": "6 1\n1 0 1 1 0 0\n1 2\n1 3\n1 4\n1 5\n1 6",
"output": "3"
},
{
"input": "7 3\n1 1 1 1 1 0 1\n1 2\n1 3\n2 4\n3 5\n5 6\n6 7",
"output": "2"
},
{
"input": "15 2\n1 0 1 0 1 0 0 0 0 0 0 0 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n4 8\n4 9\n5 10\n5 11\n6 12\n6 13\n7 14\n7 15",
"output": "8"
},
{
"input": "2 1\n1 1\n2 1",
"output": "0"
},
{
"input": "12 3\n1 0 1 0 1 1 1 1 0 0 0 0\n6 7\n12 1\n9 7\n1 4\n10 7\n7 1\n11 8\n5 1\n3 7\n5 8\n4 2",
"output": "7"
}
] | 1,692,007,401 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 780 | 24,576,000 | n, m = map(int, input().split())
a = list(map(int, input().split()))
adjlist = [[] for _ in range(n)]
for i in range(n-1):
x, y = map(int, input().split())
adjlist[x-1] += [y-1]
adjlist[y-1] += [x-1]
def dfs(node: int) ->int:
seen = [0]*n
ret = 0
s = [(node, 0)]
seen[node] = 1
while s:
cur, cat = s.pop()
if a[cur]: cat += 1
else: cat = 0
if cat > m: continue
isLeaf = True
for nb in adjlist[cur]:
if not seen[nb]:
seen[nb] = 1
s.append((nb, cat))
isLeaf = False
if isLeaf: ret += 1
return ret
ans = dfs(0)
print(ans) | Title: Kefa and Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.
The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than *m* consecutive vertices with cats.
Your task is to help Kefa count the number of restaurants where he can go.
Input Specification:
The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=*n*) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then vertex *i* has no cat), or equals to 1 (then vertex *i* has a cat).
Next *n*<=-<=1 lines contains the edges of the tree in the format "*x**i* *y**i*" (without the quotes) (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*), where *x**i* and *y**i* are the vertices of the tree, connected by an edge.
It is guaranteed that the given set of edges specifies a tree.
Output Specification:
A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats.
Demo Input:
['4 1\n1 1 0 0\n1 2\n1 3\n1 4\n', '7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n']
Demo Output:
['2\n', '2\n']
Note:
Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.
Note to the first sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/785114b4b3f5336f02078c25750f87c5a1d0b4be.png" style="max-width: 100.0%;max-height: 100.0%;"/> The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.
Note to the second sample test: <img class="tex-graphics" src="https://espresso.codeforces.com/e5c07640680c837aec99126d94287872e69aa09a.png" style="max-width: 100.0%;max-height: 100.0%;"/> The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7. | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
adjlist = [[] for _ in range(n)]
for i in range(n-1):
x, y = map(int, input().split())
adjlist[x-1] += [y-1]
adjlist[y-1] += [x-1]
def dfs(node: int) ->int:
seen = [0]*n
ret = 0
s = [(node, 0)]
seen[node] = 1
while s:
cur, cat = s.pop()
if a[cur]: cat += 1
else: cat = 0
if cat > m: continue
isLeaf = True
for nb in adjlist[cur]:
if not seen[nb]:
seen[nb] = 1
s.append((nb, cat))
isLeaf = False
if isLeaf: ret += 1
return ret
ans = dfs(0)
print(ans)
``` | 3 |
|
724 | B | Batch Sort | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | You are given a table consisting of *n* rows and *m* columns.
Numbers in each row form a permutation of integers from 1 to *m*.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to *n*<=+<=1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1,<=2,<=...,<=*m* in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=20) — the number of rows and the number of columns in the given table.
Each of next *n* lines contains *m* integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to *m*. | If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). | [
"2 4\n1 3 2 4\n1 3 4 2\n",
"4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3\n",
"3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, one can act in the following way:
1. Swap second and third columns. Now the table is <center class="tex-equation">1 2 3 4</center> <center class="tex-equation">1 4 3 2</center> 1. In the second row, swap the second and the fourth elements. Now the table is <center class="tex-equation">1 2 3 4</center> <center class="tex-equation">1 2 3 4</center> | 1,000 | [
{
"input": "2 4\n1 3 2 4\n1 3 4 2",
"output": "YES"
},
{
"input": "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3",
"output": "NO"
},
{
"input": "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5",
"output": "YES"
},
{
"input": "3 10\n1 2 3 4 5 6 7 10 9 8\n5 2 3 4 1 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10",
"output": "YES"
},
{
"input": "5 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 8 5 6 7 10 9 4 11 12\n1 5 3 4 2 6 7 10 9 8 11 12\n1 2 3 4 5 6 7 10 9 8 11 12",
"output": "YES"
},
{
"input": "4 10\n3 2 8 10 5 6 7 1 9 4\n1 2 9 4 5 3 7 8 10 6\n7 5 3 4 8 6 1 2 9 10\n4 2 3 9 8 6 7 5 1 10",
"output": "NO"
},
{
"input": "5 10\n9 2 3 4 5 6 7 8 1 10\n9 5 3 4 2 6 7 8 1 10\n9 5 3 4 2 6 7 8 1 10\n9 5 3 4 2 6 7 8 1 10\n9 5 3 4 2 10 7 8 1 6",
"output": "NO"
},
{
"input": "1 10\n9 10 4 2 3 5 7 1 8 6",
"output": "NO"
},
{
"input": "5 10\n6 4 7 3 5 8 1 9 10 2\n1 5 10 6 3 4 9 7 2 8\n3 2 1 7 8 6 5 4 10 9\n7 9 1 6 8 2 4 5 3 10\n3 4 6 9 8 7 1 2 10 5",
"output": "NO"
},
{
"input": "20 2\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n2 1",
"output": "YES"
},
{
"input": "20 3\n3 2 1\n2 3 1\n2 3 1\n2 1 3\n1 3 2\n2 1 3\n1 2 3\n3 2 1\n3 1 2\n1 3 2\n3 1 2\n2 1 3\n2 3 1\n2 3 1\n3 1 2\n1 3 2\n3 1 2\n1 3 2\n3 1 2\n3 1 2",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n1 2 3 4 5 6 7 10 9 8",
"output": "YES"
},
{
"input": "1 10\n6 9 3 4 5 1 8 7 2 10",
"output": "NO"
},
{
"input": "5 20\n1 2 3 4 5 6 7 8 9 10 11 12 19 14 15 16 17 18 13 20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 7 19 9 10 11 12 13 14 15 16 17 18 8 20\n1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"output": "YES"
},
{
"input": "5 20\n1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 17 18 19 20\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20\n1 12 3 4 5 6 7 8 9 10 11 2 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20",
"output": "YES"
},
{
"input": "5 20\n1 2 3 4 12 18 7 8 9 10 11 5 13 14 15 16 17 6 19 20\n6 2 3 4 5 1 7 8 9 10 11 12 13 20 15 16 17 18 19 14\n4 2 3 1 5 11 7 8 9 10 6 12 13 14 15 16 17 18 19 20\n1 2 3 4 5 6 19 8 9 10 11 12 13 14 15 20 17 18 7 16\n1 2 9 4 5 6 7 8 18 10 11 12 13 14 15 16 17 3 19 20",
"output": "NO"
},
{
"input": "1 10\n4 2 3 8 5 6 7 1 9 10",
"output": "YES"
},
{
"input": "1 10\n3 2 1 4 5 6 7 8 10 9",
"output": "YES"
},
{
"input": "5 20\n1 2 3 4 5 6 7 8 9 10 19 12 18 14 15 16 17 13 11 20\n1 2 11 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 3 20\n13 2 3 4 5 6 7 8 9 10 19 12 1 14 15 16 17 18 11 20\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20\n1 2 3 4 5 6 7 8 9 10 19 12 13 14 15 16 17 18 11 20",
"output": "YES"
},
{
"input": "5 20\n1 2 3 4 5 6 16 8 9 10 11 12 13 14 15 7 17 18 19 20\n1 2 3 14 5 6 16 8 9 10 11 12 13 4 15 7 17 18 19 20\n1 2 3 4 5 6 16 8 18 10 11 12 13 14 15 7 17 9 19 20\n1 2 3 4 5 6 16 8 9 15 11 12 13 14 10 7 17 18 19 20\n1 2 18 4 5 6 16 8 9 10 11 12 13 14 15 7 17 3 19 20",
"output": "YES"
},
{
"input": "5 20\n1 2 18 4 5 6 7 8 9 10 11 12 13 14 15 16 19 3 17 20\n8 2 3 9 5 6 7 1 4 10 11 12 13 14 15 16 17 18 19 20\n7 2 3 4 5 6 1 8 9 10 11 12 13 14 15 16 17 20 19 18\n1 2 3 12 5 6 7 8 9 17 11 4 13 14 15 16 10 18 19 20\n1 11 3 4 9 6 7 8 5 10 2 12 13 14 15 16 17 18 19 20",
"output": "NO"
},
{
"input": "1 10\n10 2 3 4 5 9 7 8 6 1",
"output": "YES"
},
{
"input": "1 10\n1 9 2 4 6 5 8 3 7 10",
"output": "NO"
},
{
"input": "5 20\n1 3 2 19 5 6 7 8 9 17 11 12 13 14 15 16 10 18 4 20\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\n1 3 2 4 20 6 7 8 9 17 11 12 13 14 15 16 10 18 19 5\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20\n1 3 2 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20",
"output": "NO"
},
{
"input": "5 20\n1 6 17 4 5 2 7 14 9 10 11 12 13 8 15 16 3 18 19 20\n5 6 17 4 1 2 7 8 9 10 11 12 13 14 15 16 3 18 19 20\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 18 3 16 19 20\n1 6 17 4 5 2 7 8 9 10 11 12 13 14 15 16 3 18 20 19\n1 6 17 8 5 2 7 4 9 10 11 12 13 14 15 16 3 18 19 20",
"output": "NO"
},
{
"input": "5 20\n10 2 9 4 5 6 7 8 15 1 11 16 13 14 3 12 17 18 19 20\n10 2 3 4 5 6 7 1 9 8 11 16 13 14 15 12 17 18 19 20\n9 2 3 4 5 6 7 8 10 1 11 16 13 14 15 12 20 18 19 17\n10 2 3 4 7 6 5 8 9 1 11 16 18 14 15 12 17 13 19 20\n10 2 3 4 5 6 7 8 9 20 11 16 14 13 15 12 17 18 19 1",
"output": "NO"
},
{
"input": "1 4\n2 3 4 1",
"output": "NO"
},
{
"input": "3 3\n1 2 3\n2 1 3\n3 2 1",
"output": "YES"
},
{
"input": "15 6\n2 1 4 3 6 5\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6",
"output": "NO"
},
{
"input": "2 4\n4 3 2 1\n4 3 1 2",
"output": "NO"
},
{
"input": "2 4\n1 2 3 4\n2 1 4 3",
"output": "YES"
},
{
"input": "10 6\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1\n6 5 4 3 2 1",
"output": "NO"
},
{
"input": "4 4\n2 1 4 3\n2 1 4 3\n2 1 4 3\n2 1 4 3",
"output": "YES"
},
{
"input": "4 8\n1 2 3 4 6 5 8 7\n1 2 3 4 6 5 8 7\n1 2 3 4 6 5 8 7\n1 2 3 4 6 5 8 7",
"output": "YES"
},
{
"input": "4 6\n1 2 3 5 6 4\n3 2 1 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6",
"output": "NO"
},
{
"input": "3 3\n1 2 3\n3 1 2\n1 3 2",
"output": "YES"
},
{
"input": "2 5\n5 2 1 4 3\n2 1 5 4 3",
"output": "YES"
},
{
"input": "20 8\n4 3 2 1 5 6 7 8\n1 2 3 4 8 7 6 5\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8",
"output": "NO"
},
{
"input": "6 8\n8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8",
"output": "NO"
},
{
"input": "6 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11\n1 2 3 4 5 6 7 8 10 9 12 11",
"output": "YES"
},
{
"input": "6 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 9 10 11 12\n1 2 3 4 5 6 7 8 10 11 12 9",
"output": "NO"
},
{
"input": "2 4\n2 3 1 4\n3 2 1 4",
"output": "YES"
},
{
"input": "2 4\n4 3 2 1\n1 2 3 4",
"output": "YES"
},
{
"input": "2 4\n1 2 3 4\n4 3 2 1",
"output": "YES"
},
{
"input": "2 6\n2 3 1 4 5 6\n1 2 3 5 6 4",
"output": "NO"
},
{
"input": "3 3\n2 3 1\n2 3 1\n1 2 3",
"output": "YES"
},
{
"input": "2 6\n6 5 4 3 2 1\n6 5 4 3 2 1",
"output": "NO"
},
{
"input": "5 4\n2 1 4 3\n2 1 4 3\n2 1 4 3\n2 1 4 3\n2 1 4 3",
"output": "YES"
},
{
"input": "5 4\n3 1 4 2\n3 1 4 2\n3 1 4 2\n3 1 4 2\n3 1 4 2",
"output": "NO"
},
{
"input": "6 8\n3 8 1 4 5 6 7 2\n1 8 3 6 5 4 7 2\n1 8 3 5 4 6 7 2\n1 8 3 7 5 6 4 2\n1 8 3 7 5 6 4 2\n1 8 3 7 5 6 4 2",
"output": "YES"
},
{
"input": "2 5\n5 2 4 3 1\n2 1 5 4 3",
"output": "NO"
},
{
"input": "4 4\n2 3 1 4\n1 2 3 4\n2 3 1 4\n2 1 3 4",
"output": "YES"
},
{
"input": "2 4\n1 2 4 3\n2 1 4 3",
"output": "YES"
},
{
"input": "3 5\n1 2 4 3 5\n2 1 4 3 5\n1 2 3 4 5",
"output": "YES"
},
{
"input": "3 10\n2 1 3 4 5 6 8 7 10 9\n1 2 3 4 5 6 8 7 10 9\n1 2 3 4 6 5 8 7 10 9",
"output": "NO"
},
{
"input": "3 4\n3 1 2 4\n3 2 4 1\n3 1 2 4",
"output": "YES"
},
{
"input": "2 5\n1 4 2 3 5\n1 2 4 5 3",
"output": "YES"
},
{
"input": "2 5\n2 1 5 3 4\n2 1 5 3 4",
"output": "NO"
},
{
"input": "3 6\n2 3 1 4 5 6\n2 1 4 3 5 6\n1 2 3 4 5 6",
"output": "YES"
},
{
"input": "6 6\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "2 4\n2 1 4 3\n2 1 4 3",
"output": "YES"
},
{
"input": "6 6\n6 5 4 3 2 1\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6",
"output": "NO"
},
{
"input": "4 6\n6 5 4 3 2 1\n1 2 3 4 5 6\n1 2 3 4 5 6\n1 2 3 4 5 6",
"output": "NO"
},
{
"input": "2 4\n2 3 1 4\n1 2 3 4",
"output": "YES"
},
{
"input": "3 5\n1 2 3 4 5\n1 3 4 2 5\n1 4 2 3 5",
"output": "YES"
},
{
"input": "4 3\n1 2 3\n1 2 3\n1 2 3\n3 1 2",
"output": "YES"
},
{
"input": "2 3\n3 1 2\n1 2 3",
"output": "YES"
},
{
"input": "2 5\n2 1 5 4 3\n2 1 5 4 3",
"output": "YES"
},
{
"input": "7 4\n1 2 3 4\n4 3 2 1\n4 3 2 1\n4 3 2 1\n4 3 2 1\n4 3 2 1\n4 3 2 1",
"output": "YES"
},
{
"input": "3 3\n1 2 3\n1 3 2\n3 1 2",
"output": "YES"
},
{
"input": "10 6\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5\n2 1 4 3 6 5",
"output": "NO"
}
] | 1,475,959,639 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,608,000 | I=lambda:map(int,input().split())
n,m=I()
t=[[]for _ in'0'*m]
e=list(range(1,m+1))
r='NO'
for _ in '0'*n:
for i,v in zip(range(m),I()):t[i]+=[v]
for i in range(m):
for j in range(i,m):
t[i],t[j]=t[j],t[i]
if all(3>sum(a!=b for a,b in zip(s,e))for s in t):r='YES'
t[i],t[j]=t[j],t[i]
print(r) | Title: Batch Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a table consisting of *n* rows and *m* columns.
Numbers in each row form a permutation of integers from 1 to *m*.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to *n*<=+<=1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1,<=2,<=...,<=*m* in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=20) — the number of rows and the number of columns in the given table.
Each of next *n* lines contains *m* integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to *m*.
Output Specification:
If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
Demo Input:
['2 4\n1 3 2 4\n1 3 4 2\n', '4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3\n', '3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample, one can act in the following way:
1. Swap second and third columns. Now the table is <center class="tex-equation">1 2 3 4</center> <center class="tex-equation">1 4 3 2</center> 1. In the second row, swap the second and the fourth elements. Now the table is <center class="tex-equation">1 2 3 4</center> <center class="tex-equation">1 2 3 4</center> | ```python
I=lambda:map(int,input().split())
n,m=I()
t=[[]for _ in'0'*m]
e=list(range(1,m+1))
r='NO'
for _ in '0'*n:
for i,v in zip(range(m),I()):t[i]+=[v]
for i in range(m):
for j in range(i,m):
t[i],t[j]=t[j],t[i]
if all(3>sum(a!=b for a,b in zip(s,e))for s in t):r='YES'
t[i],t[j]=t[j],t[i]
print(r)
``` | 0 |
|
980 | E | The Number Games | PROGRAMMING | 2,200 | [
"data structures",
"greedy",
"trees"
] | null | null | The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has $n$ districts numbered from $1$ to $n$, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district $i$ is equal to $2^i$.
This year, the president decided to reduce the costs. He wants to remove $k$ contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.
The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.
Which contestants should the president remove? | The first line of input contains two integers $n$ and $k$ ($1 \leq k < n \leq 10^6$) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.
The next $n-1$ lines each contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), that describe a road that connects two different districts $a$ and $b$ in the nation. It is guaranteed that there is exactly one path between every two districts. | Print $k$ space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number. | [
"6 3\n2 1\n2 6\n4 2\n5 6\n2 3\n",
"8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5\n"
] | [
"1 3 4\n",
"1 3 4 5\n"
] | In the first sample, the maximum possible total number of fans is $2^2 + 2^5 + 2^6 = 100$. We can achieve it by removing the contestants of the districts 1, 3, and 4. | 2,500 | [
{
"input": "6 3\n2 1\n2 6\n4 2\n5 6\n2 3",
"output": "1 3 4"
},
{
"input": "8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5",
"output": "1 3 4 5"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 1\n2 1\n2 3",
"output": "1"
},
{
"input": "3 2\n1 3\n1 2",
"output": "1 2"
},
{
"input": "4 2\n4 2\n1 4\n3 2",
"output": "1 3"
},
{
"input": "15 3\n9 11\n11 8\n7 9\n9 14\n12 8\n10 7\n1 14\n1 5\n12 15\n10 3\n5 2\n13 15\n4 13\n6 4",
"output": "1 2 5"
},
{
"input": "15 12\n2 3\n2 14\n4 3\n4 10\n3 5\n1 4\n1 12\n4 15\n3 9\n10 7\n11 2\n12 8\n15 13\n1 6",
"output": "1 2 3 5 6 7 8 9 10 11 12 14"
},
{
"input": "32 16\n32 8\n11 32\n22 8\n22 17\n22 3\n16 22\n8 12\n22 7\n8 27\n11 6\n32 4\n9 8\n10 22\n22 31\n1 22\n21 11\n22 15\n14 32\n32 30\n22 29\n24 11\n18 11\n25 32\n13 8\n2 32\n28 8\n32 5\n11 20\n11 19\n22 23\n26 32",
"output": "1 2 3 4 5 6 7 9 10 12 13 14 15 16 17 18"
},
{
"input": "32 1\n30 25\n30 8\n8 22\n22 20\n21 20\n6 21\n29 6\n4 29\n2 4\n13 2\n1 13\n1 11\n11 24\n31 24\n31 15\n15 14\n27 14\n16 27\n5 16\n12 5\n9 12\n9 18\n3 18\n3 17\n17 19\n19 32\n32 10\n10 26\n7 26\n7 23\n23 28",
"output": "25"
},
{
"input": "32 2\n7 20\n15 20\n7 18\n31 20\n28 15\n20 25\n27 31\n27 6\n27 12\n6 16\n22 6\n21 22\n13 6\n16 5\n23 5\n23 26\n23 24\n23 17\n24 14\n17 4\n29 4\n2 24\n30 29\n1 29\n8 4\n30 32\n11 2\n32 3\n1 9\n11 10\n19 32",
"output": "3 8"
},
{
"input": "64 46\n52 22\n38 52\n28 38\n46 38\n30 38\n30 37\n7 37\n37 48\n48 27\n2 7\n27 11\n32 2\n32 35\n8 11\n59 32\n58 59\n59 24\n58 40\n40 4\n40 49\n40 41\n49 16\n9 16\n5 9\n12 9\n9 62\n3 62\n12 63\n63 25\n64 63\n63 42\n36 42\n45 36\n14 45\n53 45\n39 53\n60 39\n50 39\n50 23\n23 10\n19 50\n20 10\n19 56\n21 56\n31 56\n44 31\n26 31\n1 31\n43 44\n15 26\n15 6\n6 29\n47 6\n18 6\n29 55\n18 54\n33 54\n61 55\n54 17\n61 34\n13 17\n17 51\n57 34",
"output": "1 2 3 4 5 6 7 8 10 11 13 14 15 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 37 38 43 44 46 47 48 51 52 54 55 56 57 61"
},
{
"input": "64 63\n11 51\n64 11\n64 39\n11 6\n24 64\n51 63\n43 51\n64 29\n6 22\n47 6\n1 47\n41 22\n41 38\n4 47\n35 47\n41 23\n45 1\n52 35\n26 45\n15 35\n21 35\n23 32\n12 21\n21 62\n25 21\n28 25\n15 54\n57 12\n20 28\n48 57\n8 57\n20 44\n46 28\n18 57\n8 9\n27 9\n48 34\n50 46\n9 56\n9 61\n7 56\n19 61\n61 17\n42 17\n19 58\n58 30\n7 14\n7 59\n31 19\n17 5\n55 14\n13 31\n2 31\n59 40\n55 49\n2 60\n2 53\n36 2\n37 13\n2 16\n53 33\n37 10\n60 3",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63"
},
{
"input": "64 21\n33 48\n33 64\n55 48\n11 55\n18 11\n62 55\n48 57\n17 62\n64 52\n30 48\n49 48\n23 18\n13 11\n9 64\n11 5\n11 45\n2 55\n62 56\n64 36\n33 10\n34 18\n55 43\n3 48\n60 62\n48 32\n33 8\n62 41\n44 11\n33 46\n15 33\n14 62\n11 6\n64 31\n62 20\n64 25\n62 51\n53 33\n62 40\n18 4\n16 62\n21 11\n33 22\n37 33\n59 62\n55 7\n27 64\n24 64\n39 64\n19 62\n54 55\n33 61\n47 48\n58 55\n42 55\n38 11\n50 18\n28 48\n11 26\n11 1\n62 35\n64 29\n12 33\n18 63",
"output": "1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 19 20 21 22 23"
}
] | 1,594,812,678 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 140 | 20,172,800 | import sys
import heapq as hp
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,k=I()
g=[[] for i in range(n)]
for i in range(n-1):
a,b=I()
g[a-1].append(b-1)
g[b-1].append(a-1)
p=[i for i in range(n)]
def dfs(i,v):
p[i]=v
for x in g[i]:
if x!=v:
dfs(x,i)
dfs(0,0)
deg=[0]*n
for i in range(n):
deg[i]=len(g[i])
he=[i for i in range(n) if deg[i]==1]
hp.heapify(he)
an=[]
while len(an)<k:
x=hp.heappop(he)
an.append(x+1)
deg[p[x]]-=1
if deg[p[x]]==1:
hp.heappush(he,p[x])
an.sort()
print(*an) | Title: The Number Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has $n$ districts numbered from $1$ to $n$, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district $i$ is equal to $2^i$.
This year, the president decided to reduce the costs. He wants to remove $k$ contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.
The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.
Which contestants should the president remove?
Input Specification:
The first line of input contains two integers $n$ and $k$ ($1 \leq k < n \leq 10^6$) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.
The next $n-1$ lines each contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), that describe a road that connects two different districts $a$ and $b$ in the nation. It is guaranteed that there is exactly one path between every two districts.
Output Specification:
Print $k$ space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number.
Demo Input:
['6 3\n2 1\n2 6\n4 2\n5 6\n2 3\n', '8 4\n2 6\n2 7\n7 8\n1 2\n3 1\n2 4\n7 5\n']
Demo Output:
['1 3 4\n', '1 3 4 5\n']
Note:
In the first sample, the maximum possible total number of fans is $2^2 + 2^5 + 2^6 = 100$. We can achieve it by removing the contestants of the districts 1, 3, and 4. | ```python
import sys
import heapq as hp
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,k=I()
g=[[] for i in range(n)]
for i in range(n-1):
a,b=I()
g[a-1].append(b-1)
g[b-1].append(a-1)
p=[i for i in range(n)]
def dfs(i,v):
p[i]=v
for x in g[i]:
if x!=v:
dfs(x,i)
dfs(0,0)
deg=[0]*n
for i in range(n):
deg[i]=len(g[i])
he=[i for i in range(n) if deg[i]==1]
hp.heapify(he)
an=[]
while len(an)<k:
x=hp.heappop(he)
an.append(x+1)
deg[p[x]]-=1
if deg[p[x]]==1:
hp.heappush(he,p[x])
an.sort()
print(*an)
``` | 0 |
|
50 | B | Choosing Symbol Pairs | PROGRAMMING | 1,500 | [
"strings"
] | B. Choosing Symbol Pairs | 2 | 256 | There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th. | The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105. | Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count. | [
"great10\n",
"aaaaaaaaaa\n"
] | [
"7\n",
"100\n"
] | none | 1,000 | [
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "aabb",
"output": "8"
},
{
"input": "w",
"output": "1"
},
{
"input": "129a",
"output": "4"
},
{
"input": "233444",
"output": "14"
},
{
"input": "abacaba",
"output": "21"
},
{
"input": "abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321abcdefghijklmnopqrstuvwxyz0987654321",
"output": "324"
},
{
"input": "zazaeeeeeeeq34443333444tttttt",
"output": "155"
},
{
"input": "00000000000000000000000",
"output": "529"
},
{
"input": "999000888775646453342311",
"output": "62"
}
] | 1,640,658,564 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | a=input()
b={}
c=0
for i in a:
b[i]=b.get(i,0)+1
for f in b.values():
c+=f**2
print(c) | Title: Choosing Symbol Pairs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th.
Input Specification:
The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105.
Output Specification:
Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count.
Demo Input:
['great10\n', 'aaaaaaaaaa\n']
Demo Output:
['7\n', '100\n']
Note:
none | ```python
a=input()
b={}
c=0
for i in a:
b[i]=b.get(i,0)+1
for f in b.values():
c+=f**2
print(c)
``` | 3.969 |
727 | C | Guess the Array | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In this problem you should guess an array *a* which is unknown for you. The only information you have initially is the length *n* of the array *a*.
The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices *i* and *j* (the indices should be distinct). Then your program should read the response: the single integer equals to *a**i*<=+<=*a**j*.
It is easy to prove that it is always possible to guess the array using at most *n* requests.
Write a program that will guess the array *a* by making at most *n* requests. | none | none | [
"5\n \n9\n \n7\n \n9\n \n11\n \n6\n "
] | [
"? 1 5\n \n? 2 3\n \n? 4 1\n \n? 5 2\n \n? 3 4\n \n! 4 6 1 5 5"
] | The format of a test to make a hack is:
- The first line contains an integer number *n* (3 ≤ *n* ≤ 5000) — the length of the array.- The second line contains *n* numbers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>) — the elements of the array to guess. | 1,500 | [
{
"input": "5\n4 6 1 5 5",
"output": "5 out of 5"
},
{
"input": "3\n1 1 1",
"output": "3 out of 3"
},
{
"input": "4\n100 1 100 1",
"output": "4 out of 4"
},
{
"input": "10\n9 5 10 7 4 4 8 5 10 5",
"output": "10 out of 10"
},
{
"input": "3\n1 1 1",
"output": "3 out of 3"
},
{
"input": "3\n100000 100000 100000",
"output": "3 out of 3"
},
{
"input": "3\n91906 50782 19777",
"output": "3 out of 3"
},
{
"input": "15\n5 10 10 7 7 6 4 6 8 10 8 4 10 9 4",
"output": "15 out of 15"
},
{
"input": "30\n2 3 3 4 3 2 4 4 4 3 3 2 4 2 3 4 4 2 4 3 4 2 2 4 3 3 4 4 4 4",
"output": "30 out of 30"
},
{
"input": "35\n4 2 2 2 4 4 3 2 4 2 2 4 2 2 3 2 3 4 4 2 3 2 2 4 3 3 3 3 4 2 3 2 2 2 3",
"output": "35 out of 35"
},
{
"input": "40\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "40 out of 40"
},
{
"input": "47\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "47 out of 47"
},
{
"input": "100\n76 92 53 18 65 98 100 65 93 72 100 44 70 62 78 61 89 89 80 32 88 64 67 27 46 30 75 14 78 94 8 86 41 9 68 38 76 29 69 44 23 23 14 24 97 14 7 98 45 80 55 71 58 35 41 100 60 54 64 85 56 98 87 93 40 62 92 6 7 27 88 85 10 94 25 43 99 65 82 65 39 34 17 100 49 27 4 15 84 10 35 76 98 52 72 17 43 10 49 5",
"output": "100 out of 100"
}
] | 1,653,237,519 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 374 | 10,444,800 | nnums = int(input())
ans = [-1] * nnums
print("? 1 2", flush = True)
a = int(input())
print("? 2 3", flush = True)
b = int(input())
print("? 3 1", flush = True)
c = int(input())
ans[0 : 3] = [(a-b+c)/2, (b-c+a)/2, (c-a+b)/2]
for i in range(3, nnums):
print("? " + str(i) + " " + str(i+1), flush = True)
ans[i] = int(input()) - ans[i-1]
print('!', *map(int, ans))
| Title: Guess the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In this problem you should guess an array *a* which is unknown for you. The only information you have initially is the length *n* of the array *a*.
The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices *i* and *j* (the indices should be distinct). Then your program should read the response: the single integer equals to *a**i*<=+<=*a**j*.
It is easy to prove that it is always possible to guess the array using at most *n* requests.
Write a program that will guess the array *a* by making at most *n* requests.
Input Specification:
none
Output Specification:
none
Demo Input:
['5\n\xa0\n9\n\xa0\n7\n\xa0\n9\n\xa0\n11\n\xa0\n6\n\xa0']
Demo Output:
['? 1 5\n\xa0\n? 2 3\n\xa0\n? 4 1\n\xa0\n? 5 2\n\xa0\n? 3 4\n\xa0\n! 4 6 1 5 5']
Note:
The format of a test to make a hack is:
- The first line contains an integer number *n* (3 ≤ *n* ≤ 5000) — the length of the array.- The second line contains *n* numbers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>) — the elements of the array to guess. | ```python
nnums = int(input())
ans = [-1] * nnums
print("? 1 2", flush = True)
a = int(input())
print("? 2 3", flush = True)
b = int(input())
print("? 3 1", flush = True)
c = int(input())
ans[0 : 3] = [(a-b+c)/2, (b-c+a)/2, (c-a+b)/2]
for i in range(3, nnums):
print("? " + str(i) + " " + str(i+1), flush = True)
ans[i] = int(input()) - ans[i-1]
print('!', *map(int, ans))
``` | 3 |
|
777 | B | Game of Credit Cards | PROGRAMMING | 1,300 | [
"data structures",
"dp",
"greedy",
"sortings"
] | null | null | After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if *n*<==<=3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick.
Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks.
Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number. | First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty. | [
"3\n123\n321\n",
"2\n88\n00\n"
] | [
"0\n2\n",
"2\n0\n"
] | First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks. | 1,000 | [
{
"input": "3\n123\n321",
"output": "0\n2"
},
{
"input": "2\n88\n00",
"output": "2\n0"
},
{
"input": "1\n4\n5",
"output": "0\n1"
},
{
"input": "1\n8\n7",
"output": "1\n0"
},
{
"input": "2\n55\n55",
"output": "0\n0"
},
{
"input": "3\n534\n432",
"output": "1\n1"
},
{
"input": "3\n486\n024",
"output": "2\n0"
},
{
"input": "5\n22222\n22222",
"output": "0\n0"
},
{
"input": "5\n72471\n05604",
"output": "2\n3"
},
{
"input": "5\n72471\n72471",
"output": "0\n3"
},
{
"input": "5\n72471\n41772",
"output": "0\n3"
},
{
"input": "8\n99999999\n99999999",
"output": "0\n0"
},
{
"input": "8\n01234567\n01234567",
"output": "0\n7"
},
{
"input": "8\n07070707\n76543210",
"output": "3\n4"
},
{
"input": "8\n88888888\n98769876",
"output": "4\n2"
},
{
"input": "8\n23456789\n01234567",
"output": "2\n5"
},
{
"input": "5\n11222\n22111",
"output": "1\n2"
},
{
"input": "9\n777777777\n777777777",
"output": "0\n0"
},
{
"input": "9\n353589343\n280419388",
"output": "3\n5"
},
{
"input": "10\n8104381743\n8104381743",
"output": "0\n8"
},
{
"input": "10\n8104381743\n8418134730",
"output": "0\n8"
},
{
"input": "10\n1111122222\n2222211111",
"output": "0\n5"
},
{
"input": "100\n6317494220822818719411404030346382869796138932712461187067886456209071515048745855973784223939110171\n6017563370120161528504797580620647099370814387367549926215651181421345104088127581963662589996747937",
"output": "2\n86"
},
{
"input": "200\n89017372169770060638462517044634884577600285180365791227828841983192945639410766634962149214165390392679430585962408483864914959904870801002680423351144765728677610509881245693518626747873607530273392\n34804385048475325130258121398275821439066233953856051421626677848150660724595847484466293487857039579239864150199164135152374201294909986469345076423004279983866383035554588630496127880705497919788390",
"output": "6\n175"
},
{
"input": "3\n112\n111",
"output": "1\n0"
},
{
"input": "5\n66666\n11119",
"output": "4\n1"
},
{
"input": "3\n232\n123",
"output": "1\n1"
}
] | 1,587,533,487 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 155 | 0 | input()
a=list(input())
b=list(input())
a.sort()
b.sort()
i,j=0,0
cnt=0
while(True):
if b[i]>a[j]:
i+=1
j+=1
cnt+=1
else:
i+=1
if i==len(b):
break
cnt1=0
while(True):
if a[0]==b[0]:
a.pop(0)
b.pop(0)
elif a[0] in b:
b.remove(a.pop(0))
elif a[0]<b[0]:
a.pop(0)
b.pop(0)
else:
a.pop(0)
b.pop(0)
cnt1+=1
if len(a)==0 or len(b)==0:
break
print(cnt1)
print(cnt)
| Title: Game of Credit Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if *n*<==<=3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick.
Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks.
Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number.
Output Specification:
First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.
Demo Input:
['3\n123\n321\n', '2\n88\n00\n']
Demo Output:
['0\n2\n', '2\n0\n']
Note:
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks. | ```python
input()
a=list(input())
b=list(input())
a.sort()
b.sort()
i,j=0,0
cnt=0
while(True):
if b[i]>a[j]:
i+=1
j+=1
cnt+=1
else:
i+=1
if i==len(b):
break
cnt1=0
while(True):
if a[0]==b[0]:
a.pop(0)
b.pop(0)
elif a[0] in b:
b.remove(a.pop(0))
elif a[0]<b[0]:
a.pop(0)
b.pop(0)
else:
a.pop(0)
b.pop(0)
cnt1+=1
if len(a)==0 or len(b)==0:
break
print(cnt1)
print(cnt)
``` | 0 |
|
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",
"output": "3"
},
{
"input": "1\n01",
"output": "1"
},
{
"input": "2\n01\n01",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "2"
},
{
"input": "3\n01\n01\n01",
"output": "1"
},
{
"input": "3\n10\n10\n01",
"output": "2"
},
{
"input": "3\n01\n10\n10",
"output": "2"
},
{
"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10",
"output": "55"
}
] | 1,690,561,131 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 156 | 0 | import sys
sys.setrecursionlimit(100000000)
input=lambda:sys.stdin.readline().strip()
write=lambda x:sys.stdout.write(str(x))
# from random import randint
# from copy import deepcopy
# from collections import deque
# from heapq import heapify,heappush,heappop
# from bisect import bisect_left,bisect,insort
# from math import inf,sqrt,gcd,ceil,floor,log,log2,log10
# from functools import cmp_to_key
n=int(input())
cnt=1
last=input()
for i in range(n-1):
s=input()
if s[0]==last[-1]:
cnt+=1
last=s
print(cnt) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output Specification:
On the single line of the output print the number of groups of magnets.
Demo Input:
['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n']
Demo Output:
['3\n', '2\n']
Note:
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | ```python
import sys
sys.setrecursionlimit(100000000)
input=lambda:sys.stdin.readline().strip()
write=lambda x:sys.stdout.write(str(x))
# from random import randint
# from copy import deepcopy
# from collections import deque
# from heapq import heapify,heappush,heappop
# from bisect import bisect_left,bisect,insort
# from math import inf,sqrt,gcd,ceil,floor,log,log2,log10
# from functools import cmp_to_key
n=int(input())
cnt=1
last=input()
for i in range(n-1):
s=input()
if s[0]==last[-1]:
cnt+=1
last=s
print(cnt)
``` | 3 |
|
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3....
Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it? | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6. | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "10\n1 -1 1 -1 1 -1 1 -1 1 -1",
"output": "0 0 0 0 0 0 0 0 0 -1 "
},
{
"input": "10\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000",
"output": "0 0 0 0 0 0 0 0 0 1000000000 "
},
{
"input": "10\n124 532 -642 6482 -124 952 -235 7594 34 -12",
"output": "656 -110 5840 6358 828 717 7359 7628 22 -12 "
},
{
"input": "10\n1294 35852 32749 537295 12048 53729 29357 58320 64739 1240",
"output": "37146 68601 570044 549343 65777 83086 87677 123059 65979 1240 "
}
] | 1,567,770,522 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 373 | 8,499,200 | n=int(input())
l=list(map(int,input().split()))
k=[]
r=0
for i in range(len(l)):
if i==len(l)-1:
r=l[len(l)-1]
print(r,end=" ")
else:
r=l[i+1]+l[i]
print(r,end=" ") | Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3....
Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it?
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number.
Output Specification:
Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type.
Demo Input:
['5\n6 -4 8 -2 3\n', '5\n3 -2 -1 5 6\n']
Demo Output:
['2 4 6 1 3 \n', '1 -3 4 11 6 \n']
Note:
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6. | ```python
n=int(input())
l=list(map(int,input().split()))
k=[]
r=0
for i in range(len(l)):
if i==len(l)-1:
r=l[len(l)-1]
print(r,end=" ")
else:
r=l[i+1]+l[i]
print(r,end=" ")
``` | 3 |
|
645 | B | Mischievous Mess Makers | PROGRAMMING | 1,200 | [
"greedy",
"math"
] | null | null | It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.
Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=<<=*j* and *p**i*<=><=*p**j*. | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. | Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. | [
"5 2\n",
"1 10\n"
] | [
"10\n",
"0\n"
] | In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.
In the second sample, there is only one cow, so the maximum possible messiness is 0. | 1,000 | [
{
"input": "5 2",
"output": "10"
},
{
"input": "1 10",
"output": "0"
},
{
"input": "100000 2",
"output": "399990"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 3",
"output": "27"
},
{
"input": "7 1",
"output": "11"
},
{
"input": "100000 40000",
"output": "4799960000"
},
{
"input": "1 1000",
"output": "0"
},
{
"input": "100 45",
"output": "4905"
},
{
"input": "9 2",
"output": "26"
},
{
"input": "456 78",
"output": "58890"
},
{
"input": "100000 50000",
"output": "4999950000"
},
{
"input": "100000 50001",
"output": "4999950000"
},
{
"input": "100000 50002",
"output": "4999950000"
},
{
"input": "100000 50003",
"output": "4999950000"
},
{
"input": "100000 49998",
"output": "4999949994"
},
{
"input": "100000 49997",
"output": "4999949985"
},
{
"input": "99999 49998",
"output": "4999849998"
},
{
"input": "99999 49997",
"output": "4999849991"
},
{
"input": "99999 49996",
"output": "4999849980"
},
{
"input": "99999 50000",
"output": "4999850001"
},
{
"input": "99999 50001",
"output": "4999850001"
},
{
"input": "99999 50002",
"output": "4999850001"
},
{
"input": "30062 9",
"output": "540945"
},
{
"input": "13486 3",
"output": "80895"
},
{
"input": "29614 7",
"output": "414491"
},
{
"input": "13038 8",
"output": "208472"
},
{
"input": "96462 6",
"output": "1157466"
},
{
"input": "22599 93799",
"output": "255346101"
},
{
"input": "421 36817",
"output": "88410"
},
{
"input": "72859 65869",
"output": "2654180511"
},
{
"input": "37916 5241",
"output": "342494109"
},
{
"input": "47066 12852",
"output": "879423804"
},
{
"input": "84032 21951",
"output": "2725458111"
},
{
"input": "70454 75240",
"output": "2481847831"
},
{
"input": "86946 63967",
"output": "3779759985"
},
{
"input": "71128 11076",
"output": "1330260828"
},
{
"input": "46111 64940",
"output": "1063089105"
},
{
"input": "46111 64940",
"output": "1063089105"
},
{
"input": "56500 84184",
"output": "1596096750"
},
{
"input": "60108 83701",
"output": "1806455778"
},
{
"input": "1 2",
"output": "0"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 4",
"output": "0"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "1 6",
"output": "0"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "1"
},
{
"input": "2 4",
"output": "1"
},
{
"input": "2 5",
"output": "1"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "3 3",
"output": "3"
},
{
"input": "3 4",
"output": "3"
},
{
"input": "3 5",
"output": "3"
},
{
"input": "4 1",
"output": "5"
},
{
"input": "4 2",
"output": "6"
},
{
"input": "4 3",
"output": "6"
},
{
"input": "4 4",
"output": "6"
},
{
"input": "4 5",
"output": "6"
},
{
"input": "5 1",
"output": "7"
},
{
"input": "5 3",
"output": "10"
},
{
"input": "5 4",
"output": "10"
},
{
"input": "5 5",
"output": "10"
},
{
"input": "6 1",
"output": "9"
},
{
"input": "6 2",
"output": "14"
},
{
"input": "6 3",
"output": "15"
},
{
"input": "7 2",
"output": "18"
},
{
"input": "7 3",
"output": "21"
},
{
"input": "7 4",
"output": "21"
},
{
"input": "10 2",
"output": "30"
},
{
"input": "60982 2",
"output": "243918"
},
{
"input": "23426 23",
"output": "1076515"
},
{
"input": "444 3",
"output": "2643"
},
{
"input": "18187 433",
"output": "15374531"
},
{
"input": "6895 3544",
"output": "23767065"
},
{
"input": "56204 22352",
"output": "1513297456"
},
{
"input": "41977 5207",
"output": "382917573"
},
{
"input": "78147 2321",
"output": "351981971"
},
{
"input": "99742 62198",
"output": "4974183411"
},
{
"input": "72099 38339",
"output": "2599096851"
},
{
"input": "82532 4838",
"output": "751762306"
},
{
"input": "79410 33144",
"output": "3066847464"
},
{
"input": "11021 3389",
"output": "51726307"
},
{
"input": "66900 7572",
"output": "898455660"
},
{
"input": "99999 49999",
"output": "4999850001"
},
{
"input": "100000 49999",
"output": "4999949999"
},
{
"input": "100000 100000",
"output": "4999950000"
},
{
"input": "100000 1",
"output": "199997"
},
{
"input": "4 100",
"output": "6"
},
{
"input": "100000 1234",
"output": "243753254"
}
] | 1,692,785,957 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 92 | 62 | 1,331,200 | n, k = map(int, input().split())
ans = 0
d = n
for i in range(min(k, n // 2)):
ans += (d*2-3)
d -= 2
print(ans) | Title: Mischievous Mess Makers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.
Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=<<=*j* and *p**i*<=><=*p**j*.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively.
Output Specification:
Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps.
Demo Input:
['5 2\n', '1 10\n']
Demo Output:
['10\n', '0\n']
Note:
In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.
In the second sample, there is only one cow, so the maximum possible messiness is 0. | ```python
n, k = map(int, input().split())
ans = 0
d = n
for i in range(min(k, n // 2)):
ans += (d*2-3)
d -= 2
print(ans)
``` | 3 |
|
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps. | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "1"
},
{
"input": "99125 26876 -21414 14176 17443",
"output": "1"
},
{
"input": "8066 7339 19155 -90534 -60666",
"output": "8"
},
{
"input": "100000 -100000 -100000 100000 100000",
"output": "2"
},
{
"input": "10 20 0 41 0",
"output": "2"
},
{
"input": "25 -64 -6 -56 64",
"output": "2"
},
{
"input": "125 455 450 439 721",
"output": "2"
},
{
"input": "5 6 3 7 2",
"output": "1"
},
{
"input": "24 130 14786 3147 2140",
"output": "271"
},
{
"input": "125 -363 176 93 330",
"output": "2"
},
{
"input": "1 14 30 30 14",
"output": "12"
},
{
"input": "25 96 13 7 2",
"output": "2"
},
{
"input": "4 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "1 3 4 2 5",
"output": "1"
},
{
"input": "1 -3 3 2 6",
"output": "3"
},
{
"input": "2 7 20 13 -5",
"output": "7"
},
{
"input": "1 1 1 1 4",
"output": "2"
},
{
"input": "249 -54242 -30537 -45023 -89682",
"output": "121"
},
{
"input": "4 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "97741 23818 78751 97583 26933",
"output": "1"
},
{
"input": "56767 -29030 51625 79823 -56297",
"output": "2"
},
{
"input": "98260 13729 74998 23701 9253",
"output": "1"
},
{
"input": "67377 -80131 -90254 -57320 14102",
"output": "1"
},
{
"input": "1 100000 100000 100000 -100000",
"output": "100000"
},
{
"input": "19312 19470 82059 58064 62231",
"output": "2"
},
{
"input": "67398 -68747 -79056 -34193 29400",
"output": "1"
},
{
"input": "91099 37184 -71137 75650 -3655",
"output": "1"
},
{
"input": "46456 -2621 -23623 -98302 -99305",
"output": "2"
},
{
"input": "100 100000 -100000 100000 -99999",
"output": "1"
},
{
"input": "1 100000 -100000 100000 -100000",
"output": "0"
},
{
"input": "8 0 0 0 32",
"output": "2"
},
{
"input": "100000 100000 1 -100000 0",
"output": "2"
}
] | 1,657,035,181 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 77 | 0 | import math
r,x,y,x1,y1 = [int(x) for x in input().split()]
dist = math.sqrt(((x1-x)**2)+((y1-y)**2))
print(math.ceil(dist/(r*2))) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
Input Specification:
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output Specification:
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
Demo Input:
['2 0 0 0 4\n', '1 1 1 4 4\n', '4 5 6 5 6\n']
Demo Output:
['1\n', '3\n', '0\n']
Note:
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
import math
r,x,y,x1,y1 = [int(x) for x in input().split()]
dist = math.sqrt(((x1-x)**2)+((y1-y)**2))
print(math.ceil(dist/(r*2)))
``` | 3 |
|
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s*. The newspaper contains string *t*, consisting of uppercase and lowercase English letters. We know that the length of string *t* greater or equal to the length of the string *s*.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some *n* letters out of the newspaper and make a message of length exactly *n*, so that it looked as much as possible like *s*. If the letter in some position has correct value and correct letter case (in the string *s* and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message. | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the length of the string *a*. | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "0 26"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nqrsimtabuvzhnwcdefgjklxyop",
"output": "26 0"
},
{
"input": "l\nFPbAVjsMpPDTLkfwNYFmBDHPTDSWSOUlrBHYJHPM",
"output": "1 0"
},
{
"input": "ncMeXssLHS\nuwyeMcaFatpInZVdEYpwJQSnVxLK",
"output": "6 1"
},
{
"input": "DpiNBmCRFWxpdbfGOzvvOcemjructoAdEwegTvbVbfWWRPGyEAxGdDRWVlqNyGWMWHMrHAIZpyxvgaflrsVZhhZRouvpxrKXFZam\nwwPLFtNfPtJXvMLuHjKfYyaRhreNSWSzOvDpqHCGcqllACNPGHxReeFUCmAqIKXYytsSQwIxJzNiiUtgebVuwRmWpRALLyKAzyDPvgIGxALSaeeTIqm",
"output": "66 12"
},
{
"input": "CCAE\ndcecc",
"output": "0 3"
},
{
"input": "Dccb\nbeeeb",
"output": "1 0"
},
{
"input": "Adc\neadeabcad",
"output": "2 1"
},
{
"input": "DBAdeb\ndeeabcddadaa",
"output": "3 2"
},
{
"input": "EDCED\neebeacdba",
"output": "0 4"
},
{
"input": "CdAbD\ndecbde",
"output": "2 2"
},
{
"input": "a\nB",
"output": "0 0"
},
{
"input": "r\nqA",
"output": "0 0"
}
] | 1,608,899,253 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 280 | 4,608,000 | s=input()
t=input()
from collections import Counter as C
import string
lower=string.ascii_lowercase
upper=string.ascii_uppercase
cS=C(s)
cT=C(t)
yay=0
whoops=0
for c,cnt in cS.items():
if c in cT.keys():
subtract=min(cnt,cT[c])
yay+=subtract
cS[c]-=subtract
cT[c]-=subtract
for c,cnt in cS.items():
if cnt==0:
continue
if c in lower:
c2=c.upper()
else:
c2=c.lower()
if c2 in cT.keys():
subtract=min(cnt,cT[c2])
whoops+=subtract
cS[c]-=subtract
cT[c2]-=subtract
print('{} {}'.format(yay,whoops)) | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s*. The newspaper contains string *t*, consisting of uppercase and lowercase English letters. We know that the length of string *t* greater or equal to the length of the string *s*.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some *n* letters out of the newspaper and make a message of length exactly *n*, so that it looked as much as possible like *s*. If the letter in some position has correct value and correct letter case (in the string *s* and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
Input Specification:
The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the length of the string *a*.
Output Specification:
Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message.
Demo Input:
['AbC\nDCbA\n', 'ABC\nabc\n', 'abacaba\nAbaCaBA\n']
Demo Output:
['3 0\n', '0 3\n', '3 4\n']
Note:
none | ```python
s=input()
t=input()
from collections import Counter as C
import string
lower=string.ascii_lowercase
upper=string.ascii_uppercase
cS=C(s)
cT=C(t)
yay=0
whoops=0
for c,cnt in cS.items():
if c in cT.keys():
subtract=min(cnt,cT[c])
yay+=subtract
cS[c]-=subtract
cT[c]-=subtract
for c,cnt in cS.items():
if cnt==0:
continue
if c in lower:
c2=c.upper()
else:
c2=c.lower()
if c2 in cT.keys():
subtract=min(cnt,cT[c2])
whoops+=subtract
cS[c]-=subtract
cT[c2]-=subtract
print('{} {}'.format(yay,whoops))
``` | 3 |
|
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively. | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 5\n2 6\n2 5\n2 5\n2 4\n2 5",
"output": "Chris"
},
{
"input": "8\n4 1\n2 6\n4 2\n2 5\n5 2\n3 5\n5 2\n1 5",
"output": "Friendship is magic!^^"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "9\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 4\n6 6\n3 2\n1 5\n5 2\n1 5\n1 5\n3 1\n6 5\n4 3\n1 1\n5 1\n3 3\n2 4\n1 5\n3 4\n5 1\n5 5\n2 5\n2 1\n4 3\n6 5\n1 1\n2 1\n1 3\n1 1\n6 4\n4 6\n6 4\n2 1\n2 5\n6 2\n3 4\n5 5\n1 4\n4 6\n3 4\n1 6\n5 1\n4 3\n3 4\n2 2\n1 2\n2 3\n1 3\n4 4\n5 5\n4 5\n4 4\n3 1\n4 5\n2 3\n2 6\n6 5\n6 1\n6 6\n2 3\n6 4\n3 3\n2 5\n4 4\n3 1\n2 4\n6 1\n3 2\n1 3\n5 4\n6 6\n2 5\n5 1\n1 1\n2 5\n6 5\n3 6\n5 6\n4 3\n3 4\n3 4\n6 5\n5 2\n4 2\n1 1\n3 1\n2 6\n1 6\n1 2\n6 1\n3 4\n1 6\n3 1\n5 3\n1 3\n5 6\n2 1\n6 4\n3 1\n1 6\n6 3\n3 3\n4 3",
"output": "Chris"
},
{
"input": "100\n4 1\n3 4\n4 6\n4 5\n6 5\n5 3\n6 2\n6 3\n5 2\n4 5\n1 5\n5 4\n1 4\n4 5\n4 6\n1 6\n4 4\n5 1\n6 4\n6 4\n4 6\n2 3\n6 2\n4 6\n1 4\n2 3\n4 3\n1 3\n6 2\n3 1\n3 4\n2 6\n4 5\n5 4\n2 2\n2 5\n4 1\n2 2\n3 3\n1 4\n5 6\n6 4\n4 2\n6 1\n5 5\n4 1\n2 1\n6 4\n4 4\n4 3\n5 3\n4 5\n5 3\n3 5\n6 3\n1 1\n3 4\n6 3\n6 1\n5 1\n2 4\n4 3\n2 2\n5 5\n1 5\n5 3\n4 6\n1 4\n6 3\n4 3\n2 4\n3 2\n2 4\n3 4\n6 2\n5 6\n1 2\n1 5\n5 5\n2 6\n5 1\n1 6\n5 3\n3 5\n2 6\n4 6\n6 2\n3 1\n5 5\n6 1\n3 6\n4 4\n1 1\n4 6\n5 3\n4 2\n5 1\n3 3\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n6 3\n4 5\n4 3\n5 4\n5 1\n6 3\n4 2\n4 6\n3 1\n2 4\n2 2\n4 6\n5 3\n5 5\n4 2\n6 2\n2 3\n4 4\n6 4\n3 5\n2 4\n2 2\n5 2\n3 5\n2 4\n4 4\n3 5\n6 5\n1 3\n1 6\n2 2\n2 4\n3 2\n5 4\n1 6\n3 4\n4 1\n1 5\n1 4\n5 3\n2 2\n4 5\n6 3\n4 4\n1 1\n4 1\n2 4\n4 1\n4 5\n5 3\n1 1\n1 6\n5 6\n6 6\n4 2\n4 3\n3 4\n3 6\n3 4\n6 5\n3 4\n5 4\n5 1\n5 3\n5 1\n1 2\n2 6\n3 4\n6 5\n4 3\n1 1\n5 5\n5 1\n3 3\n5 2\n1 3\n6 6\n5 6\n1 4\n4 4\n1 4\n3 6\n6 5\n3 3\n3 6\n1 5\n1 2\n3 6\n3 6\n4 1\n5 2\n1 2\n5 2\n3 3\n4 4\n4 2\n6 2\n5 4\n6 1\n6 3",
"output": "Mishka"
},
{
"input": "8\n4 1\n6 2\n4 1\n5 3\n4 1\n5 3\n6 2\n5 3",
"output": "Mishka"
},
{
"input": "5\n3 6\n3 5\n3 5\n1 6\n3 5",
"output": "Chris"
},
{
"input": "4\n4 1\n2 4\n5 3\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "6\n6 3\n5 1\n6 3\n4 3\n4 3\n5 2",
"output": "Mishka"
},
{
"input": "7\n3 4\n1 4\n2 5\n1 6\n1 6\n1 5\n3 4",
"output": "Chris"
},
{
"input": "6\n6 2\n2 5\n5 2\n3 6\n4 3\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "8\n6 1\n5 3\n4 3\n4 1\n5 1\n4 2\n4 2\n4 1",
"output": "Mishka"
},
{
"input": "9\n2 5\n2 5\n1 4\n2 6\n2 4\n2 5\n2 6\n1 5\n2 5",
"output": "Chris"
},
{
"input": "4\n6 2\n2 4\n4 2\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "9\n5 2\n4 1\n4 1\n5 1\n6 2\n6 1\n5 3\n6 1\n6 2",
"output": "Mishka"
},
{
"input": "8\n2 4\n3 6\n1 6\n1 6\n2 4\n3 4\n3 6\n3 4",
"output": "Chris"
},
{
"input": "6\n5 3\n3 6\n6 2\n1 6\n5 1\n3 5",
"output": "Friendship is magic!^^"
},
{
"input": "6\n5 2\n5 1\n6 1\n5 2\n4 2\n5 1",
"output": "Mishka"
},
{
"input": "5\n1 4\n2 5\n3 4\n2 6\n3 4",
"output": "Chris"
},
{
"input": "4\n6 2\n3 4\n5 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "93\n4 3\n4 1\n4 2\n5 2\n5 3\n6 3\n4 3\n6 2\n6 3\n5 1\n4 2\n4 2\n5 1\n6 2\n6 3\n6 1\n4 1\n6 2\n5 3\n4 3\n4 1\n4 2\n5 2\n6 3\n5 2\n5 2\n6 3\n5 1\n6 2\n5 2\n4 1\n5 2\n5 1\n4 1\n6 1\n5 2\n4 3\n5 3\n5 3\n5 1\n4 3\n4 3\n4 2\n4 1\n6 2\n6 1\n4 1\n5 2\n5 2\n6 2\n5 3\n5 1\n6 2\n5 1\n6 3\n5 2\n6 2\n6 2\n4 2\n5 2\n6 1\n6 3\n6 3\n5 1\n5 1\n4 1\n5 1\n4 3\n5 3\n6 3\n4 1\n4 3\n6 1\n6 1\n4 2\n6 2\n4 2\n5 2\n4 1\n5 2\n4 1\n5 1\n5 2\n5 1\n4 1\n6 3\n6 2\n4 3\n4 1\n5 2\n4 3\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "11\n1 6\n1 6\n2 4\n2 5\n3 4\n1 5\n1 6\n1 5\n1 6\n2 6\n3 4",
"output": "Chris"
},
{
"input": "70\n6 1\n3 6\n4 3\n2 5\n5 2\n1 4\n6 2\n1 6\n4 3\n1 4\n5 3\n2 4\n5 3\n1 6\n5 1\n3 5\n4 2\n2 4\n5 1\n3 5\n6 2\n1 5\n4 2\n2 5\n5 3\n1 5\n4 2\n1 4\n5 2\n2 6\n4 3\n1 5\n6 2\n3 4\n4 2\n3 5\n6 3\n3 4\n5 1\n1 4\n4 2\n1 4\n6 3\n2 6\n5 2\n1 6\n6 1\n2 6\n5 3\n1 5\n5 1\n1 6\n4 1\n1 5\n4 2\n2 4\n5 1\n2 5\n6 3\n1 4\n6 3\n3 6\n5 1\n1 4\n5 3\n3 5\n4 2\n3 4\n6 2\n1 4",
"output": "Friendship is magic!^^"
},
{
"input": "59\n4 1\n5 3\n6 1\n4 2\n5 1\n4 3\n6 1\n5 1\n4 3\n4 3\n5 2\n5 3\n4 1\n6 2\n5 1\n6 3\n6 3\n5 2\n5 2\n6 1\n4 1\n6 1\n4 3\n5 3\n5 3\n4 3\n4 2\n4 2\n6 3\n6 3\n6 1\n4 3\n5 1\n6 2\n6 1\n4 1\n6 1\n5 3\n4 2\n5 1\n6 2\n6 2\n4 3\n5 3\n4 3\n6 3\n5 2\n5 2\n4 3\n5 1\n5 3\n6 1\n6 3\n6 3\n4 3\n5 2\n5 2\n5 2\n4 3",
"output": "Mishka"
},
{
"input": "42\n1 5\n1 6\n1 6\n1 4\n2 5\n3 6\n1 6\n3 4\n2 5\n2 5\n2 4\n1 4\n3 4\n2 4\n2 6\n1 5\n3 6\n2 6\n2 6\n3 5\n1 4\n1 5\n2 6\n3 6\n1 4\n3 4\n2 4\n1 6\n3 4\n2 4\n2 6\n1 6\n1 4\n1 6\n1 6\n2 4\n1 5\n1 6\n2 5\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "78\n4 3\n3 5\n4 3\n1 5\n5 1\n1 5\n4 3\n1 4\n6 3\n1 5\n4 1\n2 4\n4 3\n2 4\n5 1\n3 6\n4 2\n3 6\n6 3\n3 4\n4 3\n3 6\n5 3\n1 5\n4 1\n2 6\n4 2\n2 4\n4 1\n3 5\n5 2\n3 6\n4 3\n2 4\n6 3\n1 6\n4 3\n3 5\n6 3\n2 6\n4 1\n2 4\n6 2\n1 6\n4 2\n1 4\n4 3\n1 4\n4 3\n2 4\n6 2\n3 5\n6 1\n3 6\n5 3\n1 6\n6 1\n2 6\n4 2\n1 5\n6 2\n2 6\n6 3\n2 4\n4 2\n3 5\n6 1\n2 5\n5 3\n2 6\n5 1\n3 6\n4 3\n3 6\n6 3\n2 5\n6 1\n2 6",
"output": "Friendship is magic!^^"
},
{
"input": "76\n4 1\n5 2\n4 3\n5 2\n5 3\n5 2\n6 1\n4 2\n6 2\n5 3\n4 2\n6 2\n4 1\n4 2\n5 1\n5 1\n6 2\n5 2\n5 3\n6 3\n5 2\n4 3\n6 3\n6 1\n4 3\n6 2\n6 1\n4 1\n6 1\n5 3\n4 1\n5 3\n4 2\n5 2\n4 3\n6 1\n6 2\n5 2\n6 1\n5 3\n4 3\n5 1\n5 3\n4 3\n5 1\n5 1\n4 1\n4 1\n4 1\n4 3\n5 3\n6 3\n6 3\n5 2\n6 2\n6 3\n5 1\n6 3\n5 3\n6 1\n5 3\n4 1\n5 3\n6 1\n4 2\n6 2\n4 3\n4 1\n6 2\n4 3\n5 3\n5 2\n5 3\n5 1\n6 3\n5 2",
"output": "Mishka"
},
{
"input": "84\n3 6\n3 4\n2 5\n2 4\n1 6\n3 4\n1 5\n1 6\n3 5\n1 6\n2 4\n2 6\n2 6\n2 4\n3 5\n1 5\n3 6\n3 6\n3 4\n3 4\n2 6\n1 6\n1 6\n3 5\n3 4\n1 6\n3 4\n3 5\n2 4\n2 5\n2 5\n3 5\n1 6\n3 4\n2 6\n2 6\n3 4\n3 4\n2 5\n2 5\n2 4\n3 4\n2 5\n3 4\n3 4\n2 6\n2 6\n1 6\n2 4\n1 5\n3 4\n2 5\n2 5\n3 4\n2 4\n2 6\n2 6\n1 4\n3 5\n3 5\n2 4\n2 5\n3 4\n1 5\n1 5\n2 6\n1 5\n3 5\n2 4\n2 5\n3 4\n2 6\n1 6\n2 5\n3 5\n3 5\n3 4\n2 5\n2 6\n3 4\n1 6\n2 5\n2 6\n1 4",
"output": "Chris"
},
{
"input": "44\n6 1\n1 6\n5 2\n1 4\n6 2\n2 5\n5 3\n3 6\n5 2\n1 6\n4 1\n2 4\n6 1\n3 4\n6 3\n3 6\n4 3\n2 4\n6 1\n3 4\n6 1\n1 6\n4 1\n3 5\n6 1\n3 6\n4 1\n1 4\n4 2\n2 6\n6 1\n2 4\n6 2\n1 4\n6 2\n2 4\n5 2\n3 6\n6 3\n2 6\n5 3\n3 4\n5 3\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "42\n5 3\n5 1\n5 2\n4 1\n6 3\n6 1\n6 2\n4 1\n4 3\n4 1\n5 1\n5 3\n5 1\n4 1\n4 2\n6 1\n6 3\n5 1\n4 1\n4 1\n6 3\n4 3\n6 3\n5 2\n6 1\n4 1\n5 3\n4 3\n5 2\n6 3\n6 1\n5 1\n4 2\n4 3\n5 2\n5 3\n6 3\n5 2\n5 1\n5 3\n6 2\n6 1",
"output": "Mishka"
},
{
"input": "50\n3 6\n2 6\n1 4\n1 4\n1 4\n2 5\n3 4\n3 5\n2 6\n1 6\n3 5\n1 5\n2 6\n2 4\n2 4\n3 5\n1 6\n1 5\n1 5\n1 4\n3 5\n1 6\n3 5\n1 4\n1 5\n1 4\n3 6\n1 6\n1 4\n1 4\n1 4\n1 5\n3 6\n1 6\n1 6\n2 4\n1 5\n2 6\n2 5\n3 5\n3 6\n3 4\n2 4\n2 6\n3 4\n2 5\n3 6\n3 5\n2 4\n2 4",
"output": "Chris"
},
{
"input": "86\n6 3\n2 4\n6 3\n3 5\n6 3\n1 5\n5 2\n2 4\n4 3\n2 6\n4 1\n2 6\n5 2\n1 4\n5 1\n2 4\n4 1\n1 4\n6 2\n3 5\n4 2\n2 4\n6 2\n1 5\n5 3\n2 5\n5 1\n1 6\n6 1\n1 4\n4 3\n3 4\n5 2\n2 4\n5 3\n2 5\n4 3\n3 4\n4 1\n1 5\n6 3\n3 4\n4 3\n3 4\n4 1\n3 4\n5 1\n1 6\n4 2\n1 6\n5 1\n2 4\n5 1\n3 6\n4 1\n1 5\n5 2\n1 4\n4 3\n2 5\n5 1\n1 5\n6 2\n2 6\n4 2\n2 4\n4 1\n2 5\n5 3\n3 4\n5 1\n3 4\n6 3\n3 4\n4 3\n2 6\n6 2\n2 5\n5 2\n3 5\n4 2\n3 6\n6 2\n3 4\n4 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "84\n6 1\n6 3\n6 3\n4 1\n4 3\n4 2\n6 3\n5 3\n6 1\n6 3\n4 3\n5 2\n5 3\n5 1\n6 2\n6 2\n6 1\n4 1\n6 3\n5 2\n4 1\n5 3\n6 3\n4 2\n6 2\n6 3\n4 3\n4 1\n4 3\n5 1\n5 1\n5 1\n4 1\n6 1\n4 3\n6 2\n5 1\n5 1\n6 2\n5 2\n4 1\n6 1\n6 1\n6 3\n6 2\n4 3\n6 3\n6 2\n5 2\n5 1\n4 3\n6 2\n4 1\n6 2\n6 1\n5 2\n5 1\n6 2\n6 1\n5 3\n5 2\n6 1\n6 3\n5 2\n6 1\n6 3\n4 3\n5 1\n6 3\n6 1\n5 3\n4 3\n5 2\n5 1\n6 2\n5 3\n6 1\n5 1\n4 1\n5 1\n5 1\n5 2\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "92\n1 5\n2 4\n3 5\n1 6\n2 5\n1 6\n3 6\n1 6\n2 4\n3 4\n3 4\n3 6\n1 5\n2 5\n1 5\n1 5\n2 6\n2 4\n3 6\n1 4\n1 6\n2 6\n3 4\n2 6\n2 6\n1 4\n3 5\n2 5\n2 6\n1 5\n1 4\n1 5\n3 6\n3 5\n2 5\n1 5\n3 5\n3 6\n2 6\n2 6\n1 5\n3 4\n2 4\n3 6\n2 5\n1 5\n2 4\n1 4\n2 6\n2 6\n2 6\n1 5\n3 6\n3 6\n2 5\n1 4\n2 4\n3 4\n1 5\n2 5\n2 4\n2 5\n3 5\n3 4\n3 6\n2 6\n3 5\n1 4\n3 4\n1 6\n3 6\n2 6\n1 4\n3 6\n3 6\n2 5\n2 6\n1 6\n2 6\n3 5\n2 5\n3 6\n2 5\n2 6\n1 5\n2 4\n1 4\n2 4\n1 5\n2 5\n2 5\n2 6",
"output": "Chris"
},
{
"input": "20\n5 1\n1 4\n4 3\n1 5\n4 2\n3 6\n6 2\n1 6\n4 1\n1 4\n5 2\n3 4\n5 1\n1 6\n5 1\n2 6\n6 3\n2 5\n6 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "100\n4 3\n4 3\n4 2\n4 3\n4 1\n4 3\n5 2\n5 2\n6 2\n4 2\n5 1\n4 2\n5 2\n6 1\n4 1\n6 3\n5 3\n5 1\n5 1\n5 1\n5 3\n6 1\n6 1\n4 1\n5 2\n5 2\n6 1\n6 3\n4 2\n4 1\n5 3\n4 1\n5 3\n5 1\n6 3\n6 3\n6 1\n5 2\n5 3\n5 3\n6 1\n4 1\n6 2\n6 1\n6 2\n6 3\n4 3\n4 3\n6 3\n4 2\n4 2\n5 3\n5 2\n5 2\n4 3\n5 3\n5 2\n4 2\n5 1\n4 2\n5 1\n5 3\n6 3\n5 3\n5 3\n4 2\n4 1\n4 2\n4 3\n6 3\n4 3\n6 2\n6 1\n5 3\n5 2\n4 1\n6 1\n5 2\n6 2\n4 2\n6 3\n4 3\n5 1\n6 3\n5 2\n4 3\n5 3\n5 3\n4 3\n6 3\n4 3\n4 1\n5 1\n6 2\n6 3\n5 3\n6 1\n6 3\n5 3\n6 1",
"output": "Mishka"
},
{
"input": "100\n1 5\n1 4\n1 5\n2 4\n2 6\n3 6\n3 5\n1 5\n2 5\n3 6\n3 5\n1 6\n1 4\n1 5\n1 6\n2 6\n1 5\n3 5\n3 4\n2 6\n2 6\n2 5\n3 4\n1 6\n1 4\n2 4\n1 5\n1 6\n3 5\n1 6\n2 6\n3 5\n1 6\n3 4\n3 5\n1 6\n3 6\n2 4\n2 4\n3 5\n2 6\n1 5\n3 5\n3 6\n2 4\n2 4\n2 6\n3 4\n3 4\n1 5\n1 4\n2 5\n3 4\n1 4\n2 6\n2 5\n2 4\n2 4\n2 5\n1 5\n1 6\n1 5\n1 5\n1 5\n1 6\n3 4\n2 4\n3 5\n3 5\n1 6\n3 5\n1 5\n1 6\n3 6\n3 4\n1 5\n3 5\n3 6\n1 4\n3 6\n1 5\n3 5\n3 6\n3 5\n1 4\n3 4\n2 4\n2 4\n2 5\n3 6\n3 5\n1 5\n2 4\n1 4\n3 4\n1 5\n3 4\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "100\n4 3\n3 4\n5 1\n2 5\n5 3\n1 5\n6 3\n2 4\n5 2\n2 6\n5 2\n1 5\n6 3\n1 5\n6 3\n3 4\n5 2\n1 5\n6 1\n1 5\n4 2\n3 5\n6 3\n2 6\n6 3\n1 4\n6 2\n3 4\n4 1\n3 6\n5 1\n2 4\n5 1\n3 4\n6 2\n3 5\n4 1\n2 6\n4 3\n2 6\n5 2\n3 6\n6 2\n3 5\n4 3\n1 5\n5 3\n3 6\n4 2\n3 4\n6 1\n3 4\n5 2\n2 6\n5 2\n2 4\n6 2\n3 6\n4 3\n2 4\n4 3\n2 6\n4 2\n3 4\n6 3\n2 4\n6 3\n3 5\n5 2\n1 5\n6 3\n3 6\n4 3\n1 4\n5 2\n1 6\n4 1\n2 5\n4 1\n2 4\n4 2\n2 5\n6 1\n2 4\n6 3\n1 5\n4 3\n2 6\n6 3\n2 6\n5 3\n1 5\n4 1\n1 5\n6 2\n2 5\n5 1\n3 6\n4 3\n3 4",
"output": "Friendship is magic!^^"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "99\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "84\n6 2\n1 5\n6 2\n2 3\n5 5\n1 2\n3 4\n3 4\n6 5\n6 4\n2 5\n4 1\n1 2\n1 1\n1 4\n2 5\n5 6\n6 3\n2 4\n5 5\n2 6\n3 4\n5 1\n3 3\n5 5\n4 6\n4 6\n2 4\n4 1\n5 2\n2 2\n3 6\n3 3\n4 6\n1 1\n2 4\n6 5\n5 2\n6 5\n5 5\n2 5\n6 4\n1 1\n6 2\n3 6\n6 5\n4 4\n1 5\n5 6\n4 4\n3 5\n6 1\n3 4\n1 5\n4 6\n4 6\n4 1\n3 6\n6 2\n1 1\n4 5\n5 4\n5 3\n3 4\n6 4\n1 1\n5 2\n6 5\n6 1\n2 2\n2 4\n3 3\n4 6\n1 3\n6 6\n5 2\n1 6\n6 2\n6 6\n4 1\n3 6\n6 4\n2 3\n3 4",
"output": "Chris"
},
{
"input": "70\n3 4\n2 3\n2 3\n6 5\n6 6\n4 3\n2 3\n3 1\n3 5\n5 6\n1 6\n2 5\n5 3\n2 5\n4 6\n5 1\n6 1\n3 1\n3 3\n5 3\n2 1\n3 3\n6 4\n6 3\n4 3\n4 5\n3 5\n5 5\n5 2\n1 6\n3 4\n5 2\n2 4\n1 6\n4 3\n4 3\n6 2\n1 3\n1 5\n6 1\n3 1\n1 1\n1 3\n2 2\n3 2\n6 4\n1 1\n4 4\n3 1\n4 5\n4 2\n6 3\n4 4\n3 2\n1 2\n2 6\n3 3\n1 5\n1 1\n6 5\n2 2\n3 1\n5 4\n5 2\n6 4\n6 3\n6 6\n6 3\n3 3\n5 4",
"output": "Mishka"
},
{
"input": "56\n6 4\n3 4\n6 1\n3 3\n1 4\n2 3\n1 5\n2 5\n1 5\n5 5\n2 3\n1 1\n3 2\n3 5\n4 6\n4 4\n5 2\n4 3\n3 1\n3 6\n2 3\n3 4\n5 6\n5 2\n5 6\n1 5\n1 5\n4 1\n6 3\n2 2\n2 1\n5 5\n2 1\n4 1\n5 4\n2 5\n4 1\n6 2\n3 4\n4 2\n6 4\n5 4\n4 2\n4 3\n6 2\n6 2\n3 1\n1 4\n3 6\n5 1\n5 5\n3 6\n6 4\n2 3\n6 5\n3 3",
"output": "Mishka"
},
{
"input": "94\n2 4\n6 4\n1 6\n1 4\n5 1\n3 3\n4 3\n6 1\n6 5\n3 2\n2 3\n5 1\n5 3\n1 2\n4 3\n3 2\n2 3\n4 6\n1 3\n6 3\n1 1\n3 2\n4 3\n1 5\n4 6\n3 2\n6 3\n1 6\n1 1\n1 2\n3 5\n1 3\n3 5\n4 4\n4 2\n1 4\n4 5\n1 3\n1 2\n1 1\n5 4\n5 5\n6 1\n2 1\n2 6\n6 6\n4 2\n3 6\n1 6\n6 6\n1 5\n3 2\n1 2\n4 4\n6 4\n4 1\n1 5\n3 3\n1 3\n3 4\n4 4\n1 1\n2 5\n4 5\n3 1\n3 1\n3 6\n3 2\n1 4\n1 6\n6 3\n2 4\n1 1\n2 2\n2 2\n2 1\n5 4\n1 2\n6 6\n2 2\n3 3\n6 3\n6 3\n1 6\n2 3\n2 4\n2 3\n6 6\n2 6\n6 3\n3 5\n1 4\n1 1\n3 5",
"output": "Chris"
},
{
"input": "81\n4 2\n1 2\n2 3\n4 5\n6 2\n1 6\n3 6\n3 4\n4 6\n4 4\n3 5\n4 6\n3 6\n3 5\n3 1\n1 3\n5 3\n3 4\n1 1\n4 1\n1 2\n6 1\n1 3\n6 5\n4 5\n4 2\n4 5\n6 2\n1 2\n2 6\n5 2\n1 5\n2 4\n4 3\n5 4\n1 2\n5 3\n2 6\n6 4\n1 1\n1 3\n3 1\n3 1\n6 5\n5 5\n6 1\n6 6\n5 2\n1 3\n1 4\n2 3\n5 5\n3 1\n3 1\n4 4\n1 6\n6 4\n2 2\n4 6\n4 4\n2 6\n2 4\n2 4\n4 1\n1 6\n1 4\n1 3\n6 5\n5 1\n1 3\n5 1\n1 4\n3 5\n2 6\n1 3\n5 6\n3 5\n4 4\n5 5\n5 6\n4 3",
"output": "Chris"
},
{
"input": "67\n6 5\n3 6\n1 6\n5 3\n5 4\n5 1\n1 6\n1 1\n3 2\n4 4\n3 1\n4 1\n1 5\n5 3\n3 3\n6 4\n2 4\n2 2\n4 3\n1 4\n1 4\n6 1\n1 2\n2 2\n5 1\n6 2\n3 5\n5 5\n2 2\n6 5\n6 2\n4 4\n3 1\n4 2\n6 6\n6 4\n5 1\n2 2\n4 5\n5 5\n4 6\n1 5\n6 3\n4 4\n1 5\n6 4\n3 6\n3 4\n1 6\n2 4\n2 1\n2 5\n6 5\n6 4\n4 1\n3 2\n1 2\n5 1\n5 6\n1 5\n3 5\n3 1\n5 3\n3 2\n5 1\n4 6\n6 6",
"output": "Mishka"
},
{
"input": "55\n6 6\n6 5\n2 2\n2 2\n6 4\n5 5\n6 5\n5 3\n1 3\n2 2\n5 6\n3 3\n3 3\n6 5\n3 5\n5 5\n1 2\n1 1\n4 6\n1 2\n5 5\n6 2\n6 3\n1 2\n5 1\n1 3\n3 3\n4 4\n2 5\n1 1\n5 3\n4 3\n2 2\n4 5\n5 6\n4 5\n6 3\n1 6\n6 4\n3 6\n1 6\n5 2\n6 3\n2 3\n5 5\n4 3\n3 1\n4 2\n1 1\n2 5\n5 3\n2 2\n6 3\n4 5\n2 2",
"output": "Mishka"
},
{
"input": "92\n2 3\n1 3\n2 6\n5 1\n5 5\n3 2\n5 6\n2 5\n3 1\n3 6\n4 5\n2 5\n1 2\n2 3\n6 5\n3 6\n4 4\n6 2\n4 5\n4 4\n5 1\n6 1\n3 4\n3 5\n6 6\n3 2\n6 4\n2 2\n3 5\n6 4\n6 3\n6 6\n3 4\n3 3\n6 1\n5 4\n6 2\n2 6\n5 6\n1 4\n4 6\n6 3\n3 1\n4 1\n6 6\n3 5\n6 3\n6 1\n1 6\n3 2\n6 6\n4 3\n3 4\n1 3\n3 5\n5 3\n6 5\n4 3\n5 5\n4 1\n1 5\n6 4\n2 3\n2 3\n1 5\n1 2\n5 2\n4 3\n3 6\n5 5\n5 4\n1 4\n3 3\n1 6\n5 6\n5 4\n5 3\n1 1\n6 2\n5 5\n2 5\n4 3\n6 6\n5 1\n1 1\n4 6\n4 6\n3 1\n6 4\n2 4\n2 2\n2 1",
"output": "Chris"
},
{
"input": "79\n5 3\n4 6\n3 6\n2 1\n5 2\n2 3\n4 4\n6 2\n2 5\n1 6\n6 6\n2 6\n3 3\n4 5\n6 2\n2 1\n1 5\n5 1\n2 1\n2 6\n5 3\n6 2\n2 6\n2 3\n1 5\n4 4\n6 3\n5 2\n3 2\n1 3\n1 3\n6 3\n2 6\n3 6\n5 3\n4 5\n6 1\n3 5\n3 5\n6 5\n1 5\n4 2\n6 2\n2 3\n4 6\n3 6\n2 5\n4 4\n1 1\n4 6\n2 6\n6 4\n3 2\n4 1\n1 2\n6 4\n5 6\n1 4\n2 2\n5 4\n3 2\n1 2\n2 4\n2 5\n2 1\n3 6\n3 3\n1 1\n2 2\n4 4\n4 5\n3 3\n5 3\n6 2\n4 5\n6 5\n2 5\n5 6\n2 2",
"output": "Chris"
},
{
"input": "65\n1 1\n5 1\n2 2\n5 4\n4 5\n2 5\n3 2\n5 6\n6 3\n1 1\n6 1\n1 5\n1 1\n5 2\n6 4\n1 6\n1 1\n4 3\n2 3\n5 6\n4 4\n6 2\n1 3\n4 3\n1 3\n6 3\n3 5\n4 2\n4 1\n6 1\n3 2\n2 6\n3 2\n3 5\n6 3\n4 3\n1 5\n2 6\n1 3\n4 1\n4 1\n2 5\n2 5\n6 2\n5 3\n3 1\n3 3\n5 1\n2 4\n5 3\n3 3\n1 1\n6 3\n3 3\n5 1\n1 6\n4 5\n6 6\n5 5\n2 5\n4 1\n2 2\n1 4\n1 6\n6 5",
"output": "Mishka"
},
{
"input": "1\n1 1",
"output": "Friendship is magic!^^"
}
] | 1,692,598,868 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | n = int(input())
mishka_Wins = 0
chris_Wins = 0
for _ in range(n):
mi, ci = map(int, input().split())
if mi > ci:
mishka_Wins += 1
elif ci > mi:
chris_Wins += 1
if mishka_Wins > chris_Wins:
print("Mishka")
elif chris_Wins > mishka_Wins:
print("Chris")
else:
print("Friendship is magic!^^") | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
Input Specification:
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively.
Output Specification:
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
Demo Input:
['3\n3 5\n2 1\n4 2\n', '2\n6 1\n1 6\n', '3\n1 5\n3 3\n2 2\n']
Demo Output:
['Mishka', 'Friendship is magic!^^', 'Chris']
Note:
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | ```python
n = int(input())
mishka_Wins = 0
chris_Wins = 0
for _ in range(n):
mi, ci = map(int, input().split())
if mi > ci:
mishka_Wins += 1
elif ci > mi:
chris_Wins += 1
if mishka_Wins > chris_Wins:
print("Mishka")
elif chris_Wins > mishka_Wins:
print("Chris")
else:
print("Friendship is magic!^^")
``` | 3 |
|
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "5\n0 73\n73 189\n189 766\n766 0\n0 0",
"output": "766"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 1\n1 0",
"output": "1"
},
{
"input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0",
"output": "1011"
},
{
"input": "5\n0 1\n1 2\n2 1\n1 2\n2 0",
"output": "2"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0",
"output": "22"
},
{
"input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0",
"output": "1776"
},
{
"input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0",
"output": "1016"
},
{
"input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0",
"output": "3"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0",
"output": "2071"
},
{
"input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0",
"output": "3"
},
{
"input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0",
"output": "1329"
},
{
"input": "2\n0 863\n863 0",
"output": "863"
},
{
"input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0",
"output": "8"
},
{
"input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0",
"output": "11"
},
{
"input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0",
"output": "7"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 900\n900 0",
"output": "900"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1000\n1000 0",
"output": "1000"
},
{
"input": "3\n0 802\n175 188\n815 0",
"output": "815"
},
{
"input": "3\n0 910\n910 976\n976 0",
"output": "976"
},
{
"input": "3\n0 2\n2 1\n1 0",
"output": "2"
}
] | 1,691,831,506 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 124 | 0 | n = int(input())
current = 0
mx = 0
for i in range(n):
l = list(map(int,input().split()))
current -= l[0]
current += l[1]
if(current>mx):
mx = current
print(mx)
| Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Input Specification:
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Output Specification:
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
Demo Input:
['4\n0 3\n2 5\n4 2\n4 0\n']
Demo Output:
['6\n']
Note:
For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | ```python
n = int(input())
current = 0
mx = 0
for i in range(n):
l = list(map(int,input().split()))
current -= l[0]
current += l[1]
if(current>mx):
mx = current
print(mx)
``` | 3 |
|
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line. | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them. | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "76 48",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "100 90",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBB"
},
{
"input": "90 100",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGG"
},
{
"input": "1 98",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "1 100",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "56 98",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "89 89",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB"
},
{
"input": "18 94",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "84 27",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "1 1",
"output": "GB"
},
{
"input": "1 2",
"output": "GBG"
},
{
"input": "2 1",
"output": "BGB"
},
{
"input": "1 34",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "46 2",
"output": "BGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "99 3",
"output": "BGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "10 100",
"output": "GBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "100 100",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB"
},
{
"input": "1 4",
"output": "GBGGG"
}
] | 1,691,204,342 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 23 | 124 | 0 | f = open('input.txt', 'r')
line = f.readline()
n, m = map(int, line.split())
f.close()
ans = ''
cur = 'B' if n > m else 'G'
while n and m:
ans += cur
if cur == 'B':
n -= 1
cur = 'G'
else:
m -= 1
cur = 'B'
while n:
ans += 'B'
n -= 1
while m:
ans += 'G'
m -= 1
f = open('output.txt', 'w')
f.write(ans) | Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line.
Input Specification:
The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space.
Output Specification:
Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them.
Demo Input:
['3 3\n', '4 2\n']
Demo Output:
['GBGBGB\n', 'BGBGBB\n']
Note:
In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | ```python
f = open('input.txt', 'r')
line = f.readline()
n, m = map(int, line.split())
f.close()
ans = ''
cur = 'B' if n > m else 'G'
while n and m:
ans += cur
if cur == 'B':
n -= 1
cur = 'G'
else:
m -= 1
cur = 'B'
while n:
ans += 'B'
n -= 1
while m:
ans += 'G'
m -= 1
f = open('output.txt', 'w')
f.write(ans)
``` | 3 |
|
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,683,528,604 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
s=str(n)
c=1
while(int(s)>10):
sm=0
for i in range(len(s)):
sm=sm+int(s[i])
c+=1
s=str(int(s)//10)
print(c) | 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
n=int(input())
s=str(n)
c=1
while(int(s)>10):
sm=0
for i in range(len(s)):
sm=sm+int(s[i])
c+=1
s=str(int(s)//10)
print(c)
``` | 0 |
174 | A | Problem About Equation | PROGRAMMING | 1,100 | [
"math"
] | null | null | A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
- there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal. | The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug. | Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma. | [
"5 50\n1 2 3 4 5\n",
"2 2\n1 100\n"
] | [
"12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n",
"-1\n"
] | none | 500 | [
{
"input": "5 50\n1 2 3 4 5",
"output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000"
},
{
"input": "2 2\n1 100",
"output": "-1"
},
{
"input": "2 2\n1 1",
"output": "1.000000\n1.000000"
},
{
"input": "3 2\n1 2 1",
"output": "1.000000\n0.000000\n1.000000"
},
{
"input": "3 5\n1 2 1",
"output": "2.000000\n1.000000\n2.000000"
},
{
"input": "10 95\n0 0 0 0 0 1 1 1 1 1",
"output": "10.000000\n10.000000\n10.000000\n10.000000\n10.000000\n9.000000\n9.000000\n9.000000\n9.000000\n9.000000"
},
{
"input": "3 5\n1 2 3",
"output": "2.666667\n1.666667\n0.666667"
},
{
"input": "3 5\n1 3 2",
"output": "2.666667\n0.666667\n1.666667"
},
{
"input": "3 5\n2 1 3",
"output": "1.666667\n2.666667\n0.666667"
},
{
"input": "3 5\n2 3 1",
"output": "1.666667\n0.666667\n2.666667"
},
{
"input": "3 5\n3 1 2",
"output": "0.666667\n2.666667\n1.666667"
},
{
"input": "3 5\n3 2 1",
"output": "0.666667\n1.666667\n2.666667"
},
{
"input": "2 1\n1 1",
"output": "0.500000\n0.500000"
},
{
"input": "2 1\n2 2",
"output": "0.500000\n0.500000"
},
{
"input": "3 2\n2 1 2",
"output": "0.333333\n1.333333\n0.333333"
},
{
"input": "3 3\n2 2 1",
"output": "0.666667\n0.666667\n1.666667"
},
{
"input": "3 3\n3 1 2",
"output": "0.000000\n2.000000\n1.000000"
},
{
"input": "100 100\n37 97 75 52 33 29 51 22 33 37 45 96 96 60 82 58 86 71 28 73 38 50 6 6 90 17 26 76 13 41 100 47 17 93 4 1 56 16 41 74 25 17 69 61 39 37 96 73 49 93 52 14 62 24 91 30 9 97 52 100 6 16 85 8 12 26 10 3 94 63 80 27 29 78 9 48 79 64 60 18 98 75 81 35 24 81 2 100 23 70 21 60 98 38 29 29 58 37 49 72",
"output": "-1"
},
{
"input": "100 100\n1 3 7 7 9 5 9 3 7 8 10 1 3 10 10 6 1 3 10 4 3 9 4 9 5 4 9 2 8 7 4 3 3 3 5 10 8 9 10 1 9 2 4 8 3 10 9 2 3 9 8 2 4 4 4 7 1 1 7 3 7 8 9 5 1 2 6 7 1 10 9 10 5 10 1 10 5 2 4 3 10 1 6 5 6 7 8 9 3 8 6 10 8 7 2 3 8 6 3 6",
"output": "-1"
},
{
"input": "100 61\n81 80 83 72 87 76 91 92 77 93 77 94 76 73 71 88 88 76 87 73 89 73 85 81 79 90 76 73 82 93 79 93 71 75 72 71 78 85 92 89 88 93 74 87 71 94 74 87 85 89 90 93 86 94 92 87 90 91 75 73 90 84 92 94 92 79 74 85 74 74 89 76 84 84 84 83 86 84 82 71 76 74 83 81 89 73 73 74 71 77 90 94 73 94 73 75 93 89 84 92",
"output": "-1"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..."
},
{
"input": "100 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1..."
},
{
"input": "100 100\n99 100 99 100 100 100 99 99 99 100 100 100 99 100 99 100 100 100 100 100 99 99 99 99 100 99 100 99 100 99 99 100 100 100 100 100 99 99 99 100 99 99 100 99 100 99 100 99 99 99 99 100 100 99 99 99 100 100 99 100 100 100 99 99 100 100 100 100 100 100 99 99 99 99 99 100 99 99 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 100 99 100 100 100 100 99",
"output": "1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0..."
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100",
"output": "0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0..."
},
{
"input": "100 100\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99",
"output": "1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n0.020000\n1.020000\n1..."
},
{
"input": "10 100\n52 52 51 52 52 52 51 51 52 52",
"output": "9.700000\n9.700000\n10.700000\n9.700000\n9.700000\n9.700000\n10.700000\n10.700000\n9.700000\n9.700000"
},
{
"input": "10 100\n13 13 13 13 12 13 12 13 12 12",
"output": "9.600000\n9.600000\n9.600000\n9.600000\n10.600000\n9.600000\n10.600000\n9.600000\n10.600000\n10.600000"
},
{
"input": "10 100\n50 51 47 51 48 46 49 51 46 51",
"output": "9.000000\n8.000000\n12.000000\n8.000000\n11.000000\n13.000000\n10.000000\n8.000000\n13.000000\n8.000000"
},
{
"input": "10 100\n13 13 9 12 12 11 13 8 10 13",
"output": "8.400000\n8.400000\n12.400000\n9.400000\n9.400000\n10.400000\n8.400000\n13.400000\n11.400000\n8.400000"
},
{
"input": "93 91\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0..."
},
{
"input": "93 97\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1..."
},
{
"input": "91 99\n99 100 100 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 99 100 99 100 100 100 100 100 99 99 100 99 100 99 99 100 100 100 100 99 99 100 100 100 99 100 100 99 100 100 99 100 99 99 99 100 99 99 99 100 99 100 99 100 99 100 99 99 100 100 100 100 99 100 99 100 99 99 100 100 99 100 100 100 100 99 99 100 100 99 99 100 99",
"output": "1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1..."
},
{
"input": "99 98\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n1.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0..."
},
{
"input": "98 99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99",
"output": "1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1..."
},
{
"input": "13 97\n52 52 51 51 52 52 51 52 51 51 52 52 52",
"output": "7.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n8.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n7.076923"
},
{
"input": "17 99\n13 13 12 13 11 12 12 12 13 13 11 13 13 13 13 12 13",
"output": "5.294118\n5.294118\n6.294118\n5.294118\n7.294118\n6.294118\n6.294118\n6.294118\n5.294118\n5.294118\n7.294118\n5.294118\n5.294118\n5.294118\n5.294118\n6.294118\n5.294118"
},
{
"input": "9 91\n52 51 50 52 52 51 50 48 51",
"output": "8.888889\n9.888889\n10.888889\n8.888889\n8.888889\n9.888889\n10.888889\n12.888889\n9.888889"
},
{
"input": "17 91\n13 13 13 13 12 12 13 13 12 13 12 13 10 12 13 13 12",
"output": "4.823529\n4.823529\n4.823529\n4.823529\n5.823529\n5.823529\n4.823529\n4.823529\n5.823529\n4.823529\n5.823529\n4.823529\n7.823529\n5.823529\n4.823529\n4.823529\n5.823529"
},
{
"input": "2 3\n1 1",
"output": "1.500000\n1.500000"
},
{
"input": "2 90\n0 89",
"output": "89.500000\n0.500000"
},
{
"input": "4 17\n3 4 8 1",
"output": "5.250000\n4.250000\n0.250000\n7.250000"
},
{
"input": "2 9\n5 5",
"output": "4.500000\n4.500000"
},
{
"input": "7 28\n1 3 9 10 9 6 10",
"output": "9.857143\n7.857143\n1.857143\n0.857143\n1.857143\n4.857143\n0.857143"
},
{
"input": "5 11\n1 2 3 4 5",
"output": "4.200000\n3.200000\n2.200000\n1.200000\n0.200000"
},
{
"input": "2 1\n1 1",
"output": "0.500000\n0.500000"
},
{
"input": "5 3\n1 1 1 1 1",
"output": "0.600000\n0.600000\n0.600000\n0.600000\n0.600000"
},
{
"input": "3 1\n100 100 100",
"output": "0.333333\n0.333333\n0.333333"
},
{
"input": "5 50\n2 2 3 2 2",
"output": "10.200000\n10.200000\n9.200000\n10.200000\n10.200000"
},
{
"input": "3 3\n2 2 3",
"output": "1.333333\n1.333333\n0.333333"
},
{
"input": "2 52\n2 100",
"output": "-1"
},
{
"input": "3 2\n2 2 3",
"output": "1.000000\n1.000000\n0.000000"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "0.200000\n0.200000\n0.200000\n0.200000\n0.200000"
},
{
"input": "2 4\n1 2",
"output": "2.500000\n1.500000"
},
{
"input": "5 49\n1 2 3 4 5",
"output": "11.800000\n10.800000\n9.800000\n8.800000\n7.800000"
}
] | 1,596,648,767 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 248 | 6,758,400 | # import sys
# sys.stdin = open("test.txt", 'r')
n, b = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = []
t = sum(a) + b
p = t/n
for v in a:
s = p-v
if s < 0:
print(-1)
break
else:
ans.append(s)
else:
for s in ans:
print(f'{s:.6f}')
| Title: Problem About Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
- there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal.
Input Specification:
The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug.
Output Specification:
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Demo Input:
['5 50\n1 2 3 4 5\n', '2 2\n1 100\n']
Demo Output:
['12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n', '-1\n']
Note:
none | ```python
# import sys
# sys.stdin = open("test.txt", 'r')
n, b = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = []
t = sum(a) + b
p = t/n
for v in a:
s = p-v
if s < 0:
print(-1)
break
else:
ans.append(s)
else:
for s in ans:
print(f'{s:.6f}')
``` | 3 |
|
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,675,957,070 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 122 | 0 | n = int(input())
a,b,c =0,0,0
while n != 0:
arr = input().split()
a, b, c = a+int(arr[0]), b+int(arr[1]), c+int(arr[2])
n -= 1
if a == 0 and b == 0 and 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 =0,0,0
while n != 0:
arr = input().split()
a, b, c = a+int(arr[0]), b+int(arr[1]), c+int(arr[2])
n -= 1
if a == 0 and b == 0 and c == 0:
print('YES')
else:
print("NO")
``` | 3.9695 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,628,043,628 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 248 | 20,172,800 | def bandwagons(s):
low=[i for i in s if i in "abcdefghijklmnopqrstuvwxyz"]
high=[i for i in s if i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
if len(low)>=len(high):
#return (len(low),s.lower())
return s.lower()
else:
#return (len(high),s.upper())
return s.upper()
s=input()
print(bandwagons(s))
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
def bandwagons(s):
low=[i for i in s if i in "abcdefghijklmnopqrstuvwxyz"]
high=[i for i in s if i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
if len(low)>=len(high):
#return (len(low),s.lower())
return s.lower()
else:
#return (len(high),s.upper())
return s.upper()
s=input()
print(bandwagons(s))
``` | 3.900425 |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win. | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output": "NO"
},
{
"input": "253308697183523656 25332878317796706",
"output": "YES"
},
{
"input": "669038685745448997 501718093668307460",
"output": "YES"
},
{
"input": "116453141993601660 87060381463547965",
"output": "YES"
},
{
"input": "766959657 370931668",
"output": "NO"
},
{
"input": "255787422422806632 146884995820359999",
"output": "YES"
},
{
"input": "502007866464507926 71266379084204128",
"output": "YES"
},
{
"input": "257439908778973480 64157133126869976",
"output": "NO"
},
{
"input": "232709385 91708542",
"output": "NO"
},
{
"input": "252482458300407528 89907711721009125",
"output": "NO"
},
{
"input": "6 2",
"output": "YES"
},
{
"input": "6 3",
"output": "NO"
},
{
"input": "6 4",
"output": "YES"
},
{
"input": "6 5",
"output": "YES"
},
{
"input": "6 6",
"output": "YES"
},
{
"input": "258266151957056904 30153168463725364",
"output": "NO"
},
{
"input": "83504367885565783 52285355047292458",
"output": "YES"
},
{
"input": "545668929424440387 508692735816921376",
"output": "YES"
},
{
"input": "547321411485639939 36665750286082900",
"output": "NO"
},
{
"input": "548973893546839491 183137237979822911",
"output": "NO"
},
{
"input": "544068082 193116851",
"output": "NO"
},
{
"input": "871412474 749817171",
"output": "YES"
},
{
"input": "999999999 1247",
"output": "NO"
},
{
"input": "851941088 712987048",
"output": "YES"
},
{
"input": "559922900 418944886",
"output": "YES"
},
{
"input": "293908937 37520518",
"output": "YES"
},
{
"input": "650075786 130049650",
"output": "NO"
},
{
"input": "1000000000 1000000000",
"output": "YES"
},
{
"input": "548147654663723363 107422751713800746",
"output": "YES"
},
{
"input": "828159210 131819483",
"output": "NO"
},
{
"input": "6242634 4110365",
"output": "YES"
},
{
"input": "458601973 245084155",
"output": "YES"
},
{
"input": "349593257 18089089",
"output": "YES"
},
{
"input": "814768821 312514745",
"output": "NO"
},
{
"input": "697884949 626323363",
"output": "YES"
},
{
"input": "667011589 54866795",
"output": "NO"
},
{
"input": "1000000000000000000 2",
"output": "NO"
},
{
"input": "1000000000000000000 3",
"output": "YES"
},
{
"input": "1000000000000000000 4",
"output": "NO"
},
{
"input": "999999999999999 1",
"output": "YES"
},
{
"input": "17 4",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
},
{
"input": "1000000000000000 2",
"output": "NO"
},
{
"input": "12 4",
"output": "YES"
},
{
"input": "6 1",
"output": "NO"
},
{
"input": "2 1",
"output": "NO"
},
{
"input": "10000000005 1",
"output": "YES"
},
{
"input": "10000000000000009 2",
"output": "NO"
},
{
"input": "12457895452123 1",
"output": "YES"
},
{
"input": "999999999999999999 9",
"output": "YES"
},
{
"input": "1000000000000 3",
"output": "YES"
},
{
"input": "13099714659575475 6549849616514894",
"output": "NO"
},
{
"input": "100000000000000001 1",
"output": "YES"
},
{
"input": "825175814723458 324",
"output": "YES"
},
{
"input": "20 4",
"output": "YES"
},
{
"input": "100000176877 4",
"output": "YES"
},
{
"input": "100000 3",
"output": "YES"
},
{
"input": "946744073709551614 10",
"output": "YES"
}
] | 1,675,727,678 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 93 | 0 | import sys
toks = (tok for tok in sys.stdin.read().split())
n = int(next(toks))
k = int(next(toks))
total = n // k
if total % 2 == 0:
print('NO')
else:
print('YES')
| Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
Output Specification:
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower).
Demo Input:
['1 1\n', '10 4\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win. | ```python
import sys
toks = (tok for tok in sys.stdin.read().split())
n = int(next(toks))
k = int(next(toks))
total = n // k
if total % 2 == 0:
print('NO')
else:
print('YES')
``` | 3 |
|
604 | B | More Cowbell | PROGRAMMING | 1,400 | [
"binary search",
"greedy"
] | null | null | Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection.
Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=><=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*. | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order. | Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*. | [
"2 1\n2 5\n",
"4 3\n2 3 5 9\n",
"3 2\n3 5 7\n"
] | [
"7\n",
"9\n",
"8\n"
] | In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | 1,000 | [
{
"input": "2 1\n2 5",
"output": "7"
},
{
"input": "4 3\n2 3 5 9",
"output": "9"
},
{
"input": "3 2\n3 5 7",
"output": "8"
},
{
"input": "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10 10\n3 15 31 61 63 63 68 94 98 100",
"output": "100"
},
{
"input": "100 97\n340 402 415 466 559 565 649 689 727 771 774 776 789 795 973 1088 1212 1293 1429 1514 1587 1599 1929 1997 2278 2529 2656 2677 2839 2894 2951 3079 3237 3250 3556 3568 3569 3578 3615 3641 3673 3892 4142 4418 4515 4766 4846 4916 5225 5269 5352 5460 5472 5635 5732 5886 5941 5976 5984 6104 6113 6402 6409 6460 6550 6563 6925 7006 7289 7401 7441 7451 7709 7731 7742 7750 7752 7827 8101 8154 8376 8379 8432 8534 8578 8630 8706 8814 8882 8972 9041 9053 9109 9173 9473 9524 9547 9775 9791 9983",
"output": "9983"
},
{
"input": "10 9\n7 29 35 38 41 47 54 56 73 74",
"output": "74"
},
{
"input": "1 2342\n12345",
"output": "12345"
},
{
"input": "10 5\n15 15 20 28 38 44 46 52 69 94",
"output": "109"
},
{
"input": "10 9\n6 10 10 32 36 38 69 80 82 93",
"output": "93"
},
{
"input": "10 10\n4 19 22 24 25 43 49 56 78 88",
"output": "88"
},
{
"input": "100 89\n474 532 759 772 803 965 1043 1325 1342 1401 1411 1452 1531 1707 1906 1928 2034 2222 2335 2606 2757 2968 2978 3211 3513 3734 3772 3778 3842 3948 3976 4038 4055 4113 4182 4267 4390 4408 4478 4595 4668 4792 4919 5133 5184 5255 5312 5341 5476 5628 5683 5738 5767 5806 5973 6051 6134 6254 6266 6279 6314 6342 6599 6676 6747 6777 6827 6842 7057 7097 7259 7340 7378 7405 7510 7520 7698 7796 8148 8351 8507 8601 8805 8814 8826 8978 9116 9140 9174 9338 9394 9403 9407 9423 9429 9519 9764 9784 9838 9946",
"output": "9946"
},
{
"input": "100 74\n10 211 323 458 490 592 979 981 1143 1376 1443 1499 1539 1612 1657 1874 2001 2064 2123 2274 2346 2471 2522 2589 2879 2918 2933 2952 3160 3164 3167 3270 3382 3404 3501 3522 3616 3802 3868 3985 4007 4036 4101 4580 4687 4713 4714 4817 4955 5257 5280 5343 5428 5461 5566 5633 5727 5874 5925 6233 6309 6389 6500 6701 6731 6847 6916 7088 7088 7278 7296 7328 7564 7611 7646 7887 7887 8065 8075 8160 8300 8304 8316 8355 8404 8587 8758 8794 8890 9038 9163 9235 9243 9339 9410 9587 9868 9916 9923 9986",
"output": "9986"
},
{
"input": "100 61\n82 167 233 425 432 456 494 507 562 681 683 921 1218 1323 1395 1531 1586 1591 1675 1766 1802 1842 2116 2625 2697 2735 2739 3337 3349 3395 3406 3596 3610 3721 4059 4078 4305 4330 4357 4379 4558 4648 4651 4784 4819 4920 5049 5312 5361 5418 5440 5463 5547 5594 5821 5951 5972 6141 6193 6230 6797 6842 6853 6854 7017 7026 7145 7322 7391 7460 7599 7697 7756 7768 7872 7889 8094 8215 8408 8440 8462 8714 8756 8760 8881 9063 9111 9184 9281 9373 9406 9417 9430 9511 9563 9634 9660 9788 9883 9927",
"output": "9927"
},
{
"input": "100 84\n53 139 150 233 423 570 786 861 995 1017 1072 1196 1276 1331 1680 1692 1739 1748 1826 2067 2280 2324 2368 2389 2607 2633 2760 2782 2855 2996 3030 3093 3513 3536 3557 3594 3692 3707 3823 3832 4009 4047 4088 4095 4408 4537 4565 4601 4784 4878 4935 5029 5252 5322 5389 5407 5511 5567 5857 6182 6186 6198 6280 6290 6353 6454 6458 6567 6843 7166 7216 7257 7261 7375 7378 7539 7542 7762 7771 7797 7980 8363 8606 8612 8663 8801 8808 8823 8918 8975 8997 9240 9245 9259 9356 9755 9759 9760 9927 9970",
"output": "9970"
},
{
"input": "100 50\n130 248 312 312 334 589 702 916 921 1034 1047 1346 1445 1500 1585 1744 1951 2123 2273 2362 2400 2455 2496 2530 2532 2944 3074 3093 3094 3134 3698 3967 4047 4102 4109 4260 4355 4466 4617 4701 4852 4892 4915 4917 4936 4981 4999 5106 5152 5203 5214 5282 5412 5486 5525 5648 5897 5933 5969 6251 6400 6421 6422 6558 6805 6832 6908 6924 6943 6980 7092 7206 7374 7417 7479 7546 7672 7756 7973 8020 8028 8079 8084 8085 8137 8153 8178 8239 8639 8667 8829 9263 9333 9370 9420 9579 9723 9784 9841 9993",
"output": "11103"
},
{
"input": "100 50\n156 182 208 409 496 515 659 761 772 794 827 912 1003 1236 1305 1388 1412 1422 1428 1465 1613 2160 2411 2440 2495 2684 2724 2925 3033 3035 3155 3260 3378 3442 3483 3921 4031 4037 4091 4113 4119 4254 4257 4442 4559 4614 4687 4839 4896 5054 5246 5316 5346 5859 5928 5981 6148 6250 6422 6433 6448 6471 6473 6485 6503 6779 6812 7050 7064 7074 7141 7378 7424 7511 7574 7651 7808 7858 8286 8291 8446 8536 8599 8628 8636 8768 8900 8981 9042 9055 9114 9146 9186 9411 9480 9590 9681 9749 9757 9983",
"output": "10676"
},
{
"input": "100 50\n145 195 228 411 577 606 629 775 1040 1040 1058 1187 1307 1514 1784 1867 1891 2042 2042 2236 2549 2555 2560 2617 2766 2807 2829 2917 3070 3072 3078 3095 3138 3147 3149 3196 3285 3287 3309 3435 3531 3560 3563 3769 3830 3967 4081 4158 4315 4387 4590 4632 4897 4914 5128 5190 5224 5302 5402 5416 5420 5467 5517 5653 5820 5862 5941 6053 6082 6275 6292 6316 6490 6530 6619 6632 6895 7071 7234 7323 7334 7412 7626 7743 8098 8098 8136 8158 8264 8616 8701 8718 8770 8803 8809 8983 9422 9530 9811 9866",
"output": "10011"
},
{
"input": "100 50\n56 298 387 456 518 532 589 792 870 1041 1055 1122 1141 1166 1310 1329 1523 1548 1626 1730 1780 1833 1850 1911 2006 2157 2303 2377 2403 2442 2450 2522 2573 2822 2994 3200 3238 3252 3280 3311 3345 3422 3429 3506 3526 3617 3686 3791 4134 4467 4525 4614 4633 4792 5017 5220 5243 5338 5445 5536 5639 5675 5763 5875 6129 6220 6228 6287 6385 6616 6789 6822 6940 6959 6985 7297 7304 7391 7443 7580 7824 7884 7981 8055 8063 8223 8280 8322 8346 8473 8688 8986 9087 9323 9477 9489 9518 9621 9699 9804",
"output": "10009"
},
{
"input": "100 49990\n221 257 543 613 818 855 884 1195 1233 1293 1327 1474 1567 1568 1728 1789 1809 1957 1994 2198 2217 2289 2298 2360 2441 2454 2517 2519 2597 2652 2909 2958 2970 3271 3310 3409 3450 3646 3950 3965 4016 4116 4134 4159 4462 4624 4631 4783 4804 5031 5276 5538 5729 5845 5880 5894 5959 5961 6028 6105 6184 6335 6370 6523 6532 6677 6762 6868 6998 7066 7245 7360 7490 7492 7645 7677 7786 7804 8038 8131 8207 8400 8507 8556 8575 8599 8673 8676 8712 8816 9123 9158 9216 9369 9628 9707 9768 9800 9876 9934",
"output": "9934"
},
{
"input": "1 50000\n2",
"output": "2"
},
{
"input": "1 40000\n23456",
"output": "23456"
},
{
"input": "1 2\n10",
"output": "10"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 2\n2 3",
"output": "3"
},
{
"input": "4 2\n1 2 8 9",
"output": "10"
}
] | 1,589,627,949 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 218 | 30,617,600 | n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0]*k
for i in range(n-1, -1, -1):
b[(n-1-i) % k] += a[i]
if n-1-i == k-1:
b = b[::-1]
print(max(b)) | Title: More Cowbell
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection.
Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=><=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*.
Input Specification:
The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order.
Output Specification:
Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*.
Demo Input:
['2 1\n2 5\n', '4 3\n2 3 5 9\n', '3 2\n3 5 7\n']
Demo Output:
['7\n', '9\n', '8\n']
Note:
In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0]*k
for i in range(n-1, -1, -1):
b[(n-1-i) % k] += a[i]
if n-1-i == k-1:
b = b[::-1]
print(max(b))
``` | 3 |
|
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "NO"
},
{
"input": "256\n16777217",
"output": "NO"
},
{
"input": "4638\n21511044",
"output": "YES\n1"
},
{
"input": "24\n191102976",
"output": "YES\n5"
},
{
"input": "52010\n557556453",
"output": "NO"
},
{
"input": "61703211\n1750753082",
"output": "NO"
},
{
"input": "137\n2571353",
"output": "YES\n2"
},
{
"input": "8758\n1746157336",
"output": "NO"
},
{
"input": "2\n64",
"output": "YES\n5"
},
{
"input": "96\n884736",
"output": "YES\n2"
},
{
"input": "1094841453\n1656354409",
"output": "NO"
},
{
"input": "1154413\n1229512809",
"output": "NO"
},
{
"input": "2442144\n505226241",
"output": "NO"
},
{
"input": "11548057\n1033418098",
"output": "NO"
},
{
"input": "581\n196122941",
"output": "YES\n2"
},
{
"input": "146\n1913781536",
"output": "NO"
},
{
"input": "945916\n1403881488",
"output": "NO"
},
{
"input": "68269\n365689065",
"output": "NO"
},
{
"input": "30\n900",
"output": "YES\n1"
},
{
"input": "6\n1296",
"output": "YES\n3"
},
{
"input": "1470193122\n1420950405",
"output": "NO"
},
{
"input": "90750\n1793111557",
"output": "NO"
},
{
"input": "1950054\n1664545956",
"output": "NO"
},
{
"input": "6767692\n123762320",
"output": "NO"
},
{
"input": "1437134\n1622348229",
"output": "NO"
},
{
"input": "444103\n1806462642",
"output": "NO"
},
{
"input": "2592\n6718464",
"output": "YES\n1"
},
{
"input": "50141\n366636234",
"output": "NO"
},
{
"input": "835\n582182875",
"output": "YES\n2"
},
{
"input": "156604\n902492689",
"output": "NO"
},
{
"input": "27385965\n1742270058",
"output": "NO"
},
{
"input": "3\n9",
"output": "YES\n1"
},
{
"input": "35\n1838265625",
"output": "YES\n5"
},
{
"input": "8\n4096",
"output": "YES\n3"
},
{
"input": "85955\n945811082",
"output": "NO"
},
{
"input": "54958832\n956670209",
"output": "NO"
},
{
"input": "1475381\n1348159738",
"output": "NO"
},
{
"input": "7313241\n413670642",
"output": "NO"
},
{
"input": "582470\n2116368165",
"output": "NO"
},
{
"input": "26859739\n595086170",
"output": "NO"
},
{
"input": "249766393\n1582130",
"output": "NO"
},
{
"input": "11734\n137686756",
"output": "YES\n1"
},
{
"input": "925093\n1098566745",
"output": "NO"
},
{
"input": "40\n1600",
"output": "YES\n1"
},
{
"input": "2147483647\n2147483647",
"output": "YES\n0"
},
{
"input": "2147483646\n2147483647",
"output": "NO"
},
{
"input": "2147483647\n2147483646",
"output": "NO"
},
{
"input": "2\n2147483647",
"output": "NO"
},
{
"input": "2\n1073741825",
"output": "NO"
},
{
"input": "2\n1073741824",
"output": "YES\n29"
},
{
"input": "10000\n10",
"output": "NO"
},
{
"input": "10\n10000",
"output": "YES\n3"
},
{
"input": "10\n2000000000",
"output": "NO"
},
{
"input": "10\n1000000000",
"output": "YES\n8"
},
{
"input": "5\n1808548329",
"output": "NO"
},
{
"input": "2\n2147483646",
"output": "NO"
},
{
"input": "25\n125",
"output": "NO"
},
{
"input": "6\n18",
"output": "NO"
},
{
"input": "5\n30",
"output": "NO"
}
] | 1,616,647,981 | 2,147,483,647 | PyPy 3 | OK | TESTS | 64 | 216 | 0 | k=int(input())
l=int(input())
i=0
while l>1:l/=k;i+=1
if l==1:
print("YES")
print(i-1)
else:print("NO") | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
Input Specification:
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
Output Specification:
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
Demo Input:
['5\n25\n', '3\n8\n']
Demo Output:
['YES\n1\n', 'NO\n']
Note:
none | ```python
k=int(input())
l=int(input())
i=0
while l>1:l/=k;i+=1
if l==1:
print("YES")
print(i-1)
else:print("NO")
``` | 3 |
|
630 | C | Lucky Numbers | PROGRAMMING | 1,100 | [
"combinatorics",
"math"
] | null | null | The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.
Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits. | The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold. | Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits. | [
"2\n"
] | [
"6"
] | none | 0 | [
{
"input": "2",
"output": "6"
},
{
"input": "1",
"output": "2"
},
{
"input": "3",
"output": "14"
},
{
"input": "5",
"output": "62"
},
{
"input": "12",
"output": "8190"
},
{
"input": "34",
"output": "34359738366"
},
{
"input": "43",
"output": "17592186044414"
},
{
"input": "49",
"output": "1125899906842622"
},
{
"input": "54",
"output": "36028797018963966"
},
{
"input": "55",
"output": "72057594037927934"
}
] | 1,695,876,778 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 31 | 0 | a=int(input())
print(2*((2**a)-1)) | Title: Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.
Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits.
Input Specification:
The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold.
Output Specification:
Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits.
Demo Input:
['2\n']
Demo Output:
['6']
Note:
none | ```python
a=int(input())
print(2*((2**a)-1))
``` | 3 |
|
811 | B | Vladik and Complicated Book | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation *P* from position *l* to position *r* inclusive, because she loves the order. For every of such sorting Vladik knows number *x* — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has *p**x* changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in permutation are distinct.
Each of the next *m* lines contains three space-separated integers *l**i*, *r**i*, *x**i* (1<=≤<=*l**i*<=≤<=*x**i*<=≤<=*r**i*<=≤<=*n*) — left and right borders of sorted subsegment in *i*-th sorting and position that is interesting to Vladik. | For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | [
"5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n",
"6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n"
] | [
"Yes\nNo\nYes\nYes\nNo\n",
"Yes\nNo\nYes\nNo\nYes\n"
] | Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes". 1. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No". | 1,000 | [
{
"input": "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo"
},
{
"input": "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3",
"output": "Yes\nNo\nYes\nNo\nYes"
},
{
"input": "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 2\n6 8 7\n1 1 1\n7 9 9\n2 9 4",
"output": "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo"
},
{
"input": "20 20\n18 17 2 3 16 15 1 9 12 8 20 11 13 14 4 5 19 7 10 6\n13 15 15\n1 1 1\n2 2 2\n11 14 13\n10 11 10\n2 8 6\n12 18 16\n4 8 8\n2 2 2\n5 11 11\n4 9 9\n5 6 6\n3 20 12\n8 8 8\n6 16 11\n9 18 18\n8 18 17\n1 1 1\n2 6 5\n1 4 3",
"output": "No\nYes\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "5 10\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo\nYes\nNo\nYes\nYes\nNo"
}
] | 1,495,880,387 | 2,687 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 9 | 2,000 | 1,024,000 | def main():
N, M = map(int, input().split())
P = list(map(int, input().split()))
for m in range(M):
l,r,x = map(lambda x:int(x)-1, input().split())
if not (l <= x <= r):
print("Yes")
continue
ix = x - l
rank = 0
for p in P[l:r+1]:
if P[x] == p:
continue
if p < P[x]:
rank += 1
if rank > ix:
break
if rank == ix:
print("Yes")
else:
print("No")
if __name__ == "__main__":
# global stime
# stime = time.clock()
main()
| Title: Vladik and Complicated Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation *P* from position *l* to position *r* inclusive, because she loves the order. For every of such sorting Vladik knows number *x* — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has *p**x* changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input Specification:
First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in permutation are distinct.
Each of the next *m* lines contains three space-separated integers *l**i*, *r**i*, *x**i* (1<=≤<=*l**i*<=≤<=*x**i*<=≤<=*r**i*<=≤<=*n*) — left and right borders of sorted subsegment in *i*-th sorting and position that is interesting to Vladik.
Output Specification:
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Demo Input:
['5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n', '6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n']
Demo Output:
['Yes\nNo\nYes\nYes\nNo\n', 'Yes\nNo\nYes\nNo\nYes\n']
Note:
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes". 1. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No". | ```python
def main():
N, M = map(int, input().split())
P = list(map(int, input().split()))
for m in range(M):
l,r,x = map(lambda x:int(x)-1, input().split())
if not (l <= x <= r):
print("Yes")
continue
ix = x - l
rank = 0
for p in P[l:r+1]:
if P[x] == p:
continue
if p < P[x]:
rank += 1
if rank > ix:
break
if rank == ix:
print("Yes")
else:
print("No")
if __name__ == "__main__":
# global stime
# stime = time.clock()
main()
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,627,587,762 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 109 | 20,172,800 | string = input()
word=[]
cnth = cnte = cntl = cnto = 0
for i in string:
if i=='h'and cnth==0:
word.append(i)
cnth+=1
elif i=='e'and cnte==0:
word.append(i)
cnte+=1
elif i=='l'and cntl<2:
word.append(i)
cntl+=1
elif i=='o'and cnto==0:
word.append(i)
cnto+=1
if("".join(word)=='hello'):
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
string = input()
word=[]
cnth = cnte = cntl = cnto = 0
for i in string:
if i=='h'and cnth==0:
word.append(i)
cnth+=1
elif i=='e'and cnte==0:
word.append(i)
cnte+=1
elif i=='l'and cntl<2:
word.append(i)
cntl+=1
elif i=='o'and cnto==0:
word.append(i)
cnto+=1
if("".join(word)=='hello'):
print("YES")
else:
print("NO")
``` | 0 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,564,770,393 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | def find_greatest(arr):
gr = arr[0]
gr_index = 0
for i in range(len(arr)):
if arr[i] > gr:
gr = arr[i]
gr_index = i
return gr_index
def cut(a, b):
# a lesss than b
if b % a == 0:
b /= a
a /= a
elif (b % 2 and a % 2) == 0:
b /= 2
a /= 2
elif (b % 3 and a % 3) == 0:
b /= 3
a /= 3
return ("{}/{}".format(int(a), int(b)))
throws = list(map(int, input().split(" ")))
big = throws[find_greatest(throws)]
need_cnt = 7 - big
print(cut(need_cnt, 6))
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
def find_greatest(arr):
gr = arr[0]
gr_index = 0
for i in range(len(arr)):
if arr[i] > gr:
gr = arr[i]
gr_index = i
return gr_index
def cut(a, b):
# a lesss than b
if b % a == 0:
b /= a
a /= a
elif (b % 2 and a % 2) == 0:
b /= 2
a /= 2
elif (b % 3 and a % 3) == 0:
b /= 3
a /= 3
return ("{}/{}".format(int(a), int(b)))
throws = list(map(int, input().split(" ")))
big = throws[find_greatest(throws)]
need_cnt = 7 - big
print(cut(need_cnt, 6))
``` | 0 |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.
For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.
To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.
In the third sample, we need to flip the second and fourth cards. | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01234567890123456789012345678901234567890123456789",
"output": "25"
},
{
"input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb",
"output": "10"
},
{
"input": "cjw2dwmr10pku4yxohe0wglktd",
"output": "4"
},
{
"input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6",
"output": "13"
},
{
"input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1",
"output": "13"
},
{
"input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs",
"output": "8"
},
{
"input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc",
"output": "14"
},
{
"input": "2222",
"output": "0"
},
{
"input": "13579",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "0",
"output": "0"
},
{
"input": "a",
"output": "1"
},
{
"input": "y",
"output": "0"
},
{
"input": "w",
"output": "0"
},
{
"input": "oo",
"output": "2"
},
{
"input": "oy",
"output": "1"
},
{
"input": "yo",
"output": "1"
},
{
"input": "yy",
"output": "0"
},
{
"input": "a0",
"output": "1"
},
{
"input": "a9",
"output": "2"
},
{
"input": "y0",
"output": "0"
},
{
"input": "y7",
"output": "1"
},
{
"input": "0a",
"output": "1"
},
{
"input": "3a",
"output": "2"
},
{
"input": "06",
"output": "0"
},
{
"input": "07",
"output": "1"
},
{
"input": "70",
"output": "1"
},
{
"input": "77",
"output": "2"
},
{
"input": "13570",
"output": "4"
},
{
"input": "0000000000011111",
"output": "5"
},
{
"input": "1357",
"output": "4"
},
{
"input": "uuuuuuuuuuuuuuuuuu",
"output": "18"
},
{
"input": "gabieurat",
"output": "5"
}
] | 1,514,627,845 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 61 | 5,632,000 | s = input().strip()
print (sum([s.count(x) for x in "aeiou13579"]))
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.
For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.
To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
Input Specification:
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Output Specification:
Print a single integer, the minimum number of cards you must turn over to verify your claim.
Demo Input:
['ee\n', 'z\n', '0ay1\n']
Demo Output:
['2\n', '0\n', '2\n']
Note:
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.
In the third sample, we need to flip the second and fourth cards. | ```python
s = input().strip()
print (sum([s.count(x) for x in "aeiou13579"]))
``` | 3 |
|
401 | A | Vanya and Cards | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*. | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value. | Print a single number — the answer to the problem. | [
"3 2\n-1 1 2\n",
"2 3\n-2 -2\n"
] | [
"1\n",
"2\n"
] | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | 500 | [
{
"input": "3 2\n-1 1 2",
"output": "1"
},
{
"input": "2 3\n-2 -2",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "2 2\n-1 -1",
"output": "1"
},
{
"input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2",
"output": "4"
},
{
"input": "15 16\n-15 -5 -15 -14 -8 15 -15 -12 -5 -3 5 -7 3 8 -15",
"output": "6"
},
{
"input": "1 4\n-3",
"output": "1"
},
{
"input": "10 7\n6 4 6 6 -3 4 -1 2 3 3",
"output": "5"
},
{
"input": "2 1\n1 -1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "8 13\n-11 -1 -11 12 -2 -2 -10 -11",
"output": "3"
},
{
"input": "16 11\n3 -7 7 -9 -2 -3 -4 -2 -6 8 10 7 1 4 6 7",
"output": "2"
},
{
"input": "67 15\n-2 -2 6 -4 -7 4 3 13 -9 -4 11 -7 -6 -11 1 11 -1 11 14 10 -8 7 5 11 -13 1 -1 7 -14 9 -11 -11 13 -4 12 -11 -8 -5 -11 6 10 -2 6 9 9 6 -11 -2 7 -10 -1 9 -8 -5 1 -7 -2 3 -1 -13 -6 -9 -8 10 13 -3 9",
"output": "1"
},
{
"input": "123 222\n44 -190 -188 -185 -55 17 190 176 157 176 -24 -113 -54 -61 -53 53 -77 68 -12 -114 -217 163 -122 37 -37 20 -108 17 -140 -210 218 19 -89 54 18 197 111 -150 -36 -131 -172 36 67 16 -202 72 169 -137 -34 -122 137 -72 196 -17 -104 180 -102 96 -69 -184 21 -15 217 -61 175 -221 62 173 -93 -106 122 -135 58 7 -110 -108 156 -141 -102 -50 29 -204 -46 -76 101 -33 -190 99 52 -197 175 -71 161 -140 155 10 189 -217 -97 -170 183 -88 83 -149 157 -208 154 -3 77 90 74 165 198 -181 -166 -4 -200 -89 -200 131 100 -61 -149",
"output": "8"
},
{
"input": "130 142\n58 -50 43 -126 84 -92 -108 -92 57 127 12 -135 -49 89 141 -112 -31 47 75 -19 80 81 -5 17 10 4 -26 68 -102 -10 7 -62 -135 -123 -16 55 -72 -97 -34 21 21 137 130 97 40 -18 110 -52 73 52 85 103 -134 -107 88 30 66 97 126 82 13 125 127 -87 81 22 45 102 13 95 4 10 -35 39 -43 -112 -5 14 -46 19 61 -44 -116 137 -116 -80 -39 92 -75 29 -65 -15 5 -108 -114 -129 -5 52 -21 118 -41 35 -62 -125 130 -95 -11 -75 19 108 108 127 141 2 -130 54 96 -81 -102 140 -58 -102 132 50 -126 82 6 45 -114 -42",
"output": "5"
},
{
"input": "7 12\n2 5 -1 -4 -7 4 3",
"output": "1"
},
{
"input": "57 53\n-49 7 -41 7 38 -51 -23 8 45 1 -24 26 37 28 -31 -40 38 25 -32 -47 -3 20 -40 -32 -44 -36 5 33 -16 -5 28 10 -22 3 -10 -51 -32 -51 27 -50 -22 -12 41 3 15 24 30 -12 -34 -15 -29 38 -10 -35 -9 6 -51",
"output": "8"
},
{
"input": "93 273\n-268 -170 -163 19 -69 18 -244 35 -34 125 -224 -48 179 -247 127 -150 271 -49 -102 201 84 -151 -70 -46 -16 216 240 127 3 218 -209 223 -227 -201 228 -8 203 46 -100 -207 126 255 40 -58 -217 93 172 -97 23 183 102 -92 -157 -117 173 47 144 -235 -227 -62 -128 13 -151 158 110 -116 68 -2 -148 -206 -52 79 -152 -223 74 -149 -69 232 38 -70 -256 -213 -236 132 -189 -200 199 -57 -108 -53 269 -101 -134",
"output": "8"
},
{
"input": "1 1000\n997",
"output": "1"
},
{
"input": "4 3\n2 -1 -2 -1",
"output": "1"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 2\n1 -1",
"output": "0"
},
{
"input": "2 2\n-1 1",
"output": "0"
},
{
"input": "2 3\n-1 1",
"output": "0"
},
{
"input": "2 2\n-2 2",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "2"
},
{
"input": "4 2\n-1 -1 -1 -1",
"output": "2"
},
{
"input": "4 1\n-1 -1 -1 1",
"output": "2"
},
{
"input": "3 2\n2 2 2",
"output": "3"
},
{
"input": "10 300\n300 300 300 300 300 300 300 300 300 300",
"output": "10"
}
] | 1,591,978,157 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 139 | 0 | n, x = map(int,input().split())
l = list(map(int,input().split()))
z = sum(l)
if z == 0:
print(0)
else:
if abs(z) <= n:
print(1)
else:
if abs(z) % n == 0:
print(abs(z) // n)
else:
print(abs(z) // n + 1) | Title: Vanya and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*.
Input Specification:
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['3 2\n-1 1 2\n', '2 3\n-2 -2\n']
Demo Output:
['1\n', '2\n']
Note:
In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | ```python
n, x = map(int,input().split())
l = list(map(int,input().split()))
z = sum(l)
if z == 0:
print(0)
else:
if abs(z) <= n:
print(1)
else:
if abs(z) % n == 0:
print(abs(z) // n)
else:
print(abs(z) // n + 1)
``` | 0 |
|
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
If we sort all lucky numbers in increasing order, what's the 1-based index of *n*?
Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back. | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"output": "8"
},
{
"input": "774",
"output": "13"
},
{
"input": "4",
"output": "1"
},
{
"input": "4447747",
"output": "140"
},
{
"input": "7747474",
"output": "233"
},
{
"input": "4444",
"output": "15"
},
{
"input": "4447",
"output": "16"
},
{
"input": "7",
"output": "2"
},
{
"input": "4",
"output": "1"
},
{
"input": "4447744",
"output": "139"
},
{
"input": "77474",
"output": "57"
},
{
"input": "7747",
"output": "28"
},
{
"input": "444",
"output": "7"
},
{
"input": "7",
"output": "2"
},
{
"input": "7774477",
"output": "242"
},
{
"input": "4477774",
"output": "157"
},
{
"input": "7444",
"output": "23"
},
{
"input": "7474747",
"output": "212"
},
{
"input": "77",
"output": "6"
},
{
"input": "774477",
"output": "114"
},
{
"input": "7",
"output": "2"
},
{
"input": "47",
"output": "4"
},
{
"input": "747777",
"output": "110"
},
{
"input": "444444444",
"output": "511"
},
{
"input": "777777777",
"output": "1022"
},
{
"input": "477477447",
"output": "728"
},
{
"input": "777744747",
"output": "996"
}
] | 1,594,305,342 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | lucky = int(input())
i = 0
while i<=lucky:
while i>0:
r = i%10
if r not 4 or r not 7:
break
count += 1
if lucky == i:
print(count)
i += 1
| Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
If we sort all lucky numbers in increasing order, what's the 1-based index of *n*?
Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.
Input Specification:
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
Print the index of *n* among all lucky numbers.
Demo Input:
['4\n', '7\n', '77\n']
Demo Output:
['1\n', '2\n', '6\n']
Note:
none | ```python
lucky = int(input())
i = 0
while i<=lucky:
while i>0:
r = i%10
if r not 4 or r not 7:
break
count += 1
if lucky == i:
print(count)
i += 1
``` | -1 |
|
858 | A | k-rounding | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*. | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 750 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "2"
},
{
"input": "100 0",
"output": "100"
},
{
"input": "1000000000 0",
"output": "1000000000"
},
{
"input": "160 2",
"output": "800"
},
{
"input": "3 0",
"output": "3"
},
{
"input": "10 0",
"output": "10"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "3 1",
"output": "30"
},
{
"input": "4 1",
"output": "20"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "6 1",
"output": "30"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "8 1",
"output": "40"
},
{
"input": "9 1",
"output": "90"
},
{
"input": "10 1",
"output": "10"
},
{
"input": "11 1",
"output": "110"
},
{
"input": "12 1",
"output": "60"
},
{
"input": "16 2",
"output": "400"
},
{
"input": "2 2",
"output": "100"
},
{
"input": "1 2",
"output": "100"
},
{
"input": "5 2",
"output": "100"
},
{
"input": "15 2",
"output": "300"
},
{
"input": "36 2",
"output": "900"
},
{
"input": "1 8",
"output": "100000000"
},
{
"input": "8 8",
"output": "100000000"
},
{
"input": "96 8",
"output": "300000000"
},
{
"input": "175 8",
"output": "700000000"
},
{
"input": "9999995 8",
"output": "199999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "12345678 8",
"output": "617283900000000"
},
{
"input": "78125 8",
"output": "100000000"
},
{
"input": "390625 8",
"output": "100000000"
},
{
"input": "1953125 8",
"output": "500000000"
},
{
"input": "9765625 8",
"output": "2500000000"
},
{
"input": "68359375 8",
"output": "17500000000"
},
{
"input": "268435456 8",
"output": "104857600000000"
},
{
"input": "125829120 8",
"output": "9830400000000"
},
{
"input": "128000 8",
"output": "400000000"
},
{
"input": "300000 8",
"output": "300000000"
},
{
"input": "3711871 8",
"output": "371187100000000"
},
{
"input": "55555 8",
"output": "1111100000000"
},
{
"input": "222222222 8",
"output": "11111111100000000"
},
{
"input": "479001600 8",
"output": "7484400000000"
},
{
"input": "655360001 7",
"output": "6553600010000000"
},
{
"input": "655360001 8",
"output": "65536000100000000"
},
{
"input": "1000000000 1",
"output": "1000000000"
},
{
"input": "1000000000 7",
"output": "1000000000"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "10000000 8",
"output": "100000000"
},
{
"input": "1000000 8",
"output": "100000000"
},
{
"input": "10000009 8",
"output": "1000000900000000"
},
{
"input": "10000005 8",
"output": "200000100000000"
},
{
"input": "10000002 8",
"output": "500000100000000"
},
{
"input": "999999997 8",
"output": "99999999700000000"
},
{
"input": "999999997 7",
"output": "9999999970000000"
},
{
"input": "999999995 8",
"output": "19999999900000000"
},
{
"input": "123 8",
"output": "12300000000"
},
{
"input": "24 2",
"output": "600"
},
{
"input": "16 4",
"output": "10000"
},
{
"input": "123456787 8",
"output": "12345678700000000"
},
{
"input": "100000000 8",
"output": "100000000"
},
{
"input": "7 1",
"output": "70"
},
{
"input": "101 1",
"output": "1010"
},
{
"input": "50 2",
"output": "100"
},
{
"input": "999999818 1",
"output": "4999999090"
},
{
"input": "2 1",
"output": "10"
},
{
"input": "123 1",
"output": "1230"
},
{
"input": "16 1",
"output": "80"
},
{
"input": "1 1",
"output": "10"
},
{
"input": "1000000000 8",
"output": "1000000000"
},
{
"input": "15304 6",
"output": "1913000000"
},
{
"input": "3 8",
"output": "300000000"
},
{
"input": "4 2",
"output": "100"
},
{
"input": "100000 7",
"output": "10000000"
},
{
"input": "5 8",
"output": "100000000"
},
{
"input": "16724 6",
"output": "4181000000"
},
{
"input": "999999999 1",
"output": "9999999990"
},
{
"input": "999999990 8",
"output": "9999999900000000"
},
{
"input": "999999999 8",
"output": "99999999900000000"
},
{
"input": "100000 1",
"output": "100000"
},
{
"input": "8 3",
"output": "1000"
},
{
"input": "16768 6",
"output": "262000000"
},
{
"input": "123456789 1",
"output": "1234567890"
},
{
"input": "2 8",
"output": "100000000"
},
{
"input": "999999937 8",
"output": "99999993700000000"
},
{
"input": "5 1",
"output": "10"
},
{
"input": "2000000 7",
"output": "10000000"
},
{
"input": "1999998 2",
"output": "99999900"
},
{
"input": "125 3",
"output": "1000"
}
] | 1,602,908,629 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 23 | 140 | 0 | import math
def function(n, k):
multi=[]
zero_count=[]
for i in range(1, 11):
total=0
multi.append(n*i)
c=str(n*i)
l=list(c)
l1=l[::-1]
for j in l1:
if j=='0':
total+=1
if j!='0':
break
zero_count.append(total)
#print(multi)
#print(zero_count)
if k in zero_count:
print(multi[zero_count.index(k)])
if k not in zero_count:
if k<min(zero_count):
print(multi[0])
if k>min(zero_count):
c=multi[zero_count.index(max(zero_count))]
s=str(c)
#print(c)
for k in range(abs(max(zero_count)-k)):
s+='0'
print(s)
if __name__=="__main__":
n, k=map(int, input().rstrip().split())
function(n, k) | Title: k-rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the *k*-rounding of *n*.
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Output Specification:
Print the *k*-rounding of *n*.
Demo Input:
['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n']
Demo Output:
['30000\n', '10000\n', '38101\n', '12345678900000000\n']
Note:
none | ```python
import math
def function(n, k):
multi=[]
zero_count=[]
for i in range(1, 11):
total=0
multi.append(n*i)
c=str(n*i)
l=list(c)
l1=l[::-1]
for j in l1:
if j=='0':
total+=1
if j!='0':
break
zero_count.append(total)
#print(multi)
#print(zero_count)
if k in zero_count:
print(multi[zero_count.index(k)])
if k not in zero_count:
if k<min(zero_count):
print(multi[0])
if k>min(zero_count):
c=multi[zero_count.index(max(zero_count))]
s=str(c)
#print(c)
for k in range(abs(max(zero_count)-k)):
s+='0'
print(s)
if __name__=="__main__":
n, k=map(int, input().rstrip().split())
function(n, k)
``` | 0 |
|
413 | A | Data Recovery | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in *n* steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only *m*.
The next day, the engineer's assistant filed in a report with all the *m* temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers *n*, *m*, *min*, *max* and the list of *m* temperatures determine whether you can upgrade the set of *m* temperatures to the set of *n* temperatures (that is add *n*<=-<=*m* temperatures), so that the minimum temperature was *min* and the maximum one was *max*. | The first line contains four integers *n*,<=*m*,<=*min*,<=*max* (1<=≤<=*m*<=<<=*n*<=≤<=100; 1<=≤<=*min*<=<<=*max*<=≤<=100). The second line contains *m* space-separated integers *t**i* (1<=≤<=*t**i*<=≤<=100) — the temperatures reported by the assistant.
Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. | If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). | [
"2 1 1 2\n1\n",
"3 1 1 3\n2\n",
"2 1 1 3\n2\n"
] | [
"Correct\n",
"Correct\n",
"Incorrect\n"
] | In the first test sample one of the possible initial configurations of temperatures is [1, 2].
In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].
In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3. | 500 | [
{
"input": "2 1 1 2\n1",
"output": "Correct"
},
{
"input": "3 1 1 3\n2",
"output": "Correct"
},
{
"input": "2 1 1 3\n2",
"output": "Incorrect"
},
{
"input": "3 1 1 5\n3",
"output": "Correct"
},
{
"input": "3 2 1 5\n1 5",
"output": "Correct"
},
{
"input": "3 2 1 5\n1 1",
"output": "Correct"
},
{
"input": "3 2 1 5\n5 5",
"output": "Correct"
},
{
"input": "3 2 1 5\n1 6",
"output": "Incorrect"
},
{
"input": "3 2 5 10\n1 10",
"output": "Incorrect"
},
{
"input": "6 5 3 6\n4 4 4 4 4",
"output": "Incorrect"
},
{
"input": "100 50 68 97\n20 42 93 1 98 6 32 11 48 46 82 96 24 73 40 100 99 10 55 87 65 80 97 54 59 48 30 22 16 92 66 2 22 60 23 81 64 60 34 60 99 99 4 70 91 99 30 20 41 96",
"output": "Incorrect"
},
{
"input": "100 50 1 2\n1 1 2 1 1 2 2 1 1 1 1 1 2 2 1 2 1 2 2 1 1 1 2 2 2 1 1 2 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 2 1 2 2 2 1 2",
"output": "Correct"
},
{
"input": "100 99 1 2\n2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 2 2 2 1 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 1 2 2 1 1 1 2 1 1 2 1 1 2 1 2 1 2 1 1 1 1 2 1 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 1 1 2 2 2",
"output": "Correct"
},
{
"input": "3 2 2 100\n40 1",
"output": "Incorrect"
},
{
"input": "3 2 2 3\n4 4",
"output": "Incorrect"
},
{
"input": "5 2 2 4\n2 2",
"output": "Correct"
},
{
"input": "5 1 1 4\n1",
"output": "Correct"
},
{
"input": "9 7 1 4\n4 3 3 2 2 4 1",
"output": "Correct"
},
{
"input": "9 5 2 3\n4 2 4 3 3",
"output": "Incorrect"
},
{
"input": "6 3 1 3\n1 4 2",
"output": "Incorrect"
},
{
"input": "3 2 1 99\n34 100",
"output": "Incorrect"
},
{
"input": "4 2 1 99\n100 38",
"output": "Incorrect"
},
{
"input": "5 2 1 99\n100 38",
"output": "Incorrect"
},
{
"input": "4 2 1 99\n36 51",
"output": "Correct"
},
{
"input": "7 6 3 10\n5 10 7 7 4 5",
"output": "Correct"
},
{
"input": "8 6 3 10\n8 5 7 8 4 4",
"output": "Correct"
},
{
"input": "9 6 3 10\n9 7 7 5 3 10",
"output": "Correct"
},
{
"input": "16 15 30 40\n36 37 35 36 34 34 37 35 32 33 31 38 39 38 38",
"output": "Incorrect"
},
{
"input": "17 15 30 40\n38 36 37 34 30 38 38 31 38 38 36 39 39 37 35",
"output": "Correct"
},
{
"input": "18 15 30 40\n35 37 31 32 30 33 36 38 36 38 31 30 39 32 36",
"output": "Correct"
},
{
"input": "17 16 30 40\n39 32 37 31 40 32 36 34 56 34 40 36 37 36 33 36",
"output": "Incorrect"
},
{
"input": "18 16 30 40\n32 35 33 39 34 30 37 34 30 34 39 18 32 37 37 36",
"output": "Incorrect"
},
{
"input": "19 16 30 40\n36 30 37 30 37 32 34 30 35 35 33 35 39 37 46 37",
"output": "Incorrect"
},
{
"input": "2 1 2 100\n38",
"output": "Incorrect"
},
{
"input": "3 1 2 100\n1",
"output": "Incorrect"
},
{
"input": "4 1 2 100\n1",
"output": "Incorrect"
},
{
"input": "91 38 1 3\n3 2 3 2 3 2 3 3 1 1 1 2 2 1 3 2 3 1 3 3 1 3 3 2 1 2 2 3 1 2 1 3 2 2 3 1 1 2",
"output": "Correct"
},
{
"input": "4 3 2 10\n6 3 10",
"output": "Correct"
},
{
"input": "41 6 4 10\n10 7 4 9 9 10",
"output": "Correct"
},
{
"input": "21 1 1 9\n9",
"output": "Correct"
},
{
"input": "2 1 9 10\n10",
"output": "Correct"
},
{
"input": "2 1 2 9\n9",
"output": "Correct"
},
{
"input": "8 7 5 9\n6 7 8 5 5 6 6",
"output": "Correct"
},
{
"input": "3 2 2 8\n7 2",
"output": "Correct"
},
{
"input": "71 36 1 10\n7 10 8 1 3 8 5 7 3 10 8 1 6 4 5 7 8 2 4 3 4 10 8 5 1 2 8 8 10 10 4 3 7 9 7 8",
"output": "Correct"
},
{
"input": "85 3 4 9\n4 8 7",
"output": "Correct"
},
{
"input": "4 3 4 10\n9 10 5",
"output": "Correct"
},
{
"input": "2 1 1 5\n1",
"output": "Correct"
},
{
"input": "91 75 1 10\n2 6 9 7 4 9 4 8 10 6 4 1 10 6 5 9 7 5 1 4 6 4 8 2 1 3 5 7 6 9 5 5 8 1 7 1 4 2 8 3 1 6 6 2 10 6 2 2 8 5 4 5 5 3 10 9 4 3 1 9 10 3 2 4 8 7 4 9 3 1 1 1 3 4 5",
"output": "Correct"
},
{
"input": "10 4 1 8\n7 9 6 6",
"output": "Incorrect"
},
{
"input": "18 1 3 10\n2",
"output": "Incorrect"
},
{
"input": "6 2 4 8\n6 3",
"output": "Incorrect"
},
{
"input": "17 6 2 8\n3 8 6 1 6 4",
"output": "Incorrect"
},
{
"input": "21 1 5 8\n4",
"output": "Incorrect"
},
{
"input": "2 1 1 10\n9",
"output": "Incorrect"
},
{
"input": "2 1 4 8\n5",
"output": "Incorrect"
},
{
"input": "2 1 1 7\n6",
"output": "Incorrect"
},
{
"input": "2 1 4 9\n5",
"output": "Incorrect"
},
{
"input": "2 1 3 8\n7",
"output": "Incorrect"
},
{
"input": "2 1 5 9\n6",
"output": "Incorrect"
},
{
"input": "3 2 1 10\n4 9",
"output": "Incorrect"
},
{
"input": "2 1 4 10\n7",
"output": "Incorrect"
},
{
"input": "2 1 2 9\n8",
"output": "Incorrect"
},
{
"input": "2 1 3 9\n3",
"output": "Correct"
},
{
"input": "3 2 6 7\n6 6",
"output": "Correct"
},
{
"input": "6 4 1 10\n11 10 9 1",
"output": "Incorrect"
},
{
"input": "7 6 3 8\n3 4 5 6 7 8",
"output": "Correct"
},
{
"input": "5 3 1 5\n2 3 4",
"output": "Correct"
}
] | 1,401,294,961 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 77 | 0 | R = lambda:map(int, input().split())
n, m, a, b = R()
t = list(R())
print("Incorrect" if n - m == 1 and min(t) != a and max(t) != b else "Correct") | Title: Data Recovery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in *n* steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only *m*.
The next day, the engineer's assistant filed in a report with all the *m* temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers *n*, *m*, *min*, *max* and the list of *m* temperatures determine whether you can upgrade the set of *m* temperatures to the set of *n* temperatures (that is add *n*<=-<=*m* temperatures), so that the minimum temperature was *min* and the maximum one was *max*.
Input Specification:
The first line contains four integers *n*,<=*m*,<=*min*,<=*max* (1<=≤<=*m*<=<<=*n*<=≤<=100; 1<=≤<=*min*<=<<=*max*<=≤<=100). The second line contains *m* space-separated integers *t**i* (1<=≤<=*t**i*<=≤<=100) — the temperatures reported by the assistant.
Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures.
Output Specification:
If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes).
Demo Input:
['2 1 1 2\n1\n', '3 1 1 3\n2\n', '2 1 1 3\n2\n']
Demo Output:
['Correct\n', 'Correct\n', 'Incorrect\n']
Note:
In the first test sample one of the possible initial configurations of temperatures is [1, 2].
In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].
In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3. | ```python
R = lambda:map(int, input().split())
n, m, a, b = R()
t = list(R())
print("Incorrect" if n - m == 1 and min(t) != a and max(t) != b else "Correct")
``` | 0 |
|
30 | A | Accounting | PROGRAMMING | 1,400 | [
"brute force",
"math"
] | A. Accounting | 2 | 256 | A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year).
King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation:
Surely, the king is not going to do this job by himself, and demands you to find such number *X*.
It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative. | The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). | Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. | [
"2 18 2\n",
"-1 8 3\n",
"0 0 10\n",
"1 16 5\n"
] | [
"3",
"-2",
"5",
"No solution"
] | none | 500 | [
{
"input": "2 18 2",
"output": "3"
},
{
"input": "-1 8 3",
"output": "-2"
},
{
"input": "0 0 10",
"output": "5"
},
{
"input": "1 16 5",
"output": "No solution"
},
{
"input": "0 1 2",
"output": "No solution"
},
{
"input": "3 0 4",
"output": "0"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "4 972 1",
"output": "243"
},
{
"input": "-1 -1 5",
"output": "1"
},
{
"input": "-1 0 4",
"output": "0"
},
{
"input": "-7 0 1",
"output": "0"
},
{
"input": "-5 -5 3",
"output": "1"
},
{
"input": "-5 -5 9",
"output": "1"
},
{
"input": "-5 -5 6",
"output": "1"
},
{
"input": "-4 0 1",
"output": "0"
},
{
"input": "-5 0 3",
"output": "0"
},
{
"input": "-4 4 9",
"output": "-1"
},
{
"input": "10 0 6",
"output": "0"
},
{
"input": "-5 3 4",
"output": "No solution"
},
{
"input": "0 3 6",
"output": "No solution"
},
{
"input": "3 6 10",
"output": "No solution"
},
{
"input": "-3 7 5",
"output": "No solution"
},
{
"input": "-526 526 1",
"output": "-1"
},
{
"input": "-373 373 3",
"output": "-1"
},
{
"input": "-141 0 8",
"output": "0"
},
{
"input": "7 175 1",
"output": "25"
},
{
"input": "-5 -560 1",
"output": "112"
},
{
"input": "-1 -512 10",
"output": "No solution"
},
{
"input": "-3 -768 8",
"output": "2"
},
{
"input": "-3 -768 7",
"output": "No solution"
},
{
"input": "-3 -768 9",
"output": "No solution"
},
{
"input": "-3 -768 4",
"output": "4"
},
{
"input": "4 972 4",
"output": "No solution"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "4 972 6",
"output": "No solution"
},
{
"input": "4 972 1",
"output": "243"
},
{
"input": "4 972 2",
"output": "No solution"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "1 961 2",
"output": "31"
},
{
"input": "1 1000 3",
"output": "10"
},
{
"input": "1 625 4",
"output": "5"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "1 729 6",
"output": "3"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "3 768 8",
"output": "2"
},
{
"input": "1 512 9",
"output": "2"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "1 961 2",
"output": "31"
},
{
"input": "1 1000 3",
"output": "10"
},
{
"input": "1 625 4",
"output": "5"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "1 729 6",
"output": "3"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "3 768 8",
"output": "2"
},
{
"input": "1 512 9",
"output": "2"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "1 961 2",
"output": "31"
},
{
"input": "1 1000 3",
"output": "10"
},
{
"input": "1 625 4",
"output": "5"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "1 729 6",
"output": "3"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "3 768 8",
"output": "2"
},
{
"input": "1 512 9",
"output": "2"
},
{
"input": "1 1 5",
"output": "1"
},
{
"input": "1 1 4",
"output": "1"
},
{
"input": "1 -1 1",
"output": "-1"
}
] | 1,667,311,143 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 37 | 186 | 0 | import math
a,b,n=map(int,input().split())
if a==b==0:
print(5)
exit()
if a==0:
print('No solution')
exit()
if b%a!=0:
print('No solution')
exit()
b=b//a
if b<0 and n%2==0:
print('No solution')
exit()
negative=False
if b<0:
b=-b
negative=True
if math.pow(b,1/n)**n==b:
if negative:
print(-int(math.pow(b,1/n)))
else:
print(int(math.pow(b,1/n)))
exit()
else:
print('No solution')
exit() | Title: Accounting
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year).
King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation:
Surely, the king is not going to do this job by himself, and demands you to find such number *X*.
It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative.
Input Specification:
The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10).
Output Specification:
Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.
Demo Input:
['2 18 2\n', '-1 8 3\n', '0 0 10\n', '1 16 5\n']
Demo Output:
['3', '-2', '5', 'No solution']
Note:
none | ```python
import math
a,b,n=map(int,input().split())
if a==b==0:
print(5)
exit()
if a==0:
print('No solution')
exit()
if b%a!=0:
print('No solution')
exit()
b=b//a
if b<0 and n%2==0:
print('No solution')
exit()
negative=False
if b<0:
b=-b
negative=True
if math.pow(b,1/n)**n==b:
if negative:
print(-int(math.pow(b,1/n)))
else:
print(int(math.pow(b,1/n)))
exit()
else:
print('No solution')
exit()
``` | 0 |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot.
The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms. | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile. | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,699,453,088 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 77 | 2,355,200 | if __name__ == '__main__':
worm_count = int(input())
wih = input()
no_of_ew = int(input())
ew = input()
worms_in_holes = wih.split() # 2 7 3 4 9
eaten_worms = ew.split() # 1 25 11
output_list = []
len_wih = len(worms_in_holes)
for i in range(len(worms_in_holes)-1):
worms_in_holes[i] = int(worms_in_holes[i])
worms_in_holes[i] += int(worms_in_holes[i+1])
worms_in_holes[-1] = worms_in_holes[-2] + int(worms_in_holes[-1])
for i in range(no_of_ew):
j=0
if worms_in_holes[len_wih//4] > int(eaten_worms[i]):
while worms_in_holes[j] < int(eaten_worms[i]):
j+=1
output_list.append(j+1)
elif worms_in_holes[len_wih//2] > int(eaten_worms[i]):
while worms_in_holes[j+len_wih//4] < int(eaten_worms[i]):
j+=1
output_list.append(j+len_wih//4)
elif worms_in_holes[3*(len_wih//4)] > int(eaten_worms[i]):
while worms_in_holes[j+len_wih//2] < int(eaten_worms[i]):
j+=1
output_list.append(j+len_wih//2)
else:
try:
while worms_in_holes[j+3*(len_wih//4)] < int(eaten_worms[i]):
j+=1
output_list.append(j+3*(len_wih//4))
except:
output_list.append(j+3*(len_wih//4))
for i in range(no_of_ew):
print(output_list[i])
| Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot.
The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms.
Output Specification:
Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is.
Demo Input:
['5\n2 7 3 4 9\n3\n1 25 11\n']
Demo Output:
['1\n5\n3\n']
Note:
For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile. | ```python
if __name__ == '__main__':
worm_count = int(input())
wih = input()
no_of_ew = int(input())
ew = input()
worms_in_holes = wih.split() # 2 7 3 4 9
eaten_worms = ew.split() # 1 25 11
output_list = []
len_wih = len(worms_in_holes)
for i in range(len(worms_in_holes)-1):
worms_in_holes[i] = int(worms_in_holes[i])
worms_in_holes[i] += int(worms_in_holes[i+1])
worms_in_holes[-1] = worms_in_holes[-2] + int(worms_in_holes[-1])
for i in range(no_of_ew):
j=0
if worms_in_holes[len_wih//4] > int(eaten_worms[i]):
while worms_in_holes[j] < int(eaten_worms[i]):
j+=1
output_list.append(j+1)
elif worms_in_holes[len_wih//2] > int(eaten_worms[i]):
while worms_in_holes[j+len_wih//4] < int(eaten_worms[i]):
j+=1
output_list.append(j+len_wih//4)
elif worms_in_holes[3*(len_wih//4)] > int(eaten_worms[i]):
while worms_in_holes[j+len_wih//2] < int(eaten_worms[i]):
j+=1
output_list.append(j+len_wih//2)
else:
try:
while worms_in_holes[j+3*(len_wih//4)] < int(eaten_worms[i]):
j+=1
output_list.append(j+3*(len_wih//4))
except:
output_list.append(j+3*(len_wih//4))
for i in range(no_of_ew):
print(output_list[i])
``` | 0 |
|
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\n1 2 2 2 4 5 6 7 8 10",
"output": "376"
},
{
"input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002",
"output": "40204082"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "10\n10 8 7 6 5 4 2 2 2 1",
"output": "376"
},
{
"input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821",
"output": "40204082"
},
{
"input": "10\n5 2 6 10 10 10 10 2 2 5",
"output": "485"
},
{
"input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255",
"output": "36742665"
},
{
"input": "10\n2 2 2 5 5 6 10 10 10 10",
"output": "485"
},
{
"input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 6 5 5 2 2 2",
"output": "485"
},
{
"input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 10 10 10 10 10 10",
"output": "640"
},
{
"input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "64000000"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "2\n1 2",
"output": "6"
},
{
"input": "2\n2 3",
"output": "10"
},
{
"input": "2\n1 1",
"output": "4"
}
] | 1,512,547,642 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 11,776,000 | n=int(input())
line=input()
S=line.split()
L=[]
for num in S:
L.append(int(num))
s=0
if n==1:
print(line)
else:
while n>1:
k=L[0]
a=0
for i in range(0,n):
s=s+L[i]
if L[i]<k:
k=L[i]
a=i
s=s+L[a]
del L[a]
n=n-1
s=s+L[0]
print(s)
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Output Specification:
Print a single integer — the largest possible score.
Demo Input:
['3\n3 1 5\n', '1\n10\n']
Demo Output:
['26\n', '10\n']
Note:
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | ```python
n=int(input())
line=input()
S=line.split()
L=[]
for num in S:
L.append(int(num))
s=0
if n==1:
print(line)
else:
while n>1:
k=L[0]
a=0
for i in range(0,n):
s=s+L[i]
if L[i]<k:
k=L[i]
a=i
s=s+L[a]
del L[a]
n=n-1
s=s+L[0]
print(s)
``` | 0 |
|
670 | A | Holidays | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. | Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. | [
"14\n",
"2\n"
] | [
"4 4\n",
"0 2\n"
] | In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | 500 | [
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output": "1 2"
},
{
"input": "7",
"output": "2 2"
},
{
"input": "8",
"output": "2 3"
},
{
"input": "9",
"output": "2 4"
},
{
"input": "10",
"output": "2 4"
},
{
"input": "11",
"output": "2 4"
},
{
"input": "12",
"output": "2 4"
},
{
"input": "13",
"output": "3 4"
},
{
"input": "1000000",
"output": "285714 285715"
},
{
"input": "16",
"output": "4 6"
},
{
"input": "17",
"output": "4 6"
},
{
"input": "18",
"output": "4 6"
},
{
"input": "19",
"output": "4 6"
},
{
"input": "20",
"output": "5 6"
},
{
"input": "21",
"output": "6 6"
},
{
"input": "22",
"output": "6 7"
},
{
"input": "23",
"output": "6 8"
},
{
"input": "24",
"output": "6 8"
},
{
"input": "25",
"output": "6 8"
},
{
"input": "26",
"output": "6 8"
},
{
"input": "27",
"output": "7 8"
},
{
"input": "28",
"output": "8 8"
},
{
"input": "29",
"output": "8 9"
},
{
"input": "30",
"output": "8 10"
},
{
"input": "100",
"output": "28 30"
},
{
"input": "99",
"output": "28 29"
},
{
"input": "98",
"output": "28 28"
},
{
"input": "97",
"output": "27 28"
},
{
"input": "96",
"output": "26 28"
},
{
"input": "95",
"output": "26 28"
},
{
"input": "94",
"output": "26 28"
},
{
"input": "93",
"output": "26 28"
},
{
"input": "92",
"output": "26 27"
},
{
"input": "91",
"output": "26 26"
},
{
"input": "90",
"output": "25 26"
},
{
"input": "89",
"output": "24 26"
},
{
"input": "88",
"output": "24 26"
},
{
"input": "87",
"output": "24 26"
},
{
"input": "86",
"output": "24 26"
},
{
"input": "85",
"output": "24 25"
},
{
"input": "84",
"output": "24 24"
},
{
"input": "83",
"output": "23 24"
},
{
"input": "82",
"output": "22 24"
},
{
"input": "81",
"output": "22 24"
},
{
"input": "80",
"output": "22 24"
},
{
"input": "1000",
"output": "285 286"
},
{
"input": "999",
"output": "284 286"
},
{
"input": "998",
"output": "284 286"
},
{
"input": "997",
"output": "284 286"
},
{
"input": "996",
"output": "284 286"
},
{
"input": "995",
"output": "284 285"
},
{
"input": "994",
"output": "284 284"
},
{
"input": "993",
"output": "283 284"
},
{
"input": "992",
"output": "282 284"
},
{
"input": "991",
"output": "282 284"
},
{
"input": "990",
"output": "282 284"
},
{
"input": "989",
"output": "282 284"
},
{
"input": "988",
"output": "282 283"
},
{
"input": "987",
"output": "282 282"
},
{
"input": "986",
"output": "281 282"
},
{
"input": "985",
"output": "280 282"
},
{
"input": "984",
"output": "280 282"
},
{
"input": "983",
"output": "280 282"
},
{
"input": "982",
"output": "280 282"
},
{
"input": "981",
"output": "280 281"
},
{
"input": "980",
"output": "280 280"
},
{
"input": "10000",
"output": "2856 2858"
},
{
"input": "9999",
"output": "2856 2858"
},
{
"input": "9998",
"output": "2856 2858"
},
{
"input": "9997",
"output": "2856 2857"
},
{
"input": "9996",
"output": "2856 2856"
},
{
"input": "9995",
"output": "2855 2856"
},
{
"input": "9994",
"output": "2854 2856"
},
{
"input": "9993",
"output": "2854 2856"
},
{
"input": "9992",
"output": "2854 2856"
},
{
"input": "9991",
"output": "2854 2856"
},
{
"input": "9990",
"output": "2854 2855"
},
{
"input": "9989",
"output": "2854 2854"
},
{
"input": "9988",
"output": "2853 2854"
},
{
"input": "9987",
"output": "2852 2854"
},
{
"input": "9986",
"output": "2852 2854"
},
{
"input": "9985",
"output": "2852 2854"
},
{
"input": "9984",
"output": "2852 2854"
},
{
"input": "9983",
"output": "2852 2853"
},
{
"input": "9982",
"output": "2852 2852"
},
{
"input": "9981",
"output": "2851 2852"
},
{
"input": "9980",
"output": "2850 2852"
},
{
"input": "100000",
"output": "28570 28572"
},
{
"input": "99999",
"output": "28570 28572"
},
{
"input": "99998",
"output": "28570 28572"
},
{
"input": "99997",
"output": "28570 28572"
},
{
"input": "99996",
"output": "28570 28571"
},
{
"input": "99995",
"output": "28570 28570"
},
{
"input": "99994",
"output": "28569 28570"
},
{
"input": "99993",
"output": "28568 28570"
},
{
"input": "99992",
"output": "28568 28570"
},
{
"input": "99991",
"output": "28568 28570"
},
{
"input": "99990",
"output": "28568 28570"
},
{
"input": "99989",
"output": "28568 28569"
},
{
"input": "99988",
"output": "28568 28568"
},
{
"input": "99987",
"output": "28567 28568"
},
{
"input": "99986",
"output": "28566 28568"
},
{
"input": "99985",
"output": "28566 28568"
},
{
"input": "99984",
"output": "28566 28568"
},
{
"input": "99983",
"output": "28566 28568"
},
{
"input": "99982",
"output": "28566 28567"
},
{
"input": "99981",
"output": "28566 28566"
},
{
"input": "99980",
"output": "28565 28566"
},
{
"input": "999999",
"output": "285714 285714"
},
{
"input": "999998",
"output": "285713 285714"
},
{
"input": "999997",
"output": "285712 285714"
},
{
"input": "999996",
"output": "285712 285714"
},
{
"input": "999995",
"output": "285712 285714"
},
{
"input": "999994",
"output": "285712 285714"
},
{
"input": "999993",
"output": "285712 285713"
},
{
"input": "999992",
"output": "285712 285712"
},
{
"input": "999991",
"output": "285711 285712"
},
{
"input": "999990",
"output": "285710 285712"
},
{
"input": "999989",
"output": "285710 285712"
},
{
"input": "999988",
"output": "285710 285712"
},
{
"input": "999987",
"output": "285710 285712"
},
{
"input": "999986",
"output": "285710 285711"
},
{
"input": "999985",
"output": "285710 285710"
},
{
"input": "999984",
"output": "285709 285710"
},
{
"input": "999983",
"output": "285708 285710"
},
{
"input": "999982",
"output": "285708 285710"
},
{
"input": "999981",
"output": "285708 285710"
},
{
"input": "999980",
"output": "285708 285710"
},
{
"input": "234123",
"output": "66892 66893"
},
{
"input": "234122",
"output": "66892 66892"
},
{
"input": "234121",
"output": "66891 66892"
},
{
"input": "234120",
"output": "66890 66892"
},
{
"input": "234119",
"output": "66890 66892"
},
{
"input": "234118",
"output": "66890 66892"
},
{
"input": "234117",
"output": "66890 66892"
},
{
"input": "234116",
"output": "66890 66891"
},
{
"input": "234115",
"output": "66890 66890"
},
{
"input": "234114",
"output": "66889 66890"
},
{
"input": "234113",
"output": "66888 66890"
},
{
"input": "234112",
"output": "66888 66890"
},
{
"input": "234111",
"output": "66888 66890"
},
{
"input": "234110",
"output": "66888 66890"
},
{
"input": "234109",
"output": "66888 66889"
},
{
"input": "234108",
"output": "66888 66888"
},
{
"input": "234107",
"output": "66887 66888"
},
{
"input": "234106",
"output": "66886 66888"
},
{
"input": "234105",
"output": "66886 66888"
},
{
"input": "234104",
"output": "66886 66888"
},
{
"input": "234103",
"output": "66886 66888"
},
{
"input": "868531",
"output": "248151 248152"
},
{
"input": "868530",
"output": "248150 248152"
},
{
"input": "868529",
"output": "248150 248152"
},
{
"input": "868528",
"output": "248150 248152"
},
{
"input": "868527",
"output": "248150 248152"
},
{
"input": "868526",
"output": "248150 248151"
},
{
"input": "868525",
"output": "248150 248150"
},
{
"input": "868524",
"output": "248149 248150"
},
{
"input": "868523",
"output": "248148 248150"
},
{
"input": "868522",
"output": "248148 248150"
},
{
"input": "868521",
"output": "248148 248150"
},
{
"input": "868520",
"output": "248148 248150"
},
{
"input": "868519",
"output": "248148 248149"
},
{
"input": "868518",
"output": "248148 248148"
},
{
"input": "868517",
"output": "248147 248148"
},
{
"input": "868516",
"output": "248146 248148"
},
{
"input": "868515",
"output": "248146 248148"
},
{
"input": "868514",
"output": "248146 248148"
},
{
"input": "868513",
"output": "248146 248148"
},
{
"input": "868512",
"output": "248146 248147"
},
{
"input": "868511",
"output": "248146 248146"
},
{
"input": "123413",
"output": "35260 35262"
},
{
"input": "123412",
"output": "35260 35262"
},
{
"input": "123411",
"output": "35260 35261"
},
{
"input": "123410",
"output": "35260 35260"
},
{
"input": "123409",
"output": "35259 35260"
},
{
"input": "123408",
"output": "35258 35260"
},
{
"input": "123407",
"output": "35258 35260"
},
{
"input": "123406",
"output": "35258 35260"
},
{
"input": "123405",
"output": "35258 35260"
},
{
"input": "123404",
"output": "35258 35259"
},
{
"input": "123403",
"output": "35258 35258"
},
{
"input": "123402",
"output": "35257 35258"
},
{
"input": "123401",
"output": "35256 35258"
},
{
"input": "123400",
"output": "35256 35258"
},
{
"input": "123399",
"output": "35256 35258"
},
{
"input": "123398",
"output": "35256 35258"
},
{
"input": "123397",
"output": "35256 35257"
},
{
"input": "123396",
"output": "35256 35256"
},
{
"input": "123395",
"output": "35255 35256"
},
{
"input": "123394",
"output": "35254 35256"
},
{
"input": "123393",
"output": "35254 35256"
},
{
"input": "15",
"output": "4 5"
}
] | 1,652,042,462 | 2,147,483,647 | Python 3 | OK | TESTS | 198 | 46 | 0 | w,e=divmod(int(input()),7)
print(w*2+int(e==6),w*2+min(e,2))
| Title: Holidays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars.
Output Specification:
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
Demo Input:
['14\n', '2\n']
Demo Output:
['4 4\n', '0 2\n']
Note:
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | ```python
w,e=divmod(int(input()),7)
print(w*2+int(e==6),w*2+min(e,2))
``` | 3 |
|
908 | E | New Year and Entity Enumeration | PROGRAMMING | 2,500 | [
"bitmasks",
"combinatorics",
"dp",
"math"
] | null | null | You are given an integer *m*.
Let *M*<==<=2*m*<=-<=1.
You are also given a set of *n* integers denoted as the set *T*. The integers will be provided in base 2 as *n* binary strings of length *m*.
A set of integers *S* is called "good" if the following hold.
1. If , then . 1. If , then 1. 1. All elements of *S* are less than or equal to *M*.
Here, and refer to the bitwise XOR and bitwise AND operators, respectively.
Count the number of good sets *S*, modulo 109<=+<=7. | The first line will contain two integers *m* and *n* (1<=≤<=*m*<=≤<=1<=000, 1<=≤<=*n*<=≤<=*min*(2*m*,<=50)).
The next *n* lines will contain the elements of *T*. Each line will contain exactly *m* zeros and ones. Elements of *T* will be distinct. | Print a single integer, the number of good sets modulo 109<=+<=7. | [
"5 3\n11010\n00101\n11000\n",
"30 2\n010101010101010010101010101010\n110110110110110011011011011011\n"
] | [
"4\n",
"860616440\n"
] | An example of a valid set *S* is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}. | 1,750 | [
{
"input": "5 3\n11010\n00101\n11000",
"output": "4"
},
{
"input": "30 2\n010101010101010010101010101010\n110110110110110011011011011011",
"output": "860616440"
},
{
"input": "30 10\n001000000011000111000010010000\n000001100001010000000000000100\n000110100010100000000000101000\n110000010000000001000000000000\n100001000000000010010101000101\n001001000000000100000000110000\n000000010000100000001000000000\n001000010001000000001000000010\n000000110000000001001010000000\n000011001000000000010001000000",
"output": "80"
}
] | 1,618,558,920 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 608 | 13,107,200 | from collections import defaultdict
def E1():
mod = 10 ** 9 + 7
comb = [[1]]
for i in range(1, 1010):
x = [1]
for j in range(1, i):
x.append((comb[i - 1][j - 1] + comb[i - 1][j]) % mod)
x.append(1)
comb.append(x)
dp = [1]
for i in range(1, 1010):
r = 0
for k in range(i):
r += dp[k] * comb[i - 1][k]
r %= mod
dp.append(r)
m, n = map(int, input().split())
ns = [0 for __ in range(m)]
for j in range(n):
temp = input()
s = [int(i) for i in temp]
for i in range(m):
ns[i] |= s[i] << j
dd = defaultdict(int)
for e in ns:
dd[e] += 1
ans = 1
for b in dd.values():
ans = ans * dp[b] % mod
print(ans)
if __name__=='__main__':
E1()
| Title: New Year and Entity Enumeration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an integer *m*.
Let *M*<==<=2*m*<=-<=1.
You are also given a set of *n* integers denoted as the set *T*. The integers will be provided in base 2 as *n* binary strings of length *m*.
A set of integers *S* is called "good" if the following hold.
1. If , then . 1. If , then 1. 1. All elements of *S* are less than or equal to *M*.
Here, and refer to the bitwise XOR and bitwise AND operators, respectively.
Count the number of good sets *S*, modulo 109<=+<=7.
Input Specification:
The first line will contain two integers *m* and *n* (1<=≤<=*m*<=≤<=1<=000, 1<=≤<=*n*<=≤<=*min*(2*m*,<=50)).
The next *n* lines will contain the elements of *T*. Each line will contain exactly *m* zeros and ones. Elements of *T* will be distinct.
Output Specification:
Print a single integer, the number of good sets modulo 109<=+<=7.
Demo Input:
['5 3\n11010\n00101\n11000\n', '30 2\n010101010101010010101010101010\n110110110110110011011011011011\n']
Demo Output:
['4\n', '860616440\n']
Note:
An example of a valid set *S* is {00000, 00101, 00010, 00111, 11000, 11010, 11101, 11111}. | ```python
from collections import defaultdict
def E1():
mod = 10 ** 9 + 7
comb = [[1]]
for i in range(1, 1010):
x = [1]
for j in range(1, i):
x.append((comb[i - 1][j - 1] + comb[i - 1][j]) % mod)
x.append(1)
comb.append(x)
dp = [1]
for i in range(1, 1010):
r = 0
for k in range(i):
r += dp[k] * comb[i - 1][k]
r %= mod
dp.append(r)
m, n = map(int, input().split())
ns = [0 for __ in range(m)]
for j in range(n):
temp = input()
s = [int(i) for i in temp]
for i in range(m):
ns[i] |= s[i] << j
dd = defaultdict(int)
for e in ns:
dd[e] += 1
ans = 1
for b in dd.values():
ans = ans * dp[b] % mod
print(ans)
if __name__=='__main__':
E1()
``` | 3 |
|
916 | A | Jamie and Alarm Snooze | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.
A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky.
Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*.
Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'.
Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00. | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60).
The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59). | Print the minimum number of times he needs to press the button. | [
"3\n11 23\n",
"5\n01 07\n"
] | [
"2\n",
"0\n"
] | In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. | 500 | [
{
"input": "3\n11 23",
"output": "2"
},
{
"input": "5\n01 07",
"output": "0"
},
{
"input": "34\n09 24",
"output": "3"
},
{
"input": "2\n14 37",
"output": "0"
},
{
"input": "14\n19 54",
"output": "9"
},
{
"input": "42\n15 44",
"output": "12"
},
{
"input": "46\n02 43",
"output": "1"
},
{
"input": "14\n06 41",
"output": "1"
},
{
"input": "26\n04 58",
"output": "26"
},
{
"input": "54\n16 47",
"output": "0"
},
{
"input": "38\n20 01",
"output": "3"
},
{
"input": "11\n02 05",
"output": "8"
},
{
"input": "55\n22 10",
"output": "5"
},
{
"input": "23\n10 08",
"output": "6"
},
{
"input": "23\n23 14",
"output": "9"
},
{
"input": "51\n03 27",
"output": "0"
},
{
"input": "35\n15 25",
"output": "13"
},
{
"input": "3\n12 15",
"output": "6"
},
{
"input": "47\n00 28",
"output": "3"
},
{
"input": "31\n13 34",
"output": "7"
},
{
"input": "59\n17 32",
"output": "0"
},
{
"input": "25\n11 03",
"output": "8"
},
{
"input": "9\n16 53",
"output": "4"
},
{
"input": "53\n04 06",
"output": "3"
},
{
"input": "37\n00 12",
"output": "5"
},
{
"input": "5\n13 10",
"output": "63"
},
{
"input": "50\n01 59",
"output": "10"
},
{
"input": "34\n06 13",
"output": "4"
},
{
"input": "2\n18 19",
"output": "1"
},
{
"input": "46\n06 16",
"output": "17"
},
{
"input": "14\n03 30",
"output": "41"
},
{
"input": "40\n13 37",
"output": "0"
},
{
"input": "24\n17 51",
"output": "0"
},
{
"input": "8\n14 57",
"output": "0"
},
{
"input": "52\n18 54",
"output": "2"
},
{
"input": "20\n15 52",
"output": "24"
},
{
"input": "20\n03 58",
"output": "30"
},
{
"input": "48\n07 11",
"output": "0"
},
{
"input": "32\n04 01",
"output": "2"
},
{
"input": "60\n08 15",
"output": "1"
},
{
"input": "44\n20 20",
"output": "4"
},
{
"input": "55\n15 35",
"output": "9"
},
{
"input": "55\n03 49",
"output": "11"
},
{
"input": "23\n16 39",
"output": "4"
},
{
"input": "7\n20 36",
"output": "7"
},
{
"input": "35\n16 42",
"output": "1"
},
{
"input": "35\n05 56",
"output": "21"
},
{
"input": "3\n17 45",
"output": "0"
},
{
"input": "47\n05 59",
"output": "6"
},
{
"input": "15\n10 13",
"output": "9"
},
{
"input": "59\n06 18",
"output": "9"
},
{
"input": "34\n17 18",
"output": "0"
},
{
"input": "18\n05 23",
"output": "2"
},
{
"input": "46\n17 21",
"output": "0"
},
{
"input": "30\n06 27",
"output": "0"
},
{
"input": "14\n18 40",
"output": "3"
},
{
"input": "58\n22 54",
"output": "6"
},
{
"input": "26\n19 44",
"output": "5"
},
{
"input": "10\n15 57",
"output": "0"
},
{
"input": "54\n20 47",
"output": "0"
},
{
"input": "22\n08 45",
"output": "3"
},
{
"input": "48\n18 08",
"output": "1"
},
{
"input": "32\n07 06",
"output": "0"
},
{
"input": "60\n19 19",
"output": "2"
},
{
"input": "45\n07 25",
"output": "0"
},
{
"input": "29\n12 39",
"output": "8"
},
{
"input": "13\n08 28",
"output": "3"
},
{
"input": "41\n21 42",
"output": "5"
},
{
"input": "41\n09 32",
"output": "3"
},
{
"input": "9\n21 45",
"output": "2"
},
{
"input": "37\n10 43",
"output": "5"
},
{
"input": "3\n20 50",
"output": "1"
},
{
"input": "47\n00 04",
"output": "1"
},
{
"input": "15\n13 10",
"output": "21"
},
{
"input": "15\n17 23",
"output": "0"
},
{
"input": "43\n22 13",
"output": "2"
},
{
"input": "27\n10 26",
"output": "6"
},
{
"input": "55\n22 24",
"output": "5"
},
{
"input": "55\n03 30",
"output": "11"
},
{
"input": "24\n23 27",
"output": "0"
},
{
"input": "52\n11 33",
"output": "3"
},
{
"input": "18\n22 48",
"output": "17"
},
{
"input": "1\n12 55",
"output": "8"
},
{
"input": "1\n04 27",
"output": "0"
},
{
"input": "1\n12 52",
"output": "5"
},
{
"input": "1\n20 16",
"output": "9"
},
{
"input": "1\n04 41",
"output": "4"
},
{
"input": "1\n20 21",
"output": "4"
},
{
"input": "1\n04 45",
"output": "8"
},
{
"input": "1\n12 18",
"output": "1"
},
{
"input": "1\n04 42",
"output": "5"
},
{
"input": "1\n02 59",
"output": "2"
},
{
"input": "1\n18 24",
"output": "7"
},
{
"input": "1\n02 04",
"output": "7"
},
{
"input": "1\n18 28",
"output": "1"
},
{
"input": "1\n18 01",
"output": "2"
},
{
"input": "1\n10 25",
"output": "8"
},
{
"input": "1\n02 49",
"output": "2"
},
{
"input": "1\n02 30",
"output": "3"
},
{
"input": "1\n18 54",
"output": "7"
},
{
"input": "1\n02 19",
"output": "2"
},
{
"input": "1\n05 25",
"output": "8"
},
{
"input": "60\n23 55",
"output": "6"
},
{
"input": "60\n08 19",
"output": "1"
},
{
"input": "60\n00 00",
"output": "7"
},
{
"input": "60\n08 24",
"output": "1"
},
{
"input": "60\n16 13",
"output": "9"
},
{
"input": "60\n08 21",
"output": "1"
},
{
"input": "60\n16 45",
"output": "9"
},
{
"input": "60\n08 26",
"output": "1"
},
{
"input": "60\n08 50",
"output": "1"
},
{
"input": "60\n05 21",
"output": "12"
},
{
"input": "60\n13 29",
"output": "6"
},
{
"input": "60\n05 18",
"output": "12"
},
{
"input": "60\n13 42",
"output": "6"
},
{
"input": "60\n05 07",
"output": "0"
},
{
"input": "60\n05 47",
"output": "0"
},
{
"input": "60\n21 55",
"output": "4"
},
{
"input": "60\n05 36",
"output": "12"
},
{
"input": "60\n21 08",
"output": "4"
},
{
"input": "60\n21 32",
"output": "4"
},
{
"input": "60\n16 31",
"output": "9"
},
{
"input": "5\n00 00",
"output": "73"
},
{
"input": "2\n06 58",
"output": "390"
},
{
"input": "60\n00 00",
"output": "7"
},
{
"input": "2\n00 00",
"output": "181"
},
{
"input": "10\n00 00",
"output": "37"
},
{
"input": "60\n01 00",
"output": "8"
},
{
"input": "12\n00 06",
"output": "31"
},
{
"input": "1\n00 01",
"output": "4"
},
{
"input": "5\n00 05",
"output": "74"
},
{
"input": "60\n01 01",
"output": "8"
},
{
"input": "11\n18 11",
"output": "2"
},
{
"input": "60\n01 15",
"output": "8"
},
{
"input": "10\n00 16",
"output": "38"
},
{
"input": "60\n00 59",
"output": "7"
},
{
"input": "30\n00 00",
"output": "13"
},
{
"input": "60\n01 05",
"output": "8"
},
{
"input": "4\n00 03",
"output": "4"
},
{
"input": "4\n00 00",
"output": "91"
},
{
"input": "60\n00 01",
"output": "7"
},
{
"input": "6\n00 03",
"output": "1"
},
{
"input": "13\n00 00",
"output": "1"
},
{
"input": "1\n18 01",
"output": "2"
},
{
"input": "5\n06 00",
"output": "145"
},
{
"input": "60\n04 08",
"output": "11"
},
{
"input": "5\n01 55",
"output": "96"
},
{
"input": "8\n00 08",
"output": "47"
},
{
"input": "23\n18 23",
"output": "2"
},
{
"input": "6\n00 06",
"output": "62"
},
{
"input": "59\n18 59",
"output": "2"
},
{
"input": "11\n00 10",
"output": "3"
},
{
"input": "10\n00 01",
"output": "37"
},
{
"input": "59\n00 00",
"output": "7"
},
{
"input": "10\n18 10",
"output": "2"
},
{
"input": "5\n00 01",
"output": "73"
},
{
"input": "1\n00 00",
"output": "3"
},
{
"input": "8\n00 14",
"output": "47"
},
{
"input": "60\n03 00",
"output": "10"
},
{
"input": "60\n00 10",
"output": "7"
},
{
"input": "5\n01 13",
"output": "87"
},
{
"input": "30\n02 43",
"output": "18"
},
{
"input": "17\n00 08",
"output": "3"
},
{
"input": "3\n00 00",
"output": "1"
},
{
"input": "60\n00 05",
"output": "7"
},
{
"input": "5\n18 05",
"output": "2"
},
{
"input": "30\n00 30",
"output": "14"
},
{
"input": "1\n00 06",
"output": "9"
},
{
"input": "55\n00 00",
"output": "7"
},
{
"input": "8\n02 08",
"output": "62"
},
{
"input": "7\n00 00",
"output": "9"
},
{
"input": "6\n08 06",
"output": "2"
},
{
"input": "48\n06 24",
"output": "16"
},
{
"input": "8\n06 58",
"output": "98"
},
{
"input": "3\n12 00",
"output": "1"
},
{
"input": "5\n01 06",
"output": "86"
},
{
"input": "2\n00 08",
"output": "185"
},
{
"input": "3\n18 03",
"output": "2"
},
{
"input": "1\n17 00",
"output": "0"
},
{
"input": "59\n00 48",
"output": "7"
},
{
"input": "5\n12 01",
"output": "49"
},
{
"input": "55\n01 25",
"output": "9"
},
{
"input": "2\n07 23",
"output": "0"
},
{
"input": "10\n01 10",
"output": "44"
},
{
"input": "2\n00 01",
"output": "2"
},
{
"input": "59\n00 01",
"output": "6"
},
{
"input": "5\n00 02",
"output": "1"
},
{
"input": "4\n01 02",
"output": "106"
},
{
"input": "5\n00 06",
"output": "74"
},
{
"input": "42\n00 08",
"output": "9"
},
{
"input": "60\n01 20",
"output": "8"
},
{
"input": "3\n06 00",
"output": "1"
},
{
"input": "4\n00 01",
"output": "1"
},
{
"input": "2\n00 06",
"output": "184"
},
{
"input": "1\n00 57",
"output": "0"
},
{
"input": "6\n00 00",
"output": "61"
},
{
"input": "5\n08 40",
"output": "9"
},
{
"input": "58\n00 55",
"output": "1"
},
{
"input": "2\n00 02",
"output": "182"
},
{
"input": "1\n08 01",
"output": "2"
},
{
"input": "10\n10 10",
"output": "14"
},
{
"input": "60\n01 11",
"output": "8"
},
{
"input": "2\n07 00",
"output": "0"
},
{
"input": "15\n00 03",
"output": "25"
},
{
"input": "6\n04 34",
"output": "106"
},
{
"input": "16\n00 16",
"output": "24"
},
{
"input": "2\n00 59",
"output": "1"
},
{
"input": "59\n00 08",
"output": "7"
},
{
"input": "10\n03 10",
"output": "56"
},
{
"input": "3\n08 03",
"output": "2"
},
{
"input": "20\n06 11",
"output": "37"
},
{
"input": "4\n01 00",
"output": "106"
},
{
"input": "38\n01 08",
"output": "12"
},
{
"input": "60\n00 06",
"output": "7"
},
{
"input": "5\n12 00",
"output": "49"
},
{
"input": "6\n01 42",
"output": "78"
},
{
"input": "4\n00 04",
"output": "92"
},
{
"input": "60\n04 05",
"output": "11"
},
{
"input": "1\n00 53",
"output": "6"
},
{
"input": "5\n08 05",
"output": "2"
},
{
"input": "60\n18 45",
"output": "1"
},
{
"input": "60\n06 23",
"output": "13"
},
{
"input": "6\n00 15",
"output": "3"
},
{
"input": "58\n00 06",
"output": "7"
},
{
"input": "2\n06 44",
"output": "383"
},
{
"input": "1\n08 00",
"output": "1"
},
{
"input": "10\n06 58",
"output": "78"
},
{
"input": "59\n00 58",
"output": "8"
},
{
"input": "1\n18 00",
"output": "1"
},
{
"input": "50\n00 42",
"output": "9"
},
{
"input": "30\n18 30",
"output": "2"
},
{
"input": "60\n21 59",
"output": "4"
},
{
"input": "2\n10 52",
"output": "87"
},
{
"input": "56\n00 00",
"output": "7"
},
{
"input": "16\n18 16",
"output": "2"
},
{
"input": "5\n01 05",
"output": "86"
},
{
"input": "5\n05 00",
"output": "133"
},
{
"input": "5\n23 59",
"output": "72"
},
{
"input": "7\n17 13",
"output": "0"
},
{
"input": "58\n00 00",
"output": "7"
},
{
"input": "15\n00 07",
"output": "0"
},
{
"input": "59\n08 00",
"output": "1"
},
{
"input": "46\n00 00",
"output": "8"
},
{
"input": "59\n01 05",
"output": "2"
},
{
"input": "2\n01 00",
"output": "211"
},
{
"input": "60\n00 24",
"output": "7"
},
{
"input": "10\n00 08",
"output": "37"
},
{
"input": "10\n00 06",
"output": "37"
},
{
"input": "60\n01 24",
"output": "8"
},
{
"input": "50\n00 10",
"output": "8"
},
{
"input": "2\n03 00",
"output": "271"
},
{
"input": "4\n19 04",
"output": "17"
},
{
"input": "25\n00 23",
"output": "16"
},
{
"input": "10\n01 01",
"output": "43"
}
] | 1,516,373,236 | 736 | PyPy 3 | WRONG_ANSWER | PRETESTS | 2 | 93 | 19,968,000 | x = int(input())
h, m = list(map(int, input().split()))
y = int()
while (not str(h+m*100).count('7')):
m -= x
if (m < 0):
h -= 1
m = 60 - m
if (h < 0):
h = 24 - h
y += 1
print(y) | Title: Jamie and Alarm Snooze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.
A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky.
Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*.
Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'.
Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00.
Input Specification:
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60).
The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59).
Output Specification:
Print the minimum number of times he needs to press the button.
Demo Input:
['3\n11 23\n', '5\n01 07\n']
Demo Output:
['2\n', '0\n']
Note:
In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. | ```python
x = int(input())
h, m = list(map(int, input().split()))
y = int()
while (not str(h+m*100).count('7')):
m -= x
if (m < 0):
h -= 1
m = 60 - m
if (h < 0):
h = 24 - h
y += 1
print(y)
``` | 0 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,611,058,235 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | st=input()
for i in st:
if(ord(i)>=65 and ord(i)<=90):
u=u+1
else:
l=l+1
if(u>l):
print(st.upper())
else:
print(st.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
st=input()
for i in st:
if(ord(i)>=65 and ord(i)<=90):
u=u+1
else:
l=l+1
if(u>l):
print(st.upper())
else:
print(st.lower())
``` | -1 |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"output": "8"
},
{
"input": "31",
"output": "3"
},
{
"input": "59",
"output": "8"
},
{
"input": "79",
"output": "9"
},
{
"input": "7",
"output": "3"
},
{
"input": "55",
"output": "4"
},
{
"input": "40",
"output": "2"
},
{
"input": "719",
"output": "13"
},
{
"input": "847",
"output": "13"
},
{
"input": "225",
"output": "4"
},
{
"input": "4704",
"output": "51"
},
{
"input": "1132",
"output": "15"
},
{
"input": "7811",
"output": "80"
},
{
"input": "7981",
"output": "84"
},
{
"input": "82655",
"output": "830"
},
{
"input": "6364",
"output": "70"
},
{
"input": "74611",
"output": "748"
},
{
"input": "45391",
"output": "459"
},
{
"input": "620448",
"output": "6210"
},
{
"input": "265145",
"output": "2654"
},
{
"input": "671704",
"output": "6721"
},
{
"input": "365173",
"output": "3658"
},
{
"input": "7130872",
"output": "71314"
},
{
"input": "9628747",
"output": "96292"
},
{
"input": "8898399",
"output": "88993"
},
{
"input": "9497953",
"output": "94985"
},
{
"input": "19070947",
"output": "190714"
},
{
"input": "20185520",
"output": "201856"
},
{
"input": "91402248",
"output": "914028"
},
{
"input": "27035533",
"output": "270360"
},
{
"input": "22717528",
"output": "227180"
},
{
"input": "24403439",
"output": "244041"
},
{
"input": "163565555",
"output": "1635659"
},
{
"input": "152541908",
"output": "1525423"
},
{
"input": "668439837",
"output": "6684403"
},
{
"input": "20",
"output": "1"
},
{
"input": "999999999",
"output": "10000009"
},
{
"input": "10",
"output": "1"
},
{
"input": "7",
"output": "3"
},
{
"input": "6",
"output": "2"
},
{
"input": "99999999",
"output": "1000009"
},
{
"input": "1000001",
"output": "10001"
},
{
"input": "2521",
"output": "27"
}
] | 1,694,802,039 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | schet = int(input())
# schet = 1000000000
dollars = 0
Banknotes = [100,20,10,5,1]
for i in Banknotes:
dollars += schet // i
schet=schet%i
print(dollars) | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
Input Specification:
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output Specification:
Output the minimum number of bills that Allen could receive.
Demo Input:
['125\n', '43\n', '1000000000\n']
Demo Output:
['3\n', '5\n', '10000000\n']
Note:
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | ```python
schet = int(input())
# schet = 1000000000
dollars = 0
Banknotes = [100,20,10,5,1]
for i in Banknotes:
dollars += schet // i
schet=schet%i
print(dollars)
``` | 3 |
|
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman.
Given the description of Appleman's cards. What is the maximum number of coins Toastman can get? | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer – the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output": "2"
},
{
"input": "5 1\nFACJT",
"output": "1"
},
{
"input": "5 5\nMJDIJ",
"output": "7"
},
{
"input": "15 5\nAZBIPTOFTJCJJIK",
"output": "13"
},
{
"input": "100 1\nEVEEVEEEGGECFEHEFVFVFHVHEEEEEFCVEEEEEEVFVEEVEEHEEVEFEVVEFEEEFEVECEHGHEEFGEEVCEECCECEFHEVEEEEEEGEEHVH",
"output": "1"
},
{
"input": "100 15\nKKTFFUTFCKUIKKKKFIFFKTUKUUKUKKIKKKTIFKTKUCFFKKKIIKKKKKKTFKFKKIRKKKFKUUKIKUUUFFKKKKTUZKITUIKKIKUKKTIK",
"output": "225"
},
{
"input": "100 50\nYYIYYAAAIEAAYAYAEAIIIAAEAAYEAEYYYIAEYAYAYYAAAIAYAEAAYAYYIYAAYYAAAAAAIYYYAAYAAEAAYAIEIYIYAYAYAYIIAAEY",
"output": "1972"
},
{
"input": "100 90\nFAFAOOAOOAFAOTFAFAFFATAAAOFAAOAFBAAAFBOAOFFFOAOAFAPFOFAOFAAFOAAAAFAAFOFAAOFPPAAOOAAOOFFOFFFOFAOTOFAF",
"output": "2828"
},
{
"input": "100 99\nBFFBBFBFBQFFFFFQBFFBFFBQFBFQFBBFQFFFBFFFBFQFQFBFFBBFYQFBFFFFFFFBQQFQBFBQBQFFFBQQFFFBQFYFBFBFFFBBBQQY",
"output": "3713"
},
{
"input": "100 100\nMQSBDAJABILIBCUEOWGWCEXMUTEYQKAIWGINXVQEOFDUBSVULROQHQRZZAALVQFEFRAAAYUIMGCAFQGIAEFBETRECGSFQJNXHHDN",
"output": "514"
},
{
"input": "100 50\nBMYIXQSJNHGFVFPJBIOBXIKSFNUFPVODCUBQYSIIQNVNXXCWXWRHKFEUPPIIDDGRDBJLZDCBMNJMYRMWFIHOSTDJJHXHPNRKWNFD",
"output": "328"
},
{
"input": "100 50\nENFNEMLJEMDMFMNNGNIMNINALGLLLAEMENEMNLMMIEIJNAINBJEJMFJLLIMINELGFLAIAMJMHMGNLIEFJIEEFEFGLLLDLMEAEIMM",
"output": "748"
}
] | 1,617,196,546 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 77 | 0 | import operator
n, k = map(int, input().split())
s = input()
d = {}
for i in s:
d[i] = d.get(i, 0) + 1
l = []
for i, v in sorted(d.items()):
l.extend([i]*v)
c = 0
z = l[:k]
for i in set(z):
c += z.count(i)**2
print(c)
| Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman.
Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman.
Output Specification:
Print a single integer – the answer to the problem.
Demo Input:
['15 10\nDZFDFZDFDDDDDDF\n', '6 4\nYJSNPI\n']
Demo Output:
['82\n', '4\n']
Note:
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | ```python
import operator
n, k = map(int, input().split())
s = input()
d = {}
for i in s:
d[i] = d.get(i, 0) + 1
l = []
for i, v in sorted(d.items()):
l.extend([i]*v)
c = 0
z = l[:k]
for i in set(z):
c += z.count(i)**2
print(c)
``` | 0 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,689,783,573 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | # Read the input numbers
n, m, a = map(int, input().split())
# Calculate the number of flagstones required for the length of the square
length_flagstones = n // a
if n % a != 0:
length_flagstones += 1
# Calculate the number of flagstones required for the width of the square
width_flagstones = m // a
if m % a != 0:
width_flagstones += 1
# Calculate the total number of flagstones needed
total_flagstones = length_flagstones * width_flagstones
# Print the total number of flagstones
print(total_flagstones)
| 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
# Read the input numbers
n, m, a = map(int, input().split())
# Calculate the number of flagstones required for the length of the square
length_flagstones = n // a
if n % a != 0:
length_flagstones += 1
# Calculate the number of flagstones required for the width of the square
width_flagstones = m // a
if m % a != 0:
width_flagstones += 1
# Calculate the total number of flagstones needed
total_flagstones = length_flagstones * width_flagstones
# Print the total number of flagstones
print(total_flagstones)
``` | 3.977 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,628,459,357 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 154 | 6,963,200 | n= int(input())
a = input().split()
for i in range(n):
a[i] = int(a[i])
x1 = 0
x0 = 0
if a[0]%2==0:
x0+=1
else:
x1+=1
if a[1]%2==0:
x0+=1
else:
x1+=1
if a[2]%2==0:
x0+=1
else:
x1+=1
if x0>=2:
for i in range(n):
if a[i]%2==1:
print(i+1)
break
else:
for i in range(n):
if a[i] % 2 == 0:
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 = input().split()
for i in range(n):
a[i] = int(a[i])
x1 = 0
x0 = 0
if a[0]%2==0:
x0+=1
else:
x1+=1
if a[1]%2==0:
x0+=1
else:
x1+=1
if a[2]%2==0:
x0+=1
else:
x1+=1
if x0>=2:
for i in range(n):
if a[i]%2==1:
print(i+1)
break
else:
for i in range(n):
if a[i] % 2 == 0:
print(i + 1)
break
``` | 3.94853 |
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3",
"output": "0\n0\n1\n1\n0"
},
{
"input": "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5",
"output": "2\n1\n1\n1\n1\n1\n1"
},
{
"input": "#..#\n1\n1 4",
"output": "1"
},
{
"input": "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4",
"output": "2\n2\n3\n2\n1\n4\n0"
},
{
"input": "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3",
"output": "0\n0\n0\n0\n0\n0\n0"
},
{
"input": "###..#...#\n2\n2 4\n1 2",
"output": "1\n1"
},
{
"input": "..\n1\n1 2",
"output": "1"
},
{
"input": "##\n1\n1 2",
"output": "1"
},
{
"input": ".#\n1\n1 2",
"output": "0"
},
{
"input": "#.\n1\n1 2",
"output": "0"
},
{
"input": "...\n2\n1 2\n1 2",
"output": "1\n1"
}
] | 1,687,979,671 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | def solve(n, m):
return m-n
s = input()
t = int(input())
while t:
n, m = map(int, input().split())
print(solve(n, m))
t-=1 | Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
Input Specification:
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the answers to the queries in the order in which they are given in the input.
Demo Input:
['......\n4\n3 4\n2 3\n1 6\n2 6\n', '#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n']
Demo Output:
['1\n1\n5\n4\n', '1\n1\n2\n2\n0\n']
Note:
none | ```python
def solve(n, m):
return m-n
s = input()
t = int(input())
while t:
n, m = map(int, input().split())
print(solve(n, m))
t-=1
``` | 0 |
|
891 | A | Pride | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"math",
"number theory"
] | null | null | You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
What is the minimum number of operations you need to make all of the elements equal to 1? | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=2000) — the number of elements in the array.
The second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array. | Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1. | [
"5\n2 2 3 4 6\n",
"4\n2 4 6 8\n",
"3\n2 6 9\n"
] | [
"5\n",
"-1\n",
"4\n"
] | In the first sample you can turn all numbers to 1 using the following 5 moves:
- [2, 2, 3, 4, 6]. - [2, 1, 3, 4, 6] - [2, 1, 3, 1, 6] - [2, 1, 1, 1, 6] - [1, 1, 1, 1, 6] - [1, 1, 1, 1, 1]
We can prove that in this case it is not possible to make all numbers one using less than 5 moves. | 500 | [
{
"input": "5\n2 2 3 4 6",
"output": "5"
},
{
"input": "4\n2 4 6 8",
"output": "-1"
},
{
"input": "3\n2 6 9",
"output": "4"
},
{
"input": "15\n10 10 10 10 10 10 21 21 21 21 21 21 21 21 21",
"output": "15"
},
{
"input": "12\n10 10 14 14 14 14 14 14 14 14 21 21",
"output": "20"
},
{
"input": "5\n10 10 14 21 21",
"output": "6"
},
{
"input": "9\n10 10 10 10 10 14 14 21 21",
"output": "11"
},
{
"input": "9\n10 10 10 10 10 10 10 10 21",
"output": "9"
},
{
"input": "13\n10 10 10 15 15 15 15 15 15 15 15 21 21",
"output": "21"
},
{
"input": "15\n10 10 10 10 10 10 10 10 10 10 10 10 15 15 21",
"output": "17"
},
{
"input": "4\n1 1 1 1",
"output": "0"
},
{
"input": "1\n3",
"output": "-1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n1000000000 1000000000",
"output": "-1"
},
{
"input": "1\n1000000000",
"output": "-1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n42 15 35",
"output": "4"
},
{
"input": "3\n6 10 15",
"output": "4"
},
{
"input": "4\n2 1 1 1",
"output": "1"
},
{
"input": "5\n2 1 1 1 2",
"output": "2"
},
{
"input": "3\n30 14 21",
"output": "4"
},
{
"input": "3\n15 6 10",
"output": "4"
},
{
"input": "4\n1 1 1 2",
"output": "1"
},
{
"input": "5\n1 1 1 2 2",
"output": "2"
},
{
"input": "4\n2 6 9 1",
"output": "3"
},
{
"input": "6\n2 3 4 1 1 1",
"output": "3"
},
{
"input": "15\n2 6 6 6 3 3 3 15 5 5 5 7 5 5 5",
"output": "15"
},
{
"input": "5\n2 3 2 6 9",
"output": "5"
},
{
"input": "6\n6 15 10 6 15 10",
"output": "7"
}
] | 1,605,794,334 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 1,740,800 | n = int(input())
a = list(map(int,input().split()))
def computeGCD(x, y):
while(y):
x, y = y, x % y
return x
gcd = []
for i in range(n-1):
gcd.append(computeGCD(a[i],a[i+1]))
z = len(set(gcd))
if z==1:
print(-1)
elif (1 in gcd):
print(n)
elif z==2:
print(n+1)
else:
counters = []
temp_count = 1
for i in range(1,len(gcd)):
if gcd[i]!=gcd[i-1]:
counters.append(temp_count)
temp_count = 1
else:
temp_count +=1
counters.append(temp_count)
print(min(counters[1::2])+n+1) | Title: Pride
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* with length *n*, you can perform operations. Each operation is like this: choose two adjacent elements from *a*, say *x* and *y*, and replace one of them with *gcd*(*x*,<=*y*), where *gcd* denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor).
What is the minimum number of operations you need to make all of the elements equal to 1?
Input Specification:
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=2000) — the number of elements in the array.
The second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
Output Specification:
Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1.
Demo Input:
['5\n2 2 3 4 6\n', '4\n2 4 6 8\n', '3\n2 6 9\n']
Demo Output:
['5\n', '-1\n', '4\n']
Note:
In the first sample you can turn all numbers to 1 using the following 5 moves:
- [2, 2, 3, 4, 6]. - [2, 1, 3, 4, 6] - [2, 1, 3, 1, 6] - [2, 1, 1, 1, 6] - [1, 1, 1, 1, 6] - [1, 1, 1, 1, 1]
We can prove that in this case it is not possible to make all numbers one using less than 5 moves. | ```python
n = int(input())
a = list(map(int,input().split()))
def computeGCD(x, y):
while(y):
x, y = y, x % y
return x
gcd = []
for i in range(n-1):
gcd.append(computeGCD(a[i],a[i+1]))
z = len(set(gcd))
if z==1:
print(-1)
elif (1 in gcd):
print(n)
elif z==2:
print(n+1)
else:
counters = []
temp_count = 1
for i in range(1,len(gcd)):
if gcd[i]!=gcd[i-1]:
counters.append(temp_count)
temp_count = 1
else:
temp_count +=1
counters.append(temp_count)
print(min(counters[1::2])+n+1)
``` | 0 |
|
448 | B | Suffix Structures | PROGRAMMING | 1,400 | [
"implementation",
"strings"
] | null | null | Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order. | The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters. | In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton. | [
"automaton\ntomat\n",
"array\narary\n",
"both\nhot\n",
"need\ntree\n"
] | [
"automaton\n",
"array\n",
"both\n",
"need tree\n"
] | In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot". | 1,000 | [
{
"input": "automaton\ntomat",
"output": "automaton"
},
{
"input": "array\narary",
"output": "array"
},
{
"input": "both\nhot",
"output": "both"
},
{
"input": "need\ntree",
"output": "need tree"
},
{
"input": "abacaba\naaaa",
"output": "automaton"
},
{
"input": "z\nzz",
"output": "need tree"
},
{
"input": "itwtyhhsdjjffmmoqkkhxjouypznewstyorotxhozlytndehmaxogrohccnqcgkrjrdmnuaogiwmnmsbdaizqkxnkqxxiihbwepc\nsnixfywvcntitcefsgqxjcodwtumurcglfmnamnowzbjzmfzspbfuldraiepeeiyasmrsneekydsbvazoqszyjxkjiotushsddet",
"output": "need tree"
},
{
"input": "y\nu",
"output": "need tree"
},
{
"input": "nbjigpsbammkuuqrxfnmhtimwpflrflehffykbylmnxgadldchdbqklqbremcmzlpxieozgpfgrhegmdcxxfyehzzelcwgkierrj\nbjbakuqrnhimwhffykylmngadhbqkqbrcziefredxxezcgkerj",
"output": "automaton"
},
{
"input": "gzvvawianfysfuxhruarhverinqsbrfxvkcsermuzowahevgskmpvfdljtcztnbkzftfhvnarvkfkqjgrzbrcfthqmspvpqcva\nwnm",
"output": "automaton"
},
{
"input": "dvzohfzgzdjavqwhjcrdphpdqjwtqijabbrhformstqaonlhbglmxugkwviigqaohwvqfhdwwcvdkjrcgxblhvtashhcxssbvpo\nzgvqhpjhforlugkwfwrchvhp",
"output": "automaton"
},
{
"input": "wkfoyetcjivofxaktmauapzeuhcpzjloszzxwydgavebgniiuzrscytsokjkjfkpylvxtlqlquzduywbhqdzmtwprfdohmwgmysy\ny",
"output": "automaton"
},
{
"input": "npeidcoiulxdxzjozsonkdwnoazsbntfclnpubgweaynuhfmrtybqtkuihxxfhwlnquslnhzvqznyofzcbdewnrisqzdhsiyhkxf\nnpeidcoiulxdxzjozsonkdwnoazsbntfclnpubgeaynuhfmrtybqtkuihxxfhwlnquslnhzvqznyofzcbdewnrisqzdhsiyhkxf",
"output": "automaton"
},
{
"input": "gahcqpgmypeahjcwkzahnhmsmxosnikucqwyzklbfwtujjlzvwklqzxakcrcqalhsvsgvknpxsoqkjnyjkypfsiogbcaxjyugeet\ngahcqpgmypeahjwwkzahnhmsmxopnikucacyzklbfwtujjlzvwkoqzxakcrcqqlhsvsgvknpxslgkjnyjkysfoisqbcaxjyuteeg",
"output": "array"
},
{
"input": "vwesbxsifsjqapwridrenumrukgemlldpbtdhxivsrmzbgprtkqgaryniudkjgpjndluwxuohwwysmyuxyrulwsodgunzirudgtx\nugeabdszfshqsksddireguvsukieqlluhngdpxjvwwnzdrtrtrdjiuxgadtgjpxrmlynspyyryngxuiibrmurwpmoxwwuklbwumo",
"output": "array"
},
{
"input": "kjnohlseyntrslfssrshjxclzlsbkfzfwwwgyxsysvmfkxugdwjodfyxhdsveruoioutwmtcbaljomaorvzjsbmglqckmsyieeiu\netihhycsjgdysowuljmaoksoecxawsgsljofkrjftuweidrkwtymyswdlilsozsxevfbformnbsumlxzqzykjvsnrlxufvgbmshc",
"output": "array"
},
{
"input": "ezbpsylkfztypqrefinexshtgglmkoinrktkloitqhfkivoabrfrivvqrcxkjckzvcozpchhiodrbbxuhnwcjigftnrjfiqyxakh\niacxghqffzdbsiqunhxbiooqvfohzticjpvrzykcrlrxklgknyrkrhjxcetmfocierekatfvkbslkkrbhftwngoijpipvqyznthi",
"output": "array"
},
{
"input": "smywwqeolrsytkthfgacnbufzaulgszikbhluzcdbafjclkqueepxbhoamrwswxherzhhuqqcttokbljfbppdinzqgdupkfevmke\nsmywwqeolrsytkthfgacnbufzaulgszikbhluzcdbafjclkqueepxbhoamrwswxherzhhufqcttokbljfbppdinzqgdupkqevmke",
"output": "array"
},
{
"input": "hxsvvydmzhxrswvhkvrbjrfqkazbkjabnrdghposgyfeslzumaovfkallszzumztftgpcilwfrzpvhhbgdzdvnmseqywlzmhhoxh\ndbelhtzgkssyfrqgzuurdjhwvmdbhylhmvphjgxpzhxbb",
"output": "both"
},
{
"input": "nppjzscfgcvdcnsjtiaudvutmgswqbewejlzibczzowgkdrjgxrpirfdaekvngcsonroheepdoeoeevaullbfwprcnhlxextbxpd\nifilrvacohnwcgzuleicucebrfxphosrgwnglxxkqrcorsxegjoppbb",
"output": "both"
},
{
"input": "ggzmtrhkpdswwqgcbtviahqrgzhyhzddtdekchrpjgngupitzyyuipwstgzewktcqpwezidwvvxgjixnflpjhfznokmpbyzczrzk\ngpgwhtzrcytstezmhettkppgmvxlxqnkjzibiqdtceczkbfhdziuajwjqzgwnhnkdzizprgzwud",
"output": "both"
},
{
"input": "iypjqiiqxhtinlmywpetgqqsdopxhghthjopgbodkwrdxzaaxmtaqcfuiarhrvasusanklzcqaytdyzndakcpljqupowompjjved\nhxeatriypptbhnokarhgqdrkqkypqzdttixphngmpqjodzjqlmcztyjfgoswjelwwdaqdjayavsdocuhqsluxaaopniviaumxip",
"output": "both"
},
{
"input": "ypyhyabmljukejpltkgunwuanhxblhiouyltdiczttndrhdprqtlpfanmzlyzbqanfwfyurxhepuzspdvehxnblhajczqcxlqebx\nlladxuucky",
"output": "both"
},
{
"input": "ddmgoarkuhknbtjggnomyxvvavobmylixwuxnnsdrrbibitoteaiydptnvtfblathihflefuggfnyayniragbtkommycpdyhft\ntejwybmyrhmalraptqwhghsckvnnaagtmzhnpwbhzzgfgritqwqqamgssllnicjqdkivrwaqyxngsqopwieljfxcdywjaal",
"output": "need tree"
},
{
"input": "kipjuscf\nkbwfqfwuvkyhmvnaznzsgdgdnpipikbicmlcwehjirmhgwpxwpgfztqjwfqfaapmsgskr",
"output": "need tree"
},
{
"input": "kobhhrqgwbgqkzcoacrhpkegyepzfds\nhlwcgbvvlegoyrcrjhsjywpdnccxtzgmeujxciuwjlnefllwldidlnjswmetkarxqjigokfvmpxpzfxarhkpdcia",
"output": "need tree"
},
{
"input": "lllolloloolllloolollololololollllooololoooloooolololloolloollllolloolloooooooololllolllolllloolllool\nlollollololololooooloooooooooolloolllololooollllol",
"output": "automaton"
},
{
"input": "lloloooolooollololloooloololooollooloollolllloolllllllloollollllolooloollloololollllooloooololooolol\nlooooollooolllololloollooooololollollloloollollolo",
"output": "both"
},
{
"input": "yyyyxxxxyxyyxxxyxxyxxxyyxxxxxyyxxxyxxyxxyyyxxxyxxxyxyxyyxyyxyxxyyyxyxxyxxyxxyyxyyyyxyyyyxxxyyxyxxyyx\nyyyyxxxxyxyyxxxyxxyxxxyyxxxxxyyxxxyxxyxxyyyxxxyxxxxxyxyyxyyxyxxyyyxyxxyxxyxxyyxyyyyxyyyyxxxyyxyxxyyx",
"output": "need tree"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "automaton"
},
{
"input": "abracadabra\nlol",
"output": "need tree"
},
{
"input": "abc\naa",
"output": "need tree"
},
{
"input": "ba\naa",
"output": "need tree"
},
{
"input": "abbb\naaab",
"output": "need tree"
},
{
"input": "baaa\nbb",
"output": "need tree"
},
{
"input": "boosss\nosos",
"output": "both"
}
] | 1,667,597,786 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | def automaton(palavra, alvo):
index = palavra.find(alvo)
if index == -1:
return False
else:
return True
def array(palavra, alvo):
if len(palavra) != len(alvo):
return False
nPalavra = {}
for w in palavra:
if w not in nPalavra:
nPalavra[w] = 1
else:
nPalavra[w] += 1
nAlvo = {}
for w in alvo:
if w not in nAlvo:
nAlvo[w] = 1
else:
nAlvo[w] += 1
if nAlvo == nPalavra:
return True
return False
def both(palavra, alvo):
aux = list(palavra)
alvoSet = set(alvo)
for w in palavra:
if w not in alvoSet:
while w in aux:
aux.remove(w)
if array(''.join(aux), alvo):
return True
return False
# s -> t
palavra = input()
alvo = input()
if automaton(palavra, alvo):
print("automaton")
elif array(palavra, alvo):
print("array")
elif both(palavra, alvo):
print("both")
else:
print("need tree")
| Title: Suffix Structures
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.
Input Specification:
The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.
Output Specification:
In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.
Demo Input:
['automaton\ntomat\n', 'array\narary\n', 'both\nhot\n', 'need\ntree\n']
Demo Output:
['automaton\n', 'array\n', 'both\n', 'need tree\n']
Note:
In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot". | ```python
def automaton(palavra, alvo):
index = palavra.find(alvo)
if index == -1:
return False
else:
return True
def array(palavra, alvo):
if len(palavra) != len(alvo):
return False
nPalavra = {}
for w in palavra:
if w not in nPalavra:
nPalavra[w] = 1
else:
nPalavra[w] += 1
nAlvo = {}
for w in alvo:
if w not in nAlvo:
nAlvo[w] = 1
else:
nAlvo[w] += 1
if nAlvo == nPalavra:
return True
return False
def both(palavra, alvo):
aux = list(palavra)
alvoSet = set(alvo)
for w in palavra:
if w not in alvoSet:
while w in aux:
aux.remove(w)
if array(''.join(aux), alvo):
return True
return False
# s -> t
palavra = input()
alvo = input()
if automaton(palavra, alvo):
print("automaton")
elif array(palavra, alvo):
print("array")
elif both(palavra, alvo):
print("both")
else:
print("need tree")
``` | 0 |
|
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
"output": "9"
},
{
"input": "10\n10 5 8 9 5 6 8 7 2 8",
"output": "46"
},
{
"input": "10\n1 1 1 1 1 1 2 3 4 4",
"output": "14"
},
{
"input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4",
"output": "296"
},
{
"input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2",
"output": "313"
},
{
"input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9",
"output": "298"
},
{
"input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5",
"output": "312"
},
{
"input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2",
"output": "287"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2",
"output": "265"
},
{
"input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9",
"output": "328"
},
{
"input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9",
"output": "324"
},
{
"input": "10\n7 4 5 3 9 1 10 3 4 5",
"output": "34"
},
{
"input": "10\n8 9 6 5 6 4 10 9 1 4",
"output": "39"
},
{
"input": "10\n1 7 1 4 9 10 8 2 9 9",
"output": "40"
},
{
"input": "1\n100000",
"output": "100000"
}
] | 1,674,078,705 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 171 | 7,372,800 | n = int(input())
vals = list(map(int, input().split(" ")))
occu = [0 for _ in range(max(vals) + 1)]
l = [0 for _ in range(max(vals) + 1)]
for x in vals:
occu[x] += 1
give = []
l[1] = occu[1]
for i in range(2, len(occu)):
l[i] = max(l[i-2] + i * occu[i],l[i-1])
print(l[-1]) | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print a single integer — the maximum number of points that Alex can earn.
Demo Input:
['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n']
Demo Output:
['2\n', '4\n', '10\n']
Note:
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | ```python
n = int(input())
vals = list(map(int, input().split(" ")))
occu = [0 for _ in range(max(vals) + 1)]
l = [0 for _ in range(max(vals) + 1)]
for x in vals:
occu[x] += 1
give = []
l[1] = occu[1]
for i in range(2, len(occu)):
l[i] = max(l[i-2] + i * occu[i],l[i-1])
print(l[-1])
``` | 3 |
|
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "534204",
"output": "106841"
},
{
"input": "469569",
"output": "93914"
},
{
"input": "502877",
"output": "100576"
},
{
"input": "942212",
"output": "188443"
},
{
"input": "97",
"output": "20"
},
{
"input": "53",
"output": "11"
},
{
"input": "89",
"output": "18"
},
{
"input": "574",
"output": "115"
},
{
"input": "716",
"output": "144"
},
{
"input": "729",
"output": "146"
},
{
"input": "8901",
"output": "1781"
},
{
"input": "3645",
"output": "729"
},
{
"input": "4426",
"output": "886"
},
{
"input": "46573",
"output": "9315"
},
{
"input": "86380",
"output": "17276"
},
{
"input": "94190",
"output": "18838"
},
{
"input": "999990",
"output": "199998"
},
{
"input": "999991",
"output": "199999"
},
{
"input": "999992",
"output": "199999"
},
{
"input": "999993",
"output": "199999"
},
{
"input": "999994",
"output": "199999"
},
{
"input": "999995",
"output": "199999"
},
{
"input": "999996",
"output": "200000"
},
{
"input": "999997",
"output": "200000"
},
{
"input": "999998",
"output": "200000"
}
] | 1,695,748,002 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 5,632,000 | x = int(input("Enter the coordinate of the friend's house: "))
steps = x // 5
if x % 5 != 0:
steps += 1
print("The minimum number of steps needed:", steps)
| Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
Input Specification:
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Output Specification:
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
Demo Input:
['5\n', '12\n']
Demo Output:
['1\n', '3\n']
Note:
In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | ```python
x = int(input("Enter the coordinate of the friend's house: "))
steps = x // 5
if x % 5 != 0:
steps += 1
print("The minimum number of steps needed:", steps)
``` | 0 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,626,779,921 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 6,758,400 | a=input()
b=input()
s=str(int(a)+int(b))
print('0'*(len(a)-len(s))+s.replace('2','0')) | 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
a=input()
b=input()
s=str(int(a)+int(b))
print('0'*(len(a)-len(s))+s.replace('2','0'))
``` | 3.968161 |
131 | B | Opposites Attract | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the *i*-th client number *t**i* (<=-<=10<=≤<=*t**i*<=≤<=10). Of course, one number can be assigned to any number of customers.
"Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of *t*. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence *t*1,<=*t*2,<=...,<=*t**n*. For example, if *t*<==<=(1,<=<=-<=1,<=1,<=<=-<=1), then any two elements *t**i* and *t**j* form a couple if *i* and *j* have different parity. Consequently, in this case the sought number equals 4.
Of course, a client can't form a couple with him/herself. | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=10<=≤<=*t**i*<=≤<=10), *t**i* — is the parameter of the *i*-th customer that has been assigned to the customer by the result of the analysis of his interests. | Print the number of couples of customs with opposite *t*. The opposite number for *x* is number <=-<=*x* (0 is opposite to itself). Couples that only differ in the clients' order are considered the same.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. | [
"5\n-3 3 0 0 3\n",
"3\n0 0 0\n"
] | [
"3\n",
"3\n"
] | In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
In the second sample any couple of clients is opposite. | 1,000 | [
{
"input": "5\n-3 3 0 0 3",
"output": "3"
},
{
"input": "3\n0 0 0",
"output": "3"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "2\n-3 3",
"output": "1"
},
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "4\n1 -1 1 -1",
"output": "4"
},
{
"input": "10\n1 -1 2 -2 3 -3 4 -4 0 0",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"output": "10"
},
{
"input": "4\n4 4 4 -1",
"output": "0"
},
{
"input": "2\n10 -10",
"output": "1"
},
{
"input": "2\n-10 10",
"output": "1"
},
{
"input": "3\n-1 -1 2",
"output": "0"
},
{
"input": "2\n-1 2",
"output": "0"
},
{
"input": "7\n0 10 -10 10 -10 10 10",
"output": "8"
},
{
"input": "5\n-3 2 1 -1 3",
"output": "2"
},
{
"input": "4\n-10 10 -10 10",
"output": "4"
},
{
"input": "4\n1 -1 2 -2",
"output": "2"
}
] | 1,697,369,008 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | import collections
import math
sums = lambda n: int(n * (n + 1) / 2) # sum from 1 to n
sumsqur = lambda n: int( (n) * (n + 1) * (2*n +1)/6) # sum square from 1 to n
def im(): return map(int, input().split())
def il(): return list(map(int, input().split()))
def ii(): return int(input())
# "abcdefghijklmnopqrstuvwxyz"
def isPalindrom(a):
return True if a[::-1] == a else False
def solve():
n=ii()
s=il()
a=[0]*11
b=[0]*11
for i in s:
if i>=0:
a[i]+=1
else:
b[-i]+=1
count=a[0]
for i in range(1,11):
count+=min(a[i],b[i])
return count
if __name__ == '__main__':
#for i in range(ii()):
print(solve())
| Title: Opposites Attract
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the *i*-th client number *t**i* (<=-<=10<=≤<=*t**i*<=≤<=10). Of course, one number can be assigned to any number of customers.
"Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of *t*. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence *t*1,<=*t*2,<=...,<=*t**n*. For example, if *t*<==<=(1,<=<=-<=1,<=1,<=<=-<=1), then any two elements *t**i* and *t**j* form a couple if *i* and *j* have different parity. Consequently, in this case the sought number equals 4.
Of course, a client can't form a couple with him/herself.
Input Specification:
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=10<=≤<=*t**i*<=≤<=10), *t**i* — is the parameter of the *i*-th customer that has been assigned to the customer by the result of the analysis of his interests.
Output Specification:
Print the number of couples of customs with opposite *t*. The opposite number for *x* is number <=-<=*x* (0 is opposite to itself). Couples that only differ in the clients' order are considered the same.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Demo Input:
['5\n-3 3 0 0 3\n', '3\n0 0 0\n']
Demo Output:
['3\n', '3\n']
Note:
In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
In the second sample any couple of clients is opposite. | ```python
import collections
import math
sums = lambda n: int(n * (n + 1) / 2) # sum from 1 to n
sumsqur = lambda n: int( (n) * (n + 1) * (2*n +1)/6) # sum square from 1 to n
def im(): return map(int, input().split())
def il(): return list(map(int, input().split()))
def ii(): return int(input())
# "abcdefghijklmnopqrstuvwxyz"
def isPalindrom(a):
return True if a[::-1] == a else False
def solve():
n=ii()
s=il()
a=[0]*11
b=[0]*11
for i in s:
if i>=0:
a[i]+=1
else:
b[-i]+=1
count=a[0]
for i in range(1,11):
count+=min(a[i],b[i])
return count
if __name__ == '__main__':
#for i in range(ii()):
print(solve())
``` | 0 |
|
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,656,705,353 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 92 | 0 |
t = int(input())
for _ in range(t):
angle = int(input())
i = 3
while True:
total = (i - 2)*180
in_angle = total/i
if in_angle > angle:
print('NO')
break
elif angle == in_angle:
print('YES')
break
i += 1
| Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
Input Specification:
The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees.
Output Specification:
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
Demo Input:
['3\n30\n60\n90\n']
Demo Output:
['NO\nYES\nYES\n']
Note:
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | ```python
t = int(input())
for _ in range(t):
angle = int(input())
i = 3
while True:
total = (i - 2)*180
in_angle = total/i
if in_angle > angle:
print('NO')
break
elif angle == in_angle:
print('YES')
break
i += 1
``` | 3 |
|
1,007 | A | Reorder the Array | PROGRAMMING | 1,300 | [
"combinatorics",
"data structures",
"math",
"sortings",
"two pointers"
] | null | null | You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20>10$, $40>20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case.
Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal. | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array. | Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array. | [
"7\n10 1 1 1 5 5 3\n",
"5\n1 1 1 1 1\n"
] | [
"4\n",
"0\n"
] | In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0. | 500 | [
{
"input": "7\n10 1 1 1 5 5 3",
"output": "4"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000",
"output": "3"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "7\n3 5 2 2 5 2 4",
"output": "4"
},
{
"input": "5\n1 5 4 2 3",
"output": "4"
}
] | 1,685,153,920 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 93 | 15,564,800 | from collections import Counter
n=int(input())
p=list(map(int, input().split(' ')))
s=Counter(p)
y=[s[i] for i in s]
y.sort()
y=[0]+y
m=len(y)
ans=0
tem=0
for i in range (0,m):
if y[i]>tem:
ans=ans+(m-i-1)*(y[i]-tem)
tem=y[i]
print(ans)
| Title: Reorder the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20>10$, $40>20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case.
Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.
Input Specification:
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array.
Output Specification:
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
Demo Input:
['7\n10 1 1 1 5 5 3\n', '5\n1 1 1 1 1\n']
Demo Output:
['4\n', '0\n']
Note:
In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0. | ```python
from collections import Counter
n=int(input())
p=list(map(int, input().split(' ')))
s=Counter(p)
y=[s[i] for i in s]
y.sort()
y=[0]+y
m=len(y)
ans=0
tem=0
for i in range (0,m):
if y[i]>tem:
ans=ans+(m-i-1)*(y[i]-tem)
tem=y[i]
print(ans)
``` | 3 |
|
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "YES"
},
{
"input": "48\nthereisasyetinsufficientdataforameaningfulanswer",
"output": "NO"
},
{
"input": "30\nToBeOrNotToBeThatIsTheQuestion",
"output": "NO"
},
{
"input": "30\njackdawslovemybigsphinxofquarz",
"output": "NO"
},
{
"input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY",
"output": "YES"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx",
"output": "YES"
},
{
"input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ",
"output": "YES"
},
{
"input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ",
"output": "YES"
},
{
"input": "25\nnxYTzLFwzNolAumjgcAboyxAj",
"output": "NO"
},
{
"input": "26\npRWdodGdxUESvcScPGbUoooZsC",
"output": "NO"
},
{
"input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj",
"output": "NO"
},
{
"input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa",
"output": "YES"
},
{
"input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK",
"output": "NO"
},
{
"input": "26\nvCUFRKElZOnjmXGylWQaHDiPst",
"output": "NO"
},
{
"input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY",
"output": "NO"
},
{
"input": "26\npGiFluRteQwkaVoPszJyNBChxM",
"output": "NO"
},
{
"input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY",
"output": "NO"
},
{
"input": "26\nLndjgvAEuICHKxPwqYztosrmBN",
"output": "NO"
},
{
"input": "26\nMdaXJrCipnOZLykfqHWEStevbU",
"output": "NO"
},
{
"input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba",
"output": "NO"
},
{
"input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo",
"output": "NO"
},
{
"input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa",
"output": "NO"
},
{
"input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO",
"output": "NO"
},
{
"input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe",
"output": "NO"
},
{
"input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG",
"output": "NO"
},
{
"input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF",
"output": "NO"
},
{
"input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu",
"output": "NO"
},
{
"input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf",
"output": "NO"
},
{
"input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE",
"output": "NO"
},
{
"input": "26\nDqspXZJTuONYieKgaHLMBwfVSC",
"output": "NO"
},
{
"input": "26\necOyUkqNljFHRVXtIpWabGMLDz",
"output": "NO"
},
{
"input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI",
"output": "NO"
},
{
"input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA",
"output": "NO"
},
{
"input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz",
"output": "NO"
},
{
"input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ",
"output": "NO"
},
{
"input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF",
"output": "NO"
},
{
"input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB",
"output": "NO"
},
{
"input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg",
"output": "NO"
},
{
"input": "26\nmnbvcxxlkjhgfdsapoiuytrewq",
"output": "NO"
},
{
"input": "26\naAbcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl",
"output": "NO"
},
{
"input": "25\nabcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "26\nabcdefhijklmnopqrstVxyzABC",
"output": "NO"
},
{
"input": "25\nqwertyuiopasdfghjklxcvbnm",
"output": "NO"
},
{
"input": "34\nTheQuickBrownFoxJumpsOverTheLayDog",
"output": "NO"
},
{
"input": "26\nabcdefghigklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyA",
"output": "NO"
},
{
"input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog",
"output": "NO"
},
{
"input": "25\nbcdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa",
"output": "NO"
},
{
"input": "26\nabcdefghiklmnopqrstvxyzABC",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxzZ",
"output": "NO"
},
{
"input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "NO"
}
] | 1,699,184,512 | 2,147,483,647 | PyPy 3 | OK | TESTS | 59 | 93 | 0 | str = "abcdefghijklmnopqrstuvwxyz"
list = list(str)
dicList = []
freq = {}
# input goes here ->str input
n = int(input())
s = input().lower()
for char in s:
if char in freq:
freq[char] += 1
#print(freq)
else:
freq[char] = 1
#print(freq)
for key in freq.keys():
dicList.append(key)
if sorted(list) == sorted(dicList):
print("YES")
else:
print("NO")
| Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output Specification:
Output "YES", if the string is a pangram and "NO" otherwise.
Demo Input:
['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
str = "abcdefghijklmnopqrstuvwxyz"
list = list(str)
dicList = []
freq = {}
# input goes here ->str input
n = int(input())
s = input().lower()
for char in s:
if char in freq:
freq[char] += 1
#print(freq)
else:
freq[char] = 1
#print(freq)
for key in freq.keys():
dicList.append(key)
if sorted(list) == sorted(dicList):
print("YES")
else:
print("NO")
``` | 3 |
|
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist. | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50",
"output": "49"
},
{
"input": "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2",
"output": "-1"
},
{
"input": "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90",
"output": "46"
},
{
"input": "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66",
"output": "14"
},
{
"input": "1 1\n4\n9",
"output": "8"
},
{
"input": "1 1\n2\n4",
"output": "-1"
},
{
"input": "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58",
"output": "-1"
},
{
"input": "1 1\n50\n100",
"output": "-1"
},
{
"input": "1 1\n49\n100",
"output": "98"
},
{
"input": "1 1\n100\n100",
"output": "-1"
},
{
"input": "1 1\n99\n100",
"output": "-1"
},
{
"input": "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100",
"output": "99"
},
{
"input": "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2",
"output": "-1"
},
{
"input": "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75",
"output": "2"
},
{
"input": "3 3\n2 3 4\n8 9 10",
"output": "4"
},
{
"input": "2 1\n2 3\n15",
"output": "4"
},
{
"input": "2 1\n2 4\n4",
"output": "-1"
},
{
"input": "2 3\n4 5\n10 11 12",
"output": "8"
},
{
"input": "3 1\n2 3 3\n5",
"output": "4"
},
{
"input": "2 1\n9 10\n100",
"output": "18"
},
{
"input": "3 3\n3 12 15\n7 8 9",
"output": "-1"
},
{
"input": "2 2\n3 5\n7 8",
"output": "6"
},
{
"input": "3 3\n4 5 6\n10 11 12",
"output": "8"
},
{
"input": "3 5\n2 3 3\n6 6 6 6 2",
"output": "-1"
},
{
"input": "3 6\n4 5 3\n8 9 7 10 7 11",
"output": "6"
},
{
"input": "3 6\n4 5 2\n8 9 6 10 7 4",
"output": "-1"
},
{
"input": "2 1\n4 6\n10",
"output": "8"
},
{
"input": "1 2\n1\n3 1",
"output": "-1"
},
{
"input": "2 1\n5 6\n20",
"output": "10"
},
{
"input": "2 1\n1 5\n5",
"output": "-1"
},
{
"input": "3 2\n10 20 30\n30 40",
"output": "-1"
},
{
"input": "2 2\n5 6\n7 100",
"output": "-1"
},
{
"input": "2 1\n2 5\n7",
"output": "5"
},
{
"input": "1 1\n5\n20",
"output": "10"
},
{
"input": "2 1\n10 11\n100",
"output": "20"
},
{
"input": "1 1\n1\n10",
"output": "2"
},
{
"input": "1 1\n10\n100",
"output": "20"
}
] | 1,591,190,888 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 310 | 0 | import sys
input = lambda: sys.stdin.readline().strip("\r\n")
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mini = min(a)
if 2 * mini < min(b):
print(max(a))
else:
print(-1)
| Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
Input Specification:
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
Output Specification:
If there is a valid TL value, print it. Otherwise, print -1.
Demo Input:
['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n']
Demo Output:
['5', '-1\n']
Note:
none | ```python
import sys
input = lambda: sys.stdin.readline().strip("\r\n")
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mini = min(a)
if 2 * mini < min(b):
print(max(a))
else:
print(-1)
``` | 0 |
|
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers. | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;",
"output": "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server"
},
{
"input": "10 10\nittmcs 112.147.123.173\njkt 228.40.73.178\nfwckqtz 88.28.31.198\nkal 224.226.34.213\nnacuyokm 49.57.13.44\nfouynv 243.18.250.17\ns 45.248.83.247\ne 75.69.23.169\nauwoqlch 100.44.219.187\nlkldjq 46.123.169.140\ngjcylatwzi 46.123.169.140;\ndxfi 88.28.31.198;\ngv 46.123.169.140;\nety 88.28.31.198;\notbmgcrn 46.123.169.140;\nw 112.147.123.173;\np 75.69.23.169;\nvdsnigk 46.123.169.140;\nmmc 46.123.169.140;\ngtc 49.57.13.44;",
"output": "gjcylatwzi 46.123.169.140; #lkldjq\ndxfi 88.28.31.198; #fwckqtz\ngv 46.123.169.140; #lkldjq\nety 88.28.31.198; #fwckqtz\notbmgcrn 46.123.169.140; #lkldjq\nw 112.147.123.173; #ittmcs\np 75.69.23.169; #e\nvdsnigk 46.123.169.140; #lkldjq\nmmc 46.123.169.140; #lkldjq\ngtc 49.57.13.44; #nacuyokm"
},
{
"input": "1 1\nervbfot 185.32.99.2\nzygoumbmx 185.32.99.2;",
"output": "zygoumbmx 185.32.99.2; #ervbfot"
},
{
"input": "1 2\ny 245.182.246.189\nlllq 245.182.246.189;\nxds 245.182.246.189;",
"output": "lllq 245.182.246.189; #y\nxds 245.182.246.189; #y"
},
{
"input": "2 1\ntdwmshz 203.115.124.110\neksckjya 201.80.191.212\nzbtjzzue 203.115.124.110;",
"output": "zbtjzzue 203.115.124.110; #tdwmshz"
},
{
"input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;",
"output": "rvzzlygosc 26.165.124.191; #cfahrkq\ndcsgxrkgv 101.24.94.85; #t\nyvmyppn 59.6.179.72; #vjoirslx\ngpdjjuq 75.18.177.178; #phftablcr\nvdviz 101.24.94.85; #t"
},
{
"input": "2 1\nmain 1.1.1.1\nget 11.1.1.1\ncommand 11.1.1.1;",
"output": "command 11.1.1.1; #get"
},
{
"input": "2 2\nmain 0.0.0.255\nmainn 0.0.2.55\nblock 0.0.0.255;\nblock 0.0.2.55;",
"output": "block 0.0.0.255; #main\nblock 0.0.2.55; #mainn"
},
{
"input": "2 2\nmain 0.0.63.0\nreplica 0.38.0.56\nblock 0.0.63.0;\nproxy 0.38.0.56;",
"output": "block 0.0.63.0; #main\nproxy 0.38.0.56; #replica"
},
{
"input": "2 2\nmain 192.168.10.12\nreplica 192.167.10.12\nblock 192.168.10.12;\nproxy 192.167.10.12;",
"output": "block 192.168.10.12; #main\nproxy 192.167.10.12; #replica"
},
{
"input": "2 1\nneserver 185.218.47.91\nserver 255.255.255.255\nblock 255.255.255.255;",
"output": "block 255.255.255.255; #server"
},
{
"input": "2 1\nalp 22.222.30.10\nbet 222.22.30.10\nblock 22.222.30.10;",
"output": "block 22.222.30.10; #alp"
}
] | 1,642,635,701 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 140 | 3,788,800 | n,m=map(int,input().split())
d={}
for i in range(n):
name,ip=input().split()
d[ip]=name
for i in range(m):
cmd,ip=input().split()
print(cmd+" "+ip+" "+"#"+d[ip[:len(ip)-1]])
| Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.
Each ip is of form "a.b.c.d" where *a*, *b*, *c* and *d* are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has *m* commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.
Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.
Input Specification:
The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase letters). It is guaranteed that all ip are distinct.
The next *m* lines contain the commands in the configuration file. Each line is of form "command ip;" (1<=≤<=|*command*|<=≤<=10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the *n* school servers.
Output Specification:
Print *m* lines, the commands in the configuration file after Dustin did his task.
Demo Input:
['2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n', '3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n']
Demo Output:
['block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n', 'redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n']
Note:
none | ```python
n,m=map(int,input().split())
d={}
for i in range(n):
name,ip=input().split()
d[ip]=name
for i in range(m):
cmd,ip=input().split()
print(cmd+" "+ip+" "+"#"+d[ip[:len(ip)-1]])
``` | 3 |
|
733 | B | Parade | PROGRAMMING | 1,100 | [
"math"
] | null | null | Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.
There will be *n* columns participating in the parade, the *i*-th column consists of *l**i* soldiers, who start to march from left leg, and *r**i* soldiers, who start to march from right leg.
The beauty of the parade is calculated by the following formula: if *L* is the total number of soldiers on the parade who start to march from the left leg, and *R* is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |*L*<=-<=*R*|.
No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index *i* and swap values *l**i* and *r**i*.
Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns.
The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=500) — the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively. | Print single integer *k* — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to *n* in the order they are given in the input data.
If there are several answers, print any of them. | [
"3\n5 6\n8 9\n10 3\n",
"2\n6 5\n5 6\n",
"6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n"
] | [
"3\n",
"1\n",
"0\n"
] | In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.
If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.
It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9. | 1,000 | [
{
"input": "3\n5 6\n8 9\n10 3",
"output": "3"
},
{
"input": "2\n6 5\n5 6",
"output": "1"
},
{
"input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32",
"output": "0"
},
{
"input": "2\n500 499\n500 500",
"output": "0"
},
{
"input": "1\n139 252",
"output": "0"
},
{
"input": "10\n18 18\n71 471\n121 362\n467 107\n138 254\n13 337\n499 373\n337 387\n147 417\n76 417",
"output": "4"
},
{
"input": "4\n4 1\n5 3\n7 6\n3 5",
"output": "4"
},
{
"input": "3\n6 5\n9 8\n3 10",
"output": "3"
},
{
"input": "3\n100 9\n1 3\n1 5",
"output": "1"
},
{
"input": "4\n10 1\n10 2\n10 3\n1 10",
"output": "4"
},
{
"input": "5\n25 1\n24 1\n2 3\n2 3\n2 3",
"output": "3"
},
{
"input": "3\n90 1\n1 90\n100 1",
"output": "2"
},
{
"input": "3\n1 123\n22 1\n12 1",
"output": "1"
},
{
"input": "3\n4 5\n7 6\n10 9",
"output": "1"
},
{
"input": "4\n50 1\n50 1\n50 1\n1 49",
"output": "4"
},
{
"input": "7\n2 1\n2 1\n2 1\n2 1\n1 200\n1 200\n1 200",
"output": "1"
},
{
"input": "5\n10 8\n7 6\n2 8\n9 1\n7 1",
"output": "3"
},
{
"input": "3\n22 1\n12 1\n1 123",
"output": "3"
},
{
"input": "3\n10 8\n9 7\n4 5",
"output": "3"
},
{
"input": "5\n1 2\n4 8\n4 8\n32 16\n128 64",
"output": "2"
},
{
"input": "5\n10 1\n10 1\n10 1\n100 1\n1 5",
"output": "5"
}
] | 1,583,476,226 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 4 | 779 | 268,390,400 | a = eval('map(int, input().split()),' * int(input()))
b = [i - j for i, j in a]
mn, mx = min(b), max(b)
m = b.index((mx, mn)[-mn > mx])
now = sum(b)
future = now - (b[m] * 2)
print((0, m + 1)[abs(future) > abs(now)]) | Title: Parade
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.
There will be *n* columns participating in the parade, the *i*-th column consists of *l**i* soldiers, who start to march from left leg, and *r**i* soldiers, who start to march from right leg.
The beauty of the parade is calculated by the following formula: if *L* is the total number of soldiers on the parade who start to march from the left leg, and *R* is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |*L*<=-<=*R*|.
No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index *i* and swap values *l**i* and *r**i*.
Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns.
The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=500) — the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively.
Output Specification:
Print single integer *k* — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to *n* in the order they are given in the input data.
If there are several answers, print any of them.
Demo Input:
['3\n5 6\n8 9\n10 3\n', '2\n6 5\n5 6\n', '6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n']
Demo Output:
['3\n', '1\n', '0\n']
Note:
In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.
If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.
It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9. | ```python
a = eval('map(int, input().split()),' * int(input()))
b = [i - j for i, j in a]
mn, mx = min(b), max(b)
m = b.index((mx, mn)[-mn > mx])
now = sum(b)
future = now - (b[m] * 2)
print((0, m + 1)[abs(future) > abs(now)])
``` | 0 |
|
160 | C | Find Pair | PROGRAMMING | 1,700 | [
"implementation",
"math",
"sortings"
] | null | null | You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing *n* (not necessarily different) integers *a*1, *a*2, ..., *a**n*. We are interested in all possible pairs of numbers (*a**i*, *a**j*), (1<=≤<=*i*,<=*j*<=≤<=*n*). In other words, let's consider all *n*2 pairs of numbers, picked from the given array.
For example, in sequence *a*<==<={3,<=1,<=5} are 9 pairs of numbers: (3,<=3),<=(3,<=1),<=(3,<=5),<=(1,<=3),<=(1,<=1),<=(1,<=5),<=(5,<=3),<=(5,<=1),<=(5,<=5).
Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (*p*1, *q*1) is lexicographically less than pair (*p*2, *q*2) only if either *p*1 < *p*2, or *p*1 = *p*2 and *q*1 < *q*2.
Then the sequence, mentioned above, will be sorted like that: (1,<=1),<=(1,<=3),<=(1,<=5),<=(3,<=1),<=(3,<=3),<=(3,<=5),<=(5,<=1),<=(5,<=3),<=(5,<=5)
Let's number all the pair in the sorted list from 1 to *n*2. Your task is formulated like this: you should find the *k*-th pair in the ordered list of all possible pairs of the array you've been given. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=*n*2). The second line contains the array containing *n* integers *a*1, *a*2, ..., *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). The numbers in the array can coincide. All numbers are separated with spaces.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout, streams or the %I64d specificator instead. | In the single line print two numbers — the sought *k*-th pair. | [
"2 4\n2 1\n",
"3 2\n3 1 5\n"
] | [
"2 2\n",
"1 3\n"
] | In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2).
The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). | 1,500 | [
{
"input": "2 4\n2 1",
"output": "2 2"
},
{
"input": "3 2\n3 1 5",
"output": "1 3"
},
{
"input": "3 3\n1 1 2",
"output": "1 1"
},
{
"input": "1 1\n-4",
"output": "-4 -4"
},
{
"input": "3 7\n5 4 3",
"output": "5 3"
},
{
"input": "3 6\n10 1 3",
"output": "3 10"
},
{
"input": "4 12\n-1 -2 -3 -4",
"output": "-2 -1"
},
{
"input": "5 10\n1 2 2 1 3",
"output": "1 3"
},
{
"input": "5 13\n3 3 3 4 5",
"output": "3 5"
},
{
"input": "8 26\n4 4 1 1 1 3 3 5",
"output": "3 1"
},
{
"input": "10 90\n2 1 1 1 1 1 2 1 2 2",
"output": "2 2"
},
{
"input": "10 6\n3 1 1 3 2 2 2 3 3 3",
"output": "1 2"
},
{
"input": "10 18\n1 1 1 3 4 4 4 1 2 3",
"output": "1 2"
},
{
"input": "50 622\n4 9 8 1 3 7 1 2 3 8 9 8 8 5 2 10 5 8 1 3 1 8 2 3 7 9 10 2 9 9 7 3 8 6 10 6 5 4 8 1 1 5 6 8 9 5 9 5 3 2",
"output": "3 3"
},
{
"input": "50 2069\n9 97 15 22 69 27 7 23 84 73 74 60 94 43 98 13 4 63 49 7 31 93 23 6 75 32 63 49 32 99 43 68 48 16 54 20 38 40 65 34 28 21 55 79 50 2 18 22 95 25",
"output": "75 28"
},
{
"input": "100 9043\n4 1 4 2 1 4 2 2 1 1 4 2 4 2 4 1 4 2 2 1 2 2 2 2 1 1 2 3 2 1 1 3 2 3 1 4 2 2 2 4 1 4 3 3 4 3 4 1 1 4 2 2 4 4 4 4 4 1 1 2 3 1 3 4 1 3 1 4 1 3 2 2 3 2 3 1 2 3 4 3 3 2 3 4 4 4 2 3 2 1 1 2 2 4 1 2 3 2 2 1",
"output": "4 3"
},
{
"input": "100 4755\n5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3 1",
"output": "3 3"
},
{
"input": "100 6819\n4 3 4 6 2 5 2 2 5 6 6 6 1 3 1 3 2 2 2 3 4 5 2 1 6 4 5 3 2 3 4 4 4 3 5 6 3 2 4 5 2 3 2 1 1 6 4 1 5 6 4 3 4 2 4 1 3 2 3 1 2 2 5 1 3 2 5 1 3 2 4 5 1 3 5 5 5 2 6 6 6 3 1 5 4 6 3 3 4 3 1 4 1 1 1 1 2 4 2 6",
"output": "4 4"
},
{
"input": "10 50\n1 1 -9 -9 -9 7 7 7 7 7",
"output": "1 7"
},
{
"input": "9 76\n1 1 2 2 2 2 3 3 9",
"output": "9 2"
},
{
"input": "5 15\n1 1 1 2 2",
"output": "1 2"
},
{
"input": "5 7\n1 3 3 3 5",
"output": "3 1"
},
{
"input": "10 91\n1 1 1 1 1 1 1 1 1 2",
"output": "2 1"
},
{
"input": "5 20\n1 2 2 3 3",
"output": "3 2"
},
{
"input": "6 36\n1 1 2 2 2 2",
"output": "2 2"
},
{
"input": "5 16\n1 1 2 2 3",
"output": "2 2"
},
{
"input": "5 17\n1 3 3 5 5",
"output": "5 1"
},
{
"input": "5 17\n1 3 3 3 5",
"output": "3 3"
},
{
"input": "10 25\n1 2 2 3 4 5 6 7 8 9",
"output": "2 7"
},
{
"input": "10 90\n1 1 1 1 1 1 1 1 1 2",
"output": "1 2"
},
{
"input": "4 5\n3 1 3 1",
"output": "1 3"
},
{
"input": "3 5\n1 1 2",
"output": "1 2"
},
{
"input": "5 3\n0 1 2 3 4",
"output": "0 2"
}
] | 1,690,815,420 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 179,916,800 | from itertools import product
import heapq
n, k = map(int, input().split())
A = list(map(int, input().split()))
X = product(A, repeat=2)
XX = heapq.nsmallest(k, X)[-1]
print(*XX) | Title: Find Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got another problem dealing with arrays. Let's consider an arbitrary sequence containing *n* (not necessarily different) integers *a*1, *a*2, ..., *a**n*. We are interested in all possible pairs of numbers (*a**i*, *a**j*), (1<=≤<=*i*,<=*j*<=≤<=*n*). In other words, let's consider all *n*2 pairs of numbers, picked from the given array.
For example, in sequence *a*<==<={3,<=1,<=5} are 9 pairs of numbers: (3,<=3),<=(3,<=1),<=(3,<=5),<=(1,<=3),<=(1,<=1),<=(1,<=5),<=(5,<=3),<=(5,<=1),<=(5,<=5).
Let's sort all resulting pairs lexicographically by non-decreasing. Let us remind you that pair (*p*1, *q*1) is lexicographically less than pair (*p*2, *q*2) only if either *p*1 < *p*2, or *p*1 = *p*2 and *q*1 < *q*2.
Then the sequence, mentioned above, will be sorted like that: (1,<=1),<=(1,<=3),<=(1,<=5),<=(3,<=1),<=(3,<=3),<=(3,<=5),<=(5,<=1),<=(5,<=3),<=(5,<=5)
Let's number all the pair in the sorted list from 1 to *n*2. Your task is formulated like this: you should find the *k*-th pair in the ordered list of all possible pairs of the array you've been given.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=*n*2). The second line contains the array containing *n* integers *a*1, *a*2, ..., *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). The numbers in the array can coincide. All numbers are separated with spaces.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout, streams or the %I64d specificator instead.
Output Specification:
In the single line print two numbers — the sought *k*-th pair.
Demo Input:
['2 4\n2 1\n', '3 2\n3 1 5\n']
Demo Output:
['2 2\n', '1 3\n']
Note:
In the first sample the sorted sequence for the given array looks as: (1, 1), (1, 2), (2, 1), (2, 2). The 4-th of them is pair (2, 2).
The sorted sequence for the array from the second sample is given in the statement. The 2-nd pair there is (1, 3). | ```python
from itertools import product
import heapq
n, k = map(int, input().split())
A = list(map(int, input().split()))
X = product(A, repeat=2)
XX = heapq.nsmallest(k, X)[-1]
print(*XX)
``` | 0 |
|
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,597,382,444 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS1 | 7 | 186 | 0 | n = int(input())
num=0
while True:
x = list(map(int,str(n)))
if x[-1]==0:
num+= n//5
break
n-=max(x)
num+=1
print(num)
| 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())
num=0
while True:
x = list(map(int,str(n)))
if x[-1]==0:
num+= n//5
break
n-=max(x)
num+=1
print(num)
``` | 0 |
|
659 | C | Tanya and Toys | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection. Today is Tanya's birthday, and her mother decided to spend no more than *m* bourles on the gift to the daughter. Tanya will choose several different types of toys from the new collection as a gift. Of course, she does not want to get a type of toy which she already has.
Tanya wants to have as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya is too little, so she asks you to help her in this. | The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the types of toys that Tanya already has. | In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated integers *t*1,<=*t*2,<=...,<=*t**k* (1<=≤<=*t**i*<=≤<=109) — the types of toys that Tanya should choose.
If there are multiple answers, you may print any of them. Values of *t**i* can be printed in any order. | [
"3 7\n1 3 4\n",
"4 14\n4 6 12 8\n"
] | [
"2\n2 5 \n",
"4\n7 2 3 1\n"
] | In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | 1,000 | [
{
"input": "3 7\n1 3 4",
"output": "2\n2 5 "
},
{
"input": "4 14\n4 6 12 8",
"output": "4\n1 2 3 5 "
},
{
"input": "5 6\n97746 64770 31551 96547 65684",
"output": "3\n1 2 3 "
},
{
"input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656",
"output": "4\n1 2 3 4 "
},
{
"input": "30 38\n9560 64176 75619 53112 54160 68775 12655 13118 99502 89757 78434 42521 19210 1927 34097 5416 56110 44786 59126 44266 79240 65567 54602 25325 37171 2879 89291 89121 39568 28162",
"output": "8\n1 2 3 4 5 6 7 8 "
},
{
"input": "1 999999298\n85187",
"output": "44720\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "1 999999119\n34421",
"output": "44720\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "1 1000000000\n1",
"output": "44719\n2 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "1 1000000000\n44720",
"output": "44720\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "1 1000000000\n44719",
"output": "44720\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "1 1000000000\n44721",
"output": "44720\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "3 1000000000\n123456789 234567891 345678912",
"output": "44720\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "2 5\n999999999 1000000000",
"output": "2\n1 2 "
},
{
"input": "2 1000000000\n1 1000000000",
"output": "44719\n2 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "3 100000\n1000000000 100000000 1",
"output": "445\n2 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 ..."
},
{
"input": "5 5\n100000000 200000000 300000000 400000000 1000000000",
"output": "2\n1 2 "
},
{
"input": "6 3\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "1 1000000000\n1000000000",
"output": "44720\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "5 1000000\n1000000000 100000000 10000000 99999999 123456789",
"output": "1413\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "2 10000000\n1234567 123456",
"output": "4471\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "1 1\n1000000000",
"output": "1\n1 "
},
{
"input": "1 1000000000\n9999999",
"output": "44720\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..."
},
{
"input": "5 10000\n1000000000 888888888 777777777 666666666 959595959",
"output": "140\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 "
},
{
"input": "3 1\n1000000000 999999999 999999998",
"output": "1\n1 "
},
{
"input": "5 100000000\n100000000 999999999 1 2 3",
"output": "14138\n4 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 15..."
},
{
"input": "3 55\n100000000 1000000000 999999999",
"output": "10\n1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "2 10\n5 10000009",
"output": "4\n1 2 3 4 "
},
{
"input": "3 10000000\n999999999 999999998 999999997",
"output": "4471\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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "1 1100\n1000000000",
"output": "46\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 "
},
{
"input": "1 40\n1000000000",
"output": "8\n1 2 3 4 5 6 7 8 "
}
] | 1,625,729,275 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 10,444,800 | a,m=map(int,input().split())
l=list(map(int,input().split()))
p=[]
t=pow(10,9)
for i in range(1,t+1):
if i not in l:
if i<=m:
m=m-i
p.append(i)
if i>m:
break
print(len(p))
print(*p) | Title: Tanya and Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection. Today is Tanya's birthday, and her mother decided to spend no more than *m* bourles on the gift to the daughter. Tanya will choose several different types of toys from the new collection as a gift. Of course, she does not want to get a type of toy which she already has.
Tanya wants to have as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya is too little, so she asks you to help her in this.
Input Specification:
The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the types of toys that Tanya already has.
Output Specification:
In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated integers *t*1,<=*t*2,<=...,<=*t**k* (1<=≤<=*t**i*<=≤<=109) — the types of toys that Tanya should choose.
If there are multiple answers, you may print any of them. Values of *t**i* can be printed in any order.
Demo Input:
['3 7\n1 3 4\n', '4 14\n4 6 12 8\n']
Demo Output:
['2\n2 5 \n', '4\n7 2 3 1\n']
Note:
In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | ```python
a,m=map(int,input().split())
l=list(map(int,input().split()))
p=[]
t=pow(10,9)
for i in range(1,t+1):
if i not in l:
if i<=m:
m=m-i
p.append(i)
if i>m:
break
print(len(p))
print(*p)
``` | 0 |
|
708 | A | Letters Cyclic Shift | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation",
"strings"
] | null | null | You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once? | The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters. | Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring. | [
"codeforces\n",
"abacaba\n"
] | [
"bncdenqbdr\n",
"aaacaba\n"
] | String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, and *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>. | 500 | [
{
"input": "codeforces",
"output": "bncdenqbdr"
},
{
"input": "abacaba",
"output": "aaacaba"
},
{
"input": "babbbabaababbaa",
"output": "aabbbabaababbaa"
},
{
"input": "bcbacaabcababaccccaaaabacbbcbbaa",
"output": "abaacaabcababaccccaaaabacbbcbbaa"
},
{
"input": "cabaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda",
"output": "babaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda"
},
{
"input": "a",
"output": "z"
},
{
"input": "eeeedddccbceaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec",
"output": "ddddcccbbabdaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec"
},
{
"input": "fddfbabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe",
"output": "ecceaabadaadaddfbfecadfaefaefefabcccdbbeeabcbbddefbafdcafdfcbdffeeaffcaebbbedabddeaecdddffcbeaafffcddccccfffdbcddcfccefafdbeaacbdeeebdeaaacdfdecadfeafaeaefbfdfffeeaefebdceebcebbfeaccfafdccdcecedeedadcadbfefccfdedfaaefabbaeebdebeecaadbebcfeafbfeeefcfaecadfe"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaaaz"
},
{
"input": "abbabaaaaa",
"output": "aaaabaaaaa"
},
{
"input": "bbbbbbbbbbbb",
"output": "aaaaaaaaaaaa"
},
{
"input": "aabaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaa",
"output": "aaaaaaaaaaaaaaaaaaaz"
},
{
"input": "abaabaaaaaabbaaaaaaabaaaaaaaaabaaaabaaaaaaabaaaaaaaaaabaaaaaaaaaaaaaaabaaaabbaaaaabaaaaaaaabaaaaaaaa",
"output": "aaaabaaaaaabbaaaaaaabaaaaaaaaabaaaabaaaaaaabaaaaaaaaaabaaaaaaaaaaaaaaabaaaabbaaaaabaaaaaaaabaaaaaaaa"
},
{
"input": "abbbbbbbabbbbbbbbbbbbbbbbbbbbbbbabbabbbbbabbbbbbbbbbbabbbbbbbbabbabbbbbbbbbbbbbbabbabbbaababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbbabbbbbbbbbbbbbbbabbbbbbbbbaababbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbabbbbbaabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbaabbbbbbbbbbbbababbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbabbbbbbbabbbbbbb",
"output": "aaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbabbabbbbbabbbbbbbbbbbabbbbbbbbabbabbbbbbbbbbbbbbabbabbbaababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbbabbbbbbbbbbbbbbbabbbbbbbbbaababbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbabbabbbbbbbbbbbbbbbbabbbabbbbbaabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbaabbbbbbbbbbbbababbabbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbabbbbbbbabbbbbbb"
},
{
"input": "aaaaa",
"output": "aaaaz"
},
{
"input": "aaa",
"output": "aaz"
},
{
"input": "aa",
"output": "az"
}
] | 1,596,177,507 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 93 | 7,065,600 | a,s,iz='',input(),0
for i in range(len(s)):
if s=='a': a='z'
elif s[i]=='a' and iz<1:a+=s[i]
elif s[i]=='a' and iz>=1:
a+=s[len(a):]
break
else:a,iz=a+chr(ord(s[i])-1),iz+1
print(a)
| Title: Letters Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from *s* by performing this shift exactly once?
Input Specification:
The only line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) consisting of lowercase English letters.
Output Specification:
Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring.
Demo Input:
['codeforces\n', 'abacaba\n']
Demo Output:
['bncdenqbdr\n', 'aaacaba\n']
Note:
String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≤ *i* ≤ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i* - 1</sub> = *t*<sub class="lower-index">*i* - 1</sub>, and *s*<sub class="lower-index">*i*</sub> < *t*<sub class="lower-index">*i*</sub>. | ```python
a,s,iz='',input(),0
for i in range(len(s)):
if s=='a': a='z'
elif s[i]=='a' and iz<1:a+=s[i]
elif s[i]=='a' and iz>=1:
a+=s[len(a):]
break
else:a,iz=a+chr(ord(s[i])-1),iz+1
print(a)
``` | 0 |
|
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "5\n0 73\n73 189\n189 766\n766 0\n0 0",
"output": "766"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 1\n1 0",
"output": "1"
},
{
"input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0",
"output": "1011"
},
{
"input": "5\n0 1\n1 2\n2 1\n1 2\n2 0",
"output": "2"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0",
"output": "22"
},
{
"input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0",
"output": "1776"
},
{
"input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0",
"output": "1016"
},
{
"input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0",
"output": "3"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0",
"output": "2071"
},
{
"input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0",
"output": "3"
},
{
"input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0",
"output": "1329"
},
{
"input": "2\n0 863\n863 0",
"output": "863"
},
{
"input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0",
"output": "8"
},
{
"input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0",
"output": "11"
},
{
"input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0",
"output": "7"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 900\n900 0",
"output": "900"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1000\n1000 0",
"output": "1000"
},
{
"input": "3\n0 802\n175 188\n815 0",
"output": "815"
},
{
"input": "3\n0 910\n910 976\n976 0",
"output": "976"
},
{
"input": "3\n0 2\n2 1\n1 0",
"output": "2"
}
] | 1,691,988,872 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | n=int(input())
temp=0
max=0
for i in range(n):
a,b=map(int,input().split())
temp=temp-a
temp=temp+b
if temp>max:
max=temp
print(max)
| Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Input Specification:
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Output Specification:
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
Demo Input:
['4\n0 3\n2 5\n4 2\n4 0\n']
Demo Output:
['6\n']
Note:
For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | ```python
n=int(input())
temp=0
max=0
for i in range(n):
a,b=map(int,input().split())
temp=temp-a
temp=temp+b
if temp>max:
max=temp
print(max)
``` | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.