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
651_B. Beautiful Paintings
1054
1054_174
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa...
n = int(input()) l = list(map(int, input().split())) d = {} for i in l: if i not in d: d[i] = 1 else: d[i] += 1 m = max(d.values()) print(n - m)
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 20 30 10 50 40
O(n)
0.000003
{ "public_tests": [ { "input": "5\n20 30 10 50 40\n", "output": "4\n" }, { "input": "4\n200 100 100 200\n", "output": "2\n" } ], "private_tests": [ { "input": "10\n103 101 103 103 101 102 100 100 101 104\n", "output": "7\n" }, { "input": "20\n9...
[ 0.000711799140625, 0.00046805663279413166, 0.00029761588391881557, 0.0001840972350169362, 0.0001635716388084572, 0.00016015356198098777, 0.00015844845364025912, 0.000158211864414882, 0.00015813686535729894, 0.00015520019797585227, 0.00015343145627631378, 0.00015175317679195805, 0.00014892661...
651_B. Beautiful Paintings
1054
1054_212
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa...
import sys from collections import Counter input = sys.stdin.readline n = int(input()) a = dict(Counter(sorted(input().split()))) ans = 0 f = 0 for val in a: ans += min(f, a[val]) f += max(a[val] - f, 0) 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 20 30 10 50 40
O(nlogn)
0.000015
{ "public_tests": [ { "input": "5\n20 30 10 50 40\n", "output": "4\n" }, { "input": "4\n200 100 100 200\n", "output": "2\n" } ], "private_tests": [ { "input": "10\n103 101 103 103 101 102 100 100 101 104\n", "output": "7\n" }, { "input": "20\n9...
[ 0.00002675380585155266, 0.00002469994344177039, 0.000017008904459472226, 0.000015942229663915453, 0.000015777795385040063, 0.000015664421199527484, 0.000015517348347107393, 0.00001548344275293781, 0.000015437206319232974, 0.000015220380844380558, 0.000015217050313383295, 0.00001516810564032910...
437_B. The Child and Set
1827
1827_44
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks. Fortunately, Picks remembers something about his set S: * its elements were distinct integers from 1 to limit; * the value of <ima...
from math import * s, l = map(int, input().split()) mL = floor(log2(l)) mS = floor(log2(l)) x = min(mL, mS) S = [] while x >= 0: a = 1 while 2 ** x <= s and a * 2 ** x <= l: S.append(a * 2 ** x) a += 2 s -= 2 ** x x -= 1 if s == 0: print(len(S)) print(' '.join(map(str, S))) else: print(-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 3
O(n**2)
0
{ "public_tests": [ { "input": "4 3\n", "output": "3\n3 2 1 " }, { "input": "5 1\n", "output": "-1" }, { "input": "5 5\n", "output": "2\n5 4 " } ], "private_tests": [ { "input": "62658 10881\n", "output": "8365\n10881 10880 10879 10878 10...
[ 6.937672689891679e-11, 4.6059875279519644e-11, 4.412405849773956e-11, 3.936862869498375e-11, 3.914413322636533e-11, 3.762937949282578e-11, 3.674561471226995e-11, 3.389667828651282e-11, 2.904068595988437e-11, 2.7978364396311384e-11, 2.3850139194872017e-11 ]
437_B. The Child and Set
1827
1827_66
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks. Fortunately, Picks remembers something about his set S: * its elements were distinct integers from 1 to limit; * the value of <ima...
s,l=map(int,input().split()) list1=[] for i in range(1,l+1): list1.append((i&-i,i)) list1.sort(reverse=True) ll=[] for i in range(l): if(list1[i][0]<=s): ll.append(list1[i][1]) s-=list1[i][0] if(s==0): print(len(ll)) print(*ll) else: print(-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 3
O(nlogn)
0.000009
{ "public_tests": [ { "input": "4 3\n", "output": "3\n3 2 1 " }, { "input": "5 1\n", "output": "-1" }, { "input": "5 5\n", "output": "2\n5 4 " } ], "private_tests": [ { "input": "62658 10881\n", "output": "8365\n10881 10880 10879 10878 10...
[ 0.0000215131716291521, 0.000015527404866499507, 0.000010513948014861878, 0.000010407631905431596, 0.000010303910619160051, 0.000009976051673873936, 0.000009926540007292483, 0.000009818035632952306, 0.000009639128350091657, 0.000009620135478025377, 0.000009517414215379131, 0.0000094712429292217...
490_A. Team Olympiad
2610
2610_51
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: * ti = 1, if the i-th child is good at programming, *...
n = int(input()) a = [[] for i in range(3)] for i, x in enumerate(map(int, input().split()), 1): a[x-1] += [i] k = min(len(a[0]), len(a[1]), len(a[2])) print(k) for i in range(k): print(a[0][i], a[1][i], a[2][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 1 1 2
O(n)
0.000002
{ "public_tests": [ { "input": "4\n2 1 1 2\n", "output": "0\n" }, { "input": "7\n1 3 1 3 2 1 2\n", "output": "2\n1 5 2\n3 7 4\n" } ], "private_tests": [ { "input": "3\n2 1 2\n", "output": "0\n" }, { "input": "5\n1 2 2 3 3\n", "output": "1...
[ 0.00010105295712685753, 0.000044690859825721155, 0.000043190847437718535, 0.000019596839338395983, 0.00001928534540264423, 0.000011029042224377185, 0.00001067576545444604, 0.000009471927720716784, 0.000009408056148929195, 0.000009135769421984266, 0.000009101318960336538, 0.00000899629802229021...
490_A. Team Olympiad
2610
2610_1259
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: * ti = 1, if the i-th child is good at programming, *...
n = int(input());t = 0;t2 = 0 l = [int(i) for i in input().split()] l2 = l[:] l2.sort() #print('l2',l2) t1 = l.count(1) t2 = l.count(2) t3 = l.count(3) i1 = 0 i2 = t1 i3 = t1+t2 print(min(t1,t2,t3)) for i in range(min(t1,t2,t3)): #print('l2',l2) # print(i1,i2,i3) print(l.index(l2[i1])+1,l.index(l2[i2])+1,l.index(l2[i3...
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 1 1 2
O(nlogn)
0.000011
{ "public_tests": [ { "input": "4\n2 1 1 2\n", "output": "0\n" }, { "input": "7\n1 3 1 3 2 1 2\n", "output": "2\n1 5 2\n3 7 4\n" } ], "private_tests": [ { "input": "3\n2 1 2\n", "output": "0\n" }, { "input": "5\n1 2 2 3 3\n", "output": "1...
[ 0.00008326199551917378, 0.000030865809237791865, 0.000029981140857189685, 0.000013577090369767376, 0.000011785416301123077, 0.000011513030654974605, 0.000011397171186366626, 0.000011265844587539506, 0.000011223357888830329, 0.000011064559802521012, 0.000011048525817832585, 0.000010610644464047...
546_C. Soldier and Cards
2680
2680_221
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game. The rules are following. On each turn a fi...
n = int(input()) a = [int(x) for x in input().split()] a = a[1:] b = [int(x) for x in input().split()] b = b[1:] k = 0 while len(a) > 0 and len(b) > 0 and k <= 10 ** 3: if a[0] > b[0] and (not(a[0] == 0 and b[0] == 9) and not(a[0] == 9 and b[0] == 0)): a.append(b[0]) a.append(a[0]) a.pop(0) b.pop(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, ...
4 2 1 3 2 4 2
O(n+m)
0.000001
{ "public_tests": [ { "input": "4\n2 1 3\n2 4 2\n", "output": "6 2\n" }, { "input": "3\n1 2\n2 1 3\n", "output": "-1\n" } ], "private_tests": [ { "input": "10\n8 1 6 5 3 8 7 10 4\n2 9 2\n", "output": "40 1\n" }, { "input": "9\n8 4 8 5 6 3 2 7 1...
[ 0.00001291931900131119, 0.000012116360768138112, 0.000011270762005572552, 0.000010372530635380245, 0.000010212893861607144, 0.000008933676136363638, 0.000008196178212412588, 0.000008094845870535715, 0.000007763614059768359, 0.000007738902125218533, 0.00000769583670236014, 0.0000070667369427447...
546_C. Soldier and Cards
2680
2680_65
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game. The rules are following. On each turn a fi...
from collections import deque n = int(input()) a = deque([int(i) for i in input().split()[1:]]) b = deque([int(i) for i in input().split()[1:]]) mark = set() ans = 0 while a and b: if str(a)+" "+str(b) in mark: print(-1) exit() mark.add(str(a)+" "+str(b)) ans += 1 aa = a.popleft() bb...
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 1 3 2 4 2
O(n**2+m**2)
0.000005
{ "public_tests": [ { "input": "4\n2 1 3\n2 4 2\n", "output": "6 2\n" }, { "input": "3\n1 2\n2 1 3\n", "output": "-1\n" } ], "private_tests": [ { "input": "10\n8 1 6 5 3 8 7 10 4\n2 9 2\n", "output": "40 1\n" }, { "input": "9\n8 4 8 5 6 3 2 7 1...
[ 0.000012511942673365223, 0.000007057254673038849, 0.000005670517514399375, 0.00000563264943934402, 0.0000053075437160167, 0.000004986113569475642, 0.0000048208368817561835, 0.000004790485988890443, 0.000004726056684424878, 0.000004647029190826723, 0.000004546315599360319, 0.0000043206999387590...
722_A. Broken Clock
2700
2700_53
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a time in format HH:MM that is currently displayed on the broken ...
n = int(input()) a = list(input()) for i in range(5): if (i != 2): a[i] = int(a[i]) n1 = a[0] * 10 + a[1] n2 = a[3] * 10 + a[4] if n == 24: ans = 0 if (n1 >= 24): a[0] = 0 if (n2 >= 60): a[3] = 0 print(''.join(map(str, a))) if (n == 12): if (n2 >= 60): a[3] = 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, ...
12 17:30
O(n)
0
{ "public_tests": [ { "input": "12\n17:30\n", "output": "07:30\n" }, { "input": "24\n99:99\n", "output": "09:09\n" }, { "input": "24\n17:30\n", "output": "17:30\n" } ], "private_tests": [ { "input": "12\n90:32\n", "output": "10:32\n" ...
[ 0.000018521983896962416, 0.0000023235922066215036, 9.507997022508742e-7, 6.407747213723777e-7, 3.990416302447553e-7, 3.981368553321679e-7, 3.8510190395541965e-7, 2.44394217111014e-7, 2.1093810096153849e-7, 2.1078277972027972e-7, 2.082901141826923e-7, 2.0671596372377627e-7, 2.0260964816433565...
722_A. Broken Clock
2700
2700_137
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59. You are given a time in format HH:MM that is currently displayed on the broken ...
a = int(input()) h,m = map(int, input().split(':')) if m > 59: m = 10 + m % 10 if a == 24: if h > 23: h = h % 10 elif h > 12: h = h % 10 if a == 12 and h == 0: h = 10 s = str(h) if h < 10: s = "0" + s s += ":" if m < 10: s += "0" s += str(m) 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, ...
12 17:30
O(1)
0.000001
{ "public_tests": [ { "input": "12\n17:30\n", "output": "07:30\n" }, { "input": "24\n99:99\n", "output": "09:09\n" }, { "input": "24\n17:30\n", "output": "17:30\n" } ], "private_tests": [ { "input": "12\n90:32\n", "output": "10:32\n" ...
[ 0.0033454245000000007, 0.0028020755, 0.002151295, 0.0000846079999999999, 0.00004215700000000013, 0.00002787049999999989, 0.000027067500000000147, 0.00001452300000000001, 0.000014363500000000006, 0.000013051500000000002, 0.000005480000000000002, 0.00000303, 0.000002475000000000006, 0.000002...
1351_A. A+B (Trial Problem)
2602
2602_57
You are given two integers a and b. Print a+b. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given as a line of two integers a and b (-1000 ≤ a, b ≤ 1000). Output Print t integers — the required numbers a+b. Example ...
testcase = int(input()) for i in range(testcase): list1 = list(map(int , input().split())) sum1 = sum(list1) print(sum1)
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 5 314 15 -99 99 123 987
O(n*m)
0.000003
{ "public_tests": [ { "input": "4\n1 5\n314 15\n-99 99\n123 987\n", "output": "6\n329\n0\n1110\n" } ], "private_tests": [ { "input": "1\n147 555\n", "output": "702\n" }, { "input": "1\n233 233\n", "output": "466\n" }, { "input": "1\n456 -456\n"...
[ 0.00000464294013603584, 0.000004499430165537587, 0.0000033958827305506995, 0.000003355103460992133, 0.00000334403477381993, 0.0000033185745328889863, 0.0000033006600879589164, 0.0000032639641881555946, 0.0000031518228256118883, 0.000003125974623033217, 0.0000031205333123907343, 0.0000031067560...
1351_A. A+B (Trial Problem)
2602
2602_62
You are given two integers a and b. Print a+b. Input The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow. Each test case is given as a line of two integers a and b (-1000 ≤ a, b ≤ 1000). Output Print t integers — the required numbers a+b. Example ...
t = int(input()) for q in range(t): a, b = map(int, input().split()) print(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, ...
4 1 5 314 15 -99 99 123 987
O(n)
0
{ "public_tests": [ { "input": "4\n1 5\n314 15\n-99 99\n123 987\n", "output": "6\n329\n0\n1110\n" } ], "private_tests": [ { "input": "1\n147 555\n", "output": "702\n" }, { "input": "1\n233 233\n", "output": "466\n" }, { "input": "1\n456 -456\n"...
[ 0.00001870372541520979, 0.000018398407629479896, 0.000018298381050590038, 0.000018018589925699303, 0.00001762969910948427, 0.000016610570681271853, 0.000016589380517919582, 0.000016569603119536715, 0.000016565330392263988, 0.00001632613348175262, 0.000015093703958151224, 0.00001509108418924825...
1331_B. Limericks
1357
1357_135
There was once young lass called Mary, Whose jokes were occasionally scary. On this April's Fool Fixed limerick rules Allowed her to trip the unwary. Can she fill all the lines To work at all times? On juggling the words Right around two-thirds Sh...
import sys n = int(sys.stdin.readline().strip()) L = [] i = 2 while n > 1: if n % i == 0: L.append(str(i)) n = n // i else: i = i + 1 print("".join(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, ...
391
O(logn)
0.000002
{ "public_tests": [ { "input": "391\n", "output": "1723" }, { "input": "57\n", "output": "319" }, { "input": "35\n", "output": "57" } ], "private_tests": [], "generated_tests": [ { "input": "4\n", "output": "22\n" }, { "in...
[ 0.0002203978730207085, 0.00001650576047063945, 0.000015901102447910916, 0.000015717888243475434, 0.000015444225252415814, 0.00001543658097801964, 0.000015177687266771033, 0.00001164958332215621, 0.000005776653252593847, 0.000004863629879506905, 0.000004054433037396431, 0.0000037291484964702856...
1331_B. Limericks
1357
1357_271
There was once young lass called Mary, Whose jokes were occasionally scary. On this April's Fool Fixed limerick rules Allowed her to trip the unwary. Can she fill all the lines To work at all times? On juggling the words Right around two-thirds Sh...
n = int(input()) i = 2 while i * i <= n: if n % i == 0: print(i, end='') print(n // i,end='') 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, ...
391
O(n)
0
{ "public_tests": [ { "input": "391\n", "output": "1723" }, { "input": "57\n", "output": "319" }, { "input": "35\n", "output": "57" } ], "private_tests": [], "generated_tests": [ { "input": "4\n", "output": "22\n" }, { "in...
[ 0.0005555167313616072, 0.0004574959672619047, 0.00043933702801804317, 0.00040030553869047623, 0.0002844487996803977, 0.00026543812250054633, 0.00022368734418706297, 0.00021223533102737106, 0.0002071582596563593, 0.00020487472757320805, 0.0001955298021607299, 0.00013548874961756994, 0.0001348...
p03214 Dwango Programming Contest V - Thumbnail
1742
1742_78
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of t...
n = int(input()) frame = list(map(int, input().split())) avg = sum(frame) / n ans= [] for d in frame: ans.append(abs(d-avg)) print(ans.index(min(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, ...
3 1 2 3
O(n)
0.000003
{ "public_tests": [ { "input": "3\n1 2 3", "output": "1" }, { "input": "4\n2 5 2 5", "output": "0" } ], "private_tests": [], "generated_tests": [ { "input": "3\n0 2 3", "output": "1\n" }, { "input": "4\n2 5 3 5", "output": "2\n" }, ...
[ 0.000003885572907561189, 0.0000036844170946241263, 0.000003671703835227273, 0.0000034692071951486015, 0.0000033088510161713293, 0.0000032093270869755246, 0.000003200153081293706, 0.0000031932128496503495, 0.0000031786951486013984, 0.000003172092438811189, 0.000003168346631883741, 0.00000309155...
p03214 Dwango Programming Contest V - Thumbnail
1742
1742_66
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of t...
n=int(input()) a=list(map(int, input().split())) mean=sum(a)/n a=[abs(i-mean) for i in a] b=[] for i in range(n): b.append([a[i],i]) b.sort() print(b[0][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 1 2 3
O(nlogn)
0.000009
{ "public_tests": [ { "input": "3\n1 2 3", "output": "1" }, { "input": "4\n2 5 2 5", "output": "0" } ], "private_tests": [], "generated_tests": [ { "input": "3\n0 2 3", "output": "1\n" }, { "input": "4\n2 5 3 5", "output": "2\n" }, ...
[ 0.000009258149142076444, 0.000009191978713499595, 0.00000912969464690705, 0.000009107947712333883, 0.000009054386934467989, 0.00000903238488131302, 0.00000902446924052593, 0.000008741363627592597, 0.000008738428007499676, 0.000008732631259354361, 0.000008670027854177911, 0.00000865234626015543...
630_F. Selection of Personnel
2286
2286_319
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the n...
def fac(x): p = 1 for i in range(2, x + 1): p *= i return p def c(n, k): return fac(n) // (fac(k) * fac(n - k)) n = int(input()) print(c(n, 5) + c(n, 6) + c(n, 7))
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
O(n**2)
0
{ "public_tests": [ { "input": "7\n", "output": "29\n" } ], "private_tests": [ { "input": "321\n", "output": "66715035255088\n" }, { "input": "8\n", "output": "92\n" }, { "input": "700\n", "output": "16017044425409540\n" }, { ...
[ 0.000026712124194443007, 0.000019421336787110047, 0.000006892372027838411, 0.000002556024423258816, 0.0000025431326663086838, 0.0000025218495475235104, 0.00000248058252560064, 0.000002479548484704732, 0.000002434272125740354, 0.0000023852926790079474, 0.0000023549031448009125, 0.00000233826376...
630_F. Selection of Personnel
2286
2286_14
One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the n...
n = int(input()) numinator = lambda x: n if x == 0 else (n - x)*numinator(x - 1) numinator5 = numinator(4) print(numinator5//120 + numinator5*(n - 5)//720 + numinator5*(n - 5)*(n - 6)//5040)
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
O(1)
0.000006
{ "public_tests": [ { "input": "7\n", "output": "29\n" } ], "private_tests": [ { "input": "321\n", "output": "66715035255088\n" }, { "input": "8\n", "output": "92\n" }, { "input": "700\n", "output": "16017044425409540\n" }, { ...
[ 0.0034716409999999698, 0.0024734520000000426, 0.0023645330000000575, 0.0018141200000000024, 0.00005821450000000002, 0.00005050800000000011, 0.00004315700000000005, 0.000028309000000000003, 0.000026146000000000003, 0.00002359700000000001, 0.000021288999999999965, 0.000021072999999999925, 0.00...
991_B. Getting an A
2593
2593_49
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that...
n = int(input()) l = list(map(int,input().split())) s = sum(l) avg = s/n if(avg>=4.5): print(0) else: req= s-avg l.sort() i=0 while(True): dif = 5-l[i] s =s+dif avg = s/n if(avg>=4.5): print(i+1) break 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 5 3 3 5
O(n**2)
0
{ "public_tests": [ { "input": "4\n5 3 3 5\n", "output": "1\n" }, { "input": "3\n4 4 4\n", "output": "2\n" }, { "input": "4\n5 4 5 5\n", "output": "0\n" } ], "private_tests": [ { "input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2...
[ 0.0001488414515096014, 0.0001303120343170402, 0.0001289237258685612, 0.00012826385488999364, 0.00011215990217165769, 0.00007596891922159268, 0.00007534475805640109, 0.000048656646311106254, 0.000004153093678131934, 0.000004151713568289557, 0.0000034985150779936505, 0.0000021815441686786122, ...
991_B. Getting an A
2593
2593_332
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that...
n = int(input()) L = list(map(int, input().split())) L = sorted(L) s = sum(L) c = 0 p = s/n if p >= 4.5: print(0) else: for i in range(n): s = s-L[i]+5 c += 1 if s/n >= 4.5: print(c) 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, ...
4 5 3 3 5
O(nlogn)
0.000011
{ "public_tests": [ { "input": "4\n5 3 3 5\n", "output": "1\n" }, { "input": "3\n4 4 4\n", "output": "2\n" }, { "input": "4\n5 4 5 5\n", "output": "0\n" } ], "private_tests": [ { "input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2...
[ 0.00010004363559877622, 0.00009202865425590035, 0.00008407454158927012, 0.0000782976266116696, 0.00001528466810140198, 0.000014942826550103645, 0.000014922428580942136, 0.000014856455784902684, 0.000014805406332755164, 0.000014749829133351758, 0.000014744457917767908, 0.000014732266405555069, ...
350_A. TL
305
305_76
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time...
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort() am = a[0] bm = min(b) i = b[0] - 1 while i >= 2*am and a[-1] <= i and i > 0: i -= 1 i+=1 if i == 0 or not(i >= 2*am and a[-1] <= i and i > 0) or bm <= i: print(-1) else: print(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 3 4 5 6
O(nlogn+mlogm)
0.000008
{ "public_tests": [ { "input": "3 1\n3 4 5\n6\n", "output": "-1\n" }, { "input": "3 6\n4 5 2\n8 9 6 10 7 11\n", "output": "5\n" } ], "private_tests": [ { "input": "3 2\n10 20 30\n30 40\n", "output": "-1\n" }, { "input": "1 1\n49\n100\n", ...
[ 0.00000819908887386217, 0.000008155185395429759, 0.000008147321001475147, 0.00000808701094545884, 0.000008079842996093353, 0.00000802578406138456, 0.000008006094068871437, 0.000008005674142492672, 0.000007992565657522386, 0.000007989939527705696, 0.000007978637669540676, 0.00000797752687880459...
350_A. TL
305
305_284
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time...
string = input() numbers = string.split() a = int(numbers[0]) b = int(numbers[1]) string = input() right = list(map(int, string.split())) string = input() wrong = list(map(int, string.split())) p = max(right) q = min(wrong) r = min(right) for x in range(p, q): if r * 2 <= x: print(x) break else: ...
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 3 4 5 6
O(n+m)
0.000001
{ "public_tests": [ { "input": "3 1\n3 4 5\n6\n", "output": "-1\n" }, { "input": "3 6\n4 5 2\n8 9 6 10 7 11\n", "output": "5\n" } ], "private_tests": [ { "input": "3 2\n10 20 30\n30 40\n", "output": "-1\n" }, { "input": "1 1\n49\n100\n", ...
[ 0.0000062693124999999994, 0.000003853057255244756, 0.0000027823561926354896, 0.0000025743187525360515, 0.0000018378096727491258, 0.0000018221307637674828, 0.000001809279611013986, 0.0000017998581730769232, 0.0000017793159282124128, 0.000001544068359375, 0.0000015167503004807695, 0.000001431731...
1149_A. Prefix Sum Primes
1892
1892_347
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in a...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) count = {1: 0, 2: 0} for i in a: count[i] += 1 if count[1] >= 1 and count[2] >= 1: ans = [2] + [1] + [2]*(count[2]-1) + [1]*(count[1] - 1) elif count[1] == 0: ans = [2] * count[2] elif count[2] == 0: 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, ...
9 1 1 2 1 1 1 2 1 1
O(n)
0.000008
{ "public_tests": [ { "input": "9\n1 1 2 1 1 1 2 1 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "5\n1 2 1 2 1\n", "output": "2 1 2 1 1\n" } ], "private_tests": [ { "input": "10\n1 1 1 2 1 1 1 2 2 2\n", "output": "2 1 2 2 2 1 1 1 1 1\n" }, { ...
[ 0.2545490669021277, 0.08960281467796612, 0.0682527589322034, 0.050034803105633796, 0.0002320381103993663, 0.00020899837433035716, 0.000051208935464925705, 0.000044745095539226405, 0.00003290564756337413, 0.00003148547660347466, 0.000028331847915756122, 0.000028084190996503495, 0.000023922981...
1149_A. Prefix Sum Primes
1892
1892_121
We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2. However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in a...
n=int(input()) l=list(map(int,input().split())) flag1=0 flag2=0 for i in range(n): if l[i]==2: flag1=1 break for i in range(n): if l[i]==1: flag2=1 break if flag1==0 or flag2==0: print(*l) else: print(2,1,end=' ') l.remove(2) l.remove(1) l.sort(reverse=True) 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, ...
9 1 1 2 1 1 1 2 1 1
O(nlogn)
0.000029
{ "public_tests": [ { "input": "9\n1 1 2 1 1 1 2 1 1\n", "output": "2 1 2 1 1 1 1 1 1\n" }, { "input": "5\n1 2 1 2 1\n", "output": "2 1 2 1 1\n" } ], "private_tests": [ { "input": "10\n1 1 1 2 1 1 1 2 2 2\n", "output": "2 1 2 2 2 1 1 1 1 1\n" }, { ...
[ 0.00023459033959790214, 0.00022879192956457608, 0.0002025365093285621, 0.00018573787269176136, 0.00002946543363341091, 0.00002937460520407675, 0.00002925580326621819, 0.000029188716916863327, 0.000029090677533852293, 0.000029055373522928407, 0.000029046989580300126, 0.000029041480992700732, ...
677_A. Vanya and Fence
229
229_3630
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
''' import math def BearAndBigBrother(): a, b = map(int, input().split(' ')) year = 0 while 1: if a > b: break else: a *= 3 b *= 2 year += 1 print(year) return None def Tram(): n = int(input()) p = [0] for i in range(1, 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 7 4 5 14
O(n+mlogm)
0.000001
{ "public_tests": [ { "input": "3 7\n4 5 14\n", "output": "4\n" }, { "input": "6 1\n1 1 1 1 1 1\n", "output": "6\n" }, { "input": "6 5\n7 6 8 9 10 5\n", "output": "11\n" } ], "private_tests": [ { "input": "10 561\n657 23 1096 487 785 66 481 554...
[ 0.0000025379297284746503, 0.0000023317318447490426, 0.0000023295793132648603, 0.0000021910136991914342, 0.000002142912464488637, 0.000002137748033216783, 0.0000020957009396853147, 0.000002059125641936189, 0.0000018823503794364717, 0.0000018104705665428319, 0.0000017715513275786712, 0.000001703...
677_A. Vanya and Fence
229
229_689
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
a,b=map(int,input().split()) c=map(int,input().split()) d=0 for i in c: if i>b: d+=2 else: d+=1 print(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, ...
3 7 4 5 14
O(n)
0.000002
{ "public_tests": [ { "input": "3 7\n4 5 14\n", "output": "4\n" }, { "input": "6 1\n1 1 1 1 1 1\n", "output": "6\n" }, { "input": "6 5\n7 6 8 9 10 5\n", "output": "11\n" } ], "private_tests": [ { "input": "10 561\n657 23 1096 487 785 66 481 554...
[ 0.013137972726313773, 0.00860981341791331, 0.007622570723281638, 0.00004214740907725088, 0.00003329572716834202, 0.000032096357360952434, 0.000008797703780594406, 0.000004645894230769232, 0.000004617203985467658, 0.000004597654283216784, 0.00000432832264805507, 0.000004281664854676573, 0.000...
1372_B. Omkar and Last Class of Math
1234
1234_71
In Omkar's last class of math, he learned about the least common multiple, or LCM. LCM(a, b) is the smallest positive integer x which is divisible by both a and b. Omkar, having a laudably curious mind, immediately thought of a problem involving the LCM operation: given an integer n, find positive integers a and b suc...
import math def solve(n): p = 1 for i in range(2, int(math.ceil(math.sqrt(n)))+1): if n % i == 0: p = i break if p != 1: k = n//p else: k = 1 return " ".join([str(k), str(n - k)]) def read(): t = int(input()) for i in range(t): 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 4 6 9
O(n)
0.000016
{ "public_tests": [ { "input": "3\n4\n6\n9\n", "output": "2 2\n3 3\n3 6\n" } ], "private_tests": [ { "input": "1\n646185419\n", "output": "58744129 587441290\n" }, { "input": "3\n312736423\n170982179\n270186827\n", "output": "19031 312717392\n21701 170960478...
[ 0.07466309345762713, 0.0000947079166643903, 0.00008489090878560183, 0.00007869831934536056, 0.00007213407989893206, 0.00006902301500766931, 0.00006839068405043038, 0.0000645014618131797, 0.00006414989036775266, 0.00006347957154327188, 0.0000630476275709447, 0.00006296698149293935, 0.00006230...
1372_B. Omkar and Last Class of Math
1234
1234_634
In Omkar's last class of math, he learned about the least common multiple, or LCM. LCM(a, b) is the smallest positive integer x which is divisible by both a and b. Omkar, having a laudably curious mind, immediately thought of a problem involving the LCM operation: given an integer n, find positive integers a and b suc...
def factors(n): i = 1 while i * i <= n: if n % i == 0: yield i yield n // i i += 1 for t in range(int(input())): n = int(input()) s = sorted(list(factors(n)))[-2] print(s, n - 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, ...
3 4 6 9
O(nlogn)
0.000075
{ "public_tests": [ { "input": "3\n4\n6\n9\n", "output": "2 2\n3 3\n3 6\n" } ], "private_tests": [ { "input": "1\n646185419\n", "output": "58744129 587441290\n" }, { "input": "3\n312736423\n170982179\n270186827\n", "output": "19031 312717392\n21701 170960478...
[ 0.00010264743682821617, 0.00010003886965342788, 0.00008893828461620369, 0.00008549663044585585, 0.00007970038230850473, 0.00007661670951886247, 0.00007618131764458732, 0.00007476097979792167, 0.00007473243550443323, 0.0000746542906739494, 0.0000745425271303552, 0.00007291006023787805, 0.0000...
1206_A. Choose Two Numbers
685
685_583
You are given an array A, consisting of n positive integers a_1, a_2, ..., a_n, and an array B, consisting of m positive integers b_1, b_2, ..., b_m. Choose some element a of A and some element b of B such that a+b doesn't belong to A and doesn't belong to B. For example, if A = [2, 1, 7] and B = [1, 3, 4], we can ...
num_n = int(input()) input_a = input() array_a = input_a.split(" ") num_m = int(input()) input_b = input() array_b = input_b.split(" ") int_array_a = [] for i in array_a: int_array_a.append(int(i)) int_array_b = [] for i in array_b: int_array_b.append(int(i)) int_array_a = sorted(int_array_a) int_array_b = sorted(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, ...
4 1 3 5 7 4 7 5 3 1
O(nlogn+mlogm)
0.000011
{ "public_tests": [ { "input": "4\n1 3 5 7\n4\n7 5 3 1\n", "output": "7 7\n" }, { "input": "3\n3 2 2\n5\n1 5 7 7 9\n", "output": "3 9\n" }, { "input": "1\n20\n2\n10 20\n", "output": "20 20\n" } ], "private_tests": [ { "input": "1\n1\n3\n3 2 1\n...
[ 0.000013296124616830855, 0.000011822703474610876, 0.000011769109867433941, 0.000011758492430429027, 0.000011568149295297338, 0.000011446288528229439, 0.000011423925297650579, 0.000011419632649329988, 0.000011410512516818728, 0.000011363317695188253, 0.000011361798707155683, 0.00001135396640601...
1206_A. Choose Two Numbers
685
685_777
You are given an array A, consisting of n positive integers a_1, a_2, ..., a_n, and an array B, consisting of m positive integers b_1, b_2, ..., b_m. Choose some element a of A and some element b of B such that a+b doesn't belong to A and doesn't belong to B. For example, if A = [2, 1, 7] and B = [1, 3, 4], we can ...
n = int(input()) elementsOfA = [int(i) for i in input().split()] m = int(input()) elementsOfB = [int(i) for i in input().split()] largestElementOfA = -1 largestElementOfB = -1 for item in elementsOfA: if item > largestElementOfA: largestElementOfA = item for item in elementsOfB: if item > largestElem...
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 3 5 7 4 7 5 3 1
O(n+m)
0.000002
{ "public_tests": [ { "input": "4\n1 3 5 7\n4\n7 5 3 1\n", "output": "7 7\n" }, { "input": "3\n3 2 2\n5\n1 5 7 7 9\n", "output": "3 9\n" }, { "input": "1\n20\n2\n10 20\n", "output": "20 20\n" } ], "private_tests": [ { "input": "1\n1\n3\n3 2 1\n...
[ 0.021145089000000002, 0.019746469500000002, 0.000041790663365930944, 0.000004875058252294581, 0.0000044648889996722035, 0.000004449365343640735, 0.0000037411916520979027, 0.000003716119195257867, 0.0000037086001693618877, 0.000003619509403682255, 0.0000031711702496722026, 0.0000031478156004152...
202_A. LLPS
3017
3017_340
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1 ≤ ...
s=input() k=0 t=0 for i in range(len(s)): if ord(s[i])>k: k=ord(s[i]) t=s[i] print(str(t)*s.count(chr(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, ...
mississipp
O(n)
0.000003
{ "public_tests": [ { "input": "mississipp\n", "output": "ssss\n" }, { "input": "bowwowwow\n", "output": "wwwww\n" }, { "input": "codeforces\n", "output": "s\n" }, { "input": "radar\n", "output": "rr\n" } ], "private_tests": [ { ...
[ 0.00047864688314732144, 0.00021482438536658656, 0.00020847211590362764, 0.0002056307554359703, 0.0002005503414554196, 0.000023524968162696677, 0.00000982174859320367, 0.000008213875000000001, 0.000007889496203015736, 0.000007884098325502623, 0.000007874997200065559, 0.000007873350237652972, ...
202_A. LLPS
3017
3017_45
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1 ≤ ...
def solution(l1): l1.sort() l1.reverse() c_out="" for x in l1: if x==l1[0]: c_out+=x return c_out def answer(): l1 = list(input()) print(solution(l1)) answer()
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, ...
mississipp
O(nlogn)
0.00003
{ "public_tests": [ { "input": "mississipp\n", "output": "ssss\n" }, { "input": "bowwowwow\n", "output": "wwwww\n" }, { "input": "codeforces\n", "output": "s\n" }, { "input": "radar\n", "output": "rr\n" } ], "private_tests": [ { ...
[ 0.0000308960731827504, 0.000030841153713515574, 0.00003058109258521448, 0.00003054986942102836, 0.00003052458635286835, 0.00003045058212932222, 0.00003037995728271622, 0.000030367965200196338, 0.0000302655721292443, 0.000030215534494726607, 0.0000301730455543478, 0.000030139132048716173, 0.0...
208_D. Prizes, Prizes, more Prizes
1092
1092_0
Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After ...
import bisect n = int(input()) a = [int(x) for x in input().split()] p = [int(x) for x in input().split()] b = [0, 0, 0, 0, 0] s = 0 for i in a: s += i k = bisect.bisect_right(p, s) while k != 0: if (k == 5) or (p[k] > s): k -= 1 b[k] += s // p[k] s %= p[k] k = 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, ...
4 10 4 39 2 3 5 10 11 12
O(n*m)
0.000007
{ "public_tests": [ { "input": "4\n10 4 39 2\n3 5 10 11 12\n", "output": "3 0 1 0 3\n0\n" }, { "input": "3\n3 10 4\n2 4 10 15 20\n", "output": "1 1 1 0 0\n1\n" } ], "private_tests": [ { "input": "15\n50 12 36 11 38 28 4 11 29 34 22 46 43 2 29\n7 8 10 17 23\n", ...
[ 0.005002261985709601, 0.0007494141093750001, 0.0003652151633049242, 0.00005699663613144669, 0.00000900987661166958, 0.000007778435109812064, 0.0000072868324546547205, 0.000007279332345388987, 0.000006510086429195806, 0.000002130610973011364, 0.000002061913270323427, 0.0000020344382648601398, ...
208_D. Prizes, Prizes, more Prizes
1092
1092_11
Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After ...
n = int(input()) sum,a,b,c,d,e=0,0,0,0,0,0 numbers = [int(x) for x in input().split(' ')] prizes = [int(x) for x in input().split(' ')] prizes.sort() for num in numbers: sum+=num if sum >= prizes[4]: e+=int(sum/prizes[4]) sum = sum%prizes[4] if sum >= prizes[3]: d+=int(sum/prizes[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, ...
4 10 4 39 2 3 5 10 11 12
O(nlogn)
0.000014
{ "public_tests": [ { "input": "4\n10 4 39 2\n3 5 10 11 12\n", "output": "3 0 1 0 3\n0\n" }, { "input": "3\n3 10 4\n2 4 10 15 20\n", "output": "1 1 1 0 0\n1\n" } ], "private_tests": [ { "input": "15\n50 12 36 11 38 28 4 11 29 34 22 46 43 2 29\n7 8 10 17 23\n", ...
[ 0.0005573317392834408, 0.0005458611432826027, 0.000059242256355928415, 0.000014448925758177497, 0.00001438459440477854, 0.000013017800453452798, 0.000012174274425309475, 0.000010661311011254372, 0.00001042368763658217, 0.000009418680561625875, 0.0000012419056366708158 ]
988_B. Substrings Sort
1272
1272_115
You are given n strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String a is a substring of string b if it is possible to choose several consecutive letters in b in such a way...
n=int(input()) list1=[] for i in range(n): s=input() list1.append(s) # list1.sort() for i in range(n-1): for j in range(i,n): if(len(list1[i])>len(list1[j])): list1[i],list1[j]=list1[j],list1[i] f=0 for i in range(n-1): # if(list1[i] in list1[i+1]): x=list1[i+1].find(list1[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 qwerty qwerty qwerty
O(n**2)
0.000002
{ "public_tests": [ { "input": "3\nqwerty\nqwerty\nqwerty\n", "output": "YES\nqwerty\nqwerty\nqwerty\n" }, { "input": "5\na\naba\nabacaba\nba\naba\n", "output": "YES\na\nba\naba\naba\nabacaba\n" }, { "input": "5\na\nabacaba\nba\naba\nabab\n", "output": "NO\n" ...
[ 0.00010277141722130022, 0.000040943857651975275, 0.00004032075550327873, 0.00003056562245332372, 0.000013439147552872176, 0.00001016155154210204, 0.000009862564222299271, 0.000008512257625421236, 0.000008355951154032757, 0.00000804581289767446, 0.0000073307626254200585, 0.000006121670794980211...
988_B. Substrings Sort
1272
1272_278
You are given n strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String a is a substring of string b if it is possible to choose several consecutive letters in b in such a way...
def solve(arr): for i in range(0,len(arr)-1): x = arr[i+1].find(arr[i]) # print(x) if x == -1: return 0 return 1 n=int(input()) arr = [] while n: s = str(input()) arr.append(s) n=n-1 arr.sort(key=len) flag = solve(arr) if flag: print("YES") for i in arr: ...
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 qwerty qwerty qwerty
O(nlogn)
0.000007
{ "public_tests": [ { "input": "3\nqwerty\nqwerty\nqwerty\n", "output": "YES\nqwerty\nqwerty\nqwerty\n" }, { "input": "5\na\naba\nabacaba\nba\naba\n", "output": "YES\na\nba\naba\naba\nabacaba\n" }, { "input": "5\na\nabacaba\nba\naba\nabab\n", "output": "NO\n" ...
[ 0.00005468984352678572, 0.000015998829268991873, 0.00001549388739926988, 0.000015404540413411602, 0.000014163695476398876, 0.00001410803075725712, 0.000013869208340655812, 0.000013858767461668833, 0.000013824701564718575, 0.000013808087826528216, 0.000013707447994674961, 0.00001322565566460874...
158_B. Taxi
223
223_180
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
g = int(input()) j = list(map(int,input().split())) c = c1 = c2 = c3 = p= q = r = 0 for i in j: if(i==4): c+=1 if(i==3): c3+=1 if(i==2): c2+=1 if(i==1): c1+=1 if(c1>c3): p= c1-c3 c+=c3 else: c+=c3 if(c2%2==0): c+=(c2/2) else: q=1 c+=((c2-1)/2) if(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, ...
5 1 2 4 3 3
O(n)
0.000002
{ "public_tests": [ { "input": "5\n1 2 4 3 3\n", "output": "4\n" }, { "input": "8\n2 3 4 4 2 1 3 1\n", "output": "5\n" } ], "private_tests": [ { "input": "5\n4 4 4 4 4\n", "output": "5\n" }, { "input": "3\n3 4 3\n", "output": "3\n" },...
[ 0.005241149242515111, 0.000026695246902779656, 0.000018943660060642484, 0.000014690123716127625, 0.000013511955706402973, 0.000012963597328452798, 0.000011783193291083918, 0.000011617678731424826, 0.000011427448754370629, 0.000010232013835773601, 0.000009670845552884616, 0.00000918147094897290...
158_B. Taxi
223
223_3085
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
n = int(input()) s = list(map(int, input().split())) s.sort() i, j = 0, len(s)-1 res = 0 while i<j: if s[i]+s[j]<=4: s[j] += s[i] i += 1 else: j -= 1 res += 1 print(res+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 2 4 3 3
O(nlogn)
0.000015
{ "public_tests": [ { "input": "5\n1 2 4 3 3\n", "output": "4\n" }, { "input": "8\n2 3 4 4 2 1 3 1\n", "output": "5\n" } ], "private_tests": [ { "input": "5\n4 4 4 4 4\n", "output": "5\n" }, { "input": "3\n3 4 3\n", "output": "3\n" },...
[ 0.001224154115234375, 0.0011728636576267932, 0.0011280222432391827, 0.00017532126924892544, 0.0001153099935669799, 0.00010833444065504809, 0.00009938330442799389, 0.00009875662011035841, 0.00009756334898109703, 0.0000964900152152535, 0.00007852460104439067, 0.00007704482462982417, 0.00006996...
1130_B. Two Cakes
3033
3033_146
Sasha and Dima want to buy two n-tier cakes. Each cake should consist of n different tiers: from the size of 1 to the size of n. Tiers should go in order from the smallest to the biggest (from top to bottom). They live on the same street, there are 2 ⋅ n houses in a row from left to right. Each house has a pastry shop...
n=int(input()) a=[int(v) for v in input().split()] b=[[] for _ in range(n+1)] for i in range(2*n): b[a[i]].append(i+1) f=b[1][0]+b[1][1]-2 for j in range(1,n): p=f+abs(b[j][0]-b[j+1][0])+abs(b[j][1]-b[j+1][1]) q=f+abs(b[j][0]-b[j+1][1])+abs(b[j][1]-b[j+1][0]) f=min(p,q) print(f)
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 4 1 3 2 2 3 1 4
O(n)
0.000002
{ "public_tests": [ { "input": "4\n4 1 3 2 2 3 1 4\n", "output": "17\n" }, { "input": "3\n1 1 2 2 3 3\n", "output": "9\n" }, { "input": "2\n2 1 1 2\n", "output": "5\n" } ], "private_tests": [ { "input": "3\n1 3 3 2 1 2\n", "output": "13\n...
[ 0.00002953618925491167, 0.000015436490714813994, 0.000015070277942611133, 0.000014034206406533734, 0.00001359296862346722, 0.000012390321582714161, 0.000010365640405883352, 0.000010264023068728147, 0.000009522323371387298, 0.000009112609150217705, 0.000008591515228911715, 0.0000079484106206293...
1130_B. Two Cakes
3033
3033_135
Sasha and Dima want to buy two n-tier cakes. Each cake should consist of n different tiers: from the size of 1 to the size of n. Tiers should go in order from the smallest to the biggest (from top to bottom). They live on the same street, there are 2 ⋅ n houses in a row from left to right. Each house has a pastry shop...
class House: c = 0 def __init__(self, val): self.id = House.c + 1 self.val = int(val) House.c += 1 n = int(input()) a = list(map(House, input().split())) a.sort(key=lambda x: x.val) length = 0 pos1 = pos2 = 1 for i in range(n * 2): if i % 2: length += abs(pos2 - a[i].id) ...
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 4 1 3 2 2 3 1 4
O(nlogn)
0.000026
{ "public_tests": [ { "input": "4\n4 1 3 2 2 3 1 4\n", "output": "17\n" }, { "input": "3\n1 1 2 2 3 3\n", "output": "9\n" }, { "input": "2\n2 1 1 2\n", "output": "5\n" } ], "private_tests": [ { "input": "3\n1 3 3 2 1 2\n", "output": "13\n...
[ 0.00004952684358533486, 0.000046809517279714084, 0.000034147315960026734, 0.00003038617272687925, 0.000029815803458306073, 0.000028791296726629883, 0.000028390617664957624, 0.000028283522067681813, 0.000028171227003790865, 0.00002814326553218671, 0.00002800367024720886, 0.000027959274318928963...
862_B. Mahmoud and Ehab and the bipartiteness
2854
2854_107
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and ...
def readln(): return map(int, input().rstrip().split()) data = {} n = int(input()) for i in range(1, n + 1): data[i] = [] for i in range(0, n - 1): u, v = readln() data[u].append(v) data[v].append(u) l = [0, 0] visited = [False] * (n + 1) stk = [(1, 0)] while stk: u = stk.pop() visited[u[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 1 2 1 3
O(n**2)
0
{ "public_tests": [ { "input": "3\n1 2\n1 3\n", "output": "0\n" }, { "input": "5\n1 2\n2 3\n3 4\n4 5\n", "output": "2\n" } ], "private_tests": [ { "input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4\n", "output": "16\n" }, { "input": "2...
[ 0.0000014955462909155754, 7.408169604358875e-7, 6.992889841239333e-7, 2.6457541022362065e-7, 1.82684450934686e-7, 1.5654778854893098e-7, 1.487732116772551e-7, 1.4662131444084603e-7, 1.4007335452529905e-7, 1.3022962513375438e-7, 1.2076883519274277e-7, 1.2060172931775338e-7, 1.1891152903871245...
862_B. Mahmoud and Ehab and the bipartiteness
2854
2854_30
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and ...
n = int(input()) G = [] for i in range(n): G.append([]) for i in range(n-1): u,v = [int(x)-1 for x in input().split()] G[u].append((v,u)) G[v].append((u,v)) options = G[0] visited = [0]*n visited[0] = 1 colors = [0]*n while options: t = options.pop() if visited[t[0]] == 0: visited[t[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 1 2 1 3
O(n)
0.000017
{ "public_tests": [ { "input": "3\n1 2\n1 3\n", "output": "0\n" }, { "input": "5\n1 2\n2 3\n3 4\n4 5\n", "output": "2\n" } ], "private_tests": [ { "input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4\n", "output": "16\n" }, { "input": "2...
[ 0.000023407885348888743, 0.000021250230718094676, 0.00002039380721116352, 0.00001938731578553566, 0.000018715590199977554, 0.00001811107223538011, 0.000017627375286699722, 0.000017347661949011337, 0.00001723399353936384, 0.00001669571032176558, 0.00001659884473753126, 0.000016434659764769536, ...
605_A. Sorting Railway Cars
1053
1053_38
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it...
n=int(input()) arr=list(map(int,input().split())) l=[n]*(n+1) for c in arr: l[c]=l[c-1]-1 print(min(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, ...
5 4 1 2 5 3
O(n)
0.000004
{ "public_tests": [ { "input": "5\n4 1 2 5 3\n", "output": "2\n" }, { "input": "4\n4 1 3 2\n", "output": "2\n" } ], "private_tests": [ { "input": "7\n1 3 5 7 2 4 6\n", "output": "5\n" }, { "input": "7\n1 2 3 6 7 4 5\n", "output": "2\n" ...
[ 0.0000076269904392482515, 0.0000071273445968094415, 0.000006978106424825175, 0.00000664560631555944, 0.000004989614223666959, 0.000004971738759287588, 0.000004959715799825175, 0.000004944564357517483, 0.0000048430492651879375, 0.0000045774787478146855, 0.000004574504111123252, 0.00000455782282...
605_A. Sorting Railway Cars
1053
1053_44
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it...
n=int(input()) p=list(map(int,input().split())) for i in range(n): p[i]=[p[i],i] p.sort() b=1 d=[] for i in range(n-1): if p[i][1]<p[i+1][1]: b+=1 else: d.append(b) b=1 d.append(b) print(n-max(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, ...
5 4 1 2 5 3
O(nlogn)
0.000015
{ "public_tests": [ { "input": "5\n4 1 2 5 3\n", "output": "2\n" }, { "input": "4\n4 1 3 2\n", "output": "2\n" } ], "private_tests": [ { "input": "7\n1 3 5 7 2 4 6\n", "output": "5\n" }, { "input": "7\n1 2 3 6 7 4 5\n", "output": "2\n" ...
[ 0.00010717719014969407, 0.00001533465397390213, 0.000014921019455017772, 0.0000010121112296928812, 9.514981028022732e-7, 9.308678277979405e-7, 8.780720695950147e-7, 8.748495882838646e-7, 8.696234674020206e-7, 8.5124818240615e-7, 7.851303713519941e-7, 7.492896118047152e-7, 7.452203998596955e-...
1155_C. Alarm Clocks Everywhere
1915
1915_63
Ivan is going to sleep now and wants to set his alarm clock. There will be many necessary events tomorrow, the i-th of them will start during the x_i-th minute. Ivan doesn't want to skip any of the events, so he has to set his alarm clock in such a way that it rings during minutes x_1, x_2, ..., x_n, so he will be awak...
def nod(a,b): while a*b!=0: if a>b: a%=b else: b%=a return a+b n,m=map(int,input().split()) l=[int(j) for j in input().split()] p=[int(j) for j in input().split()] nd=l[1]-l[0] ans=-1 for i in range(2,n): nd=nod(nd,l[i]-l[i-1]) for i in range(m): if nd%...
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 5 3 12 18 2 6 5 3 3
O(n*m)
0.000002
{ "public_tests": [ { "input": "3 5\n3 12 18\n2 6 5 3 3\n", "output": "YES\n 3 4\n" }, { "input": "4 2\n1 5 17 19\n2 1\n", "output": "YES\n 1 1\n" }, { "input": "4 2\n1 5 17 19\n4 5\n", "output": "NO\n" } ], "private_tests": [ { "input": "2 1\n...
[ 0.0000031911135407561194, 0.0000030601504452578674, 0.000002175035661604021, 0.0000021546999426354893, 0.0000021436632703234267, 0.000002107392127403846, 0.000001993166220498252, 0.000001978592302229021, 0.000001975339543269231, 0.000001955282001201923, 0.000001948166329763986, 8.5132770159527...
1155_C. Alarm Clocks Everywhere
1915
1915_158
Ivan is going to sleep now and wants to set his alarm clock. There will be many necessary events tomorrow, the i-th of them will start during the x_i-th minute. Ivan doesn't want to skip any of the events, so he has to set his alarm clock in such a way that it rings during minutes x_1, x_2, ..., x_n, so he will be awak...
import math n,m=[int(i) for i in input().split()] x=[int(i) for i in input().split()] p=[int(i) for i in input().split()] x_2=[] for i in range(1,len(x)): x_2.append(x[i]-x[i-1]) g=x_2[0] for i in range(1,len(x_2)): g=math.gcd(g,x_2[i]) b=False for i in range (0,len(p)): if(g%p[i]==0): print('YES')...
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 5 3 12 18 2 6 5 3 3
O(n+m)
0.000004
{ "public_tests": [ { "input": "3 5\n3 12 18\n2 6 5 3 3\n", "output": "YES\n 3 4\n" }, { "input": "4 2\n1 5 17 19\n2 1\n", "output": "YES\n 1 1\n" }, { "input": "4 2\n1 5 17 19\n4 5\n", "output": "NO\n" } ], "private_tests": [ { "input": "2 1\n...
[ 0.000009792629794034092, 0.000007566896470716783, 0.000006404613090034966, 0.000005896187322443183, 0.000005383839051573427, 0.000005355754015515734, 0.000005350347956730769, 0.0000050123511117788475, 0.000004956279979785839, 0.000004935445162259615, 0.000004887527193509616, 0.0000045140038652...
127_B. Canvas Frames
659
659_33
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break th...
n=int(input()) m=list(map(int,input().split())) k=set(m) k=list(k) c=0 for i in k: c+=m.count(i)//2 print(c//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 2 4 3 2 3
O(n**2)
0
{ "public_tests": [ { "input": "5\n2 4 3 2 3\n", "output": "1" }, { "input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n", "output": "3" }, { "input": "4\n3 3 3 5\n", "output": "0" } ], "private_tests": [ { "input": "4\n1 1 1 1\n", "output": "1" ...
[ 3.4288626948256943e-7, 2.6163340925831363e-7, 2.524755757709509e-7, 2.056319527880441e-7, 1.94362781583301e-7, 1.3426653771714172e-7, 1.3377280439031098e-7, 1.319245673853839e-7, 1.3016990491048768e-7, 1.2842377254127209e-7, 1.2813891222343644e-7, 1.270161004399943e-7, 1.2675709088644336e-7,...
127_B. Canvas Frames
659
659_55
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break th...
n = int(input()) a = input() a = a.split() dic = {} for i in a: dic[i] = dic.get(i, 0) + 1 c = 0 for v in dic.values(): c += v//2 print(c//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 2 4 3 2 3
O(n)
0.000003
{ "public_tests": [ { "input": "5\n2 4 3 2 3\n", "output": "1" }, { "input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n", "output": "3" }, { "input": "4\n3 3 3 5\n", "output": "0" } ], "private_tests": [ { "input": "4\n1 1 1 1\n", "output": "1" ...
[ 0.0000055711123798076925, 0.000004890601835664336, 0.000004747524407233392, 0.0000047247088751092655, 0.000004589977518575175, 0.000004508734388658216, 0.000004496728338068182, 0.000004495542791193182, 0.000004485295782342657, 0.000004111225975196679, 0.000004086880736451049, 0.000004086774161...
127_B. Canvas Frames
659
659_63
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break th...
n=int(input()) a=list(map(int, input().split())) a.sort() b,t,c=[],1,0 for i in range(n): if i==n-1 or a[i]!=a[i+1]: c+=t//4 if t%4>=2:b.append(t%2) t=1 else:t+=1 print(len(b)//2+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 2 4 3 2 3
O(nlogn)
0.000014
{ "public_tests": [ { "input": "5\n2 4 3 2 3\n", "output": "1" }, { "input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n", "output": "3" }, { "input": "4\n3 3 3 5\n", "output": "0" } ], "private_tests": [ { "input": "4\n1 1 1 1\n", "output": "1" ...
[ 0.00051515368828125, 0.0000259985321693086, 0.0000150242596141977, 0.00001476371379772218, 0.000014585639453944018, 0.00001446533343980108, 0.000014462207803287678, 0.000014448089723759328, 0.00001444627786233571, 0.000014438867727169555, 0.000014433701119074192, 0.000014422664839226998, 0.0...
595_A. Vitaly and Night
3046
3046_65
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ...
n,m=map(int,input().split()) l=0 for i in range(n): arr=list(map(int,input().split())) j=1 while j<len(arr): if arr[j-1]==1 or arr[j]==1: l+=1 j+=2 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, ...
1 3 1 1 0 1 0 0
O(n*m)
0.000004
{ "public_tests": [ { "input": "1 3\n1 1 0 1 0 0\n", "output": "2\n" }, { "input": "2 2\n0 0 0 1\n1 0 1 1\n", "output": "3\n" } ], "private_tests": [ { "input": "1 1\n0 0\n", "output": "0\n" }, { "input": "1 1\n0 1\n", "output": "1\n" ...
[ 0.000007889967315887236, 0.00000786255978201486, 0.0000077498124180507, 0.000007564750204873251, 0.000007507774789663463, 0.000006745794197989511, 0.000006358550999781469, 0.000006305109456949301, 0.000005917744222574301, 0.00000581597660347465, 0.000005679196623688812, 0.000005662904023710664...
595_A. Vitaly and Night
3046
3046_103
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered ...
n, m = map(int, input().split()) ans = 0 for _ in range(n): windows = list(map(int, input().split())) ans += sum(min(1, windows[i] + windows[i + 1]) for i in range(0, m * 2, 2)) 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, ...
1 3 1 1 0 1 0 0
O(n)
0.000002
{ "public_tests": [ { "input": "1 3\n1 1 0 1 0 0\n", "output": "2\n" }, { "input": "2 2\n0 0 0 1\n1 0 1 1\n", "output": "3\n" } ], "private_tests": [ { "input": "1 1\n0 0\n", "output": "0\n" }, { "input": "1 1\n0 1\n", "output": "1\n" ...
[ 0.000004368191843312938, 0.000004248807009396853, 0.000002977742078234266, 0.000002935783298732518, 0.0000029332395104895106, 0.0000028873093449519235, 0.0000028505045208697554, 0.000002738415537587413, 0.000002729689890187937, 0.000002723919102381993, 0.000002712928745083042, 0.00000271010500...
729_A. Interview with Oleg
307
307_116
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters. There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end...
n = int(input()) s = input() p = "ogo" while len(p) < len(s): p += "go" while len(p) > 1: s = s.replace(p, "***") p = p[:-2] 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, ...
7 aogogob
O(n**2)
0
{ "public_tests": [ { "input": "7\naogogob\n", "output": "a***b\n" }, { "input": "9\nogoogoogo\n", "output": "*********\n" }, { "input": "13\nogogmgogogogo\n", "output": "***gmg***\n" } ], "private_tests": [ { "input": "2\nog\n", "output"...
[ 0.0000516137681683597, 0.000004286305084745763, 0.000001257031885682975, 0.0000012224695309262559, 0.0000010403159648687703, 9.500674875967418e-8, 1.2214936662977533e-8, 1.1747563364446697e-8, 1.1579122295768137e-8, 1.1537113781303115e-8, 1.078797631983354e-8, 1.0504215711285933e-8, 9.521666...
729_A. Interview with Oleg
307
307_14
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters. There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end...
n = int(input()) s = input() for i in range(100, 0, -1): s = s.replace('o' + 'go' * i, '***') 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, ...
7 aogogob
O(n)
0
{ "public_tests": [ { "input": "7\naogogob\n", "output": "a***b\n" }, { "input": "9\nogoogoogo\n", "output": "*********\n" }, { "input": "13\nogogmgogogogo\n", "output": "***gmg***\n" } ], "private_tests": [ { "input": "2\nog\n", "output"...
[ 0.000018669091687609267, 0.000012828647495083043, 0.000012366546246722029, 0.00001142693597027972, 0.000010814242897727273, 0.000010507654952469406, 0.000010425003578452797, 0.000008495068345716782, 0.000008478144995629372, 0.000008418085063374126, 0.00000786908845061189, 0.0000077900774830638...
p03957 CODE FESTIVAL 2016 qual C - CF
493
493_134
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way. You are given a string s consisting of uppercase English letters. Determine whether the string `CF` can be obtai...
N=input() c=0 flag = 0 for i in N: if i=='C' and c==0 :c+=1 if i=='F' and c==1: flag=1 if flag==1: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, ...
CF
O(n)
0
{ "public_tests": [ { "input": "CF", "output": "Yes" }, { "input": "CODEFESTIVAL", "output": "Yes" }, { "input": "FCF", "output": "Yes" }, { "input": "FESTIVALCODE", "output": "No" } ], "private_tests": [], "generated_tests": [ ...
[ 8.725553567526224e-7, 5.139667695585664e-7, 4.7015493881118887e-7, 4.6022525131118886e-7, 4.519876119973778e-7, 4.4964729020979023e-7, 4.4586702360139864e-7, 4.4154120684003503e-7, 4.1877297312062937e-7, 3.70952496722028e-7, 3.537387592875874e-7, 3.4455621722027976e-7, 3.436606752622378e-7, ...
p03957 CODE FESTIVAL 2016 qual C - CF
493
493_64
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way. You are given a string s consisting of uppercase English letters. Determine whether the string `CF` can be obtai...
s = input() if 'C' in s and 'F' in s and s.index('C') < s.rindex('F'): 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, ...
CF
O(1)
0.000001
{ "public_tests": [ { "input": "CF", "output": "Yes" }, { "input": "CODEFESTIVAL", "output": "Yes" }, { "input": "FCF", "output": "Yes" }, { "input": "FESTIVALCODE", "output": "No" } ], "private_tests": [], "generated_tests": [ ...
[ 0.000011473000000000003, 0.000004525500000000003, 0.000004250000000000002, 0.000002633500000000001, 0.0000024545000000000017, 0.000002443, 0.0000022405, 0.000002099999999999997, 0.000002059500000000003, 0.000001943000000000005, 0.0000018729999999999938, 0.0000018429999999999991, 0.0000018305...
622_A. Infinite Sequence
5
5_100
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not d...
n=int(input()) k=1 while(n>k): n-=k k+=1 print(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, ...
56
O(n)
0
{ "public_tests": [ { "input": "56\n", "output": "1\n" }, { "input": "5\n", "output": "2\n" }, { "input": "55\n", "output": "10\n" }, { "input": "3\n", "output": "2\n" }, { "input": "10\n", "output": "4\n" } ], "pr...
[ 2.2559156468531467e-7, 1.0619797585227274e-7, 9.780440067744756e-8, 9.76160402097902e-8, 9.658499508304197e-8, 9.640240521197553e-8, 9.573179359702796e-8, 8.14532069493007e-8, 7.957141881555945e-8, 7.865839434003496e-8, 7.739286494755246e-8, 7.715599049388112e-8, 7.474493280157343e-8, 7.14...
622_A. Infinite Sequence
5
5_25
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not d...
import math number = input() current = 0 num = int(number) D = math.sqrt(1 + 8*num) n = ( D - 1 )/2 n = int(n) summa = n*(n+1)/2 if num == summa: n-=1 summa = n*(n+1)/2 if num>summa: num -= summa num = int (num) print (num)
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, ...
56
O(1)
0.000002
{ "public_tests": [ { "input": "56\n", "output": "1\n" }, { "input": "5\n", "output": "2\n" }, { "input": "55\n", "output": "10\n" }, { "input": "3\n", "output": "2\n" }, { "input": "10\n", "output": "4\n" } ], "pr...
[ 0.00010464699999999998, 0.000031196000000000004, 0.000014424500000000004, 0.000012899, 0.000011376500000000002, 0.000008035499999999994, 0.0000075930000000000745, 0.000006021000000000002, 0.000005931000000000001, 0.000005255499999999984, 0.000005164500000000001, 0.000004911000000000001, 0.00...
299_A. Ksusha and Array
3018
3018_50
Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! Input The first line contains integer n (1 ...
a = int(input()) s = [int(x) for x in input().split()] key = True c = min(s) for i in s: if i % c != 0: key = False print(-1) break if key: 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, ...
3 2 3 5
O(n)
0.000001
{ "public_tests": [ { "input": "3\n2 3 5\n", "output": "-1\n" }, { "input": "5\n2 1 3 1 6\n", "output": "1\n" }, { "input": "3\n2 2 4\n", "output": "2\n" } ], "private_tests": [ { "input": "2\n6 4\n", "output": "-1\n" }, { "...
[ 0.000007600765051354896, 0.000002899577947443182, 0.0000027344962576486016, 0.000002535928048513986, 0.000002411008509069056, 0.0000023514019613199306, 0.0000023304736259833916, 0.0000023153922503277975, 0.0000021220524065777975, 0.000002063702114291958, 0.000002057573180725525, 0.000002056610...
299_A. Ksusha and Array
3018
3018_143
Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! Input The first line contains integer n (1 ...
n = int(input()) a = list(map(int, input().split())) a.sort() t = a[0] for x in a: if x % a[0] != 0: t = -1 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 2 3 5
O(nlogn)
0.000008
{ "public_tests": [ { "input": "3\n2 3 5\n", "output": "-1\n" }, { "input": "5\n2 1 3 1 6\n", "output": "1\n" }, { "input": "3\n2 2 4\n", "output": "2\n" } ], "private_tests": [ { "input": "2\n6 4\n", "output": "-1\n" }, { "...
[ 0.000009302153898131828, 0.000008766126971137992, 0.000008576539589054022, 0.000008073883404272443, 0.000008054959163640844, 0.000008051736182895379, 0.000008037957499425981, 0.000008029153105189924, 0.000008012696411736164, 0.000008006256033454572, 0.00000799840750955302, 0.000007997582461057...
962_B. Students in Railway Carriage
566
566_101
There are n consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. The university team for the Olympiad consists of a student-programmers and b student-athletes. Determine the largest number of students from all a+b students, which you can put in the railway carriage so t...
n, a, b = map(int, input().split(' ')) tot = a + b lens = [len(s) for s in input().split('*')] for l in lens: if a > b: if l % 2 == 1: a -= min(a, (l+1)//2) else: a -= min(a, l//2) b -= min(b, l//2) else: a -= min(a, l//2) if 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, ...
11 3 10 .*....**.*.
O(n)
0.000005
{ "public_tests": [ { "input": "11 3 10\n.*....**.*.\n", "output": "7\n" }, { "input": "5 1 1\n*...*\n", "output": "2\n" }, { "input": "3 2 3\n***\n", "output": "0\n" }, { "input": "6 2 3\n*...*.\n", "output": "4\n" } ], "private_test...
[ 0.000028995174265187935, 0.000023305795345279723, 0.000021686463286713285, 0.000018509609415974653, 0.00001612097805124563, 0.000015100337467220282, 0.000013415044476228025, 0.000013247660893793707, 0.00001318815511636801, 0.000013116303094486444, 0.000012510098210303062, 0.0000124457730140952...
962_B. Students in Railway Carriage
566
566_183
There are n consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. The university team for the Olympiad consists of a student-programmers and b student-athletes. Determine the largest number of students from all a+b students, which you can put in the railway carriage so t...
n, a, b = list(map(int, input().split())) row = sorted([_ for _ in input().split('*') if _], key=lambda x: len(x), reverse=True) total = 0 for _ in row: if a == 0 and b == 0: break l = len(_) odd, even = l // 2 + l % 2, l // 2 if a > b: da = min(odd, a) db = min(even, b) total += da + db a -= da b -= 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, ...
11 3 10 .*....**.*.
O(nlogn)
0.000009
{ "public_tests": [ { "input": "11 3 10\n.*....**.*.\n", "output": "7\n" }, { "input": "5 1 1\n*...*\n", "output": "2\n" }, { "input": "3 2 3\n***\n", "output": "0\n" }, { "input": "6 2 3\n*...*.\n", "output": "4\n" } ], "private_test...
[ 0.00007825720394449301, 0.00007187651623961975, 0.000069746563633632, 0.00002918886736640028, 0.000015795044338094154, 0.00001539759966214758, 0.000013154764124439085, 0.000013152912387021614, 0.000013044255983013201, 0.000012792888344667027, 0.000010705905525066982, 0.000009666459191513976, ...
1005_E1. Median on Segments (Permutations Edition)
1332
1332_41
You are given a permutation p_1, p_2, ..., p_n. A permutation of length n is a sequence such that each integer between 1 and n occurs exactly once in the sequence. Find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of the median of p_l, p_{l+1}, ..., p_r is exactly the given number m. The ...
n,m=map(int,input().split()) p=list(map(int,input().split())) cur=0 while p[cur]!=m: cur+=1 pos=cur s={} cnt,len=0,0 while cur>=0: if p[cur]<=m: cnt+=1 len+=1 if 2*cnt-len in s: s[2*cnt-len]+=1 else: s[2*cnt-len]=1 cur-=1 cur=pos cnt,len,ans=0,0,0 while cur<n: if p[cu...
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 4 2 4 5 3 1
O(n)
0.000001
{ "public_tests": [ { "input": "5 4\n2 4 5 3 1\n", "output": "4" }, { "input": "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9\n", "output": "48" }, { "input": "5 5\n1 2 3 4 5\n", "output": "1" } ], "private_tests": [ { "input": "2 1\n1 2\n", ...
[ 0.00001614266104403409, 0.000013283508563701923, 0.00001183399656723485, 0.000011533338375946972, 0.000010852103971636512, 0.000010408568618881118, 0.000009188592151988638, 0.000006249931148929196, 0.000004721522549715909, 0.0000038189886909965025, 0.0000033146597191870633, 0.00000225941631610...
1005_E1. Median on Segments (Permutations Edition)
1332
1332_16
You are given a permutation p_1, p_2, ..., p_n. A permutation of length n is a sequence such that each integer between 1 and n occurs exactly once in the sequence. Find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of the median of p_l, p_{l+1}, ..., p_r is exactly the given number m. The ...
class BIT(): def __init__(self,n): self.BIT=[0]*(n+1) self.num=n def query(self,idx): res_sum = 0 while idx > 0: res_sum += self.BIT[idx] idx -= idx&(-idx) return res_sum #Ai += x O(logN) def update(self,idx,x): while idx <= self....
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 4 2 4 5 3 1
O(nlogn)
0.000042
{ "public_tests": [ { "input": "5 4\n2 4 5 3 1\n", "output": "4" }, { "input": "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9\n", "output": "48" }, { "input": "5 5\n1 2 3 4 5\n", "output": "1" } ], "private_tests": [ { "input": "2 1\n1 2\n", ...
[ 0.0000424908437598687, 0.000025736105984502237, 0.00002545646302125644, 0.0000191873001671678, 0.00000421669032858669, 0.0000013598302318993956, 1.2383768575174824e-9, 1.4319957386363636e-10 ]
296_A. Yaroslav and Permutations
2266
2266_172
Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav. Input The first line contains integer n (1 ≤ n ≤ 100) — the numb...
n = int(input()) a = list(map(int, input().split())) mx = 0 for i in a: mx = max(mx, a.count(i)) if n%2==1: if mx>(n//2)+1: print('NO') else: print('YES') else: if mx>n//2: print('NO') else: print('YES')
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 7 7 7 7
O(n**2)
0
{ "public_tests": [ { "input": "4\n7 7 7 7\n", "output": "NO\n" }, { "input": "3\n1 1 2\n", "output": "YES\n" }, { "input": "1\n1\n", "output": "YES\n" } ], "private_tests": [ { "input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317...
[ 0.00008001762134628722, 0.000024009044308585897, 0.000010487450471813497, 0.000009849104990373795, 0.000009159109525769162, 0.000004668331641707105, 4.2216524306983064e-7, 1.3938263598826656e-7, 1.2598326067131132e-7, 1.2456709611296062e-7, 1.240392101617791e-7, 1.2394521506813573e-7, 1.2393...
296_A. Yaroslav and Permutations
2266
2266_298
Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav. Input The first line contains integer n (1 ≤ n ≤ 100) — the numb...
# your code goes here n=int(input()) num=map(int,input().split()) from collections import Counter freq=Counter(num) maximum=0 for i in freq: if(maximum<freq[i]): maximum=freq[i] if(maximum <=((n+1)//2)): 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, ...
4 7 7 7 7
O(n)
0.000002
{ "public_tests": [ { "input": "4\n7 7 7 7\n", "output": "NO\n" }, { "input": "3\n1 1 2\n", "output": "YES\n" }, { "input": "1\n1\n", "output": "YES\n" } ], "private_tests": [ { "input": "100\n317 316 317 316 317 316 317 316 317 316 316 317 317...
[ 0.0000052544828125, 0.000005108046601835664, 0.000005004983984375, 0.00000478978671875, 0.000004513041015625, 0.000004413307421875, 0.000004355595703125001, 0.000004270207222465035, 0.000003767025390625, 0.000003716958203125001, 0.0000035057357681381124, 0.0000034870008468094405, 0.000003342...
68_B. Energy exchange
967
967_5
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be...
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) left = 0 right = a[-1] for i in range(100): mid = (left + right) / 2.0 s1 = sum([x - mid for x in a if x >= mid]) * (100 - k) / 100.0 s2 = sum([mid - x for x in a if x < mid]) if s1 >= s2: left = mid else: ...
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 90 1 11
O(n)
0.000095
{ "public_tests": [ { "input": "2 90\n1 11\n", "output": "1.9090909088\n" }, { "input": "3 50\n4 2 1\n", "output": "2.0000000001\n" } ], "private_tests": [ { "input": "14 6\n256 465 759 589 242 824 638 985 506 128 809 105 301 827\n", "output": "523.427098675...
[ 0.00009579514130791085, 0.0000954163802857299, 0.0000834949481534091, 0.000060383975101070805, 0.00005796360092056382, 0.000056056267482517486, 0.00004684614065231643, 0.0000349169669607736, 0.00003396202668815559, 0.000033919744577687936, 0.00003389791511418269, 0.000033881935246394235, 0.0...
68_B. Energy exchange
967
967_19
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be...
n,k=map(int,input().split()) l=list(map(int,input().split())) l.sort(reverse=True) s=sum(l) s1=0 s2=s ans=0 k=100-k for i in range(n-1): # ans=max(ans,(s1*k+100*s2)/((i+1)*k+100*(n-i-1))) s1+=l[i] s2-=l[i] a=(s1*k+100*s2)/((i+1)*k+100*(n-i-1)) if a<=l[i] and a>=l[i+1]: ans=max(ans,a) # print (s1,s2,ans,i,s1*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 90 1 11
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2 90\n1 11\n", "output": "1.9090909088\n" }, { "input": "3 50\n4 2 1\n", "output": "2.0000000001\n" } ], "private_tests": [ { "input": "14 6\n256 465 759 589 242 824 638 985 506 128 809 105 301 827\n", "output": "523.427098675...
[ 0.000050846154542722905, 0.000045039554086538465, 0.000020387413966892483, 0.000019823734830937035, 0.00000933291372205558, 0.000009305227158563496, 0.000009161737377088574, 0.000007911455283353635, 0.000006114586051653171, 0.000005507749297858727, 0.000005136998976826344, 0.000005044632603180...
1427_D. Unshuffling a Deck
1733
1733_64
You are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation. * Choose 2 ≤ k ≤ n and split the deck in k nonempty contiguous parts D_1, D_2,..., D_k (D_1 contains the first |D_1| cards of the deck, D_2 contains the f...
import sys input=sys.stdin.readline n=int(input()) c=list(map(int,input().split())) ac=[] f=int(n%2==1) for tar in range(1,n+1)[::-1]: split=[] cnt=0 if f: for i in range(n): cnt+=1 if tar<=c[i]: split.append(cnt) cnt=0 else: for 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, ...
1 1
O(n**2)
0
{ "public_tests": [ { "input": "1\n1\n", "output": "0\n" }, { "input": "6\n6 5 4 3 2 1\n", "output": "4\n3 1 1 4\n3 1 1 4\n3 1 1 4\n3 2 2 2\n" }, { "input": "4\n3 1 2 4\n", "output": "2\n3 1 2 1\n2 1 3\n" } ], "private_tests": [ { "input": "44\...
[ 0.00022690560123918277, 0.0000018382833412439426, 8.110459445615356e-7, 7.712708786785805e-7, 4.970941808675116e-7, 3.9440993771853146e-7, 2.1550806498843646e-7, 1.9536969129276751e-7, 8.416215355666874e-8, 7.997666745236913e-8, 7.803899344155313e-8, 7.584107753558187e-8, 4.969637784090912e-...
1427_D. Unshuffling a Deck
1733
1733_49
You are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation. * Choose 2 ≤ k ≤ n and split the deck in k nonempty contiguous parts D_1, D_2,..., D_k (D_1 contains the first |D_1| cards of the deck, D_2 contains the f...
n=int(input()) c=[*map(int,input().split())] if n%2:c=[n+1-i for i in c] q=0 o=[] for i in range(n): j=c.index(i+1) m=[1]*i if j-i+1:m.append(j-i+1) m+=[1]*(n-1-j) if i:c=c[:i]+c[j:i-1:-1]+c[j+1:] else:c=c[:i]+c[j::-1]+c[j+1:] if len(m)>1: q+=1 if i%2:m=m[::-1] m=[len...
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, ...
1 1
O(n)
0
{ "public_tests": [ { "input": "1\n1\n", "output": "0\n" }, { "input": "6\n6 5 4 3 2 1\n", "output": "4\n3 1 1 4\n3 1 1 4\n3 1 1 4\n3 2 2 2\n" }, { "input": "4\n3 1 2 4\n", "output": "2\n3 1 2 1\n2 1 3\n" } ], "private_tests": [ { "input": "44\...
[ 0.000001585252076048951, 9.290134123688811e-7, 5.875701622596155e-7, 4.986007976398601e-7, 4.5629160292832175e-7, 4.5236788406905597e-7, 4.2749877076048955e-7, 4.259824628496504e-7, 4.2381744427447556e-7, 4.214047339379371e-7, 4.014641198645105e-7, 3.958905703671329e-7, 3.9477611451048953e-7...
1272_A. Three Friends
1134
1134_120
Three friends are going to meet each other. Initially, the first friend stays at the position x = a, the second friend stays at the position x = b and the third friend stays at the position x = c on the coordinate axis Ox. In one minute each friend independently from other friends can change the position x by 1 to the...
def dis(a,b,c): return abs(a-b)+abs(b-c)+abs(a-c); t=int(input()); while(t>0): t-=1; l=list(map(int,input().split())); a=l[0]; b=l[1]; c=l[2]; ans=dis(a,b,c); for i in range(-1,2): for j in range(-1,2): for k in range(-1,2): x=a+i; y=b+j; z=c+k; s=dis(x,y,z); if(s<ans): ans=s; 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, ...
8 3 3 4 10 20 30 5 5 5 2 4 3 1 1000000000 1000000000 1 1000000000 999999999 3 2 5 3 2 6
O(n*m)
0.000011
{ "public_tests": [ { "input": "8\n3 3 4\n10 20 30\n5 5 5\n2 4 3\n1 1000000000 1000000000\n1 1000000000 999999999\n3 2 5\n3 2 6\n", "output": "0\n36\n0\n0\n1999999994\n1999999994\n2\n4\n" } ], "private_tests": [ { "input": "5\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n10 5 8\n", "output": "0...
[ 0.001033002384765625, 0.0007981181277343752, 0.00037786299642518945, 0.0003747557549032998, 0.000050646240234375, 0.000036295423445694935, 0.0000287134252895542, 0.000023575167483883306, 0.000016606110658872382, 0.000015571463983282344, 0.000015497771224868884, 0.000012343601330310314, 0.000...
1272_A. Three Friends
1134
1134_928
Three friends are going to meet each other. Initially, the first friend stays at the position x = a, the second friend stays at the position x = b and the third friend stays at the position x = c on the coordinate axis Ox. In one minute each friend independently from other friends can change the position x by 1 to the...
rr = lambda: input().strip() rri = lambda: int(rr()) rrm = lambda: map(int, rr().split()) def solve(a,b,c): mi = min(a,b,c) mi += 1 ma = max(a,b,c) ma -= 1 if(ma-mi>=0): return 2*(ma-mi) else: return 0 T = rri() for i in range(T): a,b,c = rrm() ans = solve(a,b,c) 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, ...
8 3 3 4 10 20 30 5 5 5 2 4 3 1 1000000000 1000000000 1 1000000000 999999999 3 2 5 3 2 6
O(n)
0
{ "public_tests": [ { "input": "8\n3 3 4\n10 20 30\n5 5 5\n2 4 3\n1 1000000000 1000000000\n1 1000000000 999999999\n3 2 5\n3 2 6\n", "output": "0\n36\n0\n0\n1999999994\n1999999994\n2\n4\n" } ], "private_tests": [ { "input": "5\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n10 5 8\n", "output": "0...
[ 0.005808593602633182, 0.002298289610237588, 0.002266302666149703, 0.002249954730078125, 0.0019453903825962838, 0.0009165282605468751, 0.0009023983156250001, 0.000881471801171875, 0.0008591220820312502, 0.0008173226203125003, 0.0008069644285156251, 0.0007939917679687501, 0.0007922010960937502...
346_A. Alice and Bob
1386
1386_38
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two di...
import math n = int(input()) arr = list(map(int, input().split())) gcd = 0 for num in arr: gcd = math.gcd(gcd, num) moves = max(arr) / gcd - n if moves % 2: print('Alice') else: print('Bob')
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 3
O(n)
0.000001
{ "public_tests": [ { "input": "2\n2 3\n", "output": "Alice\n" }, { "input": "3\n5 6 7\n", "output": "Bob\n" }, { "input": "2\n5 3\n", "output": "Alice\n" } ], "private_tests": [ { "input": "10\n78 66 6 60 18 84 36 96 72 48\n", "output": ...
[ 0.0000053726401606206295, 0.0000030046663843968534, 0.0000022634667695585666, 0.000002136800494427448, 0.0000021297081648819935, 0.000002060793282888986, 0.0000020388590198863634, 0.0000019567421738417833, 0.0000019342790783435315, 0.0000019126943837412593, 0.0000017359977873688813, 0.00000173...
346_A. Alice and Bob
1386
1386_19
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two di...
import math n = int(input()) arr = sorted(list(map(int, input().split()))) b = 0 for i in arr: b = math.gcd(b, i) c = (arr[0] - 1) // b c += sum([(arr[i+1] - arr[i] - 1) // b for i in range(n-1)]) print('Bob' if c % 2 == 0 else 'Alice')
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 3
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2\n2 3\n", "output": "Alice\n" }, { "input": "3\n5 6 7\n", "output": "Bob\n" }, { "input": "2\n5 3\n", "output": "Alice\n" } ], "private_tests": [ { "input": "10\n78 66 6 60 18 84 36 96 72 48\n", "output": ...
[ 0.000008285307237347176, 0.000005182171533387867, 0.00000508389891833685, 0.000004987449802469212, 0.000004905691726517736, 0.0000048951174686975555, 0.000004891960064989979, 0.000004877383662199956, 0.00000486794395862786, 4.007925175879754e-11 ]
514_B. Han Solo and Lazer Gun
1027
1027_207
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can ...
n,x,y = map(int, input().split()) a = [] for i in range(n): x1, y1, = map(int, input().split()) a.append((x1,y1)) d = set() for p, q in a: x2, y2 = p-x, q-y found = False for x1, y1 in d: if x1*y2 == x2*y1: found = True break if not found: d.add((x2,y2)) 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, ...
2 1 2 1 1 1 0
O(n**2)
0.000009
{ "public_tests": [ { "input": "2 1 2\n1 1\n1 0\n", "output": "1\n" }, { "input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1\n", "output": "2\n" } ], "private_tests": [ { "input": "2 -10000 -10000\n9998 9999\n9999 10000\n", "output": "2\n" }, { "input": "10 ...
[ 0.000015754143688001637, 0.000015129494732207348, 0.000013426576219678897, 0.000013422077999591355, 0.000012728548552616055, 0.000012623386556121201, 0.000012593088742377456, 0.000012307929105669532, 0.0000119583361948148, 0.00001187437018150215, 0.000011811792016437929, 0.00001179113387186357...
514_B. Han Solo and Lazer Gun
1027
1027_458
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can ...
n, x1, y1 = [int(s) for s in input().split()] slope = {} shoot=0 for i in range(n): x2,y2=[int(s) for s in input().split()] if(x2-x1)==0: m="a" else: m = (y2-y1)/(x2-x1) if m not in slope: shoot+=1 slope[m] = 0 print(shoot)
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 1 1 1 0
O(n)
0.000008
{ "public_tests": [ { "input": "2 1 2\n1 1\n1 0\n", "output": "1\n" }, { "input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1\n", "output": "2\n" } ], "private_tests": [ { "input": "2 -10000 -10000\n9998 9999\n9999 10000\n", "output": "2\n" }, { "input": "10 ...
[ 0.000040478982675710594, 0.000030162274405808528, 0.000030156663359127913, 0.000027365340836688357, 0.000026816968747212147, 0.000025896378993291876, 0.00002573952501518034, 0.000025731493503391477, 0.000025205512301108812, 0.00002508749192348535, 0.00001696629327834838, 0.00001490400663905907...
514_B. Han Solo and Lazer Gun
1027
1027_141
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can ...
import itertools n, x0, y0 = [int(x) for x in input().split()] target = [] for i in range(n): x, y = [int(x) for x in input().split()] cos2 = (x-x0)**2 / ((x-x0)**2 + (y-y0)**2) target.append(cos2 if (x-x0)*(y-y0) >= 0 else -cos2) target.sort() L = list(itertools.groupby(target)) print(len(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 2 1 1 1 0
O(nlogn)
0.000007
{ "public_tests": [ { "input": "2 1 2\n1 1\n1 0\n", "output": "1\n" }, { "input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1\n", "output": "2\n" } ], "private_tests": [ { "input": "2 -10000 -10000\n9998 9999\n9999 10000\n", "output": "2\n" }, { "input": "10 ...
[ 0.00005439813932943922, 0.00004005543517060972, 0.0000268233748120709, 0.000018950295649646464, 0.000014897876977400724, 0.000014756966574481495, 0.000012174267536526338, 0.00001150124830138508, 0.000011474002935344717, 0.00001123684487854292, 0.000010823969610548823, 0.000010413802940524736, ...
219_A. k-String
1582
1582_315
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string s, ...
from collections import defaultdict d=defaultdict(lambda:0) k=int(input()) s=input() for i in s: d[i]+=1 f=1 restring="" for i in range(97,123): if d[chr(i)]: if d[chr(i)]%k==0: restring+=(chr(i)*(d[chr(i)]//k)) else: f=0 break 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 aazz
O(n)
0.000001
{ "public_tests": [ { "input": "2\naazz\n", "output": "azaz" }, { "input": "3\nabcabcabz\n", "output": "-1\n" } ], "private_tests": [ { "input": "2\naaab\n", "output": "-1\n" }, { "input": "2\nbabac\n", "output": "-1\n" }, { ...
[ 0.000024636636759724653, 0.000011338739305616259, 0.000007326312814138987, 0.000007281274694055945, 0.000006972643752731644, 0.000006131497227381993, 0.0000048199998634178325, 0.0000041898773492132865, 0.000004004215594951922, 0.000003961009533435315, 0.000003848986751529721, 0.000003815601712...
219_A. k-String
1582
1582_118
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string s, ...
def solve(): n=int(input()) s=sorted(input(), key=(lambda x: ord(x))) ind=[[s[0],1]] if len(s) % n!=0: print(-1) return for i in range(1,len(s)): if s[i]!=ind[len(ind)-1][0]: ind.append([s[i],1]) else: ind[len(ind)-1][1]+=1 ans=[] for ii in ind: ...
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 aazz
O(nlogn)
0.000012
{ "public_tests": [ { "input": "2\naazz\n", "output": "azaz" }, { "input": "3\nabcabcabz\n", "output": "-1\n" } ], "private_tests": [ { "input": "2\naaab\n", "output": "-1\n" }, { "input": "2\nbabac\n", "output": "-1\n" }, { ...
[ 0.00025598182107736014, 0.00018540152600524475, 0.0001835357676327579, 0.0001833935886008523, 0.00018297981161221594, 0.00018285907626748252, 0.00018256785597410403, 0.00018251653980004372, 0.0001822561919525787, 0.00018225129714816434, 0.00018222127005026225, 0.00018215141684877625, 0.00018...
257_B. Playing Cubes
433
433_16
Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have n + m cubes). Petya moves first. Petya's task is to get as many pairs of nei...
def t(b, pr): i, p = 1, [0, 0] while b[0] or b[1]: if i == 0: c = pr if b[pr] else 1 - pr else: c = 1 - pr if b[1 - pr] else pr p[c != pr] += 1 b[c] -= 1 i, pr = 1 - i, c return p n, m = map(int, input().split()) v1, v2 = t([n - 1, m], 0), 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, ...
2 4
O(n+m)
0.000004
{ "public_tests": [ { "input": "2 4\n", "output": "3 2\n" }, { "input": "3 1\n", "output": "2 1\n" } ], "private_tests": [ { "input": "98813 893\n", "output": "98812 893\n" }, { "input": "947 883\n", "output": "946 883\n" }, { ...
[ 0.000017298445353474652, 0.000014835803267045454, 0.00001425867348666958, 0.000013989857312609266, 0.000013188229567307692, 0.00000950914555561626, 0.000008563070531031469, 0.000007923876775568183, 0.000007833463068181818, 0.000007662965198863638, 0.000006975216701267482, 0.0000054986285511363...
257_B. Playing Cubes
433
433_57
Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have n + m cubes). Petya moves first. Petya's task is to get as many pairs of nei...
f=input().split() kras=int(f[0]) sin=int(f[1]) print(max(kras,sin)-1,min(kras,sin))
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 4
O(1)
0.000002
{ "public_tests": [ { "input": "2 4\n", "output": "3 2\n" }, { "input": "3 1\n", "output": "2 1\n" } ], "private_tests": [ { "input": "98813 893\n", "output": "98812 893\n" }, { "input": "947 883\n", "output": "946 883\n" }, { ...
[ 0.000006346999999999999, 0.0000054259999999999985, 0.000005377500000000001, 0.0000053755, 0.000005370499999999999, 0.0000050080000000000036, 0.000004657500000000001, 0.0000044934999999999935, 0.000003880499999999998, 0.0000033410000000000075, 0.0000028199999999999967, 0.0000027994999999999924,...
486_C. Palindrome Transformation
1387
1387_34
Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down. There is a cursor pointing at some symbol of the string. Suppose that c...
n,p = map(int,input().split()) s = input() p = n-p if p > n//2 else p-1 left,right,steps = n//2,-1,0 for i in range(n//2): x = abs(ord(s[i]) - ord(s[-i-1])) steps += min(x,26-x) if (x!=0) : left = min(left,i) right = max(right,i) if (steps) : print (steps + right-left + min(abs(p-left),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, ...
8 3 aeabcaez
O(n)
0.000008
{ "public_tests": [ { "input": "8 3\naeabcaez\n", "output": "6\n" } ], "private_tests": [ { "input": "5 5\npjfjb\n", "output": "12\n" }, { "input": "10 5\nabcdeedcba\n", "output": "0\n" }, { "input": "1 1\nd\n", "output": "0\n" }, ...
[ 0.00013188857688157035, 0.00003456297620931886, 0.000026990100811298082, 0.00002285871138942528, 0.00001741304944196429, 0.000017246458593749998, 0.000017185906679060345, 0.00001680517364578447, 0.00001661818336407771, 0.00001595308973448427, 0.000013476682648947162, 0.000013413999576965028, ...
486_C. Palindrome Transformation
1387
1387_19
Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down. There is a cursor pointing at some symbol of the string. Suppose that c...
n, p = map(int, input().split()) p -= 1 s = input() ans = 0 idx = 0 pos = [] while idx < n//2: if s[idx] != s[n-1-idx]: diff = abs(ord(s[idx]) - ord(s[n-1-idx])) ans += min(diff, 26 - diff) if p >= n//2: pos.append(n-1-idx) else: pos.append(idx) idx += 1 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, ...
8 3 aeabcaez
O(nlogn)
0.000006
{ "public_tests": [ { "input": "8 3\naeabcaez\n", "output": "6\n" } ], "private_tests": [ { "input": "5 5\npjfjb\n", "output": "12\n" }, { "input": "10 5\nabcdeedcba\n", "output": "0\n" }, { "input": "1 1\nd\n", "output": "0\n" }, ...
[ 0.000006263851624080187, 0.000005658579206823813, 0.000005576595296872369, 0.000005373623944930631, 0.0000033598291457946196, 0.0000025871262718890054, 0.0000023316776758194185, 0.0000017550698231673524, 0.0000016124488280092965, 0.0000015341212115528102, 0.000001154490140389479, 0.00000109627...
913_C. Party Lemonade
514
514_90
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2i - 1 liters and costs ci r...
def f(bs): return int(bs, 2) // (1 << n - 1) * a[-1] + sum(a[i] for i in range(min(n - 1, len(bs))) if bs[-i - 1] == '1') n, x = map(int, input().split()) *a, = map(int, input().split()) for i in range(1, n): a[i] = min(a[i], 2 * a[i - 1]) bx = '0' * n + bin(x)[2:] ans = f(bx) for i in range(len(bx)): if bx...
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 12 20 30 70 90
O(n**2)
0.000008
{ "public_tests": [ { "input": "4 12\n20 30 70 90\n", "output": "150\n" }, { "input": "5 787787787\n123456789 234567890 345678901 456789012 987654321\n", "output": "44981600785557577\n" }, { "input": "4 3\n10000 1000 100 10\n", "output": "10\n" }, { ...
[ 0.00004112700546431038, 0.00002023214806499863, 0.000017373116893487804, 0.000016569433007209736, 0.000016370409036129282, 0.000014591170948434554, 0.000008088053596679832, 0.000008008720280323773, 0.000007993054490206458, 0.000007889323692107747, 0.000007498248717975678, 0.0000056702320011657...
913_C. Party Lemonade
514
514_39
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2i - 1 liters and costs ci r...
import math N = 31 n, l = map(int, input().split()) cost = [int(x) for x in input().split()] for i in range(n, N): cost.append(math.inf) for i in range(N - 1): cost[i + 1] = min(cost[i + 1], cost[i] * 2) # print(cost) ans = math.inf cur_cost = 0 for i in range(N - 1, -1, -1): # print('l = {}'.format(l)) if 2**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 12 20 30 70 90
O(n)
0.000002
{ "public_tests": [ { "input": "4 12\n20 30 70 90\n", "output": "150\n" }, { "input": "5 787787787\n123456789 234567890 345678901 456789012 987654321\n", "output": "44981600785557577\n" }, { "input": "4 3\n10000 1000 100 10\n", "output": "10\n" }, { ...
[ 0.0001661947288135593, 0.00004677760828234266, 0.000010509036674542217, 0.000010337534036276224, 0.000010050076192339901, 0.000009166396238527099, 0.000009082449294797822, 0.000006915259110030595, 0.000006913612530048077, 0.00000458621369645979, 0.000004582248647836539, 0.000004517646976070804...
913_C. Party Lemonade
514
514_140
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2i - 1 liters and costs ci r...
n, l = map(int, input().split()) p = list(map(int, input().split())) d = [] d = [[p[i] / 2**i, i + 1] for i in range(n)] d.sort(key = lambda x: x[0]) res = 10**18 q = l curres = 0 for i in d: if i[1] == 1: curres += p[i[1] - 1] * q res = min(res, curres) break curb = q // 2**(i[1] - 1) curres += curb * p[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 12 20 30 70 90
O(nlogn)
0.000016
{ "public_tests": [ { "input": "4 12\n20 30 70 90\n", "output": "150\n" }, { "input": "5 787787787\n123456789 234567890 345678901 456789012 987654321\n", "output": "44981600785557577\n" }, { "input": "4 3\n10000 1000 100 10\n", "output": "10\n" }, { ...
[ 0.00009559172103001823, 0.00004617206229550995, 0.00004260952959374254, 0.000024874809403149457, 0.000023695207353272088, 0.0000211712396038426, 0.000017772672679168405, 0.000015862639228942268, 0.000015370171633490593, 0.000015286413612371836, 0.000015170743520072556, 0.000014824060054694372,...
546_B. Soldier and Badges
2586
2586_20
Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one of them should get a badge with strictly higher factor than the secon...
n=int(input()) l1=list(map(int,input().split())) l2=[0]*int(n*(n+1)/2) cost=0 for i in range (n): if(l2[l1[i]-1]==0): l2[l1[i]-1]=1 elif(l2[l1[i]-1]==1): while(l2[l1[i]-1]==1): cost+=1 l1[i]+=1 l2[l1[i]-1]=1 print(cost)
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 2 5
O(n**2)
0.000006
{ "public_tests": [ { "input": "5\n1 2 3 2 5\n", "output": "2\n" }, { "input": "4\n1 3 1 4\n", "output": "1\n" } ], "private_tests": [ { "input": "5\n1 5 3 2 4\n", "output": "0\n" }, { "input": "50\n49 37 30 2 18 48 14 48 50 27 1 43 46 5 21 28 ...
[ 0.00009530446543273492, 0.00004368329082042504, 0.00002447314549433775, 0.00002332005783004035, 0.000019708692084527164, 0.00001852702156476139, 0.000016972028544326343, 0.000015364050055026683, 0.000014983703010328384, 0.000014334490078341571, 0.000013497901954567198, 0.000012941937767782554,...
546_B. Soldier and Badges
2586
2586_216
Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one of them should get a badge with strictly higher factor than the secon...
n=int(input()) ans=0 s=sorted(list(map(int,input().split()))) for i in range(1,n): if s[i]<=s[i-1]: ans+=s[i-1]-s[i]+1 s[i]=s[i-1]+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, ...
5 1 2 3 2 5
O(nlogn)
0.000014
{ "public_tests": [ { "input": "5\n1 2 3 2 5\n", "output": "2\n" }, { "input": "4\n1 3 1 4\n", "output": "1\n" } ], "private_tests": [ { "input": "5\n1 5 3 2 4\n", "output": "0\n" }, { "input": "50\n49 37 30 2 18 48 14 48 50 27 1 43 46 5 21 28 ...
[ 0.00010816989285128934, 0.0001035283984238418, 0.00010352673860904721, 0.00010150774138166521, 0.00010120013252567745, 0.000026859622269430457, 0.00001887166612494815, 0.000016104542228864748, 0.00001607121498276304, 0.000015889860403348906, 0.00001581682960725975, 0.000015740508944357912, 0...
p03281 AtCoder Beginner Contest 106 - 105
1254
1254_187
The number 105 is quite special - it is odd but still it has eight divisors. Now, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)? Constraints * N is an integer between 1 and 200 (inclusive). Input Input is given from Standard Input in the following...
n=int(input()) x=0 for i in range(1,n+1,2): c=0 for j in range(1,i+1): if i%j==0: c+=1 if c==8: x+=1 print(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, ...
105
O(n**2)
0.000687
{ "public_tests": [ { "input": "105", "output": "1" }, { "input": "7", "output": "0" } ], "private_tests": [], "generated_tests": [ { "input": "36", "output": "0\n" }, { "input": "122", "output": "1\n" }, { "input": "138",...
[ 0.0027118714003293467, 0.002564675555468886, 0.0014587200657392963, 0.0013523566634165369, 0.001349197818036055, 0.0013487361732969318, 0.0013450566566996015, 0.0011463703491939679, 0.001086744066129312, 0.0010507340536054777, 0.0010505781851707404, 0.0010490228901022711, 0.00102630712047148...
p03281 AtCoder Beginner Contest 106 - 105
1254
1254_182
The number 105 is quite special - it is odd but still it has eight divisors. Now, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)? Constraints * N is an integer between 1 and 200 (inclusive). Input Input is given from Standard Input in the following...
from bisect import bisect_right n = int(input()) print(bisect_right([105, 135, 165, 189, 195], 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, ...
105
O(1)
0.000001
{ "public_tests": [ { "input": "105", "output": "1" }, { "input": "7", "output": "0" } ], "private_tests": [], "generated_tests": [ { "input": "36", "output": "0\n" }, { "input": "122", "output": "1\n" }, { "input": "138",...
[ 0.000009871000000000001, 0.0000031955, 0.0000029804999999999963, 0.0000027269999999999893, 0.0000025704999999999917, 0.0000023910000000000013, 0.0000021694999999999968, 0.0000020135000000000037, 0.0000019264999999999993, 0.000001694000000000001, 0.000001660000000000001, 0.000001616500000000000...
1177_A. Digits Sequence (Easy Edition)
1501
1501_224
Let's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the k-th digit of this sequence. Input The first and only lin...
number = int(input()) count = 0 while number-len(str(count+1)) >= 0: number-=len(str(count+1)) count+=1 if number==0: count = str(count) print(count[-1]) else: count+=1 count = str(count) print(count[number-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, ...
21
O(n)
0.000009
{ "public_tests": [ { "input": "21\n", "output": "5\n" }, { "input": "7\n", "output": "7\n" } ], "private_tests": [ { "input": "2887\n", "output": "9\n" }, { "input": "100000000\n", "output": "8\n" }, { "input": "68888886\n"...
[ 0.00008671569236232519, 0.00006830988404173951, 0.00006318013823481207, 0.00006229948041411715, 0.000053308529392482514, 0.00004344677642864948, 0.000027698056859156467, 0.0000219558823208042, 0.000020279907506555946, 0.00001993896425644668, 0.000019793062937062935, 0.00001955152623743444, 0...
1177_A. Digits Sequence (Easy Edition)
1501
1501_177
Let's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the k-th digit of this sequence. Input The first and only lin...
print(''.join(str(x) for x in range(1, 2778))[int(input()) -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, ...
21
O(1)
0.000007
{ "public_tests": [ { "input": "21\n", "output": "5\n" }, { "input": "7\n", "output": "7\n" } ], "private_tests": [ { "input": "2887\n", "output": "9\n" }, { "input": "100000000\n", "output": "8\n" }, { "input": "68888886\n"...
[ 0.009677757000000002, 0.0014858589999999922, 0.0014664874999999883, 0.0011375659999999926, 0.000868724500000001, 0.0007228760000000001, 0.0007109944999999993, 0.0006200134999999989, 0.0006161415, 0.0004890930000000029, 0.0004264000000000004, 0.0004059919999999939, 0.00022263400000000004, 0...
448_B. Suffix Structures
1675
1675_29
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix...
s=input() t=input() x=set(s) s=list(s) i=0 j=0 nt=0 ar=0 at=0 while i<=len(s) and j<len(t): if i==len(s): i=0 ar=1 if t[j] in s: if s[i]==t[j]: s[i]=':' j+=1 i+=1 else: i+=1 at=1 else: nt=1 break if nt==0 and len(s)==len(t): at=0 else: at=1 if nt==1: print('need tree') elif at==ar==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, ...
need tree
O(n**2)
0.000332
{ "public_tests": [ { "input": "need\ntree\n", "output": "need tree\n" }, { "input": "automaton\ntomat\n", "output": "automaton\n" }, { "input": "array\narary\n", "output": "array\n" }, { "input": "both\nhot\n", "output": "both\n" } ], ...
[ 0.0003317278299347137, 0.000031819854630917476, 0.00003084971536939177, 0.000022549004916958043, 0.000015007279064685315, 0.000010620068587042582, 0.000001961504479895105, 0.000001722977463942308, 0.00000118277615548514, 9.924501065340908e-7, 6.163206402972028e-7, 2.766856046417764e-7, 1.659...
448_B. Suffix Structures
1675
1675_150
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix...
s=input().strip() t=input().strip() a=[s.count(chr(ord('a')+i))for i in range(26)] b=[t.count(chr(ord('a')+i))for i in range(26)] c=0 for i in s: if (c < len(t) and t[c] == i): c+= 1 if (c == len(t)): print("automaton") elif all(a[i] == b[i] for i in range(26)): print("array") elif all(a[i] >= b[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, ...
need tree
O(n)
0.000001
{ "public_tests": [ { "input": "need\ntree\n", "output": "need tree\n" }, { "input": "automaton\ntomat\n", "output": "automaton\n" }, { "input": "array\narary\n", "output": "array\n" }, { "input": "both\nhot\n", "output": "both\n" } ], ...
[ 0.000020810712248688816, 0.00000684884082714161, 0.00000626543079381556, 0.000005819279023710665, 0.000004788755886691433, 0.0000035713240958260493, 0.0000034136331949300703, 0.0000023347627704326923, 0.0000020168567389641608, 0.000001918362530048077, 0.0000012958982872596154, 3.16306490384615...
631_A. Interview
1029
1029_92
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ...
n = int(input()) ps = list(map(int, input().split())) qs = list(map(int, input().split())) maxi = 0 s_a, s_b = 0, 0 for l in range(n): s_a = ps[l] s_b = qs[l] for r in range(l, n): s_a = s_a | ps[r] s_b = s_b | qs[r] maxi = max(maxi, s_a + s_b) print(maxi)
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 13 2 7 11 8 4 9 8 5 1 5 7 18 9 2 3 0 11 8 6
O(n**2)
0.000045
{ "public_tests": [ { "input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n", "output": "46\n" }, { "input": "5\n1 2 4 3 2\n2 3 3 12 1\n", "output": "22\n" } ], "private_tests": [ { "input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 6...
[ 0.0011034412617871383, 0.0010421952542468366, 0.0010288728467672042, 0.0010107640857600973, 0.0007436697305858903, 0.00008849145522942354, 0.00007236264996945449, 0.00005248909797433294, 0.000047258811051563624, 0.000046957336969203244, 0.000046561860205104816, 0.00004619068720269635, 0.0000...
631_A. Interview
1029
1029_119
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ...
n=int(input()) f1=f2=0 for x in input().split(): f1|=int(x) for x in input().split(): f2|=int(x) print(f1+f2)
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 13 2 7 11 8 4 9 8 5 1 5 7 18 9 2 3 0 11 8 6
O(n+m)
0.000006
{ "public_tests": [ { "input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n", "output": "46\n" }, { "input": "5\n1 2 4 3 2\n2 3 3 12 1\n", "output": "22\n" } ], "private_tests": [ { "input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 6...
[ 0.000036408456239073425, 0.00001981886295850315, 0.000017761453709707298, 0.000017690243249814746, 0.000017602089199703595, 0.000017478719375231565, 0.00000809243826486014, 0.000008091906345607517, 0.000008056157699955969, 0.000008018433703015736, 0.000008009090212521853, 0.0000078887800649804...
1091_B. New Year and the Treasure Geolocation
2185
2185_148
Bob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point T, which coordinates to be found out. Bob travelled around the world and collected clues of the treasure location at n obelisks. These clues were in an ancient language, and he has only decrypted them at hom...
n = int(input()) p = [] add = dict() for i in range(n): a, b = map(int, input().split()) p.append((a, b)) for i in range(n): a, b = map(int, input().split()) add[(a, b)] = 0 for key in add.keys(): T = [key[0] + p[0][0], key[1] + p[0][1]] ok = 1 for i in range(1, n): if not ((T[0] - p[i][0], T[1] - p[i][1]) 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, ...
2 2 5 -6 4 7 -2 -1 -3
O(n**2)
0
{ "public_tests": [ { "input": "2\n2 5\n-6 4\n7 -2\n-1 -3\n", "output": "1 2\n" }, { "input": "4\n2 2\n8 2\n-7 0\n-2 6\n1 -14\n16 -12\n11 -18\n7 -14\n", "output": "9 -12\n" } ], "private_tests": [ { "input": "4\n5 -10\n-7 7\n1 0\n8 3\n7 -6\n0 -9\n15 -13\n3 4\n", ...
[ 0.00005268834347458079, 0.000014735627630960394, 0.000014016518403898297, 0.000003806073190241139, 0.0000030821592092576946, 4.9903094951923086e-9, 4.811461975524475e-9, 4.6959339488636374e-9, 4.2934809331293745e-9, 4.156297803758742e-9, 3.931428922639862e-9, 3.87683020104895e-9, 3.824061680...
1091_B. New Year and the Treasure Geolocation
2185
2185_274
Bob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point T, which coordinates to be found out. Bob travelled around the world and collected clues of the treasure location at n obelisks. These clues were in an ancient language, and he has only decrypted them at hom...
n = int(input()) a = 0 b = 0 for _ in range(2*n): x,y = map(int,input().split(" ")) a += x b += y print(a//n,b//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, ...
2 2 5 -6 4 7 -2 -1 -3
O(n)
0
{ "public_tests": [ { "input": "2\n2 5\n-6 4\n7 -2\n-1 -3\n", "output": "1 2\n" }, { "input": "4\n2 2\n8 2\n-7 0\n-2 6\n1 -14\n16 -12\n11 -18\n7 -14\n", "output": "9 -12\n" } ], "private_tests": [ { "input": "4\n5 -10\n-7 7\n1 0\n8 3\n7 -6\n0 -9\n15 -13\n3 4\n", ...
[ 0.000023866987693946682, 0.000018355813838505243, 0.000017972243430397727, 0.000017150655239291956, 0.000016851963805725525, 0.0000164674823399257, 0.000015232356697989509, 0.000015226263344077798, 0.000015216006009615387, 0.000015166979690231644, 0.00001515727377895542, 0.00001504870178649475...
442_B. Andrey and Problem
2496
2496_46
Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him. Help Andrey choose...
import bisect n=int(input()) ls=list(map(float,input().split())) ls.sort() mx=ls[-1] idx=bisect.bisect_left(ls,0.5) if idx<n and ls[idx]<0.5: idx+=1 res=0 st=0 while(st<idx-1): temp=0 for i in range(st,idx): t=1 for j in range(st,idx): if i!=j: t=t*(1-ls[j]) ...
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.1 0.2
O(n**2)
0.000029
{ "public_tests": [ { "input": "2\n0.1 0.2\n", "output": "0.2600000000\n" }, { "input": "4\n0.1 0.2 0.3 0.8\n", "output": "0.8000000000\n" } ], "private_tests": [ { "input": "20\n0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0...
[ 0.0001761637138693108, 0.00005365420117377753, 0.000052422963886257533, 0.00005192799584223509, 0.00005182684419938866, 0.00003346571203329397, 0.000031300614954379196, 0.00002945532012931441, 0.000022288624246843135, 0.000002702491718345363, 0.000002355405931554957, 0.000001491594813807816, ...
442_B. Andrey and Problem
2496
2496_30
Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him. Help Andrey choose...
import sys input() ps = sorted((float(p) for p in input().split()), reverse=True) if 1.0 in ps: print(1) sys.exit() a, b = 0, 1 for p in ps: c, d = a + p / (1 - p), b * (1 - p) if c * d > a * b: a, b = c, d else: break print('{:.9}'.format(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, ...
2 0.1 0.2
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2\n0.1 0.2\n", "output": "0.2600000000\n" }, { "input": "4\n0.1 0.2 0.3 0.8\n", "output": "0.8000000000\n" } ], "private_tests": [ { "input": "20\n0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0...
[ 0.000011815719365193744, 0.000005720935082661761, 0.0000056861861558226474, 0.000005262054701523087, 0.000005238072098301151, 0.000005184854509540407, 0.000005156628896879391, 0.000005143599379003868, 0.000005134332578203795, 0.0000051316359363351185, 0.000005116556197479832, 0.000005112812699...
p03222 AtCoder Beginner Contest 113 - Number of Amidakuji
1861
1861_28
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical l...
from collections import Counter H, W, K = [int(_) for _ in input().split()] MOD = 1000000007 pats = [[0]] for i in range(1, W): pats = [p + [i] for p in pats] + [p[:-1] + [i, i - 1] for p in pats if p[-1] == i - 1] iws = [Counter(r) for r in zip(*pats)] rs = [1] + [0] * (W - 1) for j in range(H): rs = [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, ...
2 3 1
O(n**2)
0.008616
{ "public_tests": [ { "input": "2 3 1", "output": "5" }, { "input": "1 3 2", "output": "1" }, { "input": "1 3 1", "output": "2" }, { "input": "7 1 1", "output": "1" }, { "input": "2 3 3", "output": "1" }, { "...
[ 0.10872119966101694, 0.045040104165492964, 0.0364609868274648, 0.03475489002816902, 0.03359968210563381, 0.028249020581526105, 0.02667170341445783, 0.026532695852208837, 0.017614099076305224, 0.015938392938955825, 0.015249052705216724, 0.013644365074415035, 0.013094745019754507, 0.01232157...