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
p03222 AtCoder Beginner Contest 113 - Number of Amidakuji
1861
1861_16
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical l...
f=[0,1,1,2,3,5,8,13,21,34,55,89];h,w,k=map(int,input().split());a=[0]*(w+2);a[1]=1 for i in range(h):a=[0]+[(f[j-1]*f[w-j+1]*a[j-1]+f[j]*f[w-j+1]*a[j]+f[j]*f[w-j]*a[j+1])%(10**9+7)for j in range(1,w+1)]+[0] print(a[k])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 3 1
O(n)
0.000011
{ "public_tests": [ { "input": "2 3 1", "output": "5" }, { "input": "1 3 2", "output": "1" }, { "input": "1 3 1", "output": "2" }, { "input": "7 1 1", "output": "1" }, { "input": "2 3 3", "output": "1" }, { "...
[ 0.00008865464509123689, 0.00007235704662915209, 0.00007028124150458917, 0.00006411839399857954, 0.00006214403157779721, 0.00006180890424224213, 0.00005954016852873689, 0.000059176456635161714, 0.00005671270517373252, 0.0000559218184413243, 0.00005518591710828235, 0.00005510718144940997, 0.00...
432_A. Choosing Teams
2166
2166_84
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The ...
# cook your dish here n, k = map(int,input().split()) a = list(map(int,input().split())) count = 0 for i in a: if(5-i>=k): count+=1 print(count//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, ...
6 4 0 1 2 3 4 5
O(n)
0.000004
{ "public_tests": [ { "input": "6 4\n0 1 2 3 4 5\n", "output": "0\n" }, { "input": "6 5\n0 0 0 0 0 0\n", "output": "2\n" }, { "input": "5 2\n0 4 5 1 0\n", "output": "1\n" } ], "private_tests": [ { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1\n", ...
[ 0.00006720102339930186, 0.00000859499295236014, 0.0000074564102108828665, 0.000007178916083916084, 0.0000071718896962412585, 0.000007171300385161713, 0.000006293880966016191, 0.000006278856520432692, 0.000006192771907779722, 0.0000061376131993007, 0.00000610025390625, 0.000005919001953124999, ...
432_A. Choosing Teams
2166
2166_288
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The ...
n, k = map(int,input().split()) y = map(int,input().split()) z = sorted(y) k = 5-k if(k<0): print("0") else: count = 0 for i in z: if(i<=k): count = count+1 print(int(count/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, ...
6 4 0 1 2 3 4 5
O(nlogn)
0.000018
{ "public_tests": [ { "input": "6 4\n0 1 2 3 4 5\n", "output": "0\n" }, { "input": "6 5\n0 0 0 0 0 0\n", "output": "2\n" }, { "input": "5 2\n0 4 5 1 0\n", "output": "1\n" } ], "private_tests": [ { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1\n", ...
[ 0.000038570250077209414, 0.000032543750715931154, 0.00002935100076295309, 0.000023358213342180167, 0.000020894707224667284, 0.000019257325967401785, 0.000019228343442227683, 0.000018968620032640186, 0.000018872702294386774, 0.000018764784482145482, 0.0000187554357403058, 0.00001856927193893037...
1550_A. Find The Array
1944
1944_85
Let's call an array a consisting of n positive (greater than 0) integers beautiful if the following condition is held for every i from 1 to n: either a_i = 1, or at least one of the numbers a_i - 1 and a_i - 2 exists in the array as well. For example: * the array [5, 3, 1] is beautiful: for a_1, the number a_1 - 2...
for _ in range(int(input())): n=int(input()) if n==1: print(1);continue if n==2: print(2);continue if n==3: print(2);continue S=1 c=1 for i in range(3,n+5,2): if S==n: break if i+S<=n: S=S+i c+=1 else: #print('enter') ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 8 7 42
O(n**2)
0.000014
{ "public_tests": [ { "input": "4\n1\n8\n7\n42\n", "output": "1\n3\n3\n7\n" } ], "private_tests": [], "generated_tests": [ { "input": "4\n1\n12\n7\n42\n", "output": "1\n4\n3\n7\n" }, { "input": "4\n1\n1\n7\n42\n", "output": "1\n1\n3\n7\n" }, { ...
[ 0.000029651771483413863, 0.000022820341265478907, 0.00001871078081032781, 0.000018249250940317538, 0.000016346258903159527, 0.000016234854991093245, 0.000014884494887607955, 0.000013752536264457294, 0.00001343935991355122, 0.000013048503270607127, 0.000012543566826575807, 0.0000119926572553375...
1550_A. Find The Array
1944
1944_50
Let's call an array a consisting of n positive (greater than 0) integers beautiful if the following condition is held for every i from 1 to n: either a_i = 1, or at least one of the numbers a_i - 1 and a_i - 2 exists in the array as well. For example: * the array [5, 3, 1] is beautiful: for a_1, the number a_1 - 2...
import math t=int(input()) for i in range(t): print(math.ceil(math.sqrt(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, ...
4 1 8 7 42
O(n)
0.000012
{ "public_tests": [ { "input": "4\n1\n8\n7\n42\n", "output": "1\n3\n3\n7\n" } ], "private_tests": [], "generated_tests": [ { "input": "4\n1\n12\n7\n42\n", "output": "1\n4\n3\n7\n" }, { "input": "4\n1\n1\n7\n42\n", "output": "1\n1\n3\n7\n" }, { ...
[ 0.00011362146989113323, 0.00001731189732912409, 0.000016178038168114675, 0.000015919914791547358, 0.00001564688345818141, 0.000015117290696971704, 0.000014907199312784001, 0.000014078339256782231, 0.000014015973325774344, 0.000013726805159300007, 0.000013490455004331072, 0.00001347643513607625...
1201_B. Zero Array
2010
2010_45
You are given an array a_1, a_2, …, a_n. In one operation you can choose two elements a_i and a_j (i ≠ j) and decrease each of them by one. You need to check whether it is possible to make all the elements equal to zero or not. Input The first line contains a single integer n (2 ≤ n ≤ 10^5) — the size of the array....
def check(l): s = sum(l) for i in l: if s-i < i: return "NO" if s%2: return ("NO") else: return ("YES") n = int(input()) l = list(map(int,input().split())) print(check(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, ...
6 1 2 3 4 5 6
O(n)
0.000004
{ "public_tests": [ { "input": "6\n1 2 3 4 5 6\n", "output": "NO\n" }, { "input": "4\n1 1 2 2\n", "output": "YES\n" } ], "private_tests": [ { "input": "3\n10407 5987 4237\n", "output": "NO\n" }, { "input": "8\n3343 33870 9537 1563 709 8515 5451...
[ 0.000006622487898819932, 0.000005959142482517483, 0.000005771277234484266, 0.000005759060779064685, 0.000005689299019340035, 0.000005671048595935315, 0.000005589177802666084, 0.00000555913090034965, 0.0000055461229376092655, 0.000005533124494645979, 0.000005465214980332168, 0.00000541128817315...
1201_B. Zero Array
2010
2010_401
You are given an array a_1, a_2, …, a_n. In one operation you can choose two elements a_i and a_j (i ≠ j) and decrease each of them by one. You need to check whether it is possible to make all the elements equal to zero or not. Input The first line contains a single integer n (2 ≤ n ≤ 10^5) — the size of the array....
n=int(input()) inp = input() a=[int(ele) for ele in inp.split()] a.sort() count=0 for ele in a: if ele%2!=0: count += 1 if sum(a[:n-1]) < a[-1]: print('NO') elif count%2==0: 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, ...
6 1 2 3 4 5 6
O(nlogn)
0.000018
{ "public_tests": [ { "input": "6\n1 2 3 4 5 6\n", "output": "NO\n" }, { "input": "4\n1 1 2 2\n", "output": "YES\n" } ], "private_tests": [ { "input": "3\n10407 5987 4237\n", "output": "NO\n" }, { "input": "8\n3343 33870 9537 1563 709 8515 5451...
[ 0.00001835767286714104, 0.000018136409749731036, 0.00001808882748425467, 0.000018081797949888906, 0.000018066210192702862, 0.000018020798505612774, 0.00001801255047779087, 0.000017984747064781635, 0.000017983674026723226, 0.00001797792387482535, 0.000017970883802715656, 0.00001790922305177493,...
977_F. Consecutive Subsequence
952
952_116
You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence ...
n = int(input()) a = list(map(int, input().split())) dc = dict() for x in a: dc[x] = max(dc.get(x, 0), dc.get(x - 1, 0) + 1) ans = 0 mx = 0 for x in dc.keys(): if dc[x] > mx: mx = dc[x] ans = x arr = [] for i in range(n - 1, -1, -1): if a[i] == ans: ans -= 1 arr.append(i + 1)...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 10 9 8 7
O(n)
0.000006
{ "public_tests": [ { "input": "4\n10 9 8 7\n", "output": "1\n1 \n" }, { "input": "6\n1 3 5 2 4 6\n", "output": "2\n1 4 \n" }, { "input": "7\n3 3 4 7 5 6 8\n", "output": "4\n2 3 5 6 \n" }, { "input": "9\n6 7 8 3 4 5 9 10 11\n", "output": "6\n...
[ 0.000013942904938811189, 0.000013451159637237764, 0.000010470090676901226, 0.000009933498320039336, 0.00000966085772235577, 0.000009454534678212412, 0.000009322782178758742, 0.000008995675726617133, 0.00000896500511958652, 0.000008800190723339163, 0.000008146308825939686, 0.0000080594362707604...
977_F. Consecutive Subsequence
952
952_163
You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence ...
n = int(input()) a = [*map(int, input().split())] c = [None] * n whereIs = [None] * n for i in range(0, n): c[i] = i c.sort(key=lambda value:a[value]) tot = 0 for i in range(0, n): if i == 0 or a[c[i]] != a[c[i - 1]]: whereIs[c[i]] = tot tot += 1 else : whereIs[c[i]] = whereIs[c[i - ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 10 9 8 7
O(nlogn)
0.000012
{ "public_tests": [ { "input": "4\n10 9 8 7\n", "output": "1\n1 \n" }, { "input": "6\n1 3 5 2 4 6\n", "output": "2\n1 4 \n" }, { "input": "7\n3 3 4 7 5 6 8\n", "output": "4\n2 3 5 6 \n" }, { "input": "9\n6 7 8 3 4 5 9 10 11\n", "output": "6\n...
[ 0.00003924830917995948, 0.000012367614448624216, 0.00001234948048558132, 0.000012294004592760908, 0.000005957069950557255, 0.0000056117540428321685, 0.0000014703209388791627, 0.0000011070826611235265, 0.0000010042154836530217, 9.83794763683406e-7, 9.49259766961986e-7, 7.581800155558815e-7, 7...
440_A. Forgotten Episode
2742
2742_57
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which epi...
n=int(input()) a=list(map(int,input().split())) ans=n*(n+1)//2 for elem in a: ans-=elem 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, ...
10 3 8 10 1 7 9 6 5 2
O(n)
0.000005
{ "public_tests": [ { "input": "10\n3 8 10 1 7 9 6 5 2\n", "output": " 4" } ], "private_tests": [ { "input": "5\n5 2 4 3\n", "output": " 1" }, { ...
[ 0.000015358449634376912, 0.000015134388275786715, 0.000007153714857408217, 0.000005607704682036714, 0.000005503736464707168, 0.000005355762743116259, 0.000005310716933457168, 0.0000052951315696022734, 0.0000052577013494318184, 0.000005246549442744755, 0.000005184596536276224, 0.000005157979813...
440_A. Forgotten Episode
2742
2742_0
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which epi...
import sys input=sys.stdin.buffer.readline n=int(input()) arr=list(map(int,input().split())) arr.sort() z=0 for i in range(0,n-1): if arr[i]==i+1: continue else: print(i+1) z=1 break if z==0: print(n)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
10 3 8 10 1 7 9 6 5 2
O(nlogn)
0.000028
{ "public_tests": [ { "input": "10\n3 8 10 1 7 9 6 5 2\n", "output": " 4" } ], "private_tests": [ { "input": "5\n5 2 4 3\n", "output": " 1" }, { ...
[ 0.00003491140133207488, 0.000034559876205679625, 0.000029809394982617914, 0.00002919053172348522, 0.000028641317826468074, 0.000028593535634471814, 0.000028560474676561686, 0.000028548746279343998, 0.00002849626864807941, 0.000028472883143425632, 0.000028411136616523547, 0.00002839486964897925...
47_A. Triangular numbers
1948
1948_38
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with n dots on a side. <image>. You can learn more about these numbers...
a = int(input()) n = 1 while 2*a>n**2+n: n +=1 if (2*a)-(n**2+n)==0: 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, ...
2
O(n)
0
{ "public_tests": [ { "input": "2\n", "output": "NO\n" }, { "input": "3\n", "output": "YES\n" }, { "input": "1\n", "output": "YES\n" } ], "private_tests": [ { "input": "474\n", "output": "NO\n" }, { "input": "232\n", "...
[ 0.000002674548459353147, 0.0000025543028436407344, 0.00000204661052229021, 0.0000020450519285402095, 0.0000020165021989729023, 0.0000019995282451923078, 0.0000019956153982736015, 0.0000019798545809659092, 0.000001945556381118881, 0.0000014987761145104897, 0.0000014386942061844406, 0.0000014058...
47_A. Triangular numbers
1948
1948_388
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with n dots on a side. <image>. You can learn more about these numbers...
from math import sqrt k=int(input()) n=(sqrt(8*k+1)-1)/2 if n>int(n): 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, ...
2
O(1)
0.000001
{ "public_tests": [ { "input": "2\n", "output": "NO\n" }, { "input": "3\n", "output": "YES\n" }, { "input": "1\n", "output": "YES\n" } ], "private_tests": [ { "input": "474\n", "output": "NO\n" }, { "input": "232\n", "...
[ 0.0026150224999999944, 0.0002433754999999994, 0.0001420265, 0.00009256800000000001, 0.00008720250000000004, 0.00008444, 0.00006074250000000052, 0.00003875000000000001, 0.00002909599999999994, 0.00002733949999999993, 0.000019371000000000015, 0.000018694000000000008, 0.000014937499999999977, ...
441_B. Valera and Fruits
2423
2423_56
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,...
n, v = map(int, input().split()) l = [0]*(3010) ans = 0 for i in range(n): a, b = map(int, input().split()) l[a] += b day = 1 for i in range(3004): temp = min(v, l[day-1]) ans += temp l[day-1] -= temp rem = v - temp temp2 = min(rem, l[day]) ans+=temp2 l[day]-=temp2 day+=1 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, ...
5 10 3 20 2 20 1 20 4 20 5 20
O(n)
0.000018
{ "public_tests": [ { "input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n", "output": "60\n" }, { "input": "2 3\n1 5\n2 3\n", "output": "8\n" } ], "private_tests": [ { "input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426\n", "output": "4740\n" }, { ...
[ 0.00002312302023085623, 0.000022517374947120625, 0.000022477950634408576, 0.000022330762024121627, 0.000021421858332206197, 0.000021167196268575173, 0.000020996346261320503, 0.000020885329066531603, 0.000020817368639007277, 0.000020701139141095114, 0.0000206294173829963, 0.00002041351114711545...
441_B. Valera and Fruits
2423
2423_48
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,...
def a(): n, v = list(map(int, input().split(" "))) d = [] for i in range(n): d.append(list(map(int, input().split(" ")))) d.sort() cur = 0 nex = 0 k = 0 r = 0 for i in range(d[-1][0] + 2): nex = 0 p = v if k != n: while(d[k][0] < i): k += 1 if k == n: break if k != n: while(d[k][...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 10 3 20 2 20 1 20 4 20 5 20
O(nlogn)
0.000019
{ "public_tests": [ { "input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n", "output": "60\n" }, { "input": "2 3\n1 5\n2 3\n", "output": "8\n" } ], "private_tests": [ { "input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426\n", "output": "4740\n" }, { ...
[ 0.0004376516543643172, 0.00015186928298737516, 0.0000235377282855096, 0.000023232672332073824, 0.000020735926732376193, 0.000020137522500060563, 0.00001967978290923508, 0.00001967457207912073, 0.000019475998598496414, 0.00001911640632423758, 0.000019070004236424273, 0.000018844036044721754, ...
416_A. Guess a number!
1878
1878_29
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions: * Is it true that y is stric...
u, v = -2000000000, 2000000000 for i in range(int(input())): a, b, c = input().split() k = int(b) if a == '>=': if c == 'Y': u = max(u, k) else: v = min(v, k - 1) elif a == '>': if c == 'Y': u = max(u, k + 1) else: v = min(v, k) elif a == '<=': if c == 'Y': v ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 &gt;= 1 Y &lt; 3 N &lt;= -3 N &gt; 55 N
O(n)
0.000012
{ "public_tests": [ { "input": "4\n&gt;= 1 Y\n&lt; 3 N\n&lt;= -3 N\n&gt; 55 N\n", "output": "-2000000000\n" }, { "input": "2\n&gt; 100 Y\n&lt; -100 Y\n", "output": "-2000000000\n" } ], "private_tests": [ { "input": "1\n<= -999999999 Y\n", "output": "-2000000...
[ 0.000021246540373939896, 0.00002075167992368104, 0.000018397544146721192, 0.000017565588412870622, 0.00001747038724391276, 0.00001695332184328137, 0.00001586698013462297, 0.000015749118337558886, 0.00001566481465312571, 0.000015607319883507105, 0.000015587435210898768, 0.000015336301439757802,...
416_A. Guess a number!
1878
1878_72
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions: * Is it true that y is stric...
n = int(input()) l = [] less = [] grt = [] for i in range(n): l = [x for x in input().split()] if l[2] == 'N': l[2] = 'Y' if l[0] == '>=': l[0] = '<' elif l[0] == '>': l[0] = '<=' elif l[0] == '<': l[0] = '>=' else: l[0] = '>' if (l[0] == "<" or l[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, ...
4 &gt;= 1 Y &lt; 3 N &lt;= -3 N &gt; 55 N
O(nlogn)
0.000011
{ "public_tests": [ { "input": "4\n&gt;= 1 Y\n&lt; 3 N\n&lt;= -3 N\n&gt; 55 N\n", "output": "-2000000000\n" }, { "input": "2\n&gt; 100 Y\n&lt; -100 Y\n", "output": "-2000000000\n" } ], "private_tests": [ { "input": "1\n<= -999999999 Y\n", "output": "-2000000...
[ 0.000013161952439890294, 0.000013058144675083241, 0.000012975122700286916, 0.000011677041794128735, 0.000011416643102371587, 0.000010997484291589089, 0.000010995505164192248, 0.000010742506962810334, 0.000010721002539695357, 0.000010181962626155072, 0.00001011969887679898, 0.000010088692568685...
330_B. Road Construction
698
698_43
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two r...
impassable = [] n,m = map(int,input().split()) for i in range(m): impassable.extend(list(map(int, input().split()))) center_candidates = [x for x in range(1,n+1) if x not in impassable] center = center_candidates[-1] # min number of roads print(n-1) for x in range(1,n+1): if x!=center: print (center, 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 1 1 3
O(n**2)
0.000009
{ "public_tests": [ { "input": "4 1\n1 3\n", "output": "3\n2 1\n2 3\n2 4\n" } ], "private_tests": [ { "input": "3 1\n1 2\n", "output": "2\n3 1\n3 2\n" }, { "input": "34 7\n10 28\n10 19\n10 13\n24 10\n10 29\n20 10\n10 26\n", "output": "33\n1 2\n1 3\n1 4\n1 5\...
[ 0.00003059167479785839, 0.000012512605837521853, 0.000012267173432036715, 0.00000999272529228584, 0.000009584607654064685, 0.00000904658950229458, 0.000008963246749344405, 0.00000889881280048077, 0.000008828625177556819, 0.000008822851193728149, 0.000008790809099104022, 0.000008778359702797204...
330_B. Road Construction
698
698_155
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two r...
func = lambda: map(int, input().split()) n, m = func() a = set(range(1, n+1)) for _ in range(m): a-=set(func()) a = list(a)[0] print(n-1) for i in range(1, n+1): if i!=a: print(i, 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, ...
4 1 1 3
O(n)
0.000009
{ "public_tests": [ { "input": "4 1\n1 3\n", "output": "3\n2 1\n2 3\n2 4\n" } ], "private_tests": [ { "input": "3 1\n1 2\n", "output": "2\n3 1\n3 2\n" }, { "input": "34 7\n10 28\n10 19\n10 13\n24 10\n10 29\n20 10\n10 26\n", "output": "33\n1 2\n1 3\n1 4\n1 5\...
[ 0.00001683108954326923, 0.00001564252432528409, 0.000014950814835555074, 0.000013115392687390736, 0.000012876268192744756, 0.000012608013794798952, 0.000012430747964925701, 0.00001199516945749563, 0.000011772804004589161, 0.000011693667914117133, 0.000011683490889969407, 0.00001155902653791521...
112_A. Petya and Strings
3060
3060_1359
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr...
a=input().lower() b=input().lower() c=0 while True: try: if a[c]==b[c]: c+=1 else: if a[c]<b[c]: print(-1) break else: print(1) break except IndexError: print(0) 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, ...
aaaa aaaA
O(n+m)
0
{ "public_tests": [ { "input": "aaaa\naaaA\n", "output": "0\n" }, { "input": "abs\nAbz\n", "output": "-1\n" }, { "input": "abcdefg\nAbCdEfF\n", "output": "1\n" } ], "private_tests": [ { "input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkP...
[ 0.000012106620629370628, 0.000010327556754314526, 0.00000931483937937063, 0.000008449153466728444, 0.000007240772522399476, 0.000007175160016576066, 0.000006711699187600184, 0.000006274869282193106, 0.000006205838504240423, 0.000005468101174425667, 0.0000053693532140585746, 0.00000527090556823...
112_A. Petya and Strings
3060
3060_6262
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr...
def sort(x, y): a=sorted(x+y) return a[-1] n=input().lower() m=input().lower() for i in range (0, len(n)): if n[i]==m[i]: if i==len(n)-1: print(0) continue else: if sort(n[i], m[i])==n[i]: print(1) break else: print(-1) ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
aaaa aaaA
O(nlogn)
0
{ "public_tests": [ { "input": "aaaa\naaaA\n", "output": "0\n" }, { "input": "abs\nAbz\n", "output": "-1\n" }, { "input": "abcdefg\nAbCdEfF\n", "output": "1\n" } ], "private_tests": [ { "input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkP...
[ 0.000018856385863749424, 0.0000026897089548158362, 0.0000017006122870051689, 0.0000015438448699737761, 0.0000014676024993862458, 0.0000012349033622901369, 0.0000011642121960798477, 0.000001141435301027098, 0.0000010681761244635057, 9.726781796084754e-7, 9.250156894626323e-7, 9.112497492880483e...
915_A. Garden
1563
1563_356
Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the gro...
n, k =map(int, input().split()) a = list(map(int, input().split())) m = 0 for i in a: if k % i == 0: m = max(m, i) print(k//m)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 6 2 3 5
O(n)
0.000002
{ "public_tests": [ { "input": "3 6\n2 3 5\n", "output": "2\n" }, { "input": "6 7\n1 2 3 4 5 6\n", "output": "7\n" } ], "private_tests": [ { "input": "3 7\n3 2 1\n", "output": "7\n" }, { "input": "4 97\n97 1 50 10\n", "output": "1\n" ...
[ 0.0003588038580774694, 0.000006180793460445804, 0.00000510425458916084, 0.000004782130121831294, 0.000004611302065122378, 0.000003902797189138986, 0.000003725539950284091, 0.000003556384629042833, 0.0000034320916056599654, 0.000003251925753933567, 0.0000029934684358610142, 0.000002900227218094...
915_A. Garden
1563
1563_497
Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the gro...
buckets, length = map(int,input().split()) data = list(map(int,input().split())) data.sort(reverse=True) for element in data: if length % element == 0: print(length // element) break
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 6 2 3 5
O(nlogn)
0.000008
{ "public_tests": [ { "input": "3 6\n2 3 5\n", "output": "2\n" }, { "input": "6 7\n1 2 3 4 5 6\n", "output": "7\n" } ], "private_tests": [ { "input": "3 7\n3 2 1\n", "output": "7\n" }, { "input": "4 97\n97 1 50 10\n", "output": "1\n" ...
[ 0.000014943221238944473, 0.000010410489626557086, 0.000010322517171102413, 0.000009752139691009385, 0.00000930259152886738, 0.000009054213837367955, 0.00000883639796366272, 0.000008644139703418237, 0.000008559345499029897, 0.000008445497360202093, 0.000008421651869343314, 0.0000082789830145373...
p02992 AtCoder Beginner Contest 132 - Small Products
1276
1276_39
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7. Constraints * 1\leq N\leq 10^9 * ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST) * N and K are integers. Input Input is given from Standard Input in the following forma...
mod=1000000007 n,k=map(int,input().split()) s=int(n**0.5) Num=[0]*(s+1) for i in range(s,0,-1): Num[i]=i Num.append(n//i) l=len(Num) for i in range(1,l): Num[-i]=Num[-i]-Num[-i-1] DP=[[0]*l for _ in range(k)] DP[0]=Num[:] for i in range(1,k): tmp=0 for j in range(1,l): tmp+=DP[i-1][j] ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
10 3
O(n*m)
0.001443
{ "public_tests": [ { "input": "10 3", "output": "147" }, { "input": "314159265 35", "output": "457397712" }, { "input": "3 2", "output": "5" } ], "private_tests": [], "generated_tests": [ { "input": "10 4", "output": "544" }, {...
[ 0.01442454583160721, 0.0075843486917021976, 0.005968074775804713, 0.003078030286807614, 0.001956658234398787, 0.0018201982171665869, 0.0017893190932432395, 0.0017140841480334627, 0.001637720779829002, 0.0016219006852188128, 0.0015825721899427035, 0.0015542735590507904, 0.0015152547443573752,...
p02992 AtCoder Beginner Contest 132 - Small Products
1276
1276_62
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7. Constraints * 1\leq N\leq 10^9 * ~~1~~ 2\leq K\leq 100 (fixed at 21:33 JST) * N and K are integers. Input Input is given from Standard Input in the following forma...
from itertools import accumulate def f(n,k): lim = int((n + 0.1) ** 0.5) + 1 ws = [] s = 0 for i in range(1, lim): w = n // i - n // (i + 1) ws.append(w) s += w ws += [1] * (n - s) dp=ws m = len(ws) for _ in range(k - 1): dp=[s*w%md for s,w in zip(accumul...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
10 3
O(n+m)
0.000468
{ "public_tests": [ { "input": "10 3", "output": "147" }, { "input": "314159265 35", "output": "457397712" }, { "input": "3 2", "output": "5" } ], "private_tests": [], "generated_tests": [ { "input": "10 4", "output": "544" }, {...
[ 0.000905337901171875, 0.0008839697523437503, 0.000872048222265625, 0.0008610688292968751, 0.0008607154015625, 0.0008601153390625, 0.000850063159375, 0.000847269737890625, 0.0008443984683593753, 0.0008359653250000001, 0.0008205561488281251, 0.0008017762402343752, 0.0007925346074218751, 0.00...
889_A. Petya and Catacombs
1367
1367_88
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ...
n = int(input()) a = list(map(int, input().split())) b = [0] * (n + 1) res = 1 b[1] = 1 for i in range(2, n + 1) : if b[a[i - 1]] == 0 : b[i] = 1 res += 1 else : b[i] = 1 b[a[i - 1]] = 0 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, ...
2 0 0
O(n**2)
0
{ "public_tests": [ { "input": "2\n0 0\n", "output": "2\n" }, { "input": "5\n0 1 0 1 3\n", "output": "3\n" } ], "private_tests": [ { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 ...
[ 4.674433741885986e-9, 3.7222363065936757e-9, 3.6868130413318e-9, 2.881188535974065e-9, 2.2568476086812942e-9, 1.9397364529299836e-9, 1.849012398662359e-9, 1.7849124883197626e-9, 1.781763327907659e-9, 1.7556848307009356e-9, 1.4077953499239168e-9, 1.3107245472698412e-9, 1.2277317773992334e-9, ...
889_A. Petya and Catacombs
1367
1367_59
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ...
n = int(input()) a = list(map(int, input().split())) di = {0 : 0} k = 1 q = 1 for i in a: if i in di: del di[i] else: q += 1 di[k] = i k += 1 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, ...
2 0 0
O(n)
0.000002
{ "public_tests": [ { "input": "2\n0 0\n", "output": "2\n" }, { "input": "5\n0 1 0 1 3\n", "output": "3\n" } ], "private_tests": [ { "input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 ...
[ 0.000005291608978911714, 0.0000034809289909309446, 0.000003308786289881993, 0.0000032448058894230768, 0.000002576898546765734, 0.0000025389125191215036, 0.0000022143750546328673, 0.0000022016960637019233, 0.000001939361191542832, 0.0000019230975743006994, 0.0000019169730250218534, 0.0000018707...
1043_C. Smallest Word
1913
1913_99
IA has so many colorful magnets on her fridge! Exactly one letter is written on each magnet, 'a' or 'b'. She loves to play with them, placing all magnets in a row. However, the girl is quickly bored and usually thinks how to make her entertainment more interesting. Today, when IA looked at the fridge, she noticed that...
s = input() b = 1 up = len(s)-1 out = [0]*len(s) while up > -1: if b == 1: if s[up] == 'b': out[up] = 0 else: out[up] = 1 b = (b+1)%2 else: if s[up] == 'a': out[up] = 0 else: out[up] = 1 b = (b+1)%2 up -=...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
bbab
O(n)
0.000005
{ "public_tests": [ { "input": "bbab\n", "output": "0 1 1 0\n" }, { "input": "aaaaa\n", "output": "0 0 0 0 1\n" } ], "private_tests": [ { "input": "ababbbaaababbbaaaabb\n", "output": "1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 0 0 1 0 0\n" }, { "input": "ab...
[ 0.000008816902439357519, 0.00000865172660347465, 0.00000853073179359703, 0.000008377307186953673, 0.00000816954004589161, 0.000007277242542613637, 0.0000072071741832386366, 0.000007156017769340035, 0.000006847022754589161, 0.000006789281755354021, 0.000006446403941761364, 0.0000061868498552229...
1043_C. Smallest Word
1913
1913_104
IA has so many colorful magnets on her fridge! Exactly one letter is written on each magnet, 'a' or 'b'. She loves to play with them, placing all magnets in a row. However, the girl is quickly bored and usually thinks how to make her entertainment more interesting. Today, when IA looked at the fridge, she noticed that...
s = input() ss = sorted(s) r = [0] * len(s) b_char = 'b' for i, c in enumerate(reversed(s)): if c != b_char: r[len(s)-i-1] = 1 b_char = 'a' if b_char == 'b' else 'b' print(" ".join([str(i) for i in r]))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
bbab
O(nlogn)
0.00001
{ "public_tests": [ { "input": "bbab\n", "output": "0 1 1 0\n" }, { "input": "aaaaa\n", "output": "0 0 0 0 1\n" } ], "private_tests": [ { "input": "ababbbaaababbbaaaabb\n", "output": "1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 0 0 1 0 0\n" }, { "input": "ab...
[ 0.000010771754397870915, 0.000010175450276277529, 0.000010117061294236071, 0.000002784408576512019, 0.0000027641925719127585, 0.0000026520962279242743, 0.0000025778715458330822, 0.0000024056422059100043, 0.0000022780775670201084, 0.0000020048971227247362, 0.000001790744096848086, 0.00000164318...
999_C. Alphabetic Removals
2725
2725_140
You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k ≤ n) from the string s. Polycarp uses the following algorithm k times: * if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * if th...
n,k=list(map(int,input().split())) a=list(input().strip()) count=[0]*26 aaa=ord('a') for i in a: count[ord(i)-aaa]+=1 deletables=-1 for i in range(26): if(count[i]>=k): count=k ele=i break deletables=i k-=count[i] ans="" for i in a: if(ord(i)-aaa<=deletables): continu...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
15 3 cccaabababaccbc
O(n)
0.000013
{ "public_tests": [ { "input": "15 3\ncccaabababaccbc\n", "output": "cccbbabaccbc\n" }, { "input": "1 1\nu\n", "output": "\n" }, { "input": "15 9\ncccaabababaccbc\n", "output": "cccccc\n" } ], "private_tests": [ { "input": "2 1\nzz\n", "o...
[ 0.000688796378125, 0.0006869316757812501, 0.0006800621766741071, 0.0006779767396205357, 0.0006769060662946429, 0.0006743894716517857, 0.0006724814064732144, 0.0006723633722098215, 0.0006719111931919644, 0.000668883244921875, 0.00065863624140625, 0.0006583749539062501, 0.00017740800000000002,...
999_C. Alphabetic Removals
2725
2725_319
You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k ≤ n) from the string s. Polycarp uses the following algorithm k times: * if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * if th...
n,k=list(map(int,input().split())) s=list(input()) x=sorted([j,i] for i,j in enumerate(s)) #print(x) for i in range(k): s[x[i][1]]='' 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, ...
15 3 cccaabababaccbc
O(nlogn)
0.000049
{ "public_tests": [ { "input": "15 3\ncccaabababaccbc\n", "output": "cccbbabaccbc\n" }, { "input": "1 1\nu\n", "output": "\n" }, { "input": "15 9\ncccaabababaccbc\n", "output": "cccccc\n" } ], "private_tests": [ { "input": "2 1\nzz\n", "o...
[ 0.016291663999999997, 0.0162486235, 0.0006825088011718751, 0.0006709007953125002, 0.0002843235, 0.000216139, 0.00021255700000000002, 0.000211194, 0.00021103750000000003, 0.00021067450000000003, 0.000182741, 0.00017463450000000002, 0.00017451250000000002, 0.000173401, 0.0001717875, 0.00...
450_A. Jzzhu and Children
2992
2992_87
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies. Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. ...
import math n,m = map(int,input().split()) a = list(map(int,input().split())) cc = math.ceil(a[0]/m) for i in range (len(a)): if( math.ceil(a[i]/m) >= cc ): x=i+1 cc = math.ceil(a[i]/m) 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, ...
5 2 1 3 1 4 2
O(n)
0.000007
{ "public_tests": [ { "input": "5 2\n1 3 1 4 2\n", "output": "4\n" }, { "input": "6 4\n1 1 2 2 3 3\n", "output": "6\n" } ], "private_tests": [ { "input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7...
[ 0.13466839342372883, 0.13260844923728815, 0.13223367842372882, 0.1281574761525424, 0.12647457966101697, 0.1254497842542373, 0.12543758838983052, 0.12430496622033899, 0.12412860194915254, 0.12282763742372882, 0.12205515986440679, 0.12151951086440678, 0.12038306774576273, 0.11982571979661018...
450_A. Jzzhu and Children
2992
2992_153
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies. Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. ...
import math n = input().split() a = int(n[0]) b = int(n[1]) c = [] t = input().split() for i in range(a): c.append([int(t[i]),0,int(i)]) c[i][1] = math.ceil(c[i][0] / b) c.sort(key = lambda x:(x[1],x[2])) print(c[-1][2]+1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 2 1 3 1 4 2
O(nlogn)
0.000014
{ "public_tests": [ { "input": "5 2\n1 3 1 4 2\n", "output": "4\n" }, { "input": "6 4\n1 1 2 2 3 3\n", "output": "6\n" } ], "private_tests": [ { "input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7...
[ 0.016610002341324433, 0.0022737779504669, 0.0015082401091357602, 0.0014782421376645432, 0.0005956653269178129, 0.0001224657692099606, 0.00009388560838431802, 0.0000926170569684159, 0.00009242180439798964, 0.00009186801658730406, 0.00009111360576893391, 0.00007304417183277743, 0.0000533964123...
1385_A. Three Pairwise Maximums
276
276_1206
You are given three positive (i.e. strictly greater than zero) integers x, y and z. Your task is to find positive integers a, b and c such that x = max(a, b), y = max(a, c) and z = max(b, c), or determine that it is impossible to find such a, b and c. You have to answer t independent test cases. Print required a, b a...
for i in range(int(input())): ls=[int(a) for a in input().split()] ls1=[1]*3 if ls.count(max(ls))>1: if ls.count(max(ls))==3: ls1=ls else: ls1[ls.index(min(ls))]=min(ls) ls1[ls.index(min(ls))-1]=max(ls) print("YES") for _ ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 2 3 100 100 100 50 49 49 10 30 20 1 1000000000 1000000000
O(n*m)
0.000007
{ "public_tests": [ { "input": "5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000\n", "output": "YES\n3 2 2\nYES\n100 100 100\nNO\nNO\nYES\n1000000000 1 1\n" } ], "private_tests": [ { "input": "1\n127869 127869 127869\n", "output": "YES\n127869 127869 127869\n"...
[ 0.0005296936309988839, 0.0003438888299479167, 0.00033939079540719694, 0.0003376513893229167, 0.000046653647010216354, 0.000046420485344733397, 0.000026274764464051577, 0.000025707187240493885, 0.00002516953716400787, 0.000022918314767263987, 0.000022474916507320807, 0.0000216197634260271, 0....
1385_A. Three Pairwise Maximums
276
276_610
You are given three positive (i.e. strictly greater than zero) integers x, y and z. Your task is to find positive integers a, b and c such that x = max(a, b), y = max(a, c) and z = max(b, c), or determine that it is impossible to find such a, b and c. You have to answer t independent test cases. Print required a, b a...
t = int(input()) for _ in range(t): x, y, z = map(int, input().split()) if(x != y and y != z and x!= z): print("NO") elif(x == y and x != z and x == min(x, z)): print("NO") elif(y == z and y != x and y == min(y, x)): print("NO") elif(x == z and x != y and x == min(y, z)): 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, ...
5 3 2 3 100 100 100 50 49 49 10 30 20 1 1000000000 1000000000
O(n)
0
{ "public_tests": [ { "input": "5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000\n", "output": "YES\n3 2 2\nYES\n100 100 100\nNO\nNO\nYES\n1000000000 1 1\n" } ], "private_tests": [ { "input": "1\n127869 127869 127869\n", "output": "YES\n127869 127869 127869\n"...
[ 0.0008585844449218752, 0.0003737982666429924, 0.00034990875928030303, 0.000237426014491368, 0.00022379865853092224, 0.00020165665145596595, 0.00017851571424278847, 0.00017219687577851837, 0.00017036398429305072, 0.0001617962748989292, 0.00012936509422803758, 0.00011984562068400349, 0.0001191...
799_A. Carrot Cakes
2773
2773_68
In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can bui...
n,t,k,d = list(map(int,input().split())) fi = ((n+k-1)//k) * t t1 = 0 t2 = d while n > 0: n -= k t1 += t if n <= 0: break if t1 > d: n-=k t2+=t if n <= 0: break if t1 < fi or (t2 < fi and t2 != d): 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, ...
10 3 11 4
O(n)
0
{ "public_tests": [ { "input": "10 3 11 4\n", "output": "NO\n" }, { "input": "4 2 1 4\n", "output": "YES\n" }, { "input": "8 6 4 6\n", "output": "NO\n" }, { "input": "8 6 4 5\n", "output": "YES\n" } ], "private_tests": [ { "...
[ 0.0026400015, 0.000007250927447552449, 0.0000022307497951267487, 0.000002065891949847028, 0.0000020359720143138113, 0.00000162793962385271, 0.0000013868490903627622, 8.709273246284966e-7, 6.979900021853148e-7, 6.872610904720279e-7, 5.19066911604021e-7, 5.16985891062063e-7, 5.070402234484265e...
799_A. Carrot Cakes
2773
2773_120
In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can bui...
from math import* n,t,k,d=map(int,input().split()) c1=ceil(n/k)*t if c1-t>d: 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, ...
10 3 11 4
O(1)
0.000002
{ "public_tests": [ { "input": "10 3 11 4\n", "output": "NO\n" }, { "input": "4 2 1 4\n", "output": "YES\n" }, { "input": "8 6 4 6\n", "output": "NO\n" }, { "input": "8 6 4 5\n", "output": "YES\n" } ], "private_tests": [ { "...
[ 0.0615530345, 0.06090905900000001, 0.0604093215, 0.060276684500000004, 0.059659631500000004, 0.059557027000000005, 0.0589941875, 0.05478160950000001, 0.0518509305, 0.051032682999999995, 0.049843094, 0.049735745000000005, 0.049311755, 0.0486442905, 0.048510499500000005, 0.04698888200000...
1095_D. Circular Dance
2007
2007_136
There are n kids, numbered from 1 to n, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as p_1, p_2, ..., p_n (all these numbers are from 1 to n and are distinct, so p is a permutation). Let the next kid for a kid p_i be kid p_{i + 1} if i < n and p_1 otherwise. After the da...
n=int(input()) l=[] a,b=0,0 for i in range(n): s=list(map(int,input().split(" "))) a=int(s[0]) b=int(s[1]) l.append([a,b]) ans=[1] a,b=l[0][0],l[0][1] if b in l[a-1]: ans.append(a) ans.append(b) i=a j=b else: ans.append(b) ans.append(a) i=b j=a while len(ans)<n: for c...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 3 5 1 4 2 4 1 5 2 3
O(n*m)
0.000002
{ "public_tests": [ { "input": "5\n3 5\n1 4\n2 4\n1 5\n2 3\n", "output": "1 5 3 2 4 " }, { "input": "3\n2 3\n3 1\n1 2\n", "output": "1 2 3\n" } ], "private_tests": [ { "input": "3\n3 2\n1 3\n1 2\n", "output": "1 3 2 " }, { "input": "3\n2 3\n3 1...
[ 0.0000035798278791520983, 0.00000351679564576049, 0.0000025986199464597904, 0.0000025629620301573427, 0.000002500608473557692, 0.0000024954388658216784, 0.0000024841260926573427, 0.000002480695940777972, 0.0000023703927283653847, 0.000002367416097574301, 0.00000225942106916521, 0.0000022447631...
1095_D. Circular Dance
2007
2007_4
There are n kids, numbered from 1 to n, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as p_1, p_2, ..., p_n (all these numbers are from 1 to n and are distinct, so p is a permutation). Let the next kid for a kid p_i be kid p_{i + 1} if i < n and p_1 otherwise. After the da...
n = int(input()) if n == 3: print(3, 2, 1) exit() d = [] d.append([0, 0]) for i in range(n): x, y = map(int, input().split()) d.append([x, y]) x = 1 ans = [] ans.append(1) while True: t = d[x][0] if d[t][0] == d[x][1] or d[t][1] == d[x][1]: ans.append(t) ans.append(d[x][1]) ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 3 5 1 4 2 4 1 5 2 3
O(n)
0
{ "public_tests": [ { "input": "5\n3 5\n1 4\n2 4\n1 5\n2 3\n", "output": "1 5 3 2 4 " }, { "input": "3\n2 3\n3 1\n1 2\n", "output": "1 2 3\n" } ], "private_tests": [ { "input": "3\n3 2\n1 3\n1 2\n", "output": "1 3 2 " }, { "input": "3\n2 3\n3 1...
[ 0.000043909386568509614, 0.00003284453144121504, 0.00003264512006938375, 0.000031623704108391606, 0.0000309740586756993, 0.000030878913871284967, 0.000028819724459134616, 0.000028432048869099656, 0.000028147407574847034, 0.000027548502499453676, 0.000027385317048186193, 0.000027184045509178324...
579_A. Raising Bacteria
945
945_255
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimu...
n = int(input()) bacteria = 0 while True: if n == 1: bacteria += 1 break else: bacteria += n%2 n = n//2 print(bacteria)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
8
O(logn)
0.000002
{ "public_tests": [ { "input": "8\n", "output": "1\n" }, { "input": "5\n", "output": "2\n" } ], "private_tests": [ { "input": "343000816\n", "output": "14\n" }, { "input": "999999993\n", "output": "19\n" }, { "input": "69768...
[ 0.000055213460469013764, 0.000014361960639357433, 0.00001308422984718146, 0.000013038692886067296, 0.00001147322349682364, 0.000011250397459725538, 0.000011206145612644908, 0.000010945518830115744, 0.000010779566133676747, 0.000010772364714188544, 0.000010352005102034663, 0.0000097171867773428...
579_A. Raising Bacteria
945
945_880
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimu...
is_debug = False x = int(input()) print(f'{bin(x).count("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, ...
8
O(1)
0.000001
{ "public_tests": [ { "input": "8\n", "output": "1\n" }, { "input": "5\n", "output": "2\n" } ], "private_tests": [ { "input": "343000816\n", "output": "14\n" }, { "input": "999999993\n", "output": "19\n" }, { "input": "69768...
[ 0.0015226300000000005, 0.0005532115, 0.00046929050000000004, 0.00046336550000000004, 0.0003858155, 0.000375135, 0.0003711745, 0.00032802, 0.00031768900000000007, 0.000315553, 0.0003045095, 0.00030241150000000005, 0.0002345565, 0.000234035, 0.00023173500000000006, 0.00021467100000000005...
797_A. k-Factorization
310
310_121
Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n. Input The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20). Output If it's impossible to find the representation of n as a product of k...
n, k = [int(x) for x in input().split()] sols = [] curr_div = 2 while n != 1 and len(sols) < k-1: if n % curr_div == 0: sols.append(curr_div) n //= curr_div else: curr_div += 1 if len(sols) == k-1 and n != 1: sols += [n] sols = [str(x) for x in sols] res = " ".join(sols) ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
1024 5
O(logn)
0.000001
{ "public_tests": [ { "input": "1024 5\n", "output": "2 2 2 2 64\n" }, { "input": "100000 2\n", "output": "2 50000\n" }, { "input": "100000 20\n", "output": "-1\n" } ], "private_tests": [ { "input": "15 6\n", "output": "-1\n" }, {...
[ 0.00006098598726952621, 0.000028036507283239775, 0.000023993000000000012, 0.000020901500000000003, 0.000015062087823221285, 0.000014480948900240648, 0.000007631129567761261, 0.000006350952488807, 0.000005192655319066734, 0.000004933885455942386, 0.000004598218041518203, 0.000004428881805535511...
797_A. k-Factorization
310
310_51
Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n. Input The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20). Output If it's impossible to find the representation of n as a product of k...
n, k=map(int, input().split()) h=n t="" f=0 i=2 while k!=f+1 and i<=n/2: if h%i==0: f+=1 t+="{} ".format(i) h=int(h/i) else: i+=1 if k>f+1 or h==1: print(-1) else: print(t+"{}".format(h))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
1024 5
O(n)
0.000163
{ "public_tests": [ { "input": "1024 5\n", "output": "2 2 2 2 64\n" }, { "input": "100000 2\n", "output": "2 50000\n" }, { "input": "100000 20\n", "output": "-1\n" } ], "private_tests": [ { "input": "15 6\n", "output": "-1\n" }, {...
[ 0.0026490979353927385, 0.0008295673214843751, 0.00077636935859375, 0.0006351844222522152, 0.0005941985035714286, 0.0003737322439630682, 0.00035192162213541664, 0.00035029114273200755, 0.000349379038375947, 0.00034913422945075757, 0.0003488007010890151, 0.00034742843151041675, 0.0002956025480...
p03072 AtCoder Beginner Contest 124 - Great Ocean View
1741
1741_12
There are N mountains ranging from east to west, and an ocean to the west. At the top of each mountain, there is an inn. You have decided to choose where to stay from these inns. The height of the i-th mountain from the west is H_i. You can certainly see the ocean from the inn at the top of the westmost mountain. F...
n = int(input()) h = list(map(int,input().split())) c = 0 for i in range(n): if h[i]>=max(h[:i+1]): c+=1 print(c)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 6 5 6 8
O(n**2)
0
{ "public_tests": [ { "input": "4\n6 5 6 8", "output": "3" }, { "input": "5\n9 5 6 8 4", "output": "1" }, { "input": "5\n4 5 3 5 4", "output": "3" } ], "private_tests": [], "generated_tests": [ { "input": "4\n6 5 5 8", "output": "2\n" ...
[ 8.786985435117245e-8, 8.772393430245597e-8, 8.687465607325121e-8, 8.620955400568228e-8, 7.221394164870959e-8, 6.970357172763344e-8, 6.940193620629696e-8, 6.909432452557516e-8, 6.905244642678673e-8, 6.888554067585955e-8, 6.876283923002194e-8, 6.870823691817599e-8, 6.863829862246591e-8, 6.86...
p03072 AtCoder Beginner Contest 124 - Great Ocean View
1741
1741_55
There are N mountains ranging from east to west, and an ocean to the west. At the top of each mountain, there is an inn. You have decided to choose where to stay from these inns. The height of the i-th mountain from the west is H_i. You can certainly see the ocean from the inn at the top of the westmost mountain. F...
n=int(input()) l=map(int,input().split()) m=c=0 for i in l: if m<=i: m=i c+=1 print(c)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 6 5 6 8
O(n)
0.000002
{ "public_tests": [ { "input": "4\n6 5 6 8", "output": "3" }, { "input": "5\n9 5 6 8 4", "output": "1" }, { "input": "5\n4 5 3 5 4", "output": "3" } ], "private_tests": [], "generated_tests": [ { "input": "4\n6 5 5 8", "output": "2\n" ...
[ 0.000005155380244755244, 0.0000039508781140734265, 0.000003913131146197553, 0.000003873862543706295, 0.000003818252171656469, 0.000003807831717111014, 0.0000037976237297858393, 0.000003782082400021854, 0.0000037618555916739522, 0.0000037602060478583917, 0.0000037475347465034973, 0.000003741780...
937_A. Olympiad
1099
1099_403
The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a dip...
a=int(input()) b=list(map(int, input().split())) x=[] for i in b: if i!=0: x. append(i) print(len(set(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 42 0 0 42
O(n)
0.000003
{ "public_tests": [ { "input": "4\n42 0 0 42\n", "output": "1\n" }, { "input": "4\n1 3 3 2\n", "output": "3\n" }, { "input": "3\n1 1 1\n", "output": "1\n" } ], "private_tests": [ { "input": "4\n1 1 1 2\n", "output": "2\n" }, { ...
[ 0.00017164138374125873, 0.000012521878974541083, 0.000005025129780375875, 0.000004869156659746504, 0.000004429603310751749, 0.00000401193902972028, 0.000003975426272945804, 0.000003948202401114511, 0.000003947916712194056, 0.000003903324860686189, 0.000003893334230222902, 0.0000038513383959790...
937_A. Olympiad
1099
1099_169
The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a dip...
n = int(input()) a = list(map(int, input().split())) a.sort() if (a[0]!=0): res = 1 else: res = 0 b = a[0] for i in range(len(a)): if (a[i]!=b): res+=1 b = a[i] print(str(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, ...
4 42 0 0 42
O(nlogn)
0.000011
{ "public_tests": [ { "input": "4\n42 0 0 42\n", "output": "1\n" }, { "input": "4\n1 3 3 2\n", "output": "3\n" }, { "input": "3\n1 1 1\n", "output": "1\n" } ], "private_tests": [ { "input": "4\n1 1 1 2\n", "output": "2\n" }, { ...
[ 0.000018229984281944508, 0.00001224884864083337, 0.00001203482327716297, 0.000012015881826295825, 0.000011938584305252423, 0.000011907488849975443, 0.000011905283342178046, 0.000011894569003379419, 0.000011885623670871522, 0.000011878025999284842, 0.00001184275446075078, 0.00001184229097940235...
877_B. Nikita and string
1952
1952_87
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
s=input() n=len(s) counta=[0]*(n+1) countb=[0]*(n+1) ans=0 curra=0 currb=0 for i in range(n): if s[i]=='a': curra+=1 else: currb+=1 counta[i+1]=curra countb[i+1]=currb for i in range(n+1): for j in range(i,n+1): ans=max(ans,countb[j]-countb[i]+counta[i]+counta[n]-counta[j]) 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, ...
bab
O(n**2)
0.000005
{ "public_tests": [ { "input": "bab\n", "output": "2\n" }, { "input": "abba\n", "output": "4\n" } ], "private_tests": [ { "input": "ba\n", "output": "2\n" }, { "input": "aaa\n", "output": "3\n" }, { "input": "babbbaab\n", ...
[ 0.000012444561014480192, 0.000010655736738439295, 0.000009173419020316278, 0.000009083682065571102, 0.000008546253322774062, 0.000008193508872470316, 0.0000075373224532034106, 0.000007377731506109065, 0.00000726872875587095, 0.000007256653534945938, 0.000006754172572629657, 0.00000665992563301...
877_B. Nikita and string
1952
1952_22
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make...
s=input() x1=0 x2=0 x3=0 for i in range (len(s)): if s[i]=='a': x3=max(x2, x3)+1 x1+=1 else: x2=max(x1, x2)+1 x4=max(x1, x2) x5=max(x3, x4) print(x5)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
bab
O(n)
0.000002
{ "public_tests": [ { "input": "bab\n", "output": "2\n" }, { "input": "abba\n", "output": "4\n" } ], "private_tests": [ { "input": "ba\n", "output": "2\n" }, { "input": "aaa\n", "output": "3\n" }, { "input": "babbbaab\n", ...
[ 0.000020004233965253496, 0.000018339596577250875, 0.0000157964373361014, 0.00001544202819055944, 0.000013645078302556819, 0.000012896685714285717, 0.00001204843441324301, 0.000010958657083151225, 0.00001091243657124126, 0.00001030029763986014, 0.000009648545017482518, 0.000009603174743225524, ...
1003_A. Polycarp's Pockets
976
976_656
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ...
charNum = int(input()) numArray = input().split() b = 0 for x in numArray: if numArray.count(x) > b: b = numArray.count(x) 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, ...
6 1 2 4 3 3 2
O(n**2)
0
{ "public_tests": [ { "input": "6\n1 2 4 3 3 2\n", "output": "2\n" }, { "input": "1\n100\n", "output": "1\n" } ], "private_tests": [ { "input": "3\n58 59 58\n", "output": "2\n" }, { "input": "3\n1 1 1\n", "output": "3\n" }, { ...
[ 0.0025284463080886437, 0.00043999209522772436, 0.000362288134752467, 0.00028794203254779287, 0.0002667706476032335, 0.00026583023636719437, 0.00023670290946476002, 0.00023486622738849285, 0.00023205206044220106, 0.00023137141640167027, 0.0002150671764545065, 0.00013742742366233175, 0.0001373...
1003_A. Polycarp's Pockets
976
976_1131
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ...
n = int(input()) arr = list(map(int, input().split())) d = dict() for a in arr: if not a in d: d[a] = 0 d[a] += 1 maxn = 0 for a in d: maxn = max(maxn, d[a]) print(maxn)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 4 3 3 2
O(n)
0.000003
{ "public_tests": [ { "input": "6\n1 2 4 3 3 2\n", "output": "2\n" }, { "input": "1\n100\n", "output": "1\n" } ], "private_tests": [ { "input": "3\n58 59 58\n", "output": "2\n" }, { "input": "3\n1 1 1\n", "output": "3\n" }, { ...
[ 0.00011359099269285403, 0.00006577476253061248, 0.00006327433696186626, 0.000030427446118334794, 0.000021243027903736887, 0.000013880008509069056, 0.000009871267107735785, 0.000009628473680616261, 0.000008602608593750003, 0.000007926059375000002, 0.000007902816796875, 0.000007791985937500001, ...
611_B. New Year and Old Property
1364
1364_161
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510 = 111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak...
ans = 0 a, b = map(int, input().split()) l = 2 pos = l-2 ans = 0 while True: n = ((1 << l) - 1) - (1 << pos) #print(l, pos, n) if n > b: break if n >= a: ans += 1 if pos > 0: pos -= 1 else: l += 1 pos = l-2 print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
72057594000000000 72057595000000000
O(logn)
0.000066
{ "public_tests": [ { "input": "72057594000000000 72057595000000000\n", "output": "26\n" }, { "input": "100 105\n", "output": "0\n" }, { "input": "5 10\n", "output": "2\n" }, { "input": "2015 2015\n", "output": "1\n" } ], "private_tes...
[ 0.012344017147943842, 0.008296537661997148, 0.007665257420603931, 0.00637581867848182, 0.004309717527133612, 0.0017531194405533495, 0.001293450083526274, 0.00041185949099379243, 0.00028642269501094695, 0.0002832636200252395, 0.00023921219199102972, 0.00022385750569105058, 0.00020917621037284...
611_B. New Year and Old Property
1364
1364_163
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510 = 111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak...
def z(n): n = bin(n)[2:] k = len(n) s = (k-1) * (k-2) // 2 + (n.count("0") == 1) r = n.find("0") s += k if r == -1 else r return s - 1; a, b = map(int, input().split()); print (z(b) - z(a - 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, ...
72057594000000000 72057595000000000
O(1)
0.000002
{ "public_tests": [ { "input": "72057594000000000 72057595000000000\n", "output": "26\n" }, { "input": "100 105\n", "output": "0\n" }, { "input": "5 10\n", "output": "2\n" }, { "input": "2015 2015\n", "output": "1\n" } ], "private_tes...
[ 0.002572777999999998, 0.0022523394999999996, 0.0021496100000000006, 0.0021345519999999996, 0.0021084554999999997, 0.002096886, 0.0020899789999999996, 0.001819467500000005, 0.001524317000000025, 0.001432602499999991, 0.0013286605, 0.0012304185000000245, 0.0010031555, 0.0009946035000000008, ...
1400_A. String Similarity
2235
2235_430
A binary string is a string where each character is either 0 or 1. Two binary strings a and b of equal length are similar, if they have the same character in some position (there exists an integer i such that a_i = b_i). For example: * 10010 and 01111 are similar (they have the same character in position 4); * 10...
#Written by Shagoto t = int(input()) for x in range(t): n = int(input()) s = input() if(n == 1): print(s) else: for i in range(0, len(s), 2): print(s[i], end = "") print()
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 1 3 00000 4 1110000 2 101
O(n**2)
0.000021
{ "public_tests": [ { "input": "4\n1\n1\n3\n00000\n4\n1110000\n2\n101\n", "output": "1\n000\n1100\n11\n" } ], "private_tests": [ { "input": "4\n1\n1\n3\n00000\n4\n1110000\n2\n101\n", "output": "1\n000\n1100\n11\n" }, { "input": "1\n7\n0000000000001\n", "outp...
[ 0.1310561345, 0.12494260550000001, 0.1162225005, 0.1158752655, 0.0000798842485287304, 0.00007660194572490065, 0.00006438677070928864, 0.00005632091772976986, 0.00005233839869175715, 0.000050319783394582274, 0.000048621409543899235, 0.000048280688522514385, 0.00004814420511728429, 0.0000442...
1400_A. String Similarity
2235
2235_384
A binary string is a string where each character is either 0 or 1. Two binary strings a and b of equal length are similar, if they have the same character in some position (there exists an integer i such that a_i = b_i). For example: * 10010 and 01111 are similar (they have the same character in position 4); * 10...
#872 for _ in range(int(input())): n=int(input()) a=input() print(a[::2])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 1 3 00000 4 1110000 2 101
O(n)
0.000015
{ "public_tests": [ { "input": "4\n1\n1\n3\n00000\n4\n1110000\n2\n101\n", "output": "1\n000\n1100\n11\n" } ], "private_tests": [ { "input": "4\n1\n1\n3\n00000\n4\n1110000\n2\n101\n", "output": "1\n000\n1100\n11\n" }, { "input": "1\n7\n0000000000001\n", "outp...
[ 0.111741317, 0.11160979, 0.09526332500000001, 0.0003851540326431381, 0.00010530243786709796, 0.00009867026038809863, 0.00009104745534103237, 0.00008772345092650414, 0.00008349083033995321, 0.00008340331586611374, 0.00006967093182805786, 0.0000681977620097327, 0.00006798896813136532, 0.0000...
1092_A. Uniform String
2254
2254_143
You are given two integers n and k. Your task is to construct such a string s of length n that for each i from 1 to k there is at least one i-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters except these. You have to maximize the minim...
for i in range(int(input())): n,k=map(int,input().split()) s="" x=0 for i in range(0,n): s=s+chr(x+97) x+=1 x=x%k 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, ...
3 7 3 4 4 6 2
O(n**2)
0.000002
{ "public_tests": [ { "input": "3\n7 3\n4 4\n6 2\n", "output": "abcabca\nabcd\nababab\n" } ], "private_tests": [ { "input": "66\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n...
[ 0.0000030960700188483397, 0.0000027844609648164335, 0.000002618193236451049, 0.0000022088801559768355, 0.0000022011183416193186, 0.000002134573208041958, 0.000002114410019667832, 0.00000210117034527972, 0.0000020723134970498252, 0.0000020197560232736013, 0.000002013933525458916, 0.000001950975...
1092_A. Uniform String
2254
2254_6
You are given two integers n and k. Your task is to construct such a string s of length n that for each i from 1 to k there is at least one i-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters except these. You have to maximize the minim...
"""https://codeforces.com/contest/1092/problem/A""" alpha = 'abcdefghijklmnopqrstuvwxyz' for _ in range(int(input())): n, k = tuple(map(int,input().split())) s = alpha[:k]*(n//k) + 'a'*(n%k) 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, ...
3 7 3 4 4 6 2
O(n)
0
{ "public_tests": [ { "input": "3\n7 3\n4 4\n6 2\n", "output": "abcabca\nabcd\nababab\n" } ], "private_tests": [ { "input": "66\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n...
[ 0.00008174077917395107, 0.000037829669402862764, 0.000031864833847792835, 0.00003094345860194493, 0.00002768060841892483, 0.000027276986451048956, 0.000025084564057036714, 0.000024785076622596154, 0.00002469148460718969, 0.00002320723366477273, 0.000023139488964160844, 0.00002298089089816434, ...
977_B. Two-gram
1593
1593_1104
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of ...
n = int(input()) s = input() if n == 2: print(s) else: m = 0 k = '' t = set() for i in range(n-1): s1 = 0 if s[i:i+2] not in t: t.add(s[i:i+2]) for j in range(n-1): if s[j:j+2] == s[i:i+2]: s1 += 1 if s1 > m: ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 ZZZAA
O(n**2)
0.00001
{ "public_tests": [ { "input": "5\nZZZAA\n", "output": "ZZ\n" }, { "input": "7\nABACABA\n", "output": "AB\n" } ], "private_tests": [ { "input": "15\nMIRZOYANOVECLOX\n", "output": "MI\n" }, { "input": "23\nAABBBAAACCCCCAAADDDDDDD\n", "outp...
[ 0.0007252149448777952, 0.0005724190877825548, 0.00005781698278059818, 0.000044129113508924737, 0.00004340051261122445, 0.00004115922865464482, 0.00002750215301650417, 0.000025000785632938162, 0.000023309284785131238, 0.000021961119632000942, 0.000020758127433788396, 0.000020751627002384608, ...
977_B. Two-gram
1593
1593_264
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of ...
n = int(input()) s = input() l = [] from collections import Counter for i in range(0,len(s)-1): l.append(s[i:i+2]) l = Counter(l) l = dict(l) max = 0 for word in l: if l[word] > max: max = l[word] string = word print(string)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 ZZZAA
O(n)
0.000005
{ "public_tests": [ { "input": "5\nZZZAA\n", "output": "ZZ\n" }, { "input": "7\nABACABA\n", "output": "AB\n" } ], "private_tests": [ { "input": "15\nMIRZOYANOVECLOX\n", "output": "MI\n" }, { "input": "23\nAABBBAAACCCCCAAADDDDDDD\n", "outp...
[ 0.0017320177182702187, 0.0007327675175781249, 0.0006652461046875, 0.0006488148078125, 0.0005590257787946429, 0.0005020308736979167, 0.000489020013764881, 0.0004500612587425595, 0.00018188379891007433, 0.0001277146700038243, 0.00010011728430944056, 0.00007710419185697116, 0.000076732505763767...
1271_B. Blocks
2516
2516_238
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
n = int(input()) a = input() def go(s, x): b = [1 if c == 'B' else 0 for c in s] o = [] n = len(b) for i in range(n): if b[i] != x: if i + 1 >= n: return 0 o += i + 1, b[i + 1] = b[i + 1] ^ 1 print(len(o)) print(' '.join(map(str, o))) return 1 if not go(a, 0) and not go(a...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
8 BWWWWWWB
O(n)
0.000012
{ "public_tests": [ { "input": "8\nBWWWWWWB\n", "output": "3\n2 4 6 " }, { "input": "5\nWWWWW\n", "output": "0\n" }, { "input": "3\nBWB\n", "output": "2\n1 2 " }, { "input": "4\nBWBB\n", "output": "-1\n" } ], "private_tests": [ { ...
[ 0.0000789657032069493, 0.000031756494154283226, 0.00003136382466947116, 0.00003100831248471175, 0.00002782088998788451, 0.000027186672173795428, 0.000026599706908326052, 0.000026269975005463287, 0.000026067958779501745, 0.00002587261594460227, 0.000024352654538704822, 0.000024320785511363638, ...
1271_B. Blocks
2516
2516_236
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of ope...
# for t in range(int(input())): # s = input() # i, j = 0, 0 # cnt = 0 # ans = float('inf') # dic = {} # while j < len(s): # if len(dic) < 3: # dic[s[j]] = dic.get(s[j], 0) + 1 # # print(j) # # print(dic) # while len(dic) == 3: # ans = min(a...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
8 BWWWWWWB
O(nlogn)
0.000021
{ "public_tests": [ { "input": "8\nBWWWWWWB\n", "output": "3\n2 4 6 " }, { "input": "5\nWWWWW\n", "output": "0\n" }, { "input": "3\nBWB\n", "output": "2\n1 2 " }, { "input": "4\nBWBB\n", "output": "-1\n" } ], "private_tests": [ { ...
[ 0.00002801511228420018, 0.000020939855178149524, 0.000019979375882402033, 0.000017101767445875988, 0.000016056478823790107, 0.000012923278423201888, 0.000005725115589270451, 0.000005536030243064913, 0.0000038041136470226045, 0.0000035495577005431973, 0.00000352358177293984, 0.00000311693515385...
1337_A. Ichihime and Triangle
2325
2325_862
Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears. These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite — cookies. Ichihime decides to attend the contest. Now sh...
n=int(input()) for i in range(n): l=list(map(int,input().split())) a,b,c,d=l[0],l[1],l[2],l[3] x=b y=c z=c print(x,y,z)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 3 5 7 1 5 5 7 100000 200000 300000 400000 1 1 977539810 977539810
O(n*m)
0.000007
{ "public_tests": [ { "input": "4\n1 3 5 7\n1 5 5 7\n100000 200000 300000 400000\n1 1 977539810 977539810\n", "output": "3 5 5\n5 5 5\n200000 300000 300000\n1 977539810 977539810\n" } ], "private_tests": [ { "input": "1\n1 3 4 7\n", "output": "3 4 4\n" }, { "input...
[ 0.00001311293393520542, 0.000010200039581512239, 0.000010150960213614512, 0.000009871599691324303, 0.000009494268247377625, 0.00000816333118444056, 0.000008155395159527972, 0.00000806221009069056, 0.000007967670249672202, 0.00000783935475852273, 0.000007791269654173951, 0.000007765223639641608...
1337_A. Ichihime and Triangle
2325
2325_570
Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears. These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite — cookies. Ichihime decides to attend the contest. Now sh...
import sys input = sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) tests = inp() testcount = 0 while testcount < tests: a,b,c,d = invr() 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, ...
4 1 3 5 7 1 5 5 7 100000 200000 300000 400000 1 1 977539810 977539810
O(n)
0
{ "public_tests": [ { "input": "4\n1 3 5 7\n1 5 5 7\n100000 200000 300000 400000\n1 1 977539810 977539810\n", "output": "3 5 5\n5 5 5\n200000 300000 300000\n1 977539810 977539810\n" } ], "private_tests": [ { "input": "1\n1 3 4 7\n", "output": "3 4 4\n" }, { "input...
[ 0.00010902398571350525, 0.00010524082826158217, 0.00008365131097027972, 0.00005900224274748689, 0.00004520972586593094, 0.000043609931681599656, 0.000040314491627513114, 0.00003981492176573427, 0.00003609121555397727, 0.000034100138808457176, 0.000033223698249016614, 0.000032361983241368, 0....
p02721 AtCoder Beginner Contest 161 - Yutori
1369
1369_10
Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not wor...
N,K,C=map(int,input().split()) S=input() L=[0 for i in range(K)] R=[0 for i in range(K)] n=0 rc=0 lc=0 while True: if lc==K: break if S[n]=="o": L[lc]=n+1 n+=C+1 lc+=1 else: n+=1 n=N-1 while True: if rc==K: break if S[n]=="o": R[K-1-rc]=n+1 n-=C+1 rc+=1 else: n-=1 for...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 3 ooxoo
O(n**2)
0.000001
{ "public_tests": [ { "input": "5 2 3\nooxoo", "output": "1\n5" }, { "input": "11 3 2\nooxxxoxxxoo", "output": "6" }, { "input": "16 4 3\nooxxoxoxxxoxoxxo", "output": "11\n16" } ], "private_tests": [], "generated_tests": [ { "input": "11 3 1\...
[ 0.00021117200000000003, 0.0000022870000000000003, 0.000001949499999999999, 0.0000018879999999999928, 0.0000015400000000000022, 0.0000015160000000000038, 0.0000014459999999999994, 0.0000014364999999999989, 0.000001392000000000003, 0.0000013630000000000071, 0.0000013615000000000038, 0.0000013300...
p02721 AtCoder Beginner Contest 161 - Yutori
1369
1369_7
Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not wor...
n,k,c=map(int,input().split()) s=list(input()) i=0 l=[0]*k r=[0]*k j=0 while i<n and l[-1]==0: if s[i]=='o': l[j]=i+1 i+=c+1 j+=1 else: i+=1 i=0 j=k-1 while i<n and r[0]==0: if s[-i-1]=='o': r[j]=n-i i+=c+1 j-=1 else: i+=1 for i in range(k): if r[i]==l[i]: print(r[i])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 2 3 ooxoo
O(n)
0.000003
{ "public_tests": [ { "input": "5 2 3\nooxoo", "output": "1\n5" }, { "input": "11 3 2\nooxxxoxxxoo", "output": "6" }, { "input": "16 4 3\nooxxoxoxxxoxoxxo", "output": "11\n16" } ], "private_tests": [], "generated_tests": [ { "input": "11 3 1\...
[ 0.000326063, 0.0003005995, 0.000214901, 0.0000178867560232736, 0.000007323414403955419, 0.0000062789764122596155, 0.000005642265788898602, 0.000005639130681818183, 0.000005438117228474651, 0.000005204466195913462, 0.000004794441870629371, 0.000004743425316870629, 0.000004713567157451924, 0...
p02721 AtCoder Beginner Contest 161 - Yutori
1369
1369_14
Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S. Takahashi will choose his workdays as follows: * After working for a day, he will refrain from working on the subsequent C days. * If the i-th character of S is `x`, he will not wor...
N, K, C = map(int, input().split()) S = input() left = [] right = [] i, j = 0, N-1 while len(left) <= K-1: if S[i] == "o": left.append(i) i += C+1 else: i += 1 while len(right) <= K-1: if S[j] == "o": right.append(j) j -= C+1 else: j -= 1 right.sort() for ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 3 ooxoo
O(nlogn)
0.000002
{ "public_tests": [ { "input": "5 2 3\nooxoo", "output": "1\n5" }, { "input": "11 3 2\nooxxxoxxxoo", "output": "6" }, { "input": "16 4 3\nooxxoxoxxxoxoxxo", "output": "11\n16" } ], "private_tests": [], "generated_tests": [ { "input": "11 3 1\...
[ 0.000007624002538209844, 0.000005978828267945173, 0.000005234228433675699, 0.0000048560677037805945, 0.000003864962729755475, 0.0000034846116832386365, 0.000003315312800480769, 0.0000032708909391389864, 0.0000023329839590859373, 0.0000022871025531047813, 0.0000022339999999999993, 0.00000213267...
1202_A. You Are Given Two Binary Strings...
88
88_200
You are given two binary strings x and y, which are binary representations of some two integers (let's denote these integers as f(x) and f(y)). You can choose any integer k ≥ 0, calculate the expression s_k = f(x) + f(y) ⋅ 2^k and write the binary representation of s_k in reverse order (let's denote it as rev_k). For e...
for u in range(int(input())): x=input()[::-1] y=input()[::-1] a,b=0,0 for i in range(len(y)): if(y[i]=='1'): a=i+1 break for i in range(len(x)): if(x[i]=='1' and i+1>=a): b=i+1 break print(b-a)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1010 11 10001 110 1 1 1010101010101 11110000
O(n**2)
0.000023
{ "public_tests": [ { "input": "4\n1010\n11\n10001\n110\n1\n1\n1010101010101\n11110000\n", "output": "1\n3\n0\n0\n" } ], "private_tests": [ { "input": "1\n1010101010111000100110\n1\n", "output": "1\n" }, { "input": "1\n11\n10\n", "output": "0\n" }, {...
[ 0.00004515914612261108, 0.00004299544017796247, 0.00004209579557338506, 0.00003458130567010754, 0.00003389047453012901, 0.00003217584022228042, 0.000030861277510942796, 0.000030508983136156825, 0.00003011714829246393, 0.00002998198286852246, 0.000028929558334220654, 0.000027881668331947198, ...
1202_A. You Are Given Two Binary Strings...
88
88_21
You are given two binary strings x and y, which are binary representations of some two integers (let's denote these integers as f(x) and f(y)). You can choose any integer k ≥ 0, calculate the expression s_k = f(x) + f(y) ⋅ 2^k and write the binary representation of s_k in reverse order (let's denote it as rev_k). For e...
n=int(input()) for i in range(n): a=input() b=input() k=b[::-1].index("1") a=a[::-1] p=a[k::].index("1") print(p)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1010 11 10001 110 1 1 1010101010101 11110000
O(n)
0.00002
{ "public_tests": [ { "input": "4\n1010\n11\n10001\n110\n1\n1\n1010101010101\n11110000\n", "output": "1\n3\n0\n0\n" } ], "private_tests": [ { "input": "1\n1010101010111000100110\n1\n", "output": "1\n" }, { "input": "1\n11\n10\n", "output": "0\n" }, {...
[ 0.00004500030535067297, 0.00004124376602137046, 0.00004085718602603248, 0.00003987783807544988, 0.00003973379310136436, 0.00003837111412159809, 0.000031526311333596174, 0.000031424939649888195, 0.00003095559666924708, 0.000028645534854340712, 0.000028223914230378516, 0.0000281250832688229, 0...
p02927 Japanese Student Championship 2019 Qualification - Takahashi Calendar
1954
1954_83
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 *...
M,D=map(int,input().split()) cnt=0 for i in range(1,M+1): for j in range(1,D+1): iti=j%10 ju=j//10 if iti>=2 and ju>=2 and i==iti*ju: cnt+=1 print(cnt)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
15 40
O(n**2)
0.007589
{ "public_tests": [ { "input": "15 40", "output": "10" }, { "input": "1 1", "output": "0" }, { "input": "12 31", "output": "5" } ], "private_tests": [], "generated_tests": [ { "input": "15 38", "output": "10\n" }, { "input...
[ 0.014091973368308352, 0.011303801441113493, 0.010413651515346184, 0.009362016098501071, 0.008303768108493934, 0.008217401700927909, 0.008212071798715206, 0.008176975497501786, 0.00817531034118487, 0.008171182334760886, 0.008135499903640257, 0.008120542837972878, 0.00794894088222698, 0.0079...
p02927 Japanese Student Championship 2019 Qualification - Takahashi Calendar
1954
1954_157
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 *...
mm, dd = map(int, input().split()) count = 0 for d in range(1, dd + 1): d1 = d % 10 d10 = d // 10 m = d1 * d10 if d1 >1 and d10 > 1 and m <= mm: count += 1 print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
15 40
O(n)
0.000023
{ "public_tests": [ { "input": "15 40", "output": "10" }, { "input": "1 1", "output": "0" }, { "input": "12 31", "output": "5" } ], "private_tests": [], "generated_tests": [ { "input": "15 38", "output": "10\n" }, { "input...
[ 0.0010035209207255483, 0.000848807188671875, 0.0008363642476562502, 0.0006076232622767856, 0.00037873693193655306, 0.00011113755991859702, 0.00011105335634287587, 0.00007050358815013112, 0.00006530378676791958, 0.00006424424972683568, 0.0000642101619318182, 0.00006235772092165648, 0.00005363...
1283_C. Friends and Gifts
1336
1336_157
There are n friends who want to give gifts for the New Year to each other. Each friend should give exactly one gift and receive exactly one gift. The friend cannot give the gift to himself. For each friend the value f_i is known: it is either f_i = 0 if the i-th friend doesn't know whom he wants to give the gift to or...
n = int(input()) f = [int(i) for i in input().split()] s = set([i for i in range(1, n + 1)]) zero = [i for i, a in enumerate(f) if a == 0] x = list(s - set(f)) for a, b in zip(zero, x): f[a] = b for i in range(len(zero) - 1): a = zero[i] if f[a] == a + 1: f[a] = f[zero[i + 1]] f[zero[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, ...
7 7 4 0 3 0 5 1
O(n)
0.00001
{ "public_tests": [ { "input": "7\n7 4 0 3 0 5 1\n", "output": "7 4 2 3 6 5 1 " }, { "input": "5\n5 0 0 2 4\n", "output": "5 3 1 2 4 \n" }, { "input": "5\n2 1 0 0 0\n", "output": "2 1 4 5 3 " }, { "input": "7\n7 0 0 1 4 0 6\n", "output": "7 3...
[ 0.000030726472970388986, 0.00002878746793711456, 0.00002822249104020979, 0.00001994570055167214, 0.000019641567666890186, 0.000019222259260005354, 0.000017234518698098777, 0.000016865244181599652, 0.000016416815054086536, 0.0000163400821131993, 0.000016149178299169185, 0.000015843896634615385,...
1283_C. Friends and Gifts
1336
1336_340
There are n friends who want to give gifts for the New Year to each other. Each friend should give exactly one gift and receive exactly one gift. The friend cannot give the gift to himself. For each friend the value f_i is known: it is either f_i = 0 if the i-th friend doesn't know whom he wants to give the gift to or...
n = int(input()) A = list(map(int, input().split())) # n = 7 # A = [0, 0, 1] A = [i-1 for i in A] B = [-1] * n for i in range(n): if A[i] != -1: B[A[i]] = i C = [i for i in range(n) if B[i] == -1] C.sort(key=lambda x: A[x] == B[x]) for i in range(n): if A[i] == -1: if i != C[-1]: A[i] = C[-1] C.pop() 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 7 4 0 3 0 5 1
O(nlogn)
0.000023
{ "public_tests": [ { "input": "7\n7 4 0 3 0 5 1\n", "output": "7 4 2 3 6 5 1 " }, { "input": "5\n5 0 0 2 4\n", "output": "5 3 1 2 4 \n" }, { "input": "5\n2 1 0 0 0\n", "output": "2 1 4 5 3 " }, { "input": "7\n7 0 0 1 4 0 6\n", "output": "7 3...
[ 0.00003440666388634042, 0.000025439716401796177, 0.000024323585409289204, 0.00002404553147685058, 0.00002326041558921823, 0.000023200329920713455, 0.000023182437034575385, 0.000023135177730547417, 0.000022935499257965173, 0.000022680913222165145, 0.000022255974103418885, 0.00002109586962998986...
918_A. Eleven
1699
1699_98
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters. <image> Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested th...
n=int(input()) l=[1,1] b="" for i in range(2,n+1): l.append(l[i-2]+l[i-1]) for j in range(1,n+1): if j in l: b+="O" else: b+="o" 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, ...
8
O(n**2)
0
{ "public_tests": [ { "input": "8\n", "output": "OOOoOooO\n" }, { "input": "15\n", "output": "OOOoOooOooooOoo\n" } ], "private_tests": [ { "input": "381\n", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOo...
[ 0.00004485647725917772, 0.0000011515100941916493, 5.904105390879618e-7, 2.8032460597808444e-7, 2.6810257650202086e-7, 2.6690282510571815e-7, 2.6652207578296405e-7, 2.6639130335438335e-7, 2.659443016090522e-7, 2.654020977160759e-7, 2.652981403464486e-7, 2.6500429871077476e-7, 2.64632158221393...
918_A. Eleven
1699
1699_213
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters. <image> Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested th...
n = int(input()) fib = [0, 1] while fib[-1] <= n: fib.append(fib[-1] + fib[-2]) name = '' for i in range(1,n+1): if i in fib: name += 'O' else: name += 'o' print(name)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
8
O(n)
0.000004
{ "public_tests": [ { "input": "8\n", "output": "OOOoOooO\n" }, { "input": "15\n", "output": "OOOoOooOooooOoo\n" } ], "private_tests": [ { "input": "381\n", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOo...
[ 0.00005859482268902972, 0.000038874914077483695, 0.00003671888719678758, 0.00003669750254042832, 0.000036070138576267484, 0.00003561914072060752, 0.000035424096263111894, 0.00003527694891826924, 0.00003503810754479895, 0.000034870702715253496, 0.00003475938039499563, 0.00003459167800753934, ...
841_A. Generous Kefa
2853
2853_256
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, ...
def list_input(): return list(map(int,input().split())) def map_input(): return map(int,input().split()) def map_string(): return input().split() n,k = map_input() s = input() ans = 0 for i in s: ans = max(ans,s.count(i)) if ans <= k: 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, ...
6 3 aacaab
O(n**2)
0
{ "public_tests": [ { "input": "6 3\naacaab\n", "output": "NO\n" }, { "input": "4 2\naabb\n", "output": "YES\n" } ], "private_tests": [ { "input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb\n", ...
[ 0.976771709, 0.030517360154929583, 0.03018651757746479, 0.00006675004614428541, 0.00002552673840035224, 0.000023463923683915175, 0.000023453361438779358, 0.00001130568593613418, 0.000010328656181708918, 0.000010268555411385492, 0.000008359612916317772, 0.000008113072830212877, 0.000006153130...
841_A. Generous Kefa
2853
2853_327
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, ...
n,m=list(map(int,input().split())) s=input() count={} for val in s: if(val not in count): count[val]=0 count[val]+=1 flag=0 for item in count: if(count[item]>m): flag=1 break if(flag==0): 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, ...
6 3 aacaab
O(n)
0.000001
{ "public_tests": [ { "input": "6 3\naacaab\n", "output": "NO\n" }, { "input": "4 2\naabb\n", "output": "YES\n" } ], "private_tests": [ { "input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb\n", ...
[ 0.000007120033148492134, 0.000005641358924278846, 0.000005135021921437937, 0.000005041217493444056, 0.000004512169034090909, 0.00000409169094187063, 0.0000040525087685751745, 0.000004035818577906469, 0.0000040085799142264, 0.000003970872036166959, 0.00000395832604895105, 0.00000394828575721153...
p03948 AtCoder Regular Contest 063 - An Invisible Hand
2051
2051_25
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples. Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows: * Move: ...
(N,T)=map(int,input().split()) a=list(map(int,input().split())) x=10**9 d=0 counter=0 for i in a: if i<x: x=i elif i-x>d: d=i-x counter=1 elif i-x==d: counter+=1 print(counter)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 8 50 30 40 10 20
O(n)
0.000004
{ "public_tests": [ { "input": "5 8\n50 30 40 10 20", "output": "2" }, { "input": "10 100\n7 10 4 5 9 3 6 8 2 1", "output": "2" }, { "input": "3 2\n100 50 200", "output": "1" } ], "private_tests": [], "generated_tests": [ { "input": "5 8\n21 ...
[ 0.000015154584107698373, 0.000005826577810861014, 0.000005677048964707168, 0.000005639274379916959, 0.00000542813560429251, 0.000005425360494973776, 0.000005380123825393357, 0.000004954093285620629, 0.000004936581252731644, 0.000004888703070367133, 0.000004797832003933567, 0.000004756065532124...
p03948 AtCoder Regular Contest 063 - An Invisible Hand
2051
2051_80
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples. Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows: * Move: ...
#!/usr/bin python3 # -*- coding: utf-8 -*- import bisect n, t = map(int, input().split()) a = list(map(int, input().split())) mx = 0 p = [0] * n for i in range(n-1,-1,-1): mx = max(mx, a[i]) p[i] = mx - a[i] p.sort() print(n-bisect.bisect_left(p, p[-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 8 50 30 40 10 20
O(nlogn)
0.000015
{ "public_tests": [ { "input": "5 8\n50 30 40 10 20", "output": "2" }, { "input": "10 100\n7 10 4 5 9 3 6 8 2 1", "output": "2" }, { "input": "3 2\n100 50 200", "output": "1" } ], "private_tests": [], "generated_tests": [ { "input": "5 8\n21 ...
[ 0.00001756273527070937, 0.00001528972993771056, 0.000012588002967000395, 0.000010985170252871314, 0.0000024293443545139173, 0.0000022178047819416936, 0.0000020261545412588274, 0.000001944153716081748, 0.0000016139260913575993, 0.00000154213151504943, 0.0000014902893107799885, 0.000001406939408...
608_C. Chain Reaction
2826
2826_42
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti...
n = int(input()) lis=[0]*(1000004) dp=[0]*(1000004) for i in range(n): a,b = map(int,input().split()) lis[a]=b if lis[0]>0: dp[0]=1 for i in range(1,1000002): if lis[i]>0: dp[i]=dp[max(-1,i-lis[i]-1)]+1 else: dp[i]=dp[i-1] print(n-max(dp))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
7 1 1 2 1 3 1 4 1 5 1 6 1 7 1
O(n)
0.000019
{ "public_tests": [ { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n", "output": "3\n" }, { "input": "4\n1 9\n3 1\n6 1\n7 4\n", "output": "1\n" } ], "private_tests": [ { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 6\n7 7\n", "output": "4\n" }, { ...
[ 0.0003769217774832589, 0.000044877564152644235, 0.00003079841378933564, 0.000028558190217985138, 0.000027410510871940563, 0.000025404401510598796, 0.000024472616709462424, 0.000024214419484812072, 0.00002405829440286276, 0.000023518249713177464, 0.00002285860985986672, 0.000022707827701595276,...
608_C. Chain Reaction
2826
2826_81
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti...
import sys,bisect n=int(input()) a,b=[],[] for _ in range(n): ai,bi=map(int,input().split(' ')) a.append(ai) b.append(bi) dptable=[1 for i in range(n+1)] dptable[0]=0 a.insert(0,-1*sys.maxsize) b.insert(0,0) ab=zip(a,b) sorted(ab) b=[x for _,x in sorted(zip(a,b))] a.sort() #print(a,"\n",b) for i in range(1,len(dpta...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
7 1 1 2 1 3 1 4 1 5 1 6 1 7 1
O(nlogn)
0
{ "public_tests": [ { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n", "output": "3\n" }, { "input": "4\n1 9\n3 1\n6 1\n7 4\n", "output": "1\n" } ], "private_tests": [ { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 6\n7 7\n", "output": "4\n" }, { ...
[ 0.00004000881856694469, 0.00003628809608571437, 0.00003625228021542982, 0.000036025960114478875, 0.000033882404125987596, 0.000033315030011143, 0.00003223177585724542, 0.000031603286665496275, 0.000031079130992438744, 0.00002743924726309795, 0.000026372714981313433, 3.6198520815122377e-7, 1....
390_A. Inna and Alarm Clock
225
225_145
Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square. The morning has ...
d1={} d2={} n=int(input()) l=[] for i in range(n): x=list(map(int,input().split())) l.append(x) for i in range(n): if(l[i][0] not in d1): d1[l[i][0]]=1 sum1=sum(d1.values()) for i in range(n): if(l[i][1] not in d2): d2[l[i][1]]=1 sum2=sum(d2.values()) print(sum1) if(sum1<=sum2) else 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, ...
4 0 0 0 1 1 0 1 1
O(n*m)
0.000003
{ "public_tests": [ { "input": "4\n0 0\n0 1\n1 0\n1 1\n", "output": "2" }, { "input": "4\n0 0\n0 1\n0 2\n1 0\n", "output": "2" }, { "input": "4\n1 1\n1 2\n2 3\n3 3\n", "output": "3" } ], "private_tests": [ { "input": "42\n28 87\n26 16\n59 90\n4...
[ 0.000006465628619427448, 0.000006176348202578671, 0.000003909064821896856, 0.0000037321093750000005, 0.000003730041097574301, 0.000003725203165974651, 0.0000036769213696459793, 0.00000357260309222028, 0.000003506402289117133, 0.000003503812117569931, 0.0000035037778491040205, 0.000003493458410...
390_A. Inna and Alarm Clock
225
225_85
Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square. The morning has ...
n = int(input()) x = set() y = set() for i in range(n): a, b = map(int, input().split()) x.add(a) y.add(b) print(min(len(x), len(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, ...
4 0 0 0 1 1 0 1 1
O(n)
0
{ "public_tests": [ { "input": "4\n0 0\n0 1\n1 0\n1 1\n", "output": "2" }, { "input": "4\n0 0\n0 1\n0 2\n1 0\n", "output": "2" }, { "input": "4\n1 1\n1 2\n2 3\n3 3\n", "output": "3" } ], "private_tests": [ { "input": "42\n28 87\n26 16\n59 90\n4...
[ 0.00002171240992406031, 0.000017284272781905597, 0.0000156513264996722, 0.000015646744796219404, 0.000014054372295673078, 0.00001374195664881993, 0.000013662978665865384, 0.000013659351644449303, 0.000013654598448426575, 0.000013639455146416085, 0.000013610733009178322, 0.000013586871599104023...
172_A. Phone Code
1484
1484_26
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest comm...
l=[];i=0 for _ in range(int(input())):l.append(input()) a=max(l);b=min(l) while a[i]==b[i]:i+=1 print(i)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 00209 00219 00999 00909
O(n)
0.000007
{ "public_tests": [ { "input": "4\n00209\n00219\n00999\n00909\n", "output": "2\n" }, { "input": "2\n1\n2\n", "output": "0\n" }, { "input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432\n", "output": "12\n" } ], "private_tests": [ ...
[ 0.000020018015902661668, 0.000019928398677368204, 0.000018857460054850656, 0.000018451051264932126, 0.000017778774015868124, 0.00001690837725222957, 0.000016864987012538527, 0.000014130583520629431, 0.000013300180388443953, 0.000013277529677198415, 0.000012757190259260007, 0.000012350148948599...
172_A. Phone Code
1484
1484_82
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest comm...
cases = int(input()) numbers = [] while cases: cases -= 1 s = input() numbers.append(s) numbers.sort() ct = 0 for i, j in zip(numbers[0], numbers[-1]): if i == j: ct += 1 else: print(ct) 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 00209 00219 00999 00909
O(nlogn)
0.000012
{ "public_tests": [ { "input": "4\n00209\n00219\n00999\n00909\n", "output": "2\n" }, { "input": "2\n1\n2\n", "output": "0\n" }, { "input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432\n", "output": "12\n" } ], "private_tests": [ ...
[ 0.000012242578817683149, 0.000012172366130594438, 0.00001200476103572148, 0.0000036452886782506513, 0.000002538752804594756, 0.0000017708993905681467, 0.0000016912747846826414, 0.000001659158216337754, 0.0000016213387360497957, 0.0000015687732707970694, 0.0000015669438905156186, 0.000001518740...
858_B. Which floor?
804
804_42
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o...
n, m = map(int, input().split()) a = [0] * m for i in range(m): a[i] = list(map(int, input().split())) a[i][0] -= 1 a[i][1] -= 1 n -= 1 canbe = set() last = 0 for i in range(1, 200): good = 1 for j in range(m): k = a[j][0] f = a[j][1] if not (i * f <= k <= i * (f + 1) - 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, ...
8 4 3 1 6 2 5 2 2 1
O(n*m)
0.000003
{ "public_tests": [ { "input": "8 4\n3 1\n6 2\n5 2\n2 1\n", "output": "-1\n" }, { "input": "10 3\n6 2\n2 1\n7 3\n", "output": "4\n" } ], "private_tests": [ { "input": "9 40\n73 1\n21 1\n37 1\n87 1\n33 1\n69 1\n49 1\n19 1\n35 1\n93 1\n71 1\n43 1\n79 1\n85 1\n29 1\n...
[ 0.0000036314641335227274, 0.000003376827838177448, 0.000003303223311844406, 0.0000031839901524256995, 0.0000031658466592001753, 0.000003163037136691434, 0.000003162102614182693, 0.0000031609307801573427, 0.000003160407424606644, 0.0000031407411631337416, 0.0000016557969842657343, 0.00000162962...
858_B. Which floor?
804
804_10
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o...
n, m = map(int, input().split(' ')) n -= 1 if m == 0: if n == 0: print(1) else: print(-1) exit(0) minAps = 0 maxAps = 100000 for i in range(m): k, f = map(int, input().split(' ')) k -= 1 f -= 1 if f == 0: minAps = max(minAps, k + 1) else: minAps = max(min...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
8 4 3 1 6 2 5 2 2 1
O(n)
0
{ "public_tests": [ { "input": "8 4\n3 1\n6 2\n5 2\n2 1\n", "output": "-1\n" }, { "input": "10 3\n6 2\n2 1\n7 3\n", "output": "4\n" } ], "private_tests": [ { "input": "9 40\n73 1\n21 1\n37 1\n87 1\n33 1\n69 1\n49 1\n19 1\n35 1\n93 1\n71 1\n43 1\n79 1\n85 1\n29 1\n...
[ 0.00018240055543870197, 0.00015951734902207169, 0.00010921845614346592, 0.00005452484797038899, 0.000025983016963505248, 0.000023152430261145107, 0.000018129277493990384, 0.000017049830146416085, 0.000016874902835445803, 0.000015544430179195805, 0.00001526679298240822, 0.000015084899120410842,...
981_A. Antipalindrome
2269
2269_21
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring s[l … r] (1 ≤ l ≤ r ≤ |s|) of a string s = s_{1}s_{2} … s_{|s|} is the string s_...
s, r = input(), 0 i = len(s) while i > r: for j in range(i - r): t = s[j:i] if t != t[::-1]: r = i - j break i -= 1 print(r)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
qqqqqqqq
O(n**2)
0.000023
{ "public_tests": [ { "input": "qqqqqqqq\n", "output": "0\n" }, { "input": "wuffuw\n", "output": "5\n" }, { "input": "mew\n", "output": "3\n" } ], "private_tests": [ { "input": "aaadcba\n", "output": "7\n" }, { "input": "aaa...
[ 0.0014164553832499735, 0.0008580100040734964, 0.0007778319658016934, 0.000610013151976079, 0.0005834792893963471, 0.0005612861017479612, 0.0005477529103514476, 0.0005071510617524702, 0.000506660518354803, 0.0004719421625730334, 0.00045829080434449436, 0.00045828562645360953, 0.00036907278219...
981_A. Antipalindrome
2269
2269_59
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring s[l … r] (1 ≤ l ≤ r ≤ |s|) of a string s = s_{1}s_{2} … s_{|s|} is the string s_...
s = input() def isPalindrome(s): l = len(s) for i in range(l // 2): if s[i] != s[l - i - 1]: return False return True if not isPalindrome(s): print(len(s)) elif all([c == s[0] for c in s]): print(0) else: print(len(s) - 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, ...
qqqqqqqq
O(n)
0.000002
{ "public_tests": [ { "input": "qqqqqqqq\n", "output": "0\n" }, { "input": "wuffuw\n", "output": "5\n" }, { "input": "mew\n", "output": "3\n" } ], "private_tests": [ { "input": "aaadcba\n", "output": "7\n" }, { "input": "aaa...
[ 0.000019204084872159093, 0.00001332754055124563, 0.000011854036713286715, 0.000010827353898055072, 0.000010215875437062936, 0.000008219153204217657, 0.00000819276095388986, 0.000007574531468531469, 0.000007512224827906469, 0.000006930922079873252, 0.000006726702428430945, 0.0000065835432145979...
1_B. Spreadsheets
1047
1047_641
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th...
import re for t in range(int(input())): a = input() if re.search("R\d+C\d+",a): row,col= a.split("C") row = row[1:] col = int(col) ans = "" while col: temp = col%26+64 if temp == 64: temp = 90 col-=1 ans = chr(temp) + ans col//=26 print(ans+row) else: col = "" for i in 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, ...
2 R23C55 BC23
O(n**2)
0.000016
{ "public_tests": [ { "input": "2\nR23C55\nBC23\n", "output": "BC23\nR23C55\n" } ], "private_tests": [ { "input": "1\nA1\n", "output": "R1C1\n" }, { "input": "4\nR4C25\nR90C35\nAP55\nX83\n", "output": "Y4\nAI90\nR55C42\nR83C24\n" }, { "input": ...
[ 0.000042113986039845865, 0.000035272501005787235, 0.000035140387246790555, 0.00003496371718816999, 0.00003469830531326171, 0.00003425925029281502, 0.0000318532298259801, 0.00003137533826106726, 0.000031343506286529933, 0.000030450624514732837, 0.000029834229825980105, 0.00002981122179407118, ...
1_B. Spreadsheets
1047
1047_26
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th...
import re f = lambda n: sum((ord(k)-64) * 26**i for i, k in enumerate(str(n)[::-1])) g = lambda n: '' if not n else (g(n // 26) + chr(n % 26 + 64) if n % 26 else g(n // 26 - 1) + 'Z') for cell in [input() for i in range(int(input()))]: if re.search('R\d+C\d+', cell): print(g(int(cell[cell.find('C')+1:])) + cell[...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 R23C55 BC23
O(n)
0.000018
{ "public_tests": [ { "input": "2\nR23C55\nBC23\n", "output": "BC23\nR23C55\n" } ], "private_tests": [ { "input": "1\nA1\n", "output": "R1C1\n" }, { "input": "4\nR4C25\nR90C35\nAP55\nX83\n", "output": "Y4\nAI90\nR55C42\nR83C24\n" }, { "input": ...
[ 0.0010395341080983859, 0.00006119635589328007, 0.0000467739622549203, 0.000039497799806612586, 0.000034674243504110925, 0.00003463100843192159, 0.00003305121874361491, 0.00003104953405431539, 0.00003055001769552418, 0.00003054124928271111, 0.00003038847879213443, 0.00003027641945788212, 0.00...
110_C. Lucky Sum of Digits
271
271_58
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with...
n = int(input()) aux = 0 if n < 4: print('-1') else: numSeven = n/7 rem = n%7 numFour = rem/4 toBecomeFour = rem%4 if toBecomeFour != 0: if numSeven >= toBecomeFour: numFour += ((7*toBecomeFour) + toBecomeFour)/4 numSeven -= toBecomeFour else: print("-1") aux = 1 if aux == 0: for i in range(in...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
11
O(n)
0.000001
{ "public_tests": [ { "input": "11\n", "output": "47\n" }, { "input": "10\n", "output": "-1\n" } ], "private_tests": [ { "input": "999980\n", "output": "444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...
[ 0.00006307676053048514, 0.000026868843560606066, 0.00002404607256610577, 0.000009450443209134616, 0.000008307197893902972, 0.000007073198918269231, 0.000007054475591856061, 0.000006999751728219697, 0.000006952725155703672, 0.000006852883317854021, 0.000006433496640078671, 0.0000049942933511800...
110_C. Lucky Sum of Digits
271
271_51
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with...
n=int(input()) x,y=n//7,n%7 z,w=y//4,y%4 if(x<w): print(-1) else: print('4'*(z+w*2)+'7'*(x-w))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
11
O(1)
0.000003
{ "public_tests": [ { "input": "11\n", "output": "47\n" }, { "input": "10\n", "output": "-1\n" } ], "private_tests": [ { "input": "999980\n", "output": "444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...
[ 0.23367277200000006, 0.027327917500000076, 0.017658627999999954, 0.008468784999999979, 0.0044230065000000485, 0.000020845, 0.000017162999999999998, 0.000014230499999999999, 0.000011344500000000003, 0.000008316500000000004, 0.000007675499999999998, 0.000006940000000000005, 0.00000688450000000...
1299_A. Anu Has a Function
2465
2465_139
Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers x and y value of f(x, y) is also nonnegative. She would like to r...
n = int(input()) vals = list(map(int, input().split())) pref, suff = [0] * (n + 1), [0] * (n + 1) for i in range(n): pref[i + 1] = pref[i] | vals[i] suff[n - i - 1] = suff[n - i] | vals[n - i - 1] ret = (-float('inf'), -float('inf')) for i, a in enumerate(vals): b = pref[i] | suff[i + 1] ret = max(ret, ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 13
O(n)
0.000004
{ "public_tests": [ { "input": "1\n13\n", "output": "13\n" }, { "input": "4\n4 0 11 6\n", "output": "11 4 0 6\n" } ], "private_tests": [ { "input": "10\n268439624 335544469 2491136 151142938 168395872 536905856 17833986 35939360 617678852 13111553\n", "outpu...
[ 0.00004238529514040647, 0.000041097638986013986, 0.00003769482238854895, 0.00003353405315777972, 0.00003181009581239074, 0.00003034686569875437, 0.000028039637155812943, 0.0000267435289690778, 0.000026679513029938813, 0.00002613115666395195, 0.00002093582250373393, 0.000019985644067796606, 0...
1299_A. Anu Has a Function
2465
2465_212
Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers x and y value of f(x, y) is also nonnegative. She would like to r...
n = int(input()) a = [int(x) for x in input().split()] a.sort(reverse=True) mask = 2**30 while mask and len([ai for ai in a if ai & mask])!=1: mask>>=1 for i in range(n): if mask&a[i]: break a[i], a[0] = a[0], a[i] 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 13
O(nlogn)
0.000003
{ "public_tests": [ { "input": "1\n13\n", "output": "13\n" }, { "input": "4\n4 0 11 6\n", "output": "11 4 0 6\n" } ], "private_tests": [ { "input": "10\n268439624 335544469 2491136 151142938 168395872 536905856 17833986 35939360 617678852 13111553\n", "outpu...
[ 0.00005930155181927448, 0.000053081869796219406, 0.00004186549157288025, 0.000016517716564685316, 0.000015975390201595284, 0.000013630762428977274, 0.00001351520495520105, 0.000012439533599213288, 0.000011454681381118882, 0.000008685928690450175, 0.00000636462521853147, 0.000005624207754403764...
1256_C. Platforms Jumping
1748
1748_145
There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1). There are also m wooden platforms on a river, the i-th platform has length c_i (so the i-th platform takes c_i consecuti...
n , m , d = map(int , input().split()) array = list(map(int , input().split())) ss = sum(array) ans = [0] * (n + 1) s = 0 for i in range(m) : pos = min(s + d , n + 1 - ss) for j in range(pos , pos + array[i]): ans[j] = i + 1 s = pos + array[i] - 1 ss -= array[i] if s + d <= n : print("NO") e...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 3 2 1 2 1
O(n**2)
0
{ "public_tests": [ { "input": "7 3 2\n1 2 1\n", "output": "YES\n0 1 0 2 2 0 3\n" }, { "input": "10 1 5\n2\n", "output": "YES\n0 0 0 0 1 1 0 0 0 0\n" }, { "input": "10 1 11\n1\n", "output": "YES\n0 0 0 0 0 0 0 0 0 1\n" } ], "private_tests": [ { ...
[ 0.007642526349252014, 0.00009878162131696428, 0.000015452571131993008, 0.000011629998124385289, 0.000008742397226962581, 0.000004733411158920822, 7.888524260457859e-7, 7.364150423527667e-7, 7.043967381878069e-7, 5.567093130493468e-7, 5.229299444233824e-7, 2.295342391648941e-7, 4.778426151060...
1256_C. Platforms Jumping
1748
1748_21
There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1). There are also m wooden platforms on a river, the i-th platform has length c_i (so the i-th platform takes c_i consecuti...
n, m, d = list(map(int, input().strip().split(' '))) c = list(map(int, input().strip().split(' '))) res = [] for i, ci in enumerate(c): empty = n - len(res) - sum(c[i:]) if empty >= d - 1: res.extend(['0']*(d - 1)) else: res.extend(['0'] * empty) res.extend([str(i + 1) for _ in range(c...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
7 3 2 1 2 1
O(n)
0.018108
{ "public_tests": [ { "input": "7 3 2\n1 2 1\n", "output": "YES\n0 1 0 2 2 0 3\n" }, { "input": "10 1 5\n2\n", "output": "YES\n0 0 0 0 1 1 0 0 0 0\n" }, { "input": "10 1 11\n1\n", "output": "YES\n0 0 0 0 0 0 0 0 0 1\n" } ], "private_tests": [ { ...
[ 0.04532031308098592, 0.03851987290492958, 0.03811161177112676, 0.027092525183935744, 0.026687032238554217, 0.026651657355020085, 0.02615050838232932, 0.021084126887550205, 0.019013274646586347, 0.018107910930923697, 0.01544720253493976, 0.015398001020883534, 0.014879525208835344, 0.0145869...
349_A. Cinema Line
2281
2281_112
The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the...
x= int(input()) total1 = 0 total2=0 C = "YES" f = [int(i) for i in input().split()] for z in f: if z == 25: total1 += 1 elif z==50: if total1 >=1: total1 -= 1 total2 +=1 else: C = "NO" break else: if total1 >=1 and total2>=1: 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, ...
4 25 25 50 50
O(n)
0.000002
{ "public_tests": [ { "input": "4\n25 25 50 50\n", "output": "YES\n" }, { "input": "4\n50 50 25 25\n", "output": "NO\n" }, { "input": "2\n25 100\n", "output": "NO\n" } ], "private_tests": [ { "input": "5\n25 25 50 50 50\n", "output": "NO\...
[ 0.00002539776531086101, 0.000012304926027097903, 0.000008350188114619755, 0.000008315591592001748, 0.000007645377157998252, 0.00000602557540701486, 0.000005114189425808567, 0.000004797882279829546, 0.000004784885066105769, 0.00000459630978201486, 0.000004530532124125874, 0.00000453007457386363...
349_A. Cinema Line
2281
2281_358
The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the...
import math mod=1000000007 def power(a,b): res=1 b=b%(mod-1) while(b>0): if b%2!=0: res=((res%mod)*(a%mod))%mod b=b//2 a=a%mod a=(a*a)%mod res=res%mod return res #n=int(input()) #a=[int(i) for i in input().split()] #c=[[0 for x in range(1001)] for y in ran...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 25 25 50 50
O(n+mlogm)
0.000002
{ "public_tests": [ { "input": "4\n25 25 50 50\n", "output": "YES\n" }, { "input": "4\n50 50 25 25\n", "output": "NO\n" }, { "input": "2\n25 100\n", "output": "NO\n" } ], "private_tests": [ { "input": "5\n25 25 50 50 50\n", "output": "NO\...
[ 0.0000024802059522508746, 0.0000024715084680944054, 0.000002464370643028846, 0.0000019238695230550703, 0.0000017883530785620628, 0.0000017815215390078671, 0.0000017587971891389865, 0.0000017568437363417834, 0.0000017563857626748253, 0.0000017562141471809438, 0.0000017491163133741265, 0.0000017...
746_B. Decoding
2830
2830_421
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf...
def solution(n,s): ans = [" "]*n if n%2==0: p = int(n/2) - 1 for i in range(n): if i%2==0: ans[p - int(i/2) ] = s[i] else: ans[p + int((i+1)/2) ] = s[i] else: p = int(n/2) for i in range(n): if i%2==0: ans[p + int(i/2) ] = s[i] else: ans[p - int((i+1)/2) ] = s[i] return ''.join...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 no
O(n**2)
0
{ "public_tests": [ { "input": "2\nno\n", "output": "no\n" }, { "input": "4\nabba\n", "output": "baba\n" }, { "input": "5\nlogva\n", "output": "volga\n" } ], "private_tests": [ { "input": "4\naegi\n", "output": "gaei\n" }, { ...
[ 0.000001253133126595731, 7.41987968178529e-7, 6.151394035623014e-7, 5.012887667150595e-7, 3.7526126638975265e-7, 1.4935251260852692e-7, 2.63988600034762e-8, 1.855951273774765e-8, 1.502631945020335e-8, 1.4160903618444668e-8, 1.4052878016262215e-8, 8.997877047899873e-9, 8.272864106354197e-9, ...
746_B. Decoding
2830
2830_525
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf...
n = int(input()) letras = list(map(str, input())) letras_copy = letras.copy() index_letras = [i for i in range(n)] decoding = [] while len(letras) != 0: decoding.append(index_letras[(len(letras)-1)//2]) index_letras.pop((len(letras)-1)//2) letras.pop((len(letras)-1)//2) ans = [(i, l) for i, l in zip(decoding, let...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 no
O(nlogn)
0.000006
{ "public_tests": [ { "input": "2\nno\n", "output": "no\n" }, { "input": "4\nabba\n", "output": "baba\n" }, { "input": "5\nlogva\n", "output": "volga\n" } ], "private_tests": [ { "input": "4\naegi\n", "output": "gaei\n" }, { ...
[ 0.0000059282263283498145, 0.000005815610703130917, 0.000003845136281687063, 0.000003212692326951357, 0.0000023637864955357144, 0.0000022343468512672344, 0.00000222380593630302, 0.0000019524870744109887, 0.000001947274984244106, 0.000001932757028280032, 0.0000018337065489842844, 0.0000017718861...