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 |
|---|---|---|---|---|---|---|---|---|---|---|
1051_C. Vasya and Multisets | 2005 | 2005_187 | Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the q... | from collections import *
n = int(input())
a = list(map(int,input().split()))
ans = ["A"]*n
num = 0
for i in range(n):
if a.count(a[i])>1:
continue
if num<0:
num+=1
ans[i] = "B"
else:
num-=1
if num<0:
for i in range(n):
if a.count(a[i])<=2:
continue
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4
3 5 7 1
| O(n**2) | 0.000064 | {
"public_tests": [
{
"input": "4\n3 5 7 1\n",
"output": "YES\nABAB"
},
{
"input": "3\n3 5 1\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "8\n3 5 3 3 2 1 4 3\n",
"output": "YES\nAAAABABA"
},
{
"input": "100\n9 9 72 55 14 8 55 58 35 6... | [
0.00006665693097911013,
0.00006464188871014623,
0.00006454980619530403,
0.00006447931050191517,
0.000007590628019894882,
0.0000025626874354565384,
6.835418166964035e-7,
2.6679270468268165e-7,
2.435289342763109e-7,
1.7511658825235177e-7,
1.7302063226605862e-7,
1.1650625885386189e-7,
7.8793404... |
1051_C. Vasya and Multisets | 2005 | 2005_137 | Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the q... | from collections import Counter
n = int(input())
s = list(map(int,input().split()))
c = Counter(s)
singles = [i for i in c if c[i]==1]
multis = [i for i in c if c[i]>2]
if len(singles)&1 and not multis:
print("NO")
else:
print("YES")
sin,mul=len(singles)//2,len(singles)&1
ans = ""
for x in s:
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4
3 5 7 1
| O(n) | 0.000003 | {
"public_tests": [
{
"input": "4\n3 5 7 1\n",
"output": "YES\nABAB"
},
{
"input": "3\n3 5 1\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "8\n3 5 3 3 2 1 4 3\n",
"output": "YES\nAAAABABA"
},
{
"input": "100\n9 9 72 55 14 8 55 58 35 6... | [
0.000014291718900240384,
0.000011677848516717658,
0.00000899332727819056,
0.000008741136459243883,
0.000008362311543924824,
0.000008354034200174827,
0.000007826823658763113,
0.000006999734074519232,
0.000006982595457277097,
0.000006924540496612763,
0.000006751966168597028,
0.000006490033025568... |
621_B. Wet Shark and Bishops | 750 | 750_51 | Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the onl... | n = int(input())
a = [0] * 2001
b = [0] * 2001
for i in range(n):
x, y = map(int, input().split())
a[x - y] += 1
b[x + y] += 1
ans = 0
for i in range(2001):
ans += a[i] * (a[i] - 1) // 2
ans += b[i] * (b[i] - 1) // 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, ... | 3
1 1
2 3
3 5
| O(n) | 0.000011 | {
"public_tests": [
{
"input": "3\n1 1\n2 3\n3 5\n",
"output": "0\n"
},
{
"input": "5\n1 1\n1 5\n3 3\n5 1\n5 5\n",
"output": "6\n"
}
],
"private_tests": [
{
"input": "1\n1 1\n",
"output": "0\n"
},
{
"input": "2\n1000 1\n1000 1000\n",
"out... | [
0.000017075636146755727,
0.00001534040819421622,
0.000015043592102196042,
0.000014523477589218652,
0.000014369605196135706,
0.000014271737280892345,
0.000013969253622416827,
0.00001387832110944519,
0.000013710452480510177,
0.000013426834869592993,
0.000013246774223068933,
0.0000132403820955483... |
621_B. Wet Shark and Bishops | 750 | 750_14 | Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the onl... | import sys
n=int(sys.stdin.readline())
a=[]
b=[]
res=0
for i in range(n):
_a, _b = list(map(int, sys.stdin.readline().split()))
a.append(_a+_b)
b.append(_a-_b)
a.sort()
b.sort()
i=0
while i<n:
cnt=1
while i+1<len(a) and a[i]==a[i+1]:
cnt+=1
i+=1
res+=cnt*(cnt-1)//2
i+=1
i=... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
1 1
2 3
3 5
| O(nlogn) | 0.000019 | {
"public_tests": [
{
"input": "3\n1 1\n2 3\n3 5\n",
"output": "0\n"
},
{
"input": "5\n1 1\n1 5\n3 3\n5 1\n5 5\n",
"output": "6\n"
}
],
"private_tests": [
{
"input": "1\n1 1\n",
"output": "0\n"
},
{
"input": "2\n1000 1\n1000 1000\n",
"out... | [
0.00001907865187590094,
0.000017961286960828123,
0.000011504899760855738,
0.000011344483759198134,
0.000010860577434105828,
0.000010715660921640685,
0.000010086332914135412,
0.000009974320087830119,
0.00000993474547107966,
0.000008937960133989854,
0.0000029796656442268925,
0.000002487790787550... |
24_A. Ring road | 348 | 348_33 | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two ot... | import sys,math
n=int(sys.stdin.readline())
start =[]
end=[]
ans1=0
ans2=0
for i in range(n):
a,b,c=map(int,sys.stdin.readline().split())
if (a in start) or (b in end):
ans1+=c
start.append(b)
end.append(a)
else:
ans2+=c
start.append(a)
end.append(b)
print(mi... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
1 3 1
1 2 1
3 2 1
| O(n**2) | 0 | {
"public_tests": [
{
"input": "3\n1 3 1\n1 2 1\n3 2 1\n",
"output": "1\n"
},
{
"input": "3\n1 3 1\n1 2 5\n3 2 1\n",
"output": "2\n"
},
{
"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n",
"output": "39\n"
},
{
"input": "4\n1 2 9\n2 3 8\... | [
0.000006256207725237769,
0.0000029232868991540122,
0.0000014474133228332133,
0.0000013929830762248932,
1.688286558635579e-8,
6.196111505681821e-9,
5.007532506555945e-9,
4.671383304195803e-9,
3.3908298732517487e-9,
3.3143097137237765e-9,
2.8571965144230795e-9,
2.6465458369755264e-9,
2.5521197... |
24_A. Ring road | 348 | 348_21 | Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two ot... | source=set()
dest=set()
c1=0
c2=0
for i in range(int(input())):
s,d,w=map(int,input().split())
if s in source or d in dest:
c1=c1+w
s,d=d,s
else:
c2=c2+w
source.add(s)
dest.add(d)
print(min(c1,c2)) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
1 3 1
1 2 1
3 2 1
| O(n) | 0 | {
"public_tests": [
{
"input": "3\n1 3 1\n1 2 1\n3 2 1\n",
"output": "1\n"
},
{
"input": "3\n1 3 1\n1 2 5\n3 2 1\n",
"output": "2\n"
},
{
"input": "6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n",
"output": "39\n"
},
{
"input": "4\n1 2 9\n2 3 8\... | [
0.00004369608671875,
0.000014141263453343533,
0.000013194172489619757,
0.00001012090603146853,
7.973542668269233e-8,
3.5460964816433593e-9,
2.9987639313811232e-9,
2.9682309877622372e-9,
2.841551027097901e-9,
2.8166794143356696e-9,
2.7736082277097897e-9,
2.2434303977272726e-9,
2.2103980004370... |
887_B. Cubes for Masha | 1722 | 1722_4 | Absent-minded Masha got set of n cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.
To make a number Masha can rotate her cubes and put them in a row. Aft... | def gen(cur, used, x):
pos.add(cur)
if x == n:
return
for j in range(n):
if not used[j]:
for i in a[j]:
if i != 0 or x != 0:
used[j] = True
gen(cur * 10 + i, used, x + 1)
used[j] = False
n = 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, ... | 3
0 1 3 5 6 8
1 2 4 5 7 8
2 3 4 6 7 9
| O(n**2) | 0.009115 | {
"public_tests": [
{
"input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n",
"output": "98\n"
},
{
"input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n",
"output": "87\n"
}
],
"private_tests": [
{
"input": "2\n2 6 8 1 3 1\n2 1 3 8 6 7\n",
"output": "3\n"
... | [
0.014782952877944327,
0.01350315644325482,
0.012996374319771593,
0.012571852147751606,
0.010349596398286937,
0.009887494713062099,
0.009114681620271237,
0.008957700438258389,
0.0074569165867237695,
0.007336192713775875,
0.006912358371877231,
0.005564451643112064,
0.004580531085653105,
0.00... |
887_B. Cubes for Masha | 1722 | 1722_66 | Absent-minded Masha got set of n cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.
To make a number Masha can rotate her cubes and put them in a row. Aft... | n = int(input())
a = []
a += [list(input())]
if (n > 1):
a += [list(input())]
if (n > 2):
a += [list(input())]
i = 1
while (i < 1000):
s = list(str(i))
if (n == 1):
if (s[0] in a[0]):
i += 1
continue
if (n == 2):
if (len(s) == 1 and (s[0] in a[0] or s[0] 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, ... | 3
0 1 3 5 6 8
1 2 4 5 7 8
2 3 4 6 7 9
| O(n) | 0.000012 | {
"public_tests": [
{
"input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n",
"output": "98\n"
},
{
"input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n",
"output": "87\n"
}
],
"private_tests": [
{
"input": "2\n2 6 8 1 3 1\n2 1 3 8 6 7\n",
"output": "3\n"
... | [
0.005849447000000001,
0.000016723487366149474,
0.000016640169061407343,
0.000016640003537478148,
0.000014919842466127624,
0.000012939876393138112,
0.000012301240944602274,
0.000011666880750109266,
0.00001125980337631119,
0.000010597934467875874,
0.000010357546588177449,
0.000009252246325939686... |
1323_C. Unusual Competitions | 661 | 661_99 | A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not.
The teacher gave Dmitry's class a very strange task β she asked every student... | n=int(input())
brak=[i for i in input()]
open_=0
close_=0
if brak.count('(')!=brak.count(')'):
print(-1)
else:
count=0
for i in brak:
if i=="(":
open_+=1
else:
close_+=1
if close_>open_:
count+=2
print(count)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 8
))((())(
| O(n) | 0.000003 | {
"public_tests": [
{
"input": "8\n))((())(\n",
"output": "6\n"
},
{
"input": "3\n(()\n",
"output": "-1\n"
}
],
"private_tests": [
{
"input": "4\n))))\n",
"output": "-1\n"
},
{
"input": "4\n))((\n",
"output": "4\n"
},
{
"inp... | [
0.00001285687215909091,
0.000010526258448468873,
0.000010378088264664493,
0.000009977159305762197,
0.000008388352218094405,
0.000008385668870192306,
0.00000829345108766033,
0.000008176679258911794,
0.000007707009533435315,
0.000007702878715034967,
0.000007282843551882219,
0.0000071568409227491... |
1323_C. Unusual Competitions | 661 | 661_47 | A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not.
The teacher gave Dmitry's class a very strange task β she asked every student... | n= int(input())
seq= list(input())
if seq.count(')')!=seq.count('('):
print(-1)
else:
a,b=[],[]
for i in range(len(seq)):
if seq[i]==')':
a.append(i)
else:
b.append(i)
c=[]
for i in range(len(a)):
if b[i]>a[i]:
c.append(a[i])
c.append(b[i])
c.sort()
start=0
sum=0
for i in range(len(c)-1):
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 8
))((())(
| O(nlogn) | 0.000016 | {
"public_tests": [
{
"input": "8\n))((())(\n",
"output": "6\n"
},
{
"input": "3\n(()\n",
"output": "-1\n"
}
],
"private_tests": [
{
"input": "4\n))))\n",
"output": "-1\n"
},
{
"input": "4\n))((\n",
"output": "4\n"
},
{
"inp... | [
0.000015801057483138505,
0.0000014390343319001593,
0.0000013912232485212835,
0.0000012501579330693742,
0.0000011701936064044383,
0.0000011623206701571234,
9.202252202455725e-7,
8.299393138064738e-7,
5.709836159027591e-7,
5.631570162018291e-7,
5.21044069139501e-7,
4.815193201206476e-7,
4.7797... |
886_C. Petya and Catacombs | 2505 | 2505_30 | 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())
data = list(map(int, input().split()))
d = [False] * (n + 4)
d[0] = True
res = 1
for i in range(n):
#print(d)
if d[data[i]]:
d[data[i]] = False
d[i + 1] = True
else:
d[i + 1] = True
res += 1
#print(d)
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": "1\n0\n",
"output": "1\n"
},
{
"input": "14\n0 0 1 1 2 2 3 3 4 4 5 5 6 6\n",
"output": "8\n"
... | [
4.61255067031827e-9,
3.7200434325142267e-9,
2.844054241848428e-9,
1.9286925824925423e-9,
1.8449987155194102e-9,
1.8079277616417545e-9,
1.764178551086279e-9,
1.7301892751669527e-9,
1.4106774654701826e-9,
1.283846614454291e-9,
1.2135018004216294e-9,
1.1950930396267459e-9,
1.1771138792450705e-9... |
886_C. Petya and Catacombs | 2505 | 2505_87 | 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())
arr = list(map(int, input().split()))
arr.sort()
cnt_total = 0
cnt_tmp = 0
for i in range(1,n):
if arr[i] == arr[i-1]:
cnt_total +=1
print(cnt_total+1)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2
0 0
| O(nlogn) | 0.000005 | {
"public_tests": [
{
"input": "2\n0 0\n",
"output": "2\n"
},
{
"input": "5\n0 1 0 1 3\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "1\n0\n",
"output": "1\n"
},
{
"input": "14\n0 0 1 1 2 2 3 3 4 4 5 5 6 6\n",
"output": "8\n"
... | [
0.0000053624728791522934,
0.000005360939340687206,
0.0000034698345033872386,
0.0000032901314466783218,
0.0000026100686052229024,
0.0000024926629152097903,
0.0000022019864373907347,
0.0000021494221481643354,
0.0000019066879507211541,
0.0000017391441761363638,
0.0000017103755873033217,
0.0000016... |
1131_B. Draw! | 525 | 525_273 | You still have partial information about the score during the historic football match. You are given a set of pairs (a_i, b_i), indicating that at some point during the match the score was "a_i: b_i". It is known that if the current score is Β«x:yΒ», then after the goal it will change to "x+1:y" or "x:y+1". What is the l... | n = int(input())
pair = [None] * n
count = 0
add = 0
for i in range(n):
pair[i] = list(map(int,input().split()))
if(min(pair[0]) != 0):
add += min(pair[0]) + 1
else:
add += 1
#print(add)
count+= add
for i in range(1,n):
if(min(pair[i]) - max(pair[i-1]) < 0):
continue
add = max( min(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, ... | 3
0 0
0 0
0 0
| O(n*m) | 0.000003 | {
"public_tests": [
{
"input": "3\n0 0\n0 0\n0 0\n",
"output": "1\n"
},
{
"input": "1\n5 4\n",
"output": "5\n"
},
{
"input": "3\n2 0\n3 1\n3 4\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "6\n0 0\n0 1\n1 1\n8 7\n8 8\n9 9\n",
"ou... | [
0.0000035642755135489514,
0.000002896986013986014,
0.0000028930817444274473,
0.000002853064739947553,
0.0000028340379152097905,
0.000002780787396197553,
0.000002769261172421329,
0.000002731027712521853,
0.0000026837052966564687,
0.0000026701160402097904,
0.0000026596227600524477,
0.00000265656... |
1131_B. Draw! | 525 | 525_234 | You still have partial information about the score during the historic football match. You are given a set of pairs (a_i, b_i), indicating that at some point during the match the score was "a_i: b_i". It is known that if the current score is Β«x:yΒ», then after the goal it will change to "x+1:y" or "x:y+1". What is the l... | n=int(input())
count=1
a,b=0,0
for i in range(n):
c,d=map(int,input().split(' '))
if min(c,d)>=max(a,b):
if a!=b:
count+=min(c,d)-max(a,b)+1
else:
count+=min(c,d)-max(a,b)
a,b=c,d
print(count)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
0 0
0 0
0 0
| O(n) | 0 | {
"public_tests": [
{
"input": "3\n0 0\n0 0\n0 0\n",
"output": "1\n"
},
{
"input": "1\n5 4\n",
"output": "5\n"
},
{
"input": "3\n2 0\n3 1\n3 4\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "6\n0 0\n0 1\n1 1\n8 7\n8 8\n9 9\n",
"ou... | [
0.00002156432348120629,
0.00002017521616859703,
0.00001884057659527972,
0.00001852067701048951,
0.000018078856165319056,
0.000017668022522399477,
0.000017630846618225526,
0.0000173518239729021,
0.000017344038871284967,
0.000017320103201486016,
0.000017319724035729895,
0.00001707389567854021,
... |
399_A. Pages | 2967 | 2967_293 | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks... | n,p,k = map(int,input().split())
if((p-k)>1):
print("<<",end=" ")
for i in range(p-k,p+k+1):
if(i<1) or (i>n):
continue
elif(i==p):
print("(" + str(i) + ")",end=" ")
else:
print(str(i),end=" ")
if((p+k)<n):
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, ... | 6 5 2
| O(n*m) | 0.000005 | {
"public_tests": [
{
"input": "6 5 2\n",
"output": "<< 3 4 (5) 6 \n"
},
{
"input": "6 1 2\n",
"output": "(1) 2 3 >>\n"
},
{
"input": "8 5 4\n",
"output": "1 2 3 4 (5) 6 7 8 \n"
},
{
"input": "6 2 2\n",
"output": "1 (2) 3 4 >>\n"
},
... | [
0.00002433045940626158,
0.00001602412751311189,
0.000015851153204217658,
0.000012334103197943684,
0.000010272307173953316,
0.000008395704323360504,
0.000007568171765005557,
0.000007383613201648759,
0.000007316252443034457,
0.00000702743656215265,
0.000006686385212115599,
0.00000648969357878954... |
399_A. Pages | 2967 | 2967_59 | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks... | n,p,k=map(int,input().split(" "))
ans=""
if p-k>1:
ans+='<< '
for i in range(p-k, p+k+1):
if i>0 and i<=n:
if i==p:
ans+='('+str(p)+') '
else:
ans+=str(i)+' '
if p+k<n:
ans+='>>'
if ans[len(ans)-1]==" ":
print(ans[0:len(ans)-1])
else:
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, ... | 6 5 2
| O(n+m) | 0.000002 | {
"public_tests": [
{
"input": "6 5 2\n",
"output": "<< 3 4 (5) 6 \n"
},
{
"input": "6 1 2\n",
"output": "(1) 2 3 >>\n"
},
{
"input": "8 5 4\n",
"output": "1 2 3 4 (5) 6 7 8 \n"
},
{
"input": "6 2 2\n",
"output": "1 (2) 3 4 >>\n"
},
... | [
0.00000639189322006119,
0.000005355572702687938,
0.000005300907834353147,
0.000005039228925371505,
0.000004633065327250875,
0.00000413402186680507,
0.000003868271757539336,
0.000003848102976125437,
0.000003816026824737763,
0.00000381283972082605,
0.0000037118387237762233,
0.0000036627821172967... |
914_B. Conan and Agasa play a Card Game | 565 | 565_118 | Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it.
They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all c... | from pprint import pprint as pp
def GI(): return int(input())
def GIS(): return map(int, input().split())
def main():
GI()
l = list(GIS())
s = [0] * (10 ** 5 + 1)
for x in l:
s[x] += 1
for x in reversed(s):
if x % 2:
return "Conan"
return "Agasa"
print(main())
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
4 5 7
| O(n) | 0.000002 | {
"public_tests": [
{
"input": "3\n4 5 7\n",
"output": "Conan"
},
{
"input": "2\n1 1\n",
"output": "Agasa"
}
],
"private_tests": [
{
"input": "5\n1 4 4 5 5\n",
"output": "Conan"
},
{
"input": "4\n3 3 2 1\n",
"output": "Conan"
},
{... | [
0.021078402,
0.020871779000000035,
0.019866684,
0.000003859382375437063,
0.0000032940068427666086,
0.0000028279427584134617,
0.000002783665906359266,
0.000002742524188701923,
0.0000026541961593094407,
0.0000024630657916302453,
0.000002332257935423951,
0.0000023172882703234267,
0.000002309933... |
914_B. Conan and Agasa play a Card Game | 565 | 565_158 | Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it.
They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all c... | n=int(input())
arr=list(map(int,input().split()))
arrx=[]
arr.sort(reverse=True)
i=0
while(i<n):
count=0
val=arr[i]
while(i<n and arr[i]==val):
i+=1
count+=1
arrx.append(count)
flag=0
for i in range(len(arrx)):
if(arrx[i]%2!=0):
flag=1
break
if(flag==0):
print('Agasa')
else:
print('Conan')
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
4 5 7
| O(nlogn) | 0.000008 | {
"public_tests": [
{
"input": "3\n4 5 7\n",
"output": "Conan"
},
{
"input": "2\n1 1\n",
"output": "Agasa"
}
],
"private_tests": [
{
"input": "5\n1 4 4 5 5\n",
"output": "Conan"
},
{
"input": "4\n3 3 2 1\n",
"output": "Conan"
},
{... | [
0.0000152958554783254,
0.00000923839766847746,
0.000009162181092792281,
0.000009052681049339573,
0.000008967419748696283,
0.00000894620226527086,
0.000008941841959333326,
0.000008863107985069616,
0.000008766879229594996,
0.00000874518427244145,
0.00000872996885298179,
0.000008617621794247581,
... |
489_C. Given Length and Sum of Digits... | 2282 | 2282_16 | You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pa... | n=input().split()
n[0]=int(n[0])
n[1]=int(n[1])
if n[1]==0:
if n[0]==1:
print('0 0')
if n[0]!=1:
print('-1 -1')
elif n[0]*9<n[1]:
print('-1 -1')
else:
i=(n[1]-1)//9
q=(n[1]-1)%9
mi=10**(n[0]-1)+q*10**i
while i>0:
mi+=9*10**(i-1)
i=i-1
ii=n[1]//9
qq=n[1... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2 15
| O(n**2) | 0.000006 | {
"public_tests": [
{
"input": "2 15\n",
"output": "69 96"
},
{
"input": "3 0\n",
"output": "-1 -1"
}
],
"private_tests": [
{
"input": "1 10\n",
"output": "-1 -1"
},
{
"input": "97 206\n",
"output": "10000000000000000000000000000000000000... | [
0.22671272950000004,
0.04386649527816902,
0.031079423147887326,
0.013905163000000002,
0.000605042440687354,
0.000489570832756595,
0.0003253772680745001,
0.00032084736042256514,
0.00027027742899125883,
0.00026493050643302006,
0.0002468118853728903,
0.0002149377644159226,
0.0002059088250558035... |
489_C. Given Length and Sum of Digits... | 2282 | 2282_437 | You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pa... | m, s = [int(a) for a in input().split()]
maxx=""
minn=""
s1 = s
s2 = s-1
if s==0 and m==1: print(0, 0)
elif s>9*m or s<1: print (-1, -1)
elif m==1: print(s, s)
else:
for a in range(m):
if s1>9:
maxx+=str(9)
s1-=9
elif s1==0:
maxx+=str(0)
else:
maxx+=str(s1)
s1=0
for a in range(m-1):
if s2>9:
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 15
| O(n) | 0.000005 | {
"public_tests": [
{
"input": "2 15\n",
"output": "69 96"
},
{
"input": "3 0\n",
"output": "-1 -1"
}
],
"private_tests": [
{
"input": "1 10\n",
"output": "-1 -1"
},
{
"input": "97 206\n",
"output": "10000000000000000000000000000000000000... | [
0.006108613626013212,
0.006097529471161506,
0.000058815127567744744,
0.000043647584821428566,
0.00003068576613035402,
0.00003061692825338724,
0.00002980220354840472,
0.000029785456198098778,
0.000027370512633850527,
0.000026596474172312062,
0.00002651186227054196,
0.000026366053757440476,
0.... |
489_C. Given Length and Sum of Digits... | 2282 | 2282_1118 | You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pa... | m,s=map(int,input().split())
def ismax(m,s):
op1=str()
if s==0:
return(-1)
elif s>m*9:
return(-1)
else:
for i in range(m):
if s>9:
op1=op1+'9'
s-=9
elif 0<s<=9:
op1=op1+str(s)
s=0
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2 15
| O(nlogn) | 0.00004 | {
"public_tests": [
{
"input": "2 15\n",
"output": "69 96"
},
{
"input": "3 0\n",
"output": "-1 -1"
}
],
"private_tests": [
{
"input": "1 10\n",
"output": "-1 -1"
},
{
"input": "97 206\n",
"output": "10000000000000000000000000000000000000... | [
0.00007689578209680945,
0.00007673920989947553,
0.00004912688070913461,
0.0000444552125628278,
0.00004431688177447553,
0.00004168962521853147,
0.00004166294181599651,
0.0000415790821131993,
0.00004130604535893794,
0.00004117424399038462,
0.00004041248910074301,
0.00004039389197358631,
0.0000... |
p03687 AtCoder Grand Contest 016 - Shrinking | 294 | 294_56 | Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:
* For each i (1 β€ i β€ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.
There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operati... | s = input()
exitLower = list(set(list(s)))
m = len(s)
for alp in exitLower:
SL = list(s)
cnt = 0
while len(set(SL)) > 1:
for i in range(len(SL)-1):
if SL[i+1] == alp:
SL[i] = alp
SL.pop()
cnt += 1
m = min(m,cnt)
print(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, ... | serval | O(n**2) | 0.000029 | {
"public_tests": [
{
"input": "serval",
"output": "3"
},
{
"input": "whbrjpjyhsrywlqjxdbrbaomnw",
"output": "8"
},
{
"input": "jackal",
"output": "2"
},
{
"input": "zzz",
"output": "0"
}
],
"private_tests": [],
"generated_tests": [... | [
0.00037000136455787424,
0.0003567679445443766,
0.00021885334843768295,
0.00015645579249962344,
0.00012763708793923234,
0.00011369894798329743,
0.00010818250941979613,
0.00010795661263413779,
0.00009858968018704395,
0.00009385720592898478,
0.00008964122173650202,
0.00008895879279518196,
0.000... |
p03687 AtCoder Grand Contest 016 - Shrinking | 294 | 294_131 | Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:
* For each i (1 β€ i β€ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.
There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operati... | from sys import stdin
s= (stdin.readline().rstrip())
f = lambda a, b: abs(a-b-1)
diff = lambda ls: map(f, ls[1:], ls)
ans = 100
for i in set(s):
ans = min(ans,max([len(j) for j in s.split(i)]))
print(ans) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | serval | O(n) | 0.000002 | {
"public_tests": [
{
"input": "serval",
"output": "3"
},
{
"input": "whbrjpjyhsrywlqjxdbrbaomnw",
"output": "8"
},
{
"input": "jackal",
"output": "2"
},
{
"input": "zzz",
"output": "0"
}
],
"private_tests": [],
"generated_tests": [... | [
0.00017448615963723776,
0.00008930180326704545,
0.00008143791694438374,
0.00007824102392919581,
0.000059918465581293704,
0.000059157254589160845,
0.00005841908728966346,
0.00005813987120301574,
0.000058105722560642484,
0.00005697677117023602,
0.000056728813524366256,
0.00005487784973229896,
... |
1150_C. Prefix Sum Primes | 3034 | 3034_1 | We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it β either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in a... | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
count = {1: 0, 2: 0}
for i in a:
count[i] += 1
if count[1] >= 1 and count[2] >= 1:
ans = [2] + [1] + [2]*(count[2]-1) + [1]*(count[1] - 1)
elif count[1] == 0:
ans = [2] * count[2]
elif count[2] == 0:
ans = [1... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 9
1 1 2 1 1 1 2 1 1
| O(n) | 0.000008 | {
"public_tests": [
{
"input": "9\n1 1 2 1 1 1 2 1 1\n",
"output": "2 1 2 1 1 1 1 1 1\n"
},
{
"input": "5\n1 2 1 2 1\n",
"output": "2 1 2 1 1\n"
}
],
"private_tests": [
{
"input": "5\n1 2 2 2 2\n",
"output": "2 1 2 2 2\n"
},
{
"input": "2\n2 2\... | [
0.06858335400000001,
0.00003141408518629807,
0.00002402961229785839,
0.000020865091640310918,
0.000020742664690777976,
0.000018348201349431822,
0.000016565582304414334,
0.000016489538529829553,
0.000016108313005354023,
0.000014827594501201921,
0.000014095078493771854,
0.000013978175371503495,
... |
1150_C. Prefix Sum Primes | 3034 | 3034_57 | We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it β either 1 or 2.
However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in a... | n=int(input())
y=list(map(int,input().split()))
if n==1:
print(y[0])
else:
even=y.count(2)
odd=y.count(1)
if even==0 or odd==0:
print(*y)
else:
y=sorted(y)
y.reverse()
i=0
while i<n:
if y[i]==1:
break
i+=1
t=y[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, ... | 9
1 1 2 1 1 1 2 1 1
| O(nlogn) | 0.000029 | {
"public_tests": [
{
"input": "9\n1 1 2 1 1 1 2 1 1\n",
"output": "2 1 2 1 1 1 1 1 1\n"
},
{
"input": "5\n1 2 1 2 1\n",
"output": "2 1 2 1 1\n"
}
],
"private_tests": [
{
"input": "5\n1 2 2 2 2\n",
"output": "2 1 2 2 2\n"
},
{
"input": "2\n2 2\... | [
0.00022491686501584357,
0.000029177052013880916,
0.00002868214272733138,
0.00002861398696643131,
0.000028591280739083203,
0.00002854192315618242,
0.000028239937032475225,
0.00002820067467684289,
0.000028189648984889192,
0.000027698712882855037,
0.00002755862399527765,
1.1909405048076925e-7
] |
764_A. Taymyr is calling you | 1738 | 1738_180 | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day cons... | abc= input().split()
a= int(abc[0])
b= int(abc[1])
c= int(abc[2])
d= c//a
e=c//b
test=[]
test2=[]
count=0
for i in range(1,d+1):
test.append(i*a)
for i in range(1,e+1):
if i*b in test:
count=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, ... | 1 1 10
| O(n**2) | 0 | {
"public_tests": [
{
"input": "1 1 10\n",
"output": "10\n"
},
{
"input": "2 3 9\n",
"output": "1\n"
},
{
"input": "1 2 5\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "972 1 203\n",
"output": "0\n"
},
{
"input": "6... | [
0.000041613100034929575,
0.000001810399933779264,
0.0000015042247079138421,
3.472595783283769e-7,
2.2969974851433994e-7,
2.296041380063394e-7,
2.2441002528530197e-7,
2.2417579019533621e-7,
2.238768323645683e-7,
2.2284955451121041e-7,
2.2230823357623874e-7,
2.2171112075003545e-7,
2.2167334641... |
764_A. Taymyr is calling you | 1738 | 1738_24 | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day cons... | m = [int(n) for n in input().split()]
count = 0
for i in range(1,m[2]+1):
if i%m[0] == 0 and i%m[1] == 0:
count = 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, ... | 1 1 10
| O(n) | 0.000004 | {
"public_tests": [
{
"input": "1 1 10\n",
"output": "10\n"
},
{
"input": "2 3 9\n",
"output": "1\n"
},
{
"input": "1 2 5\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "972 1 203\n",
"output": "0\n"
},
{
"input": "6... | [
0.00010499856366777753,
0.0000357330649448208,
0.00003439385169225307,
0.00003426609898109703,
0.000033931730639477716,
0.00003340164967356862,
0.000023553137347027973,
0.000017930186339051576,
0.000017888827674278847,
0.0000177738280430507,
0.00001746245660784528,
0.000017461847178212416,
0... |
52_A. 123-sequence | 2193 | 2193_138 | There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains an integer n (1 β€ n β€ 106). The second line contains a sequence o... | import sys
n_nums = int(sys.stdin.readline())
values = [int(x) for x in sys.stdin.readline().split()]
one, two, three = 0, 0, 0
for i in values:
if i == 1:
one += 1
if i == 2:
two += 1
if i == 3:
three += 1
result = one + two + three - max(one, two, three)
print(result)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 9
1 3 2 2 2 1 1 2 3
| O(n) | 0.000004 | {
"public_tests": [
{
"input": "9\n1 3 2 2 2 1 1 2 3\n",
"output": "5\n"
}
],
"private_tests": [
{
"input": "1\n1\n",
"output": "0\n"
},
{
"input": "2\n3 2\n",
"output": "1\n"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2\n",
"output":... | [
0.000010213638562609267,
0.000009107361451048951,
0.000008560072101726398,
0.000008410704340581294,
0.000008404965676901224,
0.000008396724199628496,
0.000007263138385052447,
0.000006483129001857518,
0.000006359349281577797,
0.000006244130244755245,
0.000006161197497814685,
0.00000609696335500... |
52_A. 123-sequence | 2193 | 2193_70 | There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains an integer n (1 β€ n β€ 106). The second line contains a sequence o... | n = int(input())
l = list(map(int,input().split()))
freq = {}
for item in l:
if (item in freq):
freq[item] += 1
else:
freq[item] = 1
l = list(sorted(freq.values(),reverse=True))
l.remove(l[0])
print(sum(l))
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 9
1 3 2 2 2 1 1 2 3
| O(nlogn) | 0.000024 | {
"public_tests": [
{
"input": "9\n1 3 2 2 2 1 1 2 3\n",
"output": "5\n"
}
],
"private_tests": [
{
"input": "1\n1\n",
"output": "0\n"
},
{
"input": "2\n3 2\n",
"output": "1\n"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2\n",
"output":... | [
0.000028065074117242925,
0.000027826829105092145,
0.000027610124015678537,
0.000023872956337746405,
0.000023658734971269225,
0.000023564148328234268,
0.00002328495278956579,
0.000020411168241298573,
0.000008429863294908216,
0.0000011598156727295213,
3.494198262674825e-7,
3.490392127403846e-7,
... |
1494_A. ABC String | 1414 | 1414_23 | You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting charac... | def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
import string
import sys
from heapq import heappop , heappush, heapify
from bisect impor... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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
AABBAC
CACA
BBBBAC
ABCA
| O(n**2) | 0.00003 | {
"public_tests": [
{
"input": "4\nAABBAC\nCACA\nBBBBAC\nABCA\n",
"output": "\nYES\nYES\nNO\nNO\n"
}
],
"private_tests": [
{
"input": "12\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\n",
"output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n"
},
{
... | [
0.00010357873204331648,
0.00009257215106089689,
0.00007834430611616484,
0.00006360504422010482,
0.00005802288230418805,
0.00005729638184518072,
0.00005646676174785389,
0.00005413071178368237,
0.0000513293290147314,
0.000049417497897775185,
0.000048207961998797084,
0.000037264686053371476,
0.... |
1494_A. ABC String | 1414 | 1414_8 | You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting charac... | def solve(n, a):
cnt = {"A": 0, "B": 0, "C": 0}
for i in range(n):
cnt[a[i]] += 1
vs = sorted(cnt.values())
if vs[0] + vs[1] != vs[2]:
return False
first = a[0]
last = a[-1]
if first == last:
return False
other = first
if cnt[first] == vs[2]:
other = l... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4
AABBAC
CACA
BBBBAC
ABCA
| O(n) | 0.000079 | {
"public_tests": [
{
"input": "4\nAABBAC\nCACA\nBBBBAC\nABCA\n",
"output": "\nYES\nYES\nNO\nNO\n"
}
],
"private_tests": [
{
"input": "12\nCA\nBA\nCC\nAC\nCA\nCB\nAC\nBB\nAB\nCB\nBA\nCA\n",
"output": "YES\nYES\nNO\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\n"
},
{
... | [
0.00016107011699938704,
0.00015751137316864707,
0.0001367679870269275,
0.00012702445430502835,
0.00012117255597155594,
0.00010542552182946798,
0.00010331776608755961,
0.00009338167759267199,
0.00007949805453122257,
0.00007915984591742474,
0.00006411538490714814,
0.0000625753629611297,
0.0000... |
1008_B. Turn the Rectangles | 396 | 396_361 | There are n rectangles in a row. You can either turn each rectangle by 90 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangle... | n = int(input())
dimensions = []
flag = 1
while n > 0:
dimensions.append(list(map(int, input().split())))
n -= 1
maximum = max(dimensions[0])
for i in range(1, len(dimensions)):
if maximum >= max(dimensions[i]):
maximum = max(dimensions[i])
continue
elif maximum >= min(dimensions[i]):... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
3 4
4 6
3 5
| O(n*m) | 0.000002 | {
"public_tests": [
{
"input": "3\n3 4\n4 6\n3 5\n",
"output": "YES\n"
},
{
"input": "2\n3 4\n5 5\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "4\n10 10\n8 8\n8 15\n9 9\n",
"output": "NO\n"
},
{
"input": "3\n10 10\n1 100\n20 20\n",
... | [
0.000003908446937827797,
0.0000035921687609265743,
0.0000029231363499781473,
0.0000027698642100087413,
0.000002714620684003497,
0.000002704055916739511,
0.0000026699717274912587,
0.000002656705337631119,
0.0000026360405649038464,
0.0000026190070886145107,
0.0000026185014887456294,
0.0000026137... |
1008_B. Turn the Rectangles | 396 | 396_58 | There are n rectangles in a row. You can either turn each rectangle by 90 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangle... | from math import inf
n = int(input())
last = inf
flag = True
for _ in range(n):
w, h = map(int, input().split(" "))
if h < w:
w, h = h, w
if h <= last:
last = h
elif w <= last:
last = w
else:
flag = False
break
if flag:
print("YES")
else:
print("NO... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
3 4
4 6
3 5
| O(n) | 0 | {
"public_tests": [
{
"input": "3\n3 4\n4 6\n3 5\n",
"output": "YES\n"
},
{
"input": "2\n3 4\n5 5\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "4\n10 10\n8 8\n8 15\n9 9\n",
"output": "NO\n"
},
{
"input": "3\n10 10\n1 100\n20 20\n",
... | [
0.00003298833911986451,
0.00003091843393520542,
0.0000305915152152535,
0.00003050219501201923,
0.000030130276496940565,
0.000019073780730987762,
0.000014753088505244755,
0.00001353199160019668,
0.000012574050111997377,
0.000012293328930834792,
0.000011974346959680946,
0.000011963545236013987,
... |
1285_D. Dr. Evil Underscores | 1870 | 1870_81 | Today, as a friendship gift, Bakry gave Badawy n integers a_1, a_2, ..., a_n and challenged him to choose an integer X such that the value \underset{1 β€ i β€ n}{max} (a_i β X) is minimum possible, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
As always, Badawy is too ... |
n=int(input())
arr=list(map(int,input().split()))
def solve(arr,bit):
if len(arr)==0 or bit <0:
return 0
l=[]
r=[]
for i in arr:
if (i>>bit)&1==0:
l.append(i)
else:
r.append(i)
if len(l)==0:
return solve(r,bit-1)
if len(r)==0:
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, ... | 2
1 5
| O(n) | 0.000096 | {
"public_tests": [
{
"input": "2\n1 5\n",
"output": "4"
},
{
"input": "3\n1 2 3\n",
"output": "2"
}
],
"private_tests": [
{
"input": "1\n1073741823\n",
"output": "0"
},
{
"input": "2\n0 1073741823\n",
"output": "536870912"
},
{
... | [
0.0001439889064275568,
0.00014237925012292396,
0.0001343755467793925,
0.00013299873470279722,
0.00013135862934331294,
0.0001297048765433785,
0.00011975839465417397,
0.00011637659827086977,
0.00011526023072825614,
0.00011316269966947116,
0.00011311568101234704,
0.00011112696256282782,
0.00011... |
1285_D. Dr. Evil Underscores | 1870 | 1870_58 | Today, as a friendship gift, Bakry gave Badawy n integers a_1, a_2, ..., a_n and challenged him to choose an integer X such that the value \underset{1 β€ i β€ n}{max} (a_i β X) is minimum possible, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
As always, Badawy is too ... | n = int(input())
seq = sorted(list(map(int, input().split())))
#Left (inc), Right(exc), bit to check, value to add
queue = [(0,n,30,0)]
best = 2 ** 30
while queue:
l, r, b, v = queue.pop()
if b >= 0:
mask = 1 << b
if not mask & seq[l] and mask & seq[r - 1]:
for i in range(... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2
1 5
| O(nlogn) | 0.000005 | {
"public_tests": [
{
"input": "2\n1 5\n",
"output": "4"
},
{
"input": "3\n1 2 3\n",
"output": "2"
}
],
"private_tests": [
{
"input": "1\n1073741823\n",
"output": "0"
},
{
"input": "2\n0 1073741823\n",
"output": "536870912"
},
{
... | [
0.001185442030172414,
0.00010921770804195807,
0.00010216088098229895,
0.00008306292998798076,
0.00008197568213232082,
0.00006122550693837414,
0.00003042770276988636,
0.000009841181169435163,
0.000007838349212944684,
0.000005893743751900934,
0.000005539913474224657,
0.000004900571918634675,
0... |
279_A. Point on Spiral | 2847 | 2847_21 | Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thus, t... | x, y = map(int, input().split())
cur_x, cur_y = 0, 0
i = 1
pos = 0
sign = [(1, 0), (0, 1), (-1, 0), (0, -1)]
ans = 0
j = 0
while cur_x != x or cur_y != y:
if j == i:
j = 0
if pos % 2 == 1:
i += 1
pos = (pos + 1) % 4
ans += 1
cur_x = cur_x + si... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 0
| O(n**2) | 0.000002 | {
"public_tests": [
{
"input": "1 0\n",
"output": "0\n"
},
{
"input": "0 0\n",
"output": "0\n"
},
{
"input": "0 1\n",
"output": "2\n"
},
{
"input": "-1 -1\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "17 25\n",
... | [
0.000008876592166491679,
0.0000045314848342209015,
0.000002099150327619131,
0.0000019010815506947797,
0.0000017912231345749714,
0.0000016725701359763711,
0.0000015904809859372214,
0.0000010588019060589478,
0.0000010196365537908407,
9.830537548770238e-7,
7.424034445716105e-7,
5.855186676583469e... |
279_A. Point on Spiral | 2847 | 2847_36 | Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thus, t... | U=1
D=-1
x,y=map(int,input().split())
k=A=B=0
while 1:
a,b=U,B;k+=1
if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break
A=a;b=U;k+=1
if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break
B=b;a=D;k+=1
if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=B):break
A=a;b=D;k+=1
if (A<=x<=a or a<=x<=A)and(B<=y<=b or b<=y<=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, ... | 1 0
| O(n) | 0.000001 | {
"public_tests": [
{
"input": "1 0\n",
"output": "0\n"
},
{
"input": "0 0\n",
"output": "0\n"
},
{
"input": "0 1\n",
"output": "2\n"
},
{
"input": "-1 -1\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "17 25\n",
... | [
0.00005443138786604021,
0.000008423445107626747,
0.000008240645856097028,
0.000006365983282342657,
0.000004833793993116259,
0.000003063761431927448,
0.0000028709705802010485,
0.000002102293815559441,
0.0000014267415592220282
] |
279_A. Point on Spiral | 2847 | 2847_45 | Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thus, t... | '''l = [[(0, 0), (1, 0)],
[(1,β0),β(1,β1)],
[(1,β1),β(-1,β1)],
[(-1,β1),β(-1,β-1)],
[(-1,β-β1),β(2,β-1)],
[(2,β-1),β(2,β2)]]
'''
'''
pattern er shudhone na paria
last e net theke copy marcha
pattern copy marcha re.
'''
x,y = map(int, input().split())
if y >= x and y < -x:
print(-4*x-1)
elif... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 0
| O(1) | 0.000002 | {
"public_tests": [
{
"input": "1 0\n",
"output": "0\n"
},
{
"input": "0 0\n",
"output": "0\n"
},
{
"input": "0 1\n",
"output": "2\n"
},
{
"input": "-1 -1\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "17 25\n",
... | [
0.0037606989999999924,
0.000340458,
0.000008769999999999999,
0.000008268000000000003,
0.000008193000000000001,
0.000007788999999999996,
0.0000058910000000000085,
0.000005725499999999998,
0.000004618000000000002,
0.000003237000000000003,
0.0000031035000000000017,
0.0000029064999999999967,
0.0... |
1422_A. Fence | 2577 | 2577_283 | Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths a, b, and c. Now he needs to find out some possible integer length d of the fourth straight fence segment so that he can build the fence using these four... | import sys
import math
input = sys.stdin.readline
def inInt():
return int(input())
def inStr():
return input().strip("\n")
def inIList():
return (list(map(int, input().split())))
def inSList():
return (input().split())
#########################################
def solve(l):
print(sum(l) - 1)
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2
1 2 3
12 34 56
| O(n*m) | 0.000003 | {
"public_tests": [
{
"input": "2\n1 2 3\n12 34 56\n",
"output": "5\n101\n"
}
],
"private_tests": [
{
"input": "1\n5 4 3\n",
"output": "11\n"
},
{
"input": "1\n2434 2442 14\n",
"output": "4889\n"
},
{
"input": "1\n3 4 5\n",
"output": "11\... | [
0.00017808333442143794,
0.000007093000519012237,
0.000003641117911385489,
0.0000036113323453889863,
0.0000033805921383304194,
0.0000032591316788680074,
0.0000032536617952360146,
0.0000031862634943181827,
0.0000031039679031905595,
0.0000030228281796328674,
0.000002999139341127623,
0.00000299048... |
1422_A. Fence | 2577 | 2577_822 | Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths a, b, and c. Now he needs to find out some possible integer length d of the fourth straight fence segment so that he can build the fence using these four... | import math
T = int(input())
#lets = 'abcdefghijklmnopqrstuvwxyz'
#key = {lets[i]:i for i in range(26)}
for t in range(T):
#n = int(input())
a,b,c = map(int,input().split())
#a = list(map(int,input().split()))
#a = input()
d = False
print(a+b+c-1)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2
1 2 3
12 34 56
| O(n) | 0.000009 | {
"public_tests": [
{
"input": "2\n1 2 3\n12 34 56\n",
"output": "5\n101\n"
}
],
"private_tests": [
{
"input": "1\n5 4 3\n",
"output": "11\n"
},
{
"input": "1\n2434 2442 14\n",
"output": "4889\n"
},
{
"input": "1\n3 4 5\n",
"output": "11\... | [
0.0000405888535975743,
0.00004007272373524913,
0.00003804945838341347,
0.000037967302447552453,
0.000037733148888221155,
0.000037728556435751746,
0.00003721507685478584,
0.00003682368692635489,
0.00003614325706129808,
0.00003593210661604021,
0.000035812551819274474,
0.00003577688262128497,
0... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.