Dataset Viewer
Auto-converted to Parquet Duplicate
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
604
A
Uncowed Forces
PROGRAMMING
1,000
[ "implementation" ]
null
null
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score. Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack. All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.
The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≀<=*m**i*<=≀<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted. The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≀<=*w**i*<=≀<=10) is Kevin's number of wrong submissions on problem *i*. The last line contains two space-separated integers *h**s* and *h**u* (0<=≀<=*h**s*,<=*h**u*<=≀<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.
Print a single integer, the value of Kevin's final score.
[ "20 40 60 80 100\n0 1 2 3 4\n1 0\n", "119 119 119 119 119\n0 0 0 0 0\n10 0\n" ]
[ "4900\n", "4930\n" ]
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10Β·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.
500
[ { "input": "20 40 60 80 100\n0 1 2 3 4\n1 0", "output": "4900" }, { "input": "119 119 119 119 119\n0 0 0 0 0\n10 0", "output": "4930" }, { "input": "3 6 13 38 60\n6 10 10 3 8\n9 9", "output": "5088" }, { "input": "21 44 11 68 75\n6 2 4 8 4\n2 8", "output": "4522" }, {...
1,629,089,355
2,147,483,647
Python 3
OK
TESTS
57
77
6,963,200
def score(x,m,w): t=(1-(m/250))*x - (50*w) return max(0.3*x,t) sl=[500,1000,1500,2000,2500] m=list(map(int, input().split())) w=list(map(int, input().split())) s,u=map(int,input().split()) res=0 for i in range(5): res+=score(sl[i],m[i],w[i]) res+=(100*s) res-=(50*u) print(int(res))
Title: Uncowed Forces Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score. Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack. All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer. Input Specification: The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≀<=*m**i*<=≀<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted. The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≀<=*w**i*<=≀<=10) is Kevin's number of wrong submissions on problem *i*. The last line contains two space-separated integers *h**s* and *h**u* (0<=≀<=*h**s*,<=*h**u*<=≀<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively. Output Specification: Print a single integer, the value of Kevin's final score. Demo Input: ['20 40 60 80 100\n0 1 2 3 4\n1 0\n', '119 119 119 119 119\n0 0 0 0 0\n10 0\n'] Demo Output: ['4900\n', '4930\n'] Note: In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10Β·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.
```python def score(x,m,w): t=(1-(m/250))*x - (50*w) return max(0.3*x,t) sl=[500,1000,1500,2000,2500] m=list(map(int, input().split())) w=list(map(int, input().split())) s,u=map(int,input().split()) res=0 for i in range(5): res+=score(sl[i],m[i],w[i]) res+=(100*s) res-=(50*u) print(int(res)) ```
3
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "...
1,697,612,339
2,147,483,647
Python 3
OK
TESTS
25
92
0
s=str(input()) s=list(s) a=s[0] a=a.upper() s[0]=a y="".join(s) print(y)
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input Specification: A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. Output Specification: Output the given word after capitalization. Demo Input: ['ApPLe\n', 'konjac\n'] Demo Output: ['ApPLe\n', 'Konjac\n'] Note: none
```python s=str(input()) s=list(s) a=s[0] a=a.upper() s[0]=a y="".join(s) print(y) ```
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 9...
1,372,488,972
672
Python 3
OK
TESTS
40
78
102,400
def f(x): return x // 3 r, g, b = map(int, input().split()) m = min(r, g, b) ans = 0 for i in range(max(0, m - 30), m + 1): ans = max(ans, i + f(r - i) + f(g - i) + f(b - i)) print(ans)
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 def f(x): return x // 3 r, g, b = map(int, input().split()) m = min(r, g, b) ans = 0 for i in range(max(0, m - 30), m + 1): ans = max(ans, i + f(r - i) + f(g - i) + f(b - i)) print(ans) ```
3
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,462,986,086
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
x , s = int(input()) , input() first , last , rr= s.find('R'|'L') , s.rfind('R'|'L') , s.rfind('R') if(str[first] == 'R' && str[last] == 'R'): print(first +1 , last+1) elif(str[first] == 'L' && str[last] == 'L'): print(last+1 , first+1) elif(str[first] == 'R' && str[last] == 'L'): print(first +1 , rr+1) #nums = [1 , 2 , 3 , 4]; #def ss(nums): # return sum(x**2 for x in nums) #print ( ss(nums) )
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 x , s = int(input()) , input() first , last , rr= s.find('R'|'L') , s.rfind('R'|'L') , s.rfind('R') if(str[first] == 'R' && str[last] == 'R'): print(first +1 , last+1) elif(str[first] == 'L' && str[last] == 'L'): print(last+1 , first+1) elif(str[first] == 'R' && str[last] == 'L'): print(first +1 , rr+1) #nums = [1 , 2 , 3 , 4]; #def ss(nums): # return sum(x**2 for x in nums) #print ( ss(nums) ) ```
-1
804
B
Minimum number of steps
PROGRAMMING
1,400
[ "combinatorics", "greedy", "implementation", "math" ]
null
null
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<=7. The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Print the minimum number of steps modulo 109<=+<=7.
[ "ab\n", "aab\n" ]
[ "1\n", "3\n" ]
The first example: "ab"  →  "bba". The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".
1,000
[ { "input": "ab", "output": "1" }, { "input": "aab", "output": "3" }, { "input": "aaaaabaabababaaaaaba", "output": "17307" }, { "input": "abaabaaabbabaabab", "output": "1795" }, { "input": "abbaa", "output": "2" }, { "input": "abbaaabaabaaaaabbbbaababaa...
1,609,661,478
2,147,483,647
PyPy 3
OK
TESTS
32
218
6,348,800
import math as m t=1 #t=int(input()) mod=10**9+7 while t: t-=1 s=input() ans,cost=0,0 for i in range(len(s)): if s[i]=='a': cost=(cost*2+1)%mod else : ans+=cost print(ans%mod)
Title: Minimum number of steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<=7. The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string. Input Specification: The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. Output Specification: Print the minimum number of steps modulo 109<=+<=7. Demo Input: ['ab\n', 'aab\n'] Demo Output: ['1\n', '3\n'] Note: The first example: "ab"  →  "bba". The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".
```python import math as m t=1 #t=int(input()) mod=10**9+7 while t: t-=1 s=input() ans,cost=0,0 for i in range(len(s)): if s[i]=='a': cost=(cost*2+1)%mod else : ans+=cost print(ans%mod) ```
3
189
A
Cut Ribbon
PROGRAMMING
1,300
[ "brute force", "dp" ]
null
null
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting.
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≀<=*n*,<=*a*,<=*b*,<=*c*<=≀<=4000) β€” the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Print a single number β€” the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
[ "5 5 3 2\n", "7 5 5 2\n" ]
[ "2\n", "2\n" ]
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
500
[ { "input": "5 5 3 2", "output": "2" }, { "input": "7 5 5 2", "output": "2" }, { "input": "4 4 4 4", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "4000 1 2 3", "output": "4000" }, { "input": "4000 3 4 5", "output": "1333" }, ...
1,695,169,299
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
46
102,400
n,a,b,c=input().split() n,a,b,c=int(n),int(a),int(b),int(c) numbers=[a,b,c] numbers.sort() a_div=0 b_div=0 c_div=0 n_org=n if n%a==0: a_div=n//a if n%b==0: b_div=n//b if n%c==0: c_div=n//c count=0 count_1=0 count_2=0 count_3=0 diff_1=0 div_2=1 div_3=2 turn=False s=1 final=0 while(n>0): count+=1 n-=numbers[diff_1] if n%numbers[div_2]==0: count_1=count count_1+=n//numbers[div_2] elif n%numbers[div_3]==0: count_2=count count_2+=n//numbers[div_3] elif n%(numbers[div_3]+numbers[div_2])==0: count_3=count count_3+=(n//(numbers[div_3]+numbers[div_2]))*2 if n<=0: n=n_org count=0 final=max(final,count_3,count_2,count_1) if s==1: diff_1=1 div_2=0 s+=1 elif s==2: diff_1=2 div_2=1 div_3=0 s+=1 else: break print(max(final,a_div,c_div,b_div))
Title: Cut Ribbon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting. Input Specification: The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≀<=*n*,<=*a*,<=*b*,<=*c*<=≀<=4000) β€” the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. Output Specification: Print a single number β€” the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. Demo Input: ['5 5 3 2\n', '7 5 5 2\n'] Demo Output: ['2\n', '2\n'] Note: In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
```python n,a,b,c=input().split() n,a,b,c=int(n),int(a),int(b),int(c) numbers=[a,b,c] numbers.sort() a_div=0 b_div=0 c_div=0 n_org=n if n%a==0: a_div=n//a if n%b==0: b_div=n//b if n%c==0: c_div=n//c count=0 count_1=0 count_2=0 count_3=0 diff_1=0 div_2=1 div_3=2 turn=False s=1 final=0 while(n>0): count+=1 n-=numbers[diff_1] if n%numbers[div_2]==0: count_1=count count_1+=n//numbers[div_2] elif n%numbers[div_3]==0: count_2=count count_2+=n//numbers[div_3] elif n%(numbers[div_3]+numbers[div_2])==0: count_3=count count_3+=(n//(numbers[div_3]+numbers[div_2]))*2 if n<=0: n=n_org count=0 final=max(final,count_3,count_2,count_1) if s==1: diff_1=1 div_2=0 s+=1 elif s==2: diff_1=2 div_2=1 div_3=0 s+=1 else: break print(max(final,a_div,c_div,b_div)) ```
0
622
A
Infinite Sequence
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the *n*-th position of the sequence.
The only line contains integer *n* (1<=≀<=*n*<=≀<=1014) β€” the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Print the element in the *n*-th position of the sequence (the elements are numerated from one).
[ "3\n", "5\n", "10\n", "55\n", "56\n" ]
[ "2\n", "2\n", "4\n", "10\n", "1\n" ]
none
0
[ { "input": "3", "output": "2" }, { "input": "5", "output": "2" }, { "input": "10", "output": "4" }, { "input": "55", "output": "10" }, { "input": "56", "output": "1" }, { "input": "1000000000000", "output": "88209" }, { "input": "8471941278...
1,598,660,208
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
0
n = int(input()) s = 0 i = 0 while s <= n: i += 1 s += i #print(s) s-=i #print(s) if s == n: print(i-1) else: ans = n-s print(ans)
Title: Infinite Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one). Find the number on the *n*-th position of the sequence. Input Specification: The only line contains integer *n* (1<=≀<=*n*<=≀<=1014) β€” the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Output Specification: Print the element in the *n*-th position of the sequence (the elements are numerated from one). Demo Input: ['3\n', '5\n', '10\n', '55\n', '56\n'] Demo Output: ['2\n', '2\n', '4\n', '10\n', '1\n'] Note: none
```python n = int(input()) s = 0 i = 0 while s <= n: i += 1 s += i #print(s) s-=i #print(s) if s == n: print(i-1) else: ans = n-s print(ans) ```
0
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\n...
1,576,631,314
2,147,483,647
Python 3
OK
TESTS
57
124
204,800
s = ' '+input()+' ' n = int(input()) print(s[1:-1]) for i in range(n): l,r = input().split() s = s.replace(' '+l+' ',' '+r+' ') print(s[1:-1])
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 s = ' '+input()+' ' n = int(input()) print(s[1:-1]) for i in range(n): l,r = input().split() s = s.replace(' '+l+' ',' '+r+' ') print(s[1:-1]) ```
3
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (Γ·) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
In the only line of input there is an integer *n* (3<=≀<=*n*<=≀<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "ou...
1,650,187,539
2,147,483,647
PyPy 3-64
OK
TESTS
26
61
512,000
from math import gcd n=int(input()) #print(gcd(1,0)) a=0 u=[] for i in range(1,n+1): if gcd(a+i,n-i)==1: u.append([a+i,n-i]) print(*u[(len(u)//2)-1])
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (Γ·) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. Input Specification: In the only line of input there is an integer *n* (3<=≀<=*n*<=≀<=1000), the sum of numerator and denominator of the fraction. Output Specification: Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. Demo Input: ['3\n', '4\n', '12\n'] Demo Output: ['1 2\n', '1 3\n', '5 7\n'] Note: none
```python from math import gcd n=int(input()) #print(gcd(1,0)) a=0 u=[] for i in range(1,n+1): if gcd(a+i,n-i)==1: u.append([a+i,n-i]) print(*u[(len(u)//2)-1]) ```
3
913
A
Modular Exponentiation
PROGRAMMING
900
[ "implementation", "math" ]
null
null
The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2Β·2Β·...Β·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=108). The second line contains a single integer *m* (1<=≀<=*m*<=≀<=108).
Output a single integerΒ β€” the value of .
[ "4\n42\n", "1\n58\n", "98765432\n23456789\n" ]
[ "10\n", "0\n", "23456789\n" ]
In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10. In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0.
500
[ { "input": "4\n42", "output": "10" }, { "input": "1\n58", "output": "0" }, { "input": "98765432\n23456789", "output": "23456789" }, { "input": "8\n88127381", "output": "149" }, { "input": "32\n92831989", "output": "92831989" }, { "input": "92831989\n25...
1,649,596,654
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
45,977,600
if __name__ == "__main__": a,b = int(input()),int(input()) print(b%(pow(2,a)))
Title: Modular Exponentiation Time Limit: None seconds Memory Limit: None megabytes Problem Description: The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2Β·2Β·...Β·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate Input Specification: The first line contains a single integer *n* (1<=≀<=*n*<=≀<=108). The second line contains a single integer *m* (1<=≀<=*m*<=≀<=108). Output Specification: Output a single integerΒ β€” the value of . Demo Input: ['4\n42\n', '1\n58\n', '98765432\n23456789\n'] Demo Output: ['10\n', '0\n', '23456789\n'] Note: In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10. In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0.
```python if __name__ == "__main__": a,b = int(input()),int(input()) print(b%(pow(2,a))) ```
0
317
A
Perfect Pair
PROGRAMMING
1,600
[ "brute force" ]
null
null
Let us call a pair of integer numbers *m*-perfect, if at least one number in the pair is greater than or equal to *m*. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not. Two integers *x*, *y* are written on the blackboard. It is allowed to erase one of them and replace it with the sum of the numbers, (*x*<=+<=*y*). What is the minimum number of such operations one has to perform in order to make the given pair of integers *m*-perfect?
Single line of the input contains three integers *x*, *y* and *m* (<=-<=1018<=≀<=*x*, *y*, *m*<=≀<=1018). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preffered to use the cin, cout streams or the %I64d specifier.
Print the minimum number of operations or "-1" (without quotes), if it is impossible to transform the given pair to the *m*-perfect one.
[ "1 2 5\n", "-1 4 15\n", "0 -1 5\n" ]
[ "2\n", "4\n", "-1\n" ]
In the first sample the following sequence of operations is suitable: (1, 2) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (3, 2) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (5, 2). In the second sample: (-1, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (3, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (7, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (11, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (15, 4). Finally, in the third sample *x*, *y* cannot be made positive, hence there is no proper sequence of operations.
500
[ { "input": "1 2 5", "output": "2" }, { "input": "-1 4 15", "output": "4" }, { "input": "0 -1 5", "output": "-1" }, { "input": "0 1 8", "output": "5" }, { "input": "-134 -345 -134", "output": "0" }, { "input": "-134 -345 -133", "output": "-1" }, ...
1,578,833,350
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
278
0
a , b ,m = map(int,input().split()) if max(a,b)==0: print(-1) else: c=0 while max(a,b)<m: if a>b: b = a+b else: a = a+b c+=1 if max(a,b)>=m: print(c)
Title: Perfect Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let us call a pair of integer numbers *m*-perfect, if at least one number in the pair is greater than or equal to *m*. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not. Two integers *x*, *y* are written on the blackboard. It is allowed to erase one of them and replace it with the sum of the numbers, (*x*<=+<=*y*). What is the minimum number of such operations one has to perform in order to make the given pair of integers *m*-perfect? Input Specification: Single line of the input contains three integers *x*, *y* and *m* (<=-<=1018<=≀<=*x*, *y*, *m*<=≀<=1018). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preffered to use the cin, cout streams or the %I64d specifier. Output Specification: Print the minimum number of operations or "-1" (without quotes), if it is impossible to transform the given pair to the *m*-perfect one. Demo Input: ['1 2 5\n', '-1 4 15\n', '0 -1 5\n'] Demo Output: ['2\n', '4\n', '-1\n'] Note: In the first sample the following sequence of operations is suitable: (1, 2) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (3, 2) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (5, 2). In the second sample: (-1, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (3, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (7, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (11, 4) <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> (15, 4). Finally, in the third sample *x*, *y* cannot be made positive, hence there is no proper sequence of operations.
```python a , b ,m = map(int,input().split()) if max(a,b)==0: print(-1) else: c=0 while max(a,b)<m: if a>b: b = a+b else: a = a+b c+=1 if max(a,b)>=m: print(c) ```
0
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,578,716,707
2,147,483,647
Python 3
OK
TESTS
30
248
0
p=0 c='' s=input() for i in range(len(s)): if p==0: if s[i]=='.': c+='0' elif s[i+1]=='.': c+='1' p=1 else: c+='2' p=1 else: p=0 print(c)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. Input Specification: The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). Output Specification: Output the decoded ternary number. It can have leading zeroes. Demo Input: ['.-.--\n', '--.\n', '-..-.--\n'] Demo Output: ['012', '20', '1012'] Note: none
```python p=0 c='' s=input() for i in range(len(s)): if p==0: if s[i]=='.': c+='0' elif s[i+1]=='.': c+='1' p=1 else: c+='2' p=1 else: p=0 print(c) ```
3.938
808
D
Array Division
PROGRAMMING
1,900
[ "binary search", "data structures", "implementation" ]
null
null
Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position?
The first line contains single integer *n* (1<=≀<=*n*<=≀<=100000) β€” the size of the array. The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≀<=*a**i*<=≀<=109) β€” the elements of the array.
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
[ "3\n1 3 2\n", "5\n1 2 3 4 5\n", "5\n2 2 3 4 5\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
0
[ { "input": "3\n1 3 2", "output": "YES" }, { "input": "5\n1 2 3 4 5", "output": "NO" }, { "input": "5\n2 2 3 4 5", "output": "YES" }, { "input": "5\n72 32 17 46 82", "output": "NO" }, { "input": "6\n26 10 70 11 69 57", "output": "NO" }, { "input": "7\n4...
1,659,599,404
2,147,483,647
PyPy 3-64
OK
TESTS
115
108
18,022,400
n = int(input()) arr = list(map(int, input().split())) def solve(n, a): s = sum(a) if n == 1 or s & 1: print('NO') return half = s // 2 def judge(a): pre, st = 0, {0} for num in a: st.add(num) pre += num if pre - half in st: return True return False print('YES' if judge(a) or judge(a[::-1]) else 'NO') solve(n, arr)
Title: Array Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position? Input Specification: The first line contains single integer *n* (1<=≀<=*n*<=≀<=100000) β€” the size of the array. The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≀<=*a**i*<=≀<=109) β€” the elements of the array. Output Specification: Print YES if Vasya can divide the array after moving one element. Otherwise print NO. Demo Input: ['3\n1 3 2\n', '5\n1 2 3 4 5\n', '5\n2 2 3 4 5\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left.
```python n = int(input()) arr = list(map(int, input().split())) def solve(n, a): s = sum(a) if n == 1 or s & 1: print('NO') return half = s // 2 def judge(a): pre, st = 0, {0} for num in a: st.add(num) pre += num if pre - half in st: return True return False print('YES' if judge(a) or judge(a[::-1]) else 'NO') solve(n, arr) ```
3
750
A
New Year and Hurry
PROGRAMMING
800
[ "binary search", "brute force", "implementation", "math" ]
null
null
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5Β·*i* minutes to solve the *i*-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party?
The only line of the input contains two integers *n* and *k* (1<=≀<=*n*<=≀<=10, 1<=≀<=*k*<=≀<=240)Β β€” the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
[ "3 222\n", "4 190\n", "7 1\n" ]
[ "2\n", "4\n", "7\n" ]
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
500
[ { "input": "3 222", "output": "2" }, { "input": "4 190", "output": "4" }, { "input": "7 1", "output": "7" }, { "input": "10 135", "output": "6" }, { "input": "10 136", "output": "5" }, { "input": "1 1", "output": "1" }, { "input": "1 240", ...
1,678,031,962
2,147,483,647
PyPy 3-64
OK
TESTS
52
62
0
inp = input().split() lis = [eval(i) for i in inp] k = lis[1] n = 5 a,b=0,lis[0] for i in range(lis[0]): if(k<240 and k+((i+1)*5)<=240): k+=n n+=5 else:break a=i+1 print(int(a))
Title: New Year and Hurry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5Β·*i* minutes to solve the *i*-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party? Input Specification: The only line of the input contains two integers *n* and *k* (1<=≀<=*n*<=≀<=10, 1<=≀<=*k*<=≀<=240)Β β€” the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. Output Specification: Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. Demo Input: ['3 222\n', '4 190\n', '7 1\n'] Demo Output: ['2\n', '4\n', '7\n'] Note: In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.
```python inp = input().split() lis = [eval(i) for i in inp] k = lis[1] n = 5 a,b=0,lis[0] for i in range(lis[0]): if(k<240 and k+((i+1)*5)<=240): k+=n n+=5 else:break a=i+1 print(int(a)) ```
3
433
B
Kuriyama Mirai's Stones
PROGRAMMING
1,200
[ "dp", "implementation", "sortings" ]
null
null
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r*Β (1<=≀<=*l*<=≀<=*r*<=≀<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r*Β (1<=≀<=*l*<=≀<=*r*<=≀<=*n*), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.
The first line contains an integer *n*Β (1<=≀<=*n*<=≀<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n*Β (1<=≀<=*v**i*<=≀<=109) β€” costs of the stones. The third line contains an integer *m*Β (1<=≀<=*m*<=≀<=105) β€” the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r*Β (1<=≀<=*l*<=≀<=*r*<=≀<=*n*;Β 1<=≀<=*type*<=≀<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.
Print *m* lines. Each line must contain an integer β€” the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
[ "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n" ]
[ "24\n9\n28\n", "10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n" ]
Please note that the answers to the questions may overflow 32-bit integer type.
1,500
[ { "input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "output": "24\n9\n28" }, { "input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5" }, { "input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1...
1,672,039,090
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
# Wadea # s = int(input()) l = list(map(int, input().split())) l1 = l[:] ; l1.sort() for i in range(1,s): l[i]+=l[i-1] l1[i]+=l1[i-1] n = int(input()) for j in range(n): a,b,c = map(int ,input().split()) b -= 1 c -= 1 if a == 1: if b == 0: print(l[c]) else: print(l[c]-l[b-1]) elif a == 2: if b == 0: print(l[c]) else: print(l1[c]-l1[b-1])
Title: Kuriyama Mirai's Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r*Β (1<=≀<=*l*<=≀<=*r*<=≀<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r*Β (1<=≀<=*l*<=≀<=*r*<=≀<=*n*), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy. Input Specification: The first line contains an integer *n*Β (1<=≀<=*n*<=≀<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n*Β (1<=≀<=*v**i*<=≀<=109) β€” costs of the stones. The third line contains an integer *m*Β (1<=≀<=*m*<=≀<=105) β€” the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r*Β (1<=≀<=*l*<=≀<=*r*<=≀<=*n*;Β 1<=≀<=*type*<=≀<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one. Output Specification: Print *m* lines. Each line must contain an integer β€” the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. Demo Input: ['6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n', '4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n'] Demo Output: ['24\n9\n28\n', '10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n'] Note: Please note that the answers to the questions may overflow 32-bit integer type.
```python # Wadea # s = int(input()) l = list(map(int, input().split())) l1 = l[:] ; l1.sort() for i in range(1,s): l[i]+=l[i-1] l1[i]+=l1[i-1] n = int(input()) for j in range(n): a,b,c = map(int ,input().split()) b -= 1 c -= 1 if a == 1: if b == 0: print(l[c]) else: print(l[c]-l[b-1]) elif a == 2: if b == 0: print(l[c]) else: print(l1[c]-l1[b-1]) ```
0
982
E
Billiard
PROGRAMMING
2,600
[ "geometry", "number theory" ]
null
null
Consider a [billiard table](https://en.wikipedia.org/wiki/Billiard_table) of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture). There is one ball at the point $(x, y)$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $45^{\circ}$ angle with them. We will assume that: 1. the angles between the directions of the ball before and after a collision with a side are equal, 1. the ball moves indefinitely long, it only stops when it falls into a pocket, 1. the ball can be considered as a point, it falls into a pocket if and only if its coordinates coincide with one of the pockets, 1. initially the ball is not in a pocket. Note that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side. Your task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be.
The only line contains $6$ integers $n$, $m$, $x$, $y$, $v_x$, $v_y$ ($1 \leq n, m \leq 10^9$, $0 \leq x \leq n$; $0 \leq y \leq m$; $-1 \leq v_x, v_y \leq 1$; $(v_x, v_y) \neq (0, 0)$)Β β€” the width of the table, the length of the table, the $x$-coordinate of the initial position of the ball, the $y$-coordinate of the initial position of the ball, the $x$-component of its initial speed and the $y$-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket.
Print the coordinates of the pocket the ball will fall into, or $-1$ if the ball will move indefinitely.
[ "4 3 2 2 -1 1\n", "4 4 2 0 1 1\n", "10 10 10 1 -1 0\n" ]
[ "0 0", "-1", "-1" ]
The first sample: The second sample: In the third sample the ball will never change its $y$ coordinate, so the ball will never fall into a pocket.
2,500
[ { "input": "4 3 2 2 -1 1", "output": "0 0" }, { "input": "4 4 2 0 1 1", "output": "-1" }, { "input": "10 10 10 1 -1 0", "output": "-1" }, { "input": "1000000000 1000000000 1 1000000000 0 1", "output": "-1" }, { "input": "2 1 1 0 -1 -1", "output": "0 1" }, ...
1,625,683,637
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
from sys import argv from math import trunc def Billiard_Table(n, m, x, y, vx, vy): if vx == 0: #vertical motion if vy == 0: #the ball is not moving return -1 if x == 0: #motion occurs along the left side of the billiard table if vy > 0: #motion is vertical upwards return 0, n #the ball falls in the top left hole elif vy < 0: #motion is vertical downwards return 0, 0 #the ball falls in the bottom left hole elif x == m: #motion occurs along the right side of the billiard table if vy > 0: #motion is vertical upwards return m, 0 #the ball falls in the bottom right hole elif vy < 0: #motion is vertical downwards return m, n #the ball falls in the top right hole else: return -1 #the ball yeeps bouncing indefinitely between the top and bottom sides if vy == 0: #horizontal motion if y == 0: #motion occurs along the bottom side of the table if vx > 0: #motion is oriented to the right return m, 0 #the ball falls in the bottom right hole elif vx < 0: #motion is oriented to the left return 0, 0 #the ball falls in the bottom left hole elif y == n: #motion occurs along the top side of the table if vx > 0: #motion is oriented to the right return m, n #the ball falls in the top right hole elif vx < 0: #motion is oriented to the left return 0, n #the ball falls in the top left hole else: return -1 #the ball keeps bouncing indefinitely between the right and left sides p = vy/vx r = y - p * x d, k1_0, k2_0 = GCD_Euclidean_Algorithm(m, abs(-n * p)) # k1_0 and k2_0 are coefficients by means of which # we can express the d = gcd as a LC of the arguments if r % d != 0: return -1 # right side of the Dioph. Eq. is not divisible by the gcd, so there is no solution k1_0 = k1_0 * r / d k2_0 = k2_0 * r / d # now k1_0 and k2_0 are a particular solution of the Dioph. Eq. t_lb1, t_lb2 = -2**10, -2**10 t_ub1, t_ub2 = 2**10, 2**10 # establishing upper and/or lower bounds for t depending on the original direction of the ball motion if vx > 0: t_ub1 = (k2_0 / m) * d else: t_lb1 = ((k2_0 - 1) / m) * d if vy > 0: t_ub2 = (k1_0 / (n * p)) * d else: t_lb2 = ((k1_0 - 1) / (n * p)) * d t = 0 # deciding the final value for t if vx == vy: if vy > 0: t = min(trunc(t_ub2), trunc(t_ub1)) else: t = max(trunc(t_lb1), trunc(t_lb2)) holder = t k2 = 0 notdone = True while(notdone): k2 = k2_0 - (m/d) * t if (abs(k2) > (abs(k2_0 - (m/d) * holder))): notdone = False t = holder else: holder = t t = t - 1 else: t_lb1 = max(trunc(t_lb1), trunc(t_lb2)) t_ub1 = min(trunc(t_ub2), trunc(t_ub1)) for i in range(0, (t_ub1 + 1 - t_lb1) // 2): k2_1 = k2_0 - (m/d) * (t_lb1 + i) k2_2 = k2_0 - (m/d) * (t_ub1 + 1 - i) if abs(k2_1) < abs(holder): holder = k2_1 t = t_lb1 + i elif abs(k2_2) < abs(holder): holder = k2_2 t = t_ub1 + 1 - i k2 = k2 = k2_0 - (m/d) * t k1 = k1_0 - (n* p * t) / d #by checking the parity of k1 and k2 we can know in which hole the ball fell return (k2 % 2) * m, (k1 % 2) * n def GCD_Euclidean_Algorithm(a, b): if b > a: temp = a a = b b = temp r = a % b if r == 0: # base case, d has been found return b, 1, 0 d, x_1, y_1 = GCD_Euclidean_Algorithm(b, a % b) # x, y, x_1 and y_1 are used to update the # values of the coefficients by substituting the x = y_1 - (x_1 * trunc(a/b)) # previously obtained values along with the y = x_1 # return of the recursive calls return d, x, y def main(): _, n, m, x, y, vx, vy = argv print(Billiard_Table(int(n), int(m), int(x), int(y), int(vx), int(vy))) main()
Title: Billiard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider a [billiard table](https://en.wikipedia.org/wiki/Billiard_table) of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture). There is one ball at the point $(x, y)$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $45^{\circ}$ angle with them. We will assume that: 1. the angles between the directions of the ball before and after a collision with a side are equal, 1. the ball moves indefinitely long, it only stops when it falls into a pocket, 1. the ball can be considered as a point, it falls into a pocket if and only if its coordinates coincide with one of the pockets, 1. initially the ball is not in a pocket. Note that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side. Your task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be. Input Specification: The only line contains $6$ integers $n$, $m$, $x$, $y$, $v_x$, $v_y$ ($1 \leq n, m \leq 10^9$, $0 \leq x \leq n$; $0 \leq y \leq m$; $-1 \leq v_x, v_y \leq 1$; $(v_x, v_y) \neq (0, 0)$)Β β€” the width of the table, the length of the table, the $x$-coordinate of the initial position of the ball, the $y$-coordinate of the initial position of the ball, the $x$-component of its initial speed and the $y$-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket. Output Specification: Print the coordinates of the pocket the ball will fall into, or $-1$ if the ball will move indefinitely. Demo Input: ['4 3 2 2 -1 1\n', '4 4 2 0 1 1\n', '10 10 10 1 -1 0\n'] Demo Output: ['0 0', '-1', '-1'] Note: The first sample: The second sample: In the third sample the ball will never change its $y$ coordinate, so the ball will never fall into a pocket.
```python from sys import argv from math import trunc def Billiard_Table(n, m, x, y, vx, vy): if vx == 0: #vertical motion if vy == 0: #the ball is not moving return -1 if x == 0: #motion occurs along the left side of the billiard table if vy > 0: #motion is vertical upwards return 0, n #the ball falls in the top left hole elif vy < 0: #motion is vertical downwards return 0, 0 #the ball falls in the bottom left hole elif x == m: #motion occurs along the right side of the billiard table if vy > 0: #motion is vertical upwards return m, 0 #the ball falls in the bottom right hole elif vy < 0: #motion is vertical downwards return m, n #the ball falls in the top right hole else: return -1 #the ball yeeps bouncing indefinitely between the top and bottom sides if vy == 0: #horizontal motion if y == 0: #motion occurs along the bottom side of the table if vx > 0: #motion is oriented to the right return m, 0 #the ball falls in the bottom right hole elif vx < 0: #motion is oriented to the left return 0, 0 #the ball falls in the bottom left hole elif y == n: #motion occurs along the top side of the table if vx > 0: #motion is oriented to the right return m, n #the ball falls in the top right hole elif vx < 0: #motion is oriented to the left return 0, n #the ball falls in the top left hole else: return -1 #the ball keeps bouncing indefinitely between the right and left sides p = vy/vx r = y - p * x d, k1_0, k2_0 = GCD_Euclidean_Algorithm(m, abs(-n * p)) # k1_0 and k2_0 are coefficients by means of which # we can express the d = gcd as a LC of the arguments if r % d != 0: return -1 # right side of the Dioph. Eq. is not divisible by the gcd, so there is no solution k1_0 = k1_0 * r / d k2_0 = k2_0 * r / d # now k1_0 and k2_0 are a particular solution of the Dioph. Eq. t_lb1, t_lb2 = -2**10, -2**10 t_ub1, t_ub2 = 2**10, 2**10 # establishing upper and/or lower bounds for t depending on the original direction of the ball motion if vx > 0: t_ub1 = (k2_0 / m) * d else: t_lb1 = ((k2_0 - 1) / m) * d if vy > 0: t_ub2 = (k1_0 / (n * p)) * d else: t_lb2 = ((k1_0 - 1) / (n * p)) * d t = 0 # deciding the final value for t if vx == vy: if vy > 0: t = min(trunc(t_ub2), trunc(t_ub1)) else: t = max(trunc(t_lb1), trunc(t_lb2)) holder = t k2 = 0 notdone = True while(notdone): k2 = k2_0 - (m/d) * t if (abs(k2) > (abs(k2_0 - (m/d) * holder))): notdone = False t = holder else: holder = t t = t - 1 else: t_lb1 = max(trunc(t_lb1), trunc(t_lb2)) t_ub1 = min(trunc(t_ub2), trunc(t_ub1)) for i in range(0, (t_ub1 + 1 - t_lb1) // 2): k2_1 = k2_0 - (m/d) * (t_lb1 + i) k2_2 = k2_0 - (m/d) * (t_ub1 + 1 - i) if abs(k2_1) < abs(holder): holder = k2_1 t = t_lb1 + i elif abs(k2_2) < abs(holder): holder = k2_2 t = t_ub1 + 1 - i k2 = k2 = k2_0 - (m/d) * t k1 = k1_0 - (n* p * t) / d #by checking the parity of k1 and k2 we can know in which hole the ball fell return (k2 % 2) * m, (k1 % 2) * n def GCD_Euclidean_Algorithm(a, b): if b > a: temp = a a = b b = temp r = a % b if r == 0: # base case, d has been found return b, 1, 0 d, x_1, y_1 = GCD_Euclidean_Algorithm(b, a % b) # x, y, x_1 and y_1 are used to update the # values of the coefficients by substituting the x = y_1 - (x_1 * trunc(a/b)) # previously obtained values along with the y = x_1 # return of the recursive calls return d, x, y def main(): _, n, m, x, y, vx, vy = argv print(Billiard_Table(int(n), int(m), int(x), int(y), int(vx), int(vy))) main() ```
-1
733
D
Kostya the Sculptor
PROGRAMMING
1,600
[ "data structures", "hashing" ]
null
null
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has *n* stones which are rectangular parallelepipeds. The edges sizes of the *i*-th of them are *a**i*, *b**i* and *c**i*. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.
The first line contains the integer *n* (1<=≀<=*n*<=≀<=105). *n* lines follow, in the *i*-th of which there are three integers *a**i*,<=*b**i* and *c**i* (1<=≀<=*a**i*,<=*b**i*,<=*c**i*<=≀<=109)Β β€” the lengths of edges of the *i*-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.
In the first line print *k* (1<=≀<=*k*<=≀<=2) the number of stones which Zahar has chosen. In the second line print *k* distinct integers from 1 to *n*Β β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to *n* in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them.
[ "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4\n", "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7\n" ]
[ "1\n1\n", "2\n1 5\n" ]
In the first example we can connect the pairs of stones: - 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. - 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5 - 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5 Or take only one stone: - 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5 - 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 - 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5 - 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5 - 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 - 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone.
2,000
[ { "input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4", "output": "1\n1" }, { "input": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7", "output": "2\n1 5" }, { "input": "1\n1 1 1", "output": "1\n1" }, { "input": "2\n2 3 1\n2 2 3", "output": "2\n2 1" }, { ...
1,541,441,789
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
# Possible primes # 157, 1453, 84673, 106033, 108301, 112909, 115249 class HashTable: def __init__(self, depth=2, module=1453): self.depth = depth self.module = module self.table = [] def add(self, seq): ref = self.table for i in range(self.depth-1): if len(ref) == 0: ref.extend([[] for i in range(self.module)]) box = seq[i] % self.module ref = ref[box] box = seq[self.depth-1] % self.module if len(ref) == 0: ref.extend([[] for i in range(self.module)]) ref[box].append(seq) def look_up(self, seq): ref = self.table depth = 0 while depth < self.depth and len(ref) > 0: box = seq[depth] % self.module ref = ref[box] depth += 1 if depth < self.depth or len(ref) == 0: return None max_z_value = 0 best = None d = 0 for cand in ref: while d < self.depth and cand[d] == seq[d]: d += 1 if d < self.depth: break if max_z_value < cand[d]: max_z_value = cand[d] best = cand return best if __name__ == '__main__': hash_table = HashTable() input_file = open('input.txt', "r") #n = int(input_file.readline()) n = int(input()) max_radius = 0 ordinal_numbers = [0] for i in range(1, n+1): #seq = sorted(list(map(int, input_file.readline().split())), # reverse=True) + [i] seq = sorted(list(map(int, input().split())), reverse=True) + [i] best = hash_table.look_up(seq) if best is not None: seq[2] += best[2] radius = min(seq[:-1]) if radius > max_radius: ordinal_numbers = [best[3], seq[3]] max_radius = radius else: if seq[2] > max_radius: ordinal_numbers = [seq[3]] max_radius = seq[2] hash_table.add(seq) #input_file.close() #output_file = open('output.txt', "w") #print(len(ordinal_numbers), file=output_file) #print(" ".join(map(str, ordinal_numbers)), file=output_file) #output_file.write(str(max_radius)) #output_file.close() print(len(ordinal_numbers), file=output_file) print(" ".join(map(str, ordinal_numbers)), file=output_file)
Title: Kostya the Sculptor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has *n* stones which are rectangular parallelepipeds. The edges sizes of the *i*-th of them are *a**i*, *b**i* and *c**i*. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input Specification: The first line contains the integer *n* (1<=≀<=*n*<=≀<=105). *n* lines follow, in the *i*-th of which there are three integers *a**i*,<=*b**i* and *c**i* (1<=≀<=*a**i*,<=*b**i*,<=*c**i*<=≀<=109)Β β€” the lengths of edges of the *i*-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output Specification: In the first line print *k* (1<=≀<=*k*<=≀<=2) the number of stones which Zahar has chosen. In the second line print *k* distinct integers from 1 to *n*Β β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to *n* in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Demo Input: ['6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4\n', '7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7\n'] Demo Output: ['1\n1\n', '2\n1 5\n'] Note: In the first example we can connect the pairs of stones: - 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. - 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5 - 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5 Or take only one stone: - 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5 - 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 - 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5 - 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5 - 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 - 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone.
```python # Possible primes # 157, 1453, 84673, 106033, 108301, 112909, 115249 class HashTable: def __init__(self, depth=2, module=1453): self.depth = depth self.module = module self.table = [] def add(self, seq): ref = self.table for i in range(self.depth-1): if len(ref) == 0: ref.extend([[] for i in range(self.module)]) box = seq[i] % self.module ref = ref[box] box = seq[self.depth-1] % self.module if len(ref) == 0: ref.extend([[] for i in range(self.module)]) ref[box].append(seq) def look_up(self, seq): ref = self.table depth = 0 while depth < self.depth and len(ref) > 0: box = seq[depth] % self.module ref = ref[box] depth += 1 if depth < self.depth or len(ref) == 0: return None max_z_value = 0 best = None d = 0 for cand in ref: while d < self.depth and cand[d] == seq[d]: d += 1 if d < self.depth: break if max_z_value < cand[d]: max_z_value = cand[d] best = cand return best if __name__ == '__main__': hash_table = HashTable() input_file = open('input.txt', "r") #n = int(input_file.readline()) n = int(input()) max_radius = 0 ordinal_numbers = [0] for i in range(1, n+1): #seq = sorted(list(map(int, input_file.readline().split())), # reverse=True) + [i] seq = sorted(list(map(int, input().split())), reverse=True) + [i] best = hash_table.look_up(seq) if best is not None: seq[2] += best[2] radius = min(seq[:-1]) if radius > max_radius: ordinal_numbers = [best[3], seq[3]] max_radius = radius else: if seq[2] > max_radius: ordinal_numbers = [seq[3]] max_radius = seq[2] hash_table.add(seq) #input_file.close() #output_file = open('output.txt', "w") #print(len(ordinal_numbers), file=output_file) #print(" ".join(map(str, ordinal_numbers)), file=output_file) #output_file.write(str(max_radius)) #output_file.close() print(len(ordinal_numbers), file=output_file) print(" ".join(map(str, ordinal_numbers)), file=output_file) ```
-1
253
A
Boys and Girls
PROGRAMMING
1,100
[ "greedy" ]
null
null
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≀<=*i*<=&lt;<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line.
The single line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100), separated by a space.
Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them.
[ "3 3\n", "4 2\n" ]
[ "GBGBGB\n", "BGBGBB\n" ]
In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal.
500
[ { "input": "3 3", "output": "GBGBGB" }, { "input": "4 2", "output": "BGBGBB" }, { "input": "5 5", "output": "GBGBGBGBGB" }, { "input": "6 4", "output": "BGBGBGBGBB" }, { "input": "100 1", "output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
1,617,815,412
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
7
248
2,252,800
import sys from bisect import * sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') n, m = map(int, input().split()) if n>=m: i = 0 j = 0 test = 0 ans = '' while i<n and j<m: if test: ans+='G' j+=1 test = 0 else: ans+='B' i+=1 test = 1 while i<n: ans+='B' i+=1 while j<m: ans+='G' j+=1 else: i = 0 j = 0 test = 0 while i<n and j<m: if test: ans+='B' i+=1 test = 0 else: ans+='G' j+=1 test = 1 while i<n: ans+='B' i+=1 while j<m: ans+='G' j+=1 print(ans)
Title: Boys and Girls Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≀<=*i*<=&lt;<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line. Input Specification: The single line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100), separated by a space. Output Specification: Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them. Demo Input: ['3 3\n', '4 2\n'] Demo Output: ['GBGBGB\n', 'BGBGBB\n'] Note: In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal.
```python import sys from bisect import * sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') n, m = map(int, input().split()) if n>=m: i = 0 j = 0 test = 0 ans = '' while i<n and j<m: if test: ans+='G' j+=1 test = 0 else: ans+='B' i+=1 test = 1 while i<n: ans+='B' i+=1 while j<m: ans+='G' j+=1 else: i = 0 j = 0 test = 0 while i<n and j<m: if test: ans+='B' i+=1 test = 0 else: ans+='G' j+=1 test = 1 while i<n: ans+='B' i+=1 while j<m: ans+='G' j+=1 print(ans) ```
-1
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
The first line contains two integers, *n* and *k* (1<=≀<=*n*<=≀<=2000;Β 1<=≀<=*k*<=≀<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≀<=*y**i*<=≀<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number β€” the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0...
1,690,309,052
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
15
0
x , y = map(int,input().split()) l = [*map(int,input().split())] a = 0 for i in l: if i<5: a+=1 print(a//3)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? Input Specification: The first line contains two integers, *n* and *k* (1<=≀<=*n*<=≀<=2000;Β 1<=≀<=*k*<=≀<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≀<=*y**i*<=≀<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. Output Specification: Print a single number β€” the answer to the problem. Demo Input: ['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n'] Demo Output: ['1\n', '0\n', '2\n'] Note: In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
```python x , y = map(int,input().split()) l = [*map(int,input().split())] a = 0 for i in l: if i<5: a+=1 print(a//3) ```
0
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko β€” W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W β€” the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format Β«A/BΒ», where A β€” the numerator, and B β€” the denominator. If the required probability equals to zero, output Β«0/1Β». If the required probability equals to 1, output Β«1/1Β».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,666,546,201
2,147,483,647
PyPy 3-64
OK
TESTS
36
124
0
y,w=map(int,input().split()) probability=["", "1/1", "5/6", "2/3", "1/2", "1/3", "1/6"] print(probability[max(y,w)])
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko β€” W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: The only line of the input file contains two natural numbers Y and W β€” the results of Yakko's and Wakko's die rolls. Output Specification: Output the required probability in the form of irreducible fraction in format Β«A/BΒ», where A β€” the numerator, and B β€” the denominator. If the required probability equals to zero, output Β«0/1Β». If the required probability equals to 1, output Β«1/1Β». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python y,w=map(int,input().split()) probability=["", "1/1", "5/6", "2/3", "1/2", "1/3", "1/6"] print(probability[max(y,w)]) ```
3.938
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* β€” board sizes in squares (1<=≀<=*M*<=≀<=*N*<=≀<=16).
Output one number β€” the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,670,948,713
2,147,483,647
Python 3
OK
TESTS
35
92
0
# n = int(input()) # words = [input() for i in range(n)] # def shorter(word): # if len(word) <= 10: # return word # else: # return word[0] + str(len(word)-2) + word[-1] # for i in words: # print(shorter(i)) # n = int(input()) # sol = [input().split(" ") for i in range(n)] # soln = 0 # for item in sol: # if item.count("1")>=2: # soln += 1 # print(soln) # n, k = input().split(" ") # score = input().split(" ") # count = 0 # for i in score: # if int(i) >= int(score[int(k) - 1]) and int(i) != 0: # count+=1 # print(count) m, n = list(map(int,input().split(" "))) print(m*n//2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* β€” board sizes in squares (1<=≀<=*M*<=≀<=*N*<=≀<=16). Output Specification: Output one number β€” the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python # n = int(input()) # words = [input() for i in range(n)] # def shorter(word): # if len(word) <= 10: # return word # else: # return word[0] + str(len(word)-2) + word[-1] # for i in words: # print(shorter(i)) # n = int(input()) # sol = [input().split(" ") for i in range(n)] # soln = 0 # for item in sol: # if item.count("1")>=2: # soln += 1 # print(soln) # n, k = input().split(" ") # score = input().split(" ") # count = 0 # for i in score: # if int(i) >= int(score[int(k) - 1]) and int(i) != 0: # count+=1 # print(count) m, n = list(map(int,input().split(" "))) print(m*n//2) ```
3.977
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
The first line contains two space separated integers *n*, *d* (1<=≀<=*n*<=≀<=100;Β 1<=≀<=*d*<=≀<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t**i*<=≀<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes. Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 ...
1,632,117,780
2,147,483,647
Python 3
OK
TESTS
26
62
6,758,400
n,m=map(int, input().split()) a=sum(list(map(int, input().split()))) if a+(n-1)*10<=m: print((m-a)//5) else: print(-1)
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. Input Specification: The first line contains two space separated integers *n*, *d* (1<=≀<=*n*<=≀<=100;Β 1<=≀<=*d*<=≀<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t**i*<=≀<=100). Output Specification: If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. Demo Input: ['3 30\n2 2 1\n', '3 20\n2 1 1\n'] Demo Output: ['5\n', '-1\n'] Note: Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes. Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes. Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.
```python n,m=map(int, input().split()) a=sum(list(map(int, input().split()))) if a+(n-1)*10<=m: print((m-a)//5) else: print(-1) ```
3
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...
1,627,676,949
2,147,483,647
PyPy 3
OK
TESTS
55
109
20,172,800
n, finish = map(int, input().split()) end_interval = [0, finish] points = [] for _ in range(n): x, y = map(int, input().split()) points.append([x, y]) points.sort() #print(points) merge_interval = [points[0][0], points[0][1]] for i in range(1, n): if merge_interval[1]>=points[i][0]: merge_interval[1]=max(merge_interval[1], points[i][1]) #print(merge_interval) if end_interval[0]>=merge_interval[0] and end_interval[1]<=merge_interval[1]: print('YES') else: print('NO')
Title: Visiting a Friend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car. Input Specification: The first line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=100,<=1<=≀<=*m*<=≀<=100)Β β€” the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≀<=*a**i*<=≀<=*b**i*<=≀<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit. It is guaranteed that *a**i*<=β‰₯<=*a**i*<=-<=1 for every *i* (2<=≀<=*i*<=≀<=*n*). Output Specification: Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n'] Demo Output: ['YES\n', 'NO\n'] Note: The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You can see that there is no path from Pig's house to his friend's house that uses only teleports.
```python n, finish = map(int, input().split()) end_interval = [0, finish] points = [] for _ in range(n): x, y = map(int, input().split()) points.append([x, y]) points.sort() #print(points) merge_interval = [points[0][0], points[0][1]] for i in range(1, n): if merge_interval[1]>=points[i][0]: merge_interval[1]=max(merge_interval[1], points[i][1]) #print(merge_interval) if end_interval[0]>=merge_interval[0] and end_interval[1]<=merge_interval[1]: print('YES') else: print('NO') ```
3
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
57