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
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", "output": "50" }, { "input": "101", "output": "-51" }, { "input": "102", "output": "51" }, { "input": "103", "output": "-52" }, { "input": "104", "output": "52" }, { "input": "105", "output": "-53" }, { "input": "106", "output": "53" }, { "input": "107", "output": "-54" }, { "input": "108", "output": "54" }, { "input": "109", "output": "-55" }, { "input": "208170109961052", "output": "104085054980526" }, { "input": "46017661651072", "output": "23008830825536" }, { "input": "4018154546667", "output": "-2009077273334" }, { "input": "288565475053", "output": "-144282737527" }, { "input": "3052460231", "output": "-1526230116" }, { "input": "29906716", "output": "14953358" }, { "input": "87897701693326", "output": "43948850846663" }, { "input": "8240", "output": "4120" }, { "input": "577935", "output": "-288968" }, { "input": "62", "output": "31" }, { "input": "1", "output": "-1" }, { "input": "2", "output": "1" }, { "input": "9999999999999", "output": "-5000000000000" }, { "input": "1000000000000", "output": "500000000000" }, { "input": "99999999999999", "output": "-50000000000000" }, { "input": "999999999999999", "output": "-500000000000000" }, { "input": "42191359342", "output": "21095679671" }, { "input": "100000000000000", "output": "50000000000000" }, { "input": "145645214654154", "output": "72822607327077" }, { "input": "4294967296", "output": "2147483648" }, { "input": "3037000499", "output": "-1518500250" }, { "input": "10000000000001", "output": "-5000000000001" }, { "input": "100000017040846", "output": "50000008520423" }, { "input": "98979894985999", "output": "-49489947493000" } ]
1,698,346,210
2,147,483,647
PyPy 3-64
OK
TESTS
39
46
0
z=int(input()) f=0 if z&1==1: z+=1 z=-(z//2) else: z=z//2 print(z)
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). Output Specification: Print *f*(*n*) in a single line. Demo Input: ['4\n', '5\n'] Demo Output: ['2\n', '-3\n'] Note: *f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
```python z=int(input()) f=0 if z&1==1: z+=1 z=-(z//2) else: z=z//2 print(z) ```
3
120
B
Quiz League
PROGRAMMING
1,100
[ "implementation" ]
null
null
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number *k*.
The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 if the question from sector *i* hasn't been asked yet (1<=≤<=*i*<=≤<=*n*). The sectors are given in the clockwise order, the first sector follows after the *n*-th one.
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
[ "5 5\n0 1 0 1 0\n", "2 1\n1 1\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "5 5\n0 1 0 1 0", "output": "2" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "3 2\n1 0 0", "output": "1" }, { "input": "3 3\n0 1 0", "output": "2" }, { "input": "1 1\n1", "output": "1" }, { "input": "6 3\n0 0 1 1 0 1", "output": "3" }, { "input": "3 1\n0 1 0", "output": "2" }, { "input": "3 3\n1 0 1", "output": "3" }, { "input": "4 4\n1 0 1 0", "output": "1" }, { "input": "5 3\n0 1 0 1 1", "output": "4" }, { "input": "6 4\n1 0 0 0 0 1", "output": "6" }, { "input": "7 5\n1 0 0 0 0 0 1", "output": "7" }, { "input": "101 81\n1 0 1 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 0 0 1 0", "output": "82" }, { "input": "200 31\n1 0 0 1 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 1 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 1 1 1 1 0 1 0 0 0 0 1 1 0 1 0 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 0 1 0", "output": "33" }, { "input": "17 13\n0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 1 1", "output": "13" }, { "input": "102 9\n0 0 0 0 1 1 0 1 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 1 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1", "output": "10" } ]
1,604,430,666
2,147,483,647
PyPy 3
OK
TESTS
30
140
0
import sys sys.stdin = open(r'input.txt', 'r') sys.stdout = open(r'output.txt', 'w') n, k = map(int, input().split()) a = list(map(int, input().split())) i = k-1; while (True): if i == n: i = 0 continue if a[i] == 1: print(i+1) break i += 1
Title: Quiz League Time Limit: None seconds Memory Limit: None megabytes Problem Description: A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number *k*. Input Specification: The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 if the question from sector *i* hasn't been asked yet (1<=≤<=*i*<=≤<=*n*). The sectors are given in the clockwise order, the first sector follows after the *n*-th one. Output Specification: Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. Demo Input: ['5 5\n0 1 0 1 0\n', '2 1\n1 1\n'] Demo Output: ['2\n', '1\n'] Note: none
```python import sys sys.stdin = open(r'input.txt', 'r') sys.stdout = open(r'output.txt', 'w') n, k = map(int, input().split()) a = list(map(int, input().split())) i = k-1; while (True): if i == n: i = 0 continue if a[i] == 1: print(i+1) break i += 1 ```
3
834
B
The Festive Evening
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in. There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously. For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed. Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened.
Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26). In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest.
Output «YES» if at least one door was unguarded during some time, and «NO» otherwise. You can output each letter in arbitrary case (upper or lower).
[ "5 1\nAABBB\n", "5 1\nABABB\n" ]
[ "NO\n", "YES\n" ]
In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened. In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.
1,000
[ { "input": "5 1\nAABBB", "output": "NO" }, { "input": "5 1\nABABB", "output": "YES" }, { "input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NO" }, { "input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA", "output": "YES" }, { "input": "5 2\nABACA", "output": "NO" }, { "input": "6 2\nABCABC", "output": "YES" }, { "input": "8 3\nABCBCDCA", "output": "NO" }, { "input": "73 2\nDEBECECBBADAADEAABEAEEEAEBEAEBCDDBABBAEBACCBEEBBAEADEECACEDEEDABACDCDBBBD", "output": "YES" }, { "input": "44 15\nHGJIFCGGCDGIJDHBIBGAEABCIABIGBDEADBBBAGDFDHA", "output": "NO" }, { "input": "41 19\nTMEYYIIELFDCMBDKWWKYNRNDUPRONYROXQCLVQALP", "output": "NO" }, { "input": "377 3\nEADADBBBBDEAABBAEBABACDBDBBCACAADBEAEACDEAABACADEEDEACACDADABBBBDDEECBDABACACBAECBADAEBDEEBDBCDAEADBCDDACACDCCEEDBCCBBCEDBECBABCDDBBDEADEDAEACDECECBEBACBCCDCDBDAECDECADBCBEDBBDAAEBCAAECCDCCDBDDEBADEEBDCAEABBDEDBBDDEAECCBDDCDEACDAECCBDDABABEAEDCDEDBAECBDEACEBCECEACDCBABCBAAEAADACADBBBBABEADBCADEBCBECCABBDDDEEBCDEBADEBDAAABBEABADEDEAEABCEEBEEDEAEBEABCEDDBACBCCADEBAAAAAEABABBCE", "output": "YES" }, { "input": "433 3\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVITKNFLVCPMZSDMCHBTVAWYVZLIXXIADXNYILEYNIQHKMOGMVOCWGHCWIYMPEPADSJAAKEGTUSEDWAHMNYJDIHBKHVUHLYGNGZDBULRXLSAJHPCMNWCEAAPYMHDTYWPADOTJTXTXUKLCHWKUSZRHEKQEFPVJEJJHRWCKYOIWALRTIBUMNOCRXLSIKQCJVQXEPGOHRUDJDKMUUUDORURWXJNVRVMNOUNRFKSVMTMZGOIJLXEPAMVGESOADYIGZXRBJDIWKNOWTCSROAQTBECHTOZVSQUOOJRZIBAUHMKAXDCIMDZJFMABGRNTGPUJAUNFPFWCJG", "output": "YES" }, { "input": "5 2\nABCAB", "output": "YES" }, { "input": "5 1\nAZAZA", "output": "YES" }, { "input": "7 2\nABCDBCD", "output": "YES" }, { "input": "3 26\nAAB", "output": "NO" } ]
1,585,726,076
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
109
0
# -*- coding: utf-8 -*- # Baqir Khan # Software Engineer (Backend) from sys import stdin inp = stdin.readline n, k = map(int, inp().split()) s = inp()[:-1] out_time = [-1] * 26 in_time = [-1] * 26 for i in range(n): if in_time[ord(s[i]) - ord("A")] == -1: in_time[ord(s[i]) - ord("A")] = i for i in range(n - 1, -1, -1): if out_time[ord(s[i]) - ord("A")] == -1: out_time[ord(s[i]) - ord("A")] = i requirement = [0] * (n + 1) for i in range(26): if in_time[i] != -1: requirement[in_time[i]] += 1 requirement[out_time[i] + 1] -= 1 cur_sum = 0 for i in range(n): cur_sum += requirement[i] requirement[i] = cur_sum print("YES" if max(requirement) <= k else "NO")
Title: The Festive Evening Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in. There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously. For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed. Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened. Input Specification: Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26). In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. Output Specification: Output «YES» if at least one door was unguarded during some time, and «NO» otherwise. You can output each letter in arbitrary case (upper or lower). Demo Input: ['5 1\nAABBB\n', '5 1\nABABB\n'] Demo Output: ['NO\n', 'YES\n'] Note: In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened. In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.
```python # -*- coding: utf-8 -*- # Baqir Khan # Software Engineer (Backend) from sys import stdin inp = stdin.readline n, k = map(int, inp().split()) s = inp()[:-1] out_time = [-1] * 26 in_time = [-1] * 26 for i in range(n): if in_time[ord(s[i]) - ord("A")] == -1: in_time[ord(s[i]) - ord("A")] = i for i in range(n - 1, -1, -1): if out_time[ord(s[i]) - ord("A")] == -1: out_time[ord(s[i]) - ord("A")] = i requirement = [0] * (n + 1) for i in range(26): if in_time[i] != -1: requirement[in_time[i]] += 1 requirement[out_time[i] + 1] -= 1 cur_sum = 0 for i in range(n): cur_sum += requirement[i] requirement[i] = cur_sum print("YES" if max(requirement) <= k else "NO") ```
0
109
A
Lucky Sum of Digits
PROGRAMMING
1,000
[ "brute force", "implementation" ]
A. Lucky Sum of Digits
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
[ "11\n", "10\n" ]
[ "47\n", "-1\n" ]
none
500
[ { "input": "11", "output": "47" }, { "input": "10", "output": "-1" }, { "input": "64", "output": "4477777777" }, { "input": "1", "output": "-1" }, { "input": "4", "output": "4" }, { "input": "7", "output": "7" }, { "input": "12", "output": "444" }, { "input": "1000000", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "47", "output": "44477777" }, { "input": "100", "output": "4444777777777777" }, { "input": "700", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "485", "output": "44447777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "111", "output": "444447777777777777" }, { "input": "85", "output": "4477777777777" }, { "input": "114", "output": "444477777777777777" }, { "input": "474", "output": "444777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "74", "output": "47777777777" }, { "input": "1000", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "1024", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "4444", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "45784", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10000", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9854", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "186", "output": "477777777777777777777777777" }, { "input": "10416", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10417", "output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "3840", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "100000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "9876", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "99999", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "777777", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "854759", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "11000", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "18951", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999999", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "888887", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999998", "output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "40008", "output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "10691", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "5", "output": "-1" }, { "input": "6", "output": "-1" }, { "input": "9", "output": "-1" }, { "input": "8", "output": "44" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "-1" }, { "input": "999997", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999996", "output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999990", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "999980", "output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "800000", "output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "980000", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." } ]
1,600,514,142
2,147,483,647
PyPy 3
OK
TESTS
51
310
614,400
n=int(input()) a=n%7 x=n//7 while (a%4): a=a+7 x=x-1 y=a//4 if max(0,x)*7+max(y,0)*4!=n: print (-1) else: print (('4'*y)+('7'*x))
Title: Lucky Sum of Digits Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. Output Specification: Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. Demo Input: ['11\n', '10\n'] Demo Output: ['47\n', '-1\n'] Note: none
```python n=int(input()) a=n%7 x=n//7 while (a%4): a=a+7 x=x-1 y=a//4 if max(0,x)*7+max(y,0)*4!=n: print (-1) else: print (('4'*y)+('7'*x)) ```
3.921356
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "output": "6" }, { "input": "11 562314608", "output": "39916800" }, { "input": "3 990639260", "output": "6" }, { "input": "11 859155400", "output": "39916800" }, { "input": "1 1", "output": "1" }, { "input": "5 3", "output": "6" }, { "input": "1 4", "output": "1" }, { "input": "5 4", "output": "24" }, { "input": "1 12", "output": "1" }, { "input": "9 7", "output": "5040" }, { "input": "2 3", "output": "2" }, { "input": "6 11", "output": "720" }, { "input": "6 7", "output": "720" }, { "input": "11 11", "output": "39916800" }, { "input": "4 999832660", "output": "24" }, { "input": "7 999228288", "output": "5040" }, { "input": "11 999257105", "output": "39916800" }, { "input": "11 999286606", "output": "39916800" }, { "input": "3 999279109", "output": "6" }, { "input": "999632727 11", "output": "39916800" }, { "input": "999625230 7", "output": "5040" }, { "input": "999617047 3", "output": "6" }, { "input": "999646548 7", "output": "5040" }, { "input": "999639051 3", "output": "6" }, { "input": "12 12", "output": "479001600" }, { "input": "12 1", "output": "1" }, { "input": "1213 5", "output": "120" }, { "input": "8 9", "output": "40320" }, { "input": "12 9", "output": "362880" }, { "input": "12 1000000000", "output": "479001600" }, { "input": "1000000000 1", "output": "1" }, { "input": "12 13", "output": "479001600" }, { "input": "2 29845", "output": "2" }, { "input": "10 21", "output": "3628800" }, { "input": "12 20", "output": "479001600" }, { "input": "15 12", "output": "479001600" }, { "input": "1 1", "output": "1" }, { "input": "1000000000 12", "output": "479001600" }, { "input": "11 30", "output": "39916800" }, { "input": "17 12", "output": "479001600" }, { "input": "4 19", "output": "24" }, { "input": "12 15", "output": "479001600" }, { "input": "20 6", "output": "720" }, { "input": "10 20", "output": "3628800" }, { "input": "10 10", "output": "3628800" }, { "input": "22 12", "output": "479001600" }, { "input": "20 12", "output": "479001600" }, { "input": "12 23", "output": "479001600" }, { "input": "12 22", "output": "479001600" }, { "input": "18 3", "output": "6" }, { "input": "14 10", "output": "3628800" }, { "input": "14 12", "output": "479001600" }, { "input": "8 3", "output": "6" }, { "input": "5 5", "output": "120" } ]
1,638,195,083
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
1
1,000
204,800
a,b=map(int,input().split()) za=a zb=b af=1 bf=1 for i in range(a): af*=za za-=1 for i in range(b): bf*=zb zb-=1 f=min(af,bf) while True: if af%f==0 and bf%f==0: print(f) break f-=1
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? Input Specification: The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). Output Specification: Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. Demo Input: ['4 3\n'] Demo Output: ['6\n'] Note: Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
```python a,b=map(int,input().split()) za=a zb=b af=1 bf=1 for i in range(a): af*=za za-=1 for i in range(b): bf*=zb zb-=1 f=min(af,bf) while True: if af%f==0 and bf%f==0: print(f) break f-=1 ```
0
844
A
Diversity
PROGRAMMING
1,000
[ "greedy", "implementation", "strings" ]
null
null
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
[ "yandex\n6\n", "yahoo\n5\n", "google\n7\n" ]
[ "0\n", "1\n", "impossible\n" ]
In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
500
[ { "input": "yandex\n6", "output": "0" }, { "input": "yahoo\n5", "output": "1" }, { "input": "google\n7", "output": "impossible" }, { "input": "a\n1", "output": "0" }, { "input": "z\n2", "output": "impossible" }, { "input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26", "output": "14" }, { "input": "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26", "output": "12" }, { "input": "a\n3", "output": "impossible" }, { "input": "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1", "output": "0" }, { "input": "cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4", "output": "1" }, { "input": "fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20", "output": "18" }, { "input": "swmkwaruyv\n5", "output": "0" }, { "input": "tnbqpsuhkczmejirvyfdolxwga\n22", "output": "0" }, { "input": "abcde\n3", "output": "0" }, { "input": "abb\n1", "output": "0" }, { "input": "aaaa\n1", "output": "0" }, { "input": "abcde\n2", "output": "0" }, { "input": "yandex\n4", "output": "0" }, { "input": "aaabbbccc\n1", "output": "0" }, { "input": "abcd\n2", "output": "0" }, { "input": "asdfgh\n2", "output": "0" }, { "input": "aab\n1", "output": "0" }, { "input": "mynameissako\n5", "output": "0" }, { "input": "abcde\n1", "output": "0" }, { "input": "abcd\n3", "output": "0" }, { "input": "abcdef\n2", "output": "0" }, { "input": "abcdefg\n4", "output": "0" }, { "input": "abc\n1", "output": "0" }, { "input": "asdafjsgljdllgjdgkl\n5", "output": "0" }, { "input": "yaay\n3", "output": "1" }, { "input": "yaay\n4", "output": "2" }, { "input": "zzzzzz\n2", "output": "1" } ]
1,503,597,256
4,756
Python 3
WRONG_ANSWER
CHALLENGES
0
46
0
s=[i for i in input()] n=int(input()) if len(s)<n: print('impossible') else: s=len(set(s)) print(n-s)
Title: Diversity Time Limit: None seconds Memory Limit: None megabytes Problem Description: Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input Specification: First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). Output Specification: Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. Demo Input: ['yandex\n6\n', 'yahoo\n5\n', 'google\n7\n'] Demo Output: ['0\n', '1\n', 'impossible\n'] Note: In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
```python s=[i for i in input()] n=int(input()) if len(s)<n: print('impossible') else: s=len(set(s)) print(n-s) ```
0
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,593,340,849
2,147,483,647
PyPy 3
OK
TESTS
45
155
20,172,800
n = int(input()) l = [int(x) for x in input().split()] l.sort() print(l[n//2])
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()) l = [int(x) for x in input().split()] l.sort() print(l[n//2]) ```
3
468
C
Hack it!
PROGRAMMING
2,500
[ "binary search", "constructive algorithms", "math" ]
null
null
Little X has met the following problem recently. Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code:
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018).
Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=&lt;<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists.
[ "46\n", "126444381000032\n" ]
[ "1 10\n", "2333333 2333333333333\n" ]
none
1,500
[ { "input": "46", "output": "1 10" }, { "input": "126444381000032", "output": "2333333 2333333333333" }, { "input": "69645082595", "output": "613752823618441225798858488535 713259406474207764329704856394" }, { "input": "70602205995", "output": "11 249221334020432074498656960922" }, { "input": "33898130785", "output": "9 558855506346909386939077840182" }, { "input": "58929554039", "output": "22 855783114773435710171914224422" }, { "input": "81696185182", "output": "499118531974994927425925323518 956291458400902769638235161661" }, { "input": "1", "output": "149268802942315027273202513064 277551734280589260570057105889" }, { "input": "2", "output": "119692200833686078608961312319 629363568954685219494592939495" }, { "input": "3", "output": "2 302254410562920936884653943506" }, { "input": "4", "output": "284378053387469023431537894255 317250990020830090421009164911" }, { "input": "5", "output": "2 62668056583245293799710157951" }, { "input": "6", "output": "3 93810188780011787541394067841" }, { "input": "7", "output": "2 834286447477504059026206246185" }, { "input": "8", "output": "3 257583347960907690857477857197" }, { "input": "10", "output": "3 163048811987317819669274448265" }, { "input": "11", "output": "3 919618203693907154039906935669" }, { "input": "12", "output": "448221703341269567451520778454 698029790336105644790102859494" }, { "input": "43", "output": "9 172412961300207091437973214327" }, { "input": "36", "output": "8 619355518777647869838990701242" }, { "input": "65", "output": "6 709024330418134127413755925068" }, { "input": "43", "output": "7 669540448846929747909766131221" }, { "input": "23", "output": "2 104579054315773428039906118259" }, { "input": "100", "output": "15 324437778467489559125023403167" }, { "input": "10000", "output": "2 936791129091842315790163514642" }, { "input": "1000000", "output": "18 369591628030718549289473454545" }, { "input": "100000000", "output": "7 870405265198051697453938746950" }, { "input": "10000000000", "output": "20 972749766921651560604778558599" }, { "input": "1000000000000", "output": "6 68997070398311657294228230677" }, { "input": "100000000000000", "output": "249537318528661282822184562278 397003438246047829818181818181" }, { "input": "10000000000000000", "output": "10 778165727326620883431915444624" }, { "input": "1000000000000000000", "output": "408256298986776744812953390000 824018301451167837914299999999" }, { "input": "450000000000000000", "output": "2 357722688084551093593033993033" }, { "input": "432022", "output": "3 333556238531076799985515487090" }, { "input": "428033", "output": "22 730314748425770554502599499142" }, { "input": "776930", "output": "20 521232359366297130685112811874" }, { "input": "329824", "output": "308969571112207311167474021348 745620588073413831210052337999" }, { "input": "85058261498638", "output": "16 931187081941564769324316582547" }, { "input": "2130909834463", "output": "21 895378349209612431051450316022" }, { "input": "3427089130241", "output": "10 676758114393938690602742889714" }, { "input": "22881472397923", "output": "174523915446146844994793303441 429392837423394397373605399524" }, { "input": "756499070280135900", "output": "17 414254565210363110239866979636" }, { "input": "348919756917359012", "output": "15 148711424846749040017925495268" }, { "input": "789136710974630947", "output": "13 214740524663440316532540770911" }, { "input": "32851678509090784", "output": "15 728787006985867306455350840047" }, { "input": "219760524792138559", "output": "8 51530430692061277616906746431" }, { "input": "1000000007", "output": "19 96093944063249823335491170999" }, { "input": "999999874000003969", "output": "306259936121099507549028331741 983025349899931537481252156006" }, { "input": "999999999999999989", "output": "140766388309929586494194507367 705096656792775954903252198639" }, { "input": "999999999999999983", "output": "4 365946710276937286091309116340" }, { "input": "999999999999999999", "output": "26 983966655749419565978291923474" } ]
1,635,324,634
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
4,198,400
n = int(input()) yu = 81000000000000000001 % a k = n - yu ed = 1000000000000000000 + k print(k, ed)
Title: Hack it! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little X has met the following problem recently. Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: Input Specification: The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018). Output Specification: Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=&lt;<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Demo Input: ['46\n', '126444381000032\n'] Demo Output: ['1 10\n', '2333333 2333333333333\n'] Note: none
```python n = int(input()) yu = 81000000000000000001 % a k = n - yu ed = 1000000000000000000 + k print(k, ed) ```
-1
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4 4 4 2" }, { "input": "1\n2000", "output": "1" }, { "input": "2\n2000 2000", "output": "1 1" }, { "input": "3\n500 501 502", "output": "3 2 1" }, { "input": "10\n105 106 1 1 1 11 1000 999 1000 999", "output": "6 5 8 8 8 7 1 3 1 3" }, { "input": "6\n1 2 3 4 5 6", "output": "6 5 4 3 2 1" }, { "input": "7\n6 5 4 3 2 1 1", "output": "1 2 3 4 5 6 6" }, { "input": "8\n153 100 87 14 10 8 6 5", "output": "1 2 3 4 5 6 7 8" }, { "input": "70\n11 54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10", "output": "62 18 35 7 70 23 61 56 34 22 42 58 6 66 10 37 21 2 38 13 69 29 14 42 48 7 29 5 50 66 60 29 63 35 20 38 4 23 10 65 58 52 57 27 41 28 52 23 2 46 45 14 12 66 52 55 1 19 50 33 26 44 47 29 38 48 16 17 7 63" }, { "input": "5\n1 2000 1 1 2000", "output": "3 1 3 3 1" } ]
1,476,351,266
2,147,483,647
Python 3
OK
TESTS
36
93
4,915,200
import sys n = int(input()) alist = list(map(int, sys.stdin.readline().split())) blist = sorted(alist)[::-1] clist = [str(blist.index(a)+1) for a in alist] print(' '.join(clist))
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). Output Specification: In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. Demo Input: ['3\n1 3 3\n', '1\n1\n', '5\n3 5 3 4 5\n'] Demo Output: ['3 1 1\n', '1\n', '4 1 4 3 1\n'] Note: In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3 are the last sharing fourth position.
```python import sys n = int(input()) alist = list(map(int, sys.stdin.readline().split())) blist = sorted(alist)[::-1] clist = [str(blist.index(a)+1) for a in alist] print(' '.join(clist)) ```
3
315
B
Sereja and Array
PROGRAMMING
1,200
[ "implementation" ]
null
null
Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms: 1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. Increase each array element by *y**i*. In other words, perform *n* assignments *a**i*<==<=*a**i*<=+<=*y**i* (1<=≤<=*i*<=≤<=*n*). 1. Take a piece of paper and write out the *q**i*-th array element. That is, the element *a**q**i*. Help Sereja, complete all his operations.
The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array. Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is integer *t**i* (1<=≤<=*t**i*<=≤<=3) that represents the operation type. If *t**i*<==<=1, then it is followed by two integers *v**i* and *x**i*, (1<=≤<=*v**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=109). If *t**i*<==<=2, then it is followed by integer *y**i* (1<=≤<=*y**i*<=≤<=104). And if *t**i*<==<=3, then it is followed by integer *q**i* (1<=≤<=*q**i*<=≤<=*n*).
For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input.
[ "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n" ]
[ "2\n9\n11\n20\n30\n40\n39\n" ]
none
1,000
[ { "input": "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9", "output": "2\n9\n11\n20\n30\n40\n39" }, { "input": "1 3\n1\n1 1 2\n2 1\n3 1", "output": "3" }, { "input": "1 1\n1\n3 1", "output": "1" }, { "input": "6 6\n202714501 613423725 367325359 862808465 182588146 745008828\n2 492\n2 1943\n1 3 173984392\n1 3 9356383\n3 4\n1 5 472683539", "output": "862810900" }, { "input": "6 5\n545129895 918519812 2334334 565540665 484519712 904102869\n3 3\n1 2 641196860\n2 779\n2 3036\n3 1", "output": "2334334\n545133710" }, { "input": "5 5\n286163265 724763447 761775891 215352371 491215007\n1 4 780579549\n1 2 638546757\n3 4\n1 3 38072627\n2 6119", "output": "780579549" }, { "input": "4 4\n529316834 995684640 949078705 317773978\n3 3\n3 1\n2 6271\n1 1 856879574", "output": "949078705\n529316834" }, { "input": "5 4\n293170637 715384768 756975575 129004053 875201151\n1 3 695181967\n3 3\n2 2288\n1 5 332270946", "output": "695181967" } ]
1,694,705,915
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
11,980,800
n,m = map(int, input().split()) a = list(map(int, input().split())) x = 0 for _ in range(m): b = list(map(int, input().split())) if b[0] == 1: a[b[1]-1] = b[2]-x elif b[0] == 2: x += b[1] else: print(a[b[1]-1]+x)
Title: Sereja and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has got an array, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n*. Sereja is an active boy, so he is now going to complete *m* operations. Each operation will have one of the three forms: 1. Make *v**i*-th array element equal to *x**i*. In other words, perform the assignment *a**v**i*<==<=*x**i*. 1. Increase each array element by *y**i*. In other words, perform *n* assignments *a**i*<==<=*a**i*<=+<=*y**i* (1<=≤<=*i*<=≤<=*n*). 1. Take a piece of paper and write out the *q**i*-th array element. That is, the element *a**q**i*. Help Sereja, complete all his operations. Input Specification: The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the original array. Next *m* lines describe operations, the *i*-th line describes the *i*-th operation. The first number in the *i*-th line is integer *t**i* (1<=≤<=*t**i*<=≤<=3) that represents the operation type. If *t**i*<==<=1, then it is followed by two integers *v**i* and *x**i*, (1<=≤<=*v**i*<=≤<=*n*,<=1<=≤<=*x**i*<=≤<=109). If *t**i*<==<=2, then it is followed by integer *y**i* (1<=≤<=*y**i*<=≤<=104). And if *t**i*<==<=3, then it is followed by integer *q**i* (1<=≤<=*q**i*<=≤<=*n*). Output Specification: For each third type operation print value *a**q**i*. Print the values in the order, in which the corresponding queries follow in the input. Demo Input: ['10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n'] Demo Output: ['2\n9\n11\n20\n30\n40\n39\n'] Note: none
```python n,m = map(int, input().split()) a = list(map(int, input().split())) x = 0 for _ in range(m): b = list(map(int, input().split())) if b[0] == 1: a[b[1]-1] = b[2]-x elif b[0] == 2: x += b[1] else: print(a[b[1]-1]+x) ```
0
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1", "output": "4" }, { "input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "4" }, { "input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0", "output": "4" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0", "output": "2" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "output": "3" } ]
1,695,645,621
2,147,483,647
Python 3
OK
TESTS
25
92
0
#263a #2300011863 张骏逸 for i in range(5): l=list(map(str,input().split())) if '1' in l:#双重循环也可以找1,但是不如in x=i;y=l.index('1') dis=abs(x-2)+abs(y-2) print(dis)
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. Input Specification: The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. Output Specification: Print a single integer — the minimum number of moves needed to make the matrix beautiful. Demo Input: ['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n'] Demo Output: ['3\n', '1\n'] Note: none
```python #263a #2300011863 张骏逸 for i in range(5): l=list(map(str,input().split())) if '1' in l:#双重循环也可以找1,但是不如in x=i;y=l.index('1') dis=abs(x-2)+abs(y-2) print(dis) ```
3
126
B
Password
PROGRAMMING
1,700
[ "binary search", "dp", "hashing", "string suffix structures", "strings" ]
null
null
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
[ "fixprefixsuffix\n", "abcdabc\n" ]
[ "fix", "Just a legend" ]
none
1,000
[ { "input": "fixprefixsuffix", "output": "fix" }, { "input": "abcdabc", "output": "Just a legend" }, { "input": "qwertyqwertyqwerty", "output": "qwerty" }, { "input": "papapapap", "output": "papap" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaa" }, { "input": "ghbdtn", "output": "Just a legend" }, { "input": "a", "output": "Just a legend" }, { "input": "aa", "output": "Just a legend" }, { "input": "ab", "output": "Just a legend" }, { "input": "aaa", "output": "a" }, { "input": "aba", "output": "Just a legend" }, { "input": "aab", "output": "Just a legend" }, { "input": "abb", "output": "Just a legend" }, { "input": "abc", "output": "Just a legend" }, { "input": "aaabaabaaaaab", "output": "Just a legend" }, { "input": "aabaaabaaaaab", "output": "aab" }, { "input": "aaabaaaabab", "output": "Just a legend" }, { "input": "abcabcabcabcabc", "output": "abcabcabc" }, { "input": "aaaaabaaaa", "output": "aaaa" }, { "input": "aaaabaaaaaaa", "output": "aaaa" }, { "input": "ghghghgxghghghg", "output": "ghghg" }, { "input": "kincenvizh", "output": "Just a legend" }, { "input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw", "output": "Just a legend" }, { "input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx", "output": "Just a legend" }, { "input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb", "output": "nfbdzgdlbjhrlvfryyjb" }, { "input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp", "output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp" }, { "input": "abcazabca", "output": "a" } ]
1,598,596,416
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
14
278
0
#code s=input() s=s.lower() n=len(s) pi=[0]*n ls=[0]*26 m=0;i=1 while i<n: if s[i]==s[m]: m+=1 pi[i]=m i+=1 else: if m: m=pi[m-1] else: pi[i]=0 i+=1 cr=pi[n-1] if cr==0: print("Just a legend") else: an=s[n-cr:] ix=1 for i in range(n): if pi[i]: ix=i;break if pi.count(len(an))<2: an=an[ix:] if an: print(an) else: print("Just a legend")
Title: Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. Input Specification: You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. Output Specification: Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. Demo Input: ['fixprefixsuffix\n', 'abcdabc\n'] Demo Output: ['fix', 'Just a legend'] Note: none
```python #code s=input() s=s.lower() n=len(s) pi=[0]*n ls=[0]*26 m=0;i=1 while i<n: if s[i]==s[m]: m+=1 pi[i]=m i+=1 else: if m: m=pi[m-1] else: pi[i]=0 i+=1 cr=pi[n-1] if cr==0: print("Just a legend") else: an=s[n-cr:] ix=1 for i in range(n): if pi[i]: ix=i;break if pi.count(len(an))<2: an=an[ix:] if an: print(an) else: print("Just a legend") ```
0
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1.
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input": "18 8", "output": "888888888888888888" }, { "input": "1 5", "output": "5" }, { "input": "1 10", "output": "-1" }, { "input": "100 5", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "10 2", "output": "2222222222" }, { "input": "18 10", "output": "111111111111111110" }, { "input": "1 9", "output": "9" }, { "input": "7 6", "output": "6666666" }, { "input": "4 4", "output": "4444" }, { "input": "14 7", "output": "77777777777777" }, { "input": "3 8", "output": "888" }, { "input": "1 3", "output": "3" }, { "input": "2 8", "output": "88" }, { "input": "3 8", "output": "888" }, { "input": "4 3", "output": "3333" }, { "input": "5 9", "output": "99999" }, { "input": "4 8", "output": "8888" }, { "input": "3 4", "output": "444" }, { "input": "9 4", "output": "444444444" }, { "input": "8 10", "output": "11111110" }, { "input": "1 6", "output": "6" }, { "input": "20 3", "output": "33333333333333333333" }, { "input": "15 10", "output": "111111111111110" }, { "input": "31 4", "output": "4444444444444444444444444444444" }, { "input": "18 9", "output": "999999999999999999" }, { "input": "72 4", "output": "444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "76 8", "output": "8888888888888888888888888888888888888888888888888888888888888888888888888888" }, { "input": "12 5", "output": "555555555555" }, { "input": "54 5", "output": "555555555555555555555555555555555555555555555555555555" }, { "input": "96 10", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "15 9", "output": "999999999999999" }, { "input": "100 2", "output": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" }, { "input": "99 3", "output": "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" }, { "input": "98 4", "output": "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "97 5", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "100 6", "output": "6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666" }, { "input": "99 7", "output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "98 8", "output": "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888" }, { "input": "97 9", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "100 10", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "3 10", "output": "110" }, { "input": "2 4", "output": "44" }, { "input": "2 10", "output": "10" }, { "input": "10 10", "output": "1111111110" }, { "input": "4 10", "output": "1110" }, { "input": "25 10", "output": "1111111111111111111111110" }, { "input": "50 10", "output": "11111111111111111111111111111111111111111111111110" }, { "input": "5 10", "output": "11110" }, { "input": "99 10", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "100 10", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "1 2", "output": "2" }, { "input": "20 10", "output": "11111111111111111110" }, { "input": "99 7", "output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "89 5", "output": "55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "6 10", "output": "111110" }, { "input": "3 8", "output": "888" }, { "input": "1 9", "output": "9" }, { "input": "1 4", "output": "4" }, { "input": "100 7", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" } ]
1,687,940,824
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
n, m = map(int, input().split()) if m > n: print(-1) else: print(n * str(m))
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1. Input Specification: The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. Output Specification: Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. Demo Input: ['3 2\n'] Demo Output: ['712'] Note: none
```python n, m = map(int, input().split()) if m > n: print(-1) else: print(n * str(m)) ```
0
0
none
none
none
0
[ "none" ]
null
null
Vasya has *n* items lying in a line. The items are consecutively numbered by numbers from 1 to *n* in such a way that the leftmost item has number 1, the rightmost item has number *n*. Each item has a weight, the *i*-th item weights *w**i* kilograms. Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions: 1. Take the leftmost item with the left hand and spend *w**i*<=·<=*l* energy units (*w**i* is a weight of the leftmost item, *l* is some parameter). If the previous action was the same (left-hand), then the robot spends extra *Q**l* energy units; 1. Take the rightmost item with the right hand and spend *w**j*<=·<=*r* energy units (*w**j* is a weight of the rightmost item, *r* is some parameter). If the previous action was the same (right-hand), then the robot spends extra *Q**r* energy units; Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
The first line contains five integers *n*,<=*l*,<=*r*,<=*Q**l*,<=*Q**r* (1<=≤<=*n*<=≤<=105;<=1<=≤<=*l*,<=*r*<=≤<=100;<=1<=≤<=*Q**l*,<=*Q**r*<=≤<=104). The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=100).
In the single line print a single number — the answer to the problem.
[ "3 4 4 19 1\n42 3 99\n", "4 7 2 3 9\n1 2 3 4\n" ]
[ "576\n", "34\n" ]
Consider the first sample. As *l* = *r*, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units. The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
0
[ { "input": "3 4 4 19 1\n42 3 99", "output": "576" }, { "input": "4 7 2 3 9\n1 2 3 4", "output": "34" }, { "input": "2 100 100 10000 10000\n100 100", "output": "20000" }, { "input": "2 3 4 5 6\n1 2", "output": "11" }, { "input": "1 78 94 369 10000\n93", "output": "7254" }, { "input": "1 94 78 369 10000\n93", "output": "7254" }, { "input": "5 1 100 1 10000\n1 2 3 4 5", "output": "19" }, { "input": "5 100 1 10000 1\n1 2 3 4 5", "output": "19" }, { "input": "5 1 100 10000 1\n1 2 3 4 5", "output": "906" }, { "input": "5 100 1 1 10000\n1 2 3 4 5", "output": "312" }, { "input": "6 32 47 965 897\n7 4 1 3 5 4", "output": "948" }, { "input": "7 3 13 30 978\n1 2 3 4 5 1 7", "output": "199" }, { "input": "7 13 3 978 30\n7 1 5 4 3 2 1", "output": "199" } ]
1,587,235,200
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
155
0
from sys import stdin from itertools import accumulate def arr_sum(arr): return list(accumulate(arr, lambda x, y: x + y)) rints = lambda: [int(x) for x in stdin.readline().split()] n, l, r, ql, qr = rints() w, ans = [0] + rints(), float('inf') mem = arr_sum(w) for i in range(n): s1, s2 = mem[i] - mem[0], mem[-1] - mem[i] tem = l * s1 + r * s2 if i < n - i: tem += (n - i - i - 1) * qr elif i > n - i: tem += (i - (n - i) - 1) * ql ans = min(ans, tem) print(ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* items lying in a line. The items are consecutively numbered by numbers from 1 to *n* in such a way that the leftmost item has number 1, the rightmost item has number *n*. Each item has a weight, the *i*-th item weights *w**i* kilograms. Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions: 1. Take the leftmost item with the left hand and spend *w**i*<=·<=*l* energy units (*w**i* is a weight of the leftmost item, *l* is some parameter). If the previous action was the same (left-hand), then the robot spends extra *Q**l* energy units; 1. Take the rightmost item with the right hand and spend *w**j*<=·<=*r* energy units (*w**j* is a weight of the rightmost item, *r* is some parameter). If the previous action was the same (right-hand), then the robot spends extra *Q**r* energy units; Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items. Input Specification: The first line contains five integers *n*,<=*l*,<=*r*,<=*Q**l*,<=*Q**r* (1<=≤<=*n*<=≤<=105;<=1<=≤<=*l*,<=*r*<=≤<=100;<=1<=≤<=*Q**l*,<=*Q**r*<=≤<=104). The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=100). Output Specification: In the single line print a single number — the answer to the problem. Demo Input: ['3 4 4 19 1\n42 3 99\n', '4 7 2 3 9\n1 2 3 4\n'] Demo Output: ['576\n', '34\n'] Note: Consider the first sample. As *l* = *r*, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units. The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
```python from sys import stdin from itertools import accumulate def arr_sum(arr): return list(accumulate(arr, lambda x, y: x + y)) rints = lambda: [int(x) for x in stdin.readline().split()] n, l, r, ql, qr = rints() w, ans = [0] + rints(), float('inf') mem = arr_sum(w) for i in range(n): s1, s2 = mem[i] - mem[0], mem[-1] - mem[i] tem = l * s1 + r * s2 if i < n - i: tem += (n - i - i - 1) * qr elif i > n - i: tem += (i - (n - i) - 1) * ql ans = min(ans, tem) print(ans) ```
0
478
B
Random Teams
PROGRAMMING
1,300
[ "combinatorics", "constructive algorithms", "greedy", "math" ]
null
null
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively.
The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
[ "5 1\n", "3 2\n", "6 3\n" ]
[ "10 10\n", "1 1\n", "3 6\n" ]
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends. In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one. In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.
1,000
[ { "input": "5 1", "output": "10 10" }, { "input": "3 2", "output": "1 1" }, { "input": "6 3", "output": "3 6" }, { "input": "5 3", "output": "2 3" }, { "input": "10 2", "output": "20 36" }, { "input": "10 6", "output": "4 10" }, { "input": "1000000000 1", "output": "499999999500000000 499999999500000000" }, { "input": "5000000 12", "output": "1041664166668 12499942500066" }, { "input": "1833 195", "output": "7722 1342341" }, { "input": "1000000000 1000000000", "output": "0 0" }, { "input": "1000000000 1000000", "output": "499500000000 499000500499500000" }, { "input": "1000000000 32170", "output": "15541930838100 499967831017438365" }, { "input": "1000000 1000", "output": "499500000 499000999500" }, { "input": "1234 1123", "output": "111 6216" }, { "input": "599222887 298488", "output": "601178656545 179355218158217800" }, { "input": "999999999 500000000", "output": "499999999 124999999750000000" }, { "input": "1000000000 384842119", "output": "845473643 189209609585784021" }, { "input": "1000000000 384842119", "output": "845473643 189209609585784021" }, { "input": "1000000000 2", "output": "249999999500000000 499999998500000001" }, { "input": "1000000000 999999999", "output": "1 1" }, { "input": "38447 383", "output": "1910550 724453080" }, { "input": "100000000 99999799", "output": "201 20301" }, { "input": "1 1", "output": "0 0" }, { "input": "2 1", "output": "1 1" }, { "input": "2 2", "output": "0 0" }, { "input": "10 10", "output": "0 0" } ]
1,687,733,770
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
93
2,048,000
import math def solve(n, m): upper = math.ceil(n/m) lower = math.floor(n/m) # print(lower, upper) groups = [] for i in range(m): if (m-i)*lower == n-sum(groups): print(i) groups += [lower for _ in range(m-i)] break else: groups.append(upper) # print(groups) upper_fact = upper*(upper-1)//2 lower_fact = lower*(lower-1)//2 minn = 0 for i in groups: if i == upper: minn += upper_fact elif i == lower: minn += lower_fact maxx = (n-(m-1))*(n-m)//2 print(minn, maxx) testCases = int(input()) for _ in range(testCases): _t = input().split(" ") n = int(_t[0]) m = int(_t[1]) solve(n, m)
Title: Random Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition. Input Specification: The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. Output Specification: The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. Demo Input: ['5 1\n', '3 2\n', '6 3\n'] Demo Output: ['10 10\n', '1 1\n', '3 6\n'] Note: In the first sample all the participants get into one team, so there will be exactly ten pairs of friends. In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one. In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.
```python import math def solve(n, m): upper = math.ceil(n/m) lower = math.floor(n/m) # print(lower, upper) groups = [] for i in range(m): if (m-i)*lower == n-sum(groups): print(i) groups += [lower for _ in range(m-i)] break else: groups.append(upper) # print(groups) upper_fact = upper*(upper-1)//2 lower_fact = lower*(lower-1)//2 minn = 0 for i in groups: if i == upper: minn += upper_fact elif i == lower: minn += lower_fact maxx = (n-(m-1))*(n-m)//2 print(minn, maxx) testCases = int(input()) for _ in range(testCases): _t = input().split(" ") n = int(_t[0]) m = int(_t[1]) solve(n, m) ```
-1
960
A
Check the string
PROGRAMMING
1,200
[ "implementation" ]
null
null
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time. You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
Print "YES" or "NO", according to the condition.
[ "aaabccc\n", "bbacc\n", "aabc\n" ]
[ "YES\n", "NO\n", "YES\n" ]
Consider first example: the number of 'c' is equal to the number of 'a'. Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct. Consider third example: the number of 'c' is equal to the number of 'b'.
500
[ { "input": "aaabccc", "output": "YES" }, { "input": "bbacc", "output": "NO" }, { "input": "aabc", "output": "YES" }, { "input": "aabbcc", "output": "YES" }, { "input": "aaacccbb", "output": "NO" }, { "input": "abc", "output": "YES" }, { "input": "acba", "output": "NO" }, { "input": "bbabbc", "output": "NO" }, { "input": "bbbabacca", "output": "NO" }, { "input": "aabcbcaca", "output": "NO" }, { "input": "aaaaabbbbbb", "output": "NO" }, { "input": "c", "output": "NO" }, { "input": "cc", "output": "NO" }, { "input": "bbb", "output": "NO" }, { "input": "bc", "output": "NO" }, { "input": "ccbcc", "output": "NO" }, { "input": "aaa", "output": "NO" }, { "input": "aaccaa", "output": "NO" }, { "input": "a", "output": "NO" }, { "input": "b", "output": "NO" }, { "input": "abca", "output": "NO" }, { "input": "aabbcccc", "output": "NO" }, { "input": "abac", "output": "NO" }, { "input": "abcc", "output": "NO" }, { "input": "abcb", "output": "NO" }, { "input": "aacc", "output": "NO" }, { "input": "aabbaacccc", "output": "NO" }, { "input": "aabb", "output": "NO" }, { "input": "ac", "output": "NO" }, { "input": "abbacc", "output": "NO" }, { "input": "abacc", "output": "NO" }, { "input": "ababc", "output": "NO" }, { "input": "aa", "output": "NO" }, { "input": "aabaccc", "output": "NO" }, { "input": "bbcc", "output": "NO" }, { "input": "aaabcbc", "output": "NO" }, { "input": "acbbc", "output": "NO" }, { "input": "babc", "output": "NO" }, { "input": "bbbcc", "output": "NO" }, { "input": "bbc", "output": "NO" }, { "input": "abababccc", "output": "NO" }, { "input": "ccbbaa", "output": "NO" } ]
1,618,841,215
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
62
0
#problem90 s = input() if s[:1] == 'a': if s.count('a')==s.count('c') or s.count('b')==s.count('c'): print('YES') else: print('NO') else: print('NO')
Title: Check the string Time Limit: None seconds Memory Limit: None megabytes Problem Description: A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time. You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes). Input Specification: The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. Output Specification: Print "YES" or "NO", according to the condition. Demo Input: ['aaabccc\n', 'bbacc\n', 'aabc\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: Consider first example: the number of 'c' is equal to the number of 'a'. Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct. Consider third example: the number of 'c' is equal to the number of 'b'.
```python #problem90 s = input() if s[:1] == 'a': if s.count('a')==s.count('c') or s.count('b')==s.count('c'): print('YES') else: print('NO') else: print('NO') ```
0
404
A
Valera and X
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: - on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him.
The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
[ "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n", "3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nwsw\nsws\nwsw", "output": "YES" }, { "input": "3\nxpx\npxp\nxpe", "output": "NO" }, { "input": "5\nliiil\nilili\niilii\nilili\nliiil", "output": "YES" }, { "input": "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt", "output": "NO" }, { "input": "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo\nooooososooooo\noooosooosoooo\nooosooooosooo\noosooooooosoo\nosoooooooooso\nsooooooooooos", "output": "YES" }, { "input": "3\naaa\naaa\naaa", "output": "NO" }, { "input": "3\naca\noec\nzba", "output": "NO" }, { "input": "15\nrxeeeeeeeeeeeer\nereeeeeeeeeeere\needeeeeeeeeeoee\neeereeeeeeeewee\neeeereeeeebeeee\nqeeeereeejedyee\neeeeeerereeeeee\neeeeeeereeeeeee\neeeeeerereeeeze\neeeeereeereeeee\neeeereeeeegeeee\neeereeeeeeereee\neereeeeeeqeeved\ncreeeeeeceeeere\nreeerneeeeeeeer", "output": "NO" }, { "input": "5\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx", "output": "NO" }, { "input": "5\nxxxxx\nxxxxx\nxoxxx\nxxxxx\nxxxxx", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxxxx\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxoox\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxaxx\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\noxoxx\nxoxox\noxxxo", "output": "NO" }, { "input": "3\nxxx\naxa\nxax", "output": "NO" }, { "input": "3\nxax\naxx\nxax", "output": "NO" }, { "input": "3\nxax\naxa\nxxx", "output": "NO" }, { "input": "3\nxax\nxxa\nxax", "output": "NO" }, { "input": "3\nxax\naaa\nxax", "output": "NO" }, { "input": "3\naax\naxa\nxax", "output": "NO" }, { "input": "3\nxaa\naxa\nxax", "output": "NO" }, { "input": "3\nxax\naxa\naax", "output": "NO" }, { "input": "3\nxax\naxa\nxaa", "output": "NO" }, { "input": "3\nxfx\naxa\nxax", "output": "NO" }, { "input": "3\nxax\nafa\nxax", "output": "NO" }, { "input": "3\nxax\naxa\nxaf", "output": "NO" }, { "input": "3\nxox\nxxx\nxxx", "output": "NO" }, { "input": "3\naxa\naax\nxxa", "output": "NO" }, { "input": "3\nxox\noxx\nxox", "output": "NO" }, { "input": "3\nxox\nooo\nxox", "output": "NO" }, { "input": "3\naaa\naab\nbbb", "output": "NO" }, { "input": "3\nxxx\nsxs\nxsx", "output": "NO" }, { "input": "5\nabbba\nbabab\nbbbbb\nbaaab\nabbba", "output": "NO" }, { "input": "5\nabaaa\nbbbbb\nbbabb\nbabab\nabbba", "output": "NO" }, { "input": "5\nxoxox\noxoxo\nooxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nxox\noxx\nxxx", "output": "NO" }, { "input": "5\nxoooo\noxooo\nooxoo\noooxo\noooox", "output": "NO" }, { "input": "5\nxoooo\noxoxx\nooxoo\noxoxo\noxoox", "output": "NO" }, { "input": "3\naaa\nbab\naba", "output": "NO" } ]
1,674,965,245
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
17
77
3,993,600
import sys from math import ceil,floor,sqrt,log,dist from collections import defaultdict from operator import itemgetter rmi=lambda:map(int,input().split()) rs=lambda:input() ri=lambda:int(rs()) inf=float('inf') def f(): n=ri() mtr=[] for i in range(n): s=rs() if i==0: pred=s[0] mtr.append(s) b="" for i in range(n): if mtr[i][i]!=pred: print("NO") return 0 if mtr[i][n-i-1]!=pred: print("NO") return 0 b+=mtr[i] b=b.replace(pred,"") if len(set(b))==1: print("YES") return 0 print("NO") f()
Title: Valera and X Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: - on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. Output Specification: Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. Demo Input: ['5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n', '3\nwsw\nsws\nwsw\n', '3\nxpx\npxp\nxpe\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: none
```python import sys from math import ceil,floor,sqrt,log,dist from collections import defaultdict from operator import itemgetter rmi=lambda:map(int,input().split()) rs=lambda:input() ri=lambda:int(rs()) inf=float('inf') def f(): n=ri() mtr=[] for i in range(n): s=rs() if i==0: pred=s[0] mtr.append(s) b="" for i in range(n): if mtr[i][i]!=pred: print("NO") return 0 if mtr[i][n-i-1]!=pred: print("NO") return 0 b+=mtr[i] b=b.replace(pred,"") if len(set(b))==1: print("YES") return 0 print("NO") f() ```
0
988
A
Diverse Team
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $1$ to $n$.
[ "5 3\n15 13 15 15 12\n", "5 4\n15 13 15 15 12\n", "4 4\n20 10 40 30\n" ]
[ "YES\n1 2 5 \n", "NO\n", "YES\n1 2 3 4 \n" ]
All possible answers for the first example: - {1 2 5} - {2 3 5} - {2 4 5} Note that the order does not matter.
0
[ { "input": "5 3\n15 13 15 15 12", "output": "YES\n1 2 5 " }, { "input": "5 4\n15 13 15 15 12", "output": "NO" }, { "input": "4 4\n20 10 40 30", "output": "YES\n1 2 3 4 " }, { "input": "1 1\n1", "output": "YES\n1 " }, { "input": "100 53\n16 17 1 2 27 5 9 9 53 24 17 33 35 24 20 48 56 73 12 14 39 55 58 13 59 73 29 26 40 33 22 29 34 22 55 38 63 66 36 13 60 42 10 15 21 9 11 5 23 37 79 47 26 3 79 53 44 8 71 75 42 11 34 39 79 33 10 26 23 23 17 14 54 41 60 31 83 5 45 4 14 35 6 60 28 48 23 18 60 36 21 28 7 34 9 25 52 43 54 19", "output": "YES\n1 2 3 4 5 6 7 9 10 12 13 15 16 17 18 19 20 21 22 23 24 25 27 28 29 31 33 36 37 38 39 41 42 43 44 45 47 49 50 51 52 54 57 58 59 60 73 74 76 77 79 80 83 " }, { "input": "2 2\n100 100", "output": "NO" }, { "input": "2 2\n100 99", "output": "YES\n1 2 " }, { "input": "100 100\n63 100 75 32 53 24 73 98 76 15 70 48 8 81 88 58 95 78 27 92 14 16 72 43 46 39 66 38 64 42 59 9 22 51 4 6 10 94 28 99 68 80 35 50 45 20 47 7 30 26 49 91 77 19 96 57 65 1 11 13 31 12 82 87 93 34 62 3 21 79 56 41 89 18 44 23 74 86 2 33 69 36 61 67 25 83 5 84 90 37 40 29 97 60 52 55 54 71 17 85", "output": "YES\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 " }, { "input": "100 41\n54 16 42 3 45 6 9 72 100 13 24 57 35 5 89 13 97 27 43 9 73 89 48 16 48 55 18 15 55 28 30 6 18 41 100 61 9 42 35 54 57 25 73 15 42 54 49 5 72 48 30 55 4 43 94 5 60 92 93 23 89 75 53 92 74 93 89 28 69 6 3 49 15 28 49 57 54 55 30 57 69 18 89 6 25 23 93 74 30 13 87 53 6 42 4 54 60 30 4 35", "output": "NO" }, { "input": "100 2\n70 64 70 32 70 64 32 70 64 32 32 64 70 64 64 32 64 64 64 70 70 64 64 64 64 70 32 64 70 64 32 70 70 70 64 70 64 70 64 32 70 32 70 64 64 64 32 70 64 70 70 32 70 32 32 32 70 32 70 32 64 64 70 32 32 64 70 64 32 32 64 64 32 32 70 70 32 70 32 64 32 70 64 64 32 64 32 64 70 32 70 32 70 64 64 64 70 70 64 70", "output": "YES\n1 2 " } ]
1,678,511,896
256
Python 3
OK
TESTS
10
31
0
n,k = list(map(int,input().split())) arr = list(map(int,input().split())) ln = len(set(arr)) st = list(set(arr)) if ln<k: print("NO") else: ans =[] for i in range(k): ans.append(arr.index(st[i])+1) print('YES') print(*ans)
Title: Diverse Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them. Input Specification: The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. Output Specification: If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $1$ to $n$. Demo Input: ['5 3\n15 13 15 15 12\n', '5 4\n15 13 15 15 12\n', '4 4\n20 10 40 30\n'] Demo Output: ['YES\n1 2 5 \n', 'NO\n', 'YES\n1 2 3 4 \n'] Note: All possible answers for the first example: - {1 2 5} - {2 3 5} - {2 4 5} Note that the order does not matter.
```python n,k = list(map(int,input().split())) arr = list(map(int,input().split())) ln = len(set(arr)) st = list(set(arr)) if ln<k: print("NO") else: ans =[] for i in range(k): ans.append(arr.index(st[i])+1) print('YES') print(*ans) ```
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,690,901,910
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
5,632,000
def letrasIguais(p1, p2): p1 = sorted(p1) p2 = sorted(p2) y, w = 0, 0 iguais = True for repe in range(2): for letter in range(len(p1)-1, -1, -1): for letter2 in range(len(p2)-1, -1, -1): if iguais: if p1[letter] == p2[letter2] : y += 1 p1.pop(letter) p2.pop(letter2) break else: if p2[letter2] == chr(ord(p1[letter])+32) or p2[letter2] == chr(ord(p1[letter])-32): w += 1 p1.pop(letter) p2.pop(letter2) break iguais = False return y, w p1 = input() p2 = input() print(letrasIguais(p1, p2)[0], letrasIguais(p1, p2)[1])
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 def letrasIguais(p1, p2): p1 = sorted(p1) p2 = sorted(p2) y, w = 0, 0 iguais = True for repe in range(2): for letter in range(len(p1)-1, -1, -1): for letter2 in range(len(p2)-1, -1, -1): if iguais: if p1[letter] == p2[letter2] : y += 1 p1.pop(letter) p2.pop(letter2) break else: if p2[letter2] == chr(ord(p1[letter])+32) or p2[letter2] == chr(ord(p1[letter])-32): w += 1 p1.pop(letter) p2.pop(letter2) break iguais = False return y, w p1 = input() p2 = input() print(letrasIguais(p1, p2)[0], letrasIguais(p1, p2)[1]) ```
0
442
A
Borya and Hanabi
PROGRAMMING
1,700
[ "bitmasks", "brute force", "implementation" ]
null
null
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding *n* cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Borya's cards. The next line contains the descriptions of *n* cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in.
Print a single integer — the minimum number of hints that the other players should make.
[ "2\nG3 G3\n", "4\nG4 R4 R3 B3\n", "5\nB1 Y1 W1 G1 R1\n" ]
[ "0\n", "2\n", "4\n" ]
In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
500
[ { "input": "2\nG3 G3", "output": "0" }, { "input": "4\nG4 R4 R3 B3", "output": "2" }, { "input": "5\nB1 Y1 W1 G1 R1", "output": "4" }, { "input": "10\nY4 B1 R3 G5 R5 W3 W5 W2 R1 Y1", "output": "6" }, { "input": "3\nG4 G3 B4", "output": "2" }, { "input": "2\nW3 Y5", "output": "1" }, { "input": "2\nW5 Y5", "output": "1" }, { "input": "100\nW4 Y1 W5 R4 W3 Y1 R4 W2 G3 G1 B5 Y5 Y2 Y3 G4 B5 W1 G5 Y5 Y3 G2 Y5 Y5 G5 R2 B3 B1 W5 Y1 W5 B4 W4 R4 B1 R1 W3 R5 R4 G2 W3 W3 R2 W5 Y2 B2 R3 R3 Y1 G5 G2 Y1 R4 Y5 W5 G5 B3 W2 R1 B2 W2 W2 Y5 W3 G1 B1 G2 Y3 W3 G1 W5 W1 G5 G2 Y1 W5 B5 W4 Y5 G2 R3 B4 R5 B1 R1 B4 Y4 Y4 Y3 R5 Y3 B3 W5 R5 Y5 G2 G5 W5 B4 G4 W5", "output": "8" }, { "input": "100\nB5 G3 Y2 W3 W1 G1 Y4 G3 G4 B5 W4 B5 Y3 R5 B4 G4 G4 B1 G1 R5 G4 B4 G1 G2 W1 Y4 R5 Y3 W5 W4 Y5 W1 B4 G3 R2 R3 W1 B4 Y4 G2 G2 R1 Y5 W1 Y3 B3 G5 Y3 G3 W2 W5 Y4 B2 Y5 R4 B2 Y3 W4 G2 G3 R2 W1 B4 B2 B1 Y2 Y2 Y3 W3 Y5 W1 R1 R1 R4 R4 R4 Y1 Y3 B2 Y3 Y1 R3 G4 G4 Y5 B5 W2 G1 G5 B3 G1 Y1 R2 G5 R2 Y5 R5 Y4 R4 W2", "output": "8" }, { "input": "100\nY3 Y3 Y5 Y2 Y4 Y1 Y2 Y3 Y1 Y5 Y3 Y1 Y4 Y5 Y5 Y3 Y1 Y5 Y2 Y3 Y1 Y4 Y4 Y1 Y2 Y2 Y4 Y2 Y4 Y5 Y5 Y2 Y3 Y1 Y3 Y5 Y3 Y1 Y5 Y3 Y3 Y2 Y5 Y1 Y5 Y5 Y4 Y2 Y2 Y1 Y2 Y4 Y3 Y2 Y5 Y3 Y4 Y3 Y1 Y4 Y2 Y4 Y4 Y3 Y3 Y1 Y1 Y4 Y2 Y5 Y3 Y4 Y4 Y4 Y3 Y2 Y2 Y2 Y3 Y4 Y4 Y2 Y1 Y2 Y2 Y4 Y3 Y5 Y4 Y2 Y5 Y3 Y1 Y5 Y2 Y5 Y4 Y1 Y2 Y1", "output": "4" }, { "input": "100\nG3 B3 G3 Y3 R3 G3 R3 G3 W3 B3 B3 B3 R3 Y3 Y3 W3 R3 B3 G3 W3 G3 W3 Y3 R3 Y3 W3 W3 G3 W3 G3 W3 Y3 G3 R3 Y3 W3 W3 Y3 Y3 Y3 R3 W3 R3 G3 W3 W3 G3 Y3 B3 W3 B3 Y3 G3 Y3 B3 Y3 W3 Y3 R3 Y3 R3 W3 W3 W3 G3 Y3 G3 R3 B3 R3 Y3 R3 Y3 R3 Y3 R3 Y3 R3 W3 Y3 R3 W3 W3 W3 G3 G3 Y3 B3 Y3 R3 G3 G3 B3 B3 Y3 R3 G3 R3 W3 G3", "output": "4" }, { "input": "100\nW5 Y5 Y3 W3 Y5 Y5 W5 W5 Y3 W5 Y5 Y3 W5 Y5 W5 W3 Y3 Y5 W3 W5 Y5 W3 Y5 Y3 W3 W3 Y3 Y5 W3 W3 Y3 Y5 W3 Y5 Y5 Y5 W5 Y5 W5 Y5 W5 W5 W3 W5 W3 Y3 W5 W3 W3 W5 Y3 Y5 W5 W5 W3 W5 W5 Y5 W5 W3 W3 W3 Y3 Y5 Y5 Y3 Y5 W5 W5 Y5 W3 W3 W5 Y5 Y5 Y3 W5 W5 W3 Y5 W3 W5 Y3 Y5 W5 Y3 Y3 W3 Y3 Y5 Y3 Y3 W5 Y5 Y3 Y5 Y3 W3 Y3 W5", "output": "2" }, { "input": "100\nY5 Y5 Y3 Y5 Y3 Y5 Y5 Y5 Y3 Y3 Y5 Y3 Y3 Y5 Y3 Y3 Y5 Y3 Y3 Y5 Y3 Y5 Y5 Y3 Y3 Y5 Y3 Y5 Y3 Y3 Y3 Y5 Y3 Y3 Y3 Y3 Y3 Y3 Y3 Y5 Y5 Y5 Y5 Y3 Y5 Y5 Y5 Y5 Y3 Y3 Y3 Y5 Y5 Y3 Y3 Y3 Y5 Y3 Y3 Y5 Y3 Y3 Y3 Y5 Y3 Y5 Y5 Y5 Y5 Y3 Y3 Y5 Y5 Y5 Y5 Y5 Y5 Y5 Y5 Y3 Y5 Y5 Y5 Y5 Y5 Y5 Y3 Y5 Y3 Y5 Y5 Y5 Y5 Y5 Y5 Y3 Y3 Y3 Y5 Y5", "output": "1" }, { "input": "100\nY3 Y3 Y3 W3 W3 Y3 Y3 W3 Y3 Y3 W3 Y3 Y3 Y3 W3 Y3 Y3 W3 Y3 Y3 Y3 W3 Y3 W3 W3 W3 W3 W3 Y3 Y3 W3 Y3 Y3 W3 W3 Y3 Y3 W3 Y3 Y3 W3 W3 W3 W3 W3 Y3 Y3 Y3 Y3 W3 Y3 Y3 W3 W3 W3 Y3 W3 W3 W3 Y3 Y3 Y3 Y3 W3 W3 W3 W3 W3 Y3 Y3 W3 Y3 W3 Y3 Y3 Y3 Y3 Y3 Y3 Y3 W3 W3 W3 W3 Y3 W3 Y3 Y3 Y3 Y3 Y3 Y3 Y3 Y3 W3 Y3 Y3 W3 W3 Y3", "output": "1" }, { "input": "10\nW1 Y4 Y3 W3 Y2 W2 W1 Y2 Y3 W3", "output": "3" }, { "input": "10\nW2 R2 B5 W5 W2 B3 B2 R5 Y5 R2", "output": "5" }, { "input": "5\nW3 Y5 W2 G3 Y3", "output": "3" }, { "input": "5\nW5 G5 W2 Y5 G2", "output": "3" }, { "input": "5\nW5 W3 Y3 Y5 W2", "output": "3" }, { "input": "5\nY5 W3 W2 G5 W3", "output": "3" }, { "input": "5\nG5 G3 G5 G5 W2", "output": "2" }, { "input": "5\nW2 Y2 G3 G3 G3", "output": "2" }, { "input": "5\nG3 Y5 Y2 Y5 W3", "output": "3" }, { "input": "5\nW3 W5 Y3 W2 G5", "output": "3" }, { "input": "5\nY3 Y2 Y3 Y5 Y5", "output": "2" }, { "input": "5\nW5 Y3 W5 W5 Y5", "output": "2" }, { "input": "5\nG3 Y3 G3 Y3 G3", "output": "1" }, { "input": "5\nG4 W5 Y4 Y4 R5", "output": "3" }, { "input": "5\nG3 R2 R5 B3 W4", "output": "4" }, { "input": "5\nW2 G5 W3 R4 R4", "output": "3" }, { "input": "5\nY3 Y3 G3 Y3 W3", "output": "2" }, { "input": "5\nW5 W5 W3 Y3 Y5", "output": "2" }, { "input": "35\nG5 G5 G3 G2 G3 Y3 W3 Y3 G5 W5 G2 G2 W5 G5 G5 W3 G3 G2 Y3 W5 W3 G5 W5 G2 Y2 Y3 W5 G3 W3 W2 G2 W3 Y2 G3 G3", "output": "4" }, { "input": "35\nG3 G2 G5 G2 W2 G3 W2 W5 Y5 G5 W2 W2 W2 G5 Y2 G5 W5 W3 W2 Y2 G5 W5 W3 W5 Y2 Y5 W2 W2 W3 Y3 G2 W3 G5 G3 W2", "output": "4" }, { "input": "35\nW2 W3 Y2 G5 G2 W3 G5 Y2 W5 Y5 W3 G2 G3 W5 W2 W3 Y2 Y5 Y2 Y5 Y2 Y2 G2 Y5 W3 Y5 G3 Y2 G3 Y2 Y5 W5 G3 W5 W5", "output": "4" }, { "input": "35\nY2 Y3 Y2 Y3 Y5 Y5 Y3 Y5 Y5 Y2 Y2 Y5 Y2 Y2 Y5 Y3 Y2 Y5 Y5 Y3 Y3 Y2 Y2 Y2 Y3 Y5 Y2 Y5 Y5 Y3 Y5 Y2 Y3 Y3 Y2", "output": "2" }, { "input": "35\nY5 Y5 W5 Y5 W3 Y3 W5 W3 W5 W3 W5 Y5 Y3 W3 W5 W5 W5 W3 Y5 Y3 Y5 W5 W5 Y3 Y5 Y5 Y3 W5 W3 W3 W3 W5 Y5 W3 W5", "output": "2" }, { "input": "35\nG3 G3 W3 W3 G3 G3 Y3 G3 Y3 Y3 G3 W3 Y3 G3 W3 Y3 W3 Y3 Y3 Y3 Y3 G3 G3 Y3 Y3 G3 G3 G3 G3 G3 Y3 W3 W3 W3 G3", "output": "2" }, { "input": "35\nR2 R2 R2 R2 G3 G2 Y3 G2 R3 W5 G4 Y3 Y3 G2 Y5 W5 G4 G2 W4 Y2 W3 R5 W5 G4 G4 Y2 G2 Y5 G2 Y4 W3 G5 G2 R3 G4", "output": "6" }, { "input": "35\nG2 Y1 Y1 R4 G5 B5 R2 G4 G2 G3 W4 W1 B3 W5 R2 Y5 R4 R4 B5 Y2 B4 B1 R3 G4 Y3 G2 R4 G3 B2 G2 R3 B2 R1 W2 B4", "output": "8" }, { "input": "35\nW4 Y5 Y3 Y3 R5 W3 R5 W2 R5 Y2 R2 Y2 G2 G3 Y4 Y4 R4 Y3 G2 W2 R2 R3 Y3 W5 W2 G4 R3 R3 W2 W5 Y4 R3 W2 R4 R2", "output": "6" }, { "input": "35\nY3 Y3 Y3 Y3 Y3 Y3 W3 G3 G3 G3 W3 G3 G3 Y3 Y3 W3 G3 G3 Y3 W3 W3 Y3 Y3 G3 W3 W3 G3 Y3 Y3 W3 G3 W3 G3 W3 G3", "output": "2" }, { "input": "35\nW3 Y3 W3 W5 Y5 W3 W3 Y5 W3 W3 W3 W5 W3 Y3 Y5 Y3 Y5 Y3 W3 W3 W5 W5 W3 Y5 W3 W3 Y3 W3 W5 W3 Y3 Y3 Y5 Y5 Y3", "output": "2" }, { "input": "25\nY3 R2 R2 Y2 Y5 Y4 B3 B3 Y4 W3 R1 W3 W5 B5 R1 Y4 B4 B5 B3 G3 B1 R2 R4 G5 Y5", "output": "7" }, { "input": "25\nW5 R1 Y3 G5 G3 G5 W2 Y1 R3 R4 B3 G5 G2 Y2 W1 G2 Y1 B4 Y2 G3 G3 Y4 W3 W5 Y2", "output": "7" }, { "input": "25\nY1 W2 G3 W1 G1 G3 G4 W1 B2 W3 R4 B1 G2 Y4 G1 R2 R3 Y4 B2 G4 W2 Y2 R2 Y5 R4", "output": "7" }, { "input": "25\nB3 Y1 R3 Y3 R5 B4 B3 G1 R1 B4 B5 W3 R4 W1 B3 Y3 B3 Y4 B2 G5 Y1 G5 R4 B5 Y1", "output": "7" }, { "input": "25\nG4 R4 Y1 Y4 R3 B5 W2 G4 B5 B2 G1 B4 R4 G2 Y3 Y4 G5 Y3 R1 G2 Y5 G3 Y3 Y4 W3", "output": "8" }, { "input": "25\nR1 R3 G1 B5 Y5 W3 R4 R4 R1 G3 R2 W1 B1 G2 W2 G4 R2 W3 B1 W3 B5 Y5 R2 B4 B5", "output": "7" }, { "input": "5\nW3 B1 Y1 R3 Y5", "output": "3" }, { "input": "4\nR1 R2 G1 Y5", "output": "2" }, { "input": "4\nR1 R2 G1 B3", "output": "2" }, { "input": "15\nY3 R4 G1 W1 R3 R2 W4 W1 R5 Y4 G3 R5 Y2 W1 Y1", "output": "6" }, { "input": "4\nG5 W5 W4 R3", "output": "2" } ]
1,525,611,664
2,147,483,647
Python 3
OK
TESTS
54
171
7,475,200
from itertools import chain, combinations from copy import deepcopy def powerset(iterable): s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) n = int(input()) locations = input().split() matrixG = [[0]*5 for i in range(5)] for i in locations: if i[0] == "R": matrixG[0][int(i[1])-1] += 1 elif i[0] == "G": matrixG[1][int(i[1])-1] += 1 elif i[0] == "B": matrixG[2][int(i[1])-1] += 1 elif i[0] == "Y": matrixG[3][int(i[1])-1] += 1 elif i[0] == "W": matrixG[4][int(i[1])-1] += 1 for i in list(powerset(range(10))): matrix = deepcopy(matrixG) color = [] value = [] for j in i: if j <= 4: color.append(j) else: value.append(j) for v in value: for c in color: matrix[c][v-5] = 0 ctr = 0 for r in range(5): if matrix[r][v-5] == 0: ctr += 1 if ctr == 4: for r in range(5): matrix[r][v-5] = 0 for c in color: if matrix[c].count(0) == 4: matrix[c] = [0]*5 ctr = 0 for k in range(5): for j in range(5): if matrix[k][j] == 0: ctr += 1 if ctr == 24: print(len(i)) break
Title: Borya and Hanabi Time Limit: None seconds Memory Limit: None megabytes Problem Description: Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding *n* cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Borya's cards. The next line contains the descriptions of *n* cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. Output Specification: Print a single integer — the minimum number of hints that the other players should make. Demo Input: ['2\nG3 G3\n', '4\nG4 R4 R3 B3\n', '5\nB1 Y1 W1 G1 R1\n'] Demo Output: ['0\n', '2\n', '4\n'] Note: In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
```python from itertools import chain, combinations from copy import deepcopy def powerset(iterable): s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) n = int(input()) locations = input().split() matrixG = [[0]*5 for i in range(5)] for i in locations: if i[0] == "R": matrixG[0][int(i[1])-1] += 1 elif i[0] == "G": matrixG[1][int(i[1])-1] += 1 elif i[0] == "B": matrixG[2][int(i[1])-1] += 1 elif i[0] == "Y": matrixG[3][int(i[1])-1] += 1 elif i[0] == "W": matrixG[4][int(i[1])-1] += 1 for i in list(powerset(range(10))): matrix = deepcopy(matrixG) color = [] value = [] for j in i: if j <= 4: color.append(j) else: value.append(j) for v in value: for c in color: matrix[c][v-5] = 0 ctr = 0 for r in range(5): if matrix[r][v-5] == 0: ctr += 1 if ctr == 4: for r in range(5): matrix[r][v-5] = 0 for c in color: if matrix[c].count(0) == 4: matrix[c] = [0]*5 ctr = 0 for k in range(5): for j in range(5): if matrix[k][j] == 0: ctr += 1 if ctr == 24: print(len(i)) break ```
3
525
C
Ilya and Sticks
PROGRAMMING
1,600
[ "greedy", "math", "sortings" ]
null
null
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed. Sticks with lengths *a*1, *a*2, *a*3 and *a*4 can make a rectangle if the following properties are observed: - *a*1<=≤<=*a*2<=≤<=*a*3<=≤<=*a*4 - *a*1<==<=*a*2 - *a*3<==<=*a*4 A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4. A rectangle cannot be made of, for example, sticks 5 5 5 7. Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can either stay at this length or be transformed into a stick of length 4. You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of the available sticks. The second line of the input contains *n* positive integers *l**i* (2<=≤<=*l**i*<=≤<=106) — the lengths of the sticks.
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
[ "4\n2 4 4 2\n", "4\n2 2 3 5\n", "4\n100003 100004 100005 100006\n" ]
[ "8\n", "0\n", "10000800015\n" ]
none
1,000
[ { "input": "4\n2 4 4 2", "output": "8" }, { "input": "4\n2 2 3 5", "output": "0" }, { "input": "4\n100003 100004 100005 100006", "output": "10000800015" }, { "input": "8\n5 3 3 3 3 4 4 4", "output": "25" }, { "input": "10\n123 124 123 124 2 2 2 2 9 9", "output": "15270" }, { "input": "8\n10 10 10 10 11 10 11 10", "output": "210" }, { "input": "1\n1000000", "output": "0" }, { "input": "10\n10519 10519 10520 10520 10520 10521 10521 10521 10522 10523", "output": "221372362" }, { "input": "100\n4116 4116 4117 4117 4117 4117 4118 4119 4119 4119 4119 4120 4120 4120 4120 4121 4122 4123 4123 4123 4123 4124 4124 4124 4124 4125 4126 4126 4126 4126 4127 4127 4127 4127 4128 4128 4128 4128 4129 4129 4130 4130 4131 4132 4133 4133 4134 4134 4135 4135 4136 4137 4137 4137 4138 4139 4140 4140 4141 4141 4142 4143 4143 4143 4144 4144 4144 4144 4145 4145 4145 4146 4146 4146 4147 4147 4147 4147 4148 4148 4148 4149 4149 4149 4150 4151 4151 4151 4152 4152 4153 4153 4154 4154 4155 4155 4155 4155 4156 4156", "output": "427591742" }, { "input": "10\n402840 873316 567766 493234 711262 291654 683001 496971 64909 190173", "output": "0" }, { "input": "45\n1800 4967 1094 551 871 3505 846 960 4868 4304 2112 496 2293 2128 2430 2119 4497 2159 774 4520 3535 1013 452 1458 1895 1191 958 1133 416 2613 4172 3926 1665 4237 539 101 2448 1212 2631 4530 3026 412 1006 2515 1922", "output": "0" }, { "input": "69\n2367 2018 3511 1047 1789 2332 1082 4678 2036 4108 2357 339 536 2272 3638 2588 754 3795 375 506 3243 1033 4531 1216 4266 2547 3540 4642 1256 2248 4705 14 629 876 2304 1673 4186 2356 3172 2664 3896 552 4293 1507 3307 2661 3143 4565 58 1298 4380 2738 917 2054 2676 4464 1314 3752 3378 1823 4219 3142 4258 1833 886 4286 4040 1070 2206", "output": "7402552" }, { "input": "93\n13 2633 3005 1516 2681 3262 1318 1935 665 2450 2601 1644 214 929 4873 955 1983 3945 3488 2927 1516 1026 2150 974 150 2442 2610 1664 636 3369 266 2536 3132 2515 2582 1169 4462 4961 200 2848 4793 2795 4657 474 2640 2488 378 544 1805 1390 1548 2683 1474 4027 1724 2078 183 3717 1727 1780 552 2905 4260 1444 2906 3779 400 1491 1467 4480 3680 2539 4681 2875 4021 2711 106 853 3094 4531 4066 372 2129 2577 3996 2350 943 4478 3058 3333 4592 232 2780", "output": "4403980" }, { "input": "21\n580 3221 3987 2012 35 629 1554 654 756 2254 4307 2948 3457 4612 4620 4320 1777 556 3088 348 1250", "output": "0" }, { "input": "45\n4685 272 3481 3942 952 3020 329 4371 2923 2057 4526 2791 1674 3269 829 2713 3006 2166 1228 2795 983 1065 3875 4028 3429 3720 697 734 4393 1176 2820 1173 4598 2281 2549 4341 1504 172 4230 1193 3022 3742 1232 3433 1871", "output": "0" }, { "input": "69\n3766 2348 4437 4438 3305 386 2026 1629 1552 400 4770 4069 4916 1926 2037 1079 2801 854 803 216 2152 4622 1494 3786 775 3615 4766 2781 235 836 1892 2234 3563 1843 4314 3836 320 2776 4796 1378 380 2421 3057 964 4717 1122 620 530 3455 1639 1618 3109 3120 564 2382 1995 1173 4510 286 1088 218 734 2779 3738 456 1668 4476 2780 3555", "output": "12334860" }, { "input": "4\n2 2 2 4", "output": "0" }, { "input": "8\n10 10 10 11 14 14 14 16", "output": "140" }, { "input": "2\n2 3", "output": "0" }, { "input": "3\n2 3 5", "output": "0" }, { "input": "8\n2 1000000 2 1000000 2 1000000 2 1000000", "output": "1000000000004" }, { "input": "4\n2 4 6 8", "output": "0" }, { "input": "4\n2 3 6 8", "output": "0" }, { "input": "5\n2 2 3 4 5", "output": "8" }, { "input": "5\n1000000 999999 999999 999999 999999", "output": "999998000001" }, { "input": "6\n2 2 2 2 2 2", "output": "4" }, { "input": "4\n2 4 5 5", "output": "0" }, { "input": "20\n4 4 8 4 5 6 7 4 5 4 6 4 4 5 7 6 5 8 8 4", "output": "149" }, { "input": "10\n8 4 6 6 8 5 7 7 6 8", "output": "92" }, { "input": "11\n4 4 9 9 3 8 8 8 6 4 3", "output": "84" }, { "input": "8\n2 3 3 4 4 5 5 5", "output": "26" }, { "input": "4\n3 3 3 2", "output": "6" }, { "input": "5\n3 3 10 100 100", "output": "300" }, { "input": "8\n9 9 9 8 8 7 7 6", "output": "114" }, { "input": "4\n5 6 6 7", "output": "30" }, { "input": "5\n9 9 5 2 2", "output": "18" }, { "input": "6\n3 4 100 200 1001 1002", "output": "3003" }, { "input": "6\n3 4 5 100 101 102", "output": "404" }, { "input": "5\n2 2 4 6 6", "output": "12" }, { "input": "6\n2 3 8 10 13 14", "output": "26" }, { "input": "7\n2 2 2 2 2 2 2", "output": "4" }, { "input": "5\n5 2 2 2 2", "output": "4" }, { "input": "6\n3 4 100 200 1000 1001", "output": "3000" }, { "input": "5\n5 5 7 9 9", "output": "45" }, { "input": "5\n8 8 7 4 4", "output": "32" }, { "input": "5\n2 2 5 8 9", "output": "16" }, { "input": "5\n4 4 4 2 2", "output": "8" }, { "input": "5\n3 10 100 1000 10000", "output": "0" }, { "input": "6\n10 10 7 4 2 2", "output": "20" }, { "input": "6\n5 5 7 9 10 10", "output": "50" }, { "input": "7\n10 10 7 5 3 2 2", "output": "20" }, { "input": "7\n10 9 9 9 9 2 2", "output": "81" } ]
1,597,144,414
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
156
20,275,200
from collections import Counter n = int(input()) v = list(map(int ,input().split())) temp = dict(Counter(v)) rec = [] for item1,item2 in temp.items(): l_temp = [] l_temp.append(item1) l_temp.append(item2) rec.append(l_temp) rec.sort(reverse=True) ans = 0 for i in range(0,len(rec)): ans += (rec[i][1]//4)*rec[i][0]*rec[i][0] rec[i][1] -= (rec[i][1]//4)*4 if((rec[i][1] == 3 or rec[i][1] == 1) and i+1 < len(rec) and rec[i][0] - 1 == rec[i+1][0]): rec[i][1] -= 1 rec[i+1][1] += 1 fin = [] for i in range(0,len(rec)) : if(rec[i][1] >= 2): fin.append(rec[i][0]) for i in range(1,len(fin),2) : ans += fin[i]*fin[i-1] print(ans)
Title: Ilya and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed. Sticks with lengths *a*1, *a*2, *a*3 and *a*4 can make a rectangle if the following properties are observed: - *a*1<=≤<=*a*2<=≤<=*a*3<=≤<=*a*4 - *a*1<==<=*a*2 - *a*3<==<=*a*4 A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4. A rectangle cannot be made of, for example, sticks 5 5 5 7. Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can either stay at this length or be transformed into a stick of length 4. You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks? Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of the available sticks. The second line of the input contains *n* positive integers *l**i* (2<=≤<=*l**i*<=≤<=106) — the lengths of the sticks. Output Specification: The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks. Demo Input: ['4\n2 4 4 2\n', '4\n2 2 3 5\n', '4\n100003 100004 100005 100006\n'] Demo Output: ['8\n', '0\n', '10000800015\n'] Note: none
```python from collections import Counter n = int(input()) v = list(map(int ,input().split())) temp = dict(Counter(v)) rec = [] for item1,item2 in temp.items(): l_temp = [] l_temp.append(item1) l_temp.append(item2) rec.append(l_temp) rec.sort(reverse=True) ans = 0 for i in range(0,len(rec)): ans += (rec[i][1]//4)*rec[i][0]*rec[i][0] rec[i][1] -= (rec[i][1]//4)*4 if((rec[i][1] == 3 or rec[i][1] == 1) and i+1 < len(rec) and rec[i][0] - 1 == rec[i+1][0]): rec[i][1] -= 1 rec[i+1][1] += 1 fin = [] for i in range(0,len(rec)) : if(rec[i][1] >= 2): fin.append(rec[i][0]) for i in range(1,len(fin),2) : ans += fin[i]*fin[i-1] print(ans) ```
0
106
B
Choosing Laptop
PROGRAMMING
1,000
[ "brute force", "implementation" ]
B. Choosing Laptop
2
256
Vasya is choosing a laptop. The shop has *n* laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one. There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him.
The first line contains number *n* (1<=≤<=*n*<=≤<=100). Then follow *n* lines. Each describes a laptop as *speed* *ram* *hdd* *cost*. Besides, - *speed*, *ram*, *hdd* and *cost* are integers - 1000<=≤<=*speed*<=≤<=4200 is the processor's speed in megahertz - 256<=≤<=*ram*<=≤<=4096 the RAM volume in megabytes - 1<=≤<=*hdd*<=≤<=500 is the HDD in gigabytes - 100<=≤<=*cost*<=≤<=1000 is price in tugriks All laptops have different prices.
Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to *n* in the order in which they are given in the input data.
[ "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n" ]
[ "4" ]
In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
1,000
[ { "input": "5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150", "output": "4" }, { "input": "2\n1500 500 50 755\n1600 600 80 700", "output": "2" }, { "input": "2\n1500 512 50 567\n1600 400 70 789", "output": "1" }, { "input": "4\n1000 300 5 700\n1100 400 10 600\n1200 500 15 500\n1300 600 20 400", "output": "4" }, { "input": "10\n2123 389 397 747\n2705 3497 413 241\n3640 984 470 250\n3013 2004 276 905\n3658 3213 353 602\n1428 626 188 523\n2435 1140 459 824\n2927 2586 237 860\n2361 4004 386 719\n2863 2429 476 310", "output": "2" }, { "input": "25\n2123 389 397 747\n2705 3497 413 241\n3640 984 470 250\n3013 2004 276 905\n3658 3213 353 602\n1428 626 188 523\n2435 1140 459 824\n2927 2586 237 860\n2361 4004 386 719\n2863 2429 476 310\n3447 3875 1 306\n3950 1901 31 526\n4130 1886 152 535\n1951 1840 122 814\n1798 3722 474 106\n2305 3979 82 971\n3656 3148 349 992\n1062 1648 320 491\n3113 3706 302 542\n3545 1317 184 853\n1277 2153 95 492\n2189 3495 427 655\n4014 3030 22 963\n1455 3840 155 485\n2760 717 309 891", "output": "15" }, { "input": "1\n1200 512 300 700", "output": "1" }, { "input": "1\n4200 4096 500 1000", "output": "1" }, { "input": "1\n1000 256 1 100", "output": "1" }, { "input": "2\n2000 500 200 100\n3000 600 100 200", "output": "1" }, { "input": "2\n2000 500 200 200\n3000 600 100 100", "output": "2" }, { "input": "2\n2000 600 100 100\n3000 500 200 200", "output": "1" }, { "input": "2\n2000 700 100 200\n3000 500 200 100", "output": "2" }, { "input": "2\n3000 500 100 100\n1500 600 200 200", "output": "1" }, { "input": "2\n3000 500 100 300\n1500 600 200 200", "output": "2" }, { "input": "3\n3467 1566 191 888\n3047 3917 3 849\n1795 1251 97 281", "output": "2" }, { "input": "4\n3835 1035 5 848\n2222 3172 190 370\n2634 2698 437 742\n1748 3112 159 546", "output": "2" }, { "input": "5\n3511 981 276 808\n3317 2320 354 878\n3089 702 20 732\n1088 2913 327 756\n3837 691 173 933", "output": "4" }, { "input": "6\n1185 894 287 455\n2465 3317 102 240\n2390 2353 81 615\n2884 603 170 826\n3202 2070 320 184\n3074 3776 497 466", "output": "5" }, { "input": "7\n3987 1611 470 720\n1254 4048 226 626\n1747 630 25 996\n2336 2170 402 123\n1902 3952 337 663\n1416 271 77 499\n1802 1399 419 929", "output": "4" }, { "input": "10\n3888 1084 420 278\n2033 277 304 447\n1774 514 61 663\n2055 3437 67 144\n1237 1590 145 599\n3648 663 244 525\n3691 2276 332 504\n1496 2655 324 313\n2462 1930 13 644\n1811 331 390 284", "output": "4" }, { "input": "13\n3684 543 70 227\n3953 1650 151 681\n2452 655 102 946\n3003 990 121 411\n2896 1936 158 155\n1972 717 366 754\n3989 2237 32 521\n2738 2140 445 965\n2884 1772 251 369\n2240 741 465 209\n4073 2812 494 414\n3392 955 425 133\n4028 717 90 123", "output": "11" }, { "input": "17\n3868 2323 290 182\n1253 3599 38 217\n2372 354 332 897\n1286 649 332 495\n1642 1643 301 216\n1578 792 140 299\n3329 3039 359 525\n1362 2006 172 183\n1058 3961 423 591\n3196 914 484 675\n3032 3752 217 954\n2391 2853 171 579\n4102 3170 349 516\n1218 1661 451 354\n3375 1997 196 404\n1030 918 198 893\n2546 2029 399 647", "output": "14" }, { "input": "22\n1601 1091 249 107\n2918 3830 312 767\n4140 409 393 202\n3485 2409 446 291\n2787 530 272 147\n2303 3400 265 206\n2164 1088 143 667\n1575 2439 278 863\n2874 699 369 568\n4017 1625 368 641\n3446 916 53 509\n3627 3229 328 256\n1004 2525 109 670\n2369 3299 57 351\n4147 3038 73 309\n3510 3391 390 470\n3308 3139 268 736\n3733 1054 98 809\n3967 2992 408 873\n2104 3191 83 687\n2223 2910 209 563\n1406 2428 147 673", "output": "3" }, { "input": "27\n1689 1927 40 270\n3833 2570 167 134\n2580 3589 390 300\n1898 2587 407 316\n1841 2772 411 187\n1296 288 407 506\n1215 263 236 307\n2737 1427 84 992\n1107 1879 284 866\n3311 2507 475 147\n2951 2214 209 375\n1352 2582 110 324\n2082 747 289 521\n2226 1617 209 108\n2253 1993 109 835\n2866 2360 29 206\n1431 3581 185 918\n3800 1167 463 943\n4136 1156 266 490\n3511 1396 478 169\n3498 1419 493 792\n2660 2165 204 172\n3509 2358 178 469\n1568 3564 276 319\n3871 2660 472 366\n3569 2829 146 761\n1365 2943 460 611", "output": "10" }, { "input": "2\n1000 2000 300 120\n1000 2000 300 130", "output": "1" }, { "input": "10\n2883 1110 230 501\n2662 821 163 215\n2776 1131 276 870\n2776 1131 276 596\n2776 1131 276 981\n2662 821 163 892\n2662 821 163 997\n2883 1110 230 132\n2776 1131 276 317\n2883 1110 230 481", "output": "8" }, { "input": "23\n1578 3681 380 163\n2640 3990 180 576\n3278 2311 131 386\n3900 513 443 873\n1230 1143 267 313\n2640 3990 180 501\n1230 1143 267 428\n1578 3681 380 199\n1578 3681 380 490\n3900 513 443 980\n3900 513 443 882\n3278 2311 131 951\n3278 2311 131 863\n2640 3990 180 916\n3278 2311 131 406\n3278 2311 131 455\n3278 2311 131 239\n1230 1143 267 439\n3900 513 443 438\n3900 513 443 514\n3278 2311 131 526\n1578 3681 380 123\n1578 3681 380 263", "output": "22" }, { "input": "6\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n1000 256 1 100", "output": "4" }, { "input": "2\n1000 256 1 100\n1000 256 1 101", "output": "1" }, { "input": "2\n1500 500 300 1000\n1500 500 300 900", "output": "2" }, { "input": "4\n1000 256 1 500\n1000 256 1 400\n1000 256 1 300\n1000 256 1 200", "output": "4" }, { "input": "3\n1500 1024 300 150\n1200 512 150 100\n1000 256 50 200", "output": "1" } ]
1,595,958,796
2,147,483,647
Python 3
OK
TESTS
55
218
6,963,200
n = int(input().rstrip()) l = [] for i in range(n): c, m, h, p = map(int, input().rstrip().split()) l.append([c, m, h, p]) mn = 0 for i in range(n): o = False for j in range(n): if i == j: continue if (l[i][0] < l[j][0] and l[i][1] < l[j][1] and l[i][2] < l[j][2]): o = True break if not o: if mn is 0 or l[i][3] < mn: mn = l[i][3] a = i print(a + 1)
Title: Choosing Laptop Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is choosing a laptop. The shop has *n* laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one. There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=100). Then follow *n* lines. Each describes a laptop as *speed* *ram* *hdd* *cost*. Besides, - *speed*, *ram*, *hdd* and *cost* are integers - 1000<=≤<=*speed*<=≤<=4200 is the processor's speed in megahertz - 256<=≤<=*ram*<=≤<=4096 the RAM volume in megabytes - 1<=≤<=*hdd*<=≤<=500 is the HDD in gigabytes - 100<=≤<=*cost*<=≤<=1000 is price in tugriks All laptops have different prices. Output Specification: Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to *n* in the order in which they are given in the input data. Demo Input: ['5\n2100 512 150 200\n2000 2048 240 350\n2300 1024 200 320\n2500 2048 80 300\n2000 512 180 150\n'] Demo Output: ['4'] Note: In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.
```python n = int(input().rstrip()) l = [] for i in range(n): c, m, h, p = map(int, input().rstrip().split()) l.append([c, m, h, p]) mn = 0 for i in range(n): o = False for j in range(n): if i == j: continue if (l[i][0] < l[j][0] and l[i][1] < l[j][1] and l[i][2] < l[j][2]): o = True break if not o: if mn is 0 or l[i][3] < mn: mn = l[i][3] a = i print(a + 1) ```
3.93253
898
B
Proper Nutrition
PROGRAMMING
1,100
[ "brute force", "implementation", "number theory" ]
null
null
Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars. Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* burles. In other words, you should find two non-negative integers *x* and *y* such that Vasya can buy *x* bottles of Ber-Cola and *y* Bars bars and *x*·*a*<=+<=*y*·*b*<==<=*n* or tell that it's impossible.
First line contains single integer *n* (1<=≤<=*n*<=≤<=10<=000<=000) — amount of money, that Vasya has. Second line contains single integer *a* (1<=≤<=*a*<=≤<=10<=000<=000) — cost of one bottle of Ber-Cola. Third line contains single integer *b* (1<=≤<=*b*<=≤<=10<=000<=000) — cost of one Bars bar.
If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly *n* burles print «NO» (without quotes). Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers *x* and *y* — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly *n* burles, i.e. *x*·*a*<=+<=*y*·*b*<==<=*n*. If there are multiple answers print any of them. Any of numbers *x* and *y* can be equal 0.
[ "7\n2\n3\n", "100\n25\n10\n", "15\n4\n8\n", "9960594\n2551\n2557\n" ]
[ "YES\n2 1\n", "YES\n0 10\n", "NO\n", "YES\n1951 1949\n" ]
In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles. In second example Vasya can spend exactly *n* burles multiple ways: - buy two bottles of Ber-Cola and five Bars bars; - buy four bottles of Ber-Cola and don't buy Bars bars; - don't buy Ber-Cola and buy 10 Bars bars. In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly *n* burles.
750
[ { "input": "7\n2\n3", "output": "YES\n2 1" }, { "input": "100\n25\n10", "output": "YES\n0 10" }, { "input": "15\n4\n8", "output": "NO" }, { "input": "9960594\n2551\n2557", "output": "YES\n1951 1949" }, { "input": "10000000\n1\n1", "output": "YES\n0 10000000" }, { "input": "9999999\n9999\n9999", "output": "NO" }, { "input": "9963629\n2591\n2593", "output": "YES\n635 3208" }, { "input": "1\n7\n8", "output": "NO" }, { "input": "9963630\n2591\n2593", "output": "YES\n1931 1913" }, { "input": "7516066\n1601\n4793", "output": "YES\n4027 223" }, { "input": "6509546\n1607\n6221", "output": "YES\n617 887" }, { "input": "2756250\n8783\n29", "output": "YES\n21 88683" }, { "input": "7817510\n2377\n743", "output": "YES\n560 8730" }, { "input": "6087210\n1583\n1997", "output": "YES\n1070 2200" }, { "input": "4\n2\n2", "output": "YES\n0 2" }, { "input": "7996960\n4457\n5387", "output": "YES\n727 883" }, { "input": "7988988\n4021\n3169", "output": "YES\n1789 251" }, { "input": "4608528\n9059\n977", "output": "YES\n349 1481" }, { "input": "8069102\n2789\n47", "output": "YES\n3 171505" }, { "input": "3936174\n4783\n13", "output": "YES\n5 300943" }, { "input": "10000000\n9999999\n1", "output": "YES\n0 10000000" }, { "input": "10000000\n1\n9999999", "output": "YES\n1 1" }, { "input": "4\n1\n3", "output": "YES\n1 1" }, { "input": "4\n1\n2", "output": "YES\n0 2" }, { "input": "4\n3\n1", "output": "YES\n0 4" }, { "input": "4\n2\n1", "output": "YES\n0 4" }, { "input": "100\n10\n20", "output": "YES\n0 5" }, { "input": "101\n11\n11", "output": "NO" }, { "input": "121\n11\n11", "output": "YES\n0 11" }, { "input": "25\n5\n6", "output": "YES\n5 0" }, { "input": "1\n1\n1", "output": "YES\n0 1" }, { "input": "10000000\n2\n1", "output": "YES\n0 10000000" }, { "input": "10000000\n1234523\n1", "output": "YES\n0 10000000" }, { "input": "10000000\n5000000\n5000000", "output": "YES\n0 2" }, { "input": "10000000\n5000001\n5000000", "output": "YES\n0 2" }, { "input": "10000000\n5000000\n5000001", "output": "YES\n2 0" }, { "input": "9999999\n9999999\n9999999", "output": "YES\n0 1" }, { "input": "10000000\n10000000\n10000000", "output": "YES\n0 1" }, { "input": "10\n1\n3", "output": "YES\n1 3" }, { "input": "97374\n689\n893", "output": "NO" }, { "input": "100096\n791\n524", "output": "NO" }, { "input": "75916\n651\n880", "output": "NO" }, { "input": "110587\n623\n806", "output": "NO" }, { "input": "5600\n670\n778", "output": "NO" }, { "input": "81090\n527\n614", "output": "NO" }, { "input": "227718\n961\n865", "output": "NO" }, { "input": "10000000\n3\n999999", "output": "NO" }, { "input": "3\n4\n5", "output": "NO" }, { "input": "9999999\n2\n2", "output": "NO" }, { "input": "9999999\n2\n4", "output": "NO" }, { "input": "9999997\n2\n5", "output": "YES\n1 1999999" }, { "input": "9366189\n4326262\n8994187", "output": "NO" }, { "input": "1000000\n1\n10000000", "output": "YES\n1000000 0" }, { "input": "9999991\n2\n2", "output": "NO" }, { "input": "10000000\n7\n7", "output": "NO" }, { "input": "9999991\n2\n4", "output": "NO" }, { "input": "10000000\n3\n6", "output": "NO" }, { "input": "10000000\n11\n11", "output": "NO" }, { "input": "4\n7\n3", "output": "NO" }, { "input": "1000003\n2\n2", "output": "NO" }, { "input": "1000000\n7\n7", "output": "NO" }, { "input": "999999\n2\n2", "output": "NO" }, { "input": "8\n13\n5", "output": "NO" }, { "input": "1000003\n15\n3", "output": "NO" }, { "input": "7\n7\n2", "output": "YES\n1 0" }, { "input": "9999999\n2\n8", "output": "NO" }, { "input": "1000000\n3\n7", "output": "YES\n5 142855" }, { "input": "9999999\n1\n10000000", "output": "YES\n9999999 0" }, { "input": "100\n1\n1000000", "output": "YES\n100 0" }, { "input": "10000000\n9999999\n9999997", "output": "NO" }, { "input": "2\n1\n3", "output": "YES\n2 0" }, { "input": "3\n5\n2", "output": "NO" }, { "input": "5\n2\n3", "output": "YES\n1 1" }, { "input": "10000000\n7\n14", "output": "NO" }, { "input": "10000000\n2\n9999999", "output": "YES\n5000000 0" }, { "input": "10000000\n3\n3", "output": "NO" }, { "input": "1\n3\n2", "output": "NO" }, { "input": "25\n27\n2", "output": "NO" }, { "input": "3\n2\n17", "output": "NO" }, { "input": "999997\n4\n8", "output": "NO" }, { "input": "2000000\n1\n2000001", "output": "YES\n2000000 0" }, { "input": "8\n7\n3", "output": "NO" }, { "input": "7005920\n5705\n28145", "output": "NO" }, { "input": "2\n6\n4", "output": "NO" }, { "input": "10000000\n9999999\n3", "output": "NO" }, { "input": "10000000\n77\n99", "output": "NO" }, { "input": "100\n8\n70", "output": "NO" }, { "input": "99999\n2\n2", "output": "NO" }, { "input": "5\n7\n2", "output": "NO" }, { "input": "999999\n12\n14", "output": "NO" }, { "input": "100\n1\n1000", "output": "YES\n100 0" }, { "input": "10000000\n123\n321", "output": "NO" }, { "input": "9369319\n4\n2", "output": "NO" }, { "input": "9999998\n3\n3", "output": "NO" }, { "input": "85\n5\n85", "output": "YES\n0 1" }, { "input": "64549\n9999999\n2", "output": "NO" }, { "input": "10000000\n3\n7", "output": "YES\n1 1428571" }, { "input": "9999889\n2\n2", "output": "NO" }, { "input": "10000000\n9999999\n123", "output": "NO" }, { "input": "64549\n2\n9999999", "output": "NO" } ]
1,543,299,909
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
46
1,000
0
from sys import stdin, stdout n = int(stdin.readline()) a = int(stdin.readline()) b = int(stdin.readline()) x = 0 flg = False while n >= 0: if int(n / b) == n / b: print("YES") print(x, int(n / b)) flg = True break n = n - a x += 1 if not flg: print("NO")
Title: Proper Nutrition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars. Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* burles. In other words, you should find two non-negative integers *x* and *y* such that Vasya can buy *x* bottles of Ber-Cola and *y* Bars bars and *x*·*a*<=+<=*y*·*b*<==<=*n* or tell that it's impossible. Input Specification: First line contains single integer *n* (1<=≤<=*n*<=≤<=10<=000<=000) — amount of money, that Vasya has. Second line contains single integer *a* (1<=≤<=*a*<=≤<=10<=000<=000) — cost of one bottle of Ber-Cola. Third line contains single integer *b* (1<=≤<=*b*<=≤<=10<=000<=000) — cost of one Bars bar. Output Specification: If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly *n* burles print «NO» (without quotes). Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers *x* and *y* — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly *n* burles, i.e. *x*·*a*<=+<=*y*·*b*<==<=*n*. If there are multiple answers print any of them. Any of numbers *x* and *y* can be equal 0. Demo Input: ['7\n2\n3\n', '100\n25\n10\n', '15\n4\n8\n', '9960594\n2551\n2557\n'] Demo Output: ['YES\n2 1\n', 'YES\n0 10\n', 'NO\n', 'YES\n1951 1949\n'] Note: In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles. In second example Vasya can spend exactly *n* burles multiple ways: - buy two bottles of Ber-Cola and five Bars bars; - buy four bottles of Ber-Cola and don't buy Bars bars; - don't buy Ber-Cola and buy 10 Bars bars. In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly *n* burles.
```python from sys import stdin, stdout n = int(stdin.readline()) a = int(stdin.readline()) b = int(stdin.readline()) x = 0 flg = False while n >= 0: if int(n / b) == n / b: print("YES") print(x, int(n / b)) flg = True break n = n - a x += 1 if not flg: print("NO") ```
0
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,611,025,571
2,147,483,647
PyPy 3
OK
TESTS
81
312
2,355,200
import string i=lambda:map(int,input().split()); n=int(input()); a1=0; b1=0; c1=0; for l in range(n): a,b,c=i(); a1+=a; b1+=b; c1+=c; if(a1==0&b1==0&c1==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 import string i=lambda:map(int,input().split()); n=int(input()); a1=0; b1=0; c1=0; for l in range(n): a,b,c=i(); a1+=a; b1+=b; c1+=c; if(a1==0&b1==0&c1==0): print("YES"); else: print("NO"); ```
3.917613
892
A
Greed
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans. The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<=*b**n* (*a**i*<=≤<=*b**i*<=≤<=109) — capacities of the cans.
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower).
[ "2\n3 5\n3 6\n", "3\n6 8 9\n6 10 12\n", "5\n0 0 5 0 0\n1 1 8 10 5\n", "4\n4 1 0 3\n5 2 2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n" ]
In the first sample, there are already 2 cans, so the answer is "YES".
500
[ { "input": "2\n3 5\n3 6", "output": "YES" }, { "input": "3\n6 8 9\n6 10 12", "output": "NO" }, { "input": "5\n0 0 5 0 0\n1 1 8 10 5", "output": "YES" }, { "input": "4\n4 1 0 3\n5 2 2 3", "output": "YES" }, { "input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 94 8 16 73 85", "output": "YES" }, { "input": "4\n25 35 7 31\n70 37 43 35", "output": "YES" }, { "input": "10\n15 26 15 14 14 39 40 4 25 39\n27 72 16 44 69 48 53 17 63 42", "output": "NO" }, { "input": "5\n22 5 19 16 32\n26 10 43 38 37", "output": "NO" }, { "input": "5\n32 4 22 40 26\n39 20 36 98 44", "output": "YES" }, { "input": "6\n18 25 3 10 13 37\n38 73 19 35 24 37", "output": "YES" }, { "input": "2\n2 2\n2 2", "output": "YES" }, { "input": "2\n2 5\n2 5", "output": "YES" }, { "input": "2\n1000 1008\n10000 2352", "output": "YES" }, { "input": "5\n1 2 3 4 5\n1 2 3 4 11", "output": "YES" }, { "input": "4\n1 0 0 0\n2 0 0 0", "output": "YES" }, { "input": "2\n0 0\n1 2", "output": "YES" }, { "input": "3\n9 13 4\n10 14 5", "output": "NO" }, { "input": "2\n0 0\n1 1", "output": "YES" }, { "input": "5\n1 1 2 3 1\n1 1 2 3 4", "output": "NO" }, { "input": "2\n0 0\n0 0", "output": "YES" }, { "input": "3\n5 1 1\n5 5 5", "output": "YES" } ]
1,512,212,734
2,147,483,647
Python 3
OK
TESTS
39
155
19,660,800
N = int(input()) s = input() t = input() S = [int(m) for m in s.split() ] T = [int(m) for m in t.split() ] if N>1: x = [] x.append(max(T)) T.remove(max(T)) x.append(max(T)) T.remove(max(T)) if sum(x)>=sum(S): print("YES") else: print("NO") else: if sum(T)> sum(S): print("YES") else: print("NO")
Title: Greed Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! Input Specification: The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans. The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<=*b**n* (*a**i*<=≤<=*b**i*<=≤<=109) — capacities of the cans. Output Specification: Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). Demo Input: ['2\n3 5\n3 6\n', '3\n6 8 9\n6 10 12\n', '5\n0 0 5 0 0\n1 1 8 10 5\n', '4\n4 1 0 3\n5 2 2 3\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'YES\n'] Note: In the first sample, there are already 2 cans, so the answer is "YES".
```python N = int(input()) s = input() t = input() S = [int(m) for m in s.split() ] T = [int(m) for m in t.split() ] if N>1: x = [] x.append(max(T)) T.remove(max(T)) x.append(max(T)) T.remove(max(T)) if sum(x)>=sum(S): print("YES") else: print("NO") else: if sum(T)> sum(S): print("YES") else: print("NO") ```
3
320
A
Magic Numbers
PROGRAMMING
900
[ "brute force", "greedy" ]
null
null
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not.
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Print "YES" if *n* is a magic number or print "NO" if it's not.
[ "114114\n", "1111\n", "441231\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "114114", "output": "YES" }, { "input": "1111", "output": "YES" }, { "input": "441231", "output": "NO" }, { "input": "1", "output": "YES" }, { "input": "14", "output": "YES" }, { "input": "114", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "414", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "144144144", "output": "YES" }, { "input": "1444", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "141414141", "output": "YES" }, { "input": "11110111", "output": "NO" }, { "input": "114114144", "output": "YES" }, { "input": "444", "output": "NO" }, { "input": "9999", "output": "NO" }, { "input": "111444", "output": "NO" }, { "input": "11114", "output": "YES" }, { "input": "41111", "output": "NO" }, { "input": "114414441", "output": "NO" }, { "input": "144414441", "output": "NO" }, { "input": "144244144", "output": "NO" }, { "input": "111111111", "output": "YES" }, { "input": "144444444", "output": "NO" }, { "input": "444444444", "output": "NO" }, { "input": "141441441", "output": "YES" }, { "input": "441", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "14444", "output": "NO" }, { "input": "11444", "output": "NO" }, { "input": "144", "output": "YES" }, { "input": "1414414", "output": "YES" }, { "input": "141444", "output": "NO" }, { "input": "14144", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "1144", "output": "YES" }, { "input": "141111444", "output": "NO" }, { "input": "14414414", "output": "YES" }, { "input": "141414144", "output": "YES" }, { "input": "1414", "output": "YES" }, { "input": "1441", "output": "YES" }, { "input": "12", "output": "NO" }, { "input": "144144141", "output": "YES" }, { "input": "144144", "output": "YES" }, { "input": "14414411", "output": "YES" }, { "input": "14414", "output": "YES" } ]
1,635,178,939
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
2,000
4,505,600
n=input() mn=True while len(n)>0: if len(n)>2: if n[0]+n[1]+n[2]=='144': n=n[3:] continue elif n[0]+n[1]=='14': n=n[2:] continue elif n[0]=='1': n=n[1:] continue else: mn=False print('NO') elif len(n)>1: if n[0]+n[1]=='14': n=n[2:] continue elif n[0]=='1': n=n[1:] continue else: mn=False print('NO') else: if n[0]=='1': n=n[1:] continue else: mn=False print('NO') if mn==True: print('YES')
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. Input Specification: The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. Output Specification: Print "YES" if *n* is a magic number or print "NO" if it's not. Demo Input: ['114114\n', '1111\n', '441231\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python n=input() mn=True while len(n)>0: if len(n)>2: if n[0]+n[1]+n[2]=='144': n=n[3:] continue elif n[0]+n[1]=='14': n=n[2:] continue elif n[0]=='1': n=n[1:] continue else: mn=False print('NO') elif len(n)>1: if n[0]+n[1]=='14': n=n[2:] continue elif n[0]=='1': n=n[1:] continue else: mn=False print('NO') else: if n[0]=='1': n=n[1:] continue else: mn=False print('NO') if mn==True: print('YES') ```
0
605
A
Sorting Railway Cars
PROGRAMMING
1,600
[ "constructive algorithms", "greedy" ]
null
null
An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train. The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train.
Print a single integer — the minimum number of actions needed to sort the railway cars.
[ "5\n4 1 2 5 3\n", "4\n4 1 3 2\n" ]
[ "2\n", "2\n" ]
In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
500
[ { "input": "5\n4 1 2 5 3", "output": "2" }, { "input": "4\n4 1 3 2", "output": "2" }, { "input": "1\n1", "output": "0" }, { "input": "2\n1 2", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "6\n5 3 6 1 4 2", "output": "4" }, { "input": "7\n1 2 3 6 7 4 5", "output": "2" }, { "input": "8\n6 2 1 8 5 7 3 4", "output": "5" }, { "input": "3\n1 2 3", "output": "0" }, { "input": "3\n1 3 2", "output": "1" }, { "input": "3\n2 1 3", "output": "1" }, { "input": "3\n2 3 1", "output": "1" }, { "input": "3\n3 1 2", "output": "1" }, { "input": "3\n3 2 1", "output": "2" }, { "input": "7\n1 3 5 7 2 4 6", "output": "5" }, { "input": "7\n1 5 2 6 3 7 4", "output": "3" }, { "input": "5\n1 4 2 3 5", "output": "2" }, { "input": "9\n1 6 4 5 9 8 7 3 2", "output": "7" }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "6" }, { "input": "50\n39 8 41 9 45 1 5 18 38 31 28 7 12 49 33 19 26 6 42 13 37 27 2 21 20 22 14 16 48 47 32 50 25 17 35 24 36 4 29 15 43 10 11 30 40 46 3 23 44 34", "output": "46" }, { "input": "50\n43 15 10 33 32 31 13 7 5 22 36 1 25 14 38 19 8 6 24 42 28 21 44 35 4 3 49 30 27 46 2 9 17 37 45 41 18 39 12 11 16 20 50 26 29 34 40 47 48 23", "output": "47" }, { "input": "50\n10 40 34 43 50 17 15 13 9 2 32 18 11 46 27 24 36 16 29 45 42 4 47 19 48 37 41 5 21 26 22 25 44 31 35 49 20 8 12 23 6 38 14 1 7 28 3 33 39 30", "output": "46" }, { "input": "50\n10 37 3 46 45 29 36 13 21 25 35 5 18 33 12 19 50 16 30 47 20 42 39 28 2 6 38 8 7 31 22 27 26 9 15 14 34 48 4 32 40 43 44 24 11 1 23 17 49 41", "output": "46" }, { "input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 42 37 38 39 40 41 36 43 44 45 46 47 48 49 50", "output": "14" }, { "input": "50\n1 2 3 4 5 6 7 8 43 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 50 33 34 35 36 37 38 39 40 41 42 9 44 45 46 47 48 49 32", "output": "27" }, { "input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 49 40 41 47 43 44 45 46 42 50 39 48", "output": "11" }, { "input": "50\n1 2 3 4 27 6 7 8 9 10 30 12 13 14 15 16 17 18 19 20 21 22 23 24 28 26 5 25 29 11 31 32 33 34 38 36 37 35 39 40 41 42 43 44 45 46 47 48 49 50", "output": "36" }, { "input": "50\n1 2 3 4 5 6 7 49 9 10 17 12 13 14 15 16 11 18 19 20 21 22 23 24 25 26 27 38 29 36 30 32 33 34 35 31 37 28 39 40 41 42 43 44 45 46 47 48 8 50", "output": "38" }, { "input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 31 18 19 20 21 23 22 24 25 26 27 28 29 49 17 32 33 34 39 36 37 38 47 44 41 42 43 40 45 46 35 48 30 50", "output": "33" }, { "input": "50\n1 2 15 4 5 6 7 8 9 10 11 12 13 14 3 16 17 18 19 32 21 22 36 28 23 26 27 24 29 30 31 20 33 34 37 25 35 38 40 39 41 42 43 44 45 46 47 48 49 50", "output": "39" }, { "input": "5\n4 3 1 2 5", "output": "3" }, { "input": "6\n1 3 5 6 4 2", "output": "4" }, { "input": "10\n2 1 4 3 6 5 8 7 10 9", "output": "8" }, { "input": "5\n1 2 4 5 3", "output": "2" }, { "input": "7\n1 4 2 3 7 6 5", "output": "4" }, { "input": "4\n3 1 2 4", "output": "2" }, { "input": "6\n2 5 4 3 6 1", "output": "4" }, { "input": "5\n1 3 4 5 2", "output": "2" }, { "input": "6\n2 4 6 5 1 3", "output": "4" }, { "input": "6\n1 2 4 5 6 3", "output": "3" }, { "input": "9\n9 8 7 4 5 6 3 2 1", "output": "6" }, { "input": "7\n4 1 2 3 6 5 7", "output": "4" } ]
1,450,098,954
2,147,483,647
Python 3
OK
TESTS
66
140
6,963,200
def main(): n = int(input()) l = [n] * (n + 1) for a in map(int, input().split()): l[a] = l[a - 1] - 1 print(min(l)) if __name__ == '__main__': main()
Title: Sorting Railway Cars Time Limit: None seconds Memory Limit: None megabytes Problem Description: An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train? Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train. The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train. Output Specification: Print a single integer — the minimum number of actions needed to sort the railway cars. Demo Input: ['5\n4 1 2 5 3\n', '4\n4 1 3 2\n'] Demo Output: ['2\n', '2\n'] Note: In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
```python def main(): n = int(input()) l = [n] * (n + 1) for a in map(int, input().split()): l[a] = l[a - 1] - 1 print(min(l)) if __name__ == '__main__': main() ```
3
999
A
Mishka and Contest
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list. Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list. How many problems can Mishka solve?
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list.
Print one integer — the maximum number of problems Mishka can solve.
[ "8 4\n4 2 3 1 5 1 6 4\n", "5 2\n3 1 2 1 3\n", "5 100\n12 34 55 43 21\n" ]
[ "5\n", "0\n", "5\n" ]
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$. In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
0
[ { "input": "8 4\n4 2 3 1 5 1 6 4", "output": "5" }, { "input": "5 2\n3 1 2 1 3", "output": "0" }, { "input": "5 100\n12 34 55 43 21", "output": "5" }, { "input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 18 54 19 71 2 25 33 65 49 53 5 95 90 100 68 25 5 87 48 45 72 34 14 100 44 94 75 80 26 25 7 57 82 49 73 55 43 42 60 34 8 51 11 71 41 81 23 20 89 12 72 68 26 96 92 32 63 13 47 19 9 35 56 79 62", "output": "100" }, { "input": "100 99\n84 82 43 4 71 3 30 92 15 47 76 43 2 17 76 4 1 33 24 96 44 98 75 99 59 11 73 27 67 17 8 88 69 41 44 22 91 48 4 46 42 21 21 67 85 51 57 84 11 100 100 59 39 72 89 82 74 19 98 14 37 97 20 78 38 52 44 83 19 83 69 32 56 6 93 13 98 80 80 2 33 71 11 15 55 51 98 58 16 91 39 32 83 58 77 79 88 81 17 98", "output": "98" }, { "input": "100 69\n80 31 12 89 16 35 8 28 39 12 32 51 42 67 64 53 17 88 63 97 29 41 57 28 51 33 82 75 93 79 57 86 32 100 83 82 99 33 1 27 86 22 65 15 60 100 42 37 38 85 26 43 90 62 91 13 1 92 16 20 100 19 28 30 23 6 5 69 24 22 9 1 10 14 28 14 25 9 32 8 67 4 39 7 10 57 15 7 8 35 62 6 53 59 62 13 24 7 53 2", "output": "39" }, { "input": "100 2\n2 2 2 2 1 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 2 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 16", "output": "99" }, { "input": "100 3\n86 53 82 40 2 20 59 2 46 63 75 49 24 81 70 22 9 9 93 72 47 23 29 77 78 51 17 59 19 71 35 3 20 60 70 9 11 96 71 94 91 19 88 93 50 49 72 19 53 30 38 67 62 71 81 86 5 26 5 32 63 98 1 97 22 32 87 65 96 55 43 85 56 37 56 67 12 100 98 58 77 54 18 20 33 53 21 66 24 64 42 71 59 32 51 69 49 79 10 1", "output": "1" }, { "input": "13 7\n1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "13" }, { "input": "1 5\n4", "output": "1" }, { "input": "3 2\n1 4 1", "output": "2" }, { "input": "1 2\n100", "output": "0" }, { "input": "7 4\n4 2 3 4 4 2 3", "output": "7" }, { "input": "1 2\n1", "output": "1" }, { "input": "1 2\n15", "output": "0" }, { "input": "2 1\n1 1", "output": "2" }, { "input": "5 3\n3 4 3 2 1", "output": "4" }, { "input": "1 1\n2", "output": "0" }, { "input": "1 5\n1", "output": "1" }, { "input": "6 6\n7 1 1 1 1 1", "output": "5" }, { "input": "5 5\n6 5 5 5 5", "output": "4" }, { "input": "1 4\n2", "output": "1" }, { "input": "9 4\n1 2 1 2 4 2 1 2 1", "output": "9" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 10\n5", "output": "1" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "100 10\n2 5 1 10 10 2 7 7 9 4 1 8 1 1 8 4 7 9 10 5 7 9 5 6 7 2 7 5 3 2 1 82 4 80 9 8 6 1 10 7 5 7 1 5 6 7 19 4 2 4 6 2 1 8 31 6 2 2 57 42 3 2 7 1 9 5 10 8 5 4 10 8 3 5 8 7 2 7 6 5 3 3 4 10 6 7 10 8 7 10 7 2 4 6 8 10 10 2 6 4", "output": "71" }, { "input": "100 90\n17 16 5 51 17 62 24 45 49 41 90 30 19 78 67 66 59 34 28 47 42 8 33 77 90 41 61 16 86 33 43 71 90 95 23 9 56 41 24 90 31 12 77 36 90 67 47 15 92 50 79 88 42 19 21 79 86 60 41 26 47 4 70 62 44 90 82 89 84 91 54 16 90 53 29 69 21 44 18 28 88 74 56 43 12 76 10 22 34 24 27 52 28 76 90 75 5 29 50 90", "output": "63" }, { "input": "100 10\n6 4 8 4 1 9 4 8 5 2 2 5 2 6 10 2 2 5 3 5 2 3 10 5 2 9 1 1 6 1 5 9 16 42 33 49 26 31 81 27 53 63 81 90 55 97 70 51 87 21 79 62 60 91 54 95 26 26 30 61 87 79 47 11 59 34 40 82 37 40 81 2 7 1 8 4 10 7 1 10 8 7 3 5 2 8 3 3 9 2 1 1 5 7 8 7 1 10 9 8", "output": "61" }, { "input": "100 90\n45 57 52 69 17 81 85 60 59 39 55 14 87 90 90 31 41 57 35 89 74 20 53 4 33 49 71 11 46 90 71 41 71 90 63 74 51 13 99 92 99 91 100 97 93 40 93 96 100 99 100 92 98 96 78 91 91 91 91 100 94 97 95 97 96 95 17 13 45 35 54 26 2 74 6 51 20 3 73 90 90 42 66 43 86 28 84 70 37 27 90 30 55 80 6 58 57 51 10 22", "output": "72" }, { "input": "100 10\n10 2 10 10 10 10 10 10 10 7 10 10 10 10 10 10 9 10 10 10 10 10 10 10 10 7 9 10 10 10 37 10 4 10 10 10 59 5 95 10 10 10 10 39 10 10 10 10 10 10 10 5 10 10 10 10 10 10 10 10 10 10 10 10 66 10 10 10 10 10 5 10 10 10 10 10 10 44 10 10 10 10 10 10 10 10 10 10 10 7 10 10 10 10 10 10 10 10 10 2", "output": "52" }, { "input": "100 90\n57 90 90 90 90 90 90 90 81 90 3 90 39 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 92 90 90 90 90 90 90 90 90 98 90 90 90 90 90 90 90 90 90 90 90 90 90 54 90 90 90 90 90 62 90 90 91 90 90 90 90 90 90 91 90 90 90 90 90 90 90 3 90 90 90 90 90 90 90 2 90 90 90 90 90 90 90 90 90 2 90 90 90 90 90", "output": "60" }, { "input": "100 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 78 90 61 40 87 39 91 50 64 30 10 24 10 55 28 11 28 35 26 26 10 57 45 67 14 99 96 51 67 79 59 11 21 55 70 33 10 16 92 70 38 50 66 52 5 10 10 10 2 4 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 10 10 10 10 8 10 10 10 10 10", "output": "56" }, { "input": "100 90\n90 90 90 90 90 90 55 21 90 90 90 90 90 90 90 90 90 90 69 83 90 90 90 90 90 90 90 90 93 95 92 98 92 97 91 92 92 91 91 95 94 95 100 100 96 97 94 93 90 90 95 95 97 99 90 95 98 91 94 96 99 99 94 95 95 97 99 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 12 90 3 90 90 90 90 90 90 90", "output": "61" }, { "input": "100 49\n71 25 14 36 36 48 36 49 28 40 49 49 49 38 40 49 33 22 49 49 14 46 8 44 49 11 37 49 40 49 2 49 3 49 37 49 49 11 25 49 49 32 49 11 49 30 16 21 49 49 23 24 30 49 49 49 49 49 49 27 49 42 49 49 20 32 30 29 35 49 30 49 9 49 27 25 5 49 49 42 49 20 49 35 49 22 15 49 49 49 19 49 29 28 13 49 22 7 6 24", "output": "99" }, { "input": "100 50\n38 68 9 6 50 18 19 50 50 20 33 34 43 50 24 50 50 2 50 50 50 50 50 21 30 50 41 40 50 50 50 50 50 7 50 21 19 23 1 50 24 50 50 50 25 50 50 50 50 50 50 50 7 24 28 18 50 5 43 50 20 50 13 50 50 16 50 3 2 24 50 50 18 5 50 4 50 50 38 50 33 49 12 33 11 14 50 50 50 33 50 50 50 50 50 50 7 4 50 50", "output": "99" }, { "input": "100 48\n8 6 23 47 29 48 48 48 48 48 48 26 24 48 48 48 3 48 27 28 41 45 9 29 48 48 48 48 48 48 48 48 48 48 47 23 48 48 48 5 48 22 40 48 48 48 20 48 48 57 48 32 19 48 33 2 4 19 48 48 39 48 16 48 48 44 48 48 48 48 29 14 25 43 46 7 48 19 30 48 18 8 39 48 30 47 35 18 48 45 48 48 30 13 48 48 48 17 9 48", "output": "99" }, { "input": "100 57\n57 9 57 4 43 57 57 57 57 26 57 18 57 57 57 57 57 57 57 47 33 57 57 43 57 57 55 57 14 57 57 4 1 57 57 57 57 57 46 26 57 57 57 57 57 57 57 39 57 57 57 5 57 12 11 57 57 57 25 37 34 57 54 18 29 57 39 57 5 57 56 34 57 24 7 57 57 57 2 57 57 57 57 1 55 39 19 57 57 57 57 21 3 40 13 3 57 57 62 57", "output": "99" }, { "input": "100 51\n51 51 38 51 51 45 51 51 51 18 51 36 51 19 51 26 37 51 11 51 45 34 51 21 51 51 33 51 6 51 51 51 21 47 51 13 51 51 30 29 50 51 51 51 51 51 51 45 14 51 2 51 51 23 9 51 50 23 51 29 34 51 40 32 1 36 31 51 11 51 51 47 51 51 51 51 51 51 51 50 39 51 14 4 4 12 3 11 51 51 51 51 41 51 51 51 49 37 5 93", "output": "99" }, { "input": "100 50\n87 91 95 73 50 50 16 97 39 24 58 50 33 89 42 37 50 50 12 71 3 55 50 50 80 10 76 50 52 36 88 44 66 69 86 71 77 50 72 50 21 55 50 50 78 61 75 89 65 2 50 69 62 47 11 92 97 77 41 31 55 29 35 51 36 48 50 91 92 86 50 36 50 94 51 74 4 27 55 63 50 36 87 50 67 7 65 75 20 96 88 50 41 73 35 51 66 21 29 33", "output": "3" }, { "input": "100 50\n50 37 28 92 7 76 50 50 50 76 100 57 50 50 50 32 76 50 8 72 14 8 50 91 67 50 55 82 50 50 24 97 88 50 59 61 68 86 44 15 61 67 88 50 40 50 36 99 1 23 63 50 88 59 76 82 99 76 68 50 50 30 31 68 57 98 71 12 15 60 35 79 90 6 67 50 50 50 50 68 13 6 50 50 16 87 84 50 67 67 50 64 50 58 50 50 77 51 50 51", "output": "3" }, { "input": "100 50\n43 50 50 91 97 67 6 50 86 50 76 60 50 59 4 56 11 38 49 50 37 50 50 20 60 47 33 54 95 58 22 50 77 77 72 9 57 40 81 57 95 50 81 63 62 76 13 87 50 39 74 69 50 99 63 1 11 62 84 31 97 99 56 73 70 36 45 100 28 91 93 9 19 52 73 50 83 58 84 52 86 12 50 44 64 52 97 50 12 71 97 52 87 66 83 66 86 50 9 49", "output": "6" }, { "input": "88 10\n10 8 1 10 10 1 3 7 10 5 8 8 10 2 7 10 10 10 10 10 1 10 10 10 10 1 2 9 10 9 10 10 10 64 100 25 10 12 9 52 13 8 10 56 10 4 10 7 10 3 10 79 74 8 73 10 10 10 9 10 3 5 10 10 10 5 1 10 10 4 3 10 10 10 4 10 6 4 10 10 10 10 3 3 8 5 6 8", "output": "66" }, { "input": "100 50\n80 39 33 69 75 50 23 88 50 50 67 90 87 50 29 15 55 32 60 50 50 50 38 95 62 50 50 88 8 97 45 50 42 12 22 93 49 50 24 50 50 71 60 4 50 72 57 57 50 50 50 83 69 17 1 31 72 55 50 11 50 80 93 41 91 94 20 60 50 50 51 48 53 56 76 73 50 72 19 98 50 50 50 50 50 28 48 45 62 11 16 67 93 88 63 50 50 66 48 95", "output": "0" }, { "input": "100 50\n70 50 38 50 38 50 32 30 50 31 26 42 50 33 34 50 50 50 28 21 50 44 50 47 50 50 9 40 50 50 50 50 50 42 50 50 16 50 50 3 24 50 50 50 4 26 50 2 50 50 33 1 27 50 50 50 8 29 50 23 33 50 6 29 50 50 15 50 50 50 32 50 43 50 50 50 31 50 4 50 50 31 50 50 31 16 50 17 50 17 31 13 25 16 50 10 50 47 50 66", "output": "0" }, { "input": "2 8\n8 8", "output": "2" }, { "input": "1 6\n3", "output": "1" }, { "input": "1 5\n5", "output": "1" } ]
1,663,000,952
2,147,483,647
Python 3
OK
TESTS
48
61
0
(a,b)=[int(x) for x in input().split()] l=[int(x) for x in input().split()] c=0 while(bool(l)and(l[0]<=b or l[-1]<=b)): if l[0]<=b: c+=1 l=l[1:] elif l[-1]<=b: c+=1 l.pop() print(c)
Title: Mishka and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list. Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list. How many problems can Mishka solve? Input Specification: The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list. Output Specification: Print one integer — the maximum number of problems Mishka can solve. Demo Input: ['8 4\n4 2 3 1 5 1 6 4\n', '5 2\n3 1 2 1 3\n', '5 100\n12 34 55 43 21\n'] Demo Output: ['5\n', '0\n', '5\n'] Note: In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$. In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
```python (a,b)=[int(x) for x in input().split()] l=[int(x) for x in input().split()] c=0 while(bool(l)and(l[0]<=b or l[-1]<=b)): if l[0]<=b: c+=1 l=l[1:] elif l[-1]<=b: c+=1 l.pop() print(c) ```
3
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "output": "99" }, { "input": "gngvi", "output": "44" }, { "input": "aaaaa", "output": "0" }, { "input": "a", "output": "0" }, { "input": "z", "output": "1" }, { "input": "vyadeehhikklnoqrs", "output": "28" }, { "input": "jjiihhhhgggfedcccbazyxx", "output": "21" }, { "input": "fyyptqqxuciqvwdewyppjdzur", "output": "117" }, { "input": "fqcnzmzmbobmancqcoalzmanaobpdse", "output": "368" }, { "input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza", "output": "8" }, { "input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy", "output": "644" }, { "input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", "output": "8" }, { "input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl", "output": "421" }, { "input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa", "output": "84" }, { "input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco", "output": "666" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww", "output": "22" }, { "input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh", "output": "643" }, { "input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib", "output": "245" }, { "input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro", "output": "468" }, { "input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned", "output": "523" }, { "input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna", "output": "130" }, { "input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh", "output": "163" }, { "input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb", "output": "155" }, { "input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp", "output": "57" }, { "input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs", "output": "1236" }, { "input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx", "output": "49" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt", "output": "331" }, { "input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte", "output": "692" }, { "input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh", "output": "1293" }, { "input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg", "output": "16" }, { "input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple", "output": "616" }, { "input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl", "output": "605" }, { "input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud", "output": "549" }, { "input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore", "output": "688" }, { "input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc", "output": "604" }, { "input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa", "output": "572" }, { "input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp", "output": "609" }, { "input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl", "output": "223" }, { "input": "aa", "output": "0" } ]
1,649,111,000
2,147,483,647
Python 3
OK
TESTS
44
46
0
word = input() default = 'a' num_of_rotation = 0 for c in word: num_clockwise = abs(ord(default)-ord(c)) num_counterclockwise = 26-num_clockwise if num_clockwise >= num_counterclockwise: num_of_rotation += num_counterclockwise else: num_of_rotation += num_clockwise default = c print(num_of_rotation)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. Input Specification: The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. Output Specification: Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. Demo Input: ['zeus\n', 'map\n', 'ares\n'] Demo Output: ['18\n', '35\n', '34\n'] Note: To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
```python word = input() default = 'a' num_of_rotation = 0 for c in word: num_clockwise = abs(ord(default)-ord(c)) num_counterclockwise = 26-num_clockwise if num_clockwise >= num_counterclockwise: num_of_rotation += num_counterclockwise else: num_of_rotation += num_clockwise default = c print(num_of_rotation) ```
3
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integer — the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481 554 1000 821", "output": "15" }, { "input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396", "output": "144" }, { "input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366", "output": "145" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n2", "output": "2" }, { "input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19", "output": "63" }, { "input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386", "output": "31" }, { "input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518", "output": "75" }, { "input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397", "output": "41" }, { "input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118", "output": "116" } ]
1,690,292,305
2,147,483,647
PyPy 3-64
OK
TESTS
29
62
0
n, h = map(int, input().split()) a = list(map(int, input().split())) stnd = 0 bnd = 0 for i in range(n): if a[i] > h: bnd += 1 else: stnd += 1 print(2 * bnd + stnd)
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? Input Specification: The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. Output Specification: Print a single integer — the minimum possible valid width of the road. Demo Input: ['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n'] Demo Output: ['4\n', '6\n', '11\n'] Note: In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
```python n, h = map(int, input().split()) a = list(map(int, input().split())) stnd = 0 bnd = 0 for i in range(n): if a[i] > h: bnd += 1 else: stnd += 1 print(2 * bnd + stnd) ```
3
807
B
T-Shirt Hunt
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt. Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place *p*. Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let *s* be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed: Here "div" is the integer division operator, "mod" is the modulo (the remainder of division) operator. As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of *s*. You're in the lead of the elimination round of 8VC Venture Cup 2017, having *x* points. You believe that having at least *y* points in the current round will be enough for victory. To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though. You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?
The only line contains three integers *p*, *x* and *y* (26<=≤<=*p*<=≤<=500; 1<=≤<=*y*<=≤<=*x*<=≤<=20000) — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.
Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt. It's guaranteed that your goal is achievable for any valid input data.
[ "239 10880 9889\n", "26 7258 6123\n", "493 8000 8000\n", "101 6800 6500\n", "329 19913 19900\n" ]
[ "0\n", "2\n", "24\n", "0\n", "8\n" ]
In the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places: In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408. In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400. In the fourth example, it's sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt.
1,000
[ { "input": "239 10880 9889", "output": "0" }, { "input": "26 7258 6123", "output": "2" }, { "input": "493 8000 8000", "output": "24" }, { "input": "101 6800 6500", "output": "0" }, { "input": "329 19913 19900", "output": "8" }, { "input": "264 19252 10888", "output": "0" }, { "input": "176 9670 9174", "output": "6" }, { "input": "42 11 6", "output": "27" }, { "input": "412 17647 15917", "output": "8" }, { "input": "91 4883 4302", "output": "12" }, { "input": "200 16031 15842", "output": "24" }, { "input": "186 18666 18329", "output": "23" }, { "input": "486 9748 9598", "output": "25" }, { "input": "180 4213 4207", "output": "27" }, { "input": "329 19989 1", "output": "0" }, { "input": "390 11676 2570", "output": "0" }, { "input": "173 7017 4512", "output": "0" }, { "input": "38 6404 5034", "output": "0" }, { "input": "364 17243 16625", "output": "0" }, { "input": "57 11066 9738", "output": "1" }, { "input": "419 9142 8622", "output": "1" }, { "input": "31 12956 10515", "output": "2" }, { "input": "412 5027 4975", "output": "2" }, { "input": "94 1231 986", "output": "3" }, { "input": "173 7783 7674", "output": "3" }, { "input": "338 8291 8008", "output": "7" }, { "input": "424 10906 10346", "output": "13" }, { "input": "168 2953 2292", "output": "17" }, { "input": "406 16527 16314", "output": "22" }, { "input": "368 1597 1506", "output": "26" }, { "input": "111 14627 14479", "output": "26" }, { "input": "400 15224 15212", "output": "27" }, { "input": "427 19269 19231", "output": "27" }, { "input": "26 10232 10220", "output": "27" }, { "input": "500 7030 7023", "output": "27" }, { "input": "26 13819 13682", "output": "0" }, { "input": "500 18737 18069", "output": "0" }, { "input": "26 20000 20000", "output": "7" }, { "input": "26 1 1", "output": "6" }, { "input": "26 20000 1", "output": "0" }, { "input": "68 51 1", "output": "0" }, { "input": "198 6550 6549", "output": "5" }, { "input": "68 50 49", "output": "5" }, { "input": "239 10927 10880", "output": "11" }, { "input": "239 10830 9889", "output": "1" }, { "input": "329 2150 1900", "output": "0" }, { "input": "164 49 48", "output": "1" }, { "input": "329 2150 2101", "output": "6" } ]
1,564,389,006
2,147,483,647
PyPy 3
OK
TESTS
48
155
1,228,800
import math def get_tshirts(S): winners = [] i = (S // 50) % 475 for x in range(25): i = (i * 96 + 42) % 475 winners.append(26 + i) return winners class CodeforcesTask807BSolution: def __init__(self): self.result = '' self.p_x_y = [] def read_input(self): self.p_x_y = [int(x) for x in input().split(" ")] def process_task(self): hacks = 0.0 if self.p_x_y[1] < self.p_x_y[2]: hacks += (self.p_x_y[2] - self.p_x_y[1]) // 100 + math.ceil((self.p_x_y[2] - self.p_x_y[1]) % 100 / 100) self.p_x_y[1] += ((self.p_x_y[2] - self.p_x_y[1]) // 100) * 100 + \ math.ceil((self.p_x_y[2] - self.p_x_y[1]) % 100 / 100) * 100 started = self.p_x_y[1] if self.p_x_y[1] > self.p_x_y[2]: self.p_x_y[1] = self.p_x_y[1] - ((self.p_x_y[1] - self.p_x_y[2]) // 50) * 50 while self.p_x_y[0] not in get_tshirts(self.p_x_y[1]): if self.p_x_y[1] >= started: hacks += 0.5 self.p_x_y[1] += 50 hacks += 0.5 self.result = str(int((hacks * 2) // 2)) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask807BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result())
Title: T-Shirt Hunt Time Limit: None seconds Memory Limit: None megabytes Problem Description: Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt. Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place *p*. Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let *s* be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed: Here "div" is the integer division operator, "mod" is the modulo (the remainder of division) operator. As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of *s*. You're in the lead of the elimination round of 8VC Venture Cup 2017, having *x* points. You believe that having at least *y* points in the current round will be enough for victory. To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though. You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that? Input Specification: The only line contains three integers *p*, *x* and *y* (26<=≤<=*p*<=≤<=500; 1<=≤<=*y*<=≤<=*x*<=≤<=20000) — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round. Output Specification: Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt. It's guaranteed that your goal is achievable for any valid input data. Demo Input: ['239 10880 9889\n', '26 7258 6123\n', '493 8000 8000\n', '101 6800 6500\n', '329 19913 19900\n'] Demo Output: ['0\n', '2\n', '24\n', '0\n', '8\n'] Note: In the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places: In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408. In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400. In the fourth example, it's sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt.
```python import math def get_tshirts(S): winners = [] i = (S // 50) % 475 for x in range(25): i = (i * 96 + 42) % 475 winners.append(26 + i) return winners class CodeforcesTask807BSolution: def __init__(self): self.result = '' self.p_x_y = [] def read_input(self): self.p_x_y = [int(x) for x in input().split(" ")] def process_task(self): hacks = 0.0 if self.p_x_y[1] < self.p_x_y[2]: hacks += (self.p_x_y[2] - self.p_x_y[1]) // 100 + math.ceil((self.p_x_y[2] - self.p_x_y[1]) % 100 / 100) self.p_x_y[1] += ((self.p_x_y[2] - self.p_x_y[1]) // 100) * 100 + \ math.ceil((self.p_x_y[2] - self.p_x_y[1]) % 100 / 100) * 100 started = self.p_x_y[1] if self.p_x_y[1] > self.p_x_y[2]: self.p_x_y[1] = self.p_x_y[1] - ((self.p_x_y[1] - self.p_x_y[2]) // 50) * 50 while self.p_x_y[0] not in get_tshirts(self.p_x_y[1]): if self.p_x_y[1] >= started: hacks += 0.5 self.p_x_y[1] += 50 hacks += 0.5 self.result = str(int((hacks * 2) // 2)) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask807BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
3
253
B
Physics Practical
PROGRAMMING
1,400
[ "binary search", "dp", "sortings", "two pointers" ]
null
null
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result *x*, and the largest result *y*, then the inequality *y*<=≤<=2·*x* must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes. Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
Print a single integer — the minimum number of results Vasya will have to remove.
[ "6\n4 5 3 8 3 7\n", "4\n4 3 2 4\n" ]
[ "2\n", "0\n" ]
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
1,000
[ { "input": "6\n4 5 3 8 3 7", "output": "2" }, { "input": "4\n4 3 2 4", "output": "0" }, { "input": "6\n5 6 4 9 4 8", "output": "1" }, { "input": "4\n5 4 1 5", "output": "1" }, { "input": "2\n3 2", "output": "0" }, { "input": "10\n39 9 18 13 6 16 47 15 1 24", "output": "5" }, { "input": "20\n43 49 46 46 40 41 49 49 48 30 35 36 33 34 42 38 40 46 50 45", "output": "0" }, { "input": "30\n6 1 26 13 16 30 16 23 9 1 5 14 7 2 17 22 21 23 16 3 5 17 22 10 1 24 4 30 8 18", "output": "15" }, { "input": "50\n3 61 16 13 13 12 3 8 14 16 1 32 8 23 29 7 28 13 8 5 9 2 3 2 29 13 1 2 18 29 28 4 13 3 14 9 20 26 1 19 13 7 8 22 7 5 13 14 10 23", "output": "29" }, { "input": "10\n135 188 160 167 179 192 195 192 193 191", "output": "0" }, { "input": "15\n2 19 19 22 15 24 6 36 20 3 18 27 20 1 10", "output": "6" }, { "input": "25\n8 1 2 1 2 5 3 4 2 6 3 3 4 1 6 1 6 1 4 5 2 9 1 2 1", "output": "13" }, { "input": "40\n4784 4824 4707 4343 4376 4585 4917 4848 3748 4554 3390 4944 4845 3922 4617 4606 4815 4698 4595 4942 4327 4983 4833 4507 3721 4863 4633 4553 4991 4922 4733 4396 4747 4724 4886 4226 4025 4928 4990 4792", "output": "0" }, { "input": "60\n1219 19 647 1321 21 242 677 901 10 165 434 978 448 163 919 517 1085 10 516 920 653 1363 62 98 629 928 998 1335 1448 85 357 432 1298 561 663 182 2095 801 59 208 765 1653 642 645 1378 221 911 749 347 849 43 1804 62 73 613 143 860 297 278 148", "output": "37" }, { "input": "100\n4204 4719 4688 3104 4012 4927 4696 4614 4826 4792 3891 4672 4914 4740 4968 3879 4424 4755 3856 3837 4965 4939 4030 4941 4504 4668 4908 4608 3660 4822 4846 3945 4539 4819 4895 3746 4324 4233 4135 4956 4983 4546 4673 4617 3533 4851 4868 4838 4998 4769 4899 4578 3841 4974 4627 4990 4524 4939 4469 4233 4434 4339 4446 4979 4354 4912 4558 4609 4436 3883 4379 4927 4824 4819 4984 4660 4874 3732 4853 4268 4761 4402 4642 4577 4635 4564 4113 4896 4943 4122 4413 4597 3768 4731 4669 4958 4548 4263 4657 3651", "output": "0" }, { "input": "100\n1354 1797 588 3046 1290 745 217 907 113 381 523 935 791 415 92 1597 1739 1774 240 27 1262 2498 52 1339 1031 1355 2036 230 489 7 69 877 530 2664 1230 940 2712 2651 3410 480 332 699 957 2257 1877 1940 452 1652 1216 3144 236 165 1109 888 1649 346 24 183 1061 1226 2694 3225 2021 1145 907 1671 1599 3395 942 1959 555 1281 675 1125 1386 732 1081 326 256 26 1009 1772 2687 1173 491 709 390 992 519 203 1029 1381 846 1515 705 2859 282 147 1824 299", "output": "63" }, { "input": "100\n2794 2201 4935 564 2876 4472 4196 2571 2260 1479 1451 3497 245 2805 4834 3872 4294 1299 937 2983 1458 3278 1098 2990 4447 4337 4388 947 3708 3382 3694 4562 3827 2312 3760 1181 2830 1256 1054 1583 2094 931 86 2526 998 3420 2248 3461 3662 1715 5 4123 1051 545 3704 1084 1916 695 794 121 1000 1611 3674 1910 4795 2805 825 2392 3551 1148 3738 4650 791 288 1064 2011 2991 2116 2179 3333 1303 498 1610 3092 1935 3450 3524 2624 1596 2801 2290 2297 2327 1602 4779 3135 1231 4203 3283 3580", "output": "51" }, { "input": "2\n1 5", "output": "1" } ]
1,620,464,155
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
6,963,200
def bsearch(lst, target): left = 0 right = len(lst) - 1 if target == lst[right]: return right while left <= right: mid = (left + right) // 2 if lst[mid] <= target < lst[mid + 1]: return mid elif target >= lst[mid + 1]: left = mid + 1 else: right = mid - 1 # open file fp = open('input.txt','r') # read first line line = fp.readline().strip() line = fp.readline().strip() data = [int(w) for w in line.split()] fp.close() data.sort() max_value = 0 for i in range(len(data)): j = bsearch(data,2 * data[i]) if max_value < j - i + 1: max_value = j - i + 1 break # write output out = open('output.txt','w') print(len(data) - max_value, file=out) out.close()
Title: Physics Practical Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result *x*, and the largest result *y*, then the inequality *y*<=≤<=2·*x* must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes. Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times. Input Specification: The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces. Output Specification: Print a single integer — the minimum number of results Vasya will have to remove. Demo Input: ['6\n4 5 3 8 3 7\n', '4\n4 3 2 4\n'] Demo Output: ['2\n', '0\n'] Note: In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
```python def bsearch(lst, target): left = 0 right = len(lst) - 1 if target == lst[right]: return right while left <= right: mid = (left + right) // 2 if lst[mid] <= target < lst[mid + 1]: return mid elif target >= lst[mid + 1]: left = mid + 1 else: right = mid - 1 # open file fp = open('input.txt','r') # read first line line = fp.readline().strip() line = fp.readline().strip() data = [int(w) for w in line.split()] fp.close() data.sort() max_value = 0 for i in range(len(data)): j = bsearch(data,2 * data[i]) if max_value < j - i + 1: max_value = j - i + 1 break # write output out = open('output.txt','w') print(len(data) - max_value, file=out) out.close() ```
0
991
B
Getting an A
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$. This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo. Help Vasya — calculate the minimum amount of lab works Vasya has to redo.
The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$). The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works.
Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$.
[ "3\n4 4 4\n", "4\n5 4 5 5\n", "4\n5 3 3 5\n" ]
[ "2\n", "0\n", "1\n" ]
In the first sample, it is enough to redo two lab works to make two $4$s into $5$s. In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$. In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$.
1,000
[ { "input": "3\n4 4 4", "output": "2" }, { "input": "4\n5 4 5 5", "output": "0" }, { "input": "4\n5 3 3 5", "output": "1" }, { "input": "1\n5", "output": "0" }, { "input": "4\n3 2 5 4", "output": "2" }, { "input": "5\n5 4 3 2 5", "output": "2" }, { "input": "8\n5 4 2 5 5 2 5 5", "output": "1" }, { "input": "5\n5 5 2 5 5", "output": "1" }, { "input": "6\n5 5 5 5 5 2", "output": "0" }, { "input": "6\n2 2 2 2 2 2", "output": "5" }, { "input": "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 3 3 5 3 2 2 4 5 5 4 5 5 4 2 3 2 2 2 2 5 3 5 2 3 4", "output": "40" }, { "input": "1\n2", "output": "1" }, { "input": "1\n3", "output": "1" }, { "input": "1\n4", "output": "1" }, { "input": "4\n3 2 5 5", "output": "1" }, { "input": "6\n4 3 3 3 3 4", "output": "4" }, { "input": "8\n3 3 5 3 3 3 5 5", "output": "3" }, { "input": "10\n2 4 5 5 5 5 2 3 3 2", "output": "3" }, { "input": "20\n5 2 5 2 2 2 2 2 5 2 2 5 2 5 5 2 2 5 2 2", "output": "10" }, { "input": "25\n4 4 4 4 3 4 3 3 3 3 3 4 4 3 4 4 4 4 4 3 3 3 4 3 4", "output": "13" }, { "input": "30\n4 2 4 2 4 2 2 4 4 4 4 2 4 4 4 2 2 2 2 4 2 4 4 4 2 4 2 4 2 2", "output": "15" }, { "input": "52\n5 3 4 4 4 3 5 3 4 5 3 4 4 3 5 5 4 3 3 3 4 5 4 4 5 3 5 3 5 4 5 5 4 3 4 5 3 4 3 3 4 4 4 3 5 3 4 5 3 5 4 5", "output": "14" }, { "input": "77\n5 3 2 3 2 3 2 3 5 2 2 3 3 3 3 5 3 3 2 2 2 5 5 5 5 3 2 2 5 2 3 2 2 5 2 5 3 3 2 2 5 5 2 3 3 2 3 3 3 2 5 5 2 2 3 3 5 5 2 2 5 5 3 3 5 5 2 2 5 2 2 5 5 5 2 5 2", "output": "33" }, { "input": "55\n3 4 2 3 3 2 4 4 3 3 4 2 4 4 3 3 2 3 2 2 3 3 2 3 2 3 2 4 4 3 2 3 2 3 3 2 2 4 2 4 4 3 4 3 2 4 3 2 4 2 2 3 2 3 4", "output": "34" }, { "input": "66\n5 4 5 5 4 4 4 4 4 2 5 5 2 4 2 2 2 5 4 4 4 4 5 2 2 5 5 2 2 4 4 2 4 2 2 5 2 5 4 5 4 5 4 4 2 5 2 4 4 4 2 2 5 5 5 5 4 4 4 4 4 2 4 5 5 5", "output": "16" }, { "input": "99\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "83" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "84" }, { "input": "99\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "75" }, { "input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "output": "75" }, { "input": "99\n2 2 3 3 3 3 3 2 2 3 2 3 2 3 2 2 3 2 3 2 3 3 3 3 2 2 2 2 3 2 3 3 3 3 3 2 3 3 3 3 2 3 2 3 3 3 2 3 2 3 3 3 3 2 2 3 2 3 2 3 2 3 2 2 2 3 3 2 3 2 2 2 2 2 2 2 2 3 3 3 3 2 3 2 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3", "output": "75" }, { "input": "100\n3 2 3 3 2 2 3 2 2 3 3 2 3 2 2 2 2 2 3 2 2 2 3 2 3 3 2 2 3 2 2 2 2 3 2 3 3 2 2 3 2 2 3 2 3 2 2 3 2 3 2 2 3 2 2 3 3 3 3 3 2 2 3 2 3 3 2 2 3 2 2 2 3 2 2 3 3 2 2 3 3 3 3 2 3 2 2 2 3 3 2 2 3 2 2 2 2 3 2 2", "output": "75" }, { "input": "99\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "50" }, { "input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "50" }, { "input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 4 2 2 2 4 4 2 2 2 2 4 4 4 2 2 2 4 4 2 4 2 4 2 2 4 2 4 4 4 4 4 2 2 4 4 4 2 2 2 2 4 2 4 2 2 2 2 2 2 4 4 2 4 2 2 4 2 2 2 2 2 4 2 4 2 2 4 4 4", "output": "54" }, { "input": "100\n4 2 4 4 2 4 2 2 4 4 4 4 4 4 4 4 4 2 4 4 2 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 2 2 4 4 2 4 2 4 4 4 2 2 2 2 2 2 2 4 2 2 2 4 4 4 2 2 2 2 4 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 4 4 4 4 2 4 2 2 4", "output": "50" }, { "input": "99\n4 3 4 4 4 4 4 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 3 4 3 3 3 3 4 3 4 4 3 4 4 3 3 4 4 4 3 3 3 4 4 3 3 4 3 4 3 4 3 4 3 3 3 3 4 3 4 4 4 4 4 4 3 4 4 3 3 3 3 3 3 3 3 4 3 3 3 4 4 4 4 4 4 3 3 3 3 4 4 4 3 3 4 3", "output": "51" }, { "input": "100\n3 3 4 4 4 4 4 3 4 4 3 3 3 3 4 4 4 4 4 4 3 3 3 4 3 4 3 4 3 3 4 3 3 3 3 3 3 3 3 4 3 4 3 3 4 3 3 3 4 4 3 4 4 3 3 4 4 4 4 4 4 3 4 4 3 4 3 3 3 4 4 3 3 4 4 3 4 4 4 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 4 3 3 4", "output": "51" }, { "input": "99\n3 3 4 4 4 2 4 4 3 2 3 4 4 4 2 2 2 3 2 4 4 2 4 3 2 2 2 4 2 3 4 3 4 2 3 3 4 2 3 3 2 3 4 4 3 2 4 3 4 3 3 3 3 3 4 4 3 3 4 4 2 4 3 4 3 2 3 3 3 4 4 2 4 4 2 3 4 2 3 3 3 4 2 2 3 2 4 3 2 3 3 2 3 4 2 3 3 2 3", "output": "58" }, { "input": "100\n2 2 4 2 2 3 2 3 4 4 3 3 4 4 4 2 3 2 2 3 4 2 3 2 4 3 4 2 3 3 3 2 4 3 3 2 2 3 2 4 4 2 4 3 4 4 3 3 3 2 4 2 2 2 2 2 2 3 2 3 2 3 4 4 4 2 2 3 4 4 3 4 3 3 2 3 3 3 4 3 2 3 3 2 4 2 3 3 4 4 3 3 4 3 4 3 3 4 3 3", "output": "61" }, { "input": "99\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "99\n2 2 2 2 2 5 2 2 5 2 5 2 5 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 2 5 5 2 5 2 2 5 2 5 2 2 5 5 2 2 2 2 5 5 2 2 2 5 2 2 5 2 2 2 2 2 5 5 5 5 2 2 5 2 5 2 2 2 2 2 5 2 2 5 5 2 2 2 2 2 5 5 2 2 5 5 2 2 2 2 5 5 5 2 5", "output": "48" }, { "input": "100\n5 5 2 2 2 2 2 2 5 5 2 5 2 2 2 2 5 2 5 2 5 5 2 5 5 2 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 5 5 5 2 5 5 5 5 5 5 2 2 5 2 2 5 5 5 5 5 2 5 2 5 2 2 2 5 2 5 2 5 5 2 5 5 2 2 5 2 5 5 2 5 2 2 5 2 2 2 5 2 2 2 2 5 5 2 5", "output": "38" }, { "input": "99\n5 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 5 5 3 5 5 3 3 5 5 5 3 5 3 3 3 3 5 3 3 5 5 3 5 5 5 3 5 3 5 3 5 5 5 5 3 3 3 5 3 5 3 3 3 5 5 5 5 5 3 5 5 3 3 5 5 3 5 5 3 5 5 3 3 5 5 5 3 3 3 5 3 3 3", "output": "32" }, { "input": "100\n3 3 3 5 3 3 3 3 3 3 5 5 5 5 3 3 3 3 5 3 3 3 3 3 5 3 5 3 3 5 5 5 5 5 5 3 3 5 3 3 5 3 5 5 5 3 5 3 3 3 3 3 3 3 3 3 3 3 5 5 3 5 3 5 5 3 5 3 3 5 3 5 5 5 5 3 5 3 3 3 5 5 5 3 3 3 5 3 5 5 5 3 3 3 5 3 5 5 3 5", "output": "32" }, { "input": "99\n5 3 5 5 3 3 3 2 2 5 2 5 3 2 5 2 5 2 3 5 3 2 3 2 5 5 2 2 3 3 5 5 3 5 5 2 3 3 5 2 2 5 3 2 5 2 3 5 5 2 5 2 2 5 3 3 5 3 3 5 3 2 3 5 3 2 3 2 3 2 2 2 2 5 2 2 3 2 5 5 5 3 3 2 5 3 5 5 5 2 3 2 5 5 2 5 2 5 3", "output": "39" }, { "input": "100\n3 5 3 3 5 5 3 3 2 5 5 3 3 3 2 2 3 2 5 3 2 2 3 3 3 3 2 5 3 2 3 3 5 2 2 2 3 2 3 5 5 3 2 5 2 2 5 5 3 5 5 5 2 2 5 5 3 3 2 2 2 5 3 3 2 2 3 5 3 2 3 5 5 3 2 3 5 5 3 3 2 3 5 2 5 5 5 5 5 5 3 5 3 2 3 3 2 5 2 2", "output": "42" }, { "input": "99\n4 4 4 5 4 4 5 5 4 4 5 5 5 4 5 4 5 5 5 4 4 5 5 5 5 4 5 5 5 4 4 5 5 4 5 4 4 4 5 5 5 5 4 4 5 4 4 5 4 4 4 4 5 5 5 4 5 4 5 5 5 5 5 4 5 4 5 4 4 4 4 5 5 5 4 5 5 4 4 5 5 5 4 5 4 4 5 5 4 5 5 5 5 4 5 5 4 4 4", "output": "0" }, { "input": "100\n4 4 5 5 5 5 5 5 4 4 5 5 4 4 5 5 4 5 4 4 4 4 4 4 4 4 5 5 5 5 5 4 4 4 4 4 5 4 4 5 4 4 4 5 5 5 4 5 5 5 5 5 5 4 4 4 4 4 4 5 5 4 5 4 4 5 4 4 4 4 5 5 4 5 5 4 4 4 5 5 5 5 4 5 5 5 4 4 5 5 5 4 5 4 5 4 4 5 5 4", "output": "1" }, { "input": "99\n2 2 2 5 2 2 2 2 2 4 4 5 5 2 2 4 2 5 2 2 2 5 2 2 5 5 5 4 5 5 4 4 2 2 5 2 2 2 2 5 5 2 2 4 4 4 2 2 2 5 2 4 4 2 4 2 4 2 5 4 2 2 5 2 4 4 4 2 5 2 2 5 4 2 2 5 5 5 2 4 5 4 5 5 4 4 4 5 4 5 4 5 4 2 5 2 2 2 4", "output": "37" }, { "input": "100\n4 4 5 2 2 5 4 5 2 2 2 4 2 5 4 4 2 2 4 5 2 4 2 5 5 4 2 4 4 2 2 5 4 2 5 4 5 2 5 2 4 2 5 4 5 2 2 2 5 2 5 2 5 2 2 4 4 5 5 5 5 5 5 5 4 2 2 2 4 2 2 4 5 5 4 5 4 2 2 2 2 4 2 2 5 5 4 2 2 5 4 5 5 5 4 5 5 5 2 2", "output": "31" }, { "input": "99\n5 3 4 4 5 4 4 4 3 5 4 3 3 4 3 5 5 5 5 4 3 3 5 3 4 5 3 5 4 4 3 5 5 4 4 4 4 3 5 3 3 5 5 5 5 5 4 3 4 4 3 5 5 3 3 4 4 4 5 4 4 5 4 4 4 4 5 5 4 3 3 4 3 5 3 3 3 3 4 4 4 4 3 4 5 4 4 5 5 5 3 4 5 3 4 5 4 3 3", "output": "24" }, { "input": "100\n5 4 4 4 5 5 5 4 5 4 4 3 3 4 4 4 5 4 5 5 3 5 5 4 5 5 5 4 4 5 3 5 3 5 3 3 5 4 4 5 5 4 5 5 3 4 5 4 4 3 4 4 3 3 5 4 5 4 5 3 4 5 3 4 5 4 3 5 4 5 4 4 4 3 4 5 3 4 3 5 3 4 4 4 3 4 4 5 3 3 4 4 5 5 4 3 4 4 3 5", "output": "19" }, { "input": "99\n2 2 5 2 5 3 4 2 3 5 4 3 4 2 5 3 2 2 4 2 4 4 5 4 4 5 2 5 5 3 2 3 2 2 3 4 5 3 5 2 5 4 4 5 4 2 2 3 2 3 3 3 4 4 3 2 2 4 4 2 5 3 5 3 5 4 4 4 5 4 5 2 2 5 4 4 4 3 3 2 5 2 5 2 3 2 5 2 2 5 5 3 4 5 3 4 4 4 4", "output": "37" }, { "input": "2\n5 2", "output": "1" }, { "input": "5\n2 2 2 2 2", "output": "5" }, { "input": "100\n2 3 2 2 2 3 2 3 3 3 3 3 2 3 3 2 2 3 3 2 3 2 3 2 3 4 4 4 3 3 3 3 3 4 4 3 3 4 3 2 3 4 3 3 3 3 2 3 4 3 4 3 3 2 4 4 2 4 4 3 3 3 3 4 3 2 3 4 3 4 4 4 4 4 3 2 2 3 4 2 4 4 4 2 2 4 2 2 3 2 2 4 4 3 4 2 3 3 2 2", "output": "61" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "1" }, { "input": "100\n5 4 3 5 3 5 4 2 3 3 4 5 4 5 5 4 2 4 2 2 5 2 5 3 4 4 4 5 5 5 3 4 4 4 3 5 3 2 5 4 3 3 3 5 2 3 4 2 5 4 3 4 5 2 2 3 4 4 2 3 3 3 2 5 2 3 4 3 3 3 2 5 4 3 4 5 4 2 5 4 5 2 2 4 2 2 5 5 4 5 2 2 2 2 5 2 4 4 4 5", "output": "35" }, { "input": "2\n2 2", "output": "2" }, { "input": "20\n4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5", "output": "1" } ]
1,639,836,408
2,147,483,647
PyPy 3-64
OK
TESTS
61
93
0
import math n = int(input()) arr = [int(x) for x in input().split(' ')] tol = sum(arr) arr.sort() i = 0 while tol < int(math.ceil(4.5*n)): tol += (5 - arr[i]) i += 1 print(i)
Title: Getting an A Time Limit: None seconds Memory Limit: None megabytes Problem Description: Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$. This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo. Help Vasya — calculate the minimum amount of lab works Vasya has to redo. Input Specification: The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$). The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. Output Specification: Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. Demo Input: ['3\n4 4 4\n', '4\n5 4 5 5\n', '4\n5 3 3 5\n'] Demo Output: ['2\n', '0\n', '1\n'] Note: In the first sample, it is enough to redo two lab works to make two $4$s into $5$s. In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$. In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$.
```python import math n = int(input()) arr = [int(x) for x in input().split(' ')] tol = sum(arr) arr.sort() i = 0 while tol < int(math.ceil(4.5*n)): tol += (5 - arr[i]) i += 1 print(i) ```
3
958
B1
Maximum Control (easy)
PROGRAMMING
1,000
[ "implementation" ]
null
null
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect some of them. The Resistance already has measures in place that will, when the time is right, enable them to control every planet that is not remote. A planet is considered to be remote if it is connected to the rest of the planets only via a single hyperspace tunnel. How much work is there left to be done: that is, how many remote planets are there?
The first line of the input contains an integer *N* (2<=≤<=*N*<=≤<=1000) – the number of planets in the galaxy. The next *N*<=-<=1 lines describe the hyperspace tunnels between the planets. Each of the *N*<=-<=1 lines contains two space-separated integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*N*) indicating that there is a bidirectional hyperspace tunnel between the planets *u* and *v*. It is guaranteed that every two planets are connected by a path of tunnels, and that each tunnel connects a different pair of planets.
A single integer denoting the number of remote planets.
[ "5\n4 1\n4 2\n1 3\n1 5\n", "4\n1 2\n4 3\n1 4\n" ]
[ "3\n", "2\n" ]
In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
0
[ { "input": "5\n4 1\n4 2\n1 3\n1 5", "output": "3" }, { "input": "4\n1 2\n4 3\n1 4", "output": "2" }, { "input": "10\n4 3\n2 6\n10 1\n5 7\n5 8\n10 6\n5 9\n9 3\n2 9", "output": "4" } ]
1,690,077,499
2,147,483,647
Python 3
OK
TESTS
9
46
307,200
from collections import Counter n = int(input()) cnt = Counter() for _ in range(n - 1): a, b = (int(i) for i in input().split()) cnt[a] += 1 cnt[b] += 1 res = sum(v == 1 for v in cnt.values()) print(res)
Title: Maximum Control (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect some of them. The Resistance already has measures in place that will, when the time is right, enable them to control every planet that is not remote. A planet is considered to be remote if it is connected to the rest of the planets only via a single hyperspace tunnel. How much work is there left to be done: that is, how many remote planets are there? Input Specification: The first line of the input contains an integer *N* (2<=≤<=*N*<=≤<=1000) – the number of planets in the galaxy. The next *N*<=-<=1 lines describe the hyperspace tunnels between the planets. Each of the *N*<=-<=1 lines contains two space-separated integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*N*) indicating that there is a bidirectional hyperspace tunnel between the planets *u* and *v*. It is guaranteed that every two planets are connected by a path of tunnels, and that each tunnel connects a different pair of planets. Output Specification: A single integer denoting the number of remote planets. Demo Input: ['5\n4 1\n4 2\n1 3\n1 5\n', '4\n1 2\n4 3\n1 4\n'] Demo Output: ['3\n', '2\n'] Note: In the first example, only planets 2, 3 and 5 are connected by a single tunnel. In the second example, the remote planets are 2 and 3. Note that this problem has only two versions – easy and medium.
```python from collections import Counter n = int(input()) cnt = Counter() for _ in range(n - 1): a, b = (int(i) for i in input().split()) cnt[a] += 1 cnt[b] += 1 res = sum(v == 1 for v in cnt.values()) print(res) ```
3
988
A
Diverse Team
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $1$ to $n$.
[ "5 3\n15 13 15 15 12\n", "5 4\n15 13 15 15 12\n", "4 4\n20 10 40 30\n" ]
[ "YES\n1 2 5 \n", "NO\n", "YES\n1 2 3 4 \n" ]
All possible answers for the first example: - {1 2 5} - {2 3 5} - {2 4 5} Note that the order does not matter.
0
[ { "input": "5 3\n15 13 15 15 12", "output": "YES\n1 2 5 " }, { "input": "5 4\n15 13 15 15 12", "output": "NO" }, { "input": "4 4\n20 10 40 30", "output": "YES\n1 2 3 4 " }, { "input": "1 1\n1", "output": "YES\n1 " }, { "input": "100 53\n16 17 1 2 27 5 9 9 53 24 17 33 35 24 20 48 56 73 12 14 39 55 58 13 59 73 29 26 40 33 22 29 34 22 55 38 63 66 36 13 60 42 10 15 21 9 11 5 23 37 79 47 26 3 79 53 44 8 71 75 42 11 34 39 79 33 10 26 23 23 17 14 54 41 60 31 83 5 45 4 14 35 6 60 28 48 23 18 60 36 21 28 7 34 9 25 52 43 54 19", "output": "YES\n1 2 3 4 5 6 7 9 10 12 13 15 16 17 18 19 20 21 22 23 24 25 27 28 29 31 33 36 37 38 39 41 42 43 44 45 47 49 50 51 52 54 57 58 59 60 73 74 76 77 79 80 83 " }, { "input": "2 2\n100 100", "output": "NO" }, { "input": "2 2\n100 99", "output": "YES\n1 2 " }, { "input": "100 100\n63 100 75 32 53 24 73 98 76 15 70 48 8 81 88 58 95 78 27 92 14 16 72 43 46 39 66 38 64 42 59 9 22 51 4 6 10 94 28 99 68 80 35 50 45 20 47 7 30 26 49 91 77 19 96 57 65 1 11 13 31 12 82 87 93 34 62 3 21 79 56 41 89 18 44 23 74 86 2 33 69 36 61 67 25 83 5 84 90 37 40 29 97 60 52 55 54 71 17 85", "output": "YES\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 " }, { "input": "100 41\n54 16 42 3 45 6 9 72 100 13 24 57 35 5 89 13 97 27 43 9 73 89 48 16 48 55 18 15 55 28 30 6 18 41 100 61 9 42 35 54 57 25 73 15 42 54 49 5 72 48 30 55 4 43 94 5 60 92 93 23 89 75 53 92 74 93 89 28 69 6 3 49 15 28 49 57 54 55 30 57 69 18 89 6 25 23 93 74 30 13 87 53 6 42 4 54 60 30 4 35", "output": "NO" }, { "input": "100 2\n70 64 70 32 70 64 32 70 64 32 32 64 70 64 64 32 64 64 64 70 70 64 64 64 64 70 32 64 70 64 32 70 70 70 64 70 64 70 64 32 70 32 70 64 64 64 32 70 64 70 70 32 70 32 32 32 70 32 70 32 64 64 70 32 32 64 70 64 32 32 64 64 32 32 70 70 32 70 32 64 32 70 64 64 32 64 32 64 70 32 70 32 70 64 64 64 70 70 64 70", "output": "YES\n1 2 " } ]
1,672,756,433
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
30
0
n=list(map(int,input().split())) inp=list(map(int,input().split())) distinct_inp=set(inp) count=len(distinct_inp) if n[1]<=count: print("YES") for i in distinct_inp: print(inp.index(i)+1,end=" ")
Title: Diverse Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them. Input Specification: The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. Output Specification: If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $1$ to $n$. Demo Input: ['5 3\n15 13 15 15 12\n', '5 4\n15 13 15 15 12\n', '4 4\n20 10 40 30\n'] Demo Output: ['YES\n1 2 5 \n', 'NO\n', 'YES\n1 2 3 4 \n'] Note: All possible answers for the first example: - {1 2 5} - {2 3 5} - {2 4 5} Note that the order does not matter.
```python n=list(map(int,input().split())) inp=list(map(int,input().split())) distinct_inp=set(inp) count=len(distinct_inp) if n[1]<=count: print("YES") for i in distinct_inp: print(inp.index(i)+1,end=" ") ```
0
818
A
Diplomas and Certificates
PROGRAMMING
800
[ "implementation", "math" ]
null
null
There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.
[ "18 2\n", "9 10\n", "1000000000000 5\n", "1000000000000 499999999999\n" ]
[ "3 6 9\n", "0 0 9\n", "83333333333 416666666665 500000000002\n", "1 499999999999 500000000000\n" ]
none
0
[ { "input": "18 2", "output": "3 6 9" }, { "input": "9 10", "output": "0 0 9" }, { "input": "1000000000000 5", "output": "83333333333 416666666665 500000000002" }, { "input": "1000000000000 499999999999", "output": "1 499999999999 500000000000" }, { "input": "1 1", "output": "0 0 1" }, { "input": "5 3", "output": "0 0 5" }, { "input": "42 6", "output": "3 18 21" }, { "input": "1000000000000 1000", "output": "499500499 499500499000 500000000501" }, { "input": "999999999999 999999", "output": "499999 499998500001 500000999999" }, { "input": "732577309725 132613", "output": "2762066 366285858458 366288689201" }, { "input": "152326362626 15", "output": "4760198832 71402982480 76163181314" }, { "input": "2 1", "output": "0 0 2" }, { "input": "1000000000000 500000000000", "output": "0 0 1000000000000" }, { "input": "100000000000 50000000011", "output": "0 0 100000000000" }, { "input": "1000000000000 32416187567", "output": "15 486242813505 513757186480" }, { "input": "1000000000000 7777777777", "output": "64 497777777728 502222222208" }, { "input": "1000000000000 77777777777", "output": "6 466666666662 533333333332" }, { "input": "100000000000 578485652", "output": "86 49749766072 50250233842" }, { "input": "999999999999 10000000000", "output": "49 490000000000 509999999950" }, { "input": "7 2", "output": "1 2 4" }, { "input": "420506530901 752346673804", "output": "0 0 420506530901" }, { "input": "960375521135 321688347872", "output": "1 321688347872 638687173262" }, { "input": "1000000000000 1000000000000", "output": "0 0 1000000000000" }, { "input": "99999999999 15253636363", "output": "3 45760909089 54239090907" }, { "input": "19 2", "output": "3 6 10" }, { "input": "999999999999 1000000000000", "output": "0 0 999999999999" }, { "input": "1000000000000 5915587276", "output": "84 496909331184 503090668732" }, { "input": "1000000000000 1000000006", "output": "499 499000002994 500999996507" }, { "input": "549755813888 134217728", "output": "2047 274743689216 275012122625" }, { "input": "99999999999 3333333", "output": "14999 49996661667 50003323333" }, { "input": "9 1", "output": "2 2 5" }, { "input": "1000000000000 250000000001", "output": "1 250000000001 749999999998" }, { "input": "5 1", "output": "1 1 3" }, { "input": "3107038133 596040207", "output": "2 1192080414 1914957717" }, { "input": "1000000000000 73786977", "output": "6776 499980556152 500019437072" }, { "input": "1000000000000 73786976", "output": "6776 499980549376 500019443848" }, { "input": "1000000000000 25000000000", "output": "19 475000000000 524999999981" }, { "input": "216929598879 768233755932", "output": "0 0 216929598879" }, { "input": "1000000000000 250000000000", "output": "1 250000000000 749999999999" }, { "input": "1000000000000 100000000001", "output": "4 400000000004 599999999992" }, { "input": "100000000000 100000000001", "output": "0 0 100000000000" }, { "input": "900000000000 100281800001", "output": "4 401127200004 498872799992" }, { "input": "906028900004 109123020071", "output": "4 436492080284 469536819716" }, { "input": "1000000000000 1", "output": "250000000000 250000000000 500000000000" } ]
1,620,934,264
2,147,483,647
Python 3
OK
TESTS
44
62
6,758,400
s = input().split() n , k = int(s[0]), int(s[1]) d = int((n//2) / (k+1)) c = k*d nw = n - (c + d) print(d, c, nw)
Title: Diplomas and Certificates Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners. Input Specification: The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. Output Specification: Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners. Demo Input: ['18 2\n', '9 10\n', '1000000000000 5\n', '1000000000000 499999999999\n'] Demo Output: ['3 6 9\n', '0 0 9\n', '83333333333 416666666665 500000000002\n', '1 499999999999 500000000000\n'] Note: none
```python s = input().split() n , k = int(s[0]), int(s[1]) d = int((n//2) / (k+1)) c = k*d nw = n - (c + d) print(d, c, nw) ```
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,686,050,919
2,147,483,647
PyPy 3-64
OK
TESTS
20
62
0
# -*- coding: utf-8 -*- def solve(): n, m, a = map(int, input().split()) print(((n + a - 1) // a) * ((m + a - 1) // a)) def main(): t = 1 # t = int(input()) for i in range(t): solve() if __name__ == "__main__": main()
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python # -*- coding: utf-8 -*- def solve(): n, m, a = map(int, input().split()) print(((n + a - 1) // a) * ((m + a - 1) // a)) def main(): t = 1 # t = int(input()) for i in range(t): solve() if __name__ == "__main__": main() ```
3.969
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "input": "8\n4\n1\n10\n59392", "output": "59392" }, { "input": "4\n1\n8\n7\n44835", "output": "44835" }, { "input": "6\n1\n7\n2\n62982", "output": "62982" }, { "input": "2\n7\n4\n9\n56937", "output": "35246" }, { "input": "2\n9\n8\n1\n75083", "output": "75083" }, { "input": "8\n7\n7\n6\n69038", "output": "24656" }, { "input": "4\n4\n2\n3\n54481", "output": "36320" }, { "input": "6\n4\n9\n8\n72628", "output": "28244" }, { "input": "9\n7\n8\n10\n42357", "output": "16540" }, { "input": "5\n6\n4\n3\n60504", "output": "36302" }, { "input": "7\n2\n3\n8\n21754", "output": "15539" }, { "input": "1\n2\n10\n4\n39901", "output": "39901" }, { "input": "3\n4\n7\n1\n58048", "output": "58048" }, { "input": "9\n10\n4\n6\n52003", "output": "21956" }, { "input": "5\n10\n9\n3\n70149", "output": "32736" }, { "input": "5\n5\n5\n10\n55592", "output": "11118" }, { "input": "1\n5\n2\n6\n49547", "output": "49547" }, { "input": "3\n7\n7\n7\n84046", "output": "36019" }, { "input": "10\n2\n1\n8\n63537", "output": "63537" }, { "input": "7\n2\n10\n5\n81684", "output": "53678" }, { "input": "7\n1\n6\n8\n99831", "output": "99831" }, { "input": "3\n9\n3\n3\n61082", "output": "20360" }, { "input": "5\n5\n8\n9\n79228", "output": "29931" }, { "input": "1\n5\n5\n6\n89535", "output": "89535" }, { "input": "5\n5\n2\n1\n7682", "output": "7682" }, { "input": "7\n4\n8\n8\n25829", "output": "9224" }, { "input": "3\n4\n3\n3\n87079", "output": "43539" }, { "input": "5\n8\n4\n9\n5226", "output": "2438" }, { "input": "4\n9\n6\n6\n1070", "output": "415" }, { "input": "10\n10\n10\n10\n100000", "output": "10000" }, { "input": "1\n1\n1\n1\n1", "output": "1" }, { "input": "10\n10\n10\n10\n1", "output": "0" }, { "input": "10\n10\n1\n10\n10", "output": "10" }, { "input": "10\n10\n1\n10\n100", "output": "100" }, { "input": "2\n2\n2\n2\n1", "output": "0" } ]
1,696,440,203
2,147,483,647
Python 3
OK
TESTS
40
122
4,505,600
k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) mas = [] for i in range(d): if (i+1)%k==0 or (i+1)%l==0 or (i+1)%m==0 or (i+1)%n==0: mas.append(i) print(len(mas))
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? Input Specification: Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). Output Specification: Output the number of damaged dragons. Demo Input: ['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n'] Demo Output: ['12\n', '17\n'] Note: In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
```python k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) mas = [] for i in range(d): if (i+1)%k==0 or (i+1)%l==0 or (i+1)%m==0 or (i+1)%n==0: mas.append(i) print(len(mas)) ```
3
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" }, { "input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn", "output": "IGNORE HIM!" }, { "input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx", "output": "CHAT WITH HER!" }, { "input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt", "output": "IGNORE HIM!" }, { "input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk", "output": "IGNORE HIM!" }, { "input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz", "output": "IGNORE HIM!" }, { "input": "tgcdptnkc", "output": "IGNORE HIM!" }, { "input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi", "output": "IGNORE HIM!" }, { "input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp", "output": "IGNORE HIM!" }, { "input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia", "output": "IGNORE HIM!" }, { "input": "fpellxwskyekoyvrfnuf", "output": "CHAT WITH HER!" }, { "input": "xninyvkuvakfbs", "output": "IGNORE HIM!" }, { "input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak", "output": "CHAT WITH HER!" }, { "input": "kmsk", "output": "IGNORE HIM!" }, { "input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz", "output": "CHAT WITH HER!" }, { "input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq", "output": "CHAT WITH HER!" }, { "input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm", "output": "IGNORE HIM!" }, { "input": "ppcpbnhwoizajrl", "output": "IGNORE HIM!" }, { "input": "sgubujztzwkzvztitssxxxwzanfmddfqvv", "output": "CHAT WITH HER!" }, { "input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw", "output": "IGNORE HIM!" }, { "input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu", "output": "CHAT WITH HER!" }, { "input": "ojjvpnkrxibyevxk", "output": "CHAT WITH HER!" }, { "input": "wjweqcrqfuollfvfbiyriijovweg", "output": "IGNORE HIM!" }, { "input": "hkdbykboclchfdsuovvpknwqr", "output": "IGNORE HIM!" }, { "input": "stjvyfrfowopwfjdveduedqylerqugykyu", "output": "IGNORE HIM!" }, { "input": "rafcaanqytfclvfdegak", "output": "CHAT WITH HER!" }, { "input": "xczn", "output": "CHAT WITH HER!" }, { "input": "arcoaeozyeawbveoxpmafxxzdjldsielp", "output": "IGNORE HIM!" }, { "input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika", "output": "CHAT WITH HER!" }, { "input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh", "output": "CHAT WITH HER!" }, { "input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg", "output": "CHAT WITH HER!" }, { "input": "udlpagtpq", "output": "CHAT WITH HER!" }, { "input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy", "output": "CHAT WITH HER!" }, { "input": "qagzrqjomdwhagkhrjahhxkieijyten", "output": "CHAT WITH HER!" }, { "input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb", "output": "CHAT WITH HER!" }, { "input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr", "output": "CHAT WITH HER!" }, { "input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc", "output": "IGNORE HIM!" }, { "input": "lnpdosnceumubvk", "output": "IGNORE HIM!" }, { "input": "efrk", "output": "CHAT WITH HER!" }, { "input": "temnownneghnrujforif", "output": "IGNORE HIM!" }, { "input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta", "output": "IGNORE HIM!" }, { "input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh", "output": "IGNORE HIM!" }, { "input": "gwntwbpj", "output": "IGNORE HIM!" }, { "input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim", "output": "IGNORE HIM!" }, { "input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd", "output": "CHAT WITH HER!" }, { "input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx", "output": "IGNORE HIM!" }, { "input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks", "output": "CHAT WITH HER!" }, { "input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx", "output": "CHAT WITH HER!" }, { "input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc", "output": "CHAT WITH HER!" }, { "input": "yzlzmesxdttfcztooypjztlgxwcr", "output": "IGNORE HIM!" }, { "input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc", "output": "IGNORE HIM!" }, { "input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq", "output": "CHAT WITH HER!" }, { "input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj", "output": "IGNORE HIM!" }, { "input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom", "output": "CHAT WITH HER!" }, { "input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo", "output": "CHAT WITH HER!" }, { "input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh", "output": "IGNORE HIM!" }, { "input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa", "output": "CHAT WITH HER!" }, { "input": "oh", "output": "CHAT WITH HER!" }, { "input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri", "output": "IGNORE HIM!" }, { "input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp", "output": "CHAT WITH HER!" }, { "input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp", "output": "CHAT WITH HER!" }, { "input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo", "output": "CHAT WITH HER!" }, { "input": "mnmbupgo", "output": "IGNORE HIM!" }, { "input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl", "output": "IGNORE HIM!" }, { "input": "yocxrzspinchmhtmqo", "output": "CHAT WITH HER!" }, { "input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv", "output": "CHAT WITH HER!" }, { "input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad", "output": "IGNORE HIM!" }, { "input": "ubvhyaebyxoghakajqrpqpctwbrfqzli", "output": "CHAT WITH HER!" }, { "input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy", "output": "IGNORE HIM!" }, { "input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd", "output": "IGNORE HIM!" }, { "input": "acrzbavz", "output": "CHAT WITH HER!" }, { "input": "drvzznznvrzskftnrhvvzxcalwutxmdza", "output": "IGNORE HIM!" }, { "input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws", "output": "CHAT WITH HER!" }, { "input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff", "output": "CHAT WITH HER!" }, { "input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu", "output": "CHAT WITH HER!" }, { "input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw", "output": "IGNORE HIM!" }, { "input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy", "output": "CHAT WITH HER!" }, { "input": "rhh", "output": "CHAT WITH HER!" }, { "input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo", "output": "IGNORE HIM!" }, { "input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn", "output": "CHAT WITH HER!" }, { "input": "urigreuzpxnej", "output": "CHAT WITH HER!" } ]
1,695,015,622
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
letters = [] s = input() count = 0 for i in range(len(s)): letters.append(s[i]) for i in range(len(s)): if s[i] not in letters: count += 1 if count % 2 == 0: print("CHAT WITH HER!") else: print("IGNORE HIM!")
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. Input Specification: The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. Output Specification: If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). Demo Input: ['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n'] Demo Output: ['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n'] Note: For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
```python letters = [] s = input() count = 0 for i in range(len(s)): letters.append(s[i]) for i in range(len(s)): if s[i] not in letters: count += 1 if count % 2 == 0: print("CHAT WITH HER!") else: print("IGNORE HIM!") ```
0
675
A
Infinite Sequence
PROGRAMMING
1,100
[ "math" ]
null
null
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
[ "1 7 3\n", "10 10 0\n", "1 -4 5\n", "0 60 50\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
500
[ { "input": "1 7 3", "output": "YES" }, { "input": "10 10 0", "output": "YES" }, { "input": "1 -4 5", "output": "NO" }, { "input": "0 60 50", "output": "NO" }, { "input": "1 -4 -5", "output": "YES" }, { "input": "0 1 0", "output": "NO" }, { "input": "10 10 42", "output": "YES" }, { "input": "-1000000000 1000000000 -1", "output": "NO" }, { "input": "10 16 4", "output": "NO" }, { "input": "-1000000000 1000000000 5", "output": "YES" }, { "input": "1000000000 -1000000000 5", "output": "NO" }, { "input": "1000000000 -1000000000 0", "output": "NO" }, { "input": "1000000000 1000000000 0", "output": "YES" }, { "input": "115078364 -899474523 -1", "output": "YES" }, { "input": "-245436499 416383245 992", "output": "YES" }, { "input": "-719636354 536952440 2", "output": "YES" }, { "input": "-198350539 963391024 68337739", "output": "YES" }, { "input": "-652811055 875986516 1091", "output": "YES" }, { "input": "119057893 -516914539 -39748277", "output": "YES" }, { "input": "989140430 731276607 -36837689", "output": "YES" }, { "input": "677168390 494583489 -985071853", "output": "NO" }, { "input": "58090193 777423708 395693923", "output": "NO" }, { "input": "479823846 -403424770 -653472589", "output": "NO" }, { "input": "-52536829 -132023273 -736287999", "output": "NO" }, { "input": "-198893776 740026818 -547885271", "output": "NO" }, { "input": "-2 -2 -2", "output": "YES" }, { "input": "-2 -2 -1", "output": "YES" }, { "input": "-2 -2 0", "output": "YES" }, { "input": "-2 -2 1", "output": "YES" }, { "input": "-2 -2 2", "output": "YES" }, { "input": "-2 -1 -2", "output": "NO" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "-2 -1 0", "output": "NO" }, { "input": "-2 -1 1", "output": "YES" }, { "input": "-2 -1 2", "output": "NO" }, { "input": "-2 0 -2", "output": "NO" }, { "input": "-2 0 -1", "output": "NO" }, { "input": "-2 0 0", "output": "NO" }, { "input": "-2 0 1", "output": "YES" }, { "input": "-2 0 2", "output": "YES" }, { "input": "-2 1 -2", "output": "NO" }, { "input": "-2 1 -1", "output": "NO" }, { "input": "-2 1 0", "output": "NO" }, { "input": "-2 1 1", "output": "YES" }, { "input": "-2 1 2", "output": "NO" }, { "input": "-2 2 -2", "output": "NO" }, { "input": "-2 2 -1", "output": "NO" }, { "input": "-2 2 0", "output": "NO" }, { "input": "-2 2 1", "output": "YES" }, { "input": "-2 2 2", "output": "YES" }, { "input": "-1 -2 -2", "output": "NO" }, { "input": "-1 -2 -1", "output": "YES" }, { "input": "-1 -2 0", "output": "NO" }, { "input": "-1 -2 1", "output": "NO" }, { "input": "-1 -2 2", "output": "NO" }, { "input": "-1 -1 -2", "output": "YES" }, { "input": "-1 -1 -1", "output": "YES" }, { "input": "-1 -1 0", "output": "YES" }, { "input": "-1 -1 1", "output": "YES" }, { "input": "-1 -1 2", "output": "YES" }, { "input": "-1 0 -2", "output": "NO" }, { "input": "-1 0 -1", "output": "NO" }, { "input": "-1 0 0", "output": "NO" }, { "input": "-1 0 1", "output": "YES" }, { "input": "-1 0 2", "output": "NO" }, { "input": "-1 1 -2", "output": "NO" }, { "input": "-1 1 -1", "output": "NO" }, { "input": "-1 1 0", "output": "NO" }, { "input": "-1 1 1", "output": "YES" }, { "input": "-1 1 2", "output": "YES" }, { "input": "-1 2 -2", "output": "NO" }, { "input": "-1 2 -1", "output": "NO" }, { "input": "-1 2 0", "output": "NO" }, { "input": "-1 2 1", "output": "YES" }, { "input": "-1 2 2", "output": "NO" }, { "input": "0 -2 -2", "output": "YES" }, { "input": "0 -2 -1", "output": "YES" }, { "input": "0 -2 0", "output": "NO" }, { "input": "0 -2 1", "output": "NO" }, { "input": "0 -2 2", "output": "NO" }, { "input": "0 -1 -2", "output": "NO" }, { "input": "0 -1 -1", "output": "YES" }, { "input": "0 -1 0", "output": "NO" }, { "input": "0 -1 1", "output": "NO" }, { "input": "0 -1 2", "output": "NO" }, { "input": "0 0 -2", "output": "YES" }, { "input": "0 0 -1", "output": "YES" }, { "input": "0 0 0", "output": "YES" }, { "input": "0 0 1", "output": "YES" }, { "input": "0 0 2", "output": "YES" }, { "input": "0 1 -2", "output": "NO" }, { "input": "0 1 -1", "output": "NO" }, { "input": "0 1 0", "output": "NO" }, { "input": "0 1 1", "output": "YES" }, { "input": "0 1 2", "output": "NO" }, { "input": "0 2 -2", "output": "NO" }, { "input": "0 2 -1", "output": "NO" }, { "input": "0 2 0", "output": "NO" }, { "input": "0 2 1", "output": "YES" }, { "input": "0 2 2", "output": "YES" }, { "input": "1 -2 -2", "output": "NO" }, { "input": "1 -2 -1", "output": "YES" }, { "input": "1 -2 0", "output": "NO" }, { "input": "1 -2 1", "output": "NO" }, { "input": "1 -2 2", "output": "NO" }, { "input": "1 -1 -2", "output": "YES" }, { "input": "1 -1 -1", "output": "YES" }, { "input": "1 -1 0", "output": "NO" }, { "input": "1 -1 1", "output": "NO" }, { "input": "1 -1 2", "output": "NO" }, { "input": "1 0 -2", "output": "NO" }, { "input": "1 0 -1", "output": "YES" }, { "input": "1 0 0", "output": "NO" }, { "input": "1 0 1", "output": "NO" }, { "input": "1 0 2", "output": "NO" }, { "input": "1 1 -2", "output": "YES" }, { "input": "1 1 -1", "output": "YES" }, { "input": "1 1 0", "output": "YES" }, { "input": "1 1 1", "output": "YES" }, { "input": "1 1 2", "output": "YES" }, { "input": "1 2 -2", "output": "NO" }, { "input": "1 2 -1", "output": "NO" }, { "input": "1 2 0", "output": "NO" }, { "input": "1 2 1", "output": "YES" }, { "input": "1 2 2", "output": "NO" }, { "input": "2 -2 -2", "output": "YES" }, { "input": "2 -2 -1", "output": "YES" }, { "input": "2 -2 0", "output": "NO" }, { "input": "2 -2 1", "output": "NO" }, { "input": "2 -2 2", "output": "NO" }, { "input": "2 -1 -2", "output": "NO" }, { "input": "2 -1 -1", "output": "YES" }, { "input": "2 -1 0", "output": "NO" }, { "input": "2 -1 1", "output": "NO" }, { "input": "2 -1 2", "output": "NO" }, { "input": "2 0 -2", "output": "YES" }, { "input": "2 0 -1", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "2 0 1", "output": "NO" }, { "input": "2 0 2", "output": "NO" }, { "input": "2 1 -2", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "2 1 0", "output": "NO" }, { "input": "2 1 1", "output": "NO" }, { "input": "2 1 2", "output": "NO" }, { "input": "2 2 -2", "output": "YES" }, { "input": "2 2 -1", "output": "YES" }, { "input": "2 2 0", "output": "YES" }, { "input": "2 2 1", "output": "YES" }, { "input": "2 2 2", "output": "YES" }, { "input": "-1000000000 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 2", "output": "YES" }, { "input": "1000000000 -1000000000 -1", "output": "YES" }, { "input": "5 2 3", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "3 2 1", "output": "NO" }, { "input": "0 -5 -3", "output": "NO" }, { "input": "2 5 5", "output": "NO" }, { "input": "0 10 1", "output": "YES" }, { "input": "15 5 -5", "output": "YES" }, { "input": "2 1 1", "output": "NO" }, { "input": "20 10 0", "output": "NO" }, { "input": "20 15 5", "output": "NO" }, { "input": "1 6 1", "output": "YES" }, { "input": "1000000000 0 -1000000000", "output": "YES" }, { "input": "1 1 -5", "output": "YES" }, { "input": "4 6 1", "output": "YES" }, { "input": "-5 -10 -5", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "10 9 -1", "output": "YES" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "1 13 3", "output": "YES" }, { "input": "2 3 0", "output": "NO" }, { "input": "1 1 -1", "output": "YES" }, { "input": "5 -10 -5", "output": "YES" }, { "input": "5 3 1", "output": "NO" }, { "input": "1 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 1000000000", "output": "YES" } ]
1,530,100,142
2,147,483,647
Python 3
OK
TESTS
178
93
0
a, b, c = map(int, input().split()) if c: div, mod = divmod(b - a, c) print('NO' if mod or div < 0 else 'YES') else: print('YES' if a == b else 'NO')
Title: Infinite Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help. Input Specification: The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. Output Specification: If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). Demo Input: ['1 7 3\n', '10 10 0\n', '1 -4 5\n', '0 60 50\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'NO\n'] Note: In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
```python a, b, c = map(int, input().split()) if c: div, mod = divmod(b - a, c) print('NO' if mod or div < 0 else 'YES') else: print('YES' if a == b else '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,606,465,538
2,147,483,647
PyPy 3
OK
TESTS
45
310
0
n,m = map(int,input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] v = min(a) p = max(a) c= min(b) if(max(2*v,p)<c): print(max(2*v,p)) 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 n,m = map(int,input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] v = min(a) p = max(a) c= min(b) if(max(2*v,p)<c): print(max(2*v,p)) else: print(-1) ```
3
812
B
Sagheer, the Hausmeister
PROGRAMMING
1,600
[ "bitmasks", "brute force", "dp" ]
null
null
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of *n* floors with stairs at the left and the right sides. Each floor has *m* rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with *n* rows and *m*<=+<=2 columns, where the first and the last columns represent the stairs, and the *m* columns in the middle represent rooms. Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights. Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=15 and 1<=≤<=*m*<=≤<=100) — the number of floors and the number of rooms in each floor, respectively. The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then *m* rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor. The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0.
Print a single integer — the minimum total time needed to turn off all the lights.
[ "2 2\n0010\n0100\n", "3 4\n001000\n000010\n000010\n", "4 3\n01110\n01110\n01110\n01110\n" ]
[ "5\n", "12\n", "18\n" ]
In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor. In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.
1,000
[ { "input": "2 2\n0010\n0100", "output": "5" }, { "input": "3 4\n001000\n000010\n000010", "output": "12" }, { "input": "4 3\n01110\n01110\n01110\n01110", "output": "18" }, { "input": "3 2\n0000\n0100\n0100", "output": "4" }, { "input": "1 89\n0000000000000000000000000000000100000000000000010000000000010000000000000000000000000000000", "output": "59" }, { "input": "2 73\n000000000000000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000100000010000000000000000000000000000", "output": "46" }, { "input": "3 61\n000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "4 53\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000", "output": "0" }, { "input": "5 93\n00000000000000000000000000000000000000000000000000000000100000000000000000000000000000000001010\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00000000000000000000000000000010000000000000000000100000000000000000000000000000000000000000000\n00000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000", "output": "265" }, { "input": "6 77\n0000000000000000100000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000010000000000000\n0000000000010000000000000000000000000000000000000000000000000000000000000000010\n0000000000000000000001000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000100000000000000000000000000000", "output": "311" }, { "input": "7 65\n0000000001000000000000000010000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000001000001000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000\n0000000000000000000000000000000000000000000000000000000000000000000", "output": "62" }, { "input": "8 57\n00000000100000000000000000000000000000000000000000000000000\n00000000000000010000000000000000000000000000000000000000000\n00000000000000000000000000000000000100000000000000000000000\n00000000000000000000000000000000000000000000000000000000000\n00000000000000000000000000000000000100000000000000000000000\n00000000000000000000000000000000000000000000000000000000000\n00000000000010000000000000000000000000000000000000000000000\n00000000000000000000000000000000000000000000000001000000000", "output": "277" }, { "input": "12 13\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n000000000000000\n010000000000000\n000000000000000\n000000000000000\n000000000000000\n000010000000000\n000000000000000", "output": "14" }, { "input": "13 1\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000\n000", "output": "0" }, { "input": "1 33\n00000100101110001101000000110100010", "output": "33" }, { "input": "2 21\n00100110100010010010010\n01000001111001010000000", "output": "43" }, { "input": "3 5\n0001010\n0100000\n0100000", "output": "11" }, { "input": "4 45\n00010000101101100000101101000000100000001101100\n01110000100111010011000000100000000001000001100\n00000000001000100110100001000010011010001010010\n01111110100100000101101010011000100100001000000", "output": "184" }, { "input": "5 37\n010100000000000000000110000110010000010\n001101100010110011101000001010101101110\n010000001000100010010100000000001010000\n000000000100101000000101100001000001110\n000010000000000000100001001000011100110", "output": "193" }, { "input": "6 25\n011001000100111010000101000\n000000000010000010001000010\n011001100001100001001001010\n000000100000010000000000110\n010001100001000001000000010\n011000001001010111110000100", "output": "160" }, { "input": "7 61\n010000111100010100001000011010100001000000000011100000100010000\n000010011000001000000100110101010001000000010001100000100100100\n000010001000001000000100001000000100100011001110000111000000100\n000000000101000011010000011000000101000001011001000011101010010\n000010010011000000100000110000001000000101000000101000010000010\n000010010101101100100100100011001011101010000101000010000101010\n000100001100001001000000001000000001011000110010100000000010110", "output": "436" }, { "input": "8 49\n000100100000000111110010011100110100010010000011000\n001000000101111000000001111100010010100000010000000\n000000010000011100001000000000101000110010000100100\n000000000001000110000011101101000000100000101010000\n000000110001000101101000000001000000110001000110000\n000100000000000000100100010011000001111101010100110\n000000001000000010101111000100001100000000010111000\n001000010000110000011100000000100110000010001000000", "output": "404" }, { "input": "9 41\n0011000000000101001101001000000001110000010\n0000110000001010110010110010110010010001000\n0001100010100000000001110100100001101000100\n0001010101111010000000010010001001011111000\n0101000101000011101011000000001100110010000\n0001010000000000000001011000000100010101000\n0000010011000000001000110001000010110001000\n0000100010000110100001000000100010001111100\n0000001110100001000001000110001110000100000", "output": "385" }, { "input": "10 29\n0000000000101001100001001011000\n0001110100000000000000100010000\n0010001001000011000100010001000\n0001000010101000000010100010100\n0111000000000000100100100010100\n0001000100011111000100010100000\n0000000000000001000001001011000\n0000101110000001010001011001110\n0000001000101010011000001100100\n0100010000101011010000000000000", "output": "299" }, { "input": "1 57\n00011101100001110001111000000100101111000111101100111001000", "output": "55" }, { "input": "2 32\n0011110111011011011101111101011110\n0111000110111111011110011101011110", "output": "65" }, { "input": "3 20\n0110011111110101101100\n0111110000111010100100\n0110111110010100011110", "output": "63" }, { "input": "4 4\n011100\n001010\n010000\n011110", "output": "22" }, { "input": "5 44\n0001010010001111111001111111000010100100000010\n0001111001111001101111011111010110001001111110\n0111111010111111011101100011101010100101110110\n0011010011101011101111001001010110000111111100\n0110100111011100110101110010010011011101100100", "output": "228" }, { "input": "6 36\n01110101111111110101011000011111110010\n00011101100010110111111111110001100100\n00001111110010111111101110101110111110\n00110110011100100111011110000000000010\n01100101101001010001011111100111101100\n00011111111011001000011001011110011110", "output": "226" }, { "input": "7 24\n01111001111001011010010100\n00111011010101000111101000\n01001110110010010110011110\n00000101111011011111111000\n01111111101111001001010010\n01110000111101011111111010\n00000100011100110000110000", "output": "179" }, { "input": "8 8\n0011101110\n0110010100\n0100111110\n0111111100\n0011010100\n0001101110\n0111100000\n0110111000", "output": "77" }, { "input": "9 48\n00011010111110111011111001111111111101001111110010\n01000101000101101101111110111101011100001011010010\n00110111110110101110101110111111011011101111011000\n00110111111100010110110110111001001111011010101110\n01111111100101010011111100100111110011001101110100\n01111011110011111101010101010100001110111111111000\n01110101101101110001000010110100010110101111111100\n00111101001010110010110100000111110101010100001000\n00011011010110011111001100111100100011100110110100", "output": "448" }, { "input": "10 40\n010011001001111011011011101111010001010010\n011000000110000010001011111010100000110000\n011010101001110010110110011111010101101000\n000111111010101111000110011111011011011010\n010110101110001001001111111000110011101010\n010011010100111110010100100111100111011110\n001111101100111111111111001010111010000110\n001111110010101100110100101110001011100110\n010111010010001111110101111111111110111000\n011101101111000100111111111001111100111010", "output": "418" }, { "input": "11 28\n011100111101101001011111001110\n010001111110011101101011001000\n001010011011011010101101101100\n001100011001101011011001110100\n010111110011101110000110111100\n010010001111110000011111010100\n001011111111110011101101111010\n001101101011100100011011001110\n001111110110100110101011000010\n000101101011100001101101100100\n010011101101111011100111110100", "output": "328" }, { "input": "1 68\n0101111110111111111111111111110111111111111111111110111111101111111110", "output": "68" }, { "input": "2 56\n0011111111111110111111111111111111011111111111011111011110\n0111111111010111111111110111111111111110111111010111111110", "output": "113" }, { "input": "3 17\n0111111101111111110\n0111111111101011110\n0101111111111111110", "output": "55" }, { "input": "4 4\n011110\n010110\n010110\n011110", "output": "22" }, { "input": "5 89\n0011111111111101110110111111111101111011111011101110111111111111111111111111111111111111110\n0111111111111111111111111101111111111111111111111111111111111111111111111111111111111111110\n0111111111111011111111111111111111101111011111111111111111110110111101111111111111111011010\n0111111111111111011011111111111011111111111111111111111111111111111111111111111110111111010\n0111111101111011111110101011111111110111100100101111111011111111111111011011101111111111110", "output": "453" }, { "input": "6 77\n0111111110101011111111111111111111111111111111111111100111111111101111111111110\n0111111111111111111101111101111111111011111111011111111001011111111111101111110\n0111101111111111111111111111111111111110110011111111111011111111101111111111110\n0111110111111111111111111111111111111111111111111111011011111111111111111111110\n0101111110111111111111111111111111111111111011111111111111111111101111011011110\n0110111111101111110111111111111011111111101011111101111111111111111111110111100", "output": "472" }, { "input": "7 20\n0111111111111111111100\n0111110111111111111110\n0111111111111111111100\n0111111011111111111110\n0111111111111011101110\n0111101011110111111010\n0111111111111111111010", "output": "151" }, { "input": "8 8\n0111111110\n0111101110\n0111111110\n0111111110\n0111111110\n0110111100\n0101111110\n0110111110", "output": "78" }, { "input": "11 24\n01111111111101111111111110\n01111111111111111111111110\n01110111111111111111111110\n01111111111111111111011110\n01111111111111111110111110\n01111010111111100111101110\n01111111111111010101111100\n01111111111111110111111110\n01011101111111111101111110\n00111111011111111110111110\n01111111101111111101111110", "output": "284" }, { "input": "12 12\n01111111111000\n01101111110110\n01111110111110\n01111111111110\n01111111111010\n01011111110110\n01111111111110\n01101101011110\n01111111111110\n01111101011110\n00111111111110\n01111111011110", "output": "166" }, { "input": "15 28\n011111111101011111111101111110\n011111111111111111111111111110\n011101110111011011101111011110\n011111111011111011110111111110\n011111111110101111111111111110\n011111011111110011111111011010\n011110111111001101111111111110\n011111111110111111111011111110\n011111111111111111111111011110\n011111011111111111111011001010\n011111111101111111111101111110\n011111111110111111101111011110\n010111111111101111111111111110\n011111111111111111011111111110\n011011111111111110110111110110", "output": "448" }, { "input": "2 11\n0100000000000\n0000000010000", "output": "18" }, { "input": "1 100\n010010010011100001101101110111101010000101010001111001001101011110000011101110101000100111111001101110", "output": "100" }, { "input": "15 1\n010\n010\n010\n010\n010\n010\n000\n000\n000\n010\n000\n010\n000\n000\n000", "output": "29" }, { "input": "3 3\n00010\n00000\n00010", "output": "7" } ]
1,672,051,725
2,147,483,647
Python 3
OK
TESTS
72
46
0
n, m = map(int, input().split()) p = [input() for y in range(n)][::-1] l = r = d = 0 i = j = 0 for y, t in enumerate(p): if '1' in t: l, r = min(l - i, r - j) + 2 * m + 2, min(l + i, r + j) i, j = t.find('1'), t.rfind('1') l, r, d = l - i, r + j, y print(min(l, r) + d)
Title: Sagheer, the Hausmeister Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of *n* floors with stairs at the left and the right sides. Each floor has *m* rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with *n* rows and *m*<=+<=2 columns, where the first and the last columns represent the stairs, and the *m* columns in the middle represent rooms. Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights. Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=15 and 1<=≤<=*m*<=≤<=100) — the number of floors and the number of rooms in each floor, respectively. The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then *m* rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor. The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0. Output Specification: Print a single integer — the minimum total time needed to turn off all the lights. Demo Input: ['2 2\n0010\n0100\n', '3 4\n001000\n000010\n000010\n', '4 3\n01110\n01110\n01110\n01110\n'] Demo Output: ['5\n', '12\n', '18\n'] Note: In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs. In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor. In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.
```python n, m = map(int, input().split()) p = [input() for y in range(n)][::-1] l = r = d = 0 i = j = 0 for y, t in enumerate(p): if '1' in t: l, r = min(l - i, r - j) + 2 * m + 2, min(l + i, r + j) i, j = t.find('1'), t.rfind('1') l, r, d = l - i, r + j, y print(min(l, r) + d) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,672,596,272
2,147,483,647
Python 3
OK
TESTS
30
92
0
word = input() count = 0 for char in word: if char != char.lower(): count += 1 if count > len(word) // 2: print(word.upper()) else: print(word.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python word = input() count = 0 for char in word: if char != char.lower(): count += 1 if count > len(word) // 2: print(word.upper()) else: print(word.lower()) ```
3.977
560
B
Gerald is into Art
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=×<=*b*1 rectangle, the paintings have shape of a *a*2<=×<=*b*2 and *a*3<=×<=*b*3 rectangles. Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?
The first line contains two space-separated numbers *a*1 and *b*1 — the sides of the board. Next two lines contain numbers *a*2,<=*b*2,<=*a*3 and *b*3 — the sides of the paintings. All numbers *a**i*,<=*b**i* in the input are integers and fit into the range from 1 to 1000.
If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes).
[ "3 2\n1 3\n2 1\n", "5 5\n3 3\n3 3\n", "4 2\n2 3\n1 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
That's how we can place the pictures in the first test: <img class="tex-graphics" src="https://espresso.codeforces.com/b41bf40c649073c6d3dd62eb7ae7adfc4bd131bd.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's how we can do it in the third one. <img class="tex-graphics" src="https://espresso.codeforces.com/dafdf616eaa5ef10cd3c9ccdc7fba7ece392268c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "3 2\n1 3\n2 1", "output": "YES" }, { "input": "5 5\n3 3\n3 3", "output": "NO" }, { "input": "4 2\n2 3\n1 2", "output": "YES" }, { "input": "3 3\n1 1\n1 1", "output": "YES" }, { "input": "1000 1000\n999 999\n1 1000", "output": "YES" }, { "input": "7 7\n5 5\n2 4", "output": "YES" }, { "input": "3 3\n2 2\n2 2", "output": "NO" }, { "input": "2 9\n5 1\n3 2", "output": "YES" }, { "input": "9 9\n3 8\n5 2", "output": "YES" }, { "input": "10 10\n10 5\n4 3", "output": "YES" }, { "input": "10 6\n10 1\n5 7", "output": "YES" }, { "input": "6 10\n6 3\n6 2", "output": "YES" }, { "input": "7 10\n7 5\n1 7", "output": "YES" }, { "input": "10 10\n7 4\n3 5", "output": "YES" }, { "input": "4 10\n1 1\n9 3", "output": "YES" }, { "input": "8 7\n1 7\n3 2", "output": "YES" }, { "input": "5 10\n5 2\n3 5", "output": "YES" }, { "input": "9 9\n9 7\n2 9", "output": "YES" }, { "input": "8 10\n3 8\n7 4", "output": "YES" }, { "input": "10 10\n6 6\n4 9", "output": "YES" }, { "input": "8 9\n7 6\n2 3", "output": "YES" }, { "input": "10 10\n9 10\n6 1", "output": "YES" }, { "input": "90 100\n52 76\n6 47", "output": "YES" }, { "input": "84 99\n82 54\n73 45", "output": "YES" }, { "input": "100 62\n93 3\n100 35", "output": "YES" }, { "input": "93 98\n75 32\n63 7", "output": "YES" }, { "input": "86 100\n2 29\n71 69", "output": "YES" }, { "input": "96 100\n76 21\n78 79", "output": "YES" }, { "input": "99 100\n95 68\n85 32", "output": "YES" }, { "input": "97 100\n95 40\n70 60", "output": "YES" }, { "input": "100 100\n6 45\n97 54", "output": "YES" }, { "input": "99 100\n99 72\n68 1", "output": "YES" }, { "input": "88 100\n54 82\n86 45", "output": "YES" }, { "input": "91 100\n61 40\n60 88", "output": "YES" }, { "input": "100 100\n36 32\n98 68", "output": "YES" }, { "input": "78 86\n63 8\n9 4", "output": "YES" }, { "input": "72 93\n38 5\n67 64", "output": "YES" }, { "input": "484 1000\n465 2\n9 535", "output": "YES" }, { "input": "808 1000\n583 676\n527 416", "output": "YES" }, { "input": "965 1000\n606 895\n533 394", "output": "YES" }, { "input": "824 503\n247 595\n151 570", "output": "YES" }, { "input": "970 999\n457 305\n542 597", "output": "YES" }, { "input": "332 834\n312 23\n505 272", "output": "YES" }, { "input": "886 724\n830 439\n102 594", "output": "YES" }, { "input": "958 1000\n326 461\n836 674", "output": "YES" }, { "input": "903 694\n104 488\n567 898", "output": "YES" }, { "input": "800 1000\n614 163\n385 608", "output": "YES" }, { "input": "926 1000\n813 190\n187 615", "output": "YES" }, { "input": "541 1000\n325 596\n403 56", "output": "YES" }, { "input": "881 961\n139 471\n323 731", "output": "YES" }, { "input": "993 1000\n201 307\n692 758", "output": "YES" }, { "input": "954 576\n324 433\n247 911", "output": "YES" }, { "input": "7 3\n7 8\n1 5", "output": "NO" }, { "input": "5 9\n2 7\n8 10", "output": "NO" }, { "input": "10 4\n4 3\n5 10", "output": "NO" }, { "input": "2 7\n8 3\n2 7", "output": "NO" }, { "input": "1 4\n7 2\n3 2", "output": "NO" }, { "input": "5 8\n5 1\n10 5", "output": "NO" }, { "input": "3 5\n3 6\n10 7", "output": "NO" }, { "input": "6 2\n6 6\n1 2", "output": "NO" }, { "input": "10 3\n6 6\n4 7", "output": "NO" }, { "input": "9 10\n4 8\n5 6", "output": "YES" }, { "input": "3 8\n3 2\n8 7", "output": "NO" }, { "input": "3 3\n3 4\n3 6", "output": "NO" }, { "input": "6 10\n1 8\n3 2", "output": "YES" }, { "input": "8 1\n7 5\n3 9", "output": "NO" }, { "input": "9 7\n5 2\n4 1", "output": "YES" }, { "input": "100 30\n42 99\n78 16", "output": "NO" }, { "input": "64 76\n5 13\n54 57", "output": "YES" }, { "input": "85 19\n80 18\n76 70", "output": "NO" }, { "input": "57 74\n99 70\n86 29", "output": "NO" }, { "input": "22 21\n73 65\n92 35", "output": "NO" }, { "input": "90 75\n38 2\n100 61", "output": "NO" }, { "input": "62 70\n48 12\n75 51", "output": "NO" }, { "input": "23 17\n34 71\n98 34", "output": "NO" }, { "input": "95 72\n65 31\n89 50", "output": "NO" }, { "input": "68 19\n39 35\n95 65", "output": "NO" }, { "input": "28 65\n66 27\n5 72", "output": "NO" }, { "input": "100 16\n41 76\n24 15", "output": "NO" }, { "input": "21 63\n28 73\n60 72", "output": "NO" }, { "input": "85 18\n37 84\n35 62", "output": "NO" }, { "input": "58 64\n98 30\n61 52", "output": "NO" }, { "input": "32 891\n573 351\n648 892", "output": "NO" }, { "input": "796 846\n602 302\n600 698", "output": "NO" }, { "input": "665 289\n608 360\n275 640", "output": "NO" }, { "input": "237 595\n318 161\n302 838", "output": "NO" }, { "input": "162 742\n465 429\n571 29", "output": "NO" }, { "input": "222 889\n491 923\n76 195", "output": "NO" }, { "input": "794 140\n166 622\n378 905", "output": "NO" }, { "input": "663 287\n193 212\n615 787", "output": "NO" }, { "input": "427 433\n621 441\n868 558", "output": "NO" }, { "input": "1000 388\n332 49\n735 699", "output": "NO" }, { "input": "868 535\n409 690\n761 104", "output": "YES" }, { "input": "632 786\n710 208\n436 290", "output": "YES" }, { "input": "501 932\n463 636\n363 918", "output": "NO" }, { "input": "73 79\n626 483\n924 517", "output": "NO" }, { "input": "190 34\n653 163\n634 314", "output": "NO" }, { "input": "2 4\n1 3\n1 4", "output": "YES" }, { "input": "3 10\n1 1\n1 11", "output": "NO" }, { "input": "5 4\n3 3\n2 6", "output": "NO" }, { "input": "3 4\n1 6\n2 3", "output": "NO" } ]
1,437,703,801
2,147,483,647
PyPy 3
OK
TESTS
101
109
307,200
x,y = map(int, input().split()) a1,a2 = map(int, input().split()) b1,b2 = map(int, input().split()) ans = False if (a1+b2<=x and max(b1,a2)<=y) or (a1+b2<=y and max(b1,a2)<=x): ans = True if a1+b1<=x and max(a2,b2)<=y or a1+b1<=y and max(a2,b2)<=x: ans = True if a2+b1<=x and max(a1,b2)<=y or a2+b1<=y and max(a1,b2)<=x: ans = True if a2+b2<=x and max(a1,b1)<=y or a2+b2<=y and max(a1,b1)<=x: ans = True print("YES" if ans else "NO")
Title: Gerald is into Art Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=×<=*b*1 rectangle, the paintings have shape of a *a*2<=×<=*b*2 and *a*3<=×<=*b*3 rectangles. Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough? Input Specification: The first line contains two space-separated numbers *a*1 and *b*1 — the sides of the board. Next two lines contain numbers *a*2,<=*b*2,<=*a*3 and *b*3 — the sides of the paintings. All numbers *a**i*,<=*b**i* in the input are integers and fit into the range from 1 to 1000. Output Specification: If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes). Demo Input: ['3 2\n1 3\n2 1\n', '5 5\n3 3\n3 3\n', '4 2\n2 3\n1 2\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: That's how we can place the pictures in the first test: <img class="tex-graphics" src="https://espresso.codeforces.com/b41bf40c649073c6d3dd62eb7ae7adfc4bd131bd.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's how we can do it in the third one. <img class="tex-graphics" src="https://espresso.codeforces.com/dafdf616eaa5ef10cd3c9ccdc7fba7ece392268c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python x,y = map(int, input().split()) a1,a2 = map(int, input().split()) b1,b2 = map(int, input().split()) ans = False if (a1+b2<=x and max(b1,a2)<=y) or (a1+b2<=y and max(b1,a2)<=x): ans = True if a1+b1<=x and max(a2,b2)<=y or a1+b1<=y and max(a2,b2)<=x: ans = True if a2+b1<=x and max(a1,b2)<=y or a2+b1<=y and max(a1,b2)<=x: ans = True if a2+b2<=x and max(a1,b1)<=y or a2+b2<=y and max(a1,b1)<=x: ans = True print("YES" if ans else "NO") ```
3
526
C
Om Nom and Candies
PROGRAMMING
2,000
[ "brute force", "greedy", "math" ]
null
null
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs *W**r* grams and each blue candy weighs *W**b* grams. Eating a single red candy gives Om Nom *H**r* joy units and eating a single blue candy gives Om Nom *H**b* joy units. Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than *C* grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.
The single line contains five integers *C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b* (1<=≤<=*C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b*<=≤<=109).
Print a single integer — the maximum number of joy units that Om Nom can get.
[ "10 3 5 2 3\n" ]
[ "16\n" ]
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
1,250
[ { "input": "10 3 5 2 3", "output": "16" }, { "input": "5 3 1 6 7", "output": "0" }, { "input": "982068341 55 57 106 109", "output": "513558662" }, { "input": "930064129 32726326 25428197 83013449 64501049", "output": "363523396" }, { "input": "927155987 21197 15994 54746 41309", "output": "358983713" }, { "input": "902303498 609628987 152407246 8 2", "output": "68758795931537065" }, { "input": "942733698 9180 9072 1020 1008", "output": "8484603228" }, { "input": "951102310 39876134 24967176 70096104 43888451", "output": "539219654" }, { "input": "910943911 107 105 60 59", "output": "1624516635" }, { "input": "910943911 38162 31949 67084 56162", "output": "518210503" }, { "input": "910943911 9063 9045 1007 1005", "output": "8198495199" }, { "input": "903796108 270891702 270891702 1 1", "output": "244830865957095816" }, { "input": "936111602 154673223 309346447 1 2", "output": "144791399037089047" }, { "input": "947370735 115930744 347792233 1 3", "output": "109829394468167085" }, { "input": "958629867 96557265 386229061 1 4", "output": "92562678344491221" }, { "input": "969889000 84931386 424656931 1 5", "output": "82374017230131800" }, { "input": "925819493 47350513 28377591 83230978 49881078", "output": "520855643" }, { "input": "934395168 119 105 67 59", "output": "1662906651" }, { "input": "934395168 29208 38362 51342 67432", "output": "531576348" }, { "input": "934395168 9171 9045 1019 1005", "output": "8409556512" }, { "input": "946401698 967136832 483568416 2 1", "output": "457649970001570368" }, { "input": "962693577 967217455 967217455 2 2", "output": "465567015261784540" }, { "input": "989976325 646076560 969114840 2 3", "output": "319800249268721000" }, { "input": "901235456 485501645 971003291 2 4", "output": "218775648435471424" }, { "input": "912494588 389153108 972882772 2 5", "output": "177550052841687584" }, { "input": "995503930 29205027 18903616 51333090 33226507", "output": "565303099" }, { "input": "983935533 115 108 65 61", "output": "1742049794" }, { "input": "983935533 33986 27367 59737 48104", "output": "559787479" }, { "input": "983935533 7105 7056 1015 1008", "output": "6887548731" }, { "input": "994040035 740285170 246761723 3 1", "output": "245291032098926983" }, { "input": "905299166 740361314 493574209 3 2", "output": "223416160034288041" }, { "input": "911525551 740437472 740437472 3 3", "output": "224975891301803200" }, { "input": "922784684 566833132 755777509 3 4", "output": "174354977531116762" }, { "input": "955100178 462665160 771108601 3 5", "output": "147297192414486195" }, { "input": "949164751 36679609 23634069 64467968 41539167", "output": "537909080" }, { "input": "928443151 60 63 106 112", "output": "525533853" }, { "input": "928443151 25031 33442 43995 58778", "output": "528241752" }, { "input": "928443151 1006 1012 1006 1012", "output": "928443150" }, { "input": "936645623 540336743 135084185 4 1", "output": "126526011319256470" }, { "input": "947904756 540408420 270204210 4 2", "output": "128063927875111380" }, { "input": "959163888 540480074 405360055 4 3", "output": "129602242291091928" }, { "input": "970423020 540551739 540551739 4 4", "output": "131140962756657945" }, { "input": "976649406 455467553 569334442 4 5", "output": "111208028918928288" }, { "input": "923881933 18531902 53987967 32570076 94884602", "output": "524563246" }, { "input": "977983517 57 63 101 112", "output": "551931291" }, { "input": "977983517 29808 22786 52389 40047", "output": "556454318" }, { "input": "977983517 9009 9108 1001 1012", "output": "8801851608" }, { "input": "984283960 367291526 73458305 5 1", "output": "72303831537144592" }, { "input": "990510345 367358723 146943489 5 2", "output": "72774523091497887" }, { "input": "901769477 367425909 220455545 5 3", "output": "66266693959035917" }, { "input": "907995862 367493085 293994468 5 4", "output": "66736440098722854" }, { "input": "924287742 367560271 367560271 5 5", "output": "67946290439275508" }, { "input": "1000000000 1000 999 100 1000000000", "output": "10000000000" }, { "input": "999999999 10 499999995 2 99999999", "output": "4999999995" }, { "input": "999999999 1 1000000000 2 1000000000", "output": "499999999" }, { "input": "999999997 2 999999997 2 999999997", "output": "999999997" }, { "input": "1000000000 1 1 11 11", "output": "90909090" }, { "input": "999999999 999999998 5 999999999 5", "output": "999999998" }, { "input": "100000001 3 100000000 3 100000001", "output": "100000000" }, { "input": "999999999 2 3 1 2", "output": "1999999998" }, { "input": "1000000000 2 1 3 4", "output": "666666666" }, { "input": "999999999 10000 494999 2 99", "output": "4999999994999" }, { "input": "1000000000 1 1 1 1", "output": "1000000000" }, { "input": "998999 1000 999 1000 999", "output": "998999" }, { "input": "3 100 101 2 3", "output": "101" }, { "input": "345415838 13999 13997 13999 13997", "output": "345415838" }, { "input": "5000005 3 2 5 1", "output": "10000010" }, { "input": "1000000000 1 1 1 1000000000", "output": "1000000000" }, { "input": "999999999 3 2 10 3", "output": "666666666" }, { "input": "1000000000 1000 1000 1 1", "output": "1000000000000" }, { "input": "200000001 100000002 1 100000001 1", "output": "200000002" }, { "input": "100000000 1000000000 1 100000001 1", "output": "100000000" }, { "input": "1000000000 99 100 1 2", "output": "99000000000" }, { "input": "1000000000 5 5 1 1", "output": "5000000000" }, { "input": "1000000000 1 1000000000 1 1000000000", "output": "1000000000" } ]
1,428,169,763
4,463
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
2
1,000
0
#!/usr/bin/python3 d = input().split(' ') for i in range(len(d)): d[i] = int(d[i]) i = 0 m = 0 while(i*d[3] <= d[0]): j = (d[0]-i*d[3])//d[4] t = i*d[1]+j*d[2] if(t>m): m=t i += 1 print(m)
Title: Om Nom and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs *W**r* grams and each blue candy weighs *W**b* grams. Eating a single red candy gives Om Nom *H**r* joy units and eating a single blue candy gives Om Nom *H**b* joy units. Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than *C* grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat. Input Specification: The single line contains five integers *C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b* (1<=≤<=*C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b*<=≤<=109). Output Specification: Print a single integer — the maximum number of joy units that Om Nom can get. Demo Input: ['10 3 5 2 3\n'] Demo Output: ['16\n'] Note: In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
```python #!/usr/bin/python3 d = input().split(' ') for i in range(len(d)): d[i] = int(d[i]) i = 0 m = 0 while(i*d[3] <= d[0]): j = (d[0]-i*d[3])//d[4] t = i*d[1]+j*d[2] if(t>m): m=t i += 1 print(m) ```
0
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat.
The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: - '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry.
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "0" }, { "input": "10 10\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS\nSSSSSSSSSS", "output": "0" }, { "input": "10 10\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS", "output": "30" }, { "input": "10 10\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..\n....S..S..", "output": "80" }, { "input": "9 5\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS\nSSSSS", "output": "0" }, { "input": "9 9\n...S.....\nS.S.....S\n.S....S..\n.S.....SS\n.........\n..S.S..S.\n.SS......\n....S....\n..S...S..", "output": "17" }, { "input": "5 6\nSSSSSS\nSSSSSS\nSSSSSS\nSS.S..\nS.S.SS", "output": "0" }, { "input": "9 8\n........\n.......S\n........\nS.......\n........\n........\nS.......\n........\n.......S", "output": "64" }, { "input": "9 7\n......S\n......S\nS.S.S..\n.......\n.......\n.S.....\n.S....S\n..S....\n.S....S", "output": "28" }, { "input": "10 10\n.....S....\n....SS..S.\n.S...S....\n........SS\n.S.......S\nSS..S.....\n.SS.....SS\nS..S......\n.......SSS\nSSSSS....S", "output": "10" }, { "input": "6 7\n..S.SS.\n......S\n....S.S\nSS..S..\nS..SS.S\n.....S.", "output": "0" }, { "input": "10 6\n.SSSSS\nSSS.SS\nSSSSSS\nS.SSSS\nSSSSS.\nS.SSSS\nSS.SSS\n.SSS.S\n.SSS..\nSS..SS", "output": "0" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "3 2\nS.\n.S\nS.", "output": "0" }, { "input": "3 2\nS.\n.S\nS.", "output": "0" }, { "input": "4 3\n.S.\nS.S\n.S.\nS.S", "output": "0" }, { "input": "2 3\n...\nSSS", "output": "3" }, { "input": "2 4\nS.SS\nS.SS", "output": "2" }, { "input": "2 2\n..\n.S", "output": "3" }, { "input": "3 2\n.S\n.S\nSS", "output": "0" }, { "input": "2 4\nSS.S\n..S.", "output": "0" }, { "input": "2 3\n...\nS..", "output": "5" } ]
1,601,278,638
2,147,483,647
PyPy 3
OK
TESTS
42
310
0
import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def solution(mat,r,c): total = 0 cnt = 0 for i in range(r): res = 0 for j in range(c): if mat[i][j] == 'S': res = 0 break else: res += 1 total += res if res > 0: cnt += 1 dep = 0 for j in range(c): res = 0 for i in range(r): if mat[i][j] == 'S': res = 0 break else: res += 1 total += res if res > 0: dep += 1 return (total - dep*cnt) if total >= 0 else 0 r,c = invr() mat = [] for i in range(r): s = insr() mat.append(s) print(solution(mat,r,c))
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times. Please output the maximum number of cake cells that the cakeminator can eat. Input Specification: The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: - '.' character denotes a cake cell with no evil strawberry; - 'S' character denotes a cake cell with an evil strawberry. Output Specification: Output the maximum number of cake cells that the cakeminator can eat. Demo Input: ['3 4\nS...\n....\n..S.\n'] Demo Output: ['8\n'] Note: For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
```python import sys input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def solution(mat,r,c): total = 0 cnt = 0 for i in range(r): res = 0 for j in range(c): if mat[i][j] == 'S': res = 0 break else: res += 1 total += res if res > 0: cnt += 1 dep = 0 for j in range(c): res = 0 for i in range(r): if mat[i][j] == 'S': res = 0 break else: res += 1 total += res if res > 0: dep += 1 return (total - dep*cnt) if total >= 0 else 0 r,c = invr() mat = [] for i in range(r): s = insr() mat.append(s) print(solution(mat,r,c)) ```
3
476
A
Dreamoon and Stairs
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
The single line contains two space separated integers *n*, *m* (0<=&lt;<=*n*<=≤<=10000,<=1<=&lt;<=*m*<=≤<=10).
Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead.
[ "10 2\n", "3 5\n" ]
[ "6\n", "-1\n" ]
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}. For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
500
[ { "input": "10 2", "output": "6" }, { "input": "3 5", "output": "-1" }, { "input": "29 7", "output": "21" }, { "input": "2 2", "output": "2" }, { "input": "1 2", "output": "-1" }, { "input": "10000 2", "output": "5000" }, { "input": "10000 3", "output": "5001" }, { "input": "10000 10", "output": "5000" }, { "input": "9999 3", "output": "5001" }, { "input": "9999 2", "output": "5000" }, { "input": "9999 10", "output": "5000" }, { "input": "9999 9", "output": "5004" }, { "input": "18 10", "output": "10" }, { "input": "19 10", "output": "10" }, { "input": "20 10", "output": "10" }, { "input": "21 10", "output": "20" }, { "input": "7688 5", "output": "3845" }, { "input": "4608 5", "output": "2305" }, { "input": "3979 2", "output": "1990" }, { "input": "9985 6", "output": "4998" }, { "input": "3230 8", "output": "1616" }, { "input": "24 9", "output": "18" }, { "input": "3275 8", "output": "1640" }, { "input": "6240 7", "output": "3122" }, { "input": "5227 4", "output": "2616" }, { "input": "3832 6", "output": "1920" }, { "input": "4 2", "output": "2" }, { "input": "6 3", "output": "3" }, { "input": "10 5", "output": "5" }, { "input": "3 2", "output": "2" }, { "input": "6 4", "output": "4" }, { "input": "5 2", "output": "4" }, { "input": "8 2", "output": "4" }, { "input": "9 9", "output": "9" }, { "input": "4 5", "output": "-1" } ]
1,685,535,496
2,147,483,647
PyPy 3-64
OK
TESTS
35
62
0
def solve(n, m): if(m > n): return -1 a = 0 if(n%2 == 0): a = n // 2 else: a = n//2 + 1 while(a%m != 0): a += 1 return a n, m = map(int, input().split()) print(solve(n, m))
Title: Dreamoon and Stairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? Input Specification: The single line contains two space separated integers *n*, *m* (0<=&lt;<=*n*<=≤<=10000,<=1<=&lt;<=*m*<=≤<=10). Output Specification: Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. Demo Input: ['10 2\n', '3 5\n'] Demo Output: ['6\n', '-1\n'] Note: For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}. For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
```python def solve(n, m): if(m > n): return -1 a = 0 if(n%2 == 0): a = n // 2 else: a = n//2 + 1 while(a%m != 0): a += 1 return a n, m = map(int, input().split()) print(solve(n, m)) ```
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,629,892,768
568
Python 3
WRONG_ANSWER
TESTS
0
92
6,963,200
n = int(input()) s1=0 s2=0 s3=0 for i in range(n): a= list(map(int,input().split()))[:3] s1+=a[0] s2+=a[1] s3+=a[2] if(s1+s2+s3==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()) s1=0 s2=0 s3=0 for i in range(n): a= list(map(int,input().split()))[:3] s1+=a[0] s2+=a[1] s3+=a[2] if(s1+s2+s3==0): print("yes") else: print("no") ```
0
1,004
B
Sonya and Exhibition
PROGRAMMING
1,300
[ "constructive algorithms", "greedy", "implementation", "math" ]
null
null
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily. She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies. Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.
The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively. Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive.
Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.
[ "5 3\n1 3\n2 4\n2 5\n", "6 3\n5 6\n1 4\n4 6\n" ]
[ "01100", "110010" ]
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; - in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$. The total beauty is equal to $2+2+4=8$. In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions; - in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; - in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; - in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$. The total beauty is equal to $1+4+2=7$.
1,000
[ { "input": "5 3\n1 3\n2 4\n2 5", "output": "01010" }, { "input": "6 3\n5 6\n1 4\n4 6", "output": "010101" }, { "input": "10 4\n3 3\n1 6\n9 9\n10 10", "output": "0101010101" }, { "input": "1 1\n1 1", "output": "0" }, { "input": "1000 10\n3 998\n2 1000\n1 999\n2 1000\n3 998\n2 1000\n3 998\n1 1000\n2 1000\n3 999", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "1000 20\n50 109\n317 370\n710 770\n440 488\n711 757\n236 278\n314 355\n131 190\n115 162\n784 834\n16 56\n677 730\n802 844\n632 689\n23 74\n647 702\n930 986\n926 983\n769 822\n508 558", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "1000 10\n138 238\n160 260\n716 816\n504 604\n98 198\n26 126\n114 214\n217 317\n121 221\n489 589", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "1000 5\n167 296\n613 753\n650 769\n298 439\n71 209", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "1000 5\n349 415\n714 773\n125 179\n1 80\n148 242", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "914 10\n587 646\n770 843\n825 875\n439 485\n465 521\n330 387\n405 480\n477 521\n336 376\n715 771", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "571 10\n13 94\n450 510\n230 293\n302 375\n304 354\n421 504\n24 87\n122 181\n221 296\n257 307", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "6 2\n1 6\n1 4", "output": "010101" }, { "input": "2 1\n1 2", "output": "01" } ]
1,530,814,279
5,779
Python 3
OK
TESTS
27
124
102,400
f,n=[int(x) for x in input().split(' ')] ls={} rs={} for i in range(n): l, r = [int(x) for x in input().split(' ')] ls[i]=l rs[i]=r s="" for i in range(f): s+=str(i%2) print(s)
Title: Sonya and Exhibition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily. She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies. Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible. Input Specification: The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively. Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. Output Specification: Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any. Demo Input: ['5 3\n1 3\n2 4\n2 5\n', '6 3\n5 6\n1 4\n4 6\n'] Demo Output: ['01100', '110010'] Note: In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; - in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$. The total beauty is equal to $2+2+4=8$. In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions; - in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; - in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; - in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$. The total beauty is equal to $1+4+2=7$.
```python f,n=[int(x) for x in input().split(' ')] ls={} rs={} for i in range(n): l, r = [int(x) for x in input().split(' ')] ls[i]=l rs[i]=r s="" for i in range(f): s+=str(i%2) print(s) ```
3
538
A
Cutting Banner
PROGRAMMING
1,400
[ "brute force", "implementation" ]
null
null
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters. There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc. Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
[ "CODEWAITFORITFORCES\n", "BOTTOMCODER\n", "DECODEFORCES\n", "DOGEFORCES\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "CODEWAITFORITFORCES", "output": "YES" }, { "input": "BOTTOMCODER", "output": "NO" }, { "input": "DECODEFORCES", "output": "YES" }, { "input": "DOGEFORCES", "output": "NO" }, { "input": "ABACABA", "output": "NO" }, { "input": "CODEFORCE", "output": "NO" }, { "input": "C", "output": "NO" }, { "input": "NQTSMZEBLY", "output": "NO" }, { "input": "CODEFZORCES", "output": "YES" }, { "input": "EDYKHVZCNTLJUUOQGHPTIOETQNFLLWEKZOHIUAXELGECABVSBIBGQODQXVYFKBYJWTGBYHVSSNTINKWSINWSMALUSIWNJMTCOOVF", "output": "NO" }, { "input": "OCECFDSRDE", "output": "NO" }, { "input": "MDBUWCZFFZKFMJTTJFXRHTGRPREORKDVUXOEMFYSOMSQGHUKGYCRCVJTNDLFDEWFS", "output": "NO" }, { "input": "CODEFYTORCHES", "output": "NO" }, { "input": "BCODEFORCES", "output": "YES" }, { "input": "CVODEFORCES", "output": "YES" }, { "input": "COAKDEFORCES", "output": "YES" }, { "input": "CODFMWEFORCES", "output": "YES" }, { "input": "CODEVCSYRFORCES", "output": "YES" }, { "input": "CODEFXHHPWCVQORCES", "output": "YES" }, { "input": "CODEFORQWUFJLOFFXTXRCES", "output": "YES" }, { "input": "CODEFORBWFURYIDURNRKRDLHCLXZCES", "output": "YES" }, { "input": "CODEFORCQSYSLYKCDFFUPSAZCJIAENCKZUFJZEINQIES", "output": "YES" }, { "input": "CODEFORCEVENMDBQLSVPQIIBGSHBVOPYZXNWVSTVWDRONUREYJJIJIPMEBPQDCPFS", "output": "YES" }, { "input": "CODEFORCESCFNNPAHNHDIPPBAUSPKJYAQDBVZNLSTSDCREZACVLMRFGVKGVHHZLXOHCTJDBQKIDWBUXDUJARLWGFGFCTTXUCAZB", "output": "YES" }, { "input": "CODJRDPDEFOROES", "output": "NO" }, { "input": "CODEFOGSIUZMZCMWAVQHNYFEKIEZQMAZOVEMDRMOEDBHAXPLBLDYYXCVTOOSJZVSQAKFXTBTZFWAYRZEMDEMVDJTDRXXAQBURCES", "output": "YES" }, { "input": "CODEMKUYHAZSGJBQLXTHUCZZRJJJXUSEBOCNZASOKDZHMSGWZSDFBGHXFLABVPDQBJYXSHHAZAKHSTRGOKJYHRVSSUGDCMFOGCES", "output": "NO" }, { "input": "CODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCES", "output": "YES" }, { "input": "CCODEFORCESODECODEFORCCODEFORCESODCODEFORCESEFCODEFORCESORCODEFORCESCESCESFORCODEFORCESCES", "output": "NO" }, { "input": "CCODEFORCESC", "output": "NO" }, { "input": "CODEAFORBCES", "output": "NO" }, { "input": "CODERRRRRFORCRRRRES", "output": "NO" }, { "input": "CODELFORCELS", "output": "NO" }, { "input": "CPOPDPEPFPOPRPCPEPS", "output": "NO" }, { "input": "COXDEXFORXCEXS", "output": "NO" }, { "input": "CODAAAAAFORCES", "output": "NO" }, { "input": "CAOADEFORCES", "output": "NO" }, { "input": "FORCESXCODE", "output": "NO" }, { "input": "FORCESACODE", "output": "NO" }, { "input": "ACAOADAEFORCES", "output": "NO" }, { "input": "CCODEFORCESS", "output": "NO" }, { "input": "ZCODEFORCEZ", "output": "NO" }, { "input": "CODXEFORXCES", "output": "NO" }, { "input": "CODEFORCEZ", "output": "NO" }, { "input": "CODEFORCEST", "output": "YES" }, { "input": "AXODEFORCES", "output": "NO" }, { "input": "RCODEFORCESR", "output": "NO" }, { "input": "CODECODEFORCESFORCES", "output": "YES" }, { "input": "TTTWWWCODEFORCES", "output": "YES" }, { "input": "CODEFORRCEST", "output": "NO" }, { "input": "UJYTYUCODEFORCES", "output": "YES" }, { "input": "CODEXXXXXXXXXXXXXXXXXXCODEFORCESXXXXXXXXXXXXXXXXXXXXXFORCES", "output": "YES" }, { "input": "COXEDYFORCES", "output": "NO" }, { "input": "UJYTYCODEFORCES", "output": "YES" }, { "input": "UJYTCODEFORCES", "output": "YES" } ]
1,571,060,250
2,147,483,647
PyPy 3
OK
TESTS
55
155
0
n = input() e = "CODEFORCES" i,flag = 0,-1 if n[0] == "C" and len(n) >= len(e): while True: if i == len(e): flag = 1 break elif n[i] == e[i]: i += 1 else: break j = (len(n) - (len(e[i:]))) if n[j:] == e[i:] or flag ==1: print("YES") else: print("NO") elif len(n) < len(e): print("NO") else: if n[len(n)-10:] == e: print("YES") else: print("NO")
Title: Cutting Banner Time Limit: None seconds Memory Limit: None megabytes Problem Description: A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters. There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc. Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES. Input Specification: The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES. Output Specification: Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes). Demo Input: ['CODEWAITFORITFORCES\n', 'BOTTOMCODER\n', 'DECODEFORCES\n', 'DOGEFORCES\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'NO\n'] Note: none
```python n = input() e = "CODEFORCES" i,flag = 0,-1 if n[0] == "C" and len(n) >= len(e): while True: if i == len(e): flag = 1 break elif n[i] == e[i]: i += 1 else: break j = (len(n) - (len(e[i:]))) if n[j:] == e[i:] or flag ==1: print("YES") else: print("NO") elif len(n) < len(e): print("NO") else: if n[len(n)-10:] == e: print("YES") else: print("NO") ```
3
371
C
Hamburgers
PROGRAMMING
1,600
[ "binary search", "brute force" ]
null
null
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again. Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese. Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
[ "BBBSSC\n6 4 1\n1 2 3\n4\n", "BBC\n1 10 1\n1 10 1\n21\n", "BSC\n1 1 1\n1 1 3\n1000000000000\n" ]
[ "2\n", "7\n", "200000000001\n" ]
none
1,500
[ { "input": "BBBSSC\n6 4 1\n1 2 3\n4", "output": "2" }, { "input": "BBC\n1 10 1\n1 10 1\n21", "output": "7" }, { "input": "BSC\n1 1 1\n1 1 3\n1000000000000", "output": "200000000001" }, { "input": "B\n1 1 1\n1 1 1\n381", "output": "382" }, { "input": "BSC\n3 5 6\n7 3 9\n100", "output": "10" }, { "input": "BSC\n100 1 1\n100 1 1\n100", "output": "51" }, { "input": "SBBCCSBB\n1 50 100\n31 59 21\n100000", "output": "370" }, { "input": "BBBBCCCCCCCCCCCCCCCCCCCCSSSSBBBBBBBBSS\n100 100 100\n1 1 1\n3628800", "output": "95502" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n200", "output": "0" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n2000", "output": "1" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300", "output": "0" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300000000", "output": "42858" }, { "input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n914159265358", "output": "130594181" }, { "input": "SSSSSSSSSSBBBBBBBBBCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSBB\n31 53 97\n13 17 31\n914159265358", "output": "647421579" }, { "input": "BBBCSBSBBSSSSCCCCBBCSBBBBSSBBBCBSCCSSCSSCSBSSSCCCCBSCSSBSSSCCCBBCCCSCBCBBCCSCCCCSBBCCBBBBCCCCCCBSSCB\n91 87 17\n64 44 43\n958532915587", "output": "191668251" }, { "input": "CSSCBBCCCSBSCBBBCSBBBCBSBCSCBCSCBCBSBCBCSSBBSBBCBBBBSCSBBCCBCCBCBBSBSBCSCSBBSSBBCSSBCSCSCCSSBCBBCBSB\n56 34 48\n78 6 96\n904174875419", "output": "140968956" }, { "input": "CCSCCCSBBBSCBSCSCCSSBBBSSBBBSBBBCBCSSBCSCBBCCCBCBCBCCCSSBSBBCCCCCBBSCBSCBCBBCBBCSSBCSBSSCCSCCSCCBBBS\n33 73 67\n4 56 42\n886653164314", "output": "277425898" }, { "input": "SBCSSCBBSSBCSSBBBSSBSCBSSSCBBSBBBBCSBCSBSCBSCBSCBSBSSCCCCBSBCCBCBSCCCBSCCBSBBCBSSCCCCSBSBBBSSSBCSCBC\n94 16 85\n14 18 91\n836590091442", "output": "217522127" }, { "input": "BSCSBSCCSCSSCCCSBCSSBCBBSCCBSCCSSSSSSSSSCCSBSCCBBCBBSBSCCCCBCSBSBSSBBBBBSSBSSCBCCSSBSSSCBBCSBBSBCCCB\n67 54 8\n36 73 37\n782232051273", "output": "154164772" }, { "input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSSBSBSCBBSBBCSSSSBBBBSBBCBCSBBCBCSSBBCSBSCCSCSBCSCBSCCBBCSC\n71 71 52\n52 88 3\n654400055575", "output": "137826467" }, { "input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCSC\n100 1 1\n1 17 23\n954400055575", "output": "1355681897" }, { "input": "C\n100 100 100\n1 1 1\n1000000000000", "output": "1000000000100" }, { "input": "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n100 100 100\n100 100 100\n1000000000000", "output": "100000001" }, { "input": "B\n100 100 100\n1 1 1\n1", "output": "101" }, { "input": "SC\n2 1 1\n1 1 1\n100000000000", "output": "50000000001" }, { "input": "B\n100 1 1\n1 1 1\n1000000000000", "output": "1000000000100" }, { "input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n1 1 1\n100 100 100\n1000000000000", "output": "100000000" }, { "input": "CC\n1 1 1\n100 100 100\n1", "output": "0" }, { "input": "B\n100 100 100\n1 1 1\n1000000000000", "output": "1000000000100" }, { "input": "BSC\n100 100 100\n1 1 1\n1000000000000", "output": "333333333433" }, { "input": "BSC\n100 100 100\n1 1 1\n1", "output": "100" } ]
1,697,756,094
2,147,483,647
PyPy 3-64
OK
TESTS
31
62
0
def can_make_boxes(recipe, nb, ns, nc, pb, ps, pc, r, boxes): b_needed = recipe.count('B') * boxes s_needed = recipe.count('S') * boxes c_needed = recipe.count('C') * boxes total_cost = max(0, b_needed - nb) * pb + max(0, s_needed - ns) * ps + max(0, c_needed - nc) * pc return total_cost <= r def max_boxes(recipe, nb, ns, nc, pb, ps, pc, r): low, high = 0, 10**13 # we set a high upper limit for the search ans = 0 while low <= high: mid = (low + high) // 2 if can_make_boxes(recipe, nb, ns, nc, pb, ps, pc, r, mid): ans = mid low = mid + 1 else: high = mid - 1 return ans # Input recipe = input().strip() nb, ns, nc = map(int, input().split()) pb, ps, pc = map(int, input().split()) r = int(input()) # Output print(max_boxes(recipe, nb, ns, nc, pb, ps, pc, r))
Title: Hamburgers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again. Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese. Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient. Input Specification: The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Specification: Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. Demo Input: ['BBBSSC\n6 4 1\n1 2 3\n4\n', 'BBC\n1 10 1\n1 10 1\n21\n', 'BSC\n1 1 1\n1 1 3\n1000000000000\n'] Demo Output: ['2\n', '7\n', '200000000001\n'] Note: none
```python def can_make_boxes(recipe, nb, ns, nc, pb, ps, pc, r, boxes): b_needed = recipe.count('B') * boxes s_needed = recipe.count('S') * boxes c_needed = recipe.count('C') * boxes total_cost = max(0, b_needed - nb) * pb + max(0, s_needed - ns) * ps + max(0, c_needed - nc) * pc return total_cost <= r def max_boxes(recipe, nb, ns, nc, pb, ps, pc, r): low, high = 0, 10**13 # we set a high upper limit for the search ans = 0 while low <= high: mid = (low + high) // 2 if can_make_boxes(recipe, nb, ns, nc, pb, ps, pc, r, mid): ans = mid low = mid + 1 else: high = mid - 1 return ans # Input recipe = input().strip() nb, ns, nc = map(int, input().split()) pb, ps, pc = map(int, input().split()) r = int(input()) # Output print(max_boxes(recipe, nb, ns, nc, pb, ps, pc, r)) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,595,969,381
2,147,483,647
Python 3
OK
TESTS
102
109
6,656,000
n1 = input().strip() n2 = input().strip() def n3(n1, n2): return "".join(["0" if n1[i] == n2[i] else "1" for i in range(len(n1))]) print(n3(n1, n2))
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python n1 = input().strip() n2 = input().strip() def n3(n1, n2): return "".join(["0" if n1[i] == n2[i] else "1" for i in range(len(n1))]) print(n3(n1, n2)) ```
3.960352
0
none
none
none
0
[ "none" ]
null
null
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**i* and *r**i*, and its elements are *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Alyona is going to find mex for each of the chosen subarrays. Among these *m* mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible. You are to find an array *a* of *n* elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible. The mex of a set *S* is a minimum possible non-negative integer that is not in *S*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
In the first line print single integer — the maximum possible minimum mex. In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109. It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109. If there are multiple solutions, print any of them.
[ "5 3\n1 3\n2 5\n4 5\n", "4 2\n1 4\n2 4\n" ]
[ "2\n1 0 2 1 0\n", "3\n5 2 0 1" ]
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
0
[ { "input": "5 3\n1 3\n2 5\n4 5", "output": "2\n0 1 0 1 0" }, { "input": "4 2\n1 4\n2 4", "output": "3\n0 1 2 0" }, { "input": "1 1\n1 1", "output": "1\n0" }, { "input": "2 1\n2 2", "output": "1\n0 0" }, { "input": "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3", "output": "2\n0 1 0 1 0" }, { "input": "8 3\n2 3\n2 8\n3 6", "output": "2\n0 1 0 1 0 1 0 1" }, { "input": "10 10\n1 9\n4 8\n4 8\n5 9\n1 9\n3 8\n1 6\n1 9\n1 6\n6 9", "output": "4\n0 1 2 3 0 1 2 3 0 1" }, { "input": "3 6\n1 3\n1 3\n1 1\n1 1\n3 3\n3 3", "output": "1\n0 0 0" }, { "input": "3 3\n1 3\n2 2\n1 3", "output": "1\n0 0 0" }, { "input": "6 8\n3 5\n3 6\n4 6\n2 5\n2 5\n1 3\n3 6\n3 5", "output": "3\n0 1 2 0 1 2" }, { "input": "10 4\n4 10\n4 6\n6 8\n1 10", "output": "3\n0 1 2 0 1 2 0 1 2 0" }, { "input": "9 1\n1 1", "output": "1\n0 0 0 0 0 0 0 0 0" }, { "input": "3 8\n2 3\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n1 2", "output": "1\n0 0 0" }, { "input": "3 8\n1 2\n1 2\n1 1\n2 3\n2 3\n1 1\n1 3\n1 3", "output": "1\n0 0 0" }, { "input": "7 3\n7 7\n3 7\n5 7", "output": "1\n0 0 0 0 0 0 0" }, { "input": "9 9\n4 5\n5 8\n1 8\n4 8\n3 4\n7 8\n1 4\n7 8\n6 7", "output": "2\n0 1 0 1 0 1 0 1 0" }, { "input": "10 10\n1 5\n7 10\n2 10\n2 5\n2 9\n5 9\n3 10\n4 9\n6 9\n2 7", "output": "4\n0 1 2 3 0 1 2 3 0 1" }, { "input": "8 7\n5 8\n3 7\n1 8\n3 4\n2 8\n2 7\n4 6", "output": "2\n0 1 0 1 0 1 0 1" }, { "input": "10 3\n2 4\n8 10\n4 6", "output": "3\n0 1 2 0 1 2 0 1 2 0" }, { "input": "5 8\n3 4\n1 5\n3 4\n3 5\n3 4\n1 4\n1 5\n2 5", "output": "2\n0 1 0 1 0" }, { "input": "9 4\n5 9\n3 8\n2 8\n1 4", "output": "4\n0 1 2 3 0 1 2 3 0" }, { "input": "7 7\n2 4\n1 4\n3 6\n2 6\n5 7\n3 6\n1 4", "output": "3\n0 1 2 0 1 2 0" }, { "input": "6 2\n4 6\n2 5", "output": "3\n0 1 2 0 1 2" }, { "input": "7 9\n6 7\n1 2\n2 5\n4 7\n1 7\n5 6\n2 3\n6 7\n1 2", "output": "2\n0 1 0 1 0 1 0" } ]
1,549,893,050
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define FORD(i,a,b) for(int i=(a);i>=(b);i--) #define A first #define B second #define make_pair MP #define MOD 1000000007 #define MAXM 100005 inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; } const int INF = 1<<29; typedef pair<int,int> ii; typedef vector<ii> vii; typedef long long ll; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n>>b)&1; } inline void set_bit(int & n, int b) { n |= two(b); } inline void unset_bit(int & n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; } template<class T> void chmax(T & a, const T & b) { a = max(a, b); } template<class T> void chmin(T & a, const T & b) { a = min(a, b); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int mulmd(ll a, ll b){ ll ret = (a * b) % MOD; return (int)ret; } inline int power(ll x, ll y, int p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = mulmd(res,x); y = y>>1; x = mulmd(x,x); } return (int)res; } int submd(ll a, ll b){ ll ret = a-b; if(ret<0){ ret+=MOD; } return (int)ret; } int addmd(ll a, ll b){ ll ret = (a + b) % MOD; return (int)ret; } int phi(int n){ int result = n; for(int i=2;i*i<=n;i++){ if(n%i==0){ while(n%i==0){ n=n/i; } result-=result/i; } } if(n>1) result-=result/n; return result; } int gcd(int a, int b, int& x, int& y){ if(a==0){ x=0; y=1; return b; } int x1,y1; int d = gcd(b%a, a, x1, y1); x = y1 - (b/a)*x1; y = x1; return d; } int arr[100005]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin>>n>>m; int mn=INT_MAX; REP(i,m){ int x,y; cin>>x>>y; mn=min(mn,y-x+1); } cout<<mn<<"\n"; REP(i,n){ cout<<(i%mn)<<" "; } }
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**i* and *r**i*, and its elements are *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Alyona is going to find mex for each of the chosen subarrays. Among these *m* mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible. You are to find an array *a* of *n* elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible. The mex of a set *S* is a minimum possible non-negative integer that is not in *S*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Output Specification: In the first line print single integer — the maximum possible minimum mex. In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109. It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109. If there are multiple solutions, print any of them. Demo Input: ['5 3\n1 3\n2 5\n4 5\n', '4 2\n1 4\n2 4\n'] Demo Output: ['2\n1 0 2 1 0\n', '3\n5 2 0 1'] Note: The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
```python #include<bits/stdc++.h> using namespace std; #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define FORD(i,a,b) for(int i=(a);i>=(b);i--) #define A first #define B second #define make_pair MP #define MOD 1000000007 #define MAXM 100005 inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; } const int INF = 1<<29; typedef pair<int,int> ii; typedef vector<ii> vii; typedef long long ll; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n>>b)&1; } inline void set_bit(int & n, int b) { n |= two(b); } inline void unset_bit(int & n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; } template<class T> void chmax(T & a, const T & b) { a = max(a, b); } template<class T> void chmin(T & a, const T & b) { a = min(a, b); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int mulmd(ll a, ll b){ ll ret = (a * b) % MOD; return (int)ret; } inline int power(ll x, ll y, int p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = mulmd(res,x); y = y>>1; x = mulmd(x,x); } return (int)res; } int submd(ll a, ll b){ ll ret = a-b; if(ret<0){ ret+=MOD; } return (int)ret; } int addmd(ll a, ll b){ ll ret = (a + b) % MOD; return (int)ret; } int phi(int n){ int result = n; for(int i=2;i*i<=n;i++){ if(n%i==0){ while(n%i==0){ n=n/i; } result-=result/i; } } if(n>1) result-=result/n; return result; } int gcd(int a, int b, int& x, int& y){ if(a==0){ x=0; y=1; return b; } int x1,y1; int d = gcd(b%a, a, x1, y1); x = y1 - (b/a)*x1; y = x1; return d; } int arr[100005]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin>>n>>m; int mn=INT_MAX; REP(i,m){ int x,y; cin>>x>>y; mn=min(mn,y-x+1); } cout<<mn<<"\n"; REP(i,n){ cout<<(i%mn)<<" "; } } ```
-1
873
F
Forbidden Indices
PROGRAMMING
2,400
[ "dsu", "string suffix structures", "strings" ]
null
null
You are given a string *s* consisting of *n* lowercase Latin letters. Some indices in this string are marked as forbidden. You want to find a string *a* such that the value of |*a*|·*f*(*a*) is maximum possible, where *f*(*a*) is the number of occurences of *a* in *s* such that these occurences end in non-forbidden indices. So, for example, if *s* is aaaa, *a* is aa and index 3 is forbidden, then *f*(*a*)<==<=2 because there are three occurences of *a* in *s* (starting in indices 1, 2 and 3), but one of them (starting in index 2) ends in a forbidden index. Calculate the maximum possible value of |*a*|·*f*(*a*) you can get.
The first line contains an integer number *n* (1<=≤<=*n*<=≤<=200000) — the length of *s*. The second line contains a string *s*, consisting of *n* lowercase Latin letters. The third line contains a string *t*, consisting of *n* characters 0 and 1. If *i*-th character in *t* is 1, then *i* is a forbidden index (otherwise *i* is not forbidden).
Print the maximum possible value of |*a*|·*f*(*a*).
[ "5\nababa\n00100\n", "5\nababa\n00000\n", "5\nababa\n11111\n" ]
[ "5\n", "6\n", "0\n" ]
none
0
[ { "input": "5\nababa\n00100", "output": "5" }, { "input": "5\nababa\n00000", "output": "6" }, { "input": "5\nababa\n11111", "output": "0" }, { "input": "100\neebdeddddbecdbddaaecbbaccbecdeacedddcaddcdebedbabbceeeadecadbbeaecdaeabbceacbdbdbbdacebbbccdcbbeedbe\n1101101101110110001000001101001000100001010111001001111000111011000111111010110100000111001100100000", "output": "100" }, { "input": "100\nabbbafdcebdafbfdbbcfbdbeaceccccaaabddccbeccedbdaffdccbababbbdcefbecbfaeadbddebeeaaeaaeeccbefaefbadff\n0111100010011011011011001100111001011111011101110001001001110111101110111110100101010111100111001001", "output": "99" }, { "input": "100\necagcedagfdeccefgfcfecdbgefegfgeaccdgagccfebecdcbeeegcdgbeecdebbgcfddggdfegbffdgccdaabfabadbbdedcagg\n1000101111001110110011111100111011000010000001101010010001111101111010010001111100100000110010001100", "output": "100" }, { "input": "100\neaagbfedbcgfddhdcacfccaagcfgfdadadhbggbfbdchhfcgbdgchagabdfcaafedgaacaadhehgagafhgedcggfdfacagdcecde\n1011001000111111100100111001111110001101010111011010001001111110000101000101011101010001011001101101", "output": "99" }, { "input": "200\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n11011010000011010010011110001000001101110111001110000101001100000001010100001101111100010000101111100110010001111011010010000100111111000101110101110111110110000110100011011101001010000000111000100010", "output": "5200" }, { "input": "200\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "10000" }, { "input": "200\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "10100" }, { "input": "200\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "200\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "0" }, { "input": "200\nbaaaabbbaabbaaababbbabbbababbabbbbaaabbaabbbbbabaaabbbbbabbbbaabbaaaabababbaaaaabaabaabbabbabbaabbaabaaabbaaabaaabbbbbaaaabaabbaaaabbaabaaaaabaabbabababbbabababaabbaabbbbabbabbababaaaabaaababbaaaababb\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "199" }, { "input": "200\nbaabaaabaabbbbbaabbaababbbbaabbbabbbaabaabaabbbbabaaabbbbbabaabbaababbbabaaaabbabbbabbbbabbbbabbbaabaabbbbbbaabbaababbababbabbbaaaabbbabbabbaabbbbbabbababbbabbbbaaaaaaababbababaabbabbbbabaabaaaaaababa\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "200" }, { "input": "200\nbbbbaaaababaaaaabbaabbbbbabaaaababaaababbaaababaabbbbaaabaababaaaaaabaaabbbbbabbbaabbaaabbbabbabbbbaaabbbaabbaaaaaaaaaabaabaababbbbbbbbabbbbabababbaababbabbbbbababbaaaaaabaabaaaababbabaabaabbbaaaaabbb\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "200\naaaaaaaaabbbbababaaabbbabbabbaaabababbaabaaaaaabaaababbaabbbabbbaabbbabbabbbbabbbbaabababbabbbababbbaaabaaabaaaaababaabbbabaabbbbababaaaaabbbabbabaabbabbabbaaabbbaababaabbbabbbaababaaabbaabaaabbbbbaba\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "0" }, { "input": "200\nbaabccacbabbbbcaccbcbcbbbbcbaccacbbcacabcbbaaccaacbaaabcabccbaccccbacaacbabcacbabaacbbaccbaaaccbaacbbaacaabcaaacbbbabaaabcaaabacccbbaabbbacaabbabccbbbcbbccabababbccbbbcbcccacbcacbabccababaccbcbbaaabcb\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "199" }, { "input": "200\ncbccbabbbbaacbbabccaababcaabbacbccaccbbcaaccbbaccccccbaabbcabaabaaaaabbcbbbcababcabcaaabccaacaccbcacaababbbaccabbcbcbbbabbbbcbaaaaacbaabccbbbabaccacbcbbaabaaabcbaabbacabcbabcacbabaabcbcacbcabbbbaaabac\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "200" }, { "input": "200\ncacaacabcabaccbcbaaaababbbcacbaaacbbaccabcacabaccbbbaaacabcacaabbabcacabbaacccbcbcbaccbbabbcbbbbabbaabaccbcbbabcacbbabbcacccbacabccbccacabaabccaabccaabbbabaabccbbaabccaccaabacbbbbbcacacbbcccbbbacbcbbb\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "200\naacccbcbbabcbbccbcacaacabccaabbbacbbccbcaaccacacabcbababbbbaaacaaaaaacaaacbbaaaacccabaaccbcccacbccbcbcaacbccabbcbbcccaacbacacbbabccbbcccbcccaaabacbbbabcbaccccbacccbaaabacacabbaccacbaaaaccbccbaaaabcbcb\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "0" }, { "input": "1\na\n0", "output": "1" }, { "input": "1\nt\n1", "output": "0" }, { "input": "11\nbaaaaaaaaaa\n00000000000", "output": "30" }, { "input": "7\ncaaaaaa\n0000000", "output": "12" } ]
1,677,188,779
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
77
11,571,200
def SAIS(A): """ Calculates suffix array in O(len(A) + max(A)) Input: Int list A with A[i] >= 0 for all i """ n = len(A) buckets = [0] * (max(A) + 2) for a in A: buckets[a + 1] += 1 for b in range(1, len(buckets)): buckets[b] += buckets[b - 1] isL = [1] * n for i in reversed(range(n - 1)): isL[i] = +(A[i] > A[i + 1]) if A[i] != A[i + 1] else isL[i + 1] def induced_sort(LMS): SA = [-1] * (n) SA.append(n) endpoint = buckets[1:] for j in reversed(LMS): endpoint[A[j]] -= 1 SA[endpoint[A[j]]] = j startpoint = buckets[:-1] for i in range(-1, n): j = SA[i] - 1 if j >= 0 and isL[j]: SA[startpoint[A[j]]] = j startpoint[A[j]] += 1 SA.pop() endpoint = buckets[1:] for i in reversed(range(n)): j = SA[i] - 1 if j >= 0 and not isL[j]: endpoint[A[j]] -= 1 SA[endpoint[A[j]]] = j return SA isLMS = [+(i and isL[i - 1] and not isL[i]) for i in range(n)] isLMS.append(1) LMS = [i for i in range(n) if isLMS[i]] if len(LMS) > 1: SA = induced_sort(LMS) LMS2 = [i for i in SA if isLMS[i]] prev = -1 j = 0 for i in LMS2: i1 = prev i2 = i while prev >= 0 and A[i1] == A[i2]: i1 += 1 i2 += 1 if isLMS[i1] or isLMS[i2]: j -= isLMS[i1] and isLMS[i2] break j += 1 prev = i SA[i] = j LMS = [LMS[i] for i in SAIS([SA[i] for i in LMS])] return induced_sort(LMS) def KASAI(A, SA): """ Calculates LCP array in O(n) time Input: String A and its suffix array SA """ n = len(A) rank = [0] * n for i in range(n): rank[SA[i]] = i LCP = [0] * (n - 1) k = 0 for i in range(n): SAind = rank[i] if SAind == n - 1: continue j = SA[SAind + 1] while i + k < n and A[i + k] == A[j + k]: k += 1 LCP[SAind] = k k -= k > 0 return LCP n = int(input()) s = input().strip() t = input().strip() s = s[::-1] t = t[::-1] SA = SAIS([ord(c) for c in s]) LCP = [0, 0] + KASAI(s, SA) SA = [n]+SA ans = 0 # take as much of the string as possible for i in range(n): if(t[i] != '1'): ans = n - i break # all indices are disallowed print(0) exit() prefix = [0,0] accum = 0 # calculate prefixes of allowed starts for i in SA[1:]: if (t[i] != '1'): accum += 1 prefix.append(accum) stk = [] L = [0 for _ in range(n+1)] for i in (range(n+1)): # first = value, second = index ind = (n + 10, 0); while len(stk) > 0: if stk[-1][0] < LCP[i]: ind = stk[-1] break stk.pop() L[i] = ind[1] stk.append((LCP[i], i)) stk = [] R = [0 for _ in range(n+1)] for i in reversed(range(n+1)): # first = value, second = index ind = (n + 10, n+1); while len(stk) > 0: if stk[-1][0] < LCP[i]: ind = stk[-1] break stk.pop() R[i] = ind[1] stk.append((LCP[i], i)) # take [L[i], R[i]) for i in range(n+1): ans = max(LCP[i]*(prefix[R[i]] - prefix[L[i]]), ans); print(ans)
Title: Forbidden Indices Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting of *n* lowercase Latin letters. Some indices in this string are marked as forbidden. You want to find a string *a* such that the value of |*a*|·*f*(*a*) is maximum possible, where *f*(*a*) is the number of occurences of *a* in *s* such that these occurences end in non-forbidden indices. So, for example, if *s* is aaaa, *a* is aa and index 3 is forbidden, then *f*(*a*)<==<=2 because there are three occurences of *a* in *s* (starting in indices 1, 2 and 3), but one of them (starting in index 2) ends in a forbidden index. Calculate the maximum possible value of |*a*|·*f*(*a*) you can get. Input Specification: The first line contains an integer number *n* (1<=≤<=*n*<=≤<=200000) — the length of *s*. The second line contains a string *s*, consisting of *n* lowercase Latin letters. The third line contains a string *t*, consisting of *n* characters 0 and 1. If *i*-th character in *t* is 1, then *i* is a forbidden index (otherwise *i* is not forbidden). Output Specification: Print the maximum possible value of |*a*|·*f*(*a*). Demo Input: ['5\nababa\n00100\n', '5\nababa\n00000\n', '5\nababa\n11111\n'] Demo Output: ['5\n', '6\n', '0\n'] Note: none
```python def SAIS(A): """ Calculates suffix array in O(len(A) + max(A)) Input: Int list A with A[i] >= 0 for all i """ n = len(A) buckets = [0] * (max(A) + 2) for a in A: buckets[a + 1] += 1 for b in range(1, len(buckets)): buckets[b] += buckets[b - 1] isL = [1] * n for i in reversed(range(n - 1)): isL[i] = +(A[i] > A[i + 1]) if A[i] != A[i + 1] else isL[i + 1] def induced_sort(LMS): SA = [-1] * (n) SA.append(n) endpoint = buckets[1:] for j in reversed(LMS): endpoint[A[j]] -= 1 SA[endpoint[A[j]]] = j startpoint = buckets[:-1] for i in range(-1, n): j = SA[i] - 1 if j >= 0 and isL[j]: SA[startpoint[A[j]]] = j startpoint[A[j]] += 1 SA.pop() endpoint = buckets[1:] for i in reversed(range(n)): j = SA[i] - 1 if j >= 0 and not isL[j]: endpoint[A[j]] -= 1 SA[endpoint[A[j]]] = j return SA isLMS = [+(i and isL[i - 1] and not isL[i]) for i in range(n)] isLMS.append(1) LMS = [i for i in range(n) if isLMS[i]] if len(LMS) > 1: SA = induced_sort(LMS) LMS2 = [i for i in SA if isLMS[i]] prev = -1 j = 0 for i in LMS2: i1 = prev i2 = i while prev >= 0 and A[i1] == A[i2]: i1 += 1 i2 += 1 if isLMS[i1] or isLMS[i2]: j -= isLMS[i1] and isLMS[i2] break j += 1 prev = i SA[i] = j LMS = [LMS[i] for i in SAIS([SA[i] for i in LMS])] return induced_sort(LMS) def KASAI(A, SA): """ Calculates LCP array in O(n) time Input: String A and its suffix array SA """ n = len(A) rank = [0] * n for i in range(n): rank[SA[i]] = i LCP = [0] * (n - 1) k = 0 for i in range(n): SAind = rank[i] if SAind == n - 1: continue j = SA[SAind + 1] while i + k < n and A[i + k] == A[j + k]: k += 1 LCP[SAind] = k k -= k > 0 return LCP n = int(input()) s = input().strip() t = input().strip() s = s[::-1] t = t[::-1] SA = SAIS([ord(c) for c in s]) LCP = [0, 0] + KASAI(s, SA) SA = [n]+SA ans = 0 # take as much of the string as possible for i in range(n): if(t[i] != '1'): ans = n - i break # all indices are disallowed print(0) exit() prefix = [0,0] accum = 0 # calculate prefixes of allowed starts for i in SA[1:]: if (t[i] != '1'): accum += 1 prefix.append(accum) stk = [] L = [0 for _ in range(n+1)] for i in (range(n+1)): # first = value, second = index ind = (n + 10, 0); while len(stk) > 0: if stk[-1][0] < LCP[i]: ind = stk[-1] break stk.pop() L[i] = ind[1] stk.append((LCP[i], i)) stk = [] R = [0 for _ in range(n+1)] for i in reversed(range(n+1)): # first = value, second = index ind = (n + 10, n+1); while len(stk) > 0: if stk[-1][0] < LCP[i]: ind = stk[-1] break stk.pop() R[i] = ind[1] stk.append((LCP[i], i)) # take [L[i], R[i]) for i in range(n+1): ans = max(LCP[i]*(prefix[R[i]] - prefix[L[i]]), ans); print(ans) ```
0
851
B
Arpa and an exam about geometry
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*. Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct.
Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower).
[ "0 1 1 1 1 0\n", "1 1 0 0 1000 1000\n" ]
[ "Yes\n", "No\n" ]
In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
1,000
[ { "input": "0 1 1 1 1 0", "output": "Yes" }, { "input": "1 1 0 0 1000 1000", "output": "No" }, { "input": "1 0 2 0 3 0", "output": "No" }, { "input": "3 4 0 0 4 3", "output": "Yes" }, { "input": "-1000000000 1 0 0 1000000000 1", "output": "Yes" }, { "input": "49152 0 0 0 0 81920", "output": "No" }, { "input": "1 -1 4 4 2 -3", "output": "No" }, { "input": "-2 -2 1 4 -2 0", "output": "No" }, { "input": "5 0 4 -2 0 1", "output": "No" }, { "input": "-4 -3 2 -1 -3 4", "output": "No" }, { "input": "-3 -3 5 2 3 -1", "output": "No" }, { "input": "-1000000000 -1000000000 0 0 1000000000 999999999", "output": "No" }, { "input": "-1000000000 -1000000000 0 0 1000000000 1000000000", "output": "No" }, { "input": "-357531221 381512519 -761132895 -224448284 328888775 -237692564", "output": "No" }, { "input": "264193194 -448876521 736684426 -633906160 -328597212 -47935734", "output": "No" }, { "input": "419578772 -125025887 169314071 89851312 961404059 21419450", "output": "No" }, { "input": "-607353321 -620687860 248029390 477864359 728255275 -264646027", "output": "No" }, { "input": "299948862 -648908808 338174789 841279400 -850322448 350263551", "output": "No" }, { "input": "48517753 416240699 7672672 272460100 -917845051 199790781", "output": "No" }, { "input": "-947393823 -495674431 211535284 -877153626 -522763219 -778236665", "output": "No" }, { "input": "-685673792 -488079395 909733355 385950193 -705890324 256550506", "output": "No" }, { "input": "-326038504 547872194 49630307 713863100 303770000 -556852524", "output": "No" }, { "input": "-706921242 -758563024 -588592101 -443440080 858751713 238854303", "output": "No" }, { "input": "-1000000000 -1000000000 0 1000000000 1000000000 -1000000000", "output": "Yes" }, { "input": "1000000000 1000000000 0 -1000000000 -1000000000 1000000000", "output": "Yes" }, { "input": "-999999999 -1000000000 0 0 1000000000 999999999", "output": "Yes" }, { "input": "-1000000000 -999999999 0 0 1000000000 999999999", "output": "No" }, { "input": "-1 -1000000000 0 1000000000 1 -1000000000", "output": "Yes" }, { "input": "0 1000000000 1 0 0 -1000000000", "output": "Yes" }, { "input": "0 1000000000 0 0 0 -1000000000", "output": "No" }, { "input": "0 1 1 2 2 3", "output": "No" }, { "input": "999999999 1000000000 0 0 -1000000000 -999999999", "output": "Yes" }, { "input": "0 0 1 1 2 0", "output": "Yes" }, { "input": "0 0 1 1 2 2", "output": "No" }, { "input": "1 1 2 2 3 3", "output": "No" }, { "input": "0 2 0 3 0 4", "output": "No" }, { "input": "1 1 1 2 1 3", "output": "No" }, { "input": "0 0 3 4 3 9", "output": "Yes" }, { "input": "589824 196608 262144 196608 0 0", "output": "Yes" }, { "input": "0 0 1000000000 1 1000000000 -999999999", "output": "No" }, { "input": "0 0 2 45 0 90", "output": "Yes" }, { "input": "0 0 0 2 0 1", "output": "No" }, { "input": "0 2 4 5 4 0", "output": "Yes" }, { "input": "0 0 2 0 4 0", "output": "No" }, { "input": "1 1 3 3 5 5", "output": "No" }, { "input": "1 1 2 2 3 1", "output": "Yes" } ]
1,699,261,184
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
import math a= list(map(int,input().split())) d=(a[3]-a[1])**2 + (a[0]-a[2])**2 e=(a[5]-a[1])**2 + (a[0]-a[4])**2 f=(a[3]-a[5])**2 + (a[4]-a[2])**2 if d==e or e==f or d==f: print("Yes") else: print("No")
Title: Arpa and an exam about geometry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*. Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not. Input Specification: The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. Output Specification: Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['0 1 1 1 1 0\n', '1 1 0 0 1000 1000\n'] Demo Output: ['Yes\n', 'No\n'] Note: In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
```python import math a= list(map(int,input().split())) d=(a[3]-a[1])**2 + (a[0]-a[2])**2 e=(a[5]-a[1])**2 + (a[0]-a[4])**2 f=(a[3]-a[5])**2 + (a[4]-a[2])**2 if d==e or e==f or d==f: print("Yes") else: print("No") ```
0
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input": "2\n100 100", "output": "2" }, { "input": "3\n100 100 100", "output": "3" }, { "input": "11\n1 2 3 4 5 6 5 4 3 2 1", "output": "11" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 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 1 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": "61" }, { "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 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1", "output": "81" }, { "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 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1", "output": "85" }, { "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 1 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 100 7 6 5 4 3 2 1", "output": "61" }, { "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 100 8 7 6 1 4 3 2 1", "output": "96" }, { "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 100 10 9 8 7 6 5 4 3 2 1", "output": "100" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 1 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 100 11 10 9 8 7 6 5 4 3 2 1", "output": "55" }, { "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 1 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 100 12 11 10 9 8 7 6 5 4 3 2 1", "output": "59" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 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 100 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "86" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 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": "83" }, { "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 100 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 1 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": "74" }, { "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 100 9 8 7 6 5 4 3 2 1", "output": "100" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 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 1 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": "52" }, { "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 100 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 1 2 1", "output": "98" }, { "input": "10\n1 4 4 4 4 4 1 2 4 3", "output": "7" } ]
1,686,541,625
2,147,483,647
PyPy 3-64
OK
TESTS
80
154
1,945,600
n=int(input()) a=list(map(int,input().split())) ans=0 for i in range(len(a)): r=i t=i-1 k=1 while t>=0 and a[t]<=a[r]: k+=1 r=t t-=1 q=i+1 s=i while q<n and a[s]>=a[q]: s=q q+=1 k+=1 ans=max(ans,k) print(ans)
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. Output Specification: Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. Demo Input: ['1\n2\n', '5\n1 2 1 2 1\n', '8\n1 2 1 1 1 3 3 4\n'] Demo Output: ['1\n', '3\n', '6\n'] Note: none
```python n=int(input()) a=list(map(int,input().split())) ans=0 for i in range(len(a)): r=i t=i-1 k=1 while t>=0 and a[t]<=a[r]: k+=1 r=t t-=1 q=i+1 s=i while q<n and a[s]>=a[q]: s=q q+=1 k+=1 ans=max(ans,k) print(ans) ```
3.957876
298
A
Snow Footprints
PROGRAMMING
1,300
[ "greedy", "implementation" ]
null
null
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints.
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them.
[ "9\n..RRLL...\n", "11\n.RRRLLLLL..\n" ]
[ "3 4\n", "7 5\n" ]
The first test sample is the one in the picture.
500
[ { "input": "11\n.RRRLLLLL..", "output": "7 5" }, { "input": "4\n.RL.", "output": "3 2" }, { "input": "3\n.L.", "output": "2 1" }, { "input": "3\n.R.", "output": "2 3" } ]
1,580,639,464
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
218
0
n = int(input()) s = input() start = 0 for i in range(n): if s[i] != '.': start = i+1 break t = start for i in range(n): if s[i] != '.': if s[i] == 'R': t = i + 1 else: t = i - 1 print(start, t)
Title: Snow Footprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints. Input Specification: The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists. Output Specification: Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them. Demo Input: ['9\n..RRLL...\n', '11\n.RRRLLLLL..\n'] Demo Output: ['3 4\n', '7 5\n'] Note: The first test sample is the one in the picture.
```python n = int(input()) s = input() start = 0 for i in range(n): if s[i] != '.': start = i+1 break t = start for i in range(n): if s[i] != '.': if s[i] == 'R': t = i + 1 else: t = i - 1 print(start, t) ```
0
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", "output": "1" }, { "input": "1000 9", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "999 9", "output": "1" }, { "input": "999 8", "output": "2" }, { "input": "105 6", "output": "2" }, { "input": "403 9", "output": "3" }, { "input": "546 4", "output": "4" }, { "input": "228 9", "output": "5" }, { "input": "57 2", "output": "6" }, { "input": "437 9", "output": "7" }, { "input": "997 6", "output": "8" }, { "input": "109 1", "output": "9" }, { "input": "998 9", "output": "5" }, { "input": "4 2", "output": "3" }, { "input": "9 3", "output": "7" }, { "input": "8 2", "output": "4" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "7" }, { "input": "1 8", "output": "8" }, { "input": "100 3", "output": "1" }, { "input": "1000 2", "output": "1" }, { "input": "1000 4", "output": "1" }, { "input": "1000 5", "output": "1" }, { "input": "1000 6", "output": "1" }, { "input": "1000 7", "output": "1" }, { "input": "1000 8", "output": "1" }, { "input": "23 4", "output": "8" }, { "input": "33 1", "output": "7" }, { "input": "33 2", "output": "4" }, { "input": "666 5", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "5 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "12 4", "output": "2" }, { "input": "15 5", "output": "1" }, { "input": "2 5", "output": "5" }, { "input": "25 5", "output": "1" }, { "input": "2 9", "output": "5" }, { "input": "6 7", "output": "5" }, { "input": "8 9", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "4 7", "output": "5" }, { "input": "2 1", "output": "5" }, { "input": "261 1", "output": "1" } ]
1,675,588,155
2,147,483,647
Python 3
OK
TESTS
54
46
0
k,r = map(int, input().split()) counting = True count =1 while(counting): if(k*count%10 == 0): counting = False elif(k*count%10==r): counting = False count = count+1 print(count-1)
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. Input Specification: The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. Output Specification: Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. Demo Input: ['117 3\n', '237 7\n', '15 2\n'] Demo Output: ['9\n', '1\n', '2\n'] Note: In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
```python k,r = map(int, input().split()) counting = True count =1 while(counting): if(k*count%10 == 0): counting = False elif(k*count%10==r): counting = False count = count+1 print(count-1) ```
3
724
C
Ray Tracing
PROGRAMMING
1,800
[ "greedy", "hashing", "implementation", "math", "number theory", "sortings" ]
null
null
There are *k* sensors located in the rectangular room of size *n*<=×<=*m* meters. The *i*-th sensor is located at point (*x**i*,<=*y**i*). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0,<=0) and (*n*,<=*m*). Walls of the room are parallel to coordinate axes. At the moment 0, from the point (0,<=0) the laser ray is released in the direction of point (1,<=1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1,<=1) in exactly one second after the start. When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops. For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print <=-<=1 for such sensors.
The first line of the input contains three integers *n*, *m* and *k* (2<=≤<=*n*,<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — lengths of the room's walls and the number of sensors. Each of the following *k* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=*n*<=-<=1, 1<=≤<=*y**i*<=≤<=*m*<=-<=1) — coordinates of the sensors. It's guaranteed that no two sensors are located at the same point.
Print *k* integers. The *i*-th of them should be equal to the number of seconds when the ray first passes through the point where the *i*-th sensor is located, or <=-<=1 if this will never happen.
[ "3 3 4\n1 1\n1 2\n2 1\n2 2\n", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3\n", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3\n" ]
[ "1\n-1\n-1\n2\n", "1\n-1\n-1\n2\n5\n-1\n", "13\n2\n9\n5\n-1\n" ]
In the first sample, the ray will consequently pass through the points (0, 0), (1, 1), (2, 2), (3, 3). Thus, it will stop at the point (3, 3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0, 0), (1, 1), (2, 2), (3, 3), (2, 4), (1, 3), (0, 2), (1, 1), (2, 0), (3, 1), (2, 2), (1, 3), (0, 4). The ray will stop at the point (0, 4) after 12 seconds. It will reflect at the points (3, 3), (2, 4), (0, 2), (2, 0) and (3, 1).
1,500
[ { "input": "3 3 4\n1 1\n1 2\n2 1\n2 2", "output": "1\n-1\n-1\n2" }, { "input": "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "output": "1\n-1\n-1\n2\n5\n-1" }, { "input": "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3", "output": "13\n2\n9\n5\n-1" }, { "input": "10 10 10\n3 8\n1 7\n2 3\n4 2\n4 8\n3 3\n2 8\n5 5\n6 3\n3 1", "output": "-1\n-1\n-1\n-1\n-1\n3\n-1\n5\n-1\n-1" } ]
1,476,477,708
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
4,812,800
print("Ray Tracing program") print("first is width, second is hight ,third number of point") s=input() #take firs line of input s=s.split() m,n,k=int(s[0])+1,int(s[1])+1,int(s[2]) #m=width , n=hight , k=inputs arr=[] # initialize the width and hight of the array for i in range(n): arr.append([0 for j in range(m)]) #taking inputs save it in array named point point=[] #this array will hold the time the ray taked to reach point for i in range(k): s=input() s=s.split() point.append([int(s[0]),int(s[1]),-1]) #mark points in the array for i in range(len(point)): arr[point[i][1]][point[i][0]]=-1 r,c,x,y,count=1,1,0,0,0 while not(y==n-1 and x==m-1 or y==0 and x==m-1 or y==n-1 and x==0): #test if the point collision with a wall ? if (y==n-1 or y==0): if count != 0: r*=-1 #test if the point collision with a wall ? if (x==m-1 or x==0) : if count != 0: c*=-1 x+=c y+=r count+=1 #time #check if ray pass through a point ? if arr[y][x]==-1: arr[y][x]=0 for entry in point: if x==entry[0] and y==entry[1]: entry[2]=count #output for entry in point: print(entry[2])
Title: Ray Tracing Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *k* sensors located in the rectangular room of size *n*<=×<=*m* meters. The *i*-th sensor is located at point (*x**i*,<=*y**i*). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0,<=0) and (*n*,<=*m*). Walls of the room are parallel to coordinate axes. At the moment 0, from the point (0,<=0) the laser ray is released in the direction of point (1,<=1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1,<=1) in exactly one second after the start. When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops. For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print <=-<=1 for such sensors. Input Specification: The first line of the input contains three integers *n*, *m* and *k* (2<=≤<=*n*,<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — lengths of the room's walls and the number of sensors. Each of the following *k* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=*n*<=-<=1, 1<=≤<=*y**i*<=≤<=*m*<=-<=1) — coordinates of the sensors. It's guaranteed that no two sensors are located at the same point. Output Specification: Print *k* integers. The *i*-th of them should be equal to the number of seconds when the ray first passes through the point where the *i*-th sensor is located, or <=-<=1 if this will never happen. Demo Input: ['3 3 4\n1 1\n1 2\n2 1\n2 2\n', '3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3\n', '7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3\n'] Demo Output: ['1\n-1\n-1\n2\n', '1\n-1\n-1\n2\n5\n-1\n', '13\n2\n9\n5\n-1\n'] Note: In the first sample, the ray will consequently pass through the points (0, 0), (1, 1), (2, 2), (3, 3). Thus, it will stop at the point (3, 3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0, 0), (1, 1), (2, 2), (3, 3), (2, 4), (1, 3), (0, 2), (1, 1), (2, 0), (3, 1), (2, 2), (1, 3), (0, 4). The ray will stop at the point (0, 4) after 12 seconds. It will reflect at the points (3, 3), (2, 4), (0, 2), (2, 0) and (3, 1).
```python print("Ray Tracing program") print("first is width, second is hight ,third number of point") s=input() #take firs line of input s=s.split() m,n,k=int(s[0])+1,int(s[1])+1,int(s[2]) #m=width , n=hight , k=inputs arr=[] # initialize the width and hight of the array for i in range(n): arr.append([0 for j in range(m)]) #taking inputs save it in array named point point=[] #this array will hold the time the ray taked to reach point for i in range(k): s=input() s=s.split() point.append([int(s[0]),int(s[1]),-1]) #mark points in the array for i in range(len(point)): arr[point[i][1]][point[i][0]]=-1 r,c,x,y,count=1,1,0,0,0 while not(y==n-1 and x==m-1 or y==0 and x==m-1 or y==n-1 and x==0): #test if the point collision with a wall ? if (y==n-1 or y==0): if count != 0: r*=-1 #test if the point collision with a wall ? if (x==m-1 or x==0) : if count != 0: c*=-1 x+=c y+=r count+=1 #time #check if ray pass through a point ? if arr[y][x]==-1: arr[y][x]=0 for entry in point: if x==entry[0] and y==entry[1]: entry[2]=count #output for entry in point: print(entry[2]) ```
0
583
A
Asphalting Roads
PROGRAMMING
1,000
[ "implementation" ]
null
null
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted. Road repairs are planned for *n*2 days. On the *i*-th day of the team arrives at the *i*-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads. According to the schedule of road works tell in which days at least one road will be asphalted.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city. Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the intersection that goes *i*-th in the timetable is at the intersection of the *h**i*-th horizontal and *v**i*-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct.
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.
[ "2\n1 1\n1 2\n2 1\n2 2\n", "1\n1 1\n" ]
[ "1 4 \n", "1 \n" ]
In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road.
500
[ { "input": "2\n1 1\n1 2\n2 1\n2 2", "output": "1 4 " }, { "input": "1\n1 1", "output": "1 " }, { "input": "2\n1 1\n2 2\n1 2\n2 1", "output": "1 2 " }, { "input": "2\n1 2\n2 2\n2 1\n1 1", "output": "1 3 " }, { "input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 1", "output": "1 4 5 " }, { "input": "3\n1 3\n3 1\n2 1\n1 1\n1 2\n2 2\n3 2\n3 3\n2 3", "output": "1 2 6 " }, { "input": "4\n1 3\n2 3\n2 4\n4 4\n3 1\n1 1\n3 4\n2 1\n1 4\n4 3\n4 1\n3 2\n1 2\n4 2\n2 2\n3 3", "output": "1 3 5 14 " }, { "input": "4\n3 3\n4 2\n2 3\n3 4\n4 4\n1 2\n3 2\n2 2\n1 4\n3 1\n4 1\n2 1\n1 3\n1 1\n4 3\n2 4", "output": "1 2 9 12 " }, { "input": "9\n4 5\n2 3\n8 3\n5 6\n9 3\n4 4\n5 4\n4 7\n1 7\n8 4\n1 4\n1 5\n5 7\n7 8\n7 1\n9 9\n8 7\n7 5\n3 7\n6 6\n7 3\n5 2\n3 6\n7 4\n9 6\n5 8\n9 7\n6 3\n7 9\n1 2\n1 1\n6 2\n5 3\n7 2\n1 6\n4 1\n6 1\n8 9\n2 2\n3 9\n2 9\n7 7\n2 8\n9 4\n2 5\n8 6\n3 4\n2 1\n2 7\n6 5\n9 1\n3 3\n3 8\n5 5\n4 3\n3 1\n1 9\n6 4\n3 2\n6 8\n2 6\n5 9\n8 5\n8 8\n9 5\n6 9\n9 2\n3 5\n4 9\n4 8\n2 4\n5 1\n4 6\n7 6\n9 8\n1 3\n4 2\n8 1\n8 2\n6 7\n1 8", "output": "1 2 4 9 10 14 16 32 56 " }, { "input": "8\n1 1\n1 2\n1 3\n1 4\n1 5\n8 6\n1 7\n1 8\n2 1\n8 5\n2 3\n2 4\n2 5\n2 6\n4 3\n2 2\n3 1\n3 2\n3 3\n3 4\n3 5\n3 6\n5 6\n3 8\n4 1\n4 2\n2 7\n4 4\n8 8\n4 6\n4 7\n4 8\n5 1\n5 2\n5 3\n6 5\n5 5\n3 7\n5 7\n5 8\n6 1\n6 2\n6 3\n6 4\n5 4\n6 6\n6 7\n6 8\n7 1\n7 2\n7 3\n7 4\n7 5\n7 6\n7 7\n7 8\n8 1\n8 2\n8 3\n8 4\n2 8\n1 6\n8 7\n4 5", "output": "1 6 11 18 28 36 39 56 " }, { "input": "9\n9 9\n5 5\n8 8\n3 3\n2 2\n6 6\n4 4\n1 1\n7 7\n8 4\n1 4\n1 5\n5 7\n7 8\n7 1\n1 7\n8 7\n7 5\n3 7\n5 6\n7 3\n5 2\n3 6\n7 4\n9 6\n5 8\n9 7\n6 3\n7 9\n1 2\n4 5\n6 2\n5 3\n7 2\n1 6\n4 1\n6 1\n8 9\n2 3\n3 9\n2 9\n5 4\n2 8\n9 4\n2 5\n8 6\n3 4\n2 1\n2 7\n6 5\n9 1\n8 3\n3 8\n9 3\n4 3\n3 1\n1 9\n6 4\n3 2\n6 8\n2 6\n5 9\n8 5\n4 7\n9 5\n6 9\n9 2\n3 5\n4 9\n4 8\n2 4\n5 1\n4 6\n7 6\n9 8\n1 3\n4 2\n8 1\n8 2\n6 7\n1 8", "output": "1 2 3 4 5 6 7 8 9 " } ]
1,528,663,604
2,147,483,647
Python 3
OK
TESTS
39
109
0
hm = int(input()) hm2 = hm*hm rows = [] cols = [] lis = [] for i in range(1, hm+1): rows.append(i) cols.append(i) for i in range(1, hm2+1): row, col = input().split(" ") row = int(row) col = int(col) if row in rows and col in cols: lis.append(i) rows.remove(row) cols.remove(col) print(*lis, sep=' ')
Title: Asphalting Roads Time Limit: None seconds Memory Limit: None megabytes Problem Description: City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted. Road repairs are planned for *n*2 days. On the *i*-th day of the team arrives at the *i*-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads. According to the schedule of road works tell in which days at least one road will be asphalted. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city. Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the intersection that goes *i*-th in the timetable is at the intersection of the *h**i*-th horizontal and *v**i*-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct. Output Specification: In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. Demo Input: ['2\n1 1\n1 2\n2 1\n2 2\n', '1\n1 1\n'] Demo Output: ['1 4 \n', '1 \n'] Note: In the sample the brigade acts like that: 1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do not asphalt anything; 1. On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road.
```python hm = int(input()) hm2 = hm*hm rows = [] cols = [] lis = [] for i in range(1, hm+1): rows.append(i) cols.append(i) for i in range(1, hm2+1): row, col = input().split(" ") row = int(row) col = int(col) if row in rows and col in cols: lis.append(i) rows.remove(row) cols.remove(col) print(*lis, sep=' ') ```
3
976
E
Well played!
PROGRAMMING
2,100
[ "greedy", "sortings" ]
null
null
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them: Max owns *n* creatures, *i*-th of them can be described with two numbers — its health *hp**i* and its damage *dmg**i*. Max also has two types of spells in stock: 1. Doubles health of the creature (*hp**i* := *hp**i*·2); 1. Assigns value of health of the creature to its damage (*dmg**i* := *hp**i*). Spell of first type can be used no more than *a* times in total, of the second type — no more than *b* times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells. Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way.
The first line contains three integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*a*<=≤<=20, 0<=≤<=*b*<=≤<=2·105) — the number of creatures, spells of the first type and spells of the second type, respectively. The *i*-th of the next *n* lines contain two number *hp**i* and *dmg**i* (1<=≤<=*hp**i*,<=*dmg**i*<=≤<=109) — description of the *i*-th creature.
Print single integer — maximum total damage creatures can deal.
[ "2 1 1\n10 15\n6 1\n", "3 0 3\n10 8\n7 11\n5 2\n" ]
[ "27\n", "26\n" ]
In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6·2 = 27. In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on the third creature. Total damage will be equal to 10 + 11 + 5 = 26.
0
[ { "input": "2 1 1\n10 15\n6 1", "output": "27" }, { "input": "3 0 3\n10 8\n7 11\n5 2", "output": "26" }, { "input": "1 0 0\n2 1", "output": "1" }, { "input": "1 0 200000\n1 2", "output": "2" }, { "input": "7 5 7\n29 25\n84 28\n34 34\n14 76\n85 9\n40 57\n99 88", "output": "3533" }, { "input": "7 6 7\n11 75\n61 90\n22 14\n100 36\n29 48\n69 52\n16 3", "output": "6720" }, { "input": "7 8 7\n88 29\n30 44\n14 1\n83 95\n73 88\n10 42\n29 26", "output": "22840" }, { "input": "12 7 7\n78 189\n614 271\n981 510\n37 762\n803 106\n78 369\n787 54\n768 159\n238 111\n107 54\n207 72\n485 593", "output": "130952" }, { "input": "12 20 4\n852 935\n583 820\n969 197\n219 918\n547 842\n615 163\n704 377\n326 482\n183 833\n884 994\n886 581\n909 450", "output": "1016078777" }, { "input": "2 13 2\n208637 682633\n393097 724045", "output": "3220933257" }, { "input": "1 0 200000\n42 1", "output": "42" }, { "input": "1 6 200000\n42 1", "output": "2688" }, { "input": "1 0 200000\n1 42", "output": "42" }, { "input": "1 6 200000\n1 42", "output": "64" }, { "input": "3 1 1\n10 9\n8 6\n7 5", "output": "31" }, { "input": "1 1 0\n10 1", "output": "1" }, { "input": "1 1 0\n3 4", "output": "4" }, { "input": "3 20 0\n1 5\n5 1\n5 1", "output": "7" }, { "input": "2 5 1\n10 1\n20 20", "output": "641" }, { "input": "3 20 0\n3 2\n4 3\n5 4", "output": "9" }, { "input": "2 1 0\n10 15\n6 1", "output": "16" }, { "input": "5 10 0\n20 1\n22 1\n30 1\n30 5\n40 6", "output": "14" }, { "input": "1 20 0\n1 5", "output": "5" }, { "input": "2 3 14\n28 5\n32 47", "output": "284" }, { "input": "3 1 2\n20 10\n5 1\n25 25", "output": "71" }, { "input": "2 3 3\n28 5\n32 47", "output": "284" }, { "input": "2 2 1\n10 15\n6 1", "output": "41" }, { "input": "2 1 2\n20 1\n22 23", "output": "64" }, { "input": "10 7 2\n8 6\n5 5\n3 7\n7 7\n3 8\n6 1\n10 9\n4 6\n9 5\n7 9", "output": "1339" }, { "input": "3 8 1\n6 6\n7 9\n2 5", "output": "1803" }, { "input": "10 4 4\n5 5\n8 1\n10 10\n3 1\n7 10\n1 7\n8 7\n5 9\n3 3\n1 1", "output": "214" }, { "input": "4 8 3\n1 6\n10 10\n4 8\n9 4", "output": "2583" }, { "input": "8 18 1\n8 6\n6 8\n1 7\n7 2\n5 1\n10 5\n8 3\n9 3", "output": "2621470" }, { "input": "2 11 1\n1 4\n1 5", "output": "2053" }, { "input": "2 19 2\n9 3\n7 2", "output": "4718599" }, { "input": "5 13 0\n4 4\n8 10\n1 8\n3 9\n4 6", "output": "37" }, { "input": "5 8 0\n10 7\n6 6\n6 5\n7 9\n10 7", "output": "34" }, { "input": "5 20 2\n1 10\n7 8\n10 1\n6 5\n2 1", "output": "10485785" }, { "input": "2 1 0\n5 6\n8 8", "output": "14" }, { "input": "7 3 5\n2 6\n5 9\n5 5\n4 10\n5 7\n7 8\n3 10", "output": "103" }, { "input": "10 9 0\n620118469 704168608\n528098892 341451371\n15150469 449838744\n960504540 722185004\n271837337 344050133\n940943201 419522619\n85569623 788965215\n161962866 563795701\n943389281 445744350\n610994199 473866838", "output": "5253588583" }, { "input": "10 11 1\n7 3\n9 4\n1 5\n10 3\n6 1\n10 7\n8 5\n7 6\n1 4\n9 9", "output": "20524" }, { "input": "2 1 200000\n44 42\n1000 1001", "output": "2044" }, { "input": "5 12 2\n5 9\n8 9\n4 1\n2 5\n1 8", "output": "32794" }, { "input": "4 8 1\n9 9\n7 6\n2 4\n6 10", "output": "2324" }, { "input": "2 1 1\n292725479 742903381\n239450691 307356865", "output": "1221804763" } ]
1,657,225,198
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
9
358
10,854,400
from sys import stdin,exit #parsea una línea def parser(): return map(int, stdin.readline().split()) #recibiendo los valores de n, a y b n,a,b=parser() #inicializando las listas de vida y daño hp=[] dmg=[] #recibiendo los parametros de las criaturas for creature in range(n): h,d=parser() hp.append(h) dmg.append(d) #si no hay hechizos de se solo se pueden usar los daños de las criaturas if b==0: print(sum(dmg)) exit() #seleccionando la criatura a la cual le vamos aplicar todos los hechizos de tipo 1 #iniciamos asumiendo que la criatura elegida es la primera chosen_creature=0 best_plus_dmg=hp[0]*2**a-dmg[0] #si no hay hechizos de tipo 1 no hay necesisdad de buscar otra criatura if a > 0: #se itera por las critauras calculando la mejora de daño que pueden ofrecer for i in range(1,n): plus_dmg_i=hp[i]*2**a-dmg[i] #si se encuantra una criatura mejor que la actual se actualiza if plus_dmg_i > best_plus_dmg: chosen_creature=i best_plus_dmg=plus_dmg_i #se actualiza el valor de la vida de la criatura elegida hp[chosen_creature]=best_plus_dmg+dmg[chosen_creature] #se genera una lista que contiene en la posicion i hp[i]-dmg[i] hp_less_dmg=[hp[i]-dmg[i] for i in range(n)] #lista en la que se iran guardando las criaturas con mas daño que vida creatures_hp_more_than_dmg=[] #inicializando el daño en 0 max_damage=0 #se recorre cada criatura for i in range(n): #si su vida es mayor que se daño es una criatura a la cual convendria cambiar su daño por su vida, si no se suma su daño al daño maximo if hp_less_dmg[i] > 0: creatures_hp_more_than_dmg.append(i) else: max_damage+=dmg[i] #se ordenan las criaturas cuya vida es mayor que su daño segun sea esta diferencia en orden descendente ordered_creatures_hp_more_than_dmg=sorted(creatures_hp_more_than_dmg,key= lambda i : hp_less_dmg[i],reverse=True) #se recorren estas criaturas for creature in ordered_creatures_hp_more_than_dmg: #si quedan hechizos de tipo 2 se suma la vida de la criatuara al daño maximo y se elimina uno de estos hechizos if b > 0: max_damage+=hp[creature] b-=1 #en caso de que ya no queden mas hechizos de tipo 2 se suma el daño de la criatura else: max_damage+=dmg[creature] print(max_damage)
Title: Well played! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them: Max owns *n* creatures, *i*-th of them can be described with two numbers — its health *hp**i* and its damage *dmg**i*. Max also has two types of spells in stock: 1. Doubles health of the creature (*hp**i* := *hp**i*·2); 1. Assigns value of health of the creature to its damage (*dmg**i* := *hp**i*). Spell of first type can be used no more than *a* times in total, of the second type — no more than *b* times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells. Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way. Input Specification: The first line contains three integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*a*<=≤<=20, 0<=≤<=*b*<=≤<=2·105) — the number of creatures, spells of the first type and spells of the second type, respectively. The *i*-th of the next *n* lines contain two number *hp**i* and *dmg**i* (1<=≤<=*hp**i*,<=*dmg**i*<=≤<=109) — description of the *i*-th creature. Output Specification: Print single integer — maximum total damage creatures can deal. Demo Input: ['2 1 1\n10 15\n6 1\n', '3 0 3\n10 8\n7 11\n5 2\n'] Demo Output: ['27\n', '26\n'] Note: In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6·2 = 27. In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on the third creature. Total damage will be equal to 10 + 11 + 5 = 26.
```python from sys import stdin,exit #parsea una línea def parser(): return map(int, stdin.readline().split()) #recibiendo los valores de n, a y b n,a,b=parser() #inicializando las listas de vida y daño hp=[] dmg=[] #recibiendo los parametros de las criaturas for creature in range(n): h,d=parser() hp.append(h) dmg.append(d) #si no hay hechizos de se solo se pueden usar los daños de las criaturas if b==0: print(sum(dmg)) exit() #seleccionando la criatura a la cual le vamos aplicar todos los hechizos de tipo 1 #iniciamos asumiendo que la criatura elegida es la primera chosen_creature=0 best_plus_dmg=hp[0]*2**a-dmg[0] #si no hay hechizos de tipo 1 no hay necesisdad de buscar otra criatura if a > 0: #se itera por las critauras calculando la mejora de daño que pueden ofrecer for i in range(1,n): plus_dmg_i=hp[i]*2**a-dmg[i] #si se encuantra una criatura mejor que la actual se actualiza if plus_dmg_i > best_plus_dmg: chosen_creature=i best_plus_dmg=plus_dmg_i #se actualiza el valor de la vida de la criatura elegida hp[chosen_creature]=best_plus_dmg+dmg[chosen_creature] #se genera una lista que contiene en la posicion i hp[i]-dmg[i] hp_less_dmg=[hp[i]-dmg[i] for i in range(n)] #lista en la que se iran guardando las criaturas con mas daño que vida creatures_hp_more_than_dmg=[] #inicializando el daño en 0 max_damage=0 #se recorre cada criatura for i in range(n): #si su vida es mayor que se daño es una criatura a la cual convendria cambiar su daño por su vida, si no se suma su daño al daño maximo if hp_less_dmg[i] > 0: creatures_hp_more_than_dmg.append(i) else: max_damage+=dmg[i] #se ordenan las criaturas cuya vida es mayor que su daño segun sea esta diferencia en orden descendente ordered_creatures_hp_more_than_dmg=sorted(creatures_hp_more_than_dmg,key= lambda i : hp_less_dmg[i],reverse=True) #se recorren estas criaturas for creature in ordered_creatures_hp_more_than_dmg: #si quedan hechizos de tipo 2 se suma la vida de la criatuara al daño maximo y se elimina uno de estos hechizos if b > 0: max_damage+=hp[creature] b-=1 #en caso de que ya no queden mas hechizos de tipo 2 se suma el daño de la criatura else: max_damage+=dmg[creature] print(max_damage) ```
0
585
A
Gennady the Dentist
PROGRAMMING
1,800
[ "brute force", "implementation" ]
null
null
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated with the value of his cofidence *p**i*. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor. While Gennady treats the teeth of the *i*-th child, the child is crying with the volume of *v**i*. At that the confidence of the first child in the line is reduced by the amount of *v**i*, the second one — by value *v**i*<=-<=1, and so on. The children in the queue after the *v**i*-th child almost do not hear the crying, so their confidence remains unchanged. If at any point in time the confidence of the *j*-th child is less than zero, he begins to cry with the volume of *d**j* and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the *j*-th one in the line is reduced by the amount of *d**j*. All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office. Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line. Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the *i*-th child.
In the first line print number *k* — the number of children whose teeth Gennady will cure. In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order.
[ "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n", "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n" ]
[ "2\n1 3 ", "4\n1 2 4 5 " ]
In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit. In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.
500
[ { "input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2", "output": "2\n1 3 " }, { "input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9", "output": "4\n1 2 4 5 " }, { "input": "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24", "output": "3\n1 2 5 " }, { "input": "10\n5 6 3\n7 4 10\n9 1 17\n2 8 23\n9 10 24\n6 8 18\n3 2 35\n7 6 6\n1 3 12\n9 9 5", "output": "6\n1 2 3 4 5 7 " }, { "input": "10\n4 9 1\n8 2 14\n7 10 20\n6 9 18\n5 3 19\n2 9 7\n6 8 30\n8 7 38\n6 5 5\n6 9 37", "output": "8\n1 2 3 4 5 7 8 10 " }, { "input": "10\n10 3 3\n8 6 17\n9 5 26\n10 7 17\n3 10 29\n3 1 27\n3 3 7\n8 10 28\n1 3 23\n3 4 6", "output": "5\n1 2 3 5 8 " }, { "input": "10\n5 6 1\n9 2 6\n4 1 5\n4 10 5\n1 8 23\n9 4 21\n3 9 6\n7 8 34\n7 4 24\n8 9 21", "output": "5\n1 2 5 6 8 " }, { "input": "4\n2 10 1\n1 2 2\n2 1 1\n5 5 1", "output": "3\n1 2 4 " }, { "input": "1\n1 1 1", "output": "1\n1 " }, { "input": "2\n5 1 1\n1 1 5", "output": "2\n1 2 " }, { "input": "2\n5 1 1\n1 1 4", "output": "1\n1 " }, { "input": "2\n5 1 1\n1 1 6", "output": "2\n1 2 " }, { "input": "3\n5 1 1\n1 1 4\n1 1 4", "output": "1\n1 " }, { "input": "3\n5 1 1\n1 1 4\n1 1 5", "output": "2\n1 3 " }, { "input": "3\n5 1 1\n1 1 5\n1 1 3", "output": "2\n1 2 " }, { "input": "3\n5 1 1\n10 1 5\n1000 1000 14", "output": "3\n1 2 3 " }, { "input": "10\n9 8 8\n2 9 33\n10 7 42\n7 2 18\n3 5 82\n9 9 25\n3 2 86\n3 5 49\n5 3 72\n4 4 71", "output": "10\n1 2 3 4 5 6 7 8 9 10 " }, { "input": "10\n9 8 8\n2 9 8\n10 7 16\n7 2 9\n3 5 23\n9 9 25\n3 2 35\n3 5 36\n5 3 40\n4 4 42", "output": "1\n1 " } ]
1,542,010,262
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
108
0
n,k=map(int,input().split()) k=10**k s=n*k while n*k>0: if n>k: n=n%k else: k=k%n D=s//n+k print(D)
Title: Gennady the Dentist Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated with the value of his cofidence *p**i*. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor. While Gennady treats the teeth of the *i*-th child, the child is crying with the volume of *v**i*. At that the confidence of the first child in the line is reduced by the amount of *v**i*, the second one — by value *v**i*<=-<=1, and so on. The children in the queue after the *v**i*-th child almost do not hear the crying, so their confidence remains unchanged. If at any point in time the confidence of the *j*-th child is less than zero, he begins to cry with the volume of *d**j* and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the *j*-th one in the line is reduced by the amount of *d**j*. All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office. Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line. Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the *i*-th child. Output Specification: In the first line print number *k* — the number of children whose teeth Gennady will cure. In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order. Demo Input: ['5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n', '5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n'] Demo Output: ['2\n1 3 ', '4\n1 2 4 5 '] Note: In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit. In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.
```python n,k=map(int,input().split()) k=10**k s=n*k while n*k>0: if n>k: n=n%k else: k=k%n D=s//n+k print(D) ```
-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,514,035,991
2,147,483,647
Python 3
OK
TESTS
81
124
5,632,000
x, y, z = 0, 0, 0 for i in range(int(input())): x1,y1,z1 = map(int, input().split()) x += x1 y += y1 z += z1 print(('NO', 'YES')[int (x == 0 and y == 0 and z == 0)])
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 x, y, z = 0, 0, 0 for i in range(int(input())): x1,y1,z1 = map(int, input().split()) x += x1 y += y1 z += z1 print(('NO', 'YES')[int (x == 0 and y == 0 and z == 0)]) ```
3.95851
990
B
Micro-World
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$. The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i &gt; a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i &gt; a_j$ and $a_i \le a_j + K$. The swallow operations go one after another. For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish. Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.
The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$. The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have.
Print the only integer — minimal possible number of bacteria can remain.
[ "7 1\n101 53 42 102 101 55 54\n", "6 5\n20 15 10 15 20 25\n", "7 1000000\n1 1 1 1 1 1 1\n" ]
[ "3\n", "1\n", "7\n" ]
The first example is clarified in the problem statement. In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$. In the third example no bacteria can swallow any other bacteria.
0
[ { "input": "7 1\n101 53 42 102 101 55 54", "output": "3" }, { "input": "6 5\n20 15 10 15 20 25", "output": "1" }, { "input": "7 1000000\n1 1 1 1 1 1 1", "output": "7" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 4\n8", "output": "1" }, { "input": "10 1\n1 2 3 5 6 8 10 11 9 4", "output": "2" }, { "input": "9 2\n1 6 1 5 5 8 6 8 7", "output": "4" }, { "input": "15 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "15" }, { "input": "2 1000000\n1 1000000", "output": "1" }, { "input": "7 2\n1 5 5 8 9 8 8", "output": "4" }, { "input": "10 1\n2 6 3 4 2 4 4 3 2 1", "output": "4" }, { "input": "4 1\n2 2 1 1", "output": "2" }, { "input": "10 1\n6 3 1 3 6 4 1 3 6 4", "output": "7" }, { "input": "2 1\n1 1", "output": "2" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "8 2\n3 13 9 8 3 13 9 14", "output": "5" }, { "input": "8 1000000\n1 1 5 1000000 1000000 2 2 2", "output": "2" }, { "input": "2 1\n999152 999153", "output": "1" } ]
1,548,687,991
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
436
14,643,200
n, k = input().split() k = int(k) l = input().split() l = list(map(int, l)) l.sort() n= int(n) if n==1: print(0) else: f=l[0] arr=[] mat=[] c=0 for i in range(len(l)): if l[i]==f: c=c+1 else: mat.append(c) arr.append(f) f=l[i] c=1 arr.append(f) mat.append(c) for i in range(1,len(arr)): if arr[i] - arr[i - 1] <= k : n=n-mat[i-1] print(n)
Title: Micro-World Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$. The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i &gt; a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i &gt; a_j$ and $a_i \le a_j + K$. The swallow operations go one after another. For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish. Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope. Input Specification: The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$. The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. Output Specification: Print the only integer — minimal possible number of bacteria can remain. Demo Input: ['7 1\n101 53 42 102 101 55 54\n', '6 5\n20 15 10 15 20 25\n', '7 1000000\n1 1 1 1 1 1 1\n'] Demo Output: ['3\n', '1\n', '7\n'] Note: The first example is clarified in the problem statement. In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$. In the third example no bacteria can swallow any other bacteria.
```python n, k = input().split() k = int(k) l = input().split() l = list(map(int, l)) l.sort() n= int(n) if n==1: print(0) else: f=l[0] arr=[] mat=[] c=0 for i in range(len(l)): if l[i]==f: c=c+1 else: mat.append(c) arr.append(f) f=l[i] c=1 arr.append(f) mat.append(c) for i in range(1,len(arr)): if arr[i] - arr[i - 1] <= k : n=n-mat[i-1] print(n) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd", "output": "n20n\nj27b\nk15d" }, { "input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt", "output": "t41t" }, { "input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings", "output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings" }, { "input": "1\na", "output": "a" }, { "input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz", "output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz" }, { "input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "output": "a98j" }, { "input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco", "output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco" }, { "input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt", "output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t" }, { "input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr", "output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr" } ]
1,689,946,326
2,147,483,647
Python 3
OK
TESTS
20
46
0
n=int(input()) words=[] for i in range(n): word = input() if len(word)<=10: words.append(word) else: words.append(word[0]+str(len(word[1:-1]))+word[-1]) for word in words: print(word)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. Output Specification: Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. Demo Input: ['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n'] Demo Output: ['word\nl10n\ni18n\np43s\n'] Note: none
```python n=int(input()) words=[] for i in range(n): word = input() if len(word)<=10: words.append(word) else: words.append(word[0]+str(len(word[1:-1]))+word[-1]) for word in words: print(word) ```
3.977
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,674,538,348
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n=int(input()) for i in range(n): m=0 c=0 x,y=map(int,input().split()) if x>y: m=m+1 elif y>x: c=c+1 if m==c: print("Friendship is magic!^^") elif m>c: print("Mishka") else: print("Chris")
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()) for i in range(n): m=0 c=0 x,y=map(int,input().split()) if x>y: m=m+1 elif y>x: c=c+1 if m==c: print("Friendship is magic!^^") elif m>c: print("Mishka") else: print("Chris") ```
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,642,580,277
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
n=input() l=0 u=0 n1="" for i in range(len(n)): if(n[i] >= 'A' and n[i] <= 'Z'): u+=1 elif(n[i] >= 'a' and n[i] <= 'z'): l+=1 if u==l: print(n1 = n1 + chr((ord(n[i]) - 32))) elif u>l: ptint(n1 = n1 + chr((ord(n[i]) + 32))) else: print( n1 = n1 + n[i])
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 n=input() l=0 u=0 n1="" for i in range(len(n)): if(n[i] >= 'A' and n[i] <= 'Z'): u+=1 elif(n[i] >= 'a' and n[i] <= 'z'): l+=1 if u==l: print(n1 = n1 + chr((ord(n[i]) - 32))) elif u>l: ptint(n1 = n1 + chr((ord(n[i]) + 32))) else: print( n1 = n1 + n[i]) ```
-1
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "0\n0\n3\n3\n3\n0\n3" }, { "input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969", "output": "1\n1\n0\n1\n1\n1\n0\n1\n1" }, { "input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341", "output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12" }, { "input": "4\n698 193 1584 76192\n4\n553640\n310518\n274280\n429192", "output": "4\n4\n4\n4" }, { "input": "1\n1\n1\n1000000000", "output": "1" }, { "input": "1\n1\n1\n100005", "output": "1" }, { "input": "3\n1 2 3\n1\n100005", "output": "3" }, { "input": "2\n1 2\n3\n100004\n100005\n100006", "output": "2\n2\n2" }, { "input": "3\n1 1 1\n1\n1", "output": "3" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "3\n1 2 3\n1\n100000", "output": "3" }, { "input": "5\n1 1 1 1 10\n2\n1\n10", "output": "4\n5" }, { "input": "5\n3 10 8 6 11\n1\n10000000", "output": "5" } ]
1,693,670,403
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
1,638,400
import sys scan = sys.stdin n = int(scan.readline()) x = list(map(int, scan.readline().split())) q = int(scan.readline()) m = [] for i in range(q): mi = int(scan.readline()) m.append(mi) x.append(mi) x.sort() x.reverse() mcopy = m.copy() mcopy.sort() for i in m: print(n + q - x.index(i) - mcopy.index(i) - 1)
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day. Output Specification: Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. Demo Input: ['5\n3 10 8 6 11\n4\n1\n10\n3\n11\n'] Demo Output: ['0\n4\n1\n5\n'] Note: On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
```python import sys scan = sys.stdin n = int(scan.readline()) x = list(map(int, scan.readline().split())) q = int(scan.readline()) m = [] for i in range(q): mi = int(scan.readline()) m.append(mi) x.append(mi) x.sort() x.reverse() mcopy = m.copy() mcopy.sort() for i in m: print(n + q - x.index(i) - mcopy.index(i) - 1) ```
0
559
B
Equivalent Strings
PROGRAMMING
1,700
[ "divide and conquer", "hashing", "sortings", "strings" ]
null
null
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1 As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent. Gerald has already completed this home task. Now it's your turn!
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
[ "aaba\nabaa\n", "aabb\nabab\n" ]
[ "YES\n", "NO\n" ]
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".
1,000
[ { "input": "aaba\nabaa", "output": "YES" }, { "input": "aabb\nabab", "output": "NO" }, { "input": "a\na", "output": "YES" }, { "input": "a\nb", "output": "NO" }, { "input": "ab\nab", "output": "YES" }, { "input": "ab\nba", "output": "YES" }, { "input": "ab\nbb", "output": "NO" }, { "input": "zzaa\naazz", "output": "YES" }, { "input": "azza\nzaaz", "output": "YES" }, { "input": "abc\nabc", "output": "YES" }, { "input": "abc\nacb", "output": "NO" }, { "input": "azzz\nzzaz", "output": "YES" }, { "input": "abcd\ndcab", "output": "YES" }, { "input": "abcd\ncdab", "output": "YES" }, { "input": "abcd\ndcba", "output": "YES" }, { "input": "abcd\nacbd", "output": "NO" }, { "input": "oloaxgddgujq\noloaxgujqddg", "output": "YES" }, { "input": "uwzwdxfmosmqatyv\ndxfmzwwusomqvyta", "output": "YES" }, { "input": "hagnzomowtledfdotnll\nledfdotnllomowthagnz", "output": "YES" }, { "input": "snyaydaeobufdg\nsnyaydaeobufdg", "output": "YES" }, { "input": "baaaaa\nabaaaa", "output": "NO" }, { "input": "hhiisug\nmzdjwju", "output": "NO" }, { "input": "bbbabbabaaab\naaaabbabbbbb", "output": "NO" }, { "input": "bbaaab\naababb", "output": "NO" }, { "input": "aabbaaaa\naaaaabab", "output": "NO" }, { "input": "aab\naba", "output": "NO" }, { "input": "abcddd\nbacddd", "output": "NO" }, { "input": "qgiufelsfhanx\naaaaaaaaaaaaa", "output": "NO" }, { "input": "aabaababaaba\naababaaababa", "output": "NO" }, { "input": "nocdqzdriyyil\naaaaaaaaaaaaa", "output": "NO" }, { "input": "zdmctxl\nkojqhgw", "output": "NO" }, { "input": "yhwepqwyhwepqwyhwepqweahnqtueahnqtueahnqtuyhwepqwyhwepqwyhwepqwyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtueahnqtueahnqtueahnqtueahnqtu\neahnqtueahnqtueahnqtuyhwepqweahnqtuyhwepqwyhwepqweahnqtuyhwepqweahnqtuyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtuyhwepqwyhwepqwyhwepqw", "output": "NO" }, { "input": "abc\nbac", "output": "NO" }, { "input": "ottceez\npcstdvz", "output": "NO" } ]
1,623,778,912
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
s1 = input() s2 = input() a1,a2 = [s1[:len(s1)//2],s1[len(s1)//2:]] b1,b2 = [s2[:len(s1)//2],s2[len(s1)//2:]] if a1 == b1 or a2 == b2 or a1 == b2 or a2 == b1: print("YES") else: print("NO")
Title: Equivalent Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1 As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent. Gerald has already completed this home task. Now it's your turn! Input Specification: The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. Output Specification: Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. Demo Input: ['aaba\nabaa\n', 'aabb\nabab\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".
```python s1 = input() s2 = input() a1,a2 = [s1[:len(s1)//2],s1[len(s1)//2:]] b1,b2 = [s2[:len(s1)//2],s2[len(s1)//2:]] if a1 == b1 or a2 == b2 or a1 == b2 or a2 == b1: print("YES") else: print("NO") ```
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,693,403,317
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
n = int(input()) m = int(input()) a = int(input()) length = 0 width = 0 count = 0 while length < n: length += a count += 1 while width < n: width += a count += 1 print(count)
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 n = int(input()) m = int(input()) a = int(input()) length = 0 width = 0 count = 0 while length < n: length += a count += 1 while width < n: width += a count += 1 print(count) ```
-1
166
E
Tetrahedron
PROGRAMMING
1,500
[ "dp", "math", "matrices" ]
null
null
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place. You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
[ "2\n", "4\n" ]
[ "3\n", "21\n" ]
The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
1,000
[ { "input": "2", "output": "3" }, { "input": "4", "output": "21" }, { "input": "1", "output": "0" }, { "input": "3", "output": "6" }, { "input": "5", "output": "60" }, { "input": "6", "output": "183" }, { "input": "7", "output": "546" }, { "input": "8", "output": "1641" }, { "input": "9", "output": "4920" }, { "input": "10", "output": "14763" }, { "input": "15", "output": "3587226" }, { "input": "30", "output": "782663359" }, { "input": "10000000", "output": "192336614" }, { "input": "100", "output": "721510432" }, { "input": "300", "output": "327873818" }, { "input": "900", "output": "295068084" }, { "input": "1500", "output": "451187545" }, { "input": "3000", "output": "645417275" }, { "input": "5000", "output": "755610910" }, { "input": "10000", "output": "723907367" }, { "input": "50000", "output": "969527595" }, { "input": "90000", "output": "548978368" }, { "input": "99999", "output": "909741855" }, { "input": "100000", "output": "729225554" }, { "input": "300000", "output": "93822635" }, { "input": "800000", "output": "178940616" }, { "input": "1000000", "output": "266233856" }, { "input": "4000000", "output": "882155933" }, { "input": "9000000", "output": "295060537" }, { "input": "9999999", "output": "730778875" }, { "input": "1000000", "output": "266233856" }, { "input": "9999999", "output": "730778875" }, { "input": "10000000", "output": "192336614" }, { "input": "9999998", "output": "576926295" }, { "input": "30", "output": "782663359" }, { "input": "31", "output": "347990060" } ]
1,681,542,136
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
2,000
118,681,600
m=1000000007 n=int(input()) dp=[[None for j in range(n+1)] for i in range(2)] dp[0][0]=1 dp[1][0]=0 for i in range(1,n+1): dp[0][i]=(3*dp[1][i-1])%m dp[1][i]=(2*dp[1][i-1]+dp[0][i-1])%m print(dp[0][n])
Title: Tetrahedron Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place. You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). Input Specification: The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. Output Specification: Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). Demo Input: ['2\n', '4\n'] Demo Output: ['3\n', '21\n'] Note: The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
```python m=1000000007 n=int(input()) dp=[[None for j in range(n+1)] for i in range(2)] dp[0][0]=1 dp[1][0]=0 for i in range(1,n+1): dp[0][i]=(3*dp[1][i-1])%m dp[1][i]=(2*dp[1][i-1]+dp[0][i-1])%m print(dp[0][n]) ```
0
8
B
Obsession with Robots
PROGRAMMING
1,400
[ "constructive algorithms", "graphs", "implementation" ]
B. Obsession with Robots
2
64
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
[ "LLUUUR\n", "RRUULLDD\n" ]
[ "OK\n", "BUG\n" ]
none
0
[ { "input": "LLUUUR", "output": "OK" }, { "input": "RRUULLDD", "output": "BUG" }, { "input": "L", "output": "OK" }, { "input": "R", "output": "OK" }, { "input": "R", "output": "OK" }, { "input": "RR", "output": "OK" }, { "input": "DL", "output": "OK" }, { "input": "LD", "output": "OK" }, { "input": "RUL", "output": "BUG" }, { "input": "ULD", "output": "BUG" }, { "input": "DDR", "output": "OK" }, { "input": "RRDD", "output": "OK" }, { "input": "RRLR", "output": "BUG" }, { "input": "RRDL", "output": "BUG" }, { "input": "LRUD", "output": "BUG" }, { "input": "RDRLL", "output": "BUG" }, { "input": "DRDRD", "output": "OK" }, { "input": "ULURL", "output": "BUG" }, { "input": "LUUDU", "output": "BUG" }, { "input": "RDLUR", "output": "BUG" }, { "input": "DLDLDDRR", "output": "OK" }, { "input": "RDRDDD", "output": "OK" }, { "input": "UULLDLUR", "output": "BUG" }, { "input": "LULU", "output": "OK" }, { "input": "LLDDLDLLDDDLLLDLLLLLUU", "output": "OK" }, { "input": "LLDDLDLLDDDLLLDLLLLLUU", "output": "OK" }, { "input": "LLDDLDLLDDDLLLDLLLLLUU", "output": "OK" }, { "input": "URRRRRURRURUURRRRRDDDDLDDDRDDDDLLDLL", "output": "OK" }, { "input": "R", "output": "OK" }, { "input": "UL", "output": "OK" }, { "input": "UDR", "output": "BUG" }, { "input": "DDDR", "output": "OK" }, { "input": "UUUDU", "output": "BUG" }, { "input": "LULULL", "output": "OK" }, { "input": "DLURUUU", "output": "BUG" }, { "input": "UURUURRUUU", "output": "OK" }, { "input": "DDDDRDDLDDDDDDDRDDLD", "output": "OK" }, { "input": "URRRLULUURURLRLLLLULLRLRURLULRLULLULRRUU", "output": "BUG" }, { "input": "RURRRRLURRRURRUURRRRRRRRDDULULRRURRRDRRRRRRRRRRLDR", "output": "BUG" }, { "input": "RLRRRRRDRRDRRRRDLRRRRRRRDLRLDDLRRRRLDLDRDRRRRDRDRDRDLRRURRLRRRRDRRRRRRRRLDDRLRRDRRRRRRRDRDRLDRDDDRDR", "output": "BUG" }, { "input": "DDUL", "output": "BUG" }, { "input": "UUULLLLRDD", "output": "BUG" }, { "input": "LLLLLLLLRRRRDDDDDDDUUUUUU", "output": "BUG" }, { "input": "DDDDDDDDDDDDUUUUUUUUUUUURRRRRRRRRRRRRLLLLLLLLLLLLLLL", "output": "BUG" }, { "input": "DDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUUUUUUU", "output": "BUG" }, { "input": "DLUR", "output": "BUG" }, { "input": "UUUURDLLLL", "output": "BUG" }, { "input": "RRRRRRRRRRRURLLLLLLLLLLLL", "output": "BUG" }, { "input": "LLLLLLLLLLLLLLLLLLLLLLLLLLRUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "BUG" }, { "input": "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "BUG" }, { "input": "DDLDRRR", "output": "BUG" }, { "input": "RRUULLD", "output": "BUG" }, { "input": "LUUUULLLLDDDDRRRD", "output": "BUG" }, { "input": "DDDDLLLDDDRRRUURRRR", "output": "BUG" }, { "input": "DDDDDDDLLDDRRURRRRRRR", "output": "BUG" }, { "input": "DDDDDDDDDDLLLLLLLLLLLDDDDDDDDDDDRRRRRRRRRRRUUUUUUUUUURRRRRRRRRR", "output": "BUG" }, { "input": "DDDLLLLLLLDDDDDDDRRRRRRRUUUUUURRR", "output": "BUG" }, { "input": "RRRUUULLLDD", "output": "BUG" }, { "input": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLLLLDDDDRRRRUUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "BUG" }, { "input": "RRRRRRRRRRRDDDDDDDDDDDDDDDDDDDRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLUUUUUUUUUUU", "output": "BUG" } ]
1,663,948,704
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
30
154
0
S = input() seen = set() seen.add((0,0)) y,x=0,0 for c in S: py,px=y,x if c=='U': y+=1 elif c=='D': y-=1 elif c=='L': x-=1 else: x+=1 for y1,x1 in ((1,0),(-1,0),(0,1),(0,-1)): y2,x2=y+y1,x+x1 if y2==py and x2==px:continue if (y2,x2) in seen: exit(print('BUG')) seen.add((y,x)) print('OK')
Title: Obsession with Robots Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input Specification: The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output Specification: In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Demo Input: ['LLUUUR\n', 'RRUULLDD\n'] Demo Output: ['OK\n', 'BUG\n'] Note: none
```python S = input() seen = set() seen.add((0,0)) y,x=0,0 for c in S: py,px=y,x if c=='U': y+=1 elif c=='D': y-=1 elif c=='L': x-=1 else: x+=1 for y1,x1 in ((1,0),(-1,0),(0,1),(0,-1)): y2,x2=y+y1,x+x1 if y2==py and x2==px:continue if (y2,x2) in seen: exit(print('BUG')) seen.add((y,x)) print('OK') ```
0
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,696,364,728
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
word = input() word.lower() print(word.capitalize())
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 word = input() word.lower() print(word.capitalize()) ```
0
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,584,861,943
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
108
0
n=int(input()) s=input() res='' if n%2!=0: for i in range(n): if i%2==0: res=res+s[i] else: res=s[i]+res else: for i in range(n): if i%2==0: res=s[i]+res else: res=res+s[i] print(res)
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()) s=input() res='' if n%2!=0: for i in range(n): if i%2==0: res=res+s[i] else: res=s[i]+res else: for i in range(n): if i%2==0: res=s[i]+res else: res=res+s[i] print(res) ```
0
109
B
Lucky Probability
PROGRAMMING
1,900
[ "brute force", "probabilities" ]
B. Lucky Probability
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer *p* from the interval [*p**l*,<=*p**r*] and Vasya chooses an integer *v* from the interval [*v**l*,<=*v**r*] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [*min*(*v*,<=*p*),<=*max*(*v*,<=*p*)] contains exactly *k* lucky numbers.
The single line contains five integers *p**l*, *p**r*, *v**l*, *v**r* and *k* (1<=≤<=*p**l*<=≤<=*p**r*<=≤<=109,<=1<=≤<=*v**l*<=≤<=*v**r*<=≤<=109,<=1<=≤<=*k*<=≤<=1000).
On the single line print the result with an absolute error of no more than 10<=-<=9.
[ "1 10 1 10 2\n", "5 6 8 10 1\n" ]
[ "0.320000000000\n", "1.000000000000\n" ]
Consider that [*a*, *b*] denotes an interval of integers; this interval includes the boundaries. That is, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18b4a6012d95ad18891561410f0314497a578d63.png" style="max-width: 100.0%;max-height: 100.0%;"/> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.
1,000
[ { "input": "1 10 1 10 2", "output": "0.320000000000" }, { "input": "5 6 8 10 1", "output": "1.000000000000" }, { "input": "1 20 100 120 5", "output": "0.150000000000" }, { "input": "1 10 1 10 3", "output": "0.000000000000" }, { "input": "1 100 1 100 2", "output": "0.362600000000" }, { "input": "47 95 18 147 4", "output": "0.080533751962" }, { "input": "1 1000000000 1 1000000000 47", "output": "0.000000010664" }, { "input": "1 2 3 4 12", "output": "0.000000000000" }, { "input": "1 50 64 80 4", "output": "0.231764705882" }, { "input": "1 128 45 99 2", "output": "0.432954545455" }, { "input": "45 855 69 854 7", "output": "0.005859319848" }, { "input": "1 1000 1 1000 2", "output": "0.082970000000" }, { "input": "999 999 1000 1000 1", "output": "0.000000000000" }, { "input": "789 5888 1 10 7", "output": "0.000000000000" }, { "input": "1 1000 1 1000 14", "output": "0.001792000000" }, { "input": "4 4 7 7 2", "output": "1.000000000000" }, { "input": "7 7 4 4 2", "output": "1.000000000000" }, { "input": "2588 3000 954 8555 4", "output": "0.035122336227" }, { "input": "1 10000 1 10000 2", "output": "0.009328580000" }, { "input": "1 10000 1 10000 6", "output": "0.009012260000" }, { "input": "69 98200 9999 88888 7", "output": "0.000104470975" }, { "input": "1 1000000000 1 1000000000 1000", "output": "0.000001185373" }, { "input": "1 1000000 1 1000000 19", "output": "0.000010456080" }, { "input": "4855 95555 485 95554750 7", "output": "0.000000239243" }, { "input": "2 999999999 3 999999998 999", "output": "0.000000001334" }, { "input": "45 8555 969 4000 3", "output": "0.000704970039" }, { "input": "369 852 741 963 2", "output": "0.134584738539" }, { "input": "8548 8554575 895 9954448 47", "output": "0.000001161081" }, { "input": "488 985544 8500 74844999 105", "output": "0.000000323831" }, { "input": "458995 855555 999999 84444444 245", "output": "0.000000065857" }, { "input": "8544 8855550 9874 8800000 360", "output": "0.000000000000" }, { "input": "1 1000000000 1 1000000000 584", "output": "0.000003345099" }, { "input": "1 1000000000 1 1000000000 48", "output": "0.000094672776" }, { "input": "1 1000000000 1 1000000000 470", "output": "0.000000073832" }, { "input": "1 1000000000 1 1000000000 49", "output": "0.000000010664" }, { "input": "1 1000000000 1 1000000000 998", "output": "0.000000012002" }, { "input": "4555 99878870 950000 400000000 458", "output": "0.000000218543" }, { "input": "99999999 989999999 1 1000000000 21", "output": "0.000000009517" }, { "input": "9887400 488085444 599 600000000 374", "output": "0.000000066330" }, { "input": "4 47777777 444444444 777777777 320", "output": "0.010618322184" }, { "input": "4 7 1 1000000000 395", "output": "0.000000021000" }, { "input": "123456789 987654321 4588 95470 512", "output": "0.000734548731" }, { "input": "1 1000000000 488 744444444 748", "output": "0.000000298888" }, { "input": "69 74444 47 744444 100", "output": "0.000000000000" }, { "input": "1 1000000000 100000000 1000000000 300", "output": "0.000000594125" }, { "input": "987654215 1000000000 9854874 854888120 270", "output": "0.000000031951" }, { "input": "85478 999999999 1 1000000000 1000", "output": "0.000000592737" }, { "input": "47 555555555 8596 584987999 894", "output": "0.000000000000" }, { "input": "74 182015585 98247 975000999 678", "output": "0.000000083341" }, { "input": "1 1000000000 7 1000000000 987", "output": "0.000000001335" }, { "input": "47 47 47 47 1", "output": "1.000000000000" }, { "input": "6 8 6 8 1", "output": "0.777777777778" }, { "input": "5 30 6 43 1", "output": "0.159919028340" }, { "input": "777777776 778777777 777777775 1000000000 1", "output": "0.000002013496" }, { "input": "28 46 8 45 1", "output": "0.199445983380" }, { "input": "444444 444445 444440 444446 1", "output": "0.857142857143" }, { "input": "1 6 2 4 1", "output": "0.666666666667" }, { "input": "1 10 1 10 1", "output": "0.460000000000" }, { "input": "4 4 4 4 1", "output": "1.000000000000" }, { "input": "4 7 4 7 2", "output": "0.125000000000" } ]
1,600,419,875
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
50
218
307,200
def gen_len(l): gen = [] for i in range(2 ** l): k = int(bin(i)[2:].rjust(l, '0').replace('0', '4').replace('1', '7')) if k <= 10 ** 9: gen.append(k) return gen def pairs_with_k_len(a, k): l = 0 r = k - 1 while r < len(a): yield l, r l += 1 r += 1 def get_intersection_length(l1, r1, l2, r2): return max(min(r1, r2) - max(l1, l2) + 1, 0) def main(): gen = set() for i in range(1, 10): for e in gen_len(i): gen.add(e) gen = list(sorted(gen)) pl, pr, vl, vr, k = map(int, input().split()) denominator = (pr - pl + 1) * (vr - vl + 1) p = (pl, pr) v = (vl, vr) count = 0 for l, r in pairs_with_k_len(gen, k): if gen[l] >= min(pl, vl) and gen[r] <= max(pr, vr): l1 = gen[l - 1] if l != 0 else 0 r1 = gen[l] l2 = gen[r] r2 = gen[r + 1] if r != len(gen) - 1 else 10**9 count += (get_intersection_length(l1 + 1, r1, pl, pr) * get_intersection_length(l2, r2 - 1, vl, vr)) count += (get_intersection_length(l1 + 1, r1, vl, vr) * get_intersection_length(l2, r2 - 1, pl, pr)) print(count / denominator) if __name__ == '__main__': main()
Title: Lucky Probability Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer *p* from the interval [*p**l*,<=*p**r*] and Vasya chooses an integer *v* from the interval [*v**l*,<=*v**r*] (also randomly). Both players choose their integers equiprobably. Find the probability that the interval [*min*(*v*,<=*p*),<=*max*(*v*,<=*p*)] contains exactly *k* lucky numbers. Input Specification: The single line contains five integers *p**l*, *p**r*, *v**l*, *v**r* and *k* (1<=≤<=*p**l*<=≤<=*p**r*<=≤<=109,<=1<=≤<=*v**l*<=≤<=*v**r*<=≤<=109,<=1<=≤<=*k*<=≤<=1000). Output Specification: On the single line print the result with an absolute error of no more than 10<=-<=9. Demo Input: ['1 10 1 10 2\n', '5 6 8 10 1\n'] Demo Output: ['0.320000000000\n', '1.000000000000\n'] Note: Consider that [*a*, *b*] denotes an interval of integers; this interval includes the boundaries. That is, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18b4a6012d95ad18891561410f0314497a578d63.png" style="max-width: 100.0%;max-height: 100.0%;"/> In first case there are 32 suitable pairs: (1, 7), (1, 8), (1, 9), (1, 10), (2, 7), (2, 8), (2, 9), (2, 10), (3, 7), (3, 8), (3, 9), (3, 10), (4, 7), (4, 8), (4, 9), (4, 10), (7, 1), (7, 2), (7, 3), (7, 4), (8, 1), (8, 2), (8, 3), (8, 4), (9, 1), (9, 2), (9, 3), (9, 4), (10, 1), (10, 2), (10, 3), (10, 4). Total number of possible pairs is 10·10 = 100, so answer is 32 / 100. In second case Petya always get number less than Vasya and the only lucky 7 is between this numbers, so there will be always 1 lucky number.
```python def gen_len(l): gen = [] for i in range(2 ** l): k = int(bin(i)[2:].rjust(l, '0').replace('0', '4').replace('1', '7')) if k <= 10 ** 9: gen.append(k) return gen def pairs_with_k_len(a, k): l = 0 r = k - 1 while r < len(a): yield l, r l += 1 r += 1 def get_intersection_length(l1, r1, l2, r2): return max(min(r1, r2) - max(l1, l2) + 1, 0) def main(): gen = set() for i in range(1, 10): for e in gen_len(i): gen.add(e) gen = list(sorted(gen)) pl, pr, vl, vr, k = map(int, input().split()) denominator = (pr - pl + 1) * (vr - vl + 1) p = (pl, pr) v = (vl, vr) count = 0 for l, r in pairs_with_k_len(gen, k): if gen[l] >= min(pl, vl) and gen[r] <= max(pr, vr): l1 = gen[l - 1] if l != 0 else 0 r1 = gen[l] l2 = gen[r] r2 = gen[r + 1] if r != len(gen) - 1 else 10**9 count += (get_intersection_length(l1 + 1, r1, pl, pr) * get_intersection_length(l2, r2 - 1, vl, vr)) count += (get_intersection_length(l1 + 1, r1, vl, vr) * get_intersection_length(l2, r2 - 1, pl, pr)) print(count / denominator) if __name__ == '__main__': main() ```
0
902
A
Visiting a Friend
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit. It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*).
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "3 5\n0 2\n2 4\n3 5\n", "3 7\n0 4\n2 5\n6 7\n" ]
[ "YES\n", "NO\n" ]
The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You can see that there is no path from Pig's house to his friend's house that uses only teleports.
500
[ { "input": "3 5\n0 2\n2 4\n3 5", "output": "YES" }, { "input": "3 7\n0 4\n2 5\n6 7", "output": "NO" }, { "input": "1 1\n0 0", "output": "NO" }, { "input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10", "output": "NO" }, { "input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 100\n71 73\n80 94\n81 92\n84 85\n85 100\n88 91\n91 95\n92 98\n92 98\n99 100\n100 100", "output": "YES" }, { "input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 6\n1 6\n1 2\n1 3\n1 2\n1 3\n2 5\n2 4\n2 3\n2 4\n2 6\n2 2\n2 5\n2 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 9\n3 3\n3 7\n3 9\n3 3\n3 9\n4 6\n4 7\n4 5\n4 7\n5 8\n5 5\n5 9\n5 7\n5 5\n6 6\n6 9\n6 7\n6 8\n6 9\n6 8\n7 7\n7 8\n7 7\n7 8\n8 9\n8 8\n8 9\n8 8\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "NO" }, { "input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 10\n8 10\n9 9\n9 9\n10 10\n10 10", "output": "YES" }, { "input": "50 100\n0 95\n1 100\n1 38\n2 82\n5 35\n7 71\n8 53\n11 49\n15 27\n17 84\n17 75\n18 99\n18 43\n18 69\n21 89\n27 60\n27 29\n38 62\n38 77\n39 83\n40 66\n48 80\n48 100\n50 51\n50 61\n53 77\n53 63\n55 58\n56 68\n60 82\n62 95\n66 74\n67 83\n69 88\n69 81\n69 88\n69 98\n70 91\n70 76\n71 90\n72 99\n81 99\n85 87\n88 97\n88 93\n90 97\n90 97\n92 98\n98 99\n100 100", "output": "YES" }, { "input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 10\n1 9\n1 6\n1 2\n1 3\n1 2\n2 6\n2 5\n2 4\n2 3\n2 10\n2 2\n2 6\n2 2\n3 10\n3 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 10\n3 5\n3 3\n3 7\n4 8\n4 8\n4 9\n4 6\n5 7\n5 10\n5 7\n5 8\n5 5\n6 8\n6 9\n6 10\n6 6\n6 9\n6 7\n7 8\n7 9\n7 10\n7 10\n8 8\n8 8\n8 9\n8 10\n9 10\n9 9\n9 10\n9 10\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "YES" }, { "input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 4\n1 5\n1 9\n1 1\n1 6\n1 6\n2 5\n2 7\n2 7\n2 7\n2 7\n3 4\n3 7\n3 9\n3 5\n3 3\n4 4\n4 6\n4 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n5 8\n5 9\n5 8\n6 8\n6 7\n6 8\n6 9\n6 9\n6 6\n6 9\n6 7\n7 7\n7 7\n7 7\n7 8\n7 7\n7 8\n7 8\n7 9\n8 8\n8 8\n8 8\n8 8\n8 8\n8 9\n8 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "NO" }, { "input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 40\n38 38\n40 40", "output": "NO" }, { "input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 92\n92 97\n96 99\n97 98\n97 99\n99 99\n100 100\n100 100\n100 100", "output": "NO" }, { "input": "1 10\n0 10", "output": "YES" }, { "input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 40\n23 23\n23 28\n24 29\n25 38\n26 35\n27 37\n28 39\n28 33\n28 40\n28 33\n29 31\n29 33\n30 38\n30 36\n30 30\n30 38\n31 37\n31 35\n31 32\n31 36\n33 39\n33 40\n35 38\n36 38\n37 38\n37 40\n38 39\n38 40\n38 39\n39 39\n39 40\n40 40\n40 40\n40 40\n40 40", "output": "YES" }, { "input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 40\n11 31\n12 26\n13 25\n14 32\n17 19\n21 29\n22 36\n24 27\n25 39\n25 27\n27 32\n27 29\n27 39\n27 29\n28 38\n30 38\n32 40\n32 38\n33 33\n33 40\n34 35\n34 34\n34 38\n34 38\n35 37\n36 39\n36 39\n37 37\n38 40\n39 39\n40 40", "output": "YES" }, { "input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 22\n23 28\n23 39\n24 24\n25 27\n26 38\n27 39\n28 33\n28 39\n28 34\n28 33\n29 30\n29 35\n30 30\n30 38\n30 34\n30 31\n31 36\n31 31\n31 32\n31 38\n33 34\n33 34\n35 36\n36 38\n37 38\n37 39\n38 38\n38 38\n38 38\n39 39\n39 39\n40 40\n40 40\n40 40\n40 40", "output": "NO" }, { "input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n88 99", "output": "NO" }, { "input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 10\n7 10\n9 10", "output": "NO" }, { "input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 5\n4 8\n5 5\n5 7\n6 7\n6 6\n7 7\n7 7\n7 7\n7 8\n7 8\n8 8\n8 8\n8 9\n8 8\n8 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "NO" }, { "input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n32 37", "output": "NO" }, { "input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 10\n4 6\n5 9\n5 5\n6 7\n6 10\n7 8\n7 7\n7 7\n7 7\n7 10\n8 8\n8 8\n8 10\n8 8\n8 8\n9 10\n9 10\n9 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "YES" }, { "input": "1 1\n0 1", "output": "YES" }, { "input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 36\n38 38\n40 40", "output": "NO" }, { "input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 82\n71 94\n80 90\n81 88\n84 93\n85 89\n88 92\n91 97\n92 99\n92 97\n99 99\n100 100", "output": "NO" }, { "input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n79 100", "output": "YES" }, { "input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n37 40", "output": "YES" }, { "input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 10\n1 2\n1 5\n1 10\n1 8\n1 1\n2 8\n2 7\n2 5\n2 5\n2 7\n3 5\n3 7\n3 5\n3 4\n3 7\n4 7\n4 8\n4 6\n5 7\n5 10\n5 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n6 10\n6 9\n6 7\n6 10\n6 8\n6 7\n6 10\n6 10\n7 8\n7 9\n7 8\n7 8\n7 8\n7 8\n7 7\n7 7\n8 8\n8 8\n8 10\n8 9\n8 9\n8 9\n8 9\n9 9\n9 10\n9 9\n9 9\n9 9\n9 9\n9 10\n9 10\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10", "output": "YES" }, { "input": "50 100\n0 95\n1 7\n1 69\n2 83\n5 67\n7 82\n8 31\n11 25\n15 44\n17 75\n17 27\n18 43\n18 69\n18 40\n21 66\n27 29\n27 64\n38 77\n38 90\n39 52\n40 60\n48 91\n48 98\n50 89\n50 63\n53 54\n53 95\n55 76\n56 59\n60 96\n62 86\n66 70\n67 77\n69 88\n69 98\n69 80\n69 95\n70 74\n70 77\n71 99\n72 73\n81 87\n85 99\n88 96\n88 91\n90 97\n90 99\n92 92\n98 99\n100 100", "output": "NO" }, { "input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 35\n11 23\n12 36\n13 31\n14 31\n17 17\n21 25\n22 33\n24 26\n25 32\n25 25\n27 39\n27 29\n27 34\n27 32\n28 34\n30 36\n32 37\n32 33\n33 35\n33 33\n34 38\n34 38\n34 36\n34 36\n35 36\n36 36\n36 39\n37 37\n38 39\n39 39\n40 40", "output": "NO" }, { "input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 9\n7 7\n9 9", "output": "NO" }, { "input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 100\n92 97\n96 96\n97 98\n97 100\n99 100\n100 100\n100 100\n100 100", "output": "YES" }, { "input": "2 2\n0 2\n0 1", "output": "YES" }, { "input": "2 100\n0 49\n50 100", "output": "NO" }, { "input": "2 100\n0 50\n50 100", "output": "YES" }, { "input": "10 100\n0 10\n10 20\n20 30\n30 40\n40 50\n50 60\n60 70\n70 80\n80 90\n90 100", "output": "YES" }, { "input": "100 10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 10", "output": "YES" }, { "input": "1 4\n1 4", "output": "NO" }, { "input": "3 5\n0 2\n2 5\n3 4", "output": "YES" }, { "input": "2 5\n0 5\n1 2", "output": "YES" }, { "input": "5 5\n0 2\n0 2\n3 5\n3 5\n3 5", "output": "NO" }, { "input": "4 10\n0 3\n2 10\n4 10\n5 7", "output": "YES" }, { "input": "3 8\n0 0\n1 8\n2 8", "output": "NO" }, { "input": "6 8\n0 3\n1 5\n2 3\n5 6\n6 7\n7 8", "output": "YES" } ]
1,513,698,190
490
Python 3
WRONG_ANSWER
TESTS
14
62
5,529,600
n, m = list(map(int, input().split())) al = [None] * m for i in range(n): a, b = list(map(int, input().split())) for j in range(a, b): al[j] = 1 g = True for i in range(m): if al[i] is None: print('NO') g = False if g: print('YES')
Title: Visiting a Friend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit. It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*). Output Specification: Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n'] Demo Output: ['YES\n', 'NO\n'] Note: The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You can see that there is no path from Pig's house to his friend's house that uses only teleports.
```python n, m = list(map(int, input().split())) al = [None] * m for i in range(n): a, b = list(map(int, input().split())) for j in range(a, b): al[j] = 1 g = True for i in range(m): if al[i] is None: print('NO') g = False if g: print('YES') ```
0
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer.
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "input": "71 85 88", "output": "17" }, { "input": "30 38 99", "output": "69" }, { "input": "23 82 95", "output": "72" }, { "input": "22 41 47", "output": "25" }, { "input": "9 94 77", "output": "85" }, { "input": "1 53 51", "output": "52" }, { "input": "25 97 93", "output": "72" }, { "input": "42 53 51", "output": "11" }, { "input": "81 96 94", "output": "15" }, { "input": "21 5 93", "output": "88" }, { "input": "50 13 75", "output": "62" }, { "input": "41 28 98", "output": "70" }, { "input": "69 46 82", "output": "36" }, { "input": "87 28 89", "output": "61" }, { "input": "44 45 40", "output": "5" }, { "input": "86 97 68", "output": "29" }, { "input": "43 92 30", "output": "62" }, { "input": "16 70 1", "output": "69" }, { "input": "40 46 19", "output": "27" }, { "input": "71 38 56", "output": "33" }, { "input": "82 21 80", "output": "61" }, { "input": "75 8 35", "output": "67" }, { "input": "75 24 28", "output": "51" }, { "input": "78 23 56", "output": "55" }, { "input": "85 31 10", "output": "75" }, { "input": "76 50 9", "output": "67" }, { "input": "95 37 34", "output": "61" }, { "input": "84 61 35", "output": "49" }, { "input": "87 85 37", "output": "50" }, { "input": "1 3 2", "output": "2" }, { "input": "4 2 6", "output": "4" }, { "input": "6 9 3", "output": "6" }, { "input": "12 4 8", "output": "8" }, { "input": "15 10 5", "output": "10" }, { "input": "1 50 17", "output": "49" }, { "input": "10 5 15", "output": "10" }, { "input": "8 1 9", "output": "8" }, { "input": "3 5 4", "output": "2" }, { "input": "2 1 3", "output": "2" }, { "input": "1 8 2", "output": "7" }, { "input": "1 100 2", "output": "99" }, { "input": "1 4 6", "output": "5" } ]
1,675,189,597
2,147,483,647
Python 3
OK
TESTS
48
46
0
n_t = list(map(int, input().split())) minn = [abs(n_t[0] - n_t[1]), abs(n_t[0] - n_t[2]), abs(n_t[1] - n_t[2])] minn.sort() print(minn[-1]) '21 5 93'
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year? It's guaranteed that the optimal answer is always integer. Input Specification: The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. Output Specification: Print one integer — the minimum total distance the friends need to travel in order to meet together. Demo Input: ['7 1 4\n', '30 20 10\n'] Demo Output: ['6\n', '20\n'] Note: In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
```python n_t = list(map(int, input().split())) minn = [abs(n_t[0] - n_t[1]), abs(n_t[0] - n_t[2]), abs(n_t[1] - n_t[2])] minn.sort() print(minn[-1]) '21 5 93' ```
3
870
A
Search for Pretty Integers
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively. The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list. The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list.
Print the smallest pretty integer.
[ "2 3\n4 2\n5 7 6\n", "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n" ]
[ "25\n", "1\n" ]
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list. In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
500
[ { "input": "2 3\n4 2\n5 7 6", "output": "25" }, { "input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1", "output": "1" }, { "input": "1 1\n9\n1", "output": "19" }, { "input": "9 1\n5 4 2 3 6 1 7 9 8\n9", "output": "9" }, { "input": "5 3\n7 2 5 8 6\n3 1 9", "output": "12" }, { "input": "4 5\n5 2 6 4\n8 9 1 3 7", "output": "12" }, { "input": "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1", "output": "1" }, { "input": "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6", "output": "1" }, { "input": "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7", "output": "1" }, { "input": "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "9 9\n1 2 3 4 5 6 7 8 9\n9 8 7 6 5 4 3 2 1", "output": "1" }, { "input": "9 9\n9 8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "9 9\n9 8 7 6 5 4 3 2 1\n9 8 7 6 5 4 3 2 1", "output": "1" }, { "input": "1 1\n8\n9", "output": "89" }, { "input": "1 1\n9\n8", "output": "89" }, { "input": "1 1\n1\n2", "output": "12" }, { "input": "1 1\n2\n1", "output": "12" }, { "input": "1 1\n9\n9", "output": "9" }, { "input": "1 1\n1\n1", "output": "1" }, { "input": "4 5\n3 2 4 5\n1 6 5 9 8", "output": "5" }, { "input": "3 2\n4 5 6\n1 5", "output": "5" }, { "input": "5 4\n1 3 5 6 7\n2 4 3 9", "output": "3" }, { "input": "5 5\n1 3 5 7 9\n2 4 6 8 9", "output": "9" }, { "input": "2 2\n1 8\n2 8", "output": "8" }, { "input": "5 5\n5 6 7 8 9\n1 2 3 4 5", "output": "5" }, { "input": "5 5\n1 2 3 4 5\n1 2 3 4 5", "output": "1" }, { "input": "5 5\n1 2 3 4 5\n2 3 4 5 6", "output": "2" }, { "input": "2 2\n1 5\n2 5", "output": "5" }, { "input": "4 4\n1 3 5 8\n2 4 6 8", "output": "8" }, { "input": "3 3\n1 5 3\n2 5 7", "output": "5" }, { "input": "3 3\n3 6 8\n2 6 9", "output": "6" }, { "input": "2 2\n1 4\n2 4", "output": "4" }, { "input": "5 3\n3 4 5 6 7\n1 5 9", "output": "5" }, { "input": "4 4\n1 2 3 4\n2 5 6 7", "output": "2" }, { "input": "5 5\n1 2 3 4 5\n9 2 1 7 5", "output": "1" }, { "input": "2 2\n1 3\n2 3", "output": "3" }, { "input": "3 3\n3 2 1\n3 2 1", "output": "1" }, { "input": "3 3\n1 3 5\n2 3 6", "output": "3" }, { "input": "3 3\n5 6 7\n5 6 7", "output": "5" }, { "input": "1 2\n5\n2 5", "output": "5" }, { "input": "3 3\n2 4 9\n7 8 9", "output": "9" }, { "input": "3 3\n1 2 4\n3 4 5", "output": "4" }, { "input": "3 2\n1 4 9\n2 4", "output": "4" }, { "input": "3 3\n3 5 6\n1 5 9", "output": "5" }, { "input": "3 2\n1 2 4\n3 4", "output": "4" }, { "input": "2 4\n8 9\n1 2 3 9", "output": "9" }, { "input": "1 2\n9\n8 9", "output": "9" }, { "input": "3 2\n1 2 4\n4 2", "output": "2" }, { "input": "2 3\n4 5\n1 3 5", "output": "5" }, { "input": "3 2\n1 2 3\n2 3", "output": "2" }, { "input": "4 3\n1 3 5 9\n2 8 9", "output": "9" }, { "input": "2 2\n1 9\n9 2", "output": "9" } ]
1,670,505,837
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
r = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) a_sorty = [] b_sorty = [] for x in range(len(a)): if a[x] not in a_sorty: a_sorty.append(a[x]) for y in range(len(b)): if b[y] not in b_sorty: b_sorty.append(b[y]) a_sorty = sorted(a_sorty) b_sorty = sorted(b_sorty) if a_sorty[0] > b_sorty[0]: test = str(a_sorty[0]) + str(b_sorty[0]) else: test = str(b_sorty[0]) + str(a_sorty[0]) print(test)
Title: Search for Pretty Integers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively. The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list. The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list. Output Specification: Print the smallest pretty integer. Demo Input: ['2 3\n4 2\n5 7 6\n', '8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n'] Demo Output: ['25\n', '1\n'] Note: In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list. In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
```python r = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) a_sorty = [] b_sorty = [] for x in range(len(a)): if a[x] not in a_sorty: a_sorty.append(a[x]) for y in range(len(b)): if b[y] not in b_sorty: b_sorty.append(b[y]) a_sorty = sorted(a_sorty) b_sorty = sorted(b_sorty) if a_sorty[0] > b_sorty[0]: test = str(a_sorty[0]) + str(b_sorty[0]) else: test = str(b_sorty[0]) + str(a_sorty[0]) print(test) ```
0
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" }, { "input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn", "output": "IGNORE HIM!" }, { "input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx", "output": "CHAT WITH HER!" }, { "input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt", "output": "IGNORE HIM!" }, { "input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk", "output": "IGNORE HIM!" }, { "input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz", "output": "IGNORE HIM!" }, { "input": "tgcdptnkc", "output": "IGNORE HIM!" }, { "input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi", "output": "IGNORE HIM!" }, { "input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp", "output": "IGNORE HIM!" }, { "input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia", "output": "IGNORE HIM!" }, { "input": "fpellxwskyekoyvrfnuf", "output": "CHAT WITH HER!" }, { "input": "xninyvkuvakfbs", "output": "IGNORE HIM!" }, { "input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak", "output": "CHAT WITH HER!" }, { "input": "kmsk", "output": "IGNORE HIM!" }, { "input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz", "output": "CHAT WITH HER!" }, { "input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq", "output": "CHAT WITH HER!" }, { "input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm", "output": "IGNORE HIM!" }, { "input": "ppcpbnhwoizajrl", "output": "IGNORE HIM!" }, { "input": "sgubujztzwkzvztitssxxxwzanfmddfqvv", "output": "CHAT WITH HER!" }, { "input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw", "output": "IGNORE HIM!" }, { "input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu", "output": "CHAT WITH HER!" }, { "input": "ojjvpnkrxibyevxk", "output": "CHAT WITH HER!" }, { "input": "wjweqcrqfuollfvfbiyriijovweg", "output": "IGNORE HIM!" }, { "input": "hkdbykboclchfdsuovvpknwqr", "output": "IGNORE HIM!" }, { "input": "stjvyfrfowopwfjdveduedqylerqugykyu", "output": "IGNORE HIM!" }, { "input": "rafcaanqytfclvfdegak", "output": "CHAT WITH HER!" }, { "input": "xczn", "output": "CHAT WITH HER!" }, { "input": "arcoaeozyeawbveoxpmafxxzdjldsielp", "output": "IGNORE HIM!" }, { "input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika", "output": "CHAT WITH HER!" }, { "input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh", "output": "CHAT WITH HER!" }, { "input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg", "output": "CHAT WITH HER!" }, { "input": "udlpagtpq", "output": "CHAT WITH HER!" }, { "input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy", "output": "CHAT WITH HER!" }, { "input": "qagzrqjomdwhagkhrjahhxkieijyten", "output": "CHAT WITH HER!" }, { "input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb", "output": "CHAT WITH HER!" }, { "input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr", "output": "CHAT WITH HER!" }, { "input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc", "output": "IGNORE HIM!" }, { "input": "lnpdosnceumubvk", "output": "IGNORE HIM!" }, { "input": "efrk", "output": "CHAT WITH HER!" }, { "input": "temnownneghnrujforif", "output": "IGNORE HIM!" }, { "input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta", "output": "IGNORE HIM!" }, { "input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh", "output": "IGNORE HIM!" }, { "input": "gwntwbpj", "output": "IGNORE HIM!" }, { "input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim", "output": "IGNORE HIM!" }, { "input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd", "output": "CHAT WITH HER!" }, { "input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx", "output": "IGNORE HIM!" }, { "input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks", "output": "CHAT WITH HER!" }, { "input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx", "output": "CHAT WITH HER!" }, { "input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc", "output": "CHAT WITH HER!" }, { "input": "yzlzmesxdttfcztooypjztlgxwcr", "output": "IGNORE HIM!" }, { "input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc", "output": "IGNORE HIM!" }, { "input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq", "output": "CHAT WITH HER!" }, { "input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj", "output": "IGNORE HIM!" }, { "input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom", "output": "CHAT WITH HER!" }, { "input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo", "output": "CHAT WITH HER!" }, { "input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh", "output": "IGNORE HIM!" }, { "input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa", "output": "CHAT WITH HER!" }, { "input": "oh", "output": "CHAT WITH HER!" }, { "input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri", "output": "IGNORE HIM!" }, { "input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp", "output": "CHAT WITH HER!" }, { "input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp", "output": "CHAT WITH HER!" }, { "input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo", "output": "CHAT WITH HER!" }, { "input": "mnmbupgo", "output": "IGNORE HIM!" }, { "input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl", "output": "IGNORE HIM!" }, { "input": "yocxrzspinchmhtmqo", "output": "CHAT WITH HER!" }, { "input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv", "output": "CHAT WITH HER!" }, { "input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad", "output": "IGNORE HIM!" }, { "input": "ubvhyaebyxoghakajqrpqpctwbrfqzli", "output": "CHAT WITH HER!" }, { "input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy", "output": "IGNORE HIM!" }, { "input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd", "output": "IGNORE HIM!" }, { "input": "acrzbavz", "output": "CHAT WITH HER!" }, { "input": "drvzznznvrzskftnrhvvzxcalwutxmdza", "output": "IGNORE HIM!" }, { "input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws", "output": "CHAT WITH HER!" }, { "input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff", "output": "CHAT WITH HER!" }, { "input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu", "output": "CHAT WITH HER!" }, { "input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw", "output": "IGNORE HIM!" }, { "input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy", "output": "CHAT WITH HER!" }, { "input": "rhh", "output": "CHAT WITH HER!" }, { "input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo", "output": "IGNORE HIM!" }, { "input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn", "output": "CHAT WITH HER!" }, { "input": "urigreuzpxnej", "output": "CHAT WITH HER!" } ]
1,695,196,659
2,147,483,647
Python 3
OK
TESTS
85
92
0
user_name = input() distinct = {} for char in user_name: if char not in distinct: distinct[char] = 0 else: distinct[char] += 1 # print(distinct) rep = 0 count = 0 for val in distinct.values(): if val == 0: count += 1 else: rep +=1 if (count + rep) % 2 == 0: print("CHAT WITH HER!") else: print("IGNORE HIM!")
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. Input Specification: The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. Output Specification: If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). Demo Input: ['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n'] Demo Output: ['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n'] Note: For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
```python user_name = input() distinct = {} for char in user_name: if char not in distinct: distinct[char] = 0 else: distinct[char] += 1 # print(distinct) rep = 0 count = 0 for val in distinct.values(): if val == 0: count += 1 else: rep +=1 if (count + rep) % 2 == 0: print("CHAT WITH HER!") else: print("IGNORE HIM!") ```
3
987
A
Infinity Gauntlet
PROGRAMMING
800
[ "implementation" ]
null
null
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
[ "4\nred\npurple\nyellow\norange\n", "0\n" ]
[ "2\nSpace\nTime\n", "6\nTime\nMind\nSoul\nPower\nReality\nSpace\n" ]
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
500
[ { "input": "4\nred\npurple\nyellow\norange", "output": "2\nSpace\nTime" }, { "input": "0", "output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul" }, { "input": "6\npurple\nblue\nyellow\nred\ngreen\norange", "output": "0" }, { "input": "1\npurple", "output": "5\nTime\nReality\nSoul\nSpace\nMind" }, { "input": "3\nblue\norange\npurple", "output": "3\nTime\nReality\nMind" }, { "input": "2\nyellow\nred", "output": "4\nPower\nSoul\nSpace\nTime" }, { "input": "1\ngreen", "output": "5\nReality\nSpace\nPower\nSoul\nMind" }, { "input": "2\npurple\ngreen", "output": "4\nReality\nMind\nSpace\nSoul" }, { "input": "1\nblue", "output": "5\nPower\nReality\nSoul\nTime\nMind" }, { "input": "2\npurple\nblue", "output": "4\nMind\nSoul\nTime\nReality" }, { "input": "2\ngreen\nblue", "output": "4\nReality\nMind\nPower\nSoul" }, { "input": "3\npurple\ngreen\nblue", "output": "3\nMind\nReality\nSoul" }, { "input": "1\norange", "output": "5\nReality\nTime\nPower\nSpace\nMind" }, { "input": "2\npurple\norange", "output": "4\nReality\nMind\nTime\nSpace" }, { "input": "2\norange\ngreen", "output": "4\nSpace\nMind\nReality\nPower" }, { "input": "3\norange\npurple\ngreen", "output": "3\nReality\nSpace\nMind" }, { "input": "2\norange\nblue", "output": "4\nTime\nMind\nReality\nPower" }, { "input": "3\nblue\ngreen\norange", "output": "3\nPower\nMind\nReality" }, { "input": "4\nblue\norange\ngreen\npurple", "output": "2\nMind\nReality" }, { "input": "1\nred", "output": "5\nTime\nSoul\nMind\nPower\nSpace" }, { "input": "2\nred\npurple", "output": "4\nMind\nSpace\nTime\nSoul" }, { "input": "2\nred\ngreen", "output": "4\nMind\nSpace\nPower\nSoul" }, { "input": "3\nred\npurple\ngreen", "output": "3\nSoul\nSpace\nMind" }, { "input": "2\nblue\nred", "output": "4\nMind\nTime\nPower\nSoul" }, { "input": "3\nred\nblue\npurple", "output": "3\nTime\nMind\nSoul" }, { "input": "3\nred\nblue\ngreen", "output": "3\nSoul\nPower\nMind" }, { "input": "4\npurple\nblue\ngreen\nred", "output": "2\nMind\nSoul" }, { "input": "2\norange\nred", "output": "4\nPower\nMind\nTime\nSpace" }, { "input": "3\nred\norange\npurple", "output": "3\nMind\nSpace\nTime" }, { "input": "3\nred\norange\ngreen", "output": "3\nMind\nSpace\nPower" }, { "input": "4\nred\norange\ngreen\npurple", "output": "2\nSpace\nMind" }, { "input": "3\nblue\norange\nred", "output": "3\nPower\nMind\nTime" }, { "input": "4\norange\nblue\npurple\nred", "output": "2\nTime\nMind" }, { "input": "4\ngreen\norange\nred\nblue", "output": "2\nMind\nPower" }, { "input": "5\npurple\norange\nblue\nred\ngreen", "output": "1\nMind" }, { "input": "1\nyellow", "output": "5\nPower\nSoul\nReality\nSpace\nTime" }, { "input": "2\npurple\nyellow", "output": "4\nTime\nReality\nSpace\nSoul" }, { "input": "2\ngreen\nyellow", "output": "4\nSpace\nReality\nPower\nSoul" }, { "input": "3\npurple\nyellow\ngreen", "output": "3\nSoul\nReality\nSpace" }, { "input": "2\nblue\nyellow", "output": "4\nTime\nReality\nPower\nSoul" }, { "input": "3\nyellow\nblue\npurple", "output": "3\nSoul\nReality\nTime" }, { "input": "3\ngreen\nyellow\nblue", "output": "3\nSoul\nReality\nPower" }, { "input": "4\nyellow\nblue\ngreen\npurple", "output": "2\nReality\nSoul" }, { "input": "2\nyellow\norange", "output": "4\nTime\nSpace\nReality\nPower" }, { "input": "3\nyellow\npurple\norange", "output": "3\nSpace\nReality\nTime" }, { "input": "3\norange\nyellow\ngreen", "output": "3\nSpace\nReality\nPower" }, { "input": "4\ngreen\nyellow\norange\npurple", "output": "2\nSpace\nReality" }, { "input": "3\nyellow\nblue\norange", "output": "3\nTime\nReality\nPower" }, { "input": "4\norange\npurple\nblue\nyellow", "output": "2\nReality\nTime" }, { "input": "4\nblue\norange\nyellow\ngreen", "output": "2\nReality\nPower" }, { "input": "5\ngreen\nyellow\norange\nblue\npurple", "output": "1\nReality" }, { "input": "3\nyellow\npurple\nred", "output": "3\nTime\nSoul\nSpace" }, { "input": "3\nred\ngreen\nyellow", "output": "3\nPower\nSoul\nSpace" }, { "input": "4\nred\npurple\ngreen\nyellow", "output": "2\nSpace\nSoul" }, { "input": "3\nred\nyellow\nblue", "output": "3\nPower\nSoul\nTime" }, { "input": "4\nblue\nyellow\nred\npurple", "output": "2\nTime\nSoul" }, { "input": "4\nblue\nyellow\nred\ngreen", "output": "2\nSoul\nPower" }, { "input": "5\nred\nyellow\ngreen\nblue\npurple", "output": "1\nSoul" }, { "input": "3\nred\nyellow\norange", "output": "3\nPower\nSpace\nTime" }, { "input": "4\norange\ngreen\nyellow\nred", "output": "2\nPower\nSpace" }, { "input": "5\norange\nred\ngreen\nyellow\npurple", "output": "1\nSpace" }, { "input": "4\nyellow\nred\norange\nblue", "output": "2\nTime\nPower" }, { "input": "5\npurple\nblue\norange\nyellow\nred", "output": "1\nTime" }, { "input": "5\norange\nblue\nyellow\nred\ngreen", "output": "1\nPower" } ]
1,664,401,640
2,147,483,647
PyPy 3-64
OK
TESTS
64
62
0
n = int(input()) gems = ['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind'] colors = ['purple', 'green', 'blue', 'orange', 'red', 'yellow'] d = dict(zip(colors, gems)) for i in range(n): gems.remove(d[input()]) print(6 - n) for i in range(6-n): print(gems[i])
Title: Infinity Gauntlet Time Limit: None seconds Memory Limit: None megabytes Problem Description: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. Input Specification: In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. Output Specification: In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. Demo Input: ['4\nred\npurple\nyellow\norange\n', '0\n'] Demo Output: ['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n'] Note: In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
```python n = int(input()) gems = ['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind'] colors = ['purple', 'green', 'blue', 'orange', 'red', 'yellow'] d = dict(zip(colors, gems)) for i in range(n): gems.remove(d[input()]) print(6 - n) for i in range(6-n): print(gems[i]) ```
3
322
B
Ciel and Flowers
PROGRAMMING
1,600
[ "combinatorics", "math" ]
null
null
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make.
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
[ "3 6 9\n", "4 4 4\n", "0 0 0\n" ]
[ "6\n", "4\n", "0\n" ]
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
1,000
[ { "input": "3 6 9", "output": "6" }, { "input": "4 4 4", "output": "4" }, { "input": "0 0 0", "output": "0" }, { "input": "0 3 6", "output": "3" }, { "input": "7 8 9", "output": "7" }, { "input": "8 8 9", "output": "8" }, { "input": "15 3 999", "output": "339" }, { "input": "32 62 92", "output": "62" }, { "input": "123456789 123456789 123456789", "output": "123456789" }, { "input": "3 5 5", "output": "4" }, { "input": "666806767 385540591 357848286", "output": "470065214" }, { "input": "80010646 727118126 817880463", "output": "541669744" }, { "input": "829651016 732259171 572879931", "output": "711596705" }, { "input": "242854896 442432924 180395753", "output": "288561190" }, { "input": "139978911 5123031 935395222", "output": "360165721" }, { "input": "553182792 10264076 395427398", "output": "319624755" }, { "input": "597790453 720437830 855459575", "output": "724562619" }, { "input": "494914467 356982656 757942689", "output": "536613270" }, { "input": "908118348 67156409 217974865", "output": "397749873" }, { "input": "952726009 629846517 972974334", "output": "851848953" }, { "input": "775140200 616574841 630329230", "output": "674014756" }, { "input": "524780569 326748594 90361407", "output": "313963523" }, { "input": "937984449 184405994 992844522", "output": "705078321" }, { "input": "835108464 525983528 452876698", "output": "604656229" }, { "input": "879716125 531124573 207876166", "output": "539572288" }, { "input": "292920005 241298326 667908343", "output": "400708891" }, { "input": "1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1000000000 999999999 999999998", "output": "999999998" }, { "input": "999999998 999999998 999999999", "output": "999999998" }, { "input": "0 1 1", "output": "0" }, { "input": "0 1000000000 0", "output": "333333333" }, { "input": "0 1 0", "output": "0" }, { "input": "1 0 0", "output": "0" }, { "input": "0 2 2", "output": "0" }, { "input": "3 3 5", "output": "3" }, { "input": "2 2 0", "output": "0" }, { "input": "0 5 5", "output": "2" }, { "input": "2 0 11", "output": "3" }, { "input": "9 9 7", "output": "8" }, { "input": "65 30 74", "output": "56" } ]
1,373,011,460
2,147,483,647
Python 3
OK
TESTS
40
93
0
r, g, b = map(int, input().split(' ')) s = 0 for i in range(0, 10): for j in range(0, 10): for k in range(0, 10): if (r >= i and g >= j and b >= k): s = max(s, (r - i) // 3 + (g - j) // 3 + (b - k) // 3 + min(i, min(j, k))) print(s)
Title: Ciel and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3 blue flowers. - To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower. Help Fox Ciel to find the maximal number of bouquets she can make. Input Specification: The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. Output Specification: Print the maximal number of bouquets Fox Ciel can make. Demo Input: ['3 6 9\n', '4 4 4\n', '0 0 0\n'] Demo Output: ['6\n', '4\n', '0\n'] Note: In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
```python r, g, b = map(int, input().split(' ')) s = 0 for i in range(0, 10): for j in range(0, 10): for k in range(0, 10): if (r >= i and g >= j and b >= k): s = max(s, (r - i) // 3 + (g - j) // 3 + (b - k) // 3 + min(i, min(j, k))) print(s) ```
3
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }, { "input": "859 453892 543", "output": "126416972" }, { "input": "1000 1000000000 1000", "output": "0" }, { "input": "1000 500500000 1000", "output": "0" }, { "input": "1000 500500001 1000", "output": "0" }, { "input": "1000 500499999 1000", "output": "1" }, { "input": "634 87973 214", "output": "14497197" }, { "input": "432 10000 241", "output": "12587552" }, { "input": "111 111111111 111", "output": "0" }, { "input": "20 43 3", "output": "77" } ]
1,694,360,302
2,147,483,647
Python 3
OK
TESTS
15
46
0
k,n,w=input().split() c=0 for i in range(1,int(w)+1): c=c+i*int(k) if c<int(n): print(0) else: print(c-int(n))
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. Output Specification: Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python k,n,w=input().split() c=0 for i in range(1,int(w)+1): c=c+i*int(k) if c<int(n): print(0) else: print(c-int(n)) ```
3
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", "output": "1" }, { "input": "1000 9", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "999 9", "output": "1" }, { "input": "999 8", "output": "2" }, { "input": "105 6", "output": "2" }, { "input": "403 9", "output": "3" }, { "input": "546 4", "output": "4" }, { "input": "228 9", "output": "5" }, { "input": "57 2", "output": "6" }, { "input": "437 9", "output": "7" }, { "input": "997 6", "output": "8" }, { "input": "109 1", "output": "9" }, { "input": "998 9", "output": "5" }, { "input": "4 2", "output": "3" }, { "input": "9 3", "output": "7" }, { "input": "8 2", "output": "4" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "7" }, { "input": "1 8", "output": "8" }, { "input": "100 3", "output": "1" }, { "input": "1000 2", "output": "1" }, { "input": "1000 4", "output": "1" }, { "input": "1000 5", "output": "1" }, { "input": "1000 6", "output": "1" }, { "input": "1000 7", "output": "1" }, { "input": "1000 8", "output": "1" }, { "input": "23 4", "output": "8" }, { "input": "33 1", "output": "7" }, { "input": "33 2", "output": "4" }, { "input": "666 5", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "5 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "12 4", "output": "2" }, { "input": "15 5", "output": "1" }, { "input": "2 5", "output": "5" }, { "input": "25 5", "output": "1" }, { "input": "2 9", "output": "5" }, { "input": "6 7", "output": "5" }, { "input": "8 9", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "4 7", "output": "5" }, { "input": "2 1", "output": "5" }, { "input": "261 1", "output": "1" } ]
1,692,879,340
2,147,483,647
PyPy 3-64
OK
TESTS
54
62
0
a, b = [int(i) for i in input().split()] i = 1 while (a * i) % 10 != b and (i * a) % 10 != 0: i += 1 print(i)
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. Input Specification: The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. Output Specification: Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. Demo Input: ['117 3\n', '237 7\n', '15 2\n'] Demo Output: ['9\n', '1\n', '2\n'] Note: In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
```python a, b = [int(i) for i in input().split()] i = 1 while (a * i) % 10 != b and (i * a) % 10 != 0: i += 1 print(i) ```
3
884
B
Japanese Crosswords Strike Back
PROGRAMMING
1,100
[ "implementation" ]
null
null
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
[ "2 4\n1 3\n", "3 10\n3 3 2\n", "2 10\n1 3\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
0
[ { "input": "2 4\n1 3", "output": "NO" }, { "input": "3 10\n3 3 2", "output": "YES" }, { "input": "2 10\n1 3", "output": "NO" }, { "input": "1 1\n1", "output": "YES" }, { "input": "1 10\n10", "output": "YES" }, { "input": "1 10000\n10000", "output": "YES" }, { "input": "10 1\n5 78 3 87 4 9 5 8 9 1235", "output": "NO" }, { "input": "3 12\n3 3 3", "output": "NO" }, { "input": "3 9\n2 2 2", "output": "NO" }, { "input": "2 5\n1 1", "output": "NO" }, { "input": "1 2\n1", "output": "NO" }, { "input": "3 13\n3 3 3", "output": "NO" }, { "input": "3 6\n1 1 1", "output": "NO" }, { "input": "1 6\n5", "output": "NO" }, { "input": "3 11\n3 3 2", "output": "NO" }, { "input": "2 6\n1 3", "output": "NO" }, { "input": "3 10\n2 2 2", "output": "NO" }, { "input": "3 8\n2 1 1", "output": "NO" }, { "input": "1 5\n2", "output": "NO" }, { "input": "1 3\n1", "output": "NO" }, { "input": "5 5\n1 1 1 1 1", "output": "NO" }, { "input": "2 10\n4 4", "output": "NO" }, { "input": "2 8\n2 3", "output": "NO" }, { "input": "2 4\n1 1", "output": "NO" }, { "input": "3 10\n1 2 4", "output": "NO" }, { "input": "3 10\n2 1 3", "output": "NO" }, { "input": "2 6\n1 2", "output": "NO" }, { "input": "3 4\n1 1 1", "output": "NO" }, { "input": "3 11\n1 2 4", "output": "NO" }, { "input": "3 12\n3 3 2", "output": "NO" }, { "input": "4 9\n1 1 1 1", "output": "NO" }, { "input": "1 10\n9", "output": "NO" }, { "input": "1 7\n5", "output": "NO" }, { "input": "2 5\n1 2", "output": "NO" }, { "input": "3 8\n1 1 2", "output": "NO" }, { "input": "3 7\n1 1 1", "output": "NO" }, { "input": "1 10\n1", "output": "NO" }, { "input": "3 10\n2 3 4", "output": "NO" }, { "input": "3 9\n1 2 3", "output": "NO" }, { "input": "3 9\n3 3 2", "output": "NO" }, { "input": "3 6\n3 3 2", "output": "NO" }, { "input": "1 1\n3", "output": "NO" }, { "input": "1 3\n2", "output": "NO" }, { "input": "3 10\n3 3 3", "output": "NO" }, { "input": "3 5\n1 1 1", "output": "YES" }, { "input": "2 1\n100 100", "output": "NO" }, { "input": "3 3\n3 3 3", "output": "NO" }, { "input": "4 17\n3 3 9 1", "output": "NO" }, { "input": "4 1660\n1505 13 37 100", "output": "NO" }, { "input": "3 5\n3 3 2", "output": "NO" }, { "input": "4 10\n3 3 2 5", "output": "NO" }, { "input": "5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n2", "output": "NO" }, { "input": "5 10\n1 2 2 4 5", "output": "NO" }, { "input": "2 1\n1 1", "output": "NO" } ]
1,580,848,733
2,147,483,647
PyPy 3
OK
TESTS
66
186
9,216,000
l = [int(x) for x in input().split()] n = l[0] x = l[1] l = [int(x) for x in input().split()] count = 0 for e in l: count += e+1 if count == x+1: print("YES") else: print("NO")
Title: Japanese Crosswords Strike Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! Input Specification: The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. Output Specification: Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. Demo Input: ['2 4\n1 3\n', '3 10\n3 3 2\n', '2 10\n1 3\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: none
```python l = [int(x) for x in input().split()] n = l[0] x = l[1] l = [int(x) for x in input().split()] count = 0 for e in l: count += e+1 if count == x+1: print("YES") else: print("NO") ```
3
965
A
Paper Airplanes
PROGRAMMING
800
[ "math" ]
null
null
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy?
The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Print a single integer — the minimum number of packs they should buy.
[ "5 3 2 3\n", "5 3 100 1\n" ]
[ "4\n", "5\n" ]
In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
500
[ { "input": "5 3 2 3", "output": "4" }, { "input": "5 3 100 1", "output": "5" }, { "input": "10000 10000 1 1", "output": "100000000" }, { "input": "1 1 10000 10000", "output": "1" }, { "input": "300 300 21 23", "output": "196" }, { "input": "300 2 37 51", "output": "6" }, { "input": "2 400 23 57", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "10000 10000 3 2", "output": "16670000" }, { "input": "1 2 1 2", "output": "1" }, { "input": "1 1 2 2", "output": "1" }, { "input": "1 1 10 10", "output": "1" }, { "input": "5324 5439 32 13", "output": "69622" }, { "input": "9000 1 2432 1", "output": "9000" }, { "input": "230 1234 9124 23", "output": "10" }, { "input": "11 1 1 1", "output": "11" }, { "input": "6246 8489 1227 9", "output": "4858" }, { "input": "9 20 5 7", "output": "6" } ]
1,524,753,761
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
77
7,065,600
line=input() temp=line.split(' ') k=int(temp[0]) n=int(temp[1]) s=int(temp[2]) p=int(temp[3]) sheetperperson=(n/s)+1 res=int((sheetperperson*k)/p) print(res)
Title: Paper Airplanes Time Limit: None seconds Memory Limit: None megabytes Problem Description: To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes. A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $n$ airplanes. How many packs should they buy? Input Specification: The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. Output Specification: Print a single integer — the minimum number of packs they should buy. Demo Input: ['5 3 2 3\n', '5 3 100 1\n'] Demo Output: ['4\n', '5\n'] Note: In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs. In the second sample they have to buy a pack for each person as they can't share sheets.
```python line=input() temp=line.split(' ') k=int(temp[0]) n=int(temp[1]) s=int(temp[2]) p=int(temp[3]) sheetperperson=(n/s)+1 res=int((sheetperperson*k)/p) print(res) ```
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,608,868,433
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
0
string1 = input() string2 = 'hello' i = 0 j = 0 while i<len(string1) and j<len(string2): if string1[i] == string2[j]: i = i+1 j = j+1 else: i = i+1 if j==len(string2): 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 string1 = input() string2 = 'hello' i = 0 j = 0 while i<len(string1) and j<len(string2): if string1[i] == string2[j]: i = i+1 j = j+1 else: i = i+1 if j==len(string2): print("Yes") else: print('No') ```
0
0
none
none
none
0
[ "none" ]
null
null
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide.
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
[ "3\n1 1\n7 5\n1 5\n", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n" ]
[ "2\n", "11\n" ]
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
0
[ { "input": "3\n1 1\n7 5\n1 5", "output": "2" }, { "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "output": "11" }, { "input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "output": "33" }, { "input": "1\n-5 -90", "output": "0" }, { "input": "2\n315 845\n-669 -762", "output": "0" }, { "input": "3\n8911 7861\n-6888 7861\n8911 7861", "output": "3" }, { "input": "2\n-1 1000000000\n0 -1", "output": "0" }, { "input": "2\n1000000000 0\n-7 1", "output": "0" }, { "input": "2\n1 4\n2 1", "output": "0" }, { "input": "2\n1 0\n0 2333333", "output": "0" }, { "input": "2\n2 1\n1 2", "output": "0" }, { "input": "2\n1 1000000000\n2 -1000000000", "output": "0" }, { "input": "2\n0 1000000000\n1 -7", "output": "0" }, { "input": "2\n1 0\n0 19990213", "output": "0" } ]
1,566,344,063
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
0
n = int(input()) w = [None]*n for i in range(n): x,y = map(int,input().split()) w[i] = (x,y) w.sort() eq = 0 np = 0 for i in range(n): eq += 1 if i+1==n or w[i][0] != w[i+1][0]: #print("keq",eq) comb = eq*(eq-1)//2 np += comb eq = 0 elif i>0 and w[i][0] == w[i-1][0] and w[i][1]==w[i-1][1]: np -= 1 def sortSecond(val): return val[1] w.sort(key=sortSecond) eq = 0 for i in range(n): eq += 1 if i+1==n or w[i][1] != w[i+1][1]: #print("eq",eq) comb = eq*(eq-1)//2 np += comb eq = 0 print(np)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. Input Specification: The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide. Output Specification: Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. Demo Input: ['3\n1 1\n7 5\n1 5\n', '6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n'] Demo Output: ['2\n', '11\n'] Note: In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
```python n = int(input()) w = [None]*n for i in range(n): x,y = map(int,input().split()) w[i] = (x,y) w.sort() eq = 0 np = 0 for i in range(n): eq += 1 if i+1==n or w[i][0] != w[i+1][0]: #print("keq",eq) comb = eq*(eq-1)//2 np += comb eq = 0 elif i>0 and w[i][0] == w[i-1][0] and w[i][1]==w[i-1][1]: np -= 1 def sortSecond(val): return val[1] w.sort(key=sortSecond) eq = 0 for i in range(n): eq += 1 if i+1==n or w[i][1] != w[i+1][1]: #print("eq",eq) comb = eq*(eq-1)//2 np += comb eq = 0 print(np) ```
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,688,328,720
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
n = int(input()) c=0 z=0 s=[] for i in range(0,n): s.append (input().split()) if i != 0: z=int(s[i-1][1])-int(s[i][0])+int(s[i][1]) if z> c: c=z print(c)
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()) c=0 z=0 s=[] for i in range(0,n): s.append (input().split()) if i != 0: z=int(s[i-1][1])-int(s[i][0])+int(s[i][1]) if z> c: c=z print(c) ```
0
641
A
Little Artem and Grasshopper
PROGRAMMING
1,000
[ "implementation" ]
null
null
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip. Next line contains a string of length *n* which consists of characters "&lt;" and "&gt;" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d**i*<=≤<=109) — the length of the jump from the *i*-th cell.
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
[ "2\n&gt;&lt;\n1 2\n", "3\n&gt;&gt;&lt;\n2 1 1\n" ]
[ "FINITE\n", "INFINITE" ]
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip. Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
500
[ { "input": "2\n><\n1 2", "output": "FINITE" }, { "input": "3\n>><\n2 1 1", "output": "INFINITE" }, { "input": "1\n>\n1000000000", "output": "FINITE" }, { "input": "1\n<\n1000000000", "output": "FINITE" }, { "input": "2\n>>\n1 1", "output": "FINITE" }, { "input": "5\n>><><\n1 2 3 1 2", "output": "FINITE" }, { "input": "5\n>><><\n1 2 2 1 2", "output": "INFINITE" }, { "input": "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 10", "output": "FINITE" }, { "input": "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 5", "output": "INFINITE" }, { "input": "10\n>>>>>>>>><\n1 1 1 1 1 1 1 1 1 1", "output": "INFINITE" }, { "input": "3\n><<\n2 1 1", "output": "INFINITE" }, { "input": "10\n>>>>>>>>>>\n1 1 1 1 1 1 1 1 1 100", "output": "FINITE" }, { "input": "3\n><<\n2 100 2", "output": "INFINITE" }, { "input": "3\n><<\n2 3 2", "output": "INFINITE" }, { "input": "3\n>><\n2 3 2", "output": "INFINITE" }, { "input": "3\n><>\n1 1 1", "output": "INFINITE" }, { "input": "3\n>><\n2 2 2", "output": "INFINITE" }, { "input": "4\n>><<\n2 100 2 100", "output": "INFINITE" }, { "input": "3\n><>\n1 1 3", "output": "INFINITE" }, { "input": "5\n><>>>\n1 1 10 10 10", "output": "INFINITE" }, { "input": "5\n><<<<\n500 1 2 3 4", "output": "FINITE" }, { "input": "4\n><><\n2 1000 1 1", "output": "INFINITE" }, { "input": "3\n><<\n2 10 2", "output": "INFINITE" }, { "input": "3\n><<\n2 5 2", "output": "INFINITE" }, { "input": "2\n><\n5 5", "output": "FINITE" }, { "input": "3\n>><\n1 10 10", "output": "FINITE" }, { "input": "4\n><<>\n2 1 1 5", "output": "INFINITE" }, { "input": "5\n<<>>>\n1 1 1 1 1", "output": "FINITE" }, { "input": "3\n><>\n1 1 12345", "output": "INFINITE" }, { "input": "4\n>>><\n3 2 2 3", "output": "INFINITE" }, { "input": "3\n><>\n1 1 100000", "output": "INFINITE" } ]
1,462,632,820
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
4,608,000
def main(): n = int(input()) arrows = input() cells = [int(x) for x in input().split()] print(solver(arrows, cells)) def solver(arrows, cells): for i in range(len(arrows)): if arrows[i] == '<': cells[i] = - cells[i] visited = [False] * len(cells) index = 0 print(cells) while True: if index >= len(cells) or index < 0: return "FINITE" elif visited[index] == True: return "INFINITE" else: visited[index] = True index = index + cells[index] #print(solver(">><", [2, 1, 1])) #print(solver("><", [1, 2]))
Title: Little Artem and Grasshopper Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip. Next line contains a string of length *n* which consists of characters "&lt;" and "&gt;" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d**i*<=≤<=109) — the length of the jump from the *i*-th cell. Output Specification: Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes). Demo Input: ['2\n&gt;&lt;\n1 2\n', '3\n&gt;&gt;&lt;\n2 1 1\n'] Demo Output: ['FINITE\n', 'INFINITE'] Note: In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip. Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
```python def main(): n = int(input()) arrows = input() cells = [int(x) for x in input().split()] print(solver(arrows, cells)) def solver(arrows, cells): for i in range(len(arrows)): if arrows[i] == '<': cells[i] = - cells[i] visited = [False] * len(cells) index = 0 print(cells) while True: if index >= len(cells) or index < 0: return "FINITE" elif visited[index] == True: return "INFINITE" else: visited[index] = True index = index + cells[index] #print(solver(">><", [2, 1, 1])) #print(solver("><", [1, 2])) ```
0
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", "output": "YES" }, { "input": "5 7", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "11 13", "output": "YES" }, { "input": "13 17", "output": "YES" }, { "input": "17 19", "output": "YES" }, { "input": "19 23", "output": "YES" }, { "input": "23 29", "output": "YES" }, { "input": "29 31", "output": "YES" }, { "input": "31 37", "output": "YES" }, { "input": "37 41", "output": "YES" }, { "input": "41 43", "output": "YES" }, { "input": "43 47", "output": "YES" }, { "input": "2 5", "output": "NO" }, { "input": "2 7", "output": "NO" }, { "input": "2 6", "output": "NO" }, { "input": "2 11", "output": "NO" }, { "input": "3 6", "output": "NO" }, { "input": "3 7", "output": "NO" }, { "input": "3 9", "output": "NO" }, { "input": "5 6", "output": "NO" }, { "input": "5 9", "output": "NO" }, { "input": "5 11", "output": "NO" }, { "input": "5 13", "output": "NO" }, { "input": "5 15", "output": "NO" }, { "input": "7 8", "output": "NO" }, { "input": "7 13", "output": "NO" }, { "input": "13 15", "output": "NO" }, { "input": "13 17", "output": "YES" }, { "input": "19 21", "output": "NO" }, { "input": "13 20", "output": "NO" }, { "input": "41 49", "output": "NO" }, { "input": "43 49", "output": "NO" }, { "input": "47 50", "output": "NO" }, { "input": "47 49", "output": "NO" }, { "input": "47 48", "output": "NO" }, { "input": "23 25", "output": "NO" }, { "input": "2 50", "output": "NO" }, { "input": "31 33", "output": "NO" } ]
1,569,110,874
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
404
2,560,000
x =int(input()) z =int(input()) if (z /z ==1) & (z/1 ==z )&(z%2!=0)&(x%2!=0)& (x/x ==1) & (x/1 ==x): print("YES") else: print("NO")
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? Input Specification: The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4. Output Specification: Print YES, if *m* is the next prime number after *n*, or NO otherwise. Demo Input: ['3 5\n', '7 11\n', '7 9\n'] Demo Output: ['YES', 'YES', 'NO'] Note: none
```python x =int(input()) z =int(input()) if (z /z ==1) & (z/1 ==z )&(z%2!=0)&(x%2!=0)& (x/x ==1) & (x/1 ==x): print("YES") else: print("NO") ```
-1
496
B
Secret Combination
PROGRAMMING
1,500
[ "brute force", "constructive algorithms", "implementation" ]
null
null
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068. You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display. The second line contains *n* digits — the initial state of the display.
Print a single line containing *n* digits — the desired state of the display containing the smallest possible number.
[ "3\n579\n", "4\n2014\n" ]
[ "024\n", "0142\n" ]
none
1,000
[ { "input": "3\n579", "output": "024" }, { "input": "4\n2014", "output": "0142" }, { "input": "1\n1", "output": "0" }, { "input": "3\n039", "output": "014" }, { "input": "4\n4444", "output": "0000" }, { "input": "5\n46802", "output": "02468" }, { "input": "10\n4447444444", "output": "0000000003" }, { "input": "10\n5810438174", "output": "0147609473" }, { "input": "30\n027027027027027027027027027027", "output": "027027027027027027027027027027" }, { "input": "50\n41012516454101251645410125164541012516454101251645", "output": "01076781720107678172010767817201076781720107678172" }, { "input": "72\n464553044645330446455304464553064645530445455304464553044645530446455304", "output": "001011960020119600201196002011960020119600201996002011960020119620201196" }, { "input": "100\n2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031", "output": "0005996121738545755443472571416650525236761083528703911639570359104365792010332041424619191680979818" }, { "input": "200\n79025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544", "output": "00274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086" }, { "input": "100\n6669666666666666666866266666666666666666666666666666666666666666626666666666666966666766665667666656", "output": "0000000000000000000000000000000000000000006000000000000030000010000900100009000030000000000000002006" }, { "input": "1\n0", "output": "0" } ]
1,699,017,997
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
n = int(input()) init_display = input() def add_button(y, n): added = '' for i in range(n): added += str((int(y[i]) + int(10 - int(y[0]))) % 10) return added min = add_button(init_display,n) for i in range(1,n): if int(add_button(init_display,n))<int(min): min = add_button(init_display,n) init_display=str((int(init_display) + (int(init_display) % 10) * (10 ** (n))) // 10) print(min)
Title: Secret Combination Time Limit: None seconds Memory Limit: None megabytes Problem Description: You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068. You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display. The second line contains *n* digits — the initial state of the display. Output Specification: Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. Demo Input: ['3\n579\n', '4\n2014\n'] Demo Output: ['024\n', '0142\n'] Note: none
```python n = int(input()) init_display = input() def add_button(y, n): added = '' for i in range(n): added += str((int(y[i]) + int(10 - int(y[0]))) % 10) return added min = add_button(init_display,n) for i in range(1,n): if int(add_button(init_display,n))<int(min): min = add_button(init_display,n) init_display=str((int(init_display) + (int(init_display) % 10) * (10 ** (n))) // 10) print(min) ```
0
313
A
Ilya and Bank Account
PROGRAMMING
900
[ "implementation", "number theory" ]
null
null
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
In a single line print an integer — the maximum state of the bank account that Ilya can get.
[ "2230\n", "-10\n", "-100003\n" ]
[ "2230\n", "0\n", "-10000\n" ]
In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
500
[ { "input": "2230", "output": "2230" }, { "input": "-10", "output": "0" }, { "input": "-100003", "output": "-10000" }, { "input": "544883178", "output": "544883178" }, { "input": "-847251738", "output": "-84725173" }, { "input": "423654797", "output": "423654797" }, { "input": "-623563697", "output": "-62356367" }, { "input": "645894116", "output": "645894116" }, { "input": "-384381709", "output": "-38438170" }, { "input": "437587210", "output": "437587210" }, { "input": "-297534606", "output": "-29753460" }, { "input": "891773002", "output": "891773002" }, { "input": "-56712976", "output": "-5671296" }, { "input": "963662765", "output": "963662765" }, { "input": "-272656295", "output": "-27265625" }, { "input": "383441522", "output": "383441522" }, { "input": "-477665112", "output": "-47766511" }, { "input": "791725034", "output": "791725034" }, { "input": "-812168727", "output": "-81216872" }, { "input": "528894922", "output": "528894922" }, { "input": "-479977172", "output": "-47997712" }, { "input": "568044564", "output": "568044564" }, { "input": "-392784794", "output": "-39278474" }, { "input": "925596634", "output": "925596634" }, { "input": "-836078769", "output": "-83607876" }, { "input": "71036059", "output": "71036059" }, { "input": "-337396162", "output": "-33739612" }, { "input": "87129297", "output": "87129297" }, { "input": "-648171877", "output": "-64817187" }, { "input": "20218400", "output": "20218400" }, { "input": "10", "output": "10" }, { "input": "1000000000", "output": "1000000000" }, { "input": "-1000000000", "output": "-100000000" }, { "input": "-102", "output": "-10" }, { "input": "-120", "output": "-10" }, { "input": "-20", "output": "0" }, { "input": "-15", "output": "-1" }, { "input": "-5575533", "output": "-557553" }, { "input": "-50", "output": "0" }, { "input": "-31", "output": "-1" }, { "input": "-55", "output": "-5" }, { "input": "-81", "output": "-1" }, { "input": "-99", "output": "-9" }, { "input": "-23", "output": "-2" }, { "input": "-41", "output": "-1" }, { "input": "-24", "output": "-2" }, { "input": "46", "output": "46" } ]
1,684,837,624
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
0
n=int(input()) print(max(n,n//10,(n//100)*100+abs(n%10)))
Title: Ilya and Bank Account Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. Input Specification: The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. Output Specification: In a single line print an integer — the maximum state of the bank account that Ilya can get. Demo Input: ['2230\n', '-10\n', '-100003\n'] Demo Output: ['2230\n', '0\n', '-10000\n'] Note: In the first test sample Ilya doesn't profit from using the present. In the second test sample you can delete digit 1 and get the state of the account equal to 0.
```python n=int(input()) print(max(n,n//10,(n//100)*100+abs(n%10))) ```
0
811
A
Vladik and Courtesy
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
[ "1 1\n", "7 6\n" ]
[ "Valera\n", "Vladik\n" ]
Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
500
[ { "input": "1 1", "output": "Valera" }, { "input": "7 6", "output": "Vladik" }, { "input": "25 38", "output": "Vladik" }, { "input": "8311 2468", "output": "Valera" }, { "input": "250708 857756", "output": "Vladik" }, { "input": "957985574 24997558", "output": "Valera" }, { "input": "999963734 999994456", "output": "Vladik" }, { "input": "1000000000 1000000000", "output": "Vladik" }, { "input": "946 879", "output": "Valera" }, { "input": "10819 45238", "output": "Vladik" }, { "input": "101357 236928", "output": "Vladik" }, { "input": "1033090 7376359", "output": "Vladik" }, { "input": "9754309 9525494", "output": "Valera" }, { "input": "90706344 99960537", "output": "Vladik" }, { "input": "965161805 908862070", "output": "Valera" }, { "input": "9 11", "output": "Valera" }, { "input": "3 2", "output": "Vladik" }, { "input": "6 6", "output": "Vladik" }, { "input": "4 4", "output": "Valera" }, { "input": "5 5", "output": "Valera" }, { "input": "5 4", "output": "Valera" }, { "input": "12345680 1", "output": "Valera" }, { "input": "9 10", "output": "Valera" }, { "input": "678 76687", "output": "Vladik" }, { "input": "1 678", "output": "Vladik" }, { "input": "45 1678", "output": "Vladik" }, { "input": "3 3", "output": "Vladik" }, { "input": "10 11", "output": "Valera" }, { "input": "2 1", "output": "Valera" }, { "input": "1 2", "output": "Vladik" }, { "input": "2 2", "output": "Vladik" }, { "input": "4 5", "output": "Valera" }, { "input": "9 6", "output": "Valera" }, { "input": "1 5", "output": "Vladik" }, { "input": "7 8", "output": "Vladik" }, { "input": "1000000000 999982505", "output": "Valera" }, { "input": "12 12", "output": "Vladik" }, { "input": "1000 950", "output": "Valera" }, { "input": "10 9", "output": "Valera" }, { "input": "100 9", "output": "Valera" }, { "input": "1000 996", "output": "Vladik" }, { "input": "9 5", "output": "Valera" } ]
1,694,190,808
748
PyPy 3
OK
TESTS
42
93
1,228,800
import sys input = sys.stdin.buffer.readline def process(a, b): for x in range(1, 10**5): if x*x > a: a_fail = x break for x in range(1, 10**5): if x*(x+1) > b: b_fail = x break if b_fail < a_fail: sys.stdout.write('Valera\n') else: sys.stdout.write('Vladik\n') return a, b = [int(x) for x in input().split()] process(a, b)
Title: Vladik and Courtesy Time Limit: None seconds Memory Limit: None megabytes Problem Description: At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Specification: Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. Output Specification: Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Demo Input: ['1 1\n', '7 6\n'] Demo Output: ['Valera\n', 'Vladik\n'] Note: Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python import sys input = sys.stdin.buffer.readline def process(a, b): for x in range(1, 10**5): if x*x > a: a_fail = x break for x in range(1, 10**5): if x*(x+1) > b: b_fail = x break if b_fail < a_fail: sys.stdout.write('Valera\n') else: sys.stdout.write('Vladik\n') return a, b = [int(x) for x in input().split()] process(a, b) ```
3
242
B
Big Segment
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1. Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment. It is guaranteed that no two segments coincide.
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input.
[ "3\n1 1\n2 2\n3 3\n", "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n" ]
[ "-1\n", "3\n" ]
none
1,000
[ { "input": "3\n1 1\n2 2\n3 3", "output": "-1" }, { "input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10", "output": "3" }, { "input": "4\n1 5\n2 2\n2 4\n2 5", "output": "1" }, { "input": "5\n3 3\n1 3\n2 2\n2 3\n1 2", "output": "2" }, { "input": "7\n7 7\n8 8\n3 7\n1 6\n1 7\n4 7\n2 8", "output": "-1" }, { "input": "3\n2 5\n3 4\n2 3", "output": "1" }, { "input": "16\n15 15\n8 12\n6 9\n15 16\n8 14\n3 12\n7 19\n9 13\n5 16\n9 17\n10 15\n9 14\n9 9\n18 19\n5 15\n6 19", "output": "-1" }, { "input": "9\n1 10\n7 8\n6 7\n1 4\n5 9\n2 8\n3 10\n1 1\n2 3", "output": "1" }, { "input": "1\n1 100000", "output": "1" }, { "input": "6\n2 2\n3 3\n3 5\n4 5\n1 1\n1 5", "output": "6" }, { "input": "33\n2 18\n4 14\n2 16\n10 12\n4 6\n9 17\n2 8\n4 12\n8 20\n1 10\n11 14\n11 17\n8 15\n3 16\n3 4\n6 9\n6 19\n4 17\n17 19\n6 16\n3 12\n1 7\n6 20\n8 16\n12 19\n1 3\n12 18\n6 11\n7 20\n16 18\n4 15\n3 15\n15 19", "output": "-1" }, { "input": "34\n3 8\n5 9\n2 9\n1 4\n3 7\n3 3\n8 9\n6 10\n4 7\n6 7\n5 8\n5 10\n1 5\n8 8\n2 5\n3 5\n7 7\n2 8\n4 5\n1 1\n7 9\n5 6\n2 3\n1 2\n2 4\n8 10\n7 8\n1 3\n4 8\n9 10\n1 7\n10 10\n2 2\n1 8", "output": "-1" }, { "input": "55\n3 4\n6 8\n9 10\n3 9\n9 9\n2 5\n4 8\n3 8\n8 10\n1 1\n4 9\n10 10\n6 6\n8 8\n1 8\n5 5\n4 5\n5 9\n2 2\n3 10\n4 6\n3 6\n1 6\n1 7\n6 10\n2 6\n3 7\n2 4\n4 4\n5 10\n1 4\n2 9\n1 3\n7 9\n7 8\n1 9\n1 10\n2 8\n8 9\n6 7\n1 2\n6 9\n7 7\n4 7\n3 3\n2 7\n4 10\n7 10\n2 3\n2 10\n5 7\n3 5\n5 8\n1 5\n5 6", "output": "37" }, { "input": "1\n999999999 1000000000", "output": "1" }, { "input": "3\n1 20\n2 22\n3 18", "output": "-1" }, { "input": "1\n1000000000 1000000000", "output": "1" }, { "input": "2\n100001 100008\n100005 100006", "output": "1" }, { "input": "1\n1000000 10000000", "output": "1" }, { "input": "3\n3 6\n2 4\n1 5", "output": "-1" }, { "input": "2\n3 5\n1 2", "output": "-1" } ]
1,596,295,132
2,147,483,647
Python 3
OK
TESTS
45
622
10,956,800
n = int(input()) L = [0]*n R = [0]*n for i in range(n): L[i], R[i] = map(int, input().split()) smallest = min(L) largest = max(R) for i in range(n): if L[i] == smallest and R[i] == largest: print(i+1) exit() print(-1)
Title: Big Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1. Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≤<=*c*<=≤<=*d*<=≤<=*b*. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment. It is guaranteed that no two segments coincide. Output Specification: Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input. Demo Input: ['3\n1 1\n2 2\n3 3\n', '6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n'] Demo Output: ['-1\n', '3\n'] Note: none
```python n = int(input()) L = [0]*n R = [0]*n for i in range(n): L[i], R[i] = map(int, input().split()) smallest = min(L) largest = max(R) for i in range(n): if L[i] == smallest and R[i] == largest: print(i+1) exit() print(-1) ```
3
776
A
A Serial Killer
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days. Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.
Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
[ "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n", "icm codeforces\n1\ncodeforces technex\n" ]
[ "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n", "icm codeforces\nicm technex\n" ]
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
500
[ { "input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler" }, { "input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex" }, { "input": "a b\n3\na c\nb d\nd e", "output": "a b\nc b\nc d\nc e" }, { "input": "ze udggmyop\n4\nze szhrbmft\nudggmyop mjorab\nszhrbmft ojdtfnzxj\nojdtfnzxj yjlkg", "output": "ze udggmyop\nszhrbmft udggmyop\nszhrbmft mjorab\nojdtfnzxj mjorab\nyjlkg mjorab" }, { "input": "q s\n10\nq b\nb j\ns g\nj f\nf m\ng c\nc a\nm d\nd z\nz o", "output": "q s\nb s\nj s\nj g\nf g\nm g\nm c\nm a\nd a\nz a\no a" }, { "input": "iii iiiiii\n7\niii iiiiiiiiii\niiiiiiiiii iiii\niiii i\niiiiii iiiiiiii\niiiiiiii iiiiiiiii\ni iiiii\niiiii ii", "output": "iii iiiiii\niiiiiiiiii iiiiii\niiii iiiiii\ni iiiiii\ni iiiiiiii\ni iiiiiiiii\niiiii iiiiiiiii\nii iiiiiiiii" }, { "input": "bwyplnjn zkms\n26\nzkms nzmcsytxh\nnzmcsytxh yujsb\nbwyplnjn gtbzhudpb\ngtbzhudpb hpk\nyujsb xvy\nhpk wrwnfokml\nwrwnfokml ndouuikw\nndouuikw ucgrja\nucgrja tgfmpldz\nxvy nycrfphn\nnycrfphn quvs\nquvs htdy\nhtdy k\ntgfmpldz xtdpkxm\nxtdpkxm suwqxs\nk fv\nsuwqxs qckllwy\nqckllwy diun\nfv lefa\nlefa gdoqjysx\ndiun dhpz\ngdoqjysx bdmqdyt\ndhpz dgz\ndgz v\nbdmqdyt aswy\naswy ydkayhlrnm", "output": "bwyplnjn zkms\nbwyplnjn nzmcsytxh\nbwyplnjn yujsb\ngtbzhudpb yujsb\nhpk yujsb\nhpk xvy\nwrwnfokml xvy\nndouuikw xvy\nucgrja xvy\ntgfmpldz xvy\ntgfmpldz nycrfphn\ntgfmpldz quvs\ntgfmpldz htdy\ntgfmpldz k\nxtdpkxm k\nsuwqxs k\nsuwqxs fv\nqckllwy fv\ndiun fv\ndiun lefa\ndiun gdoqjysx\ndhpz gdoqjysx\ndhpz bdmqdyt\ndgz bdmqdyt\nv bdmqdyt\nv aswy\nv ydkayhlrnm" }, { "input": "wxz hbeqwqp\n7\nhbeqwqp cpieghnszh\ncpieghnszh tlqrpd\ntlqrpd ttwrtio\nttwrtio xapvds\nxapvds zk\nwxz yryk\nzk b", "output": "wxz hbeqwqp\nwxz cpieghnszh\nwxz tlqrpd\nwxz ttwrtio\nwxz xapvds\nwxz zk\nyryk zk\nyryk b" }, { "input": "wced gnsgv\n23\ngnsgv japawpaf\njapawpaf nnvpeu\nnnvpeu a\na ddupputljq\nddupputljq qyhnvbh\nqyhnvbh pqwijl\nwced khuvs\nkhuvs bjkh\npqwijl ysacmboc\nbjkh srf\nsrf jknoz\njknoz hodf\nysacmboc xqtkoyh\nhodf rfp\nxqtkoyh bivgnwqvoe\nbivgnwqvoe nknf\nnknf wuig\nrfp e\ne bqqknq\nwuig sznhhhu\nbqqknq dhrtdld\ndhrtdld n\nsznhhhu bguylf", "output": "wced gnsgv\nwced japawpaf\nwced nnvpeu\nwced a\nwced ddupputljq\nwced qyhnvbh\nwced pqwijl\nkhuvs pqwijl\nbjkh pqwijl\nbjkh ysacmboc\nsrf ysacmboc\njknoz ysacmboc\nhodf ysacmboc\nhodf xqtkoyh\nrfp xqtkoyh\nrfp bivgnwqvoe\nrfp nknf\nrfp wuig\ne wuig\nbqqknq wuig\nbqqknq sznhhhu\ndhrtdld sznhhhu\nn sznhhhu\nn bguylf" }, { "input": "qqqqqqqqqq qqqqqqqq\n3\nqqqqqqqq qqqqqqqqq\nqqqqqqqqq qqqqq\nqqqqq q", "output": "qqqqqqqqqq qqqqqqqq\nqqqqqqqqqq qqqqqqqqq\nqqqqqqqqqq qqqqq\nqqqqqqqqqq q" }, { "input": "wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww", "output": "wwwww w\nwwwwwwww w\nwwwwwwwww w\nwwwwwwwwww w\nwwwwwwwwww www\nwwww www\nww www\nww wwwwww\nww wwwwwww" }, { "input": "k d\n17\nk l\nd v\nv z\nl r\nz i\nr s\ns p\np w\nw j\nj h\ni c\nh m\nm q\nc o\no g\nq x\nx n", "output": "k d\nl d\nl v\nl z\nr z\nr i\ns i\np i\nw i\nj i\nh i\nh c\nm c\nq c\nq o\nq g\nx g\nn g" } ]
1,590,008,814
2,147,483,647
Python 3
OK
TESTS
57
124
0
p1,p2 = input().split() n = int(input()) print(p1,p2) for i in range(n): killed,potential = input().split() if killed == p1: print(p2, potential) p1 = potential elif killed == p2: print(p1, potential) p2 = potential
Title: A Serial Killer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input Specification: First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days. Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Specification: Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Demo Input: ['ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n', 'icm codeforces\n1\ncodeforces technex\n'] Demo Output: ['ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n', 'icm codeforces\nicm technex\n'] Note: In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
```python p1,p2 = input().split() n = int(input()) print(p1,p2) for i in range(n): killed,potential = input().split() if killed == p1: print(p2, potential) p1 = potential elif killed == p2: print(p1, potential) p2 = potential ```
3
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,669,306,871
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
a=input() a=list(a) num_1=0 num_2=0 for i in range(len(a)-1): if num_1>=7 or num_2>=7: print('YES') break if a[i]=='1': num_1+=1 if a[i+1]=='0' and a[i]!=len(a): num_1=0 else: num_2+=1 if a[i+1]=='1' and a[i]!=len(a): num_2=0 if num_1<7 and num_2<7: 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 a=input() a=list(a) num_1=0 num_2=0 for i in range(len(a)-1): if num_1>=7 or num_2>=7: print('YES') break if a[i]=='1': num_1+=1 if a[i+1]=='0' and a[i]!=len(a): num_1=0 else: num_2+=1 if a[i+1]=='1' and a[i]!=len(a): num_2=0 if num_1<7 and num_2<7: print('NO') ```
0
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3" }, { "input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2", "output": "7\n7" }, { "input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1", "output": "7" }, { "input": "2 2\n8 4\n1\n1", "output": "2\n2" }, { "input": "1 5\n5\n1\n1\n1\n1\n1", "output": "1\n1\n1\n1\n1" }, { "input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4", "output": "1\n4\n3\n2\n3\n1\n1" }, { "input": "4 3\n9 1 7 1\n1\n4\n2", "output": "3\n1\n2" }, { "input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7", "output": "4\n3\n2" }, { "input": "1 1\n1\n1", "output": "1" } ]
1,667,913,341
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
4,915,200
n, m = map(int,input().split()) lst = [int(x) for x in input().split()] dp = [1]*n rev_lst = list(reversed(lst)) #print(rev_lst) for i in range(1,n): Flag = True for j in range(i): if rev_lst[j] == rev_lst[i]: dp[i] = dp[i-1] Flag = False if Flag: dp[i] = dp[i-1] + 1 #print(dp) rev_dp = list(reversed(dp)) #print(rev_dp) for i in range(m): l = int(input()) print(rev_dp[l-1])
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). Output Specification: Print *m* lines — on the *i*-th line print the answer to the number *l**i*. Demo Input: ['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n'] Demo Output: ['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n'] Note: none
```python n, m = map(int,input().split()) lst = [int(x) for x in input().split()] dp = [1]*n rev_lst = list(reversed(lst)) #print(rev_lst) for i in range(1,n): Flag = True for j in range(i): if rev_lst[j] == rev_lst[i]: dp[i] = dp[i-1] Flag = False if Flag: dp[i] = dp[i-1] + 1 #print(dp) rev_dp = list(reversed(dp)) #print(rev_dp) for i in range(m): l = int(input()) print(rev_dp[l-1]) ```
0
733
A
Grasshopper And the String
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump. Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability. The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
[ "ABABBBACFEYUKOTT\n", "AAA\n" ]
[ "4", "1" ]
none
500
[ { "input": "ABABBBACFEYUKOTT", "output": "4" }, { "input": "AAA", "output": "1" }, { "input": "A", "output": "1" }, { "input": "B", "output": "2" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU", "output": "39" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI", "output": "1" }, { "input": "KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVC", "output": "85" }, { "input": "QWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZ", "output": "18" }, { "input": "PKLKBWTXVJ", "output": "11" }, { "input": "CFHFPTGMOKXVLJJZJDQW", "output": "12" }, { "input": "TXULTFSBUBFLRNQORMMULWNVLPWTYJXZBPBGAWNX", "output": "9" }, { "input": "DAIUSEAUEUYUWEIOOEIOUYVYYOPEEWEBZOOOAOXUOIEUKYYOJOYAUYUUIYUXOUJLGIYEIIYUOCUAACRY", "output": "4" }, { "input": "VRPHBNWNWVWBWMFJJDCTJQJDJBKSJRZLVQRVVFLTZFSGCGDXCWQVWWWMFVCQHPKXXVRKTGWGPSMQTPKNDQJHNSKLXPCXDJDQDZZD", "output": "101" }, { "input": "SGDDFCDRDWGPNNFBBZZJSPXFYMZKPRXTCHVJSJJBWZXXQMDZBNKDHRGSRLGLRKPMWXNSXJPNJLDPXBSRCQMHJKPZNTPNTZXNPCJC", "output": "76" }, { "input": "NVTQVNLGWFDBCBKSDLTBGWBMNQZWZQJWNGVCTCQBGWNTYJRDBPZJHXCXFMIXNRGSTXHQPCHNFQPCMDZWJGLJZWMRRFCVLBKDTDSC", "output": "45" }, { "input": "SREZXQFVPQCLRCQGMKXCBRWKYZKWKRMZGXPMKWNMFZTRDPHJFCSXVPPXWKZMZTBFXGNLPLHZIPLFXNRRQFDTLFPKBGCXKTMCFKKT", "output": "48" }, { "input": "ICKJKMVPDNZPLKDSLTPZNRLSQSGHQJQQPJJSNHNWVDLJRLZEJSXZDPHYXGGWXHLCTVQSKWNWGTLJMOZVJNZPVXGVPJKHFVZTGCCX", "output": "47" }, { "input": "XXFPZDRPXLNHGDVCBDKJMKLGUQZXLLWYLOKFZVGXVNPJWZZZNRMQBRJCZTSDRHSNCVDMHKVXCXPCRBWSJCJWDRDPVZZLCZRTDRYA", "output": "65" }, { "input": "HDDRZDKCHHHEDKHZMXQSNQGSGNNSCCPVJFGXGNCEKJMRKSGKAPQWPCWXXWHLSMRGSJWEHWQCSJJSGLQJXGVTBYALWMLKTTJMFPFS", "output": "28" }, { "input": "PXVKJHXVDPWGLHWFWMJPMCCNHCKSHCPZXGIHHNMYNFQBUCKJJTXXJGKRNVRTQFDFMLLGPQKFOVNNLTNDIEXSARRJKGSCZKGGJCBW", "output": "35" }, { "input": "EXNMTTFPJLDHXDQBJJRDRYBZVFFHUDCHCPNFZWXSMZXNFVJGHZWXVBRQFNUIDVLZOVPXQNVMFNBTJDSCKRLNGXPSADTGCAHCBJKL", "output": "30" }, { "input": "NRNLSQQJGIJBCZFTNKJCXMGPARGWXPSHZXOBNSFOLDQVXTVAGJZNLXULHBRDGMNQKQGWMRRDPYCSNFVPUFTFBUBRXVJGNGSPJKLL", "output": "19" }, { "input": "SRHOKCHQQMVZKTCVQXJJCFGYFXGMBZSZFNAFETXILZHPGHBWZRZQFMGSEYRUDVMCIQTXTBTSGFTHRRNGNTHHWWHCTDFHSVARMCMB", "output": "30" }, { "input": "HBSVZHDKGNIRQUBYKYHUPJCEETGFMVBZJTHYHFQPFBVBSMQACYAVWZXSBGNKWXFNMQJFMSCHJVWBZXZGSNBRUHTHAJKVLEXFBOFB", "output": "34" }, { "input": "NXKMUGOPTUQNSRYTKUKSCWCRQSZKKFPYUMDIBJAHJCEKZJVWZAWOLOEFBFXLQDDPNNZKCQHUPBFVDSXSUCVLMZXQROYQYIKPQPWR", "output": "17" }, { "input": "TEHJDICFNOLQVQOAREVAGUAWODOCXJXIHYXFAEPEXRHPKEIIRCRIVASKNTVYUYDMUQKSTSSBYCDVZKDDHTSDWJWACPCLYYOXGCLT", "output": "15" }, { "input": "LCJJUZZFEIUTMSEXEYNOOAIZMORQDOANAMUCYTFRARDCYHOYOPHGGYUNOGNXUAOYSEMXAZOOOFAVHQUBRNGORSPNQWZJYQQUNPEB", "output": "9" }, { "input": "UUOKAOOJBXUTSMOLOOOOSUYYFTAVBNUXYFVOOGCGZYQEOYISIYOUULUAIJUYVVOENJDOCLHOSOHIHDEJOIGZNIXEMEGZACHUAQFW", "output": "5" }, { "input": "OUUBEHXOOURMOAIAEHXCUOIYHUJEVAWYRCIIAGDRIPUIPAIUYAIWJEVYEYYUYBYOGVYESUJCFOJNUAHIOOKBUUHEJFEWPOEOUHYA", "output": "4" }, { "input": "EMNOYEEUIOUHEWZITIAEZNCJUOUAOQEAUYEIHYUSUYUUUIAEDIOOERAEIRBOJIEVOMECOGAIAIUIYYUWYIHIOWVIJEYUEAFYULSE", "output": "5" }, { "input": "BVOYEAYOIEYOREJUYEUOEOYIISYAEOUYAAOIOEOYOOOIEFUAEAAESUOOIIEUAAGAEISIAPYAHOOEYUJHUECGOYEIDAIRTBHOYOYA", "output": "5" }, { "input": "GOIEOAYIEYYOOEOAIAEOOUWYEIOTNYAANAYOOXEEOEAVIOIAAIEOIAUIAIAAUEUAOIAEUOUUZYIYAIEUEGOOOOUEIYAEOSYAEYIO", "output": "3" }, { "input": "AUEAOAYIAOYYIUIOAULIOEUEYAIEYYIUOEOEIEYRIYAYEYAEIIMMAAEAYAAAAEOUICAUAYOUIAOUIAIUOYEOEEYAEYEYAAEAOYIY", "output": "3" }, { "input": "OAIIYEYYAOOEIUOEEIOUOIAEFIOAYETUYIOAAAEYYOYEYOEAUIIUEYAYYIIAOIEEYGYIEAAOOWYAIEYYYIAOUUOAIAYAYYOEUEOY", "output": "2" }, { "input": "EEEAOEOEEIOUUUEUEAAOEOIUYJEYAIYIEIYYEAUOIIYIUOOEUCYEOOOYYYIUUAYIAOEUEIEAOUOIAACAOOUAUIYYEAAAOOUYIAAE", "output": "2" }, { "input": "AYEYIIEUIYOYAYEUEIIIEUYUUAUEUIYAIAAUYONIEYIUIAEUUOUOYYOUUUIUIAEYEOUIIUOUUEOAIUUYAAEOAAEOYUUIYAYRAIII", "output": "2" }, { "input": "YOOAAUUAAAYEUYIUIUYIUOUAEIEEIAUEOAUIIAAIUYEUUOYUIYEAYAAAYUEEOEEAEOEEYYOUAEUYEEAIIYEUEYJOIIYUIOIUOIEE", "output": "2" }, { "input": "UYOIIIAYOOAIUUOOEEUYIOUAEOOEIOUIAIEYOAEAIOOEOOOIUYYUYIAAUIOUYYOOUAUIEYYUOAAUUEAAIEUIAUEUUIAUUOYOAYIU", "output": "1" }, { "input": "ABBABBB", "output": "4" }, { "input": "ABCD", "output": "4" }, { "input": "XXYC", "output": "3" }, { "input": "YYY", "output": "1" }, { "input": "ABABBBBBBB", "output": "8" }, { "input": "YYYY", "output": "1" }, { "input": "YYYYY", "output": "1" }, { "input": "AXXX", "output": "4" }, { "input": "YYYYYYY", "output": "1" }, { "input": "BYYBBB", "output": "4" }, { "input": "YYYYYYYYY", "output": "1" }, { "input": "CAAAAA", "output": "2" }, { "input": "CCCACCCC", "output": "5" }, { "input": "ABABBBACFEYUKOTTTT", "output": "5" }, { "input": "AABBYYYYYYYY", "output": "3" }, { "input": "BYBACYC", "output": "2" }, { "input": "Y", "output": "1" }, { "input": "ABBBBBB", "output": "7" }, { "input": "BACDYDI", "output": "3" }, { "input": "XEXXXXXXXXXXXXXXX", "output": "16" }, { "input": "TTYTT", "output": "3" }, { "input": "AAYBC", "output": "3" }, { "input": "ABABBBACFEYUKOTTTTT", "output": "6" }, { "input": "YYAYY", "output": "1" }, { "input": "YZZY", "output": "3" }, { "input": "YY", "output": "1" }, { "input": "ZZYZZ", "output": "3" }, { "input": "YBBBY", "output": "4" }, { "input": "BBBACCCCCCC", "output": "8" }, { "input": "YBBBBY", "output": "5" }, { "input": "YYYYYYYYYY", "output": "1" }, { "input": "ABABBBBBBBBBBBB", "output": "13" } ]
1,685,384,497
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
s = input() vowels = "AEIOUY" prev_i = -1 curr_i = -1 ans = 0 for i, ch in enumerate(s): if ch in vowels: prev_i = curr_i curr_i = i ans = max(ans, curr_i-prev_i) print(ans)
Title: Grasshopper And the String Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump. Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability. The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'. Input Specification: The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. Output Specification: Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. Demo Input: ['ABABBBACFEYUKOTT\n', 'AAA\n'] Demo Output: ['4', '1'] Note: none
```python s = input() vowels = "AEIOUY" prev_i = -1 curr_i = -1 ans = 0 for i, ch in enumerate(s): if ch in vowels: prev_i = curr_i curr_i = i ans = max(ans, curr_i-prev_i) print(ans) ```
0
0
none
none
none
0
[ "none" ]
null
null
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally: Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomial *P*(*x*) is valid if all the following conditions are satisfied: - *a**i* is integer for every *i*; - |*a**i*|<=≤<=*k* for every *i*; - *a**n*<=≠<=0. Limak has recently got a valid polynomial *P* with coefficients *a*0,<=*a*1,<=*a*2,<=...,<=*a**n*. He noticed that *P*(2)<=≠<=0 and he wants to change it. He is going to change one coefficient to get a valid polynomial *Q* of degree *n* that *Q*(2)<==<=0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*k*<=≤<=109) — the degree of the polynomial and the limit for absolute values of coefficients. The second line contains *n*<=+<=1 integers *a*0,<=*a*1,<=...,<=*a**n* (|*a**i*|<=≤<=*k*,<=*a**n*<=≠<=0) — describing a valid polynomial . It's guaranteed that *P*(2)<=≠<=0.
Print the number of ways to change one coefficient to get a valid polynomial *Q* that *Q*(2)<==<=0.
[ "3 1000000000\n10 -9 -3 5\n", "3 12\n10 -9 -3 5\n", "2 20\n14 -7 19\n" ]
[ "3\n", "2\n", "0\n" ]
In the first sample, we are given a polynomial *P*(*x*) = 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup>. Limak can change one coefficient in three ways: 1. He can set *a*<sub class="lower-index">0</sub> =  - 10. Then he would get *Q*(*x*) =  - 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) =  - 10 - 18 - 12 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">2</sub> =  - 8. Then *Q*(*x*) = 10 - 9*x* - 8*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 18 - 32 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">1</sub> =  - 19. Then *Q*(*x*) = 10 - 19*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 38 - 12 + 40 = 0. In the second sample, we are given the same polynomial. This time though, *k* is equal to 12 instead of 10<sup class="upper-index">9</sup>. Two first of ways listed above are still valid but in the third way we would get |*a*<sub class="lower-index">1</sub>| &gt; *k* what is not allowed. Thus, the answer is 2 this time.
0
[]
1,692,040,840
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1692040840.0840833")# 1692040840.084097
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials. He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally: Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomial *P*(*x*) is valid if all the following conditions are satisfied: - *a**i* is integer for every *i*; - |*a**i*|<=≤<=*k* for every *i*; - *a**n*<=≠<=0. Limak has recently got a valid polynomial *P* with coefficients *a*0,<=*a*1,<=*a*2,<=...,<=*a**n*. He noticed that *P*(2)<=≠<=0 and he wants to change it. He is going to change one coefficient to get a valid polynomial *Q* of degree *n* that *Q*(2)<==<=0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*k*<=≤<=109) — the degree of the polynomial and the limit for absolute values of coefficients. The second line contains *n*<=+<=1 integers *a*0,<=*a*1,<=...,<=*a**n* (|*a**i*|<=≤<=*k*,<=*a**n*<=≠<=0) — describing a valid polynomial . It's guaranteed that *P*(2)<=≠<=0. Output Specification: Print the number of ways to change one coefficient to get a valid polynomial *Q* that *Q*(2)<==<=0. Demo Input: ['3 1000000000\n10 -9 -3 5\n', '3 12\n10 -9 -3 5\n', '2 20\n14 -7 19\n'] Demo Output: ['3\n', '2\n', '0\n'] Note: In the first sample, we are given a polynomial *P*(*x*) = 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup>. Limak can change one coefficient in three ways: 1. He can set *a*<sub class="lower-index">0</sub> =  - 10. Then he would get *Q*(*x*) =  - 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) =  - 10 - 18 - 12 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">2</sub> =  - 8. Then *Q*(*x*) = 10 - 9*x* - 8*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 18 - 32 + 40 = 0. 1. Or he can set *a*<sub class="lower-index">1</sub> =  - 19. Then *Q*(*x*) = 10 - 19*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup> and indeed *Q*(2) = 10 - 38 - 12 + 40 = 0. In the second sample, we are given the same polynomial. This time though, *k* is equal to 12 instead of 10<sup class="upper-index">9</sup>. Two first of ways listed above are still valid but in the third way we would get |*a*<sub class="lower-index">1</sub>| &gt; *k* what is not allowed. Thus, the answer is 2 this time.
```python print("_RANDOM_GUESS_1692040840.0840833")# 1692040840.084097 ```
0
441
B
Valera and Fruits
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat). Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree.
Print a single integer — the maximum number of fruit that Valera can collect.
[ "2 3\n1 5\n2 3\n", "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n" ]
[ "8\n", "60\n" ]
In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
1,000
[ { "input": "2 3\n1 5\n2 3", "output": "8" }, { "input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60" }, { "input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202", "output": "10596" }, { "input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426", "output": "4740" }, { "input": "2 1500\n2 575\n1 2522", "output": "3097" }, { "input": "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\n9 772", "output": "18465" }, { "input": "24 1524\n16 934\n23 1940\n21 1447\n20 417\n24 1340\n22 1932\n13 775\n19 2918\n12 2355\n9 593\n11 2676\n3 1857\n16 868\n13 426\n18 1679\n22 991\n9 2728\n10 2497\n16 1221\n9 772\n23 2522\n24 982\n12 1431\n18 757", "output": "25893" }, { "input": "1 10\n3000 30", "output": "20" }, { "input": "2 1\n30 3\n31 2", "output": "3" }, { "input": "4 2061\n1 426\n3 2522\n1 772\n1 1447", "output": "5167" }, { "input": "2 1\n1 1\n1 1", "output": "2" }, { "input": "1 10\n3000 20", "output": "20" }, { "input": "1 1000\n3000 2000", "output": "2000" }, { "input": "2 100\n3000 100\n3000 100", "output": "200" }, { "input": "2 3\n1 6\n3 6", "output": "12" }, { "input": "1 40\n3000 42", "output": "42" }, { "input": "1 100\n3000 200", "output": "200" }, { "input": "1 50\n3000 100", "output": "100" }, { "input": "1 1\n3000 2", "output": "2" }, { "input": "2 3000\n3000 3000\n3000 3000", "output": "6000" }, { "input": "2 2\n2999 3\n3000 2", "output": "5" }, { "input": "1 2\n3000 3", "output": "3" }, { "input": "2 5\n2999 10\n3000 5", "output": "15" }, { "input": "1 3\n5 3", "output": "3" }, { "input": "2 1000\n2999 2000\n3000 1000", "output": "3000" }, { "input": "1 5\n3000 10", "output": "10" }, { "input": "1 10\n3000 15", "output": "15" }, { "input": "5 1\n10 100\n2698 100\n200 100\n3000 100\n1500 100", "output": "10" }, { "input": "1 1\n3000 3000", "output": "2" }, { "input": "2 10\n2999 100\n3000 100", "output": "30" }, { "input": "1 10\n3000 100", "output": "20" } ]
1,626,722,697
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
25
77
7,168,000
n, v = map(int, input().split()) d = {} for i in range(n): a,b = map(int, input().split()) if a in d : d[a] += b else : d[a] = b c = 0 for i in range(1, n+2): quota = v if i-1 in d : if quota>d[i-1]: c += d[i-1] quota -= d[i-1] d[i-1] = 0 else : c += quota d[i-1] -= quota quota = 0 if i in d : if quota>d[i]: c += d[i] quota -= d[i] d[i] = 0 else : c += quota d[i] -= quota quota = 0 # print(i, d, c) print(c)
Title: Valera and Fruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat). Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well? Input Specification: The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree. Output Specification: Print a single integer — the maximum number of fruit that Valera can collect. Demo Input: ['2 3\n1 5\n2 3\n', '5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n'] Demo Output: ['8\n', '60\n'] Note: In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
```python n, v = map(int, input().split()) d = {} for i in range(n): a,b = map(int, input().split()) if a in d : d[a] += b else : d[a] = b c = 0 for i in range(1, n+2): quota = v if i-1 in d : if quota>d[i-1]: c += d[i-1] quota -= d[i-1] d[i-1] = 0 else : c += quota d[i-1] -= quota quota = 0 if i in d : if quota>d[i]: c += d[i] quota -= d[i] d[i] = 0 else : c += quota d[i] -= quota quota = 0 # print(i, d, c) print(c) ```
0