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
166_A. Rank List
1671
1671_196
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two give...
n,k=map(int,input().split()) A=[[0,0]] for i in range(n): a,b=map(int,input().split()) A.append([a,b]) for j in range(2,n+1): key=A[j] i=j-1 while(i>0 and (A[i][0]>key[0] or (A[i][0]==key[0] and A[i][1]<key[1]))): A[i+1]=A[i] i-=1 A[i+1]=key A.pop(0) A=[[0,0]]+A[::-1] print(A.cou...
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 3 1 3 1 5 3 3 1 3 1
O(n**2)
0.000003
{ "public_tests": [ { "input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n", "output": "4\n" }, { "input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "output": "3\n" } ], "private_tests": [ { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50...
[ 0.000022282960893042368, 0.000014086768965610793, 0.000013563110741814474, 0.000013373668008332086, 0.000013298392683720935, 0.000012259511132797704, 0.000010187633964177728, 0.000008767892238427716, 0.000007504319757778487, 0.000007289269029922305, 0.000004349929615057704, 0.00000379404504231...
166_A. Rank List
1671
1671_68
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two give...
# Description of the problem can be found at http://codeforces.com/problemset/problem/166/A n, k = map(int, input().split()) l_t = list([list(map(int, input().split())) for _ in range(n)]) l_t.sort(key=lambda x: (-x[0], x[1])) l = 0 h = 0 t = 0 while k - l - 1 >= 0 and l_t[k - l - 1] == l_t[k - 1]: t += 1 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 3 1 3 1 5 3 3 1 3 1
O(nlogn)
0.000022
{ "public_tests": [ { "input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n", "output": "4\n" }, { "input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "output": "3\n" } ], "private_tests": [ { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50...
[ 0.000056835354655477106, 0.000043024277469416794, 0.000041689973769446717, 0.0000380110503956091, 0.000034246938248554056, 0.00002978553429758869, 0.00002943380267832285, 0.00002925373155236623, 0.00002923854718987761, 0.0000291015679494116, 0.00002908249568011331, 0.000029069447252557017, 0...
141_A. Amusing Joke
2962
2962_1968
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
n=input() l=input() m=input() a=len(n)+len(l) c=0 n=list(n)+list(l) m=list(m) d=[] d=d+m for i in range(len(n)): if n[i] not in m: c=1 break else: d.remove(n[i]) m.remove(n[i]) if c==1: print("NO") elif len(d)!=0: 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, ...
BABBONATALE FATHERCHRISTMAS BABCHRISTMASBONATALLEFATHER
O(n**2)
0.000001
{ "public_tests": [ { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n", "output": "NO" }, { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "output": "NO" ...
[ 0.007873025741613134, 0.0029487490409516384, 0.002943129855130872, 0.002935844715895303, 0.0029323160729762526, 0.002801110406136246, 0.0024698678747616574, 0.002375829786704802, 0.002367358118911423, 0.002366418293768418, 0.0023620661932743977, 0.0023614042006846942, 0.0023550961939244235, ...
141_A. Amusing Joke
2962
2962_1209
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
first = input() second = input() total = input() need = first + second if len(need) != len(total): print("NO") else: for letters in need: if need.count(letters) != total.count(letters): print("NO") exit() 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, ...
BABBONATALE FATHERCHRISTMAS BABCHRISTMASBONATALLEFATHER
O(n**2+m**2)
0
{ "public_tests": [ { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n", "output": "NO" }, { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "output": "NO" ...
[ 0.0004486615797606468, 0.0004424491671923187, 0.00044222290769226633, 0.0003632791282967528, 0.0003557539827543094, 0.0002789590862445855, 0.0002726656793710458, 0.00019203004783030714, 0.0001632696687262549, 0.00005748154331532029, 0.00003302897851801206, 0.000026603906918595123, 0.00001627...
769_B. News About Credit
2831
2831_61
Polycarp studies at the university in the group which consists of n students (including himself). All they are registrated in the social net "TheContacnt!". Not all students are equally sociable. About each student you know the value ai — the maximum number of messages which the i-th student is agree to send per day. ...
n = int(input()) a = list(map(int, input().split())) p = a[0] a = [(p, 0)] + sorted([(a[i], i) for i in range(1, n)], reverse=True) result = "" got = {0} for i in range(n): temp_a = a[i][0] temp_i = i + 1 while temp_a > 0 and temp_i < n: if temp_i not in got: got.add(temp_i) temp_a -= 1 result += st...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 0 2 2
O(n**2)
0.000001
{ "public_tests": [ { "input": "3\n0 2 2\n", "output": "-1\n" }, { "input": "4\n1 2 1 0\n", "output": "3\n1 2\n2 3\n2 4\n" }, { "input": "6\n2 0 1 3 2 0\n", "output": "5\n1 4\n1 5\n4 3\n4 6\n4 2\n" } ], "private_tests": [ { "input": "100\n2 0 0...
[ 0.00000856890340909091, 0.0000053884227328059305, 0.0000034386931495743402, 0.000003278196610030595, 0.000002445688928247211, 0.0000021183910045394265, 0.000002065086765336457, 0.0000015639032197223238, 0.0000013062685751748254, 0.0000012370512285806304, 0.000001172199969951923, 0.000001158121...
769_B. News About Credit
2831
2831_71
Polycarp studies at the university in the group which consists of n students (including himself). All they are registrated in the social net "TheContacnt!". Not all students are equally sociable. About each student you know the value ai — the maximum number of messages which the i-th student is agree to send per day. ...
import itertools n = int(input()) a = list(map(int, input().split())) a = [(a[0], 1)] + sorted(zip(a[1:], itertools.count(2)), reverse=True) w = 1 ans = [ ] for r, cur in enumerate(a): if r == w: print(-1) break while w != n and cur[0] > 0: ans.append("%s %s" % (cur[1], a[w][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 0 2 2
O(nlogn)
0.000008
{ "public_tests": [ { "input": "3\n0 2 2\n", "output": "-1\n" }, { "input": "4\n1 2 1 0\n", "output": "3\n1 2\n2 3\n2 4\n" }, { "input": "6\n2 0 1 3 2 0\n", "output": "5\n1 4\n1 5\n4 3\n4 6\n4 2\n" } ], "private_tests": [ { "input": "100\n2 0 0...
[ 0.00008719961168715961, 0.00007709032453288899, 0.00007376543049526874, 0.00007318852812226836, 0.00006860468624344406, 0.00003583036780731142, 0.000012532610413406222, 0.000010770313796064469, 0.000010762238935727348, 0.000010754089590029135, 0.00001067351050511076, 0.000010430701876954357, ...
984_A. Game
187
187_762
Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate t...
def sort(n,a): list = a for i in range(0,n): for j in range(0,n): if(list[i]>list[j]): t = list[i] list[i] = list[j] list[j] = t return list def erase(n,a): temp=1 list = sort(n,a) t=0 print(a[(n)//2]) n = int(input()) 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, ...
3 2 2 2
O(n**2)
0.000002
{ "public_tests": [ { "input": "3\n2 2 2\n", "output": "2\n" }, { "input": "3\n2 1 3\n", "output": "2\n" } ], "private_tests": [ { "input": "10\n38 82 23 37 96 4 81 60 67 86\n", "output": "60\n" }, { "input": "9\n44 53 51 80 5 27 74 79 94\n", ...
[ 0.13969693123333335, 0.0019167473008383003, 0.0012396209182765497, 0.001212356230036059, 0.0000756379553626158, 0.00006911811259833917, 0.00006822779529064686, 0.00006615508541329255, 0.00004255427540727908, 0.00004141442278460613, 0.0000399513466785999, 0.00003983840411063372, 0.00003950586...
984_A. Game
187
187_193
Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate t...
n=int(input()) a=input().split() for i in range(n): a[i]=int(a[i]) a=sorted(a) if n%2==0: print(a[(n//2)-1]) else: print(a[(n//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, ...
3 2 2 2
O(nlogn)
0.000009
{ "public_tests": [ { "input": "3\n2 2 2\n", "output": "2\n" }, { "input": "3\n2 1 3\n", "output": "2\n" } ], "private_tests": [ { "input": "10\n38 82 23 37 96 4 81 60 67 86\n", "output": "60\n" }, { "input": "9\n44 53 51 80 5 27 74 79 94\n", ...
[ 0.000034639980245535714, 0.000034410204241071434, 0.000017147389788960017, 0.000012706032787115123, 0.000012011308280411307, 0.000011909519956800496, 0.000011201659028459768, 0.000011033203016665798, 0.000010504569878972315, 0.00001043712526481234, 0.000009946902109478577, 0.000009838350167776...
1107_C. Brutality
2083
2083_142
You are playing a new famous fighting game: Kortal Mombat XII. You have to perform a brutality on your opponent's character. You are playing the game on the new generation console so your gamepad have 26 buttons. Each button has a single lowercase Latin letter from 'a' to 'z' written on it. All the letters on buttons ...
def main(): n, k = map(int, input().split()) a = list(map(int, input().split())) s = input().strip() last = s[0] seg = [a[0]] all = [] for i in range(1, len(s)): if last == s[i]: seg.append(a[i]) else: last = s[i] all.append(seg) seg = [a[i]] if seg: all.append(seg) ans = 0 for seg in all: ...
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 10 10 qq
O(n**2)
0
{ "public_tests": [ { "input": "2 1\n10 10\nqq\n", "output": "10\n" }, { "input": "8 1\n10 15 2 1 4 8 15 16\nqqwweerr\n", "output": "41\n" }, { "input": "7 3\n1 5 16 18 7 2 10\nbaaaaca\n", "output": "54\n" }, { "input": "5 5\n2 4 1 3 1000\naaaaa\n"...
[ 0.0303117205, 0.0286576945, 1.0688464667154951e-7, 1.0395185021045521e-7, 6.133291324115037e-8, 5.867742192123749e-8, 5.6287784046271264e-8, 5.5117670216957734e-8, 5.431899212813568e-8, 5.422091213766228e-8, 5.3756054317520384e-8, 5.360181506011995e-8, 5.351858679200831e-8, 5.3490301291555...
1107_C. Brutality
2083
2083_80
You are playing a new famous fighting game: Kortal Mombat XII. You have to perform a brutality on your opponent's character. You are playing the game on the new generation console so your gamepad have 26 buttons. Each button has a single lowercase Latin letter from 'a' to 'z' written on it. All the letters on buttons ...
n,k=map(int,input().split()) l=list(map(int,input().split())) s=str(input()) t=0 i=0 while(i<n): j=i p=[] while(j<n and s[i]==s[j]): p.append(l[j]) j+=1 p.sort(reverse=True) c=min(k,len(p)) t=t+sum(p[0:c]) i=j 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, ...
2 1 10 10 qq
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2 1\n10 10\nqq\n", "output": "10\n" }, { "input": "8 1\n10 15 2 1 4 8 15 16\nqqwweerr\n", "output": "41\n" }, { "input": "7 3\n1 5 16 18 7 2 10\nbaaaaca\n", "output": "54\n" }, { "input": "5 5\n2 4 1 3 1000\naaaaa\n"...
[ 0.030098928499999997, 0.029505409999999996, 0.029394896, 0.000011847045823317309, 0.000011712698167067306, 0.000005981761436444672, 0.000005542226462862838, 0.0000055365353266319364, 0.000005369149073206834, 0.000005024593685993781, 0.000004982951353876995, 0.000004943857576935564, 0.0000049...
952_C. Ravioli Sort
1765
1765_40
Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you... You come up with...
size = int(input()) data = [int(x) for x in input().split()] error = False while size > 1: for i in range(size - 1): if abs(data[i] - data[i+1]) >= 2: error = True data.remove(max(data)) size -= 1 print("NO" if error else "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 3 1 2
O(n**2)
0.000002
{ "public_tests": [ { "input": "3\n3 1 2\n", "output": "NO" }, { "input": "3\n1 2 3\n", "output": "YES" } ], "private_tests": [ { "input": "4\n90 91 90 91\n", "output": "YES" }, { "input": "4\n54 54 54 55\n", "output": "YES" }, { ...
[ 0.012942853619486, 0.00854102512543153, 0.005978228581080448, 0.004985737953708476, 0.003944201023388293, 0.0035330654008892183, 0.000054108432995001274, 0.000014079294087413974, 0.000013832559116182906, 0.000008904122137954164, 0.000006521147289083154, 0.0000051150448016599474, 0.0000050600...
952_C. Ravioli Sort
1765
1765_73
Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you... You come up with...
# =================================== # (c) MidAndFeed aka ASilentVoice # =================================== # import math # import collections # =================================== n = int(input()) q = [int(x) for x in input().split()] for i in range(n-1): if abs(q[i]-q[i+1]) > 1: print("NO") break else: print...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 1 2
O(n)
0.000001
{ "public_tests": [ { "input": "3\n3 1 2\n", "output": "NO" }, { "input": "3\n1 2 3\n", "output": "YES" } ], "private_tests": [ { "input": "4\n90 91 90 91\n", "output": "YES" }, { "input": "4\n54 54 54 55\n", "output": "YES" }, { ...
[ 0.000009418633263221152, 0.0000070727724131337415, 0.0000070386507047639856, 0.000006377838805725525, 0.000005741652439357518, 0.000005500755586210665, 0.000005440149120410839, 0.000005113652029611014, 0.000005056259232954546, 0.0000028793484347683574, 0.0000027115786166958045, 0.0000026651585...
116_A. Tram
1310
1310_3062
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
import math x = list(map(int, input().split())) s = [] for i in range(0,x[0]): s.append(list(map(int, input().split()))) q = 1 p = 0 q = 0 for i in range(0,x[0]): p = p - s[i][0] + s[i][1] if p > q : q = p print(q)
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 0 3 2 5 4 2 4 0
O(n*m)
0.000003
{ "public_tests": [ { "input": "4\n0 3\n2 5\n4 2\n4 0\n", "output": "6\n" } ], "private_tests": [ { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0\n", "output": "0\n" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0\n", "output": "2\n" }, { ...
[ 0.00003126985964816434, 0.000015251133203125005, 0.000015084793359375001, 0.000014836418750000002, 0.000014357667791193182, 0.000013427860937500003, 0.000013061912109375, 0.000013038284765625003, 0.000012934824218750003, 0.000012923316796875003, 0.00001284755625, 0.000012261683962521854, 0.0...
116_A. Tram
1310
1310_1170
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
number_of_stations = input() people = 0 max_people= 0 for i in range(int(number_of_stations)): a_b = input() a, b = a_b.split() a, b = int(a), int(b) people = people + b - a max_people = max(people, max_people) print(max_people)
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 0 3 2 5 4 2 4 0
O(n)
0.000011
{ "public_tests": [ { "input": "4\n0 3\n2 5\n4 2\n4 0\n", "output": "6\n" } ], "private_tests": [ { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0\n", "output": "0\n" }, { "input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0\n", "output": "2\n" }, { ...
[ 0.00009831244092821242, 0.00009809979938811191, 0.00002401019013603584, 0.000022048054960664336, 0.000020498042026333042, 0.000019794730946787588, 0.00001959007002567745, 0.00001954045453179633, 0.000019524062595607518, 0.000019446663953234264, 0.000019235081375655595, 0.000019137820271525352,...
p03938 AtCoder Grand Contest 007 - Construct Sequences
1981
1981_39
You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a...
n = int(input()) p = list(map(int, input().split())) a = [i*40000+1 for i in range(n)] b = a[:] b.reverse() for i in range(n): b[p[i]-1] += i+1 print(*a) print(*b)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 2 1
O(n)
0.000008
{ "public_tests": [ { "input": "3\n3 2 1", "output": "1 2 3\n5 3 1" }, { "input": "3\n2 3 1", "output": "5 10 100\n100 10 1" }, { "input": "2\n1 2", "output": "1 4\n5 4" } ], "private_tests": [], "generated_tests": [ { "input": "2\n1 0", ...
[ 0.00001424930613630935, 0.000013048854786770228, 0.000012771390996549531, 0.000012638754320280643, 0.000012310001556883815, 0.000011801700799161988, 0.00001159500232813125, 0.000011419500381307036, 0.000010949544768323601, 0.000010216527656990582, 0.000010145406148108286, 0.0000100447702344534...
p03938 AtCoder Grand Contest 007 - Construct Sequences
1981
1981_62
You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a...
def gen_ordinary_lists(n): up_lis = list(range(1, n * 20001, 20001)) return up_lis, up_lis[::-1] def argsort(lis): tpls = [(l, i) for i, l in enumerate(lis)] return sorted(tpls) def solve(N, lis): up_list, down_list = gen_ordinary_lists(N) arg_tpls = argsort(lis) for val, idx in arg_tpls...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 2 1
O(nlogn)
0.000009
{ "public_tests": [ { "input": "3\n3 2 1", "output": "1 2 3\n5 3 1" }, { "input": "3\n2 3 1", "output": "5 10 100\n100 10 1" }, { "input": "2\n1 2", "output": "1 4\n5 4" } ], "private_tests": [], "generated_tests": [ { "input": "2\n1 0", ...
[ 0.000009907551203911047, 0.000009861470843847829, 0.000009664360226979553, 0.000008715976577002237, 0.000008508026051128122, 0.000008469954722170471, 0.000008314632342639402, 0.0000032383949036395006, 0.0000022172486445051675, 0.000002084303050982787, 0.000001919595075424913, 0.000001851958754...
348_A. Mafia
1626
1626_33
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number ...
""" Code of Ayush Tiwari Codeforces: servermonk Codechef: ayush572000 """ import sys input = sys.stdin.buffer.readline def solution(): n=int(input()) l=list(map(int,input().split())) beg=0 end=10**12 m=max(l) s=sum(l) while beg<end-1: mid=(beg+end)//2 if n*mid-s>=mid and mi...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 2 2
O(n)
0.000001
{ "public_tests": [ { "input": "3\n3 2 2\n", "output": "4\n" }, { "input": "4\n2 2 2 2\n", "output": "3\n" } ], "private_tests": [ { "input": "3\n1000000000 1000000000 10000000\n", "output": "1005000000\n" }, { "input": "3\n1 2 1\n", "out...
[ 0.0001276384138029939, 0.00007678220219624127, 0.0000644844134888549, 0.000059901777425699305, 0.00003865573109702797, 0.000004478546574519231, 0.000002862931545017483, 0.0000028546085145323428, 0.000002821081034200175, 0.000002417995970826049, 0.0000024011889204545454, 0.000002230624781468531...
348_A. Mafia
1626
1626_179
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number ...
import math n = int(input()) a = [int(x) for x in input().split()] a.sort(reverse=True) low = a[0] high = sum(a) while low < high: mid = (low + high) // 2 t = 0 i = 0 while i < n and t < mid: if t >= a[i]: t = mid break t += (mid - a[i]) i += 1 if t >= mid: high = mid else: low = mid + 1 print(hi...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 2 2
O(nlogn)
0.000008
{ "public_tests": [ { "input": "3\n3 2 2\n", "output": "4\n" }, { "input": "4\n2 2 2 2\n", "output": "3\n" } ], "private_tests": [ { "input": "3\n1000000000 1000000000 10000000\n", "output": "1005000000\n" }, { "input": "3\n1 2 1\n", "out...
[ 0.00005512697022508742, 0.000034628062486341786, 0.000022893483418924827, 0.000011963657037959188, 0.00001160108197889001, 0.000011121795680636446, 0.000011040350868313944, 0.000008233217771133299, 0.000008200809439929776, 0.000008143327199983831, 0.000008133398352635908, 0.0000081138324364794...
43_B. Letter
799
799_94
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him;...
a = list(input()) b =(input()) h=0 for k in b: if k!=' ': if k in a: a.remove(k) else: print('NO') h+=1 break if h==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, ...
Instead of dogging your footsteps it disappears but you dont notice anything Your dog is upstears
O(n**2)
0.000051
{ "public_tests": [ { "input": "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n", "output": "NO\n" }, { "input": "abcdefg hijk\nk j i h g f e d c b a\n", "output": "YES\n" }, { "input": "Instead of dogging Your foot...
[ 0.04454171600000001, 0.03346077221126761, 0.009281605152748038, 0.007219831174161314, 0.002932158397035882, 0.0022603018645779172, 0.0007656276180243548, 0.0006775674892516919, 0.0006639974912494387, 0.0005580806895668144, 0.00009165964459840774, 0.00008945155827401195, 0.0000651364011747529...
43_B. Letter
799
799_281
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him;...
a={} for c in input(): if c==" ": continue if c in a: a[c]+=1 else: a[c]=1 ans="YES" for c in input(): if c==" ": continue if c in a: if a[c]==0: ans="NO" break else: a[c]-=1 else: ans="NO" 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, ...
Instead of dogging your footsteps it disappears but you dont notice anything Your dog is upstears
O(n)
0.000017
{ "public_tests": [ { "input": "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n", "output": "NO\n" }, { "input": "abcdefg hijk\nk j i h g f e d c b a\n", "output": "YES\n" }, { "input": "Instead of dogging Your foot...
[ 0.00006581962715799825, 0.000051402304865056824, 0.0000466194080392264, 0.00004245563977819056, 0.0000360325472847465, 0.00003394578843422203, 0.000031953786016717666, 0.00003150427040537587, 0.00002517037345662151, 0.000022723214338395983, 0.000022297086797967658, 0.000022060013808457167, 0...
394_A. Counting Sticks
2799
2799_66
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add...
s=input() ar=[0,0,0] k=0 for i in s: if i=='|': ar[k]+=1 else: k+=1 if ar[0]+ar[1]-ar[2]==0: print(s) elif ar[0]+ar[1]-ar[2]==2: if ar[0]>1: print(s[1:]+s[0]) else: s='|'*ar[0]+"+"+'|'*(ar[1]-1)+"="+'|'*(ar[2]+1) print(s) elif ar[0]+ar[1]-ar[2]==-2: if ar[...
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, ...
|+|=||||||
O(n**2)
0
{ "public_tests": [ { "input": "|+|=||||||\n", "output": "Impossible\n" }, { "input": "|||||+||=||\n", "output": "Impossible\n" }, { "input": "||+|=|||||\n", "output": "|||+|=||||\n" }, { "input": "||||+||=||||||\n", "output": "||||+||=||||||...
[ 0.000005250733610274906, 0.0000010540234829003535, 5.32202979359346e-7, 4.784939223205184e-7, 4.141017323338045e-7, 3.777470715477776e-7, 3.2407308580568507e-7, 2.6541139395189654e-7, 2.5093919672924867e-7, 2.0178769550017498e-7, 1.9849436556922682e-7, 1.9678717557530269e-7, 8.49410431826946...
394_A. Counting Sticks
2799
2799_164
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add...
s = input() l = [] l = s.split("+") temp = l[1].split("=") l[1] = temp[0] l.append(temp[1]) a = [] for i in l: a.append(i.count("|")) result = (a[0] + a[1]) - a[2] if result == 0: print(s) elif result == 2: l[2] += "|" if a[0] == 1: l[1] = l[1][:-1] else: l[0] = l[0][:-1] 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, ...
|+|=||||||
O(n)
0.000001
{ "public_tests": [ { "input": "|+|=||||||\n", "output": "Impossible\n" }, { "input": "|||||+||=||\n", "output": "Impossible\n" }, { "input": "||+|=|||||\n", "output": "|||+|=||||\n" }, { "input": "||||+||=||||||\n", "output": "||||+||=||||||...
[ 0.000007573635830965909, 0.00000731929326923077, 0.000004181742651879372, 0.0000033910385844624122, 0.0000026537211948208043, 0.0000023989877076048952, 0.000002394918856534091, 0.0000023933218012456296, 0.0000022695318782779723, 0.0000018467630982298953, 0.0000014754424715909093, 8.77399844296...
1342_B. Binary Period
662
662_559
Let's say string s has period k if s_i = s_{i + k} for all i from 1 to |s| - k (|s| means length of string s) and k is the minimum positive integer with this property. Some examples of a period: for s="0101" the period is k=2, for s="0000" the period is k=1, for s="010" the period is k=2, for s="0011" the period is k=...
def fun(s): if s.strip("0") == "" or s.strip("1") == "": return s ans = "" n = len(s) for i in range(0, n): if s[0] == "0": ans = ans + "01" else: ans = ans + "10" return ans tc = int(input()) while tc > 0: s = str(input()) print(fun(s)) tc = tc - 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 00 01 111 110
O(n**2)
0.000014
{ "public_tests": [ { "input": "4\n00\n01\n111\n110\n", "output": "00\n01\n111\n1010\n" } ], "private_tests": [ { "input": "4\n00\n01\n111\n110\n", "output": "00\n01\n111\n1010\n" }, { "input": "1\n0001010000\n", "output": "01010101010101010101\n" }, ...
[ 0.00003436814556719781, 0.00003109086645620437, 0.00003043825908446023, 0.000026513220242942944, 0.000026001766473183324, 0.000025821038804106032, 0.000024924805611112868, 0.000024727234640520994, 0.00002466383240620566, 0.000024561566297062643, 0.000024552647660789262, 0.00002450660524793591,...
1342_B. Binary Period
662
662_527
Let's say string s has period k if s_i = s_{i + k} for all i from 1 to |s| - k (|s| means length of string s) and k is the minimum positive integer with this property. Some examples of a period: for s="0101" the period is k=2, for s="0000" the period is k=1, for s="010" the period is k=2, for s="0011" the period is k=...
# list( map(int, input().split()) ) rw = int(input()) for ewqr in range(rw): t = input() if t.count('1') == 0 or t.count('0') == 0: print(t) continue s = '01' * len(t) 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, ...
4 00 01 111 110
O(n)
0.000012
{ "public_tests": [ { "input": "4\n00\n01\n111\n110\n", "output": "00\n01\n111\n1010\n" } ], "private_tests": [ { "input": "4\n00\n01\n111\n110\n", "output": "00\n01\n111\n1010\n" }, { "input": "1\n0001010000\n", "output": "01010101010101010101\n" }, ...
[ 0.0011742961925781251, 0.00007654417125721966, 0.00007190102964410385, 0.00004817611640625001, 0.00004306334556201779, 0.0000384146540494807, 0.00003731868756133288, 0.00003687366837223624, 0.000036567369686522454, 0.00003636105388659785, 0.00003609774516603404, 0.00003528038335026433, 0.000...
1041_A. Heist
603
603_489
There was an electronic store heist last night. All keyboards which were in the store yesterday were numbered in ascending order from some integer number x. For example, if x = 4 and there were 3 keyboards in the store, then the devices had indices 4, 5 and 6, and if x = 10 and there were 7 of them then the keyboards ...
import math n=int(input()) indices=[] indices=input().split(' ') for i in range(n): indices[i]=int(indices[i]) minIndic=min(indices) maxIndic=max(indices) diff=maxIndic-minIndic+1 if diff<n : x=0 else: x=diff-n 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, ...
4 10 13 12 8
O(n)
0.000002
{ "public_tests": [ { "input": "4\n10 13 12 8\n", "output": "2\n" }, { "input": "5\n7 5 6 4 8\n", "output": "0\n" } ], "private_tests": [ { "input": "3\n1000000000 500000000 2\n", "output": "999999996\n" }, { "input": "2\n500000000 500000001\n"...
[ 0.0001373727151852054, 0.0001348171008932474, 0.00013468278148218968, 0.00013445403170072115, 0.0001340132126447771, 0.00013310029378824304, 0.0001214776022180944, 0.000046082778887128504, 0.000005430471194820804, 0.0000052981226917613644, 0.000004741829723011364, 0.000004581226972246504, 0....
1041_A. Heist
603
603_284
There was an electronic store heist last night. All keyboards which were in the store yesterday were numbered in ascending order from some integer number x. For example, if x = 4 and there were 3 keyboards in the store, then the devices had indices 4, 5 and 6, and if x = 10 and there were 7 of them then the keyboards ...
n=int(input()) l=list(map(int,input().split())) l.sort() x=0 for i in range(n-1): x+=l[i+1]-l[i]-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, ...
4 10 13 12 8
O(nlogn)
0.000011
{ "public_tests": [ { "input": "4\n10 13 12 8\n", "output": "2\n" }, { "input": "5\n7 5 6 4 8\n", "output": "0\n" } ], "private_tests": [ { "input": "3\n1000000000 500000000 2\n", "output": "999999996\n" }, { "input": "2\n500000000 500000001\n"...
[ 0.00013145536952305508, 0.000022189737107175983, 0.000013359023533490596, 0.000012161181552995752, 0.000012089754321481248, 0.000012085450933491895, 0.000011936734322213764, 0.000011931328271359922, 0.000011833871928699696, 0.000011807625718564458, 0.000011806590150864912, 0.000011801911259931...
1075_B. Taxi drivers and Lyft
85
85_141
Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5. Lyft has become so popular so that it is now used by all m taxi drivers in the city, who every day transport the rest of the city residents — n riders. Each resident (including taxi drivers) of Palo...
n, m = map(int, input().split()) a = list(map(int, input().split())) s = list(map(int, input().split())) d = [0]*m f = [] for q in range(len(s)): if s[q] == 1: f.append(a[q]) q2, q1 = -float('inf'), f[0] q3, q4 = -1, 0 for q in range(len(a)): if s[q] == 1: q2, q1 = a[q], f[q4+1] if len(f) > q4+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, ...
1 4 2 4 6 10 15 1 1 1 1 0
O(n)
0.000004
{ "public_tests": [ { "input": "1 4\n2 4 6 10 15\n1 1 1 1 0\n", "output": "0 0 0 1\n" }, { "input": "3 2\n2 3 4 5 6\n1 0 0 0 1\n", "output": "2 1\n" }, { "input": "3 1\n1 2 3 10\n0 0 1 0\n", "output": "3\n" } ], "private_tests": [], "generated_tests": ...
[ 0.000016542751523069797, 0.00001625159415693734, 0.000012549356930179196, 0.000011446024495739435, 0.0000035587600661057693, 0.000002389356356534091, 0.0000020330907998251747, 0.0000020228335882867137, 0.000001992670468203671, 0.0000019904880490603147, 0.0000019818242050917835, 7.9962181763548...
1075_B. Taxi drivers and Lyft
85
85_71
Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5. Lyft has become so popular so that it is now used by all m taxi drivers in the city, who every day transport the rest of the city residents — n riders. Each resident (including taxi drivers) of Palo...
def binary_search(array, target): lower = 0 upper = len(array) - 1 if upper == lower: return 0 while lower < upper: # use < instead of <= x = lower + (upper - lower) // 2 val = array[x] if target == val: return x elif target > val: if low...
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 4 2 4 6 10 15 1 1 1 1 0
O(nlogn)
0.000015
{ "public_tests": [ { "input": "1 4\n2 4 6 10 15\n1 1 1 1 0\n", "output": "0 0 0 1\n" }, { "input": "3 2\n2 3 4 5 6\n1 0 0 0 1\n", "output": "2 1\n" }, { "input": "3 1\n1 2 3 10\n0 0 1 0\n", "output": "3\n" } ], "private_tests": [], "generated_tests": ...
[ 0.00001469056799312123, 0.00001468492477416062, 0.000014652266712439308, 0.000012263306032708951, 0.0000020900162716754988, 0.0000020846613391149396, 0.000001961068286183712, 0.0000018291142525360645 ]
1214_B. Badges
1937
1937_10
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them. Organizers are preparing red badges for girls and blue ones for boys. Vasya ...
b = int(input()) g = int(input()) n = int(input()) bn = list(range(n+1)) gn = list(reversed(list(range(n+1)))) res = 0 for i in range(n+1): if bn[i] > b: continue if gn[i] > g: continue res += 1 print(res)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 3 5
O(n)
0.000002
{ "public_tests": [ { "input": "5\n3\n5\n", "output": "4\n" }, { "input": "5\n6\n3\n", "output": "4\n" } ], "private_tests": [ { "input": "4\n7\n10\n", "output": "2\n" }, { "input": "100\n200\n250\n", "output": "51\n" }, { "...
[ 0.00010220357070858828, 0.000009662402698863637, 0.000008617352627840909, 0.000008071488212958917, 0.00000743207502458479, 0.000007329643465909092, 0.000006654078671328672, 0.000006620997432255245, 0.000006122921506228148, 0.000005933953603037588, 0.000005833403286166959, 0.0000056948221700174...
1214_B. Badges
1937
1937_360
There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them. Organizers are preparing red badges for girls and blue ones for boys. Vasya ...
b, g, n = (int(input()) for _ in range(3)) print(1 + min(b+g-n, b, g, n))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 3 5
O(1)
0.000002
{ "public_tests": [ { "input": "5\n3\n5\n", "output": "4\n" }, { "input": "5\n6\n3\n", "output": "4\n" } ], "private_tests": [ { "input": "4\n7\n10\n", "output": "2\n" }, { "input": "100\n200\n250\n", "output": "51\n" }, { "...
[ 0.0000250005, 0.000006591000000000002, 0.000005801000000000001, 0.000004773499999999998, 0.000004387500000000002, 0.000004178500000000001, 0.000003911000000000004, 0.000003720500000000006, 0.0000036095, 0.0000035774999999999975, 0.000003444000000000003, 0.0000034340000000000013, 0.0000034035...
339_D. Xenia and Bit Operations
772
772_19
Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value v for a. Namely, it takes several iterations to calculate value v. At the first iteration, Xeni...
import sys reader = (line.rstrip() for line in sys.stdin) input = reader.__next__ class SegmentTree() : def __init__(self, size): N = 1 while N < size: N <<= 1 self.N = N self.tree = [0] * (2 * N) def update(self, index, value) : index += self.N self.tree[index] = value flag = False while index...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 4 1 6 3 5 1 4 3 4 1 2 1 2
O(n**2)
0.000007
{ "public_tests": [ { "input": "2 4\n1 6 3 5\n1 4\n3 4\n1 2\n1 2\n", "output": "1\n3\n3\n3\n" } ], "private_tests": [ { "input": "1 10\n6 26\n1 11\n1 9\n1 31\n1 10\n2 12\n1 8\n2 10\n2 4\n2 18\n1 31\n", "output": "27\n27\n31\n26\n14\n12\n10\n12\n26\n31\n" }, { "inp...
[ 0.0014366781391862956, 0.000516018125624554, 0.00000965484296930764, 0.00000898170164168451, 0.000008729333333333333, 0.000006562598857958601, 0.000005181731620271235, 0.0000032154561027837263, 0.000002947241256245539, 0.0000027957573162027125, 6.961391862955032e-7, 1.6715289332378776e-9 ]
339_D. Xenia and Bit Operations
772
772_6
Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value v for a. Namely, it takes several iterations to calculate value v. At the first iteration, Xeni...
#Xenia and Bit Operations #from operator import or_, xor import sys def ispow2(n): #doesn't work for n = 0. neg = n & (n-1) if neg == 0: return True else: return False def build_seg_tree(n, a): #n is length of a. Tree will have high-level nodes from 1 to n-1, and array will start at n to 2...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 4 1 6 3 5 1 4 3 4 1 2 1 2
O(n)
0.000002
{ "public_tests": [ { "input": "2 4\n1 6 3 5\n1 4\n3 4\n1 2\n1 2\n", "output": "1\n3\n3\n3\n" } ], "private_tests": [ { "input": "1 10\n6 26\n1 11\n1 9\n1 31\n1 10\n2 12\n1 8\n2 10\n2 4\n2 18\n1 31\n", "output": "27\n27\n31\n26\n14\n12\n10\n12\n26\n31\n" }, { "inp...
[ 0.000018970394729872882, 0.000004819135421219406, 0.000004782102341018357, 0.000004763660907451923, 0.0000044202899231991525, 0.0000042261511691433574, 0.000004221254452578672, 0.000003991729977054196, 0.000003968559863964161, 0.000003953843422202798, 0.000003953113950502622, 0.000003952503277...
1547_B. Alphabetical Strings
2087
2087_50
A string s of length n (1 ≤ n ≤ 26) is called alphabetical if it can be obtained using the following algorithm: * first, write an empty string to s (i.e. perform the assignment s := ""); * then perform the next step n times; * at the i-th step take i-th lowercase letter of the Latin alphabet and write it eithe...
for _ in range(int(input())): a=input() s="" while len(a)!=1: if a[0]>a[-1]: s+=a[0] a=a[1:] else: s+=a[-1] a=a[:-1] if len(a)==1: break s+="a" if a!="a" or s[::-1] not in "abcdefghijklmnopqrstuvwxyz": prin...
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 a ba ab bac ihfcbadeg z aa ca acb xyz ddcba
O(n**2)
0.000004
{ "public_tests": [ { "input": "11\na\nba\nab\nbac\nihfcbadeg\nz\naa\nca\nacb\nxyz\nddcba\n", "output": "YES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" } ], "private_tests": [ { "input": "1\nbabe\n", "output": "NO\n" }, { "input": "1\naaaaaaaaaaaaaaaaa\n", ...
[ 0.0007427046852244709, 0.00007841636395012393, 0.00007567043290162378, 0.0000747068488162535, 0.00007321934236329385, 0.00006534804840347694, 0.00006437374600132113, 0.00005968349717390881, 0.000059167587721748396, 0.00005543435385267765, 0.00005411970084477406, 0.000019480511845776863, 0.00...
1547_B. Alphabetical Strings
2087
2087_119
A string s of length n (1 ≤ n ≤ 26) is called alphabetical if it can be obtained using the following algorithm: * first, write an empty string to s (i.e. perform the assignment s := ""); * then perform the next step n times; * at the i-th step take i-th lowercase letter of the Latin alphabet and write it eithe...
a = "abcdefghijklmnopqrstuvwxyz" def alpha (r,n): if len(r)==1 and r[0]==n: print("YES") return 0 elif r[0]==n: alpha(r[1:],a[(a.find(n))-1]) elif r[-1]==n: alpha(r[:-1],a[(a.find(n))-1]) else: print("NO") k = int(input()) for i in range(k): r = str(input()) ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
11 a ba ab bac ihfcbadeg z aa ca acb xyz ddcba
O(n)
0.000044
{ "public_tests": [ { "input": "11\na\nba\nab\nbac\nihfcbadeg\nz\naa\nca\nacb\nxyz\nddcba\n", "output": "YES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n" } ], "private_tests": [ { "input": "1\nbabe\n", "output": "NO\n" }, { "input": "1\naaaaaaaaaaaaaaaaa\n", ...
[ 0.00037630971998106063, 0.00022926463275786715, 0.00017671173266772293, 0.00016296119551737325, 0.00016151690025404284, 0.00015353775083315122, 0.0001423873134697334, 0.0001072296415947334, 0.00009197283268684442, 0.00007870415951431382, 0.00007284600797639861, 0.00007247476623961977, 0.0000...
1202_D. Print a 1337-string...
1867
1867_45
The subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You are given an integer n. You have to find a sequence s consisting of digits \{1, 3, 7\} such that it has exactly n subsequences equal to 1337. For example, seque...
import sys input = sys.stdin.readline from math import floor, sqrt, log q = int(input()) for _ in range(q): #a = c = 1 n = int(input()) if n == 1: print("1337") continue x = 2 while (x * (x - 1) // 2 < n): x += 1 x -= 1 n -= x * (x - 1) // 2 print("133", end = '') print('7' * n, end = '') print('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, ...
2 6 1
O(n**2)
0.000007
{ "public_tests": [ { "input": "2\n6\n1\n", "output": "133337\n1337\n" } ], "private_tests": [ { "input": "10\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n", "output": "133777773333333333333337\n1337777773333333333333337\n13377777773333333333333337\n1337777777733333333333...
[ 0.000020308210481482866, 0.000009974525049713804, 0.000008881165288685398, 0.000008117705449668911, 0.000007313482415270699, 0.000007240977118700161, 0.000006752890278541192, 0.0000060478269182621605, 0.000006044525910172696, 0.000005996105822054799, 0.000005967008791645204, 0.0000057083616920...
1202_D. Print a 1337-string...
1867
1867_16
The subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You are given an integer n. You have to find a sequence s consisting of digits \{1, 3, 7\} such that it has exactly n subsequences equal to 1337. For example, seque...
import bisect Q=int(input()) A=[n*(n-1)//2 for n in range(10**5)] x=bisect.bisect(A,10**9) for testcases in range(Q): t=int(input()) if t==1: print(1337) continue x=bisect.bisect_left(A,t) ANS="1"+"3"*(x-1-2)+"1"*(t-(A[x-1]))+"337" print(ANS)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 6 1
O(n)
0.000007
{ "public_tests": [ { "input": "2\n6\n1\n", "output": "133337\n1337\n" } ], "private_tests": [ { "input": "10\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n", "output": "133777773333333333333337\n1337777773333333333333337\n13377777773333333333333337\n1337777777733333333333...
[ 0.06491736655932204, 0.05016561546126761, 0.021679401, 0.0177110535, 0.00934822739796701, 0.000034519125980966306, 0.000027253988595322437, 0.000026977262393917513, 0.000025232993104817706, 0.000013867606341495702, 0.000013424523651108383, 0.000012634839255343335, 0.000011758335924302652, ...
1105_B. Zuhair and Strings
2231
2231_77
Given a string s of length n and integer k (1 ≤ k ≤ n). The string s has a level x, if x is largest non-negative integer, such that it's possible to find in s: * x non-intersecting (non-overlapping) substrings of length k, * all characters of these x substrings are the same (i.e. each substring contains only one ...
k = int(input().split()[1]) result = {} prev = 0 value = 0 STR = input() + '$' for letter in STR: if letter != prev: result[prev] = result.get(prev, 0) + value//k prev = letter value = 0 value+=1 print(max(result.values()))
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 abab
O(n)
0.000001
{ "public_tests": [ { "input": "4 2\nabab\n", "output": "0\n" }, { "input": "8 2\naaacaabb\n", "output": "2\n" }, { "input": "2 1\nab\n", "output": "1\n" } ], "private_tests": [ { "input": "3 2\nzzz\n", "output": "1\n" }, { ...
[ 0.0001236455021033654, 0.00002897183648382867, 0.000023909910402097904, 0.000022393053840690563, 0.00002147354430725525, 0.00002042812864674388, 0.00001038877972027972, 0.000008944696814903846, 0.000008937743744536714, 0.000008935206443946678, 0.0000074072104458041965, 0.000006900236123251747,...
1105_B. Zuhair and Strings
2231
2231_194
Given a string s of length n and integer k (1 ≤ k ≤ n). The string s has a level x, if x is largest non-negative integer, such that it's possible to find in s: * x non-intersecting (non-overlapping) substrings of length k, * all characters of these x substrings are the same (i.e. each substring contains only one ...
n,k=input().split() n=int(n) k=int(k) s=input() arr=[] f=s[0] z='' for i in range (len(s)): if s[i]==f: z=z+s[i] else: f=s[i] arr.append(z) z=f arr.append(z) arr arr.sort() f=arr[0][0] c=0 i=0 q=[] while i<len(arr): if f in arr[i]: c=c+int(len(arr[i])/k) 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, ...
4 2 abab
O(nlogn)
0.000011
{ "public_tests": [ { "input": "4 2\nabab\n", "output": "0\n" }, { "input": "8 2\naaacaabb\n", "output": "2\n" }, { "input": "2 1\nab\n", "output": "1\n" } ], "private_tests": [ { "input": "3 2\nzzz\n", "output": "1\n" }, { ...
[ 0.000011167501868613431, 0.000011074882954934317, 0.000006643253406134823, 0.000006208776030098015, 0.000003585341509632473, 0.0000035364231587466156, 0.0000030800167186620876, 0.0000030020006252753372, 0.0000029397211730421895, 9.514218781913937e-7, 9.433027481209528e-7, 8.373224019277092e-7,...
1155_A. Reverse a Substring
1577
1577_173
You are given a string s consisting of n lowercase Latin letters. Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from po...
n=int(input()) s=input() f=0 for i in range(len(s)-1): if s[i+1]<s[i]: print("YES") print(i+1,i+2) f=1 break if f==0: 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, ...
7 abacaba
O(n)
0.000003
{ "public_tests": [ { "input": "7\nabacaba\n", "output": "YES\n2 3\n" }, { "input": "6\naabcfg\n", "output": "NO\n" } ], "private_tests": [ { "input": "6\nbabcdc\n", "output": "YES\n1 2\n" }, { "input": "5\nbadec\n", "output": "YES\n1 2\n...
[ 0.000013162871489838287, 0.000011293737379807693, 0.000010393602065101342, 0.000009391852054195805, 0.000006511211350575126, 0.000006397615411931819, 0.000005875782001201924, 0.000005771513627769513, 0.000005737136431927449, 0.000005402512155812937, 0.000004234321869536714, 0.00000411822630299...
1155_A. Reverse a Substring
1577
1577_61
You are given a string s consisting of n lowercase Latin letters. Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from po...
n = int(input()) s = input() s = [i for i in s] z = sorted(s) if z == s: print("NO") else: for i in range(n-1): if ord(s[i]) > ord(s[i+1]): print("YES") print(i+1, i+2) 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, ...
7 abacaba
O(nlogn)
0.000021
{ "public_tests": [ { "input": "7\nabacaba\n", "output": "YES\n2 3\n" }, { "input": "6\naabcfg\n", "output": "NO\n" } ], "private_tests": [ { "input": "6\nbabcdc\n", "output": "YES\n1 2\n" }, { "input": "5\nbadec\n", "output": "YES\n1 2\n...
[ 0.000042490725600810334, 0.000042430595324918565, 0.00004216235073104636, 0.000023213394814560425, 0.000022668412702068833, 0.000022386484992407863, 0.000022308197539072577, 0.000021855788164012594, 0.000021590333958805005, 0.000021568531106103626, 0.00002152438142259603, 0.0000215041268443716...
1155_A. Reverse a Substring
1577
1577_411
You are given a string s consisting of n lowercase Latin letters. Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from po...
def main(): n = int(input()) s = input() try: index = next(i for i in range(n - 1) if s[i] > s[i + 1]) print('YES\n%d %d' % (index + 1, index + 2)) except StopIteration: print('NO') if __name__ == '__main__': main()
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 abacaba
O(1)
0
{ "public_tests": [ { "input": "7\nabacaba\n", "output": "YES\n2 3\n" }, { "input": "6\naabcfg\n", "output": "NO\n" } ], "private_tests": [ { "input": "6\nbabcdc\n", "output": "YES\n1 2\n" }, { "input": "5\nbadec\n", "output": "YES\n1 2\n...
[ 0.000004849999999999982, 0.000004152499999999998, 0.0000035134999999999995, 0.0000032199999999999997, 0.0000031940000000000036, 0.000003131500000000002, 0.000003117000000000001, 0.0000030530000000000028, 0.000002942500000000001, 0.000002878000000000002, 0.0000027795000000000028, 0.000002723500...
1351_B. Square?
1018
1018_421
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rec...
#By maxwill, contest: Testing Round #16 (Unrated), problem: (B) Square?, Compilation error, #, Copy T = int(input().strip()) for i in range(T): a = list(map(int, input().strip().split())) b = list(map(int, input().strip().split())) flag = False for i in range(2): for j in range(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, ...
3 2 3 3 1 3 2 1 3 3 3 1 3
O(n*m)
0.000005
{ "public_tests": [ { "input": "3\n2 3\n3 1\n3 2\n1 3\n3 3\n1 3\n", "output": "Yes\nYes\nNo\n" } ], "private_tests": [ { "input": "1\n64 9\n41 36\n", "output": "No\n" } ], "generated_tests": [ { "input": "1\n64 9\n41 14\n", "output": "No\n" }, { ...
[ 0.00005078542743389423, 0.000009411331088833043, 0.000008191859607189686, 0.000006604482517482518, 0.00000646976596645542, 0.000006277632621284966, 0.000005809313155594406, 0.000005778906045126748, 0.000005751047366695804, 0.0000057229640105987775, 0.000005604953876201924, 0.000005590783831402...
1351_B. Square?
1018
1018_254
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rec...
import math for _ in range(int(input())): a, b = map(int, input().split()) c, d = map(int, input().split()) if c + b == a == d or a + d == b == c or a + c == d == b or b + d == a == c: print('Yes') else: print('No')
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 2 3 3 1 3 2 1 3 3 3 1 3
O(n)
0
{ "public_tests": [ { "input": "3\n2 3\n3 1\n3 2\n1 3\n3 3\n1 3\n", "output": "Yes\nYes\nNo\n" } ], "private_tests": [ { "input": "1\n64 9\n41 36\n", "output": "No\n" } ], "generated_tests": [ { "input": "1\n64 9\n41 14\n", "output": "No\n" }, { ...
[ 0.0004504473409598215, 0.0000858726726808348, 0.00007845475401551573, 0.0000783221214898383, 0.00006916599243334791, 0.00006771212370246942, 0.00006723730718695368, 0.00006556092762510927, 0.0000652465951294799, 0.00006520754899202362, 0.00006509654016881555, 0.00006508433901059878, 0.000065...
630_H. Benches
2803
2803_133
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections. The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Ob...
def fact(i): ans = 1 for j in range(1, i + 1): ans *= j return ans def c(i, j): return fact(i) // (fact(j) * fact(i - j)) n = int(input()) ans = 1 for j in range(5): ans *= n - j print(ans * c(n, 5))
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
O(n**2)
0
{ "public_tests": [ { "input": "5\n", "output": "120\n" } ], "private_tests": [ { "input": "7\n", "output": "52920\n" }, { "input": "100\n", "output": "680185280130048000\n" }, { "input": "83\n", "output": "101159538130177920\n" }, ...
[ 7.947781637010583e-7, 4.250447474664373e-7, 4.199607457498551e-7, 3.9803008828842533e-7, 3.8682803837405796e-7, 7.315555646119063e-8, 1.636877504225658e-8, 1.636640446027586e-8, 1.618612237693284e-8, 8.251769749142259e-9, 8.202311331016429e-9, 8.170409740020814e-9, 8.164779476430939e-9, 8....
630_H. Benches
2803
2803_59
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections. The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Ob...
n = int(input()) fact = 120 print(n * n * ((n - 1) ** 2) * ((n - 2) ** 2) * ((n - 3) ** 2) * ((n - 4) ** 2) // fact)
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
O(1)
0.000004
{ "public_tests": [ { "input": "5\n", "output": "120\n" } ], "private_tests": [ { "input": "7\n", "output": "52920\n" }, { "input": "100\n", "output": "680185280130048000\n" }, { "input": "83\n", "output": "101159538130177920\n" }, ...
[ 0.0015451120000000151, 0.000016213000000000002, 0.000011433000000000004, 0.000011074999999999998, 0.000009993000000000007, 0.000008299000000000003, 0.000008198499999999996, 0.000008149499999999997, 0.0000079885, 0.000007854500000000004, 0.000007468, 0.000007366499999999998, 0.000007245500000...
1433_E. Two Round Dances
1073
1073_645
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n/2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people. Each person should belong to exactly one of these two round da...
def f(a): res = 1 for i in range(1, 1+a): res *= i return res n = int(input()) print(f(n) * f(n//2 - 1) ** 2 // f(n//2) ** 2 // 2)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2
O(n**2)
0
{ "public_tests": [ { "input": "2\n", "output": "1\n" }, { "input": "20\n", "output": "12164510040883200\n" }, { "input": "4\n", "output": "3\n" }, { "input": "8\n", "output": "1260\n" } ], "private_tests": [ { "input": "14\...
[ 0.0004314418020454152, 0.00007291855087536835, 0.00004792331890275611, 0.00004754700130005201, 0.00004608582613971225, 0.00003279911635465419, 0.000030533548968625414, 0.00002626165630958572, 4.3214306053232764e-7, 4.1649247143565505e-7, 3.775790797575759e-7, 4.25956838273531e-8, 2.956554054...
1433_E. Two Round Dances
1073
1073_822
One day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly n/2 people. Your task is to find the number of ways n people can make two round dances if each round dance consists of exactly n/2 people. Each person should belong to exactly one of these two round da...
fact = 1 n = int(input()) for i in range(2, n): fact *= i print(fact * 2 // 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
O(n)
0.000001
{ "public_tests": [ { "input": "2\n", "output": "1\n" }, { "input": "20\n", "output": "12164510040883200\n" }, { "input": "4\n", "output": "3\n" }, { "input": "8\n", "output": "1260\n" } ], "private_tests": [ { "input": "14\...
[ 0.000004977270268793707, 0.000002900042253521127, 0.0000028905460338284216, 0.0000025709395857307253, 0.0000021837757110059507, 0.0000020133449776785715, 0.000002009490605819238, 0.000002007179637351825, 0.000001933863093285855, 0.0000019293658482142857, 0.0000019185926064751908, 0.00000190237...
525_B. Pasha and String
380
380_19
Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string. Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent ...
s = list(input()) n = len(s) m = int(input()) a = list(map(int,input().split())) l = [0]*(n+1) for i in a: l[i-1]+=1 l[n-i+1]-=1 k = 0 l2 = [] for i in range(n): k += l[i] if k%2==0: l2.append(s[i]) else: l2.append(s[n-i-1]) print("".join(l2))
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, ...
abcdef 3 1 2 3
O(n+m)
0.000004
{ "public_tests": [ { "input": "abcdef\n3\n1 2 3\n", "output": "fbdcea\n" }, { "input": "abcdef\n1\n2\n", "output": "aedcbf\n" }, { "input": "vwxyz\n2\n2 2\n", "output": "vwxyz\n" } ], "private_tests": [ { "input": "wljqgdlxyc\n13\n3 4 3 3 5 4 ...
[ 0.00006730111743334792, 0.000014172479526333042, 0.000009003086797967658, 0.000008878895897071678, 0.000007717185656140735, 0.000007487563087303321, 0.000007363230455091784, 0.000007071249904392483, 0.000007043415305397729, 0.0000066592291302447545, 0.00000658898900513549, 0.000006399131706184...
525_B. Pasha and String
380
380_112
Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string. Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent ...
s = list(input()) m = int(input()) n=len(s) lis = sorted(map(int,input().split())) has=[0]*(n+3) for i in range(m): a=lis[i] has[a-1]+=1 for i in range(1,n+2): has[i]+=has[i-1] for i in range(n//2): if has[i]%2: s[i],s[n-i-1]=s[n-i-1],s[i] print(''.join(s))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
abcdef 3 1 2 3
O(nlogn)
0.000008
{ "public_tests": [ { "input": "abcdef\n3\n1 2 3\n", "output": "fbdcea\n" }, { "input": "abcdef\n1\n2\n", "output": "aedcbf\n" }, { "input": "vwxyz\n2\n2 2\n", "output": "vwxyz\n" } ], "private_tests": [ { "input": "wljqgdlxyc\n13\n3 4 3 3 5 4 ...
[ 0.000008789337322148138, 0.000008514739746269029, 0.00000822900248527365, 0.000008220949357834386, 0.000008206118262544688, 0.000008160902991104706, 0.000008132516576981796, 0.000008108795042102714, 0.00000808508283593417, 0.00000807988155006946, 0.00000806973537199218, 0.000008011189964937245...
1197_B. Pillars
1453
1453_483
There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius a_i. You can move these disks from one pillar to another. You can take a disk from pillar i and place it on top of pillar j if all these conditions are met: ...
n=int(input()) a=list(map(int,input().split())) p=1 r=1 e=0 if r==0: print("NO") else: k=max(a) t=a.index(k) c=max(t,n-t-1) for i in range(c): if i<t: if a[i]<a[i+1]: pass else: e=1 break if i+t<n-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 3 1 2
O(n)
0.000001
{ "public_tests": [ { "input": "3\n3 1 2\n", "output": "NO" }, { "input": "4\n1 3 4 2\n", "output": "YES" } ], "private_tests": [ { "input": "5\n3 1 5 4 2\n", "output": "NO" }, { "input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n", "output": "...
[ 0.00006641244703343531, 0.00006617123490767045, 0.00006591277552720717, 0.0000656675291329764, 0.00006562597059385927, 0.00006557483241368008, 0.00006556602816324301, 0.00006556043392154722, 0.0000653540394722465, 0.00006491893024748689, 0.00006489688823481207, 0.00006458486583533654, 0.0000...
1197_B. Pillars
1453
1453_211
There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius a_i. You can move these disks from one pillar to another. You can take a disk from pillar i and place it on top of pillar j if all these conditions are met: ...
def f(l): for i in range(len(l)-1): if l[i] > l[i+1]: break #print(i+1) if sorted(l[i+1:],reverse=True) == l[i+1:]:return 0 return 1 M = 10**9 + 7 R = lambda: map(int, input().split()) n = int(input()) L = list(R()) if len(set(L)) != n:print("NO") else:print("YNEOS"[f(L)::2])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 1 2
O(nlogn)
0.000008
{ "public_tests": [ { "input": "3\n3 1 2\n", "output": "NO" }, { "input": "4\n1 3 4 2\n", "output": "YES" } ], "private_tests": [ { "input": "5\n3 1 5 4 2\n", "output": "NO" }, { "input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n", "output": "...
[ 0.00015017467554906034, 0.00001623126550283517, 0.000016031244779323844, 0.000015992484673356803, 0.000015854046872022225, 0.000013445847495100254, 0.000009953166446806819, 0.000009002793332867401, 0.00000899040460563296, 0.000008904412611363042, 0.000008681369950871973, 0.00000861284488338319...
978_B. File Name
2226
2226_1222
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia...
n = int(input()) string = input() counter = int() result = int() for letter in string: if letter == 'x': counter += 1 if counter >= 3: result += 1 else: counter = 0 print(result)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
10 xxxxxxxxxx
O(n)
0.000004
{ "public_tests": [ { "input": "10\nxxxxxxxxxx\n", "output": "8\n" }, { "input": "5\nxxoxx\n", "output": "0\n" }, { "input": "6\nxxxiii\n", "output": "1\n" } ], "private_tests": [ { "input": "5\nfcyju\n", "output": "0\n" }, { ...
[ 0.000026897697648055072, 0.000022561077970813464, 0.00002254239016062063, 0.000021244298049606648, 0.000020226293801901223, 0.000019195817662805944, 0.000019008700311407343, 0.00001652660402097902, 0.000015168875614619757, 0.000015103416684877623, 0.000015054024844296332, 0.0000149070353277369...
978_B. File Name
2226
2226_607
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia...
from math import ceil, log, floor, sqrt import math k = 1 def mod_expo(n, p, m): """find (n^p)%m""" result = 1 while p != 0: if p%2 == 1: result = (result * n)%m p //= 2 n = (n * n)%m return result def is_prime(n): m = 2 while m*m <= n: if n%m == 0: return False m += 1 return True def 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, ...
10 xxxxxxxxxx
O(nlogn)
0.000001
{ "public_tests": [ { "input": "10\nxxxxxxxxxx\n", "output": "8\n" }, { "input": "5\nxxoxx\n", "output": "0\n" }, { "input": "6\nxxxiii\n", "output": "1\n" } ], "private_tests": [ { "input": "5\nfcyju\n", "output": "0\n" }, { ...
[ 0.00003068139055670892, 0.000029525664349087308, 0.00002011042361053156, 0.000005912773047903046, 0.00000527845523914309, 0.000005277354840512244, 0.000005073113157943341, 0.0000048318000740914475, 0.00000479156924294885, 0.000004513656971815965, 0.000004435533054850825, 0.00000443399055547334...
883_F. Lost in Transliteration
2704
2704_92
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland s...
def replacement(str): str2 = str.replace("oo","u") str3 = str2.replace("kh","h") if str3 == str: return str3 else : str3 = replacement(str3) return str3 n = int(input()) myList = [] myList2 = [] for i in range(n): myList.append(input()) for x in myList: str4 = replacement(x) str4 = str4.replace("u"...
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 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon
O(n**2)
0.000048
{ "public_tests": [ { "input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n", "output": "4" }, { "input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n", "output": "5" }, { "input": "2\nalex\nale...
[ 0.00014939107972338696, 0.00010882471225276196, 0.00009112724187528239, 0.0000875340724483365, 0.00008110549264868816, 0.0000756630965929857, 0.00007158345392516022, 0.00006528488054585901, 0.00006366944306438477, 0.00006113570237043475, 0.00005948077223163899, 0.00005799487138873461, 0.0000...
883_F. Lost in Transliteration
2704
2704_62
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland s...
#### Answer to <https://codeforces.com/problemset/problem/251/A> # import math # count, bounds = [int(x) for x in input().split(" ")] # total = 0 # left_index = 0 # right_index = 2 # current = 0 # lst = [int(x) for x in input().split(" ")] # if lst[0] < 0: # delta = 1 - lst[0] # lst = [x + delta for x in lst...
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 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon
O(nlogn)
0.000022
{ "public_tests": [ { "input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n", "output": "4" }, { "input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n", "output": "5" }, { "input": "2\nalex\nale...
[ 0.0001429161614928818, 0.00013821540802154888, 0.00006082299039106274, 0.00005249396984077194, 0.000048791044260393854, 0.0000469782060525657, 0.0000436940279663529, 0.000042930172471646594, 0.00004279544880269591, 0.000042417137112253914, 0.00003976403756377899, 0.0000388838507866436, 0.000...
1088_A. Ehab and another construction problem
2913
2913_309
Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of in...
t = int(input()) flag=0 for i in range(1,t+1): if flag!=1: for j in range(1,t+1): if flag!=1: if i%j == 0: if i*j>t: if i%j < t: a,b = i,j flag=1 if flag==1: print(a,b) 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, ...
1
O(n**2)
0
{ "public_tests": [ { "input": "1\n", "output": "-1\n" }, { "input": "10\n", "output": "4 4\n" } ], "private_tests": [ { "input": "82\n", "output": "10 10\n" }, { "input": "49\n", "output": "8 8\n" }, { "input": "35\n", ...
[ 6.921815032853759e-7, 4.3410845334498605e-7, 4.19770193492123e-7, 3.860305858916997e-7, 3.8367698570748557e-7, 2.600179532782636e-7, 2.5228497183968347e-7, 2.5079663590895123e-7, 2.3677933999991532e-7, 2.3652082211775025e-7, 2.354455804306466e-7, 2.3395738448014025e-7, 2.338500282217249e-7, ...
1088_A. Ehab and another construction problem
2913
2913_484
Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of in...
def Calculo_Brute_Force(x): for a in range(1,x+1): if ((a*a)>x) : print (a,a) return(a,a) print(-1) return(-1) Calculo_Brute_Force(int(input()))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
1
O(n)
0
{ "public_tests": [ { "input": "1\n", "output": "-1\n" }, { "input": "10\n", "output": "4 4\n" } ], "private_tests": [ { "input": "82\n", "output": "10 10\n" }, { "input": "49\n", "output": "8 8\n" }, { "input": "35\n", ...
[ 0.00001172839936625874, 0.0000044950388029938815, 0.0000033027920809659094, 0.0000011404491914335665, 0.0000010272236123251749, 8.983902289117134e-7, 7.332557637674824e-7, 7.110290237106643e-7, 7.063311161494756e-7, 6.805569274475525e-7, 6.32283899694056e-7, 5.747569520323428e-7, 5.530637292...
1088_A. Ehab and another construction problem
2913
2913_633
Given an integer x, find 2 integers a and b such that: * 1 ≤ a,b ≤ x * b divides a (a is divisible by b). * a ⋅ b>x. * a/b<x. Input The only line contains the integer x (1 ≤ x ≤ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of in...
x=int(input()); print(-1) if x==1 else print(x-(x%2),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, ...
1
O(1)
0.000002
{ "public_tests": [ { "input": "1\n", "output": "-1\n" }, { "input": "10\n", "output": "4 4\n" } ], "private_tests": [ { "input": "82\n", "output": "10 10\n" }, { "input": "49\n", "output": "8 8\n" }, { "input": "35\n", ...
[ 0.000038636999999999996, 0.000018951000000000005, 0.000016260000000000004, 0.000010033000000000004, 0.000009698000000000001, 0.000009336, 0.000009240000000000006, 0.0000091275, 0.000008597500000000004, 0.000008367000000000003, 0.000008284, 0.000008160500000000001, 0.000008050999999999998, ...
1430_A. Number of Apartments
795
795_300
Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apar...
t=int(input()) while(t>0): n=int(input()) f=0 for i in range(n//3+1): if(f==1): break for j in range(n//5+1): if(f==1): break for k in range(n//7+1): if(f==1): break if(3*i+5*j+7*k==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, ...
4 30 67 4 14
O(n**2)
0.000036
{ "public_tests": [ { "input": "4\n30\n67\n4\n14\n", "output": "10 0 0\n20 0 1\n-1\n3 1 0\n" } ], "private_tests": [ { "input": "1\n1\n", "output": "-1\n" }, { "input": "4\n30\n67\n4\n14\n", "output": "10 0 0\n20 0 1\n-1\n3 1 0\n" }, { "input":...
[ 0.0016209632372103868, 0.00018050008390193647, 0.0001636815412574211, 0.00016177770560219174, 0.00015397684592030253, 0.00013807548169582348, 0.00013665778650547212, 0.00013339499867909488, 0.0001332624154836556, 0.00013268572252646849, 0.00012715034365692152, 0.00012337380969181758, 0.00012...
1430_A. Number of Apartments
795
795_580
Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apar...
import math from sys import stdin from sys import setrecursionlimit setrecursionlimit(100000) def put(): return map(int, stdin.readline().split()) for _ in range(int(input())): n=int(input()) if(n%3==0): print(n//3,0,0) elif(n%3==1): if(n//3>=2): print((n//3)-2,0,1) else: print(-1) else: if(n//3>=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 30 67 4 14
O(n)
0.000017
{ "public_tests": [ { "input": "4\n30\n67\n4\n14\n", "output": "10 0 0\n20 0 1\n-1\n3 1 0\n" } ], "private_tests": [ { "input": "1\n1\n", "output": "-1\n" }, { "input": "4\n30\n67\n4\n14\n", "output": "10 0 0\n20 0 1\n-1\n3 1 0\n" }, { "input":...
[ 0.10075361255932205, 0.07274234598305085, 0.07074109727118645, 0.06927485986440678, 0.04981597536971832, 0.04850274353521127, 0.04667251386619719, 0.04616460575352113, 0.044768302510563386, 0.044098282179577473, 0.04351310978521127, 0.04074735713380282, 0.03055874157991968, 0.0300728925020...
1251_A. Broken Keyboard
960
960_36
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning. To check which buttons need replacement, Polycarp pressed som...
t = int(input()) for _ in range(t): s = list(input().strip()) g = set() n = len(s) c = 1 if n==1: print(s[0]) else: for i in range(1,n): if s[i]!=s[i-1] and c&1: g.add(s[i-1]) else: c += 1 if i==n-1 and c&1: ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 a zzaaz ccff cbddbb
O(n**2)
0.000032
{ "public_tests": [ { "input": "4\na\nzzaaz\nccff\ncbddbb\n", "output": "a\nz\n\nbc\n" } ], "private_tests": [ { "input": "1\naababbaaamr\n", "output": "abmr\n" }, { "input": "1\naabambaaamr\n", "output": "abmr\n" }, { "input": "1\ndeep\n", ...
[ 0.00012897801511702528, 0.00010627437372406034, 0.00010476008648906872, 0.00010165459272092067, 0.00009048476673793991, 0.00007097255875725563, 0.00006698750641603042, 0.00006581931048752621, 0.00006005758055362904, 0.0000593860433913016, 0.00005894727004595829, 0.00005670437539030013, 0.000...
1251_A. Broken Keyboard
960
960_63
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning. To check which buttons need replacement, Polycarp pressed som...
n = int(input()) r = [] for i in ' '*n: s = input() m = [] t = set() j = 0 while j < len(s): if s[j] not in t: c = 1 while j < len(s)-1 and s[j] == s[j+1]: j += 1 c += 1 if c % 2 == 1: t.add(s[j]) j += 1 r += [t] for i in r: print(*sorted(i), sep='')
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 a zzaaz ccff cbddbb
O(nlogn)
0.000033
{ "public_tests": [ { "input": "4\na\nzzaaz\nccff\ncbddbb\n", "output": "a\nz\n\nbc\n" } ], "private_tests": [ { "input": "1\naababbaaamr\n", "output": "abmr\n" }, { "input": "1\naabambaaamr\n", "output": "abmr\n" }, { "input": "1\ndeep\n", ...
[ 0.00037302249028026786, 0.0001953942546440319, 0.0001859463166076545, 0.0001783119355083675, 0.00014405166784847866, 0.00012403363527190792, 0.00009857755212682993, 0.00009163981334085396, 0.0000864081386029486, 0.00008221923930541687, 0.00008135472876551489, 0.00007912985402991174, 0.000068...
459_B. Pashmak and Flowers
669
669_40
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
lst = list(map(int, input().split())) n=lst[0] b = list(map(int, input().split())) max=-1 min=10000000000 maxf=0 minf=0 for x in b: if(x>max): maxf=1 max=x elif x==max: maxf+=1 if(x<min): minf=1 min=x elif x==min: minf+=1 if(max==min): print(max-min,ma...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 1 4 5
O(n)
0.000002
{ "public_tests": [ { "input": "3\n1 4 5\n", "output": "4 1\n" }, { "input": "2\n1 2\n", "output": "1 1\n" }, { "input": "5\n3 1 2 3 1\n", "output": "2 4\n" } ], "private_tests": [ { "input": "5\n5 5 5 5 5\n", "output": "0 10\n" }, ...
[ 0.000005431781577797203, 0.000004974170249672203, 0.000004884924620301574, 0.0000047911915974650345, 0.000004671986027644231, 0.000004652318919361888, 0.000004620356110686189, 0.000004536329736669581, 0.000004482013753824301, 0.000004297281837303322, 0.000004123101767373253, 0.0000040819157151...
459_B. Pashmak and Flowers
669
669_107
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
x=int(input()) s=[int(i) for i in input().split()] s.sort() a=min(s) b=max(s) if a==b: print(0,int(x*(x-1)/2)) else: A=0 B=0 for i in s: if i==a: A+=1 if i==b: B+=1 print(b-a,int(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, ...
3 1 4 5
O(nlogn)
0.000008
{ "public_tests": [ { "input": "3\n1 4 5\n", "output": "4 1\n" }, { "input": "2\n1 2\n", "output": "1 1\n" }, { "input": "5\n3 1 2 3 1\n", "output": "2 4\n" } ], "private_tests": [ { "input": "5\n5 5 5 5 5\n", "output": "0 10\n" }, ...
[ 0.000017316373862639836, 0.000016935157388386723, 0.00001683417467493593, 0.000016320539390312657, 0.000009098056700432401, 0.000008791438470523366, 0.000008756453133274247, 0.000008734431313453526, 0.000008591492354906109, 0.000008568778436705905, 0.000008549714107960677, 0.000008482833029126...
248_A. Cupboards
1650
1650_428
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
#!/usr/bin/env python3 # -*- coding: utf-8 -*- n=int(input()) d=[] l,p,t=0,0,0, for i in range(n): d.append(list(map(int,input().split()))) if d[i][0]==1: l+=1 if d[i][1]==1: p+=1 if l<n-l: t+=l else: t+=n-l if p<n-p: t+=p else: t+=n-p 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, ...
5 0 1 1 0 0 1 1 1 0 1
O(n*m)
0.000002
{ "public_tests": [ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1\n", "output": "3\n" } ], "private_tests": [ { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0\n", "output": "7\n" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1\n", "output": "6\n" ...
[ 0.000004930878810642483, 0.00000383770078944493, 0.0000030338438319493003, 0.0000026799804141171333, 0.0000026525486778846153, 0.000002597184030812937, 0.000002591177133413462, 0.0000025748665728802447, 0.000002571535292832168, 0.000002571106725305944, 0.000002567290428321678, 0.00000255410829...
248_A. Cupboards
1650
1650_311
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
n = int(input()) left = [] right = [] for i in range(n): l, r = input().split() left.append(l) right.append(r) left_0 = left.count('0') left_1 = left.count('1') right_0 = right.count('0') right_1 = right.count('1') print (min(left_0, left_1) + min(right_0, right_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 0 1 1 0 0 1 1 1 0 1
O(n)
0
{ "public_tests": [ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1\n", "output": "3\n" } ], "private_tests": [ { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0\n", "output": "7\n" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1\n", "output": "6\n" ...
[ 0.00003066723956512238, 0.000022982638945039338, 0.000022653262961647728, 0.000022590331594187068, 0.00002239335081129808, 0.000021843478529283216, 0.000020985241163133744, 0.000020765196555397733, 0.000020073167217548076, 0.000019369010448535843, 0.0000193178629534528, 0.000019312311830747382...
975_B. Mancala
2639
2639_73
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. <image> Initially, each hole has a_i stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in th...
a = list(map(int, input().split())) ans = 0 for i in range(len(a)): x = a[i] b = [j for j in a] b[i] = 0 for j in range(len(a)): b[j] += x // 14 for j in range(1, x % 14 + 1): b[(i + j) % 14] += 1 ans_now = 0 for j in b: if j % 2 == 0: ans_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, ...
0 1 1 0 0 0 0 0 0 7 0 0 0 0
O(n**2)
0.000142
{ "public_tests": [ { "input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0\n", "output": "4\n" }, { "input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0\n", "output": "8\n" } ], "private_tests": [ { "input": "787 393 649 463 803 365 81 961 989 531 303 407 579 915\n", "output": "7588\n" ...
[ 0.0003670194104226995, 0.00031561009044711347, 0.0002974694064675373, 0.00029095999937083075, 0.0002317975423151929, 0.00021045341320995693, 0.00020302318931950082, 0.00020276436218283234, 0.00019384668902243258, 0.0001871824141580255, 0.00017560208222213724, 0.00016340376872561266, 0.000156...
975_B. Mancala
2639
2639_117
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. <image> Initially, each hole has a_i stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in th...
a = list(map(int, input().split())) def check(a): a = a[:] x = a[0] a[0] = 0 for i in range(1, 14): a[i] += max(0, (x+14-i) // 14) a[0] = max(0, x // 14) return sum((x if x % 2 == 0 else 0 for x in a)) print(max((check(a[i:] + a[:i]) for i in range(14) if a[i] > 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, ...
0 1 1 0 0 0 0 0 0 7 0 0 0 0
O(n)
0.00003
{ "public_tests": [ { "input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0\n", "output": "4\n" }, { "input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0\n", "output": "8\n" } ], "private_tests": [ { "input": "787 393 649 463 803 365 81 961 989 531 303 407 579 915\n", "output": "7588\n" ...
[ 0.000743686399609375, 0.0003604091580965909, 0.0003168999081758086, 0.0003139855089734484, 0.0003109865031140734, 0.0003048887639040647, 0.0003034638610822771, 0.00029681096855878493, 0.00026797162083424386, 0.00021080098031850964, 0.00020681512583315122, 0.0001845992634123689, 0.00017620210...
18_D. Seller Bob
2942
2942_42
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory ...
n = int(input()) d = [0 for i in range(2009)] ans = 0 for i in range(n): s = input().split() x = int(s[1]) if s[0] == 'win': d[x] = ans+ 2**x else: ans = max(d[x], ans) 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, ...
7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10
O(n*m)
0.000002
{ "public_tests": [ { "input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n", "output": "1056" }, { "input": "3\nwin 5\nsell 6\nsell 4\n", "output": "0" } ], "private_tests": [ { "input": "10\nsell 1898\nsell 173\nsell 1635\nsell 29\nsell 881\nsell ...
[ 0.0000023940973830856647, 0.000002169782902644231, 0.0000020854790756118883, 0.0000020553955692744757, 0.0000020351952578671327, 0.0000020351825420673078, 0.00000203462576486014, 0.0000020331515515734265, 0.0000020256877048732522, 0.0000020247704463505245, 0.0000020218649885270977, 0.000002019...
18_D. Seller Bob
2942
2942_55
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory ...
s=int(input()) a={} sum=[] ls=-1 for i in range(s): sum.append(0) for i in range(s): n, z = map(str, input().split()) m=int(z) if(n=="win"): a[m]=(1,i) if (n=="sell"): p = a.get(m, -1) if(p!=-1): if(sum[i-1]<2**m+sum[a[m][1]]): sum[i]=2**m+sum[a[m][1]] ls=i 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, ...
7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10
O(n)
0
{ "public_tests": [ { "input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10\n", "output": "1056" }, { "input": "3\nwin 5\nsell 6\nsell 4\n", "output": "0" } ], "private_tests": [ { "input": "10\nsell 1898\nsell 173\nsell 1635\nsell 29\nsell 881\nsell ...
[ 0.00423214058843649, 0.00009371315874945369, 0.000041542446664663464, 0.00002660091440592364, 0.000025054255280023253, 0.000024602313415100526, 0.00002328261563046329, 0.00002299710184932255, 0.00002282101226513645, 0.000021285997268356644, 0.00002110335157615822, 0.000017213817635489516, 0....
978_C. Letters
1180
1180_39
There are n dormitories in Berland State University, they are numbered with integers from 1 to n. Each dormitory consists of rooms, there are a_i rooms in i-th dormitory. The rooms in i-th dormitory are numbered from 1 to a_i. A postman delivers letters. Sometimes there is no specific dormitory and room number in it o...
from bisect import bisect n, m = map(int, input().split()) x = [1] for v in map(int, input().split()): x.append(x[-1] + v) for v in map(int, input().split()): i = bisect(x, v) - 1 print(i+1, v-x[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, ...
2 3 5 10000000000 5 6 9999999999
O(n+m)
0.000008
{ "public_tests": [ { "input": "2 3\n5 10000000000\n5 6 9999999999\n", "output": "1 5\n2 1\n2 9999999994\n" }, { "input": "3 6\n10 15 12\n1 9 12 23 26 37\n", "output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12\n" } ], "private_tests": [ { "input": "3 10\n1000000000 10000000...
[ 0.000013743377813592657, 0.000011136444834462414, 0.000010953029788570805, 0.000010875727627840911, 0.000010726264764532346, 0.000010652642224645962, 0.000010399362789554196, 0.000010061829977351802, 0.00000984300081949301, 0.000009687487147618006, 0.000009476406495847903, 0.000009424845074847...
978_C. Letters
1180
1180_626
There are n dormitories in Berland State University, they are numbered with integers from 1 to n. Each dormitory consists of rooms, there are a_i rooms in i-th dormitory. The rooms in i-th dormitory are numbered from 1 to a_i. A postman delivers letters. Sometimes there is no specific dormitory and room number in it o...
n_dorm,n_letter = map(int,input().split()) dorms = list(map(int,input().split()))[:n_dorm] lroom = list(map(int,input().split()))[:n_letter] d_left = 0 d_right = len(dorms) - 1 l_left = 0 l_right = len(lroom) - 1 lst = [] new = 0 while l_left <= l_right: if lroom[l_left] <= dorms[d_left]: lst.append([d_left...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 3 5 10000000000 5 6 9999999999
O(n+m)log(n+m)
0.000026
{ "public_tests": [ { "input": "2 3\n5 10000000000\n5 6 9999999999\n", "output": "1 5\n2 1\n2 9999999994\n" }, { "input": "3 6\n10 15 12\n1 9 12 23 26 37\n", "output": "1 1\n1 9\n2 2\n2 13\n3 1\n3 12\n" } ], "private_tests": [ { "input": "3 10\n1000000000 10000000...
[ 0.00005186257773915146, 0.000027683406211419644, 0.00002629601292067308, 0.00002588427850469843, 0.000025035213764750875, 0.000023545625874125878, 0.00002127887069766171, 0.000020861130176464164, 0.000020618333861451053, 0.000020415310697115388, 0.000019801803485576923, 0.0000196020561629289, ...
768_A. Oath of the Night's Watch
1997
1997_199
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple...
n = int(input()) arr = [int(x) for x in input().split()] ans, mi, ma = 0, min(arr), max(arr) for x in arr: if not (x == mi or x == ma): ans += 1 print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 1 2 5
O(n)
0.000002
{ "public_tests": [ { "input": "3\n1 2 5\n", "output": "1\n" }, { "input": "2\n1 5\n", "output": "0\n" } ], "private_tests": [ { "input": "6\n1 1 1 1 1 1\n", "output": "0\n" }, { "input": "2\n1 1\n", "output": "0\n" }, { "in...
[ 0.00042594334009630927, 0.00004369024435915647, 0.00004359606326486014, 0.00004355748187554633, 0.00004347568909801137, 0.000003574564152644231, 0.0000034343082796110144, 0.0000033261764505026225, 0.000003276448672421329, 0.0000032079847984047205, 0.0000030517001884833917, 0.000002958958205856...
768_A. Oath of the Night's Watch
1997
1997_311
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple...
n = int(input()) stewards = sorted(list(map(int, input().split()))) help = 0 mx = max(stewards) mn = min(stewards) for each in stewards: if mn < each < mx: help += 1 print(help)
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 5
O(nlogn)
0.000008
{ "public_tests": [ { "input": "3\n1 2 5\n", "output": "1\n" }, { "input": "2\n1 5\n", "output": "0\n" } ], "private_tests": [ { "input": "6\n1 1 1 1 1 1\n", "output": "0\n" }, { "input": "2\n1 1\n", "output": "0\n" }, { "in...
[ 0.00008755666743607956, 0.000015112450073880827, 0.00000914249769296748, 0.000008937397385403395, 0.000008890516107053907, 0.000008863159758173709, 0.000008816490527091387, 0.000008734409670004278, 0.000008715712957040999, 0.000008711976544996389, 0.00000870486095147654, 0.00000862147930816843...
1138_A. Sushi for Two
2105
2105_521
Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers n pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy. The pieces of sushi are of two types: either with tuna or with eel. Let's denote the type of the i-th from t...
n = int(input()) a = list(map(int, input().split())) b = []; k = 0; c = a[0] for i in range(n): if a[i] == c: k += 1 else: b.append(k) k = 1 c = a[i] b.append(k) ans = [] for i in range(len(b)-1): ans.append(min(b[i], b[i+1])) print(max(ans)*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, ...
6 1 2 1 2 1 2
O(n)
0.000009
{ "public_tests": [ { "input": "6\n1 2 1 2 1 2\n", "output": "2\n" }, { "input": "9\n2 2 1 1 1 2 2 2 2\n", "output": "6\n" }, { "input": "7\n2 2 2 1 1 2 2\n", "output": "4\n" } ], "private_tests": [ { "input": "10\n2 2 1 1 1 2 1 1 2 2\n", ...
[ 0.0000259134486501731, 0.000023108350425481096, 0.00002117258802720717, 0.000019731627909200175, 0.00001875349691932694, 0.00001815418689512474, 0.000017620743775100402, 0.00001723789309301877, 0.000016656224125080217, 0.000016655149633513576, 0.000016601978488308566, 0.0000162177164690778, ...
1138_A. Sushi for Two
2105
2105_248
Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers n pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy. The pieces of sushi are of two types: either with tuna or with eel. Let's denote the type of the i-th from t...
PZS= list(map(int, input().split())) ARREGLODETIPOS= list(map(int, input().split())) if ARREGLODETIPOS[PZS[0]-1]==1: ARREGLODETIPOS.append(2) elif ARREGLODETIPOS[PZS[0]-1]==2: ARREGLODETIPOS.append(1) cont1=0 cont2=0 arreglorepetidos=[] arregloacomodado=[] cont1=1 cont2=1 for i in range(PZS[0]): if ARREGLOD...
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, ...
6 1 2 1 2 1 2
O(nlogn)
0.00001
{ "public_tests": [ { "input": "6\n1 2 1 2 1 2\n", "output": "2\n" }, { "input": "9\n2 2 1 1 1 2 2 2 2\n", "output": "6\n" }, { "input": "7\n2 2 2 1 1 2 2\n", "output": "4\n" } ], "private_tests": [ { "input": "10\n2 2 1 1 1 2 1 1 2 2\n", ...
[ 0.000026943457347604594, 0.000013386734919856644, 0.000009773084308878283, 0.00000974039832434435, 0.00000972385855936218, 0.000009693515676123932, 0.000004538835611155966, 0.000003705061106291183, 0.0000036469035633137966, 0.000003233141807334765, 0.000003187992055438504, 0.000003057302907480...
608_A. Saitama Destroys Hotel
2425
2425_188
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to s and elevator initially starts on floor s...
n,s=map(int,input().split()) f,t=map(int,input().split()) p=max(s,f+t) for i in range(n-1): f,t=map(int,input().split()) v=max(s,f+t) if(p<v): p=v print(p)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 10 2 77 3 33 8 21 9 12 10 64
O(n)
0.000017
{ "public_tests": [ { "input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n", "output": "79\n" }, { "input": "3 7\n2 1\n3 8\n5 2\n", "output": "11\n" } ], "private_tests": [ { "input": "2 10\n9 10\n6 11\n", "output": "19\n" }, { "input": "2 7\n6 3\n1...
[ 0.00006780355249230912, 0.000026499078474426527, 0.000022621222199839422, 0.00002165282559735704, 0.00002130394939408154, 0.000021180819482055548, 0.00002088376708327458, 0.000020702303468599008, 0.000020683243199065295, 0.000020656928158876972, 0.00002060463570069844, 0.000020390999879132862,...
608_A. Saitama Destroys Hotel
2425
2425_5
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to s and elevator initially starts on floor s...
k = [] a, b = map(int, input().split(' ')) for i in range(a): x, y = map(int, input().split(' ')) k.append([x,y]) k.append([0, -1]) k.sort() k.reverse() curr = b t = 0 for i in k: d = curr - i[0] curr = i[0] t = max(i[1], t+d) 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, ...
5 10 2 77 3 33 8 21 9 12 10 64
O(nlogn)
0.000019
{ "public_tests": [ { "input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n", "output": "79\n" }, { "input": "3 7\n2 1\n3 8\n5 2\n", "output": "11\n" } ], "private_tests": [ { "input": "2 10\n9 10\n6 11\n", "output": "19\n" }, { "input": "2 7\n6 3\n1...
[ 0.00011752390427322879, 0.000034334134637990956, 0.00002533371522264014, 0.00002329277955848962, 0.000023163555337435012, 0.00002296618470512736, 0.000022734797607981838, 0.000021938985389465566, 0.000021783231532508946, 0.000021598756218387117, 0.000021565816463254953, 0.000021249095556981662...
361_B. Levko and Permutation
2089
2089_121
Levko loves permutations very much. A permutation of length n is a sequence of distinct positive integers, each is at most n. Let’s assume that value gcd(a, b) shows the greatest common divisor of numbers a and b. Levko assumes that element pi of permutation p1, p2, ... , pn is good if gcd(i, pi) > 1. Levko considers ...
n,k=map(int,input().split()) if n==k: print(-1) else: a=[] a.append(n-k) for i in range(1,n-k): a.append(i) for j in range(n-k+1,n+1): a.append(j) print(*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, ...
1 1
O(n*m)
0.000001
{ "public_tests": [ { "input": "1 1\n", "output": "-1\n" }, { "input": "4 2\n", "output": "2 1 3 4\n" } ], "private_tests": [ { "input": "8485 8484\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35...
[ 0.0000019233318536931822, 0.0000017667201294798952, 0.000001618803758741259, 0.0000015752444684222029, 0.0000014315842848557694, 0.0000012445947470498255, 0.000001237561052229021, 0.0000012350441433566434, 0.0000012325614210008741, 0.000001119652862762238, 0.000001102157328999126, 0.0000010060...
361_B. Levko and Permutation
2089
2089_8
Levko loves permutations very much. A permutation of length n is a sequence of distinct positive integers, each is at most n. Let’s assume that value gcd(a, b) shows the greatest common divisor of numbers a and b. Levko assumes that element pi of permutation p1, p2, ... , pn is good if gcd(i, pi) > 1. Levko considers ...
n,k=map(int,input().split()) if n<=k: print(-1) else: l=[n-k] for i in range(2,n-k+1): l.append(i-1) for i in range(n-k+1,n+1): l.append(i) print(*l)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
1 1
O(n)
0.000001
{ "public_tests": [ { "input": "1 1\n", "output": "-1\n" }, { "input": "4 2\n", "output": "2 1 3 4\n" } ], "private_tests": [ { "input": "8485 8484\n", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35...
[ 0.0000025235866613854894, 0.0000022289639013330423, 0.000002116120998142483, 0.0000020576727901005246, 0.0000019648981506774475, 0.0000018511053321678324, 0.000001820419676027098, 0.00000181531131173514, 0.000001775494536713287, 0.000001755967192963287, 0.0000017421944793487764, 0.000001723450...
25_A. IQ test
1093
1093_628
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is di...
n = int(input()) numbers = list(map(int, input().split())) evens = list() odds = list() def fill_evens(): for k in numbers: if k % 2 == 0: evens.append(k) else: odds.append(k) fill_evens() distinct = evens[0] if len(evens) == 1 else odds[0] print(numbers.index(distinct) +...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 2 1 1
O(n)
0.000003
{ "public_tests": [ { "input": "4\n1 2 1 1\n", "output": "2\n" }, { "input": "5\n2 4 7 8 10\n", "output": "3\n" } ], "private_tests": [ { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 4...
[ 0.00004201527477600525, 0.000041681029296875, 0.000018306791220498252, 0.000012593442840362763, 0.000012189866968968533, 0.000010790135994864512, 0.000010415035388170561, 0.000009818831934248279, 0.000009507907274366259, 0.000009363309495192309, 0.000009323645938046329, 0.000009091269818072553...
25_A. IQ test
1093
1093_909
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is di...
#t=int(input()) #for i in range(t): # n,r=map(int,input().split()) # a=list(map(int,input().split())) # bomb=0 # a.sort() # a=list(set(a)) # n=len(a) # for i in range(n): # if (a[i]>bomb*r): # bomb+=1 # print(bomb-1) n=int(input()) a=list(map(int,input().split())) leven,lodd,ce...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 2 1 1
O(n+mlogm)
0.000002
{ "public_tests": [ { "input": "4\n1 2 1 1\n", "output": "2\n" }, { "input": "5\n2 4 7 8 10\n", "output": "3\n" } ], "private_tests": [ { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 4...
[ 0.00000764945656687063, 0.000006425928745083042, 0.000004454214693509615, 0.000003865281796328671, 0.000003731682323535839, 0.0000034025569957386367, 0.000002901763945039336, 0.0000028223964297421334, 0.0000025633626802884618, 0.0000025592596017263986, 0.00000254591991502193, 0.000002528301696...
1388_B. Captain Flint and a Long Voyage
721
721_169
Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it. ...
from math import ceil t = int(input()) for _ in range(t): n = int(input()) s = [] if n == 1: print(8) else: s = ['9'] * (n - int(ceil(n / 4))) s += ['8'] * int(ceil(n / 4)) print(''.join(s))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 1 3
O(n**2)
0.000008
{ "public_tests": [ { "input": "2\n1\n3\n", "output": "8\n998\n" } ], "private_tests": [ { "input": "1\n2\n", "output": "98\n" }, { "input": "2\n87911\n94124\n", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
[ 0.000023610109399146452, 0.00002232522302000927, 0.000015846365018748795, 0.000014974693880957382, 0.000014489657243826425, 0.000014483905804212507, 0.000014228873676576813, 0.000013886260635588465, 0.000013828406340920146, 0.000013693810514865221, 0.00001360197728561192, 0.0000135522009588792...
1388_B. Captain Flint and a Long Voyage
721
721_309
Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it. ...
import sys sys.setrecursionlimit(10000) # default is 1000 in python t = int(input()) # t = 1 for _ in range(t): n = int(input()) remain = n % 4 times = n // 4 y = "8" * times z = "" if remain != 0: z = "8" # z+y digleft = n - times - 1 if remain == 0: digleft += 1 x = "9"*digleft x = x + z + y 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 1 3
O(nlogn)
0.000001
{ "public_tests": [ { "input": "2\n1\n3\n", "output": "8\n998\n" } ], "private_tests": [ { "input": "1\n2\n", "output": "98\n" }, { "input": "2\n87911\n94124\n", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
[ 0.0980037565, 0.097540636, 0.088634402, 0.087565689, 0.086538763, 0.08530776600000001, 0.0828743155, 0.07463126699999999, 0.0736882055, 0.07297002600000001, 0.072886793, 0.072857081, 0.072631685, 0.0710518585, 0.070176474, 0.0696887665, 0.069586418, 0.06947966700000001, 0.0692036...
1004_C. Sonya and Robots
1039
1039_146
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will giv...
n=int(input()) nums = list(map(int, input().split())) left = {} from collections import Counter left=Counter(nums) count = 0 done = set() for i in nums: left[i] -= 1 if left[i] == 0: del left[i] if i not in done: count += len(left.keys()) done.add(i) print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 1 5 4 1 3
O(n)
0.000003
{ "public_tests": [ { "input": "5\n1 5 4 1 3\n", "output": "9\n" }, { "input": "7\n1 2 1 1 1 3 2\n", "output": "7\n" } ], "private_tests": [ { "input": "10\n2 2 4 4 3 1 1 2 3 2\n", "output": "14\n" }, { "input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5...
[ 0.000011010376207592181, 0.000009884639079222653, 0.000008337355291822179, 0.000007487326948478954, 0.000007138373462181537, 0.000006744818468640735, 0.00000630546488472465, 0.000005952968422202797, 0.000005766935546875001, 0.000005731574847027972, 0.000005720007020323427, 0.000005670603133194...
1004_C. Sonya and Robots
1039
1039_15
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will giv...
from collections import defaultdict from bisect import bisect INF = 10**9 n = int(input()) a = list(map(int, input().split())) first_pos = [INF] * (n+1) for i, x in enumerate(a): if first_pos[x] == INF: first_pos[x] = i last_pos = [-1] * (n+1) for i, x in enumerate(a): last_pos[x] = i last_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 5 4 1 3
O(nlogn)
0.000012
{ "public_tests": [ { "input": "5\n1 5 4 1 3\n", "output": "9\n" }, { "input": "7\n1 2 1 1 1 3 2\n", "output": "7\n" } ], "private_tests": [ { "input": "10\n2 2 4 4 3 1 1 2 3 2\n", "output": "14\n" }, { "input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5...
[ 0.000012150336438618166, 0.000012112067935679104, 0.0000020984015501905413, 0.0000013128825395998442, 0.0000013101497321457601, 0.0000011659292514053216, 0.0000010696984301785926, 0.0000010425868776210676, 9.718771347709944e-7, 9.395111846272619e-7, 8.918863637939339e-7, 8.721338199689024e-7, ...
25_B. Phone numbers
1966
1966_59
Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three d...
n = int(input()) num = input() res = [] if n % 2 == 0: for i in range(0, n, 2): res.append(num[i:i+2]) else: for i in range(0, n-3, 2): res.append(num[i:i+2]) res.append(num[n-3:]) print('-'.join(res))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
6 549871
O(n)
0.000002
{ "public_tests": [ { "input": "6\n549871\n", "output": "54-98-71\n" }, { "input": "7\n1198733\n", "output": "11-98-733\n" } ], "private_tests": [ { "input": "7\n1198733\n", "output": "11-98-733\n" }, { "input": "22\n7135498415686025907059\n", ...
[ 0.000004072547913024476, 0.000004048983459899476, 0.000003950478980004371, 0.000003668629070148602, 0.000003660710650677447, 0.0000035003410320148603, 0.0000034175233145760493, 0.0000031993984784746506, 0.000003030712153081294, 0.0000030299363117351404, 0.000002943386349978147, 0.0000028759294...
25_B. Phone numbers
1966
1966_144
Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three d...
n = int(input()) s = input() if n > 3: if n % 2 == 0: res = '-'.join(a + b for a, b in zip(s[::2], s[1::2])) else: res = s[0:3] + '-' + '-'.join(a + b for a, b in zip(s[3::2], s[4::2])) print(res) else: 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, ...
6 549871
O(1)
0.000002
{ "public_tests": [ { "input": "6\n549871\n", "output": "54-98-71\n" }, { "input": "7\n1198733\n", "output": "11-98-733\n" } ], "private_tests": [ { "input": "7\n1198733\n", "output": "11-98-733\n" }, { "input": "22\n7135498415686025907059\n", ...
[ 0.0000115485, 0.000007862500000000001, 0.000004384000000000004, 0.000004112000000000004, 0.000003942999999999999, 0.0000036910000000000024, 0.0000035110000000000008, 0.0000034435000000000052, 0.0000032660000000000057, 0.0000031014999999999973, 0.000003089500000000005, 0.0000029504999999999983,...
1113_B. Sasha and Magnetic Machines
342
342_149
One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by n machines, and the power of the i-th machine is a_i. This year 2D decided to cultivate a new culture, but what exactly he d...
n = int(input()) arr_str = input().split() arr = [int(x) for x in arr_str] min_el = arr[0] s = 0 for x in arr: s += x if x < min_el: min_el = x diff = 0 for x in arr: if x == min_el: continue for y in range(2, x // 2 + 1): if x % y == 0: new_x = x // y ...
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 2 3 7
O(n**2)
0
{ "public_tests": [ { "input": "5\n2 4 2 3 7\n", "output": "18" }, { "input": "5\n1 2 3 4 5\n", "output": "14" }, { "input": "4\n4 2 4 4\n", "output": "14" } ], "private_tests": [ { "input": "12\n95 98 98 92 94 97 100 83 93 97 87 72\n", "...
[ 0.00023431681003067297, 0.0001214518155115897, 0.00012000788737810725, 0.00004504925773661101, 0.000023320418344177798, 0.000016174277226041688, 0.000008321181273350189, 0.000007471195669301352, 0.000003051984892199689, 0.0000023946611074435744, 0.000001933601365187627, 6.172093471428642e-7, ...
1113_B. Sasha and Magnetic Machines
342
342_86
One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by n machines, and the power of the i-th machine is a_i. This year 2D decided to cultivate a new culture, but what exactly he d...
input() a = list(map(int , input().split())) m = min(a) print(sum(a)-max(i+m-i//j-m*j for i in set(a) for j in range(1 , int(i**.5) + 1)if i%j==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, ...
5 2 4 2 3 7
O(n)
0.010506
{ "public_tests": [ { "input": "5\n2 4 2 3 7\n", "output": "18" }, { "input": "5\n1 2 3 4 5\n", "output": "14" }, { "input": "4\n4 2 4 4\n", "output": "14" } ], "private_tests": [ { "input": "12\n95 98 98 92 94 97 100 83 93 97 87 72\n", "...
[ 0.028678403166265066, 0.026945016285140563, 0.02071065264176707, 0.01846474405220884, 0.0181918684248996, 0.017089389882730927, 0.01706468773172691, 0.01690415049799197, 0.01687844099036145, 0.01683267143293173, 0.01640679759116466, 0.01634850657670683, 0.01631053785060241, 0.0162607351044...
192_A. Funky Numbers
2065
2065_128
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as <image>, where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky ...
#codeforces.com:3.2.5(2.4.0) import math a=int(input())*2;b=0 for i in range(1,int(math.sqrt(a))): c=a-i*i-i;d=int(math.sqrt(c)) if d*(d+1)==c:b=1 print("YES")if(b)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, ...
512
O(n)
0.000001
{ "public_tests": [ { "input": "512\n", "output": "NO\n" }, { "input": "256\n", "output": "YES\n" } ], "private_tests": [ { "input": "39210\n", "output": "YES\n" }, { "input": "187719774\n", "output": "NO\n" }, { "input": "9...
[ 0.000008596645787805945, 0.000004787609115493882, 0.0000031045985167176576, 0.0000030960659555288456, 0.0000028149576731861895, 0.000002745483070640297, 0.0000018560427638767487, 0.0000013061865712412587, 0.0000010521759588068182, 0.0000010154962030157342, 0.0000010102539062500003, 0.000001007...
192_A. Funky Numbers
2065
2065_24
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as <image>, where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky ...
bruh = set([(i+1)*i/2 for i in range(1, 50001)]) n = int(input()) if any(n-t in bruh for t in bruh): print('YES') else: print('NO') ###### thanking telegram for solutions ###### '''__________ ____ ___ _____________ __.___ \______ \ | \/ _____/ |/ _| | | _/ | /\_____ \| < | |...
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, ...
512
O(1)
0.011513
{ "public_tests": [ { "input": "512\n", "output": "NO\n" }, { "input": "256\n", "output": "YES\n" } ], "private_tests": [ { "input": "39210\n", "output": "YES\n" }, { "input": "187719774\n", "output": "NO\n" }, { "input": "9...
[ 0.8181772565, 0.5067492325, 0.34051452950000005, 0.2760858395, 0.11514066550000002, 0.07997363950000001, 0.0729382155, 0.0726859865, 0.06333561100000001, 0.048766059000000014, 0.040643554, 0.032607948, 0.03234084349999998, 0.03130467350000002, 0.02898721999999998, 0.028311029000000015,...
357_A. Group of Students
894
894_85
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 po...
dumb = input() l = [int(o) for o in input().split()] x, y = [int(o) for o in input().split()] def Valid(l, k, x, y): s = 0 for i in range(k): s += l[i] if s >= x and s <= y and sum(l) - s >= x and sum(l) - s <= y and s != sum(l) and s != 0 and sum(l) - s != 0: return True return...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 3 4 3 2 1 6 8
O(n**2)
0.000007
{ "public_tests": [ { "input": "5\n3 4 3 2 1\n6 8\n", "output": "3\n" }, { "input": "2\n2 5\n3 6\n", "output": "0\n" }, { "input": "5\n0 3 3 4 2\n3 10\n", "output": "3\n" } ], "private_tests": [ { "input": "8\n1 1 1 1 2 2 2 1\n3 7\n", "ou...
[ 0.00013600130176464158, 0.000007958542220066261, 0.000007688641463658265, 0.000006993172426082861, 0.000005988464395482676, 1.251205458638067e-7, 1.228199537901932e-7, 1.2177072139542805e-7, 6.335471898675215e-8, 2.278885699655197e-14 ]
357_A. Group of Students
894
894_3
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 po...
m = int(input()) cs = list(map(int, input().split())) l, r = map(int, input().split()) s = sum(cs) ps = 0 for i, a in enumerate(cs): ps += a if(l <= ps <= r and l <= (s-ps) <= r): print(i+2) break else: print(0)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 3 4 3 2 1 6 8
O(n)
0.000004
{ "public_tests": [ { "input": "5\n3 4 3 2 1\n6 8\n", "output": "3\n" }, { "input": "2\n2 5\n3 6\n", "output": "0\n" }, { "input": "5\n0 3 3 4 2\n3 10\n", "output": "3\n" } ], "private_tests": [ { "input": "8\n1 1 1 1 2 2 2 1\n3 7\n", "ou...
[ 0.000005223764546000875, 0.000005177428786057693, 0.000005127269176136364, 0.000005059367897727274, 0.000004892921752076049, 0.0000048290338996940555, 0.000004828571637347029, 0.000004533531509506119, 0.000004382108296000874, 0.000004213625122923951, 0.00000419038391881556, 0.00000396670643028...
914_A. Perfect Squares
2358
2358_421
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y2. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second ...
input() ar = list(map(int, input().split())) maxim = -10 ** 6 for i in ar: if (i < 0 or (int(i ** 0.5)) ** 2 != i) and i > maxim: maxim = i print(maxim)
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 2
O(n)
0.000002
{ "public_tests": [ { "input": "2\n4 2\n", "output": "2\n" }, { "input": "8\n1 2 4 8 16 32 64 576\n", "output": "32\n" } ], "private_tests": [ { "input": "2\n370881 659345\n", "output": "659345\n" }, { "input": "5\n804610 765625 2916 381050 930...
[ 0.007294546740336411, 0.004759837076043668, 0.0047406342365178275, 0.0046386214232769524, 0.004612730979946586, 0.004364571476737103, 0.0013573617855644354, 0.001148637399687472, 0.001000946583048672, 0.000998273638938211, 0.0006865864492187502, 0.0006374262411830357, 0.0006321685054289489, ...
914_A. Perfect Squares
2358
2358_103
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y2. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second ...
from math import sqrt as S def ps(n): return int(S(n))!=S(n) n=int(input()) l=sorted([int(i) for i in input().split()]) for i in l: if i<0: ans=i elif ps(i): ans=i print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 4 2
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2\n4 2\n", "output": "2\n" }, { "input": "8\n1 2 4 8 16 32 64 576\n", "output": "32\n" } ], "private_tests": [ { "input": "2\n370881 659345\n", "output": "659345\n" }, { "input": "5\n804610 765625 2916 381050 930...
[ 0.00006579706579163026, 0.0000453030738909528, 0.00004436745283817745, 0.0000439323518083479, 0.000036265446664663466, 0.00003428011692799389, 0.000006567560295959547, 0.0000055400178374744635, 0.000005528554045514256, 0.00000546843485727994, 0.000005407300790971155, 0.000005220854826943995, ...
814_A. An abandoned sentiment from past
101
101_10
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t...
n,m=map(int,input().split()) l=list(map(int,input().split())) k=list(sorted(map(int,input().split()),reverse=True)) for i in range(n): if l[i]==0: l[i]=k[0] k.pop(0) if l==sorted(l): 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 2 11 0 0 14 5 4
O(nlogn+mlogm)
0.000011
{ "public_tests": [ { "input": "4 2\n11 0 0 14\n5 4\n", "output": "YES\n" }, { "input": "6 1\n2 3 0 8 9 10\n5\n", "output": "NO\n" }, { "input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n", "output": "YES\n" }, { "input": "4 1\n8 94 0 4\n89\n", "ou...
[ 0.000018503115384633504, 0.00001840115190971046, 0.000011983012504210444, 0.00001184321438124554, 0.000011821761048331962, 0.00001170984856602256, 0.000011617690216718626, 0.000011612625681234479, 0.000011611271239518255, 0.000011609723260645087, 0.0000116005963663039, 0.000011523835101263494,...
814_A. An abandoned sentiment from past
101
101_43
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t...
import sys input = sys.stdin.readline N, K = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if a.count(0) > 1: print("Yes") else: for i in range(N): if a[i] == 0: a[i] = b[0] for i in range(N - 1): if a[i + 1] <= a[i]: print("Yes") 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 2 11 0 0 14 5 4
O(n+m)
0.000002
{ "public_tests": [ { "input": "4 2\n11 0 0 14\n5 4\n", "output": "YES\n" }, { "input": "6 1\n2 3 0 8 9 10\n5\n", "output": "NO\n" }, { "input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n", "output": "YES\n" }, { "input": "4 1\n8 94 0 4\n89\n", "ou...
[ 0.0000040589740084134615, 0.000003933104116586539, 0.000002394457673186189, 0.000002223291288789336, 0.0000021664871612762236, 0.0000019597470771416083, 0.000001920252021416084, 0.0000018389865739729025, 0.000001831177748033217, 0.000001823257990056818, 0.0000018200410702578676, 0.000001817097...
186_A. Comparing Strings
1243
1243_0
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Mish...
g1=list(input()) g2=list(input()) cntr=0 if sorted(g1)!=sorted(g2): print('NO') else: for i in range(len(g1)): if g1[i]!=g2[i]: cntr=cntr+1 if cntr==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, ...
ab ba
O(nlogn+mlogm)
0.000005
{ "public_tests": [ { "input": "ab\nba\n", "output": "YES\n" }, { "input": "aa\nab\n", "output": "NO\n" } ], "private_tests": [ { "input": "acaa\nabca\n", "output": "NO\n" }, { "input": "aab\naa\n", "output": "NO\n" }, { "in...
[ 0.000004889860143164823, 0.000004870863266805937, 0.000004839338117484781, 0.000004825749412784371, 0.000004825489476320075, 0.000004822676583400103, 0.000004814289995494631, 0.000004808885601596871, 0.000004806307071596037, 0.000004797503844846795, 0.000004790914791881772, 0.00000476648078258...
186_A. Comparing Strings
1243
1243_178
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Mish...
# http://codeforces.com/problemset/problem/186/A a = list(input()) b = list(input()) ans = 'NO' if len(a)==len(b): l = [] for i in range(len(a)): if a[i]!= b[i]: l.append(i) if len(l) == 2: a[l[0]],a[l[1]] = a[l[1]], a[l[0]] if a == b: ans = 'YES' 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, ...
ab ba
O(n+m)
0
{ "public_tests": [ { "input": "ab\nba\n", "output": "YES\n" }, { "input": "aa\nab\n", "output": "NO\n" } ], "private_tests": [ { "input": "acaa\nabca\n", "output": "NO\n" }, { "input": "aab\naa\n", "output": "NO\n" }, { "in...
[ 0.000001208118211866259, 0.0000010173867597246504, 8.679937991695805e-7, 8.653319629589162e-7, 8.523948590472028e-7, 8.479820667613637e-7, 5.797754179414336e-7, 5.695727982954546e-7, 5.477627567744755e-7, 5.338302966564686e-7, 4.722969023164336e-7, 4.6525412478146857e-7, 4.575358391608391e-7...