problem_name
stringlengths
9
76
problem_id
stringlengths
1
4
solution_id
stringlengths
4
9
description
stringlengths
164
3.45k
solution_code
stringlengths
37
12.2k
dataclass_code
stringlengths
3.26k
4k
inputs_example
stringlengths
1
103
time_complexity_inferred
stringclasses
11 values
time_curve_coefficient
float64
0
0.07
tests
dict
problem_time_curve_coefficient_list
listlengths
8
3.27k
300_A. Array
1717
1717_238
Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of a...
#A. Array n = int(input()) a,b,c =[],[],[] l = list(map(int,input().split())) for i in l: if i<0: a.append(i) elif i>0: b.append(i) else: c.append(i) if len(b)==0 and len(a)>2: b.append(a.pop()) b.append(a.pop()) if len(a)%2==0: c.append(a.pop()) print(len(a),*a) pr...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 -1 -2 -3 0
O(n)
0.000006
{ "public_tests": [ { "input": "4\n-1 -2 -3 0\n", "output": "1 -1\n2 -3 -2\n1 0\n" }, { "input": "3\n-1 2 0\n", "output": "1 -1\n1 2\n1 0\n" } ], "private_tests": [ { "input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 ...
[ 0.000012011960363854897, 0.000011650656222683569, 0.00001152581577797203, 0.000011295203097683568, 0.000011288363171984266, 0.000010955091400786714, 0.000010717416193181819, 0.000010675385462194056, 0.000010625342507102274, 0.000010561500177556819, 0.000010296421478911713, 0.000010043508754916...
300_A. Array
1717
1717_175
Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero ( < 0). 2. The product of all numbers in the second set is greater than zero ( > 0). 3. The product of a...
(input()) a=sorted(map(int,input().split())) b=[a.pop(0)] c=a[-1]>0 and [a.pop()] or [a.pop(0),a.pop(0)] for l in b,c,a: print(len(l),*l)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 -1 -2 -3 0
O(nlogn)
0.000012
{ "public_tests": [ { "input": "4\n-1 -2 -3 0\n", "output": "1 -1\n2 -3 -2\n1 0\n" }, { "input": "3\n-1 2 0\n", "output": "1 -1\n1 2\n1 0\n" } ], "private_tests": [ { "input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 ...
[ 0.00002087753022029749, 0.00001893894765826371, 0.000016788290392761865, 0.000014121765889930757, 0.000013856458015707598, 0.000012319327057325987, 0.000012302450377720542, 0.000012301930472324306, 0.000012265624733936694, 0.000012217629769495987, 0.000012147268416040262, 0.0000121274908618497...
137_B. Permutation
1413
1413_222
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of n integers is calle...
n = int(input()) x = list(map(int, input().split())) a, list_of_set = n * [0], n * [0] ans = 0 for i in range(1, n + 1): a[i - 1] = i for j in range(n): if j + 1 in set(x): list_of_set[j] = j + 1 for k in range(n): if list_of_set[k] != a[k]: ans += 1 print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 2 2
O(n**2)
0
{ "public_tests": [ { "input": "2\n2 2\n", "output": "1\n" }, { "input": "3\n3 1 2\n", "output": "0\n" }, { "input": "5\n5 3 3 3 1\n", "output": "2\n" } ], "private_tests": [ { "input": "100\n340 14 3275 2283 2673 1107 817 2243 1226 32 2382 363...
[ 0.00001752841712194056, 0.00000924227734375, 0.000006904312418050699, 0.000006892622377622378, 0.000006889492747486887, 0.000006609331949300701, 8.84411264773725e-8, 4.624087106753035e-8, 4.045804122207912e-8, 3.0479932450166966e-8, 5.1464285185353154e-9, 2.4291092962001724e-9, 2.41885169216...
137_B. Permutation
1413
1413_104
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of n integers is calle...
n = int(input()) ns = [int(x) for x in input().split()] ok = [False]*n for ni in ns: ni-=1 if ni<n: ok[ni]=True print(sum([1 for isOK in ok if not isOK]))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 2 2
O(n)
0.000001
{ "public_tests": [ { "input": "2\n2 2\n", "output": "1\n" }, { "input": "3\n3 1 2\n", "output": "0\n" }, { "input": "5\n5 3 3 3 1\n", "output": "2\n" } ], "private_tests": [ { "input": "100\n340 14 3275 2283 2673 1107 817 2243 1226 32 2382 363...
[ 0.0000028812745574737766, 0.000002488892837631119, 0.000002292101862980769, 0.0000021158861997377623, 0.000002059154051027098, 0.0000018935927256337409, 0.0000018526755900349651, 0.0000017540736997377624, 0.0000017519947552447553, 0.0000017449858910620631, 0.0000016097824928977275, 0.000001607...
1102_C. Doors Breaking and Repairing
2982
2982_323
You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move. There are n doors, the i-th door initially has durability equal to a_i. During your move you can try to br...
from math import ceil n, x, y = map(int, input().split()) li = list(map(int, input().split())) if x > y: print(len(li)) else: num = 0 for i in li: if i <= x: num += 1 print(ceil(num / 2))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 5 6 1 2 6 10 3
O(n)
0.000003
{ "public_tests": [ { "input": "5 5 6\n1 2 6 10 3\n", "output": "2\n" }, { "input": "6 3 2\n2 3 1 3 4 2\n", "output": "6\n" }, { "input": "5 3 3\n1 2 4 2 3\n", "output": "2\n" } ], "private_tests": [ { "input": "1 2 3\n3\n", "output": "0\...
[ 0.042477502218309864, 0.000004523451526988637, 0.0000044658248606861895, 0.000004092630886691434, 0.000004070891157670455, 0.000004068205815668707, 0.000004061600210336538, 0.000004059164841018357, 0.000003993006187172204, 0.000003984669402862762, 0.0000039739422803758745, 0.000003961245055725...
1102_C. Doors Breaking and Repairing
2982
2982_103
You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move. There are n doors, the i-th door initially has durability equal to a_i. During your move you can try to br...
n,x,y=input().split() n=int(n) x=int(x) y=int(y) l=[int(x) for x in input().split()] l.sort() count_a=0 for i in range(n): if(l[i]<=x): count_a+=1 if(x>y): print(n) else: print((count_a%2)+(count_a//2))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 5 6 1 2 6 10 3
O(nlogn)
0.000014
{ "public_tests": [ { "input": "5 5 6\n1 2 6 10 3\n", "output": "2\n" }, { "input": "6 3 2\n2 3 1 3 4 2\n", "output": "6\n" }, { "input": "5 3 3\n1 2 4 2 3\n", "output": "2\n" } ], "private_tests": [ { "input": "1 2 3\n3\n", "output": "0\...
[ 0.00001896206035324976, 0.00001715002833060554, 0.00001555067730383755, 0.000015251951034254272, 0.000015135689806336875, 0.000014928358453196, 0.000014840798875093106, 0.000014691368665684796, 0.000014645832176865757, 0.000014615825641969398, 0.000014606040551523946, 0.000014600560362655594, ...
499_A. Watching a movie
1138
1138_83
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 2. Skip exactly x minutes of the movi...
n,x = map(int, input().split()) data = [] result = 0 for _ in range(n): data.append(list(map(int, input().split()))) for i in range(n): if i==0: result += (data[i][0]-1)%x else: result += (data[i][0]-data[i-1][1]-1)%x result += data[i][1]-data[i][0]+1 print(result)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 3 5 6 10 12
O(n*m)
0.000002
{ "public_tests": [ { "input": "2 3\n5 6\n10 12\n", "output": "6\n" }, { "input": "1 1\n1 100000\n", "output": "100000\n" } ], "private_tests": [ { "input": "1 100\n5 6\n", "output": "6\n" }, { "input": "1 3\n4 100000\n", "output": "99997...
[ 0.000005614333342438811, 0.0000022258838368662593, 0.0000019078166520979018, 0.0000018696114510489515, 0.0000018089166029283217, 0.000001806049784200175, 0.0000017898719678758745, 0.0000017759407643138112, 0.0000017626189357517486, 0.0000017370410839160838, 0.0000017218942034527974, 0.00000171...
499_A. Watching a movie
1138
1138_66
You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie. 2. Skip exactly x minutes of the movi...
n,x=map(int, input().split()) w=0 m=1 for i in range(n): l,r=map(int, input().split()) k=r l,r=l-m,r-m w+=l%x+r-l+1 m=k+1 print(w)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 3 5 6 10 12
O(n)
0.000007
{ "public_tests": [ { "input": "2 3\n5 6\n10 12\n", "output": "6\n" }, { "input": "1 1\n1 100000\n", "output": "100000\n" } ], "private_tests": [ { "input": "1 100\n5 6\n", "output": "6\n" }, { "input": "1 3\n4 100000\n", "output": "99997...
[ 0.00001486612691215035, 0.000011527583752185316, 0.000010805071705638112, 0.00001031349651715472, 0.000010246949724104022, 0.000010000881555944057, 0.000009907754848666958, 0.00000986425281359266, 0.000009847783626529721, 0.000009701817935970281, 0.000009454618157233393, 0.00000938650105168269...
725_A. Jumping Ball
410
410_105
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it...
n = int(input()) s = input() begin = True counter = 0 ans = 0 for i in range(n): if begin and s[i] == "<": ans += 1 elif s[i] == ">": counter += 1 begin = False else: counter = 0 print(ans + counter)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 &gt;&gt;&gt;&gt;&gt;
O(n)
0.000001
{ "public_tests": [ { "input": "5\n&gt;&gt;&gt;&gt;&gt;\n", "output": "0" }, { "input": "4\n&lt;&lt;&gt;&lt;\n", "output": "0" }, { "input": "4\n&gt;&gt;&lt;&lt;\n", "output": "0" } ], "private_tests": [ { "input": "4\n<><>\n", "output": ...
[ 0.000022257482613090036, 0.000022010910606971156, 0.000015191888371394233, 0.000014906069096918707, 0.000014653378592111017, 0.000014441434782014861, 0.000008299748074191434, 0.000008235939999453672, 0.000008124931012347029, 0.000008112272303868008, 0.000007961386377294582, 0.00000794655874399...
725_A. Jumping Ball
410
410_176
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it...
n, s = int(input()), input() if '<' not in s or '>' not in s: print(n) else: print(s.find('>') + (n - 1 - s.rfind('<')))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 &gt;&gt;&gt;&gt;&gt;
O(1)
0.000001
{ "public_tests": [ { "input": "5\n&gt;&gt;&gt;&gt;&gt;\n", "output": "0" }, { "input": "4\n&lt;&lt;&gt;&lt;\n", "output": "0" }, { "input": "4\n&gt;&gt;&lt;&lt;\n", "output": "0" } ], "private_tests": [ { "input": "4\n<><>\n", "output": ...
[ 0.000005731500000000001, 0.000004074500000000003, 0.0000039795000000000015, 0.000003951000000000003, 0.0000037329999999999997, 0.000003642500000000001, 0.0000036309999999999996, 0.000003562500000000002, 0.0000034259999999999974, 0.000003420000000000001, 0.000003339000000000003, 0.0000032995000...
1199_A. City Day
1820
1820_122
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the n days of summer. On the i-th day, a_i millimeters of rain will fall. All values a_i are distinct. The mayor k...
n,x,y=map(int,input().split()) a=list(map(int,input().split())) ind=0 for i in range(len(a)): chx=1 chy=1 for j in range(i-x,i): if(j>=0): if(a[i]>=a[j]): chx=0 break for j in range(i+1,i+y+1): if(j<n): if(a[i]>...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 5 5 100000 10000 1000 100 10
O(n**2)
0.000002
{ "public_tests": [ { "input": "5 5 5\n100000 10000 1000 100 10\n", "output": "5\n" }, { "input": "10 2 2\n10 9 6 7 8 3 2 1 4 5\n", "output": "3\n" }, { "input": "10 2 3\n10 9 6 7 8 3 2 1 4 5\n", "output": "8\n" } ], "private_tests": [ { "input...
[ 0.0359381185387324, 0.02818258442248996, 0.02603322441285141, 0.0001891475097657768, 0.00007427681200849974, 0.00004983837334735577, 0.000012603050522864336, 0.000011940911203896034, 0.000011908731390112196, 0.000011802143079730543, 0.00000832197102088924, 0.000007281308272738899, 0.00000652...
1199_A. City Day
1820
1820_180
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the n days of summer. On the i-th day, a_i millimeters of rain will fall. All values a_i are distinct. The mayor k...
n , x , y = map(int,input().split()) arr = list(map(int,input().split())) for i in range(n): if i >= x : if arr[i] == min(arr[i - x : i + y + 1]): print(i + 1 ) break else: if arr[i] == min(arr[0 : i + y +1]): print(i + 1 ) break
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 5 5 100000 10000 1000 100 10
O(n)
0.000008
{ "public_tests": [ { "input": "5 5 5\n100000 10000 1000 100 10\n", "output": "5\n" }, { "input": "10 2 2\n10 9 6 7 8 3 2 1 4 5\n", "output": "3\n" }, { "input": "10 2 3\n10 9 6 7 8 3 2 1 4 5\n", "output": "8\n" } ], "private_tests": [ { "input...
[ 0.00905593346029143, 0.0003480291688360468, 0.00031279487359320366, 0.0003111442326267483, 0.000035532157642437784, 0.00003541184197919736, 0.00002960928470552885, 0.000028212183026934005, 0.000028201364496831294, 0.00001657746735686189, 0.00001433440429481221, 0.000013256618687210243, 0.000...
1445_B. Elimination
914
914_14
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests. A result of the elimination stage is the tota...
t=int(input()) for j in range(t): m=list(map(int,input().split())) a=m[0]+m[1] b=m[2]+m[3] if a>b: print(a) else: print(b)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 1 2 2 1 4 8 9 2
O(n*m)
0.000003
{ "public_tests": [ { "input": "2\n1 2 2 1\n4 8 9 2\n", "output": "3\n12\n" } ], "private_tests": [ { "input": "1\n0 0 0 0\n", "output": "0\n" } ], "generated_tests": [ { "input": "1\n0 0 1 0\n", "output": "1\n" }, { "input": "2\n1 2 2 1\n4...
[ 0.000006849102395651225, 0.0000037933839051573426, 0.0000037851964871066434, 0.0000037752614455856643, 0.0000037504962166739513, 0.0000037486697852928326, 0.0000037369461183347906, 0.000003728857326267482, 0.000003719051860249126, 0.0000037102251010708043, 0.000003697150103802448, 0.0000036953...
1445_B. Elimination
914
914_416
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests. A result of the elimination stage is the tota...
import sys import math import collections input=sys.stdin.readline t=int(input()) for w in range(t): a,b,c,d=(int(i) for i in input().split()) print(max(a+b,c+d))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 1 2 2 1 4 8 9 2
O(n)
0
{ "public_tests": [ { "input": "2\n1 2 2 1\n4 8 9 2\n", "output": "3\n12\n" } ], "private_tests": [ { "input": "1\n0 0 0 0\n", "output": "0\n" } ], "generated_tests": [ { "input": "1\n0 0 1 0\n", "output": "1\n" }, { "input": "2\n1 2 2 1\n4...
[ 0.00446835655491728, 0.004348677603197943, 0.002143195600321161, 0.000035082039158107516, 0.00003414055130026224, 0.000016943268233719406, 0.000016303944725196675, 0.00001412485484047203, 0.000013683960705310315, 0.000013554284418706295, 0.000013168568700830421, 0.000013007454763986017, 0.00...
1326_A. Bad Ugly Numbers
1043
1043_408
You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of mult...
t = int(input()) while t: n = int(input()) if n >= 2: print('23',end="") else: print("-1") while n>2: print('3',end="") n -= 1 print(" ") t -= 1
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 2 3 4
O(n**2)
0.000014
{ "public_tests": [ { "input": "4\n1\n2\n3\n4\n", "output": "-1\n23\n233\n2333\n" } ], "private_tests": [ { "input": "5\n19999\n19998\n20001\n20000\n20002\n", "output": "233333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
[ 0.00006423655577586629, 0.00005698115374587397, 0.000048058978379171726, 0.00004291843968586056, 0.0000280147696013399, 0.000027202054139843275, 0.00002646419750553255, 0.000025898590320844692, 0.000025872473600603188, 0.00002558707264402614, 0.000025426855042893443, 0.000025051944150750096, ...
1326_A. Bad Ugly Numbers
1043
1043_358
You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of mult...
n = int(input()) for _ in range(n): v = int(input()) if v == 1: print(-1) else: print("2" + "3" * (v - 1))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 2 3 4
O(n)
0.073163
{ "public_tests": [ { "input": "4\n1\n2\n3\n4\n", "output": "-1\n23\n233\n2333\n" } ], "private_tests": [ { "input": "5\n19999\n19998\n20001\n20000\n20002\n", "output": "233333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
[ 0.135423398, 0.1345136855, 0.13346100750000003, 0.13293982850000002, 0.1325553725, 0.132183881, 0.132153365, 0.1319846485, 0.13072050200000002, 0.13061006, 0.12985595100000002, 0.12940846650000004, 0.1292314155, 0.12841866650000003, 0.12818751150000002, 0.127962016, 0.127773465500000...
501_B. Misha and Changing Handles
2217
2217_247
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the re...
q = int(input()) n = [input() for x in range(q)] a = [n[0].split(), ] for x in range(1, q): f = False s = n[x].split() for y in a: if s[0] == y[-1]: y.append(s[1]) f = True break if not f: a.append(s) print(len(a)) for x in a: print(x[0], x[-1])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 Misha ILoveCodeforces Vasya Petrov Petrov VasyaPetrov123 ILoveCodeforces MikeMirzayanov Petya Ivanov
O(n**2)
0
{ "public_tests": [ { "input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n", "output": "3\nMisha MikeMirzayanov\nVasya VasyaPetrov123\nPetya Ivanov\n" } ], "private_tests": [ { "input": "1\nMisha Vasya\n", "outp...
[ 0.000021340792947966625, 0.000019894102756592517, 0.000009506811941024263, 0.0000048807757412466525, 0.000004146267950504823, 0.000003662116888896133, 0.0000030457480242030656, 0.000002972547886592922, 0.0000029133971831165415, 0.000002863259978794774, 0.0000020842071748849206, 0.0000020517627...
501_B. Misha and Changing Handles
2217
2217_419
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the re...
t = int(input()) d = {} for i in range(t): old,new = input().split() d[new] = d.get(old,old) if old in d: d.pop(old) print(len(d)) for a,b in d.items(): print(b,a)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 Misha ILoveCodeforces Vasya Petrov Petrov VasyaPetrov123 ILoveCodeforces MikeMirzayanov Petya Ivanov
O(n)
0.000014
{ "public_tests": [ { "input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n", "output": "3\nMisha MikeMirzayanov\nVasya VasyaPetrov123\nPetya Ivanov\n" } ], "private_tests": [ { "input": "1\nMisha Vasya\n", "outp...
[ 0.00003844539582260158, 0.00003346469632995577, 0.000029387916759954993, 0.000027345953017217812, 0.000026759247299914534, 0.000025911500346773568, 0.00002546465283217598, 0.00002383924668118991, 0.000023278273824495166, 0.000023244265783952874, 0.00002232252631881873, 0.000022130878773141023,...
p00021 Parallelism
522
522_62
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO". Input Input consists of several datasets. In the fir...
N = int(input()) for _ in range(N): P = list(map(float,input().split())) a, b, c, d = [complex(P[i*2],P[i*2+1])*1000000 for i in range(4)] parallel = ((a-b).conjugate() *(c-d)).imag ==0 print("YES" if parallel else "NO")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0 3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
O(n*m)
0.000009
{ "public_tests": [ { "input": "2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0", "output": "YES\nNO" } ], "private_tests": [], "generated_tests": [ { "input": "2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.680227793087974 6.0 13.0 5.0 7.0 9.0", "output":...
[ 0.00003909120694930071, 0.00001429791067526224, 0.00001403480325338724, 0.00001384886787041084, 0.000009891773983828674, 0.00000974992294034091, 0.000009523226193728146, 0.0000095144237461757, 0.000009498083765843531, 0.000009298158394340036, 0.000009279868471372378, 0.000009212277575939687, ...
p00021 Parallelism
522
522_46
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "YES" and if not prints "NO". Input Input consists of several datasets. In the fir...
n = int(input()) for i in range(n): x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split()) print('YES' if abs((x2 - x1)*(y4 - y3) - (x4 - x3)*(y2 - y1)) < 1e-10 else 'NO')
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0 3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
O(n)
0
{ "public_tests": [ { "input": "2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0", "output": "YES\nNO" } ], "private_tests": [], "generated_tests": [ { "input": "2\n0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0\n3.0 2.0 9.680227793087974 6.0 13.0 5.0 7.0 9.0", "output":...
[ 9.38953234265734e-9, 8.69928704108391e-9, 8.604143902972029e-9, 6.151585718968532e-9, 5.791616586538463e-9, 5.497254698426575e-9, 5.271095115821678e-9, 5.089795946241259e-9, 4.72868635270979e-9, 4.600326431381117e-9, 4.593859265734264e-9, 4.336210664335664e-9, 4.286501584353149e-9, 4.28436...
1349_A. Orac and LCM
1871
1871_291
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integ...
def gcd(a, b): while b: a, b = b, a % b return a def solve(array): lcm = (array[0] * array[1])//gcd(array[0], array[1]) current = lcm for i in range(2, len(array)): running = (current * array[i])//gcd(current, array[i]) lcm = gcd(lcm, running) current = gcd(current, ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 1 1
O(n)
0.000003
{ "public_tests": [ { "input": "2\n1 1\n", "output": "1\n" }, { "input": "10\n540 648 810 648 720 540 594 864 972 648\n", "output": "54\n" }, { "input": "4\n10 24 40 80\n", "output": "40\n" } ], "private_tests": [ { "input": "2\n10007 20014\n",...
[ 0.03692887500000008, 0.01725903716546185, 0.004506295260319543, 0.004465471931359228, 0.0043149509545986975, 0.00407031561926627, 0.004006306177482078, 0.003942523437426791, 0.0038134986748911636, 0.003662709740860377, 0.0034051594325097264, 0.0032282973638268807, 0.0024023685135814194, 0....
1349_A. Orac and LCM
1871
1871_156
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integ...
from math import gcd n = int(input()) lst = list(map(int, input().split())) lst.sort() g = gcd(lst[0],lst[1]) l = int((lst[0]*lst[1])/(g)) for i in range(2,n): l = gcd(l , int((lst[i]*g)/gcd(g,lst[i]))) g = gcd(g, lst[i]) print(l)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 1 1
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2\n1 1\n", "output": "1\n" }, { "input": "10\n540 648 810 648 720 540 594 864 972 648\n", "output": "54\n" }, { "input": "4\n10 24 40 80\n", "output": "40\n" } ], "private_tests": [ { "input": "2\n10007 20014\n",...
[ 0.0019967902245629555, 0.0003690910602715258, 0.00008057547447279282, 0.00007353452926955856, 0.000060530015816215035, 0.00003264477111893294, 0.00003057869463374271, 0.00002071395132936102, 0.00002054103612259141, 0.000019474632320804197, 0.00001412747466400787, 0.000012571647827991764, 0.0...
1322_A. Unusual Competitions
1168
1168_57
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. The teacher gave Dmitry's class a very strange task — she asked every student...
def fn(): diff = 0 ans = 0 f = 'p' n = int(input()) s = input() if len(s) % 2 == 1: return -1 for i in range(n): if s[i] == '(': diff += 1 elif s[i] == ')': diff -= 1 if diff >= 0: f = 'p' continue elif diff < 0: ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 (()
O(n**2)
0
{ "public_tests": [ { "input": "3\n(()\n", "output": "-1\n" }, { "input": "8\n))((())(\n", "output": "6" } ], "private_tests": [ { "input": "51\n))((((((((()))(())()(()(()())()(()(())(())()())))))\n", "output": "-1\n" }, { "input": "4\n((()\n",...
[ 5.57028065296016e-9, 4.9190708182585615e-9, 4.39949441842425e-9, 3.958146812236166e-9, 3.725516780348223e-9, 3.718266656815627e-9, 3.7032491275729223e-9, 3.541171529474678e-9, 3.164434094422454e-9, 3.1490262392277905e-9, 2.7574584189949343e-9, 2.6606607296724252e-9, 2.657549510462381e-9, 2...
1322_A. Unusual Competitions
1168
1168_24
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. The teacher gave Dmitry's class a very strange task — she asked every student...
input() s = input() t = 0 l = 0 e = -1 for i in range(len(s)): if s[i] == "(": l += 1 if l == 0: t += i-e+1 elif s[i] == ")": l -= 1 if l == -1: e = i if l != 0: print(-1) else: print(t)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 (()
O(n)
0.000001
{ "public_tests": [ { "input": "3\n(()\n", "output": "-1\n" }, { "input": "8\n))((())(\n", "output": "6" } ], "private_tests": [ { "input": "51\n))((((((((()))(())()(()(()())()(()(())(())()())))))\n", "output": "-1\n" }, { "input": "4\n((()\n",...
[ 0.000008174500000000008, 0.000007595500000000002, 0.0000074990000000000005, 0.000006967239633413461, 0.000004699919648710665, 0.0000040604714624060044, 0.0000035354697197333914, 0.0000032522639723557694, 0.0000026704780649038466, 0.0000026523442826704553, 0.0000026332466537368884, 0.0000026134...
975_A. Aramic script
619
619_362
In Aramic language words can only represent objects. Words in Aramic have special properties: * A word is a root if it does not contain the same letter more than once. * A root and all its permutations represent the same object. * The root x of a word y is the word that contains all letters that appear in y ...
t=str(input()) arr = [str(x) for x in input().split()] ss = set() for x in arr: a2 = [] s="" for i in range(int(26)): a2.append(0) for i in range(len(x)): nu = ord(x[i]) nu = nu - ord('a') a2[nu]=1 for i in range(int(26)): ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 a aa aaa ab abb
O(n**2)
0.000001
{ "public_tests": [ { "input": "5\na aa aaa ab abb\n", "output": "2\n" }, { "input": "3\namer arem mrea\n", "output": "1\n" } ], "private_tests": [ { "input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd\n", "output": "6\n" }, { "input": "2\nfh...
[ 0.0001843060516102668, 0.00009318365113428052, 0.00009265305082885551, 0.00009233769862120767, 0.00006828252304687501, 0.000037506410534396635, 0.00003670637051406612, 0.00003463809103136431, 0.00003340864127644056, 0.00003326771521021501, 0.00003307187231940348, 0.000030189073158109723, 0.0...
975_A. Aramic script
619
619_340
In Aramic language words can only represent objects. Words in Aramic have special properties: * A word is a root if it does not contain the same letter more than once. * A root and all its permutations represent the same object. * The root x of a word y is the word that contains all letters that appear in y ...
n = int(input()) s = list(input().split()) dic = dict() for i in s: l2 = list(set(list(i))) l2.sort() l2 = ''.join(l2) if l2 in dic: pass else: dic[l2] = 1 c = 0 #print(dic) for i in dic: c+=1 print(c)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 a aa aaa ab abb
O(nlogn)
0.000181
{ "public_tests": [ { "input": "5\na aa aaa ab abb\n", "output": "2\n" }, { "input": "3\namer arem mrea\n", "output": "1\n" } ], "private_tests": [ { "input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd\n", "output": "6\n" }, { "input": "2\nfh...
[ 0.0012683359386718752, 0.0012402051574218753, 0.0012347208921875, 0.0012251018777343751, 0.0012206510843750004, 0.0012147938257812503, 0.0012130574738281252, 0.0012130377898437502, 0.0012123103949218752, 0.00120854866875, 0.0012083333370480254, 0.0012065449031250003, 0.0012060589515625, 0....
617_A. Elephant
897
897_2438
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order ...
x = int(input()) step = 0 while x != 0: if x >= 5: step += 1 x = x - 5 elif x >= 4: step += 1 x = x - 4 elif x >= 3: step += 1 x = x - 3 elif x >= 2: step += 1 x = x - 2 elif x >= 1: step += 1 x = x - 1 print(int(step)) ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
12
O(n)
0.000001
{ "public_tests": [ { "input": "12\n", "output": "3\n" }, { "input": "5\n", "output": "1\n" } ], "private_tests": [ { "input": "574\n", "output": "115\n" }, { "input": "999997\n", "output": "200000\n" }, { "input": "46573\n"...
[ 0.00004408596294525787, 0.00004264831039663462, 0.00002331703164608829, 0.00002330280711866259, 0.000009515741736778848, 0.000008128523765297202, 0.000007348764491368008, 0.000006702239210008743, 0.000005627117583588288, 0.0000048185741914335665, 0.000004802771989729022, 0.00000417184978693181...
617_A. Elephant
897
897_1880
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order ...
x = int(input()) ans = x // 5 x %= 5 if (x != 0): ans += 1 print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
12
O(1)
0.000002
{ "public_tests": [ { "input": "12\n", "output": "3\n" }, { "input": "5\n", "output": "1\n" } ], "private_tests": [ { "input": "574\n", "output": "115\n" }, { "input": "999997\n", "output": "200000\n" }, { "input": "46573\n"...
[ 0.004754386499999999, 0.0004210745000000002, 0.0002991235, 0.0002491545, 0.0002147265, 0.000181518, 0.00012513050000000005, 0.0000171975, 0.0000171675, 0.000011974500000000002, 0.000010818999999999992, 0.000010567000000000002, 0.000010394000000000002, 0.000010299999999999993, 0.000010212...
1345_B. Card Constructions
577
577_656
A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h-1 onto a base. A base consists of h pyramids of height 1, and h-1 cards on top. For example, card pyramids of heights 1, 2, and 3 look as follows: ...
from typing import List def pyramid(): n = int(input()) aux = n respuesta = 1 altura = 1 if(n<2): respuesta = 0 while(aux>=2): aux = aux - 2*altura - altura + 1 if( aux < 0 ): aux = aux + 2*altura + altura - 1 altura = 1 respuesta = res...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 3 14 15 24 1
O(n**2)
0.000018
{ "public_tests": [ { "input": "5\n3\n14\n15\n24\n1\n", "output": "1\n2\n1\n3\n0\n" } ], "private_tests": [ { "input": "50\n11833308\n5211498\n64660\n9077929\n2699416\n2432035\n234901\n1337830\n8457191\n10523566\n5722429\n5452712\n5511654\n8587879\n348160\n3141182\n2661936\n395300\n6...
[ 0.3182614705, 0.03686537761619719, 0.00004135760480475641, 0.00003806959222018539, 0.00003591423564199155, 0.00003316041149504013, 0.00003301722534526273, 0.00003266471825870747, 0.000032056875184538216, 0.00003036196398734924, 0.00002970903687886523, 0.000029175168931966195, 0.0000290291794...
1345_B. Card Constructions
577
577_509
A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h-1 onto a base. A base consists of h pyramids of height 1, and h-1 cards on top. For example, card pyramids of heights 1, 2, and 3 look as follows: ...
check=[2] i=0 while check[-1]<=10**9: check.append(check[-1]+3*i+5) i+=1 from bisect import bisect_right def dfs(x): if x<2: return 0 return dfs(x-check[bisect_right(check,x)-1])+1 for _ in range(int(input())): n=int(input()) print(dfs(n))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 3 14 15 24 1
O(n)
0.00002
{ "public_tests": [ { "input": "5\n3\n14\n15\n24\n1\n", "output": "1\n2\n1\n3\n0\n" } ], "private_tests": [ { "input": "50\n11833308\n5211498\n64660\n9077929\n2699416\n2432035\n234901\n1337830\n8457191\n10523566\n5722429\n5452712\n5511654\n8587879\n348160\n3141182\n2661936\n395300\n6...
[ 0.3186817905, 0.307629582, 0.301700438, 0.10694257537288136, 0.09875733510169493, 0.09797151494915254, 0.05010046130633803, 0.05001116141197184, 0.047720826961267615, 0.042682507059859154, 0.03559876139084507, 0.033735088535211274, 0.029253859096385542, 0.028730357158450705, 0.0286924635...
1029_C. Maximal Intersection
1333
1333_58
You are given n segments on a number line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide. The intersection of a sequence of segments is such a maximal set of points (not necesserily having...
n = int(input()) l, r = [], [] a, b = 0, 0 for i in range(n): a, b = map(int, input().split()) l.append(a) r.append(b) minr = 10**10 maxl = -1 l1 = -1 r1 = -1 for i in range(n): if l[i] > maxl: maxl = l[i] l1 = i if r[i] < minr: minr = r[i] r1 = i l_1 = l.copy() l_2 =...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 3 10 1 5
O(n)
0.000008
{ "public_tests": [ { "input": "2\n3 10\n1 5\n", "output": "7\n" }, { "input": "5\n2 6\n1 3\n0 4\n1 20\n0 4\n", "output": "2\n" }, { "input": "4\n1 3\n2 6\n0 4\n3 3\n", "output": "1\n" }, { "input": "3\n4 5\n1 2\n9 20\n", "output": "0\n" ...
[ 0.00006013489350688375, 0.000032867072921219406, 0.000032607883809549825, 0.00003093386614947553, 0.00002551493956239074, 0.00002224091623415647, 0.00002059293919361888, 0.00002014491912969843, 0.000018879745998142485, 0.000018158814111669583, 0.000018059213122814685, 0.000017879335596044582, ...
1029_C. Maximal Intersection
1333
1333_127
You are given n segments on a number line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide. The intersection of a sequence of segments is such a maximal set of points (not necesserily having...
n = int(input()) L = [] R = [] S = [] for _ in range(n): a,b = [int(x) for x in input().split()] L.append(a) R.append(b) S.append((a,b)) L.sort(reverse = True) R.sort() if (L[0],R[0]) in S: print(max(R[1]-L[1],0)) else: print(max(R[0]-L[1],R[1]-L[0],0))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 3 10 1 5
O(nlogn)
0.000011
{ "public_tests": [ { "input": "2\n3 10\n1 5\n", "output": "7\n" }, { "input": "5\n2 6\n1 3\n0 4\n1 20\n0 4\n", "output": "2\n" }, { "input": "4\n1 3\n2 6\n0 4\n3 3\n", "output": "1\n" }, { "input": "3\n4 5\n1 2\n9 20\n", "output": "0\n" ...
[ 0.000020716858674227997, 0.00001440352017251919, 0.000013234265845727208, 0.000011400375249232763, 0.000011286910941903415, 0.000011193764429980278, 0.000011161331334245002, 0.000011140512087161246, 0.000011133527767760614, 0.000011107653965090663, 0.00001109600302841008, 0.0000110859272915871...
1365_C. Rotation Matching
2188
2188_371
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b. Note that a permutation of n elements is a sequence of numbers a_1, a_2, …, a_n, in ...
n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) ga={} gb={} for i in range(n):ga[a[i]]=i;gb[b[i]]=i g={} for i in range(1,n+1):o=(gb[i]-ga[i])%n;g[o]=g[o]+1if g.get(o)else 1 print(max(g[i]for i in g))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 1 2 3 4 5 2 3 4 5 1
O(n*m)
0.000001
{ "public_tests": [ { "input": "5\n1 2 3 4 5\n2 3 4 5 1\n", "output": "5\n" }, { "input": "4\n1 3 2 4\n4 2 3 1\n", "output": "2\n" }, { "input": "5\n5 4 3 2 1\n1 2 3 4 5\n", "output": "1\n" } ], "private_tests": [ { "input": "18\n11 16 18 3 7 1...
[ 0.0000028733410183566432, 0.0000023832848147945807, 0.000002344458506337413, 0.00000233756950666521, 0.0000023297260981206293, 0.000002306253728693182, 0.000002204059959571678, 0.000002163293241914336, 0.000002149704763986014, 0.0000020712843504152098, 0.0000020590275622814686, 0.0000020359435...
1365_C. Rotation Matching
2188
2188_359
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b. Note that a permutation of n elements is a sequence of numbers a_1, a_2, …, a_n, in ...
n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) dif = [0]*n a = list(enumerate(a)) b = list(enumerate(b)) a.sort(key = lambda x:x[1]) b.sort(key = lambda x:x[1]) for i in range(n): q1 = a[i][0] q2 = b[i][0] if q2-q1<0: dif[i]=(n+(q2-q1)) else: dif[i...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 1 2 3 4 5 2 3 4 5 1
O(nlogn)
0.00003
{ "public_tests": [ { "input": "5\n1 2 3 4 5\n2 3 4 5 1\n", "output": "5\n" }, { "input": "4\n1 3 2 4\n4 2 3 1\n", "output": "2\n" }, { "input": "5\n5 4 3 2 1\n1 2 3 4 5\n", "output": "1\n" } ], "private_tests": [ { "input": "18\n11 16 18 3 7 1...
[ 0.00004403277878775281, 0.00003387863115534059, 0.00003164950372852682, 0.00003148392810120345, 0.00003133927484636751, 0.00003052473481283265, 0.00003052469829194747, 0.000030441203608095335, 0.000030366068926481388, 0.000030024266209497686, 0.000029837878088568507, 0.000029612119901263015, ...
195_A. Let's Watch Football
1580
1580_12
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si...
a,b,c=map(int,input().split()) val=b res=[val] i=2 while(val<a*c): val=b*i res+=[val] i+=1 n=len(res) l=0 h=n-1 ans=-1 #print(res) while(l<=h): mid=l+(h-l)//2 if(res[mid]+b*(c-1)<a*c): ans=mid l=mid+1 else: h=mid-1 #print(mid) print(ans+1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
10 3 2
O(n+m)
0.000005
{ "public_tests": [ { "input": "10 3 2\n", "output": "5\n" }, { "input": "13 12 1\n", "output": "1\n" }, { "input": "4 1 1\n", "output": "3\n" } ], "private_tests": [ { "input": "993 992 991\n", "output": "1\n" }, { "input":...
[ 0.016158049, 0.000009609706416630245, 0.000006096801955856644, 0.000006032003141389861, 0.000005962617788461539, 0.000005586940409200175, 0.000005558271484375, 0.000005499581676136364, 0.0000049432978174169585, 0.000004700566515515734, 0.0000046281026141826925, 0.000004595230646306818, 0.000...
195_A. Let's Watch Football
1580
1580_118
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si...
a , b, c = list(map(int, input().split())) t = a*c if t%b == 0: print(t//b - c) else: print(t//b -c +1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
10 3 2
O(1)
0.000002
{ "public_tests": [ { "input": "10 3 2\n", "output": "5\n" }, { "input": "13 12 1\n", "output": "1\n" }, { "input": "4 1 1\n", "output": "3\n" } ], "private_tests": [ { "input": "993 992 991\n", "output": "1\n" }, { "input":...
[ 0.002319113499999914, 0.000016668499999999998, 0.000015647000000000008, 0.000014330499999999994, 0.000013957000000000002, 0.000011014500000000001, 0.000010289000000000003, 0.000003012500000000002, 0.0000029435000000000032, 0.000002841000000000002, 0.000002808000000000001, 0.0000026469999999999...
1261_B1. Optimal Subsequences (Easy Version)
1338
1338_61
This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems. You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily...
import copy a=[] ai=[] otv='' n=int(input()) a=list(map(int,input().split())) m=int(input()) for i in range(1,m+1): #print(ai) #print(a,'kkkk') ai=copy.deepcopy(a) ai.reverse() #print(ai) k,pos=map(int,input().split()) for j in range(1,n-k+1): #print(min(ai)) ai.remove(min(ai...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
7 1 2 1 3 1 2 1 9 2 1 2 2 3 1 3 2 3 3 1 1 7 1 7 7 7 4
O(n*m)
0.0001
{ "public_tests": [ { "input": "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "output": "2\n3\n2\n3\n2\n3\n1\n1\n3\n" }, { "input": "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "output": "20\n10\n20\n10\n20\n10\n" } ], "private_tests": [ { ...
[ 0.08919967205084747, 0.046495095380281695, 0.0056744482846183344, 0.004398409257274047, 0.002172401212324009, 0.0015109169859592677, 0.00010018440095061189, 0.00010015263342711976, 5.363171984265736e-10 ]
1261_B1. Optimal Subsequences (Easy Version)
1338
1338_48
This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems. You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily...
n = int(input()) a = [int(i) for i in input().split()] b = [(a[i], n - i) for i in range(n)] b.sort(reverse=True) b = [(b[i][0], n - b[i][1]) for i in range(n)] m = int(input()) for qu in range(m): k, p = map(int, input().split()) c = b[:k] c.sort(key = lambda x: x[1]) print(c[p-1][0])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
7 1 2 1 3 1 2 1 9 2 1 2 2 3 1 3 2 3 3 1 1 7 1 7 7 7 4
O(n+mlogm)
0.000208
{ "public_tests": [ { "input": "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "output": "2\n3\n2\n3\n2\n3\n1\n1\n3\n" }, { "input": "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "output": "20\n10\n20\n10\n20\n10\n" } ], "private_tests": [ { ...
[ 0.0003959713724578332, 0.000312105738234747, 0.0002554271814043035, 0.00024072304175383973, 0.00023670669072977846, 0.00023481295065167531, 0.00023187326983875755, 0.00023100672023287068, 0.00022611978099738408, 0.00022008326990494666, 0.00021807264688954183, 0.00021082141452535196, 0.000207...
p02293 Parallel/Orthogonal
2183
2183_1
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise. s1 crosses points p0 and p1, and s2 crosses points p2 and p3. Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xpi, ypi ≤ 10000 * p0 ≠ p1 and p2 ≠ p3. Input The entire input looks like: q (the number of queries) 1st...
EPS = 1e-4 #外積 def OuterProduct(one, two): tmp = one.conjugate() * two return tmp.imag #内積 def InnerProduct(one, two): tmp = one.conjugate() * two return tmp.real def solve(a, b, c, d): if abs(OuterProduct(b-a, d-c)) <= EPS: return 2 elif abs(InnerProduct(b-a, d-c)) <= EPS: return 1 else: return 0 n = ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 0 0 3 0 0 2 3 2 0 0 3 0 1 1 1 4 0 0 3 0 1 1 2 2
O(n*m)
0.000011
{ "public_tests": [ { "input": "3\n0 0 3 0 0 2 3 2\n0 0 3 0 1 1 1 4\n0 0 3 0 1 1 2 2", "output": "2\n1\n0" } ], "private_tests": [], "generated_tests": [ { "input": "3\n0 0 3 0 0 2 3 2\n0 0 3 0 1 1 1 7\n0 0 3 0 1 1 2 2", "output": "2\n1\n0\n" }, { "input": "3\n0...
[ 0.000011891202018684442, 0.000011652915401005246, 0.000011214104362434442, 0.000011021242829436189, 0.000010883836879916958, 0.000010735305001638987, 0.00001073460637019231, 0.000010569510789991258, 0.00000497425823590472, 0.000004480947306599651, 4.2145842438811173e-10 ]
p02293 Parallel/Orthogonal
2183
2183_2
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise. s1 crosses points p0 and p1, and s2 crosses points p2 and p3. Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xpi, ypi ≤ 10000 * p0 ≠ p1 and p2 ≠ p3. Input The entire input looks like: q (the number of queries) 1st...
q=int(input()) for _ in [0]*q: x0,y0,x1,y1,x2,y2,x3,y3=map(int,input().split()) a1=x1-x0 a2=x3-x2 b1=y1-y0 b2=y3-y2 parallel=a1*b2-a2*b1 orthogonal=a1*a2+b1*b2 if parallel==0: print("2") elif orthogonal==0: print("1") else: print("0")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 0 0 3 0 0 2 3 2 0 0 3 0 1 1 1 4 0 0 3 0 1 1 2 2
O(n)
0.000024
{ "public_tests": [ { "input": "3\n0 0 3 0 0 2 3 2\n0 0 3 0 1 1 1 4\n0 0 3 0 1 1 2 2", "output": "2\n1\n0" } ], "private_tests": [], "generated_tests": [ { "input": "3\n0 0 3 0 0 2 3 2\n0 0 3 0 1 1 1 7\n0 0 3 0 1 1 2 2", "output": "2\n1\n0\n" }, { "input": "3\n0...
[ 0.00008279999075338724, 0.00006610086929086539, 0.00004739289539171766, 0.00004622015032233392, 0.00003605205024857955, 0.000035179383427119756, 0.00003390392747486888, 0.00003243275363308566, 0.00003202344141990822, 0.00003125420558347902, 0.000029177025062827802, 0.000028181797762784093, 0...
1042_A. Benches
61
61_295
There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people c...
n = int(input()) m = int(input()) l = [] for i in range(n): l.append(int(input())) mz = max(l) mx = mz + m s1 = sum(l) s2 = s1 + m x = s2 // n y = s2 % n if y == 0: if mz < x: mn = x else: mn = mz elif y <=n: if mz <= x: mn = x + 1 else: mn = mz else: z1 = y // n z2 = y % n if mz <...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 6 1 1 1 1
O(n)
0.000008
{ "public_tests": [ { "input": "4\n6\n1\n1\n1\n1\n", "output": "3 7\n" }, { "input": "1\n10\n5\n", "output": "15 15\n" }, { "input": "3\n6\n1\n6\n5\n", "output": "6 12\n" }, { "input": "3\n7\n1\n6\n5\n", "output": "7 13\n" } ], "priva...
[ 0.00008875747165234009, 0.00004445732847370709, 0.00002187412920984549, 0.000012236320361220068, 0.000012146721577250876, 0.000011384577652817787, 0.000011375597647695324, 0.000010474909997150989, 0.000010371328433418036, 0.000010336788324234725, 0.00001020541881037961, 0.000010090183110832286...
1042_A. Benches
61
61_161
There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available. Let k be the maximum number of people sitting on one bench after additional m people c...
n = int(input()) m = int(input()) a = [] _sum = 0 for i in range(n): j = int(input()) a.append(j) _sum += j #print(a) a = sorted(a) if n == 1: print(m + a[0], m + a[0]) else: _max = m + a[-1] temp = a[-1] * n if temp- _sum >= m: print(a[-1], _max) else: m -= temp - _...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 6 1 1 1 1
O(nlogn)
0.000011
{ "public_tests": [ { "input": "4\n6\n1\n1\n1\n1\n", "output": "3 7\n" }, { "input": "1\n10\n5\n", "output": "15 15\n" }, { "input": "3\n6\n1\n6\n5\n", "output": "6 12\n" }, { "input": "3\n7\n1\n6\n5\n", "output": "7 13\n" } ], "priva...
[ 0.0001350068504758424, 0.00006267336465039182, 0.000032883604727056106, 0.000013913114790434757, 0.000012107066355442672, 0.000011594069125544274, 0.000011399641251593006, 0.000011134748536292605, 0.000011031269578792643, 0.000011029842368127203, 0.00001098435112391685, 0.00001095937992699229,...
p03714 AtCoder Beginner Contest 062 - 3N Numbers
3029
3029_114
Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements ...
import heapq N=int(input()) a=list(map(int,input().split())) l=[None]*(N+1) r=[None]*(N+1) h=a[:N] s=sum(h) heapq.heapify(h) l[0]=s for i in range(N): heapq.heappush(h,a[i+N]) s+=a[i+N]-heapq.heappop(h) l[i+1]=s h=list(map(lambda x:-x,a[2*N:])) heapq.heapify(h) s=sum(h) r[-1]=s for i in range(N): heapq....
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 3 1 4 1 5 9
O(n+m)
0.000009
{ "public_tests": [ { "input": "2\n3 1 4 1 5 9", "output": "1" }, { "input": "1\n1 2 3", "output": "-1" }, { "input": "3\n8 2 2 7 4 6 5 3 8", "output": "5" } ], "private_tests": [], "generated_tests": [ { "input": "2\n3 1 4 1 7 9", "out...
[ 0.000015375083593750002, 0.000013763668750000003, 0.000013535675042951003, 0.000013345247265625, 0.000012915557657940253, 0.000012670437501618757, 0.000012428381250000003, 0.000012364901562500003, 0.000012105650458916084, 0.000012089819411057694, 0.000012045681250000003, 0.0000115722234375, ...
p03714 AtCoder Beginner Contest 062 - 3N Numbers
3029
3029_74
Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements ...
import heapq N=int(input()) A=list(map(int,input().split())) R=sorted(A[:N]) SUM1=[sum(A[:N])] for i in range(N,2*N): heapq.heappush(R,A[i]) tmp=heapq.heappop(R) SUM1.append(SUM1[-1]+A[i]-tmp) B=list(map(lambda x:x*(-1),A[2*N:3*N])) B.sort() SUM2=[-sum(B)] for i in range(2*N-1,N-1,-1): heapq.heappush...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 3 1 4 1 5 9
O(nlogn)
0.000077
{ "public_tests": [ { "input": "2\n3 1 4 1 5 9", "output": "1" }, { "input": "1\n1 2 3", "output": "-1" }, { "input": "3\n8 2 2 7 4 6 5 3 8", "output": "5" } ], "private_tests": [], "generated_tests": [ { "input": "2\n3 1 4 1 7 9", "out...
[ 0.00008105497695312503, 0.00007737911250000002, 0.00004207561015625, 0.000024870404687500003, 0.000024113540527612596, 0.00001793519480521021, 0.000017811191594118737, 0.000017357050647301775, 0.000017330493382343293, 0.000014557213055998467, 0.00001342399500317749, 0.000011138247236160077, ...
1184_A1. Heidi Learns Hashing (Easy)
167
167_177
Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor. Heidi figured out that Madame Kovarian uses a...
import math n = int(input()) x = math.floor(math.sqrt(n)) p = 0 for i in range(1, x): if (n-1-i**2-i)%(2*i) == 0 : print(i, (n-1-i**2-i)//(2*i)) p = 1 break if not p: print("NO")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
19
O(n)
0
{ "public_tests": [ { "input": "19\n", "output": "1 8\n" }, { "input": "16\n", "output": "NO\n" } ], "private_tests": [ { "input": "768407398177\n", "output": "1 384203699087\n" }, { "input": "7\n", "output": "1 2\n" }, { "i...
[ 1.0118403081293706e-7, 9.507236123251748e-8, 8.235933402534967e-8, 8.120229184877623e-8, 8.112829163024476e-8, 8.036918159965036e-8, 8.022708151223776e-8, 7.98541575611888e-8, 7.705240657779721e-8, 7.6265625e-8, 7.556543651660841e-8, 7.42185041520979e-8, 7.245748197115384e-8, 7.19361478365...
1184_A1. Heidi Learns Hashing (Easy)
167
167_191
Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor. Heidi figured out that Madame Kovarian uses a...
def calculate(n): if (n < 5) or (n%2 == 0): return 'NO' else: y = int((n-3)/2) return "1 "+str(y) print (calculate(int(input())))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
19
O(1)
0.000001
{ "public_tests": [ { "input": "19\n", "output": "1 8\n" }, { "input": "16\n", "output": "NO\n" } ], "private_tests": [ { "input": "768407398177\n", "output": "1 384203699087\n" }, { "input": "7\n", "output": "1 2\n" }, { "i...
[ 0.376345574, 0.00003381, 0.000022641500000000003, 0.000014075499999999998, 0.000009752499999999999, 0.000007779000000000001, 0.000007094999999999999, 0.000007038500000000004, 0.0000063499999999999985, 0.000003996500000000015, 0.0000029434999999999965, 0.0000027720000000000033, 0.000002712000...
879_A. Borya's Diagnosis
827
827_148
It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the...
n = int(input()) arr = [[0,0] for i in range(n)] for i in range(n): arr[i][0] , arr[i][1] = map(int , input().split()) # arr.sort(key = lambda x: x[1]) dates = [arr[0][0]] for i,j in arr[1:]: while i<=dates[-1] : i += j dates.append(i) print(dates[-1])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 10 1 6 5
O(n**2)
0.000001
{ "public_tests": [ { "input": "2\n10 1\n6 5\n", "output": "11\n" }, { "input": "3\n2 2\n1 2\n2 2\n", "output": "4\n" } ], "private_tests": [ { "input": "2\n5 5\n15 5\n", "output": "15\n" }, { "input": "2\n1 1\n10 1\n", "output": "10\n" ...
[ 0.000011189321129589714, 0.000009067832481028177, 0.000008659442249970504, 0.000008554562504136823, 0.00000818633099465019, 0.000008168458486455687, 0.000008124657079792455, 0.000008086589189873636, 0.000007325805772269049, 0.000007198243714189514, 0.000007180105128507665, 0.000001458059514871...
879_A. Borya's Diagnosis
827
827_40
It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the...
# n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for i in range(m): # for _ in range(int(input())): #from collections import Counter #from fractions import Fraction #s=iter(input()) from collections import deque import math ls=[] for i in range(int...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 10 1 6 5
O(nlogn)
0.000001
{ "public_tests": [ { "input": "2\n10 1\n6 5\n", "output": "11\n" }, { "input": "3\n2 2\n1 2\n2 2\n", "output": "4\n" } ], "private_tests": [ { "input": "2\n5 5\n15 5\n", "output": "15\n" }, { "input": "2\n1 1\n10 1\n", "output": "10\n" ...
[ 0.00000200173561988205, 0.0000018971451158333268, 0.0000018807160108005525, 0.0000017652954959840078, 0.000001699679774279578, 0.000001680352142122168, 0.0000016755684250372438, 0.0000016607833374929269, 0.0000016358116410336154, 0.000001621422255812871, 0.0000015988986254435825, 0.00000157177...
1187_A. Stickers and Toys
1231
1231_51
Your favorite shop sells n Kinder Surprise chocolate eggs. You know that exactly s stickers and exactly t toys are placed in n eggs in total. Each Kinder Surprise can be one of three types: * it can contain a single sticker and no toy; * it can contain a single toy and no sticker; * it can contain both a sing...
t=int(input()) for i in range(t): l=list(map(int,input().split())) print(max(l[0]-l[1],l[0]-l[2])+1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 10 5 7 10 10 10 2 1 1
O(n*m)
0.000004
{ "public_tests": [ { "input": "3\n10 5 7\n10 10 10\n2 1 1\n", "output": "6\n1\n2\n" } ], "private_tests": [ { "input": "4\n1 1 1\n1000000000 1000000000 1000000000\n1000000000 999999999 1\n999999999 666666667 666666666\n", "output": "1\n1\n1000000000\n333333334\n" }, { ...
[ 0.000005582929018247378, 0.000005570910128933567, 0.000004737013426027098, 0.000004289859375, 0.000004247297298404721, 0.0000042134589707167834, 0.000004205796670126749, 0.000004176148177993882, 0.000004174386541193182, 0.000004167573822661714, 0.000004154402453015734, 0.000004151993061625875,...
1187_A. Stickers and Toys
1231
1231_541
Your favorite shop sells n Kinder Surprise chocolate eggs. You know that exactly s stickers and exactly t toys are placed in n eggs in total. Each Kinder Surprise can be one of three types: * it can contain a single sticker and no toy; * it can contain a single toy and no sticker; * it can contain both a sing...
T=int(input()) for t in range(0,T): n,s,t=map(int,input().split()) print(max(n-s+1,n-t+1))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 10 5 7 10 10 10 2 1 1
O(n)
0
{ "public_tests": [ { "input": "3\n10 5 7\n10 10 10\n2 1 1\n", "output": "6\n1\n2\n" } ], "private_tests": [ { "input": "4\n1 1 1\n1000000000 1000000000 1000000000\n1000000000 999999999 1\n999999999 666666667 666666666\n", "output": "1\n1\n1000000000\n333333334\n" }, { ...
[ 0.000023402000000000004, 0.000021921412819602276, 0.000020992447811953672, 0.000020879591646634613, 0.00002011376148656032, 0.000019741254985249125, 0.0000196610957850743, 0.000019592769572224653, 0.000019429346754807695, 0.000019416823371940563, 0.00001928952891444493, 0.000019034984142810317...
1223_B. Strings Equalization
392
392_537
You are given two strings of equal length s and t consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa. ...
n = int(input()) for i in range(0, n): first_string = input() second_string = input() map = {} for i in range(0, len(first_string)): if first_string[i] in map: map[first_string[i]]+=1 else: map[first_string[i]] = 1 same = False for i in range(0, l...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 xabb aabx technocup technocup a z
O(n**2)
0.000015
{ "public_tests": [ { "input": "3\nxabb\naabx\ntechnocup\ntechnocup\na\nz\n", "output": "YES\nYES\nNO\n" } ], "private_tests": [], "generated_tests": [ { "input": "3\nxabb\naabx\nteohnccup\ntechnocup\na\nz\n", "output": "YES\nYES\nNO\n" }, { "input": "3\nbcbw\nx...
[ 0.00008289105576291623, 0.00003862956548264838, 0.000031321791466780244, 0.000031157921096782926, 0.000029775159676996975, 0.00002955034960243346, 0.000028988472990511935, 0.000026630974839491324, 0.000026232705918748507, 0.00002582471490032778, 0.000025724470944403998, 0.00002556522514669529,...
1223_B. Strings Equalization
392
392_411
You are given two strings of equal length s and t consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa. ...
from sys import stdin, stdout from math import gcd input = stdin.readline for _ in range(int(input())): s = input()[:-1] t = input()[:-1] if set(s) & set(t): print('YES') else: print('NO')
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 xabb aabx technocup technocup a z
O(n)
0.000014
{ "public_tests": [ { "input": "3\nxabb\naabx\ntechnocup\ntechnocup\na\nz\n", "output": "YES\nYES\nNO\n" } ], "private_tests": [], "generated_tests": [ { "input": "3\nxabb\naabx\nteohnccup\ntechnocup\na\nz\n", "output": "YES\nYES\nNO\n" }, { "input": "3\nbcbw\nx...
[ 0.00015463068699440847, 0.00008210726780128292, 0.000057847221875000005, 0.00005753270859375001, 0.00003663656349409622, 0.00002941967985749189, 0.000028697306674455883, 0.000028397621147719786, 0.00002782812843284248, 0.00002730400249504301, 0.000027131402527849806, 0.000026923842501489254, ...
1421_C. Palindromifier
450
450_276
Ringo found a string s of length n in his [yellow submarine](https://www.youtube.com/watch?v=m2uTFF_3MaA). The string contains only lowercase letters from the English alphabet. As Ringo and his friends love palindromes, he would like to turn the string s into a palindrome by applying two types of operations to the stri...
def isPalin(st): i,j=0,len(st)-1 while(i<=j): if(st[i]==st[j]): i+=1 j-=1 else: return False return True def proC(st): if(isPalin(st)): print(0) return print(3) print('R',len(st)-1) print('L',len(st)) pri...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
acccc
O(n)
0.000001
{ "public_tests": [ { "input": "acccc\n", "output": "3\nL 2\nR 2\nR 9\n" }, { "input": "abac\n", "output": "3\nL 2\nR 2\nR 7\n" }, { "input": "hannah\n", "output": "3\nL 2\nR 2\nR 11\n" } ], "private_tests": [ { "input": "vux\n", "output"...
[ 0.00001270903549770542, 0.0000020568354048295456, 0.000001968432337194056, 0.0000013467424743225526, 0.0000013368237680288462, 0.0000013310721700174827, 0.0000013284788570804198, 0.0000013230681408435317, 0.0000013170221672858392, 9.899129015515736e-7, 9.756577387456296e-7, 9.258791247814685e-...
1421_C. Palindromifier
450
450_204
Ringo found a string s of length n in his [yellow submarine](https://www.youtube.com/watch?v=m2uTFF_3MaA). The string contains only lowercase letters from the English alphabet. As Ringo and his friends love palindromes, he would like to turn the string s into a palindrome by applying two types of operations to the stri...
print('3 L 2 R 2 R',len(input())*2-1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
acccc
O(1)
0.000002
{ "public_tests": [ { "input": "acccc\n", "output": "3\nL 2\nR 2\nR 9\n" }, { "input": "abac\n", "output": "3\nL 2\nR 2\nR 7\n" }, { "input": "hannah\n", "output": "3\nL 2\nR 2\nR 11\n" } ], "private_tests": [ { "input": "vux\n", "output"...
[ 0.0005997019999999936, 0.00002424900000000001, 0.000009123, 0.000007227500000000005, 0.000006981500000000001, 0.0000061764999999999975, 0.000005139999999999995, 0.0000051175, 0.0000049830000000000165, 0.000004901500000000007, 0.0000047625000000000006, 0.000004540999999999996, 0.0000041909999...
263_A. Beautiful Matrix
531
531_3456
You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
col=row=1 for i in range (0,5): a=list(input().split()) if(len(set(a))==1): row+=1 else: col=a.index('1')+1 ; break print(abs(3-row)+abs(3-col))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
O(n)
0.000005
{ "public_tests": [ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "output": "3\n" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "output": "1\n" } ], "private_tests": [ { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n...
[ 0.00025862184278026664, 0.00007225786180616259, 0.00007049767436079546, 0.00006436570401278409, 0.00006194116993553321, 0.000058789068373033224, 0.00005875827570476398, 0.000057047117228474653, 0.00005431463533927011, 0.00005378150293651661, 0.000043681204996175705, 0.00003867271204381556, 0...
263_A. Beautiful Matrix
531
531_3499
You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
# n=int(input()) # x=list(map(int,input().split())) # x.sort() # print(x) # fi=fj=0 # for i in range(5): # x=input().split() # k=0 # for j in x: # if j=="1": # fi=i # fj=k # k+=1 # t1,t2=abs(fi-2),abs(fj-2) # print(t1+t2) for i in range(5): try: print(abs(2-i) + abs(2-input().split().index("...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
O(nlogn)
0.000005
{ "public_tests": [ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "output": "3\n" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "output": "1\n" } ], "private_tests": [ { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n...
[ 0.00009103878059440559, 0.00004190075239018794, 0.00003394560527753497, 0.000031842309741040214, 0.00003124672238308567, 0.00003123802403846154, 0.00003095540971918706, 0.00002991107409582605, 0.00002982838375491696, 0.000027557485754479897, 0.000026691096672858394, 0.000026592245738636365, ...
834_B. The Festive Evening
1830
1830_16
<image> It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in th...
n,k=map(int,input().split()) s=input() m=0 a=[0]*30 b=[0]*30 for i in s: q=ord(i)-65 a[q]+=1 for i in s: q=ord(i)-65 if a[q]>0: if b[q]==0: if k==0: m=1 break b[q]=1 k-=1 a[q]-=1 if a[q]==0: k+=1 ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 1 AABBB
O(n)
0.000004
{ "public_tests": [ { "input": "5 1\nAABBB\n", "output": "NO\n" }, { "input": "5 1\nABABB\n", "output": "YES\n" } ], "private_tests": [ { "input": "433 3\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVI...
[ 0.000028952027207167834, 0.000011692967486740588, 0.000007815265187937064, 0.000007570596618225525, 0.000007117292463395979, 0.0000066013675426136375, 0.000006179611630871768, 0.000006010186958436095, 0.000005459696764501898, 0.000005429781385885597, 0.000005408996952421516, 0.0000050752398382...
834_B. The Festive Evening
1830
1830_0
<image> It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in th...
import sys n, k = map(int, input().split()) a = list(input()) st = [0] * 26 ed = [0] * 26 for i in range(n): if st[ord(a[i])-65] == 0: st[ord(a[i])-65] = i + 1 else: ed[ord(a[i])-65] = i + 1 for i in range(26): if st[i] != 0 and ed[i] == 0: ed[i] = st[i] n = 52 i = 0 j = 0 maxi = -1 * sys.maxsize l = 0 st.sort...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 1 AABBB
O(nlogn)
0
{ "public_tests": [ { "input": "5 1\nAABBB\n", "output": "NO\n" }, { "input": "5 1\nABABB\n", "output": "YES\n" } ], "private_tests": [ { "input": "433 3\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVI...
[ 0.000003889640129615614, 0.0000037864966405927826, 0.000003759636590671607, 0.0000037547780523057133, 0.00000309375305944056, 8.451371069763466e-7, 7.994175273102422e-7, 7.575767686707765e-7, 6.779460879532076e-7, 6.671359683270511e-7, 6.661059808783907e-7, 6.636686243021097e-7, 6.6137322125...
1328_A. Divisibility Problem
171
171_82
You are given two positive integers a and b. In one move you can increase a by 1 (replace a with a+1). Your task is to find the minimum number of moves you need to do in order to make a divisible by b. It is possible, that you have to make 0 moves, as a is already divisible by b. You have to answer t independent test c...
num = int(input()) for i in range(num): l = input().split() a = int(l[0]) b = int(l[1]) if a % b == 0: print(0) else: print(int(b - (a % b)))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 10 4 13 9 100 13 123 456 92 46
O(n*m)
0.000002
{ "public_tests": [ { "input": "5\n10 4\n13 9\n100 13\n123 456\n92 46\n", "output": "2\n5\n4\n333\n0\n" } ], "private_tests": [ { "input": "1\n515151 2\n", "output": "1\n" }, { "input": "21\n1 3218\n28 10924\n908802 141084\n82149 9274\n893257 10248\n2750048 802705...
[ 0.000023947063141936188, 0.000006045236464707169, 0.000004166286535729895, 0.0000041025426682692306, 0.000003877157725087413, 0.0000038185202687937065, 0.000003816692075502622, 0.0000037818557828889866, 0.0000036376915838068183, 0.000001935904611013986, 0.000001935822893902972, 0.0000019234604...
1328_A. Divisibility Problem
171
171_0
You are given two positive integers a and b. In one move you can increase a by 1 (replace a with a+1). Your task is to find the minimum number of moves you need to do in order to make a divisible by b. It is possible, that you have to make 0 moves, as a is already divisible by b. You have to answer t independent test c...
t=int(input()) for i in range(0,t): a,b=input().split() a=int(a) b=int(b) print((b-a%b)%b)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 10 4 13 9 100 13 123 456 92 46
O(n)
0
{ "public_tests": [ { "input": "5\n10 4\n13 9\n100 13\n123 456\n92 46\n", "output": "2\n5\n4\n333\n0\n" } ], "private_tests": [ { "input": "1\n515151 2\n", "output": "1\n" }, { "input": "21\n1 3218\n28 10924\n908802 141084\n82149 9274\n893257 10248\n2750048 802705...
[ 0.00002808704117952361, 0.000027029078043050702, 0.0000251626017263986, 0.000025087284254807696, 0.00002499912713068182, 0.00002465115465198864, 0.000024226548145214157, 0.000024092881583260493, 0.0000236925760899257, 0.000023671278190559443, 0.000023639649024803324, 0.000023533747282014863, ...
1023_C. Bracket Subsequence
1935
1935_61
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are r...
R = lambda:list(map(int,input().split())) n,t = R() s = input() st = [] req = n-t flag = 0 for x in s: if(x==")" and flag==0 and req>0): req-=2 st.pop() if(req==0): flag = 1 else: st.append(x) print("".join(st))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
8 8 (()(()))
O(n+m)
0.000003
{ "public_tests": [ { "input": "8 8\n(()(()))\n", "output": "(()(()))\n" }, { "input": "6 4\n()(())\n", "output": "()()\n" } ], "private_tests": [ { "input": "20 10\n((()))()((()()(())))\n", "output": "((()))()()\n" }, { "input": "2 2\n()\n", ...
[ 0.000012993989674493294, 0.000010050224861794187, 0.000008849769381009616, 0.000008466176408461852, 0.000008062839707167833, 0.00000764528109091223, 0.000006811012005572552, 0.000006743688756555944, 0.000006641537314248253, 0.0000064845144913680075, 0.000006155260107080419, 0.00000613928687718...
1023_C. Bracket Subsequence
1935
1935_144
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are r...
aa,bb=map(int, input().split()) s=input() kiri=[] tupl=[] ini=[] cetak="" for i in range(len(s)): if s[i]=="(": kiri.append(i) else: tupl.append((kiri.pop(),i)) tupl=tupl[:bb//2] for k in tupl: ini.extend(k) ini.sort() for j in ini: cetak+=s[j] print(cetak)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
8 8 (()(()))
O(n+m)log(n+m)
0.00006
{ "public_tests": [ { "input": "8 8\n(()(()))\n", "output": "(()(()))\n" }, { "input": "6 4\n()(())\n", "output": "()()\n" } ], "private_tests": [ { "input": "20 10\n((()))()((()()(())))\n", "output": "((()))()()\n" }, { "input": "2 2\n()\n", ...
[ 0.0000607615366996285, 0.00006006334818892045, 0.00005768192982408216, 0.00000826969337446653, 0.000003998179738063651, 0.0000026509092411494758, 0.0000025109351576158217, 0.0000024254302816324297, 0.0000022365381269121504, 0.0000022272134847574302, 0.0000021144544498470275, 0.0000011603785579...
1023_C. Bracket Subsequence
1935
1935_157
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are r...
n,k=map(int,input().split()) ans=(n-k)//2 s=input() s=s.replace("(","",ans) s=s.replace(")","",ans) print(s)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
8 8 (()(()))
O(1)
0.000038
{ "public_tests": [ { "input": "8 8\n(()(()))\n", "output": "(()(()))\n" }, { "input": "6 4\n()(())\n", "output": "()()\n" } ], "private_tests": [ { "input": "20 10\n((()))()((()()(())))\n", "output": "((()))()()\n" }, { "input": "2 2\n()\n", ...
[ 0.1597666255, 0.005574804000000001, 0.005349027500000001, 0.0050310070000000005, 0.0049851475, 0.004957081000000001, 0.0029273714999999995, 0.002787533, 0.0026176050000000003, 0.0008390155, 0.000838664, 0.0005406094999999998, 0.000042439500000000006, 0.00004231950000000047, 0.00003978000...
80_B. Depression
1855
1855_50
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels! There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle... Everybody was upset. The beautiful ...
import sys import math import itertools import collections def getdict(n): d = {} if type(n) is list or type(n) is str: for i in n: if i in d: d[i] += 1 else: d[i] = 1 else: for i in range(n): t = ii() if t in d...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
04:30
O(n**2)
0
{ "public_tests": [ { "input": "04:30\n", "output": "135 180\n" }, { "input": "08:17\n", "output": "248.5 102\n" }, { "input": "12:00\n", "output": "0 0\n" } ], "private_tests": [ { "input": "17:48\n", "output": "174 288\n" }, { ...
[ 2.0420372078052143e-11, 2.0204468222948016e-11, 1.9943323731239798e-11, 1.990569053760357e-11, 1.990536405122564e-11, 1.9892681249020748e-11, 1.9857954226233705e-11, 1.9854689590967017e-11, 1.9824970371647644e-11, 1.9688274145838428e-11, 1.968434618709839e-11, 1.967433646280124e-11, 1.964223...
80_B. Depression
1855
1855_33
Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels! There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle... Everybody was upset. The beautiful ...
import math import sys hm=str(input()) h=12-(int(hm[0]+hm[1])%12) m=int(hm[3]+hm[4]) print(360-(30*h-m/2),end=" ") print((m*6)%360)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
04:30
O(1)
0.000002
{ "public_tests": [ { "input": "04:30\n", "output": "135 180\n" }, { "input": "08:17\n", "output": "248.5 102\n" }, { "input": "12:00\n", "output": "0 0\n" } ], "private_tests": [ { "input": "17:48\n", "output": "174 288\n" }, { ...
[ 0.000019286000000000005, 0.000006829999999999997, 0.000006691000000000001, 0.000006261, 0.000005443999999999997, 0.000004930000000000002, 0.0000048720000000000035, 0.0000036789999999999965, 0.000003469, 0.0000026130000000000036, 0.0000024925000000000037, 0.0000024810000000000056, 0.000002423...
938_A. Word Correction
333
333_536
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec...
n = int(input()) s = list(input()) glas = list('aoiyue') f = 1 while f: f = 0 for i in range(1, len(s)): if s[i] in glas and s[i - 1] in glas: f = 1 s = s[:i] + s[i + 1:] break print(''.join(s))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 word
O(n**2)
0
{ "public_tests": [ { "input": "4\nword\n", "output": "word\n" }, { "input": "5\naaeaa\n", "output": "a\n" }, { "input": "5\nweird\n", "output": "werd\n" } ], "private_tests": [ { "input": "4\naepo\n", "output": "apo\n" }, { ...
[ 0.00012821387945517702, 0.000057172092852785025, 0.000007521140850170605, 0.000005223331694936185, 0.000004044559568679675, 0.000003567221071315513, 0.0000018297014304128186, 8.06379109666258e-7, 7.713381435503273e-7, 7.071671377905967e-7, 6.894669380374662e-7, 6.319737909052591e-7, 4.894976...
938_A. Word Correction
333
333_21
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec...
k = input() s = input() vowels = ['a','e','i','o','u','y'] new = [] new.append(s[0]) curr = s[0] for i in range(1, len(s)): if curr in vowels and s[i] in vowels: continue else: new.append(s[i]) curr = s[i] print(''.join(new))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 word
O(n)
0.000002
{ "public_tests": [ { "input": "4\nword\n", "output": "word\n" }, { "input": "5\naaeaa\n", "output": "a\n" }, { "input": "5\nweird\n", "output": "werd\n" } ], "private_tests": [ { "input": "4\naepo\n", "output": "apo\n" }, { ...
[ 0.00018481156669307257, 0.00011899045505080857, 0.00011054063326322114, 0.00001435222058020105, 0.000010856119058675701, 0.000008077627642889416, 0.00000788232671537804, 0.000007817107499805749, 0.000007590575830419581, 0.0000074768202715253515, 0.000007287674797858392, 0.000007103250559986889...
938_A. Word Correction
333
333_197
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec...
#/usr/bin/python3 # MC721A # 27 de março de 2020 # Rogério Meirelles - RA160245 n = int(input()) word = [char for char in input()] vowels = ['a', 'e', 'i', 'o', 'u', 'y'] remove = [] for i in range(1, n): if word[i] in vowels and word[i-1] in vowels: remove.append(i) remove.sort(reverse=True) for r in ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 word
O(nlogn)
0
{ "public_tests": [ { "input": "4\nword\n", "output": "word\n" }, { "input": "5\naaeaa\n", "output": "a\n" }, { "input": "5\nweird\n", "output": "werd\n" } ], "private_tests": [ { "input": "4\naepo\n", "output": "apo\n" }, { ...
[ 0.00000150820013263233, 0.0000014682885724546786, 0.0000010921399490313972, 0.000001021668727625203, 8.730286042601589e-7, 8.583135034917722e-7, 8.19751850170436e-7, 8.109439927722707e-7, 7.99971009053445e-7, 7.897368689781593e-7, 7.662280085904741e-7, 7.348058859198552e-7, 7.293558737669206...
1208_B. Uniqueness
2650
2650_153
You are given an array a_{1}, a_{2}, …, a_{n}. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct. In other words, at most one time you can choose two integers l and r (1 ≤ l ≤ r ≤ n) and delete integers a_l, a_{l+1}, …, a_r from the array. Remaining elements should be pa...
n = int(input()) lst = [int(i) for i in input().split()] d, count1 = {}, 0 for elem in lst: d[elem] = d.get(elem, 0) + 1 if d[elem] == 2: count1 += 1 result = n if len(d) == n: result = 0 for i in range(n): f = d.copy() count2 = count1 for j in range(i, n): f[lst[j]] -= 1 ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 1 2 2
O(n**2)
0.000004
{ "public_tests": [ { "input": "4\n1 1 2 2\n", "output": "2" }, { "input": "3\n1 2 3\n", "output": "0" }, { "input": "5\n1 4 1 4 9\n", "output": "2" } ], "private_tests": [ { "input": "8\n9 3 1 8 3 5 8 4\n", "output": "2" }, { ...
[ 0.007586884275987724, 0.00025821561868990384, 0.00004257409170362227, 0.00003744254972387615, 0.000012654336746901934, 0.000011623345424107144, 0.000009720741128217238, 0.000009267702670344136, 0.000009077587071818504, 0.000009071039741205234, 0.000008480001458479938, 0.000008085086284812906, ...
1208_B. Uniqueness
2650
2650_97
You are given an array a_{1}, a_{2}, …, a_{n}. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct. In other words, at most one time you can choose two integers l and r (1 ≤ l ≤ r ≤ n) and delete integers a_l, a_{l+1}, …, a_r from the array. Remaining elements should be pa...
def b_uniqueness(arr): i = 0 j = len(arr) - 1 last_pos = {} for ind, elem in enumerate(arr): last_pos[elem] = ind repeated_set = set() while arr[j] not in repeated_set: repeated_set.add(arr[j]) j -= 1 repeated_set.clear() ans = j + 1 while arr[i] not in rep...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 1 2 2
O(n)
0.000011
{ "public_tests": [ { "input": "4\n1 1 2 2\n", "output": "2" }, { "input": "3\n1 2 3\n", "output": "0" }, { "input": "5\n1 4 1 4 9\n", "output": "2" } ], "private_tests": [ { "input": "8\n9 3 1 8 3 5 8 4\n", "output": "2" }, { ...
[ 0.003938491341236002, 0.00006751654993444056, 0.00001694196701540647, 0.000012379712672093532, 0.00001175080023492133, 0.000011588000682910837, 0.000011451452524038463, 0.000010821760107080419, 0.000009667548759833916, 0.000009451246722027972, 0.000009369581443946678, 0.000008719553936298079, ...
1208_B. Uniqueness
2650
2650_140
You are given an array a_{1}, a_{2}, …, a_{n}. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct. In other words, at most one time you can choose two integers l and r (1 ≤ l ≤ r ≤ n) and delete integers a_l, a_{l+1}, …, a_r from the array. Remaining elements should be pa...
n = int(input()) data = list(map(int, input().split(' '))) seq = sorted(data) seq2 = [] for i in range(0, len(seq)): if (i == 0) or (seq[i-1] != seq[i]): seq2.append(seq[i]) for i in range(0, len(data)): l = 0 r = len(seq2) while r-l > 1: mid = (r+l)//2 if (seq2[mid] < data[i]): ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 1 2 2
O(nlogn)
0.000011
{ "public_tests": [ { "input": "4\n1 1 2 2\n", "output": "2" }, { "input": "3\n1 2 3\n", "output": "0" }, { "input": "5\n1 4 1 4 9\n", "output": "2" } ], "private_tests": [ { "input": "8\n9 3 1 8 3 5 8 4\n", "output": "2" }, { ...
[ 0.00003908196491399728, 0.000011402455924948064, 0.000010959624639804675, 0.000006910811828305589, 0.0000019722566409153254, 0.0000019570678267045457, 0.0000016118688264860141, 0.000001611427160729895, 5.361725881746443e-7, 1.815791630244755e-9, 1.1411440122377621e-9, 1.5144913680069933e-10, ...
245_A. System Administrator
2719
2719_94
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re...
num=eval(input()) alist=[] for i in range(num): a=input() b=a.split() c=[int(x) for x in b] alist.append(c) geshua=0 geshub=0 zongshua=0 zongshub=0 for k in alist: if k[0]==1: geshua=geshua+1 zongshua=zongshua+k[1] else: geshub=geshub+1 zongshub=zongshub+k[1] ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 1 5 5 2 6 4
O(n*m)
0.000003
{ "public_tests": [ { "input": "2\n1 5 5\n2 6 4\n", "output": "LIVE\nLIVE\n" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0\n", "output": "LIVE\nDEAD\n" } ], "private_tests": [ { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9\n", ...
[ 0.0000031900619673295457, 0.0000029826089379370634, 0.00000297595155430507, 0.0000029708044826267484, 0.000002937309317635489, 0.0000028130877403846154, 0.0000028017445640297204, 0.0000027936905730987764, 0.0000027910452360139864, 0.000002768584585336538, 0.0000027673709025349653, 0.0000027649...
245_A. System Administrator
2719
2719_289
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re...
n = int(input()) a = [0, 0] b = [0, 0] for i in range(n): t, x, y = (int(x) for x in input().split()) if t == 1: a[0] += x a[1] += y else: b[0] += x b[1] += y if a[0] >= a[1]: print('LIVE') else: print('DEAD') if b[0] >= b[1]: print('LIVE') else: print('DEAD')...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 1 5 5 2 6 4
O(n)
0
{ "public_tests": [ { "input": "2\n1 5 5\n2 6 4\n", "output": "LIVE\nLIVE\n" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0\n", "output": "LIVE\nDEAD\n" } ], "private_tests": [ { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9\n", ...
[ 0.000009847644435642483, 0.000008752885708041959, 0.000008563401551573426, 0.000008176665619536713, 0.000008099770637565561, 0.000007871298240821679, 0.000007847938551682693, 0.00000784102748033217, 0.000007839642905922203, 0.000007835137456293706, 0.000007822784282124127, 0.000007820003837958...
839_B. Game of the Rows
2426
2426_17
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two s...
n,k = map(int, input().split()) a = list(map(int,input().split())) all_sum = sum(a) r4,r2 = n,n*2 for v in range(len(a)): mid = a[v] // 4 a[v] = a[v] % 4 if mid <= r4: r4 -= mid else: a[v] += 4 * (mid - r4) r4 = 0 if r4 == 0: break mid = 0 r22 = 0 for v in a: if v % 2 == 1: mid += 1 r22 += v // 2 #pri...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 2 5 8
O(n)
0.000002
{ "public_tests": [ { "input": "2 2\n5 8\n", "output": "YES\n" }, { "input": "1 2\n7 1\n", "output": "NO\n" }, { "input": "1 4\n2 2 1 2\n", "output": "YES\n" }, { "input": "1 2\n4 4\n", "output": "YES\n" } ], "private_tests": [ { ...
[ 0.10611024589830509, 0.0017798170077326187, 0.000008272536931818182, 0.000005120863499781469, 0.000001987008249562937, 0.000001966119045017483, 0.0000016330809932255245, 0.0000015881791958041959, 0.0000014980251994099651, 0.0000014930424770541959, 0.0000014886473311844407, 0.000001478127567744...
839_B. Game of the Rows
2426
2426_4
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two s...
n, k = map(int, input().split()) seat = {4:n, 2:n*2, 1:0} extra1 = 0 a = sorted(map(int, input().split()), reverse=True) def sit(n, m): num = min(seat[n], m) seat[n] -= num return m - num for m in a: p4 = m // 4 p3, p2, p1 = 0, 0, 0 if m%4 == 3: p3 = 1 else: p2 = int(m % 4 ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 2 5 8
O(nlogn)
0.000006
{ "public_tests": [ { "input": "2 2\n5 8\n", "output": "YES\n" }, { "input": "1 2\n7 1\n", "output": "NO\n" }, { "input": "1 4\n2 2 1 2\n", "output": "YES\n" }, { "input": "1 2\n4 4\n", "output": "YES\n" } ], "private_tests": [ { ...
[ 0.000013608052953961153, 0.000013573885725696895, 0.000013571534081523018, 0.000005790279149003837, 0.0000053766814201312855, 0.00000524616777221725, 0.00000504740800654662, 0.000004978793757712805, 0.000001906566720388986, 0.0000011749344223916216, 3.849768876517102e-7 ]
155_A. I_love_%username%
1756
1756_577
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
t = int(input()) a = list(map(int, input().split())) c = 0 for i in range(1, t): if min(a[:i]) > a[i] or max(a[:i]) < a[i]: c += 1 print(c)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242
O(n**2)
0.000001
{ "public_tests": [ { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n", "output": "4\n" }, { "input": "5\n100 50 200 150 200\n", "output": "2\n" } ], "private_tests": [ { "input": "5\n100 36 53 7 81\n", "output": "2\n" }, { "i...
[ 0.020416625498795183, 0.0005536146965629613, 0.0005504914879852872, 0.0005029355306558686, 0.00005676102795678471, 0.00005579789639384269, 0.000055306166832847533, 0.00005090635568665874, 0.00004939220383274475, 0.00004716889745357386, 0.000031819162051185264, 0.000031575170792999875, 0.0000...
155_A. I_love_%username%
1756
1756_1282
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
m=int(input()) x=[int(x) for x in input().split()] if(m==1): print(0) else: maximum=x[0] minimum=x[0] count=0 for i in x: if(i<minimum): count=count+1 minimum=i if(i>maximum): count=count+1 maximum=i print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242
O(n)
0.000005
{ "public_tests": [ { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n", "output": "4\n" }, { "input": "5\n100 50 200 150 200\n", "output": "2\n" } ], "private_tests": [ { "input": "5\n100 36 53 7 81\n", "output": "2\n" }, { "i...
[ 0.00012181956592821241, 0.0001152980964270105, 0.00011436271596372379, 0.00009271759697333917, 0.000047161421915974656, 0.000046748665510270983, 0.000027761745373234838, 0.000027488919499610057, 0.000027242146206066955, 0.000027173155084045824, 0.000026871482777872107, 0.000026585783564371824,...
1425_H. Huge Boxes of Animal Toys
1170
1170_10
Chaneka has a hobby of playing with animal toys. Every toy has a different fun value, a real number. Chaneka has four boxes to store the toys with specification: * The first box stores toys with fun values in range of (-∞,-1]. * The second box stores toys with fun values in range of (-1, 0). * The third box s...
t=int(input()) for _ in range(t): l=list(map(int,input().split())) a=[0]*4 if(l[0]+l[3]!=0): a[0]=1 a[3]=1 if(l[1]+l[2]!=0): a[1]=1 a[2]=1 if((l[1]+l[0])%2==0): a[0]=0 a[1]=0 else: a[2]=0 a[3]=0 for x in a: if(x==0): ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 1 2 0 1 0 1 0 0
O(n*m)
0.000003
{ "public_tests": [ { "input": "2\n1 2 0 1\n0 1 0 0\n", "output": "Ya Ya Tidak Tidak \nTidak Ya Tidak Tidak \n" } ], "private_tests": [], "generated_tests": [ { "input": "2\n2 2 0 1\n0 1 0 0\n", "output": "Tidak Tidak Ya Ya\nTidak Ya Tidak Tidak\n" }, { "input":...
[ 0.0000035255234238417838, 0.0000035222978857080416, 0.0000035149087494536716, 0.0000034916753715034972, 0.0000034890755845716788, 0.000003459273355550699, 0.0000034526404611013986, 0.000003443757512019231, 0.0000034384632047639866, 0.0000034253435724431818, 0.000003420094651442308, 0.000003416...
1425_H. Huge Boxes of Animal Toys
1170
1170_62
Chaneka has a hobby of playing with animal toys. Every toy has a different fun value, a real number. Chaneka has four boxes to store the toys with specification: * The first box stores toys with fun values in range of (-∞,-1]. * The second box stores toys with fun values in range of (-1, 0). * The third box s...
t = int(input()) for tc in range(t): a, b, c, d = map(int, input().split()) k = ["Tidak"] * 4 if not (a+b) % 2: if (b+c): k[2] = "Ya" if (a+d): k[3] = "Ya" else: if (b+c): k[1] = "Ya" if (a+d): k[0] = "Ya" print(*k)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 1 2 0 1 0 1 0 0
O(n)
0
{ "public_tests": [ { "input": "2\n1 2 0 1\n0 1 0 0\n", "output": "Ya Ya Tidak Tidak \nTidak Ya Tidak Tidak \n" } ], "private_tests": [], "generated_tests": [ { "input": "2\n2 2 0 1\n0 1 0 0\n", "output": "Tidak Tidak Ya Ya\nTidak Ya Tidak Tidak\n" }, { "input":...
[ 0.000017460018534200174, 0.000017347672271088287, 0.00001704079331020542, 0.000014574477928321679, 0.00001456039712631119, 0.000014431128728693183, 0.000014235286877185315, 0.00001419670647126311, 0.000013503253086756995, 0.000013313715130572553, 0.000013134016280594406, 0.00001302404490821678...
1236_A. Stones
1578
1578_724
Alice is playing with some stones. Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones. Each time she can do one of two operations: 1. take one stone from the first heap and two stones from the second heap (...
for i in range(int(input())): a, b, c = map(int, input().split()) res = 0 while True: if b >= 1 and c >= 2: res += 3 c -= 2 b -= 1 elif a >= 1 and b >= 2: res += 3 a -= 1 b -= 2 else: print(res) ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 4 5 1 0 5 5 3 2
O(n**2)
0.000001
{ "public_tests": [ { "input": "3\n3 4 5\n1 0 5\n5 3 2\n", "output": "9\n0\n6\n" } ], "private_tests": [ { "input": "20\n9 4 8\n10 6 7\n4 6 0\n7 7 6\n3 3 10\n4 2 1\n4 4 0\n2 0 0\n8 8 7\n3 1 7\n3 10 7\n1 7 3\n7 9 1\n1 6 9\n0 9 5\n4 0 0\n2 10 0\n4 8 5\n10 0 1\n8 1 1\n", "output":...
[ 0.014636632525700037, 0.00001903552890099528, 0.000016631907896954387, 0.000016462201029083804, 0.000016384923747193952, 0.000016338037793103423, 0.00001620655104569351, 0.000010963828456474788, 0.000010695323594014354, 0.000008945618639094482, 0.000004445304482626749, 0.00000301657425972465, ...
1236_A. Stones
1578
1578_481
Alice is playing with some stones. Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones. Each time she can do one of two operations: 1. take one stone from the first heap and two stones from the second heap (...
t=int(input()) for i in range(t): a,b,c=map(int,input().split()) n=min(b,c//2) b-=n m=min(a,b//2) print((m+n)*3)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 4 5 1 0 5 5 3 2
O(n)
0
{ "public_tests": [ { "input": "3\n3 4 5\n1 0 5\n5 3 2\n", "output": "9\n0\n6\n" } ], "private_tests": [ { "input": "20\n9 4 8\n10 6 7\n4 6 0\n7 7 6\n3 3 10\n4 2 1\n4 4 0\n2 0 0\n8 8 7\n3 1 7\n3 10 7\n1 7 3\n7 9 1\n1 6 9\n0 9 5\n4 0 0\n2 10 0\n4 8 5\n10 0 1\n8 1 1\n", "output":...
[ 0.0005518340863839286, 0.0001416391729266827, 0.000041949314931162584, 0.000040903535279173956, 0.00003904644625491696, 0.000032884378633085665, 0.00003138692094624126, 0.000030124259861232523, 0.000029784622036166958, 0.0000295634682583042, 0.000028249886063155593, 0.00002707783535019668, 0...
467_A. George and Accommodation
3091
3091_384
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living...
n=int(input()) a=[] count=0 for x in range(n): a+=list(map(int,input().split())) i=0 while i<n*2: if abs(a[i]-a[i+1])>=2: count+=1 i+=2 print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 1 1 2 2 3 3
O(n*m)
0.000002
{ "public_tests": [ { "input": "3\n1 1\n2 2\n3 3\n", "output": "0\n" }, { "input": "3\n1 10\n0 10\n10 10\n", "output": "2\n" } ], "private_tests": [ { "input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n6...
[ 0.000025397852791739505, 0.000009757009765625002, 0.000009746170703125, 0.000009672402734375, 0.000009656382812500002, 0.000009622530184659092, 0.00000868512521853147, 0.000008468665625, 0.000008425448828125002, 0.0000084230125, 0.000008417229296875001, 0.000008406854687500002, 0.00000840164...
467_A. George and Accommodation
3091
3091_1574
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living...
n=int(input()) count=0 for i in range(n): p,q = map(int,input().split()) if p<q and (q-p)>=2: count+=1 print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 1 1 2 2 3 3
O(n)
0
{ "public_tests": [ { "input": "3\n1 1\n2 2\n3 3\n", "output": "0\n" }, { "input": "3\n1 10\n0 10\n10 10\n", "output": "2\n" } ], "private_tests": [ { "input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n6...
[ 0.00007312916015625001, 0.00004167034002130682, 0.000018051241654829547, 0.000013113727095170455, 0.000012953259779283217, 0.000012866746134724652, 0.000012835024830638112, 0.000012569119345498254, 0.000012563680138221154, 0.00001243629399311626, 0.000012345495779611016, 0.00001232097829709353...
1194_A. Remove a Progression
2627
2627_428
You have a list of numbers from 1 to n written from left to right on the blackboard. You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit). <image> When there are less than ...
t=int(input()) for k in range(t): c=input() n=int(c.split()[0]) x=int(c.split()[1]) print(2*x)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 1 4 2 69 6
O(n*m)
0.000002
{ "public_tests": [ { "input": "3\n3 1\n4 2\n69 6\n", "output": "2\n4\n12\n" } ], "private_tests": [ { "input": "1\n241139 1\n", "output": "2\n" }, { "input": "1\n2441139 10\n", "output": "20\n" }, { "input": "1\n2452199 2\n", "output": "...
[ 0.0000043891280730987764, 0.000002940116545563811, 0.000002932321091018357, 0.00000290472690395542, 0.0000028978607544798954, 0.000002879040127840909, 0.0000028510221672858397, 0.0000028137480605332167, 0.0000027651856015078674, 0.000002734025841346154, 0.0000027287926272945808, 0.000002726023...
1194_A. Remove a Progression
2627
2627_568
You have a list of numbers from 1 to n written from left to right on the blackboard. You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit). <image> When there are less than ...
t = int(input()) for i in range(t): n,x = map(int, input().split(" ")) print(2*x)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 1 4 2 69 6
O(n)
0
{ "public_tests": [ { "input": "3\n3 1\n4 2\n69 6\n", "output": "2\n4\n12\n" } ], "private_tests": [ { "input": "1\n241139 1\n", "output": "2\n" }, { "input": "1\n2441139 10\n", "output": "20\n" }, { "input": "1\n2452199 2\n", "output": "...
[ 0.00001552245826048951, 0.000015274897481424827, 0.000015177750546328672, 0.000014919444697880246, 0.000014608549060314685, 0.000014523468941215037, 0.000013868008987106642, 0.000013836146593640734, 0.000013797645883413463, 0.000013725990534855768, 0.000013690112748579546, 0.000013662907684112...
228_A. Is your horseshoe on the other hoof?
1434
1434_1616
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
a = list(map(int,input().split())) count = 0 for i in range(1,len(a)): if a[i] in a[:i]: count += 1 print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
7 7 7 7
O(n**2)
0
{ "public_tests": [ { "input": "7 7 7 7\n", "output": "3\n" }, { "input": "1 7 3 3\n", "output": "1\n" } ], "private_tests": [ { "input": "2 2 2 1\n", "output": "2\n" }, { "input": "3491663 217797045 522540872 715355328\n", "output": "0\n...
[ 0.000023585184017333403, 0.000009013353733363371, 0.000008985722331504145, 0.000005667814436839647, 0.000004213186012394459, 0.000004011330618018963, 0.0000038027009962832498, 0.0000034066670416789648, 0.000003140472968043968, 0.0000030672946232649785, 0.000003039828046343853, 0.00000303637418...
228_A. Is your horseshoe on the other hoof?
1434
1434_1729
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
x = list(map(int, input().split())) dic ={} for each in x: if each not in dic: dic[each] = 0 dic[each] += 0 h = len(dic) print(4 - h)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
7 7 7 7
O(n)
0.000002
{ "public_tests": [ { "input": "7 7 7 7\n", "output": "3\n" }, { "input": "1 7 3 3\n", "output": "1\n" } ], "private_tests": [ { "input": "2 2 2 1\n", "output": "2\n" }, { "input": "3491663 217797045 522540872 715355328\n", "output": "0\n...
[ 0.00007884283806818183, 0.000010604211716018358, 0.000010597972096263112, 0.000006780243416739511, 0.000005931016417176574, 0.000005546388767482518, 0.000004925508631993007, 0.000004658699423623252, 0.000004415677666083916, 0.000004122494673295455, 0.000003924737092985139, 0.000003884418760926...
1011_B. Planning The Expedition
1306
1306_15
Natasha is planning an expedition to Mars for n people. One of the important tasks is to provide food for each participant. The warehouse has m daily food packages. Each package has some food type a_i. Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the sam...
num_part, num_pack = [int(i) for i in input().split(' ')] type_pack = input().split(' ') dict_count = {} for element in set(type_pack): dict_count[element] = type_pack.count(element) count = 0 for days in range(1,101): survival = 0 for element in dict_count: survival += dict_count[element] // days if survival ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 10 1 5 2 1 1 1 2 5 7 2
O(n**2)
0.000001
{ "public_tests": [ { "input": "4 10\n1 5 2 1 1 1 2 5 7 2\n", "output": "2\n" }, { "input": "2 5\n5 4 3 2 1\n", "output": "1\n" }, { "input": "3 9\n42 42 42 42 42 42 42 42 42\n", "output": "3\n" }, { "input": "100 1\n1\n", "output": "0\n" ...
[ 0.005264647502038139, 0.004816063673616642, 0.0047629613879492105, 0.002626808502697759, 0.0020747693122684326, 0.001111393887675507, 0.00023387590926688401, 0.0002034993285984314, 0.00011086475853253342, 0.000023321745866423192, 0.000007252462894203632, 0.0000055766004105952, 0.000004251432...
1011_B. Planning The Expedition
1306
1306_126
Natasha is planning an expedition to Mars for n people. One of the important tasks is to provide food for each participant. The warehouse has m daily food packages. Each package has some food type a_i. Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the sam...
from collections import* R=lambda:map(int,input().split()) n,m=R() a=Counter(R()).values() i=1 while sum(x//i for x in a)>=n:i+=1 print(i-1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 10 1 5 2 1 1 1 2 5 7 2
O(n)
0.000009
{ "public_tests": [ { "input": "4 10\n1 5 2 1 1 1 2 5 7 2\n", "output": "2\n" }, { "input": "2 5\n5 4 3 2 1\n", "output": "1\n" }, { "input": "3 9\n42 42 42 42 42 42 42 42 42\n", "output": "3\n" }, { "input": "100 1\n1\n", "output": "0\n" ...
[ 0.002774340785105595, 0.002769421251111523, 0.000983495663671875, 0.000875860146875, 0.0004631810053571429, 0.0004619413297991072, 0.0002930532760735358, 0.00025960878452797203, 0.00025759026193728147, 0.00024638359077250874, 0.00023046942149256995, 0.0001621553790681144, 0.00009130244874071...
1011_B. Planning The Expedition
1306
1306_197
Natasha is planning an expedition to Mars for n people. One of the important tasks is to provide food for each participant. The warehouse has m daily food packages. Each package has some food type a_i. Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the sam...
from collections import Counter n,m = list(map(int,input().split())) l = list(map(int,input().split())) l2 = [y for x,y in Counter(l).items()] l2.sort(reverse=True) #print(l2) for i in range(1,max(l2)+2): if sum(int(x/i) for x in l2) < n: print(i-1) break else: print()
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 10 1 5 2 1 1 1 2 5 7 2
O(nlogn)
0.000027
{ "public_tests": [ { "input": "4 10\n1 5 2 1 1 1 2 5 7 2\n", "output": "2\n" }, { "input": "2 5\n5 4 3 2 1\n", "output": "1\n" }, { "input": "3 9\n42 42 42 42 42 42 42 42 42\n", "output": "3\n" }, { "input": "100 1\n1\n", "output": "0\n" ...
[ 0.0036235222640204692, 0.0006621419757812501, 0.00027699334387292396, 0.00020537266986724219, 0.00006142638366892195, 0.00005916675064162326, 0.000038589192827200475, 0.000033814286756393965, 0.0000336296977831842, 0.000032215098809540996, 0.000032121531471213535, 0.00003196830179527913, 0.0...
463_B. Caisa and Pylons
2015
2015_168
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon...
"Codeforces Round #339 (Div. 2)" "B. Gena's Code" # y=int(input()) # # a=list(map(int,input().split())) # a=list(input().split()) # nz=0 # nb='' # z=0 # # print(len(str(z))) # for i in a: # if i=='0': # z=1 # break # else: # s='1' # l=(len(i)-1) # qz='0'*l # s+=qz...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 3 4 3 2 4
O(n+mlogm)
0
{ "public_tests": [ { "input": "5\n3 4 3 2 4\n", "output": "4\n" }, { "input": "3\n4 4 4\n", "output": "4\n" } ], "private_tests": [ { "input": "3\n3 2 1\n", "output": "3\n" }, { "input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 3...
[ 0.0000012142827797202798, 0.000001214060041520979, 0.0000012093923322770977, 0.0000011958696869536714, 8.243539716064949e-7, 6.503722086625638e-7, 6.4850963543316e-7, 6.398305875450888e-7, 6.252611838539339e-7, 6.181282899857025e-7, 6.146011924485018e-7, 5.844270536227282e-7, 5.8099415706411...
463_B. Caisa and Pylons
2015
2015_175
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon...
n = int(input()) h = [int(x) for x in input().split()] ans = 0 for i in h: ans = max(ans,i) print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 3 4 3 2 4
O(n)
0.000003
{ "public_tests": [ { "input": "5\n3 4 3 2 4\n", "output": "4\n" }, { "input": "3\n4 4 4\n", "output": "4\n" } ], "private_tests": [ { "input": "3\n3 2 1\n", "output": "3\n" }, { "input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 3...
[ 0.000008132442321350524, 0.000006873630832058566, 0.000006631798718859267, 0.000006169107511316906, 0.00000611532268902972, 0.000005663612489073427, 0.000004787058334243881, 0.0000046761030785620635, 0.000004603391157670455, 0.0000045991337412587415, 0.000004586438415100524, 0.0000045589031769...
p03776 AtCoder Beginner Contest 057 - Maximum Average Sets
3079
3079_181
You are given N items. The value of the i-th item (1 \leq i \leq N) is v_i. Your have to select at least A and at most B of these items. Under this condition, find the maximum possible arithmetic mean of the values of selected items. Additionally, find the number of ways to select items so that the mean of the values o...
import collections from math import factorial def comb(n,r): return factorial(n)//factorial(n-r)//factorial(r) n,a,b=map(int,input().split()) v=list(map(int,input().split())) v.sort(reverse=True) c=collections.Counter(v) k=min(v[:a]) if c[max(v)]<a: ans=comb(c[k],v[:a].count(k)) else: ans=0 for i in ran...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 2 3 10 20 10 10
O(n**2)
0
{ "public_tests": [ { "input": "4 2 3\n10 20 10 10", "output": "15.000000\n3" }, { "input": "5 1 5\n1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n1" }, { "input": "5 2 2\n1 2 3 4 5", "outpu...
[ 0.000009570073874322866, 0.000007377979041478168, 0.000002253335929554825, 0.0000010594696758874228, 5.489015247153669e-7, 3.1285485655675236e-7, 3.1118242320472565e-7, 3.056446282006383e-7, 3.040500613873953e-7, 3.0311706594096887e-7, 2.462033048541931e-7, 2.107683690175381e-7, 2.0903102446...
p03776 AtCoder Beginner Contest 057 - Maximum Average Sets
3079
3079_85
You are given N items. The value of the i-th item (1 \leq i \leq N) is v_i. Your have to select at least A and at most B of these items. Under this condition, find the maximum possible arithmetic mean of the values of selected items. Additionally, find the number of ways to select items so that the mean of the values o...
N, A, B = map(int, input().split()) val = [int(i) for i in input().split()] def combi(n, m): from math import factorial return factorial(n) // (factorial(m) * factorial(n-m)) val.sort(reverse=True) ave = sum(val[:A])/A l = val.index(val[A-1]) x = val.count(val[A-1]) ct = 0 if val[0] == val[A-1]: for i i...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 2 3 10 20 10 10
O(nlogn)
0.000012
{ "public_tests": [ { "input": "4 2 3\n10 20 10 10", "output": "15.000000\n3" }, { "input": "5 1 5\n1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n1" }, { "input": "5 2 2\n1 2 3 4 5", "outpu...
[ 0.8725107660000001, 0.8163634000000001, 0.802404309, 0.7879638935000001, 0.7849845975, 0.7768553255, 0.7715715175, 0.7177516320000001, 0.7177356355000001, 0.714469953, 0.634042993, 0.603961957, 0.5821775245, 0.5421108465, 0.5222458075, 0.490225432, 0.47744883050000003, 0.4734082810...
214_A. System of Equations
482
482_543
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pai...
n,m=map(int,input().split()) c=0 for i in range(0,n+1): for j in range(0,m+1): if(i**2+j==n and j**2+i==m): c+=1 print(c)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
14 28
O(n*m)
0.000276
{ "public_tests": [ { "input": "14 28\n", "output": "1" }, { "input": "9 3\n", "output": "1" }, { "input": "4 20\n", "output": "0" } ], "private_tests": [ { "input": "247 499\n", "output": "1" }, { "input": "18 198\n", ...
[ 0.11039630081355933, 0.0518492633943662, 0.006595251034952913, 0.005826220529541302, 0.0016881522105131387, 0.0004955636660714286, 0.0004940873361607143, 0.0004927703824776786, 0.00037508596638257584, 0.0003721590035037879, 0.00036000219332386364, 0.00034950487365056817, 0.000338084409753787...
214_A. System of Equations
482
482_366
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pai...
import math k=list(map(int,input().split())) n=max(k) m=min(k) p=0 for b in range(0,n+1): if b<=n: a=math.sqrt(n-b) if m>=a: if b==math.sqrt(m-a): if int(b)==b and int(a)==a: p+=1 print(p)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
14 28
O(n+m)
0.000016
{ "public_tests": [ { "input": "14 28\n", "output": "1" }, { "input": "9 3\n", "output": "1" }, { "input": "4 20\n", "output": "0" } ], "private_tests": [ { "input": "247 499\n", "output": "1" }, { "input": "18 198\n", ...
[ 0.0007447251796875001, 0.00007367976522891171, 0.0000714515176464161, 0.00007130041092111014, 0.00007083889886090474, 0.0000566540506173514, 0.00005518893958970717, 0.00003890362579217658, 0.00003122476486013986, 0.00002775888927283654, 0.00002717200521743881, 0.00002423061104130245, 0.00002...
214_A. System of Equations
482
482_385
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pai...
n,m = map(int, input().split()) c = 0 for a in range(0,max(n ,m) + 1): for b in range(0, max(n, m) + 1): if ((a **2) + b) == n and (a + (b ** 2)) == m: c = c + 1 print(c)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
14 28
O(n**2+m**2)
0.000559
{ "public_tests": [ { "input": "14 28\n", "output": "1" }, { "input": "9 3\n", "output": "1" }, { "input": "4 20\n", "output": "0" } ], "private_tests": [ { "input": "247 499\n", "output": "1" }, { "input": "18 198\n", ...
[ 0.0009821586734702723, 0.0009669168192061018, 0.0009491429241689722, 0.0009343590274744324, 0.0009215242150719363, 0.0007420518848485826, 0.0007405581203434081, 0.0007291978487251257, 0.0007246326754427711, 0.0007112189671084297, 0.0006459987278117009, 0.0006433882209378925, 0.00064275909730...
214_A. System of Equations
482
482_438
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: <image> You should count, how many there are pai...
n, m = map(int, input().split()) r=range(32) print(sum(a**2+b-n == b**2+a-m == 0 for a in r for b in r))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
14 28
O(1)
0.000059
{ "public_tests": [ { "input": "14 28\n", "output": "1" }, { "input": "9 3\n", "output": "1" }, { "input": "4 20\n", "output": "0" } ], "private_tests": [ { "input": "247 499\n", "output": "1" }, { "input": "18 198\n", ...
[ 0.013823934000000038, 0.011301090500000055, 0.0111321915, 0.011018577999999946, 0.010716158499999962, 0.010229782500000062, 0.00999238349999998, 0.009463776000000035, 0.009246402499999973, 0.009171883000000047, 0.009029886500000028, 0.008749351500000002, 0.008299109000000027, 0.00820206000...
1136_A. Nastya Is Reading a Book
2914
2914_264
After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the fi...
n = int(input()) mas = [] for i in range(n): c = list(map(int,input().split())) mas.append(c) k = int(input()) for i in range(n): if k >= mas[i][0] and k <= mas[i][1]: print(n-i) break
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 1 4 5 9 10 12 9
O(n*m)
0.000002
{ "public_tests": [ { "input": "3\n1 4\n5 9\n10 12\n9\n", "output": "2\n" }, { "input": "1\n1 7\n4\n", "output": "1\n" }, { "input": "3\n1 3\n4 7\n8 11\n2\n", "output": "3\n" } ], "private_tests": [ { "input": "1\n1 5\n1\n", "output": "1\...
[ 0.0000046988938073645106, 0.0000040459374726835675, 0.000003724667217548077, 0.000003130230059003497, 0.0000030838376584353144, 0.000002993535675262238, 0.0000029456325666520976, 0.0000029429290319055945, 0.0000029145795317963287, 0.0000029099405184659093, 0.0000029030535948426574, 0.000002893...
1136_A. Nastya Is Reading a Book
2914
2914_3
After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the fi...
n = int(input()) chapters = [] for _ in range(n): l, r = map(int, input().split()) chapters.append((l, r)) k = int(input()) for i in range(len(chapters)): if k >= chapters[i][0] and k <= chapters[i][1]: break print(n - i)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 1 4 5 9 10 12 9
O(n)
0.000011
{ "public_tests": [ { "input": "3\n1 4\n5 9\n10 12\n9\n", "output": "2\n" }, { "input": "1\n1 7\n4\n", "output": "1\n" }, { "input": "3\n1 3\n4 7\n8 11\n2\n", "output": "3\n" } ], "private_tests": [ { "input": "1\n1 5\n1\n", "output": "1\...
[ 0.00004993230993479095, 0.000015359697333916085, 0.000014649456471263112, 0.000014381058224978148, 0.000014171784514313813, 0.000014111832509287589, 0.000013813896279501747, 0.000013681003277972032, 0.000013640177092438812, 0.000013583461060423952, 0.000013408143329326925, 0.000013379211401879...