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 |
|---|---|---|---|---|---|---|---|---|---|---|
1373_E. Sum of Digits | 554 | 554_70 | Let f(x) be the sum of digits of a decimal number x.
Find the smallest non-negative integer x such that f(x) + f(x + 1) + ... + f(x + k) = n.
Input
The first line contains one integer t (1 ≤ t ≤ 150) — the number of test cases.
Each test case consists of one line containing two integers n and k (1 ≤ n ≤ 150, 0 ≤ k ... | import sys
sys.setrecursionlimit(10**7)
for _ in range(int(input())):
N, K = map(int, input().split());ans = float("inf")
for i in range(100 - K):
val = 0
for j in range(i, i + K + 1):val += sum(list(map(int, list(str(j)))))
if (N - val) % (K + 1) == 0 and N >= val:x = int((N - val) // (K + 1));tail = str(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, ... | 7
1 0
1 1
42 7
13 7
99 1
99 0
99 2
| O(n**2) | 0.00721 | {
"public_tests": [
{
"input": "7\n1 0\n1 1\n42 7\n13 7\n99 1\n99 0\n99 2\n",
"output": "1\n0\n4\n-1\n599998\n99999999999\n7997\n"
}
],
"private_tests": [
{
"input": "2\n13 9\n17 9\n",
"output": "-1\n-1\n"
}
],
"generated_tests": [
{
"input": "2\n13 9\n27 9\n"... | [
0.020135650257831327,
0.015182825397008057,
0.007361850837745397,
0.007267902277561729,
0.007210133120976432,
0.00711978064859673,
0.0037126188573545762,
0.003699232141313913,
0.003415606321299556,
0.003411977981023064,
0.0033453714277162836,
0.002947371735619674,
0.0027593811402487033,
0.... |
1373_E. Sum of Digits | 554 | 554_107 | Let f(x) be the sum of digits of a decimal number x.
Find the smallest non-negative integer x such that f(x) + f(x + 1) + ... + f(x + k) = n.
Input
The first line contains one integer t (1 ≤ t ≤ 150) — the number of test cases.
Each test case consists of one line containing two integers n and k (1 ≤ n ≤ 150, 0 ≤ k ... | a=[[1, 0, -1, -1, -1, -1, -1, -1, -1, -1], [2, -1, -1, -1, -1, -1, -1, -1, -1, -1], [3, 1, 0, -1, -1, -1, -1, -1, -1, -1], [4, -1, -1, -1, -1, -1, -1, -1, -1, -1], [5, 2, -1, -1, -1, -1, -1, -1, -1, -1], [6, -1, 1, 0, -1, -1, -1, -1, -1, -1], [7, 3, -1, -1, -1, -1, -1, -1, -1, -1], [8, -1, -1, -1, -1, -1, -1, -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, ... | 7
1 0
1 1
42 7
13 7
99 1
99 0
99 2
| O(n) | 0.000032 | {
"public_tests": [
{
"input": "7\n1 0\n1 1\n42 7\n13 7\n99 1\n99 0\n99 2\n",
"output": "1\n0\n4\n-1\n599998\n99999999999\n7997\n"
}
],
"private_tests": [
{
"input": "2\n13 9\n17 9\n",
"output": "-1\n-1\n"
}
],
"generated_tests": [
{
"input": "2\n13 9\n27 9\n"... | [
0.0648665333220339,
0.03032014944658635,
0.026764421270682733,
0.01717254610120482,
0.015831046674698798,
0.013693440572688915,
0.012124690791522825,
0.011862469664940546,
0.007891690915228232,
0.00508893496893595,
0.00465506909483203,
0.003504989753670341,
0.0032229883576324566,
0.0031400... |
56_B. Spoilt Permutation | 2771 | 2771_26 | Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order... | n = int(input())
arr = [0]+list(map(int, input().split()))
l, r = -1, -1
i = 0
while(i<n and arr[i]+1==arr[i+1]):
i+=1
l = i
i+=1
while(i<n and arr[i]-1==arr[i+1]):
i+=1
r = i
i+=1
while(i<n and arr[i]+1==arr[i+1]):
i+=1
if(r != -1 and i>= n-1):
print(l+1, r)
else:
print(0, 0) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 8
1 6 5 4 3 2 7 8
| O(n) | 0.000004 | {
"public_tests": [
{
"input": "8\n1 6 5 4 3 2 7 8\n",
"output": "2\n6\n"
},
{
"input": "4\n2 3 4 1\n",
"output": "0\n0\n"
},
{
"input": "4\n1 2 3 4\n",
"output": "0\n0\n"
}
],
"private_tests": [
{
"input": "8\n1 3 2 4 6 5 7 8\n",
"output... | [
0.000015639622265625,
0.000010916924019340035,
0.000004435388548951049,
0.00000431337495902535,
0.000003951992337740385,
0.000003824732066761364,
0.0000036022890761582173,
0.0000035971819001311186,
0.000003554145787805944,
0.0000035498152999344404,
0.0000035234180506993007,
0.00000352042787095... |
56_B. Spoilt Permutation | 2771 | 2771_23 | Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order... | n=int(input())
a=list(map(int,input().split()))
s=sorted(a)
l=0
r=0
c=0
b=0
for i in range(1,n):
if a[i]<a[i-1]:
l=i-1 if c==0 else l
c=1
else:
if c==1:
r=i
b=1
break
if b==0 and c==1:
r=n
a1=a[l:r]
a1.reverse()
a=a[:l]+a1+a[r:]
if a==s and 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, ... | 8
1 6 5 4 3 2 7 8
| O(nlogn) | 0.000028 | {
"public_tests": [
{
"input": "8\n1 6 5 4 3 2 7 8\n",
"output": "2\n6\n"
},
{
"input": "4\n2 3 4 1\n",
"output": "0\n0\n"
},
{
"input": "4\n1 2 3 4\n",
"output": "0\n0\n"
}
],
"private_tests": [
{
"input": "8\n1 3 2 4 6 5 7 8\n",
"output... | [
0.00008628519598635348,
0.00005706354842624325,
0.000029595642148768025,
0.000028874080725504144,
0.000028600558106210573,
0.000028416117334316017,
0.000028277371401154257,
0.000028208844841186323,
0.000028193785840457807,
0.000028190535167840395,
0.000028174370107281165,
0.0000281300305513248... |
785_B. Anton and Classes | 1177 | 1177_230 | Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th v... | n=int(input())
l1=1000000005
z2=1000000005
l2=0
z1=0
for i in range(0,n):
x,y=input().split(" ")
x,y=int(x),int(y)
l1=min(y,l1)
z1=max(z1,x)
m=int(input())
for i in range(0,m):
x,y=input().split(" ")
x,y=int(x),int(y)
l2=max(x,l2)
z2=min(z2,y)
o=max(z1-z2,l2-l1)
if(o<0):
pri... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
1 5
2 6
2 3
2
2 4
6 8
| O(n) | 0.000007 | {
"public_tests": [
{
"input": "3\n1 5\n2 6\n2 3\n2\n2 4\n6 8\n",
"output": "3\n"
},
{
"input": "3\n1 5\n2 6\n3 7\n2\n2 4\n1 4\n",
"output": "0\n"
}
],
"private_tests": [
{
"input": "1\n200000000 200000001\n1\n200000000 200000001\n",
"output": "0\n"
},
... | [
0.000010618429843822398,
0.000009991765411279206,
0.000009638869944084563,
0.000009534288109839448,
0.000009298545766916362,
0.000009226253113048187,
0.000009099320214452829,
0.000008830324516747293,
0.000008672576139100813,
0.00000854763158258247,
0.000008425559373102456,
0.000008248646000305... |
785_B. Anton and Classes | 1177 | 1177_9 | Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th v... | n=int(input())
c=[]
for i in range(n):
c.append(list(map(int,input().split())))
m=int(input())
p=[]
for i in range(m):
p.append(list(map(int,input().split())))
c.sort()
p.sort()
ans=0
for i in range(n):
ans=max(ans,p[-1][0]-c[i][1])
for i in range(m):
ans=max(ans,c[-1][0]-p[i][1])
print(ans) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
1 5
2 6
2 3
2
2 4
6 8
| O(nlogn) | 0.000039 | {
"public_tests": [
{
"input": "3\n1 5\n2 6\n2 3\n2\n2 4\n6 8\n",
"output": "3\n"
},
{
"input": "3\n1 5\n2 6\n3 7\n2\n2 4\n1 4\n",
"output": "0\n"
}
],
"private_tests": [
{
"input": "1\n200000000 200000001\n1\n200000000 200000001\n",
"output": "0\n"
},
... | [
0.00006910160976606456,
0.00006780020370428992,
0.00006746829821375641,
0.00006610122325886574,
0.00006586456979069838,
0.00006552274124072993,
0.00006550414997884824,
0.00006346037535864445,
0.00006275951429829435,
0.00006251034841102882,
0.0000614893164503049,
0.0000610960123485923,
0.0000... |
1205_A. Almost Equal | 1015 | 1015_168 | You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied:
For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more th... | n = int(input())
l = [0 for i in range(2*n+1)]
if n%2 == 0:
print('NO')
else:
toggle = True
for i in range(1,n+1):
if toggle:
l[i] = 2*i-1
l[i+n] = 2*i
toggle = False
else:
l[i] = 2*i
l[i+n] = 2*i -1
toggle = True
pr... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4
| O(n) | 0.000001 | {
"public_tests": [
{
"input": "4\n",
"output": "NO\n"
},
{
"input": "3\n",
"output": "YES\n1 4 5 2 3 6\n"
}
],
"private_tests": [
{
"input": "11\n",
"output": "YES\n1 4 5 8 9 12 13 16 17 20 21 2 3 6 7 10 11 14 15 18 19 22\n"
},
{
"input": "2\n... | [
0.00003311014169034092,
0.000029563995738636365,
0.000024711577879152097,
0.000022523316051136364,
0.000018778982449191437,
0.000018261375245847904,
0.00001813234231588724,
0.000017967489032451923,
0.00001749261078179633,
0.000017116025540865386,
0.000014848048636909966,
0.00001328667119208916... |
1205_A. Almost Equal | 1015 | 1015_129 | You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied:
For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more th... | n=int(input())
n*=n%2
print('YNEOS'[n<1::2],*(i%n*2+i%2+1for i in range(2*n))) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4
| O(1) | 0.000001 | {
"public_tests": [
{
"input": "4\n",
"output": "NO\n"
},
{
"input": "3\n",
"output": "YES\n1 4 5 2 3 6\n"
}
],
"private_tests": [
{
"input": "11\n",
"output": "YES\n1 4 5 8 9 12 13 16 17 20 21 2 3 6 7 10 11 14 15 18 19 22\n"
},
{
"input": "2\n... | [
0.000013394500000000002,
0.000012461500000000003,
0.000007847000000000001,
0.000003730500000000001,
0.0000032069999999999983,
0.0000031084999999999923,
0.0000025295000000000035,
0.0000025065000000000005,
0.0000024120000000000033,
0.000002069500000000001,
0.000001995999999999999,
0.000001863500... |
8_B. Obsession with Robots | 949 | 949_67 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ... | # maa chudaaye duniya
d = [[0,1], [0, -1], [1, 0], [-1, 0], [0, 0]]
path = input()
vis = []
cur = [0, 0]
f = True
for p in path:
prev = cur
if p == 'L': index = 0
elif p == 'R' : index = 1
elif p == 'U' : index = 2
else: index = 3
cur = [cur[0] + d[index][0], cur[1] + d[index][1]]
if cur in vis:
f = False
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | RRUULLDD
| O(n**2) | 0.000002 | {
"public_tests": [
{
"input": "RRUULLDD\n",
"output": "BUG\n"
},
{
"input": "LLUUUR\n",
"output": "OK\n"
}
],
"private_tests": [
{
"input": "DDUL\n",
"output": "BUG\n"
},
{
"input": "LLLLLLLLRRRRDDDDDDDUUUUUU\n",
"output": "BUG\n"
},... | [
0.00004781247305856427,
0.000031377263055493615,
0.000019517222376374967,
0.0000015511103702201754,
5.949892933618816e-7,
4.0067665952890634e-7,
3.6356987017392416e-7,
7.241830045919362e-8,
7.173701750967474e-8
] |
8_B. Obsession with Robots | 949 | 949_38 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ... | s=input()
x,y=0,0
used=set()
used.add((x,y))
bo=0
for e in s:
if(e=='L'):
x+=1
elif(e=='R'):
x-=1
elif(e=='U'):
y+=1
else:
y-=1
a=(x-1,y) in used
b=(x+1,y) in used
c=(x,y-1) in used
d=(x,y+1) in used
if(a+b+c+d>1):
bo=1
if((x,y) in used):
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | RRUULLDD
| O(n) | 0.000016 | {
"public_tests": [
{
"input": "RRUULLDD\n",
"output": "BUG\n"
},
{
"input": "LLUUUR\n",
"output": "OK\n"
}
],
"private_tests": [
{
"input": "DDUL\n",
"output": "BUG\n"
},
{
"input": "LLLLLLLLRRRRDDDDDDDUUUUUU\n",
"output": "BUG\n"
},... | [
0.00006521481129807694,
0.000044923789335664346,
0.000039862185560533226,
0.00003372823938756556,
0.00002411698322770979,
0.000016504349978146856,
0.000016083072893902975,
0.000011617448085118008,
0.000007945984962303323,
0.000005044230919471154,
0.000004414968176354896,
0.00000350598707932692... |
1101_A. Minimum Integer | 1548 | 1548_179 | You are given q queries in the following form:
Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].
Can you answer all the queries?
Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r.
Input
The first l... | def minint(n, a):
for i in range(n):
l=a[i][0]
r=a[i][1]
d=a[i][2]
if l<= d<=r:
print((r//d+1)*d)
else:
print(d)
n=int(input())
v=[]
for i in range(n):
a = input().strip().split()
a = list(map(int, a))
v.append(a)
minint(n, 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, ... | 5
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5
| O(n*m) | 0.000006 | {
"public_tests": [
{
"input": "5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n",
"output": "6\n4\n1\n3\n10\n"
}
],
"private_tests": [
{
"input": "20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000... | [
0.000011618923213505247,
0.000009527457140515734,
0.000009458836893575175,
0.000008694105414117133,
0.000008650060451267483,
0.000008564600947880245,
0.000008093587726726399,
0.0000073648316078452815,
0.000007134950475305945,
0.000007122584489729023,
0.000007111150786713287,
0.0000071007878059... |
1101_A. Minimum Integer | 1548 | 1548_552 | You are given q queries in the following form:
Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].
Can you answer all the queries?
Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r.
Input
The first l... | from math import ceil
n = int(input())
for i in range(n):
[l, r, d] = [int(j) for j in input().split()]
if l>d:
print(d)
else:
k = ceil(r/d)*d
print(k+d if k==r else 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
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5
| O(n) | 0 | {
"public_tests": [
{
"input": "5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n",
"output": "6\n4\n1\n3\n10\n"
}
],
"private_tests": [
{
"input": "20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000... | [
0.000030147058743990386,
0.000028179464912041084,
0.000027257514737215915,
0.00002706261614947553,
0.000026852322880244757,
0.0000266779350551792,
0.000026299233268684442,
0.000025703470867023603,
0.000025500352054195803,
0.000025034796683784967,
0.00002497760119372815,
0.000024936952565013115... |
p03683 AtCoder Regular Contest 076 - Reconciled? | 681 | 681_105 | Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there a... | mod=10**9+7
def main():
n, m = map(int, input().split())
if abs(n - m) > 1:
return 0
fact = 1
for i in range(1, min(n, m) + 1):
fact = fact * i % mod
if n == m:
return fact ** 2 * 2 % mod
else:
return fact * fact * (min(n, m) + 1) % mod
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, ... | 100000 100000 | O(n) | 0.067059 | {
"public_tests": [
{
"input": "100000 100000",
"output": "530123477"
},
{
"input": "3 2",
"output": "12"
},
{
"input": "1 8",
"output": "0"
},
{
"input": "2 2",
"output": "8"
}
],
"private_tests": [],
"generated_tests": [
{
... | [
0.09349935730508475,
0.09064635230508475,
0.09029902162711866,
0.08239851323728813,
0.08188765,
0.07121805022033899,
0.06857208530508475,
0.06770523557627119,
0.06744361188135593,
0.06705931903389832,
0.06704843444067797,
0.06689599206779662,
0.06679574959322035,
0.06636962715254238,
0.0... |
p03683 AtCoder Regular Contest 076 - Reconciled? | 681 | 681_52 | Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there a... | n,m=map(int,input().split())
mod=10**9+7
import math
if m==n:
print((math.factorial(n)*math.factorial(m)*2)%mod)
elif abs(n-m)==1:
print((math.factorial(n)*math.factorial(m))%mod)
else:
print(0)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 100000 100000 | O(1) | 0.000001 | {
"public_tests": [
{
"input": "100000 100000",
"output": "530123477"
},
{
"input": "3 2",
"output": "12"
},
{
"input": "1 8",
"output": "0"
},
{
"input": "2 2",
"output": "8"
}
],
"private_tests": [],
"generated_tests": [
{
... | [
0.002386608499999998,
0.0019885539999999896,
0.001327362999999998,
0.001203781000000001,
0.0011800109999999947,
0.0011065869999999922,
0.000953895499999996,
0.0008510245000000055,
0.00041699749999998814,
0.00015043200000003365,
0.0000031955,
0.0000028939999999999963,
0.000002547000000000001,... |
1099_B. Squares and Segments | 1011 | 1011_368 | Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with ve... | # http://codeforces.com/contest/1099/problem/B
n = int(input())
a = b = 1
while a * b < n:
if a < b:
a += 1
else:
b += 1
print(a+b)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4
| O(n) | 0 | {
"public_tests": [
{
"input": "4\n",
"output": "4\n"
},
{
"input": "1\n",
"output": "2\n"
},
{
"input": "2\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "10\n",
"output": "7\n"
},
{
"input": "87341\n",
"outpu... | [
0.000003500523519449301,
8.073824027534967e-8,
5.443048650568182e-8,
4.9823180725524476e-8,
4.0855277534965035e-8,
4.047747760052448e-8,
4.008373852709791e-8,
3.975213068181819e-8,
3.6222587958916084e-8,
3.5154720279720286e-8,
3.4513357736014e-8,
3.2443045236013984e-8,
3.219229403409091e-8,
... |
1099_B. Squares and Segments | 1011 | 1011_177 | Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with ve... | n = int(input())
rt = n**0.5
if rt % 1> 0.5:
b = int(rt) + 1
else:
b = int(rt)
# if rt * rt == n:
# print(int(rt) * 2)
# else:
# if n > a * b:
# print(max(a,b) * 2)
# else:
# print(a + b)
q = n // b
if n % b != 0:
q += 1
print(q + b) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4
| O(1) | 0.000001 | {
"public_tests": [
{
"input": "4\n",
"output": "4\n"
},
{
"input": "1\n",
"output": "2\n"
},
{
"input": "2\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "10\n",
"output": "7\n"
},
{
"input": "87341\n",
"outpu... | [
0.01608216450000001,
0.0018558350000000001,
0.0012118485000000012,
0.0010611869999999912,
0.0004726239999999979,
0.0001797515000000055,
0.000163837,
0.00002762350000000001,
0.000013486,
0.000011675,
0.0000116645,
0.000011479499999999997,
0.000009578499999999996,
0.000009472999999999996,
... |
633_A. Ebony and Ivory | 1678 | 1678_212 | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of dama... | a, b, c = map(int, input().split())
ok = False
for i in range(c//a+1):
#print(c-a*i)
#print((c-a*i)%b==0)
if c-a*i >= 0 and (c-a*i)%b==0:
ok = True
if ok:
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 11 6
| O(n) | 0.000001 | {
"public_tests": [
{
"input": "6 11 6\n",
"output": "YES"
},
{
"input": "3 2 7\n",
"output": "YES"
},
{
"input": "4 6 15\n",
"output": "NO"
}
],
"private_tests": [
{
"input": "15 12 26\n",
"output": "NO"
},
{
"input": "79 3... | [
0.000026309500000000003,
0.000011804000000000004,
0.000009350499999999998,
0.000007813390256228147,
0.000005932499999999991,
0.0000054528512893356645,
0.000004910606342875874,
0.000004020957522945805,
0.000004001183552775351,
0.0000035653516581075172,
0.000003562103236607143,
0.000003250945203... |
633_A. Ebony and Ivory | 1678 | 1678_68 | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of dama... | from math import ceil
def gcdEx(a,b,x,y):
if not a:
return 0,1,b
x1,y1,g=gcdEx(b%a,a,0,0)
x=y1-(b//a)*x1
y=x1
return x,y,g
a,b,c=map(int, input().split())
x,y,g=gcdEx(a,b,0,0)
if c%g:
print("No")
else:
x,y=x*c//g,y*c//g
k1=ceil(-x*g/b)
k2=(y*g)//a
c=abs(k2-k1+1)
p... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 6 11 6
| O(1) | 0.000006 | {
"public_tests": [
{
"input": "6 11 6\n",
"output": "YES"
},
{
"input": "3 2 7\n",
"output": "YES"
},
{
"input": "4 6 15\n",
"output": "NO"
}
],
"private_tests": [
{
"input": "15 12 26\n",
"output": "NO"
},
{
"input": "79 3... | [
0.0541946725,
0.03114800849999999,
0.0220334995,
0.018280900500000002,
0.007724315500000001,
0.006679084,
0.005321091000000001,
0.005298949,
0.005205953500000001,
0.0051602825,
0.0051287425,
0.001934865,
0.0014702705000000003,
0.0006836970000000005,
0.00013220900000000032,
0.000126246,... |
1352_A. Sum of Round Numbers | 1263 | 1263_2538 | A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are roun... | t = int(input())
for _ in range(t):
n = input()
k = len(n.replace('0', ''))
print(k)
ln = len(n)
lst = [n[i]+'0'*(ln-i-1) for i in range(ln) if n[i] != '0']
print(*lst)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 5
5009
7
9876
10000
10
| O(n) | 0.000031 | {
"public_tests": [
{
"input": "5\n5009\n7\n9876\n10000\n10\n",
"output": "2\n5000 9\n1\n7\n4\n9000 800 70 6\n1\n10000\n1\n10\n"
}
],
"private_tests": [
{
"input": "2\n954\n18\n",
"output": "3\n900 50 4\n2\n10 8\n"
},
{
"input": "5\n5009\n7\n9876\n10000\n10\n",
... | [
0.7619716885,
0.0007509899351375153,
0.00074885517130902,
0.00016238798916800245,
0.00011251651372561435,
0.00011164341546351108,
0.00009991784497638775,
0.00009720376566452465,
0.00009572595110348817,
0.00008682903791486925,
0.00008574989711041212,
0.00008517008186733968,
0.0000766813717441... |
1352_A. Sum of Round Numbers | 1263 | 1263_1960 | A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are roun... |
import sys
ip = lambda : sys.stdin.readline()
ipl = lambda : sys.stdin.readline().split()
for _ in range(int(ip())):
n = int(input())
res = []
k = 1
while n:
if n % 10 != 0:
res.append(n%10 * k)
n //= 10
k *= 10
print(len(res))
res.sort(reverse=True)
print(*res) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 5
5009
7
9876
10000
10
| O(nlogn) | 0.000071 | {
"public_tests": [
{
"input": "5\n5009\n7\n9876\n10000\n10\n",
"output": "2\n5000 9\n1\n7\n4\n9000 800 70 6\n1\n10000\n1\n10\n"
}
],
"private_tests": [
{
"input": "2\n954\n18\n",
"output": "3\n900 50 4\n2\n10 8\n"
},
{
"input": "5\n5009\n7\n9876\n10000\n10\n",
... | [
0.00013508972448645108,
0.00011459223827516843,
0.0001016623353890339,
0.00009936779346396575,
0.00009799642391557718,
0.00009577705058865172,
0.00009166991516278214,
0.00008698172028467088,
0.00007710900188782954,
0.00007669285063412079,
0.00007608487880767448,
0.00007572943035894663,
0.000... |
630_G. Challenge Pennants | 1077 | 1077_84 | Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting... | def Fact(n):
res = 1
while n > 0 :
res *= n
n -= 1
return res
def C(n,k):
return (Fact(n) // ( Fact(k) * Fact(n-k) ) )
n = int ( input() ) - 1
print ( C(n+5,n)*C(n+3,3) )
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2
| O(n**2) | 0 | {
"public_tests": [
{
"input": "2\n",
"output": "24"
}
],
"private_tests": [
{
"input": "4\n",
"output": "1120"
},
{
"input": "6\n",
"output": "14112"
},
{
"input": "139\n",
"output": "212332162372330"
},
{
"input": "1\n",
... | [
0.000010961565743172184,
0.000005624270779192032,
5.302782788283459e-7,
1.2941698115457307e-7,
1.1537910574113431e-7,
1.149898766983654e-7,
1.131091985537166e-7,
5.814979101337544e-8,
1.1630969444167175e-8,
1.1367804254551784e-8,
5.946318501843586e-9,
3.464781155249598e-9,
3.1230227912399173... |
630_G. Challenge Pennants | 1077 | 1077_64 | Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting... | n = int(input())
print((n * (n + 1) * (n + 2) * (n + 3) * (n + 4) // 120) *
(n * (n + 1) * (n + 2) // 6)) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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.000005 | {
"public_tests": [
{
"input": "2\n",
"output": "24"
}
],
"private_tests": [
{
"input": "4\n",
"output": "1120"
},
{
"input": "6\n",
"output": "14112"
},
{
"input": "139\n",
"output": "212332162372330"
},
{
"input": "1\n",
... | [
0.0015519780000000094,
0.000533912999999997,
0.000310673999999983,
0.000036506000000000006,
0.000022114,
0.0000185885,
0.000014496000000000005,
0.000013838000000000005,
0.000012916,
0.000012051500000000005,
0.000011592,
0.0000106245,
0.000010336000000000004,
0.000010057000000000002,
0.00... |
859_C. Pie Rules | 647 | 647_11 | You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be ... | n = int(input())
X = list(map(int, input().split()))
ali = [None]*(n+1)
bob = [None]*(n+1)
ali[n] = 0
bob[n] = 0
for i in range(n-1, -1, -1):
bob[i] = max(bob[i+1], ali[i+1]+X[i])
ali[i] = sum(X[i:n]) - bob[i]
#print(ali)
#print(bob)
print(ali[0], bob[0], sep=' ')
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 5
10 21 10 21 10
| O(n**2) | 0 | {
"public_tests": [
{
"input": "5\n10 21 10 21 10\n",
"output": "31 41\n"
},
{
"input": "3\n141 592 653\n",
"output": "653 733\n"
}
],
"private_tests": [
{
"input": "3\n25987 64237 88891\n",
"output": "88891 90224\n"
},
{
"input": "5\n25539 292... | [
0.00012096223318148202,
0.000012691854130710205,
0.0000024712021566217962,
0.0000019841591034593332,
0.0000012871435731324756,
0.000001128422077416025,
9.237111136693789e-7,
7.641080259883256e-7,
5.578673262722e-7,
5.290863842378908e-7,
9.222068096735674e-8,
9.026466095003264e-8,
8.662803614... |
859_C. Pie Rules | 647 | 647_54 | You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be ... | n = int(input())
a = list(map(int, input().split()))
x = s = 0
for ai in reversed(a):
x = max(x, ai + s - x)
s += ai
print(s - x, x)
# Made By Mostafa_Khaled | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 21 10 21 10
| O(n) | 0.000006 | {
"public_tests": [
{
"input": "5\n10 21 10 21 10\n",
"output": "31 41\n"
},
{
"input": "3\n141 592 653\n",
"output": "653 733\n"
}
],
"private_tests": [
{
"input": "3\n25987 64237 88891\n",
"output": "88891 90224\n"
},
{
"input": "5\n25539 292... | [
0.00002412177439357518,
0.000020338406779660978,
0.00001711801765811292,
0.000016659788502513114,
0.00001385865865969858,
0.000013783142459185758,
0.000013472160511555764,
0.000013150778327141611,
0.000012610596073544776,
0.000012591534114748957,
0.000011770873624776613,
0.00001177049729631729... |
628_A. Tennis Tournament | 354 | 354_95 | A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such ... | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 28 10:54:09 2020
@author: shailesh
"""
import math
n,b,p = [int(i) for i in input().split()]
matches_count = 0
towels = n*p
while(n>1):
power = int(math.log2(n))
matches_count += power
n = n - power
bottles = matches_count*(2*b + 1)
pr... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 5 2 3
| O(n) | 0 | {
"public_tests": [
{
"input": "5 2 3\n",
"output": "20 15\n"
},
{
"input": "8 2 4\n",
"output": "35 32\n"
}
],
"private_tests": [
{
"input": "59 1 1\n",
"output": "174 59\n"
},
{
"input": "1 2 133\n",
"output": "0 133\n"
},
{
... | [
5.536049633959791e-7,
3.8178298459353144e-7,
3.1797791466346153e-7,
2.430127021416084e-7,
3.9017195694930073e-8,
3.075381064248252e-8,
2.02004411604021e-8,
1.4524420891608392e-8,
1.2875088778409093e-8,
1.2367481151660841e-8,
1.1935519558566435e-8,
1.1648874562937066e-8,
1.1372971754807695e-8... |
628_A. Tennis Tournament | 354 | 354_35 | A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
* let k be the maximal power of the number 2 such ... | a,b,c=map(int,input().split())
m=(a-1)*(2*b+1)
n=a*c
print(m,n) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 5 2 3
| O(1) | 0.000002 | {
"public_tests": [
{
"input": "5 2 3\n",
"output": "20 15\n"
},
{
"input": "8 2 4\n",
"output": "35 32\n"
}
],
"private_tests": [
{
"input": "59 1 1\n",
"output": "174 59\n"
},
{
"input": "1 2 133\n",
"output": "0 133\n"
},
{
... | [
0.0052976035,
0.000036968,
0.000014935000000000005,
0.000012156500000000005,
0.000008249000000000002,
0.000007471999999999999,
0.0000071899999999999905,
0.000007186000000000002,
0.0000071835,
0.000007133000000000008,
0.000006487500000000002,
0.0000059055,
0.000005529000000000001,
0.0000055... |
797_B. Odd sum | 1366 | 1366_112 | You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequence by deletin... |
n = int(input())
a = list(map(int,input().split()))
s=0
mi = 100000000
for i in a:
if i>0:
s+=i
if i%2==1:
mi = min(mi,abs(i))
if s%2==0:
s -= mi
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
2 -5 -3
| O(n) | 0.000002 | {
"public_tests": [
{
"input": "3\n2 -5 -3\n",
"output": "-1\n"
},
{
"input": "4\n-2 2 -3 1\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "4\n1 -4 -3 -4\n",
"output": "1\n"
},
{
"input": "10\n-2 6 6 5 0 10 6 7 -1 1\n",
"output": ... | [
0.0000201588245153084,
0.00001553887774577037,
0.000013899192578757888,
0.000009373948044143357,
0.000006557759874890735,
0.000004773992679195805,
0.000004738467643684441,
0.000004588883604676574,
0.00000400176401333042,
0.000003935226180069931,
0.0000038840038106424834,
0.00000386636811625874... |
797_B. Odd sum | 1366 | 1366_102 | You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequence by deletin... | '''input
10
1184 5136 1654 3254 6576 6900 6468 327 179 7114
'''
input()
a = list(map(int, input().split()))
s = 0
p, n = [i for i in a if i > 0], [j for j in a if j < 0]
s = sum(p)
if s % 2 == 1:
print(s)
else:
m = -10000000
for x in sorted(n)[::-1]:
if x % 2 == 1:
m = x
break
for y in sorted(p):
if y % 2... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
2 -5 -3
| O(nlogn) | 0.000007 | {
"public_tests": [
{
"input": "3\n2 -5 -3\n",
"output": "-1\n"
},
{
"input": "4\n-2 2 -3 1\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "4\n1 -4 -3 -4\n",
"output": "1\n"
},
{
"input": "10\n-2 6 6 5 0 10 6 7 -1 1\n",
"output": ... | [
0.000014393178116536683,
0.000013950255308613933,
0.00001154202622368274,
0.000010570723661974895,
0.000009472162304838626,
0.000008568099679028683,
0.000008309746195704862,
0.000008305710406422962,
0.000008294584276101141,
0.000008284376446917418,
0.00000828229493202994,
0.0000082116863953704... |
1144_D. Equalize Them All | 397 | 397_80 | You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (indices i and j are adjacent) and set a_i := a_i + |a_i - a_j|;
2. Choose a pair of indices (i, j) such that |i-j|=1 (indice... | from collections import Counter
n=int(input())
l=list(map(int,input().split()))
c,f=Counter(l).most_common(1)[0]
a=int(l.index(c))
print(n-f)
for i in range(a-1,-1,-1):
if l[i]!=c:
print(1 if l[i]<c else 2,i+1,i+2)
for i in range(a+1,len(l)):
if l[i]!=c:
print(1 if l[i]<c else 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, ... | 5
2 4 6 6 6
| O(n) | 0.000018 | {
"public_tests": [
{
"input": "5\n2 4 6 6 6\n",
"output": "2\n1 2 3\n1 1 2\n"
},
{
"input": "4\n1 1 1 1\n",
"output": "0\n"
},
{
"input": "3\n2 8 10\n",
"output": "2\n2 2 1\n2 3 2\n"
}
],
"private_tests": [
{
"input": "69\n1 1 1 1 1 1 1 1 1 1 ... | [
0.00010950001629425263,
0.000034700488062718526,
0.00003469968625710228,
0.00003461736061789772,
0.000034074250095607526,
0.00003331999842930507,
0.000031435409828452804,
0.000029743720948972904,
0.0000296040952114292,
0.000029314616231424833,
0.000028601807159637244,
0.00002810004157561189,
... |
1144_D. Equalize Them All | 397 | 397_163 | You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):
1. Choose a pair of indices (i, j) such that |i-j|=1 (indices i and j are adjacent) and set a_i := a_i + |a_i - a_j|;
2. Choose a pair of indices (i, j) such that |i-j|=1 (indice... | import collections
def solve():
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
max_count = sorted(c.values(), reverse=True)[0]
max_key = [k for k in c.keys() if c[k] == max_count][0]
pivot = A.index(max_key)
ans=[]
for i in range(pivot-1, -1, -1):
if A[... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 5
2 4 6 6 6
| O(nlogn) | 0.000013 | {
"public_tests": [
{
"input": "5\n2 4 6 6 6\n",
"output": "2\n1 2 3\n1 1 2\n"
},
{
"input": "4\n1 1 1 1\n",
"output": "0\n"
},
{
"input": "3\n2 8 10\n",
"output": "2\n2 2 1\n2 3 2\n"
}
],
"private_tests": [
{
"input": "69\n1 1 1 1 1 1 1 1 1 1 ... | [
0.00015593558558238635,
0.00001814152990776471,
0.000016513814497097995,
0.00001626253557264946,
0.000015495621533339457,
0.000015350517972518782,
0.00001478865401495603,
0.000014530113396698657,
0.000013997135851359266,
0.000013821001559451592,
0.000013698035916471408,
0.000013554320986916569... |
489_B. BerSU Ball | 1718 | 1718_1166 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m... | n = int(input())
boys = list(map(int, input().split()))
m = int(input())
girls = list(map(int, input().split()))
boys.sort()
girls.sort()
mark = [0]*m
for i in range(n):
for j in range(m):
#print("{} {}".format(i, j))
if mark[j] == 0 and abs(boys[i] - girls[j]) <= 1:
#print("{} {}".forma... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4
1 2 3 4
4
10 11 12 13
| O(n*m) | 0.007816 | {
"public_tests": [
{
"input": "4\n1 2 3 4\n4\n10 11 12 13\n",
"output": "0\n"
},
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9\n",
"output": "3\n"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "1\n4\n3\n4 ... | [
0.02648520265140845,
0.0235763599373494,
0.021943675242570283,
0.021851390888353413,
0.020965594969477912,
0.020532169578313254,
0.019935044889156626,
0.019358110138955824,
0.01906095481686747,
0.017574099982329318,
0.016410037175903617,
0.015602738647389558,
0.015427509187951811,
0.015160... |
489_B. BerSU Ball | 1718 | 1718_621 | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m... | n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
b = [int(x) for x in input().split()]
a = sorted(a)
b = sorted(b)
idx_a = 0
idx_b = 0
cnt = 0
while(idx_a < n and idx_b < m):
if( abs(a[idx_a]-b[idx_b]) <= 1):
idx_a+=1
idx_b+=1
cnt+=1
elif(a[idx_a]>b[idx_b]):
idx_b+=1
else:
idx_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 2 3 4
4
10 11 12 13
| O(nlogn+mlogm) | 0.000011 | {
"public_tests": [
{
"input": "4\n1 2 3 4\n4\n10 11 12 13\n",
"output": "0\n"
},
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9\n",
"output": "3\n"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "1\n4\n3\n4 ... | [
0.000028172701166933312,
0.000020998590266576337,
0.000020796870083187264,
0.00001858377848744926,
0.000017922051597271603,
0.000017918275150206422,
0.000017814301681856894,
0.000015376553346381187,
0.000013241069187049706,
0.000012485112593760135,
0.000012411998876450471,
0.000012297274118515... |
454_B. Little Pony and Sort by Shift | 71 | 71_257 | One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
a1, a2, ..., an → an, a1, a2, ..., an - 1.
Help Twi... | #Codeforces454B
n = int(input())
lst = [int(x) for x in input().split()]
index = 0
count = 0
for i in range(n):
if lst[i-1] > lst[i]:
index = i
count += 1
if count == 2:
print(-1)
break
if count != 2:
print((n - index) % n)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
1 3 2
| O(n) | 0.000001 | {
"public_tests": [
{
"input": "3\n1 3 2\n",
"output": "-1\n"
},
{
"input": "2\n1 2\n",
"output": "0\n"
},
{
"input": "2\n2 1\n",
"output": "1\n"
}
],
"private_tests": [
{
"input": "6\n5 6 7 5 5 5\n",
"output": "3\n"
},
{
"i... | [
0.0001489243313210227,
0.00011598718517810316,
0.0000746621239346591,
0.000007793685546875,
0.0000037691831840034972,
0.000003659216059331294,
0.0000036489819848120628,
0.000003623378277972028,
0.0000032916588177447556,
0.000003043631323754371,
0.0000028239980605332167,
0.000002754432883522727... |
454_B. Little Pony and Sort by Shift | 71 | 71_217 | One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
a1, a2, ..., an → an, a1, a2, ..., an - 1.
Help Twi... | n=int(input())
a=list(map(int,input().split()))
#for x in range(len(a)):
# a[x]=int(a[x])
# print(x)
ans=0
d=0
for x in range(1,n):
if(a[x-1]>a[x]):
d=1
if(sorted(a)==a[x:]+a[:x]):
ans=n-x
else:
ans=-1
break
if(d==0):
print(0)
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, ... | 3
1 3 2
| O(nlogn) | 0.000008 | {
"public_tests": [
{
"input": "3\n1 3 2\n",
"output": "-1\n"
},
{
"input": "2\n1 2\n",
"output": "0\n"
},
{
"input": "2\n2 1\n",
"output": "1\n"
}
],
"private_tests": [
{
"input": "6\n5 6 7 5 5 5\n",
"output": "3\n"
},
{
"i... | [
0.00010166129331020543,
0.00010047002933784965,
0.00010042372652152535,
0.00010011223279064686,
0.000016011709020752035,
0.000016006411883918162,
0.000015926485754631664,
0.000015869733335206965,
0.00001586104342672658,
0.000015843319479758103,
0.000015827981447319417,
0.000015795816410348055,... |
171_B. Star | 2522 | 2522_11 | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | sum = 1
n = int(input())
if n ==1:
print(sum)
else:
for i in range(1, n):
sum += 12*i
print(sum)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2
| O(n) | 0.000001 | {
"public_tests": [
{
"input": "2\n",
"output": "13\n"
}
],
"private_tests": [
{
"input": "3823\n",
"output": "87669037\n"
},
{
"input": "3994\n",
"output": "95688253\n"
},
{
"input": "8543\n",
"output": "437845837\n"
},
{
"... | [
0.000002170227259069056,
0.0000020606197415865383,
0.0000016994977054195806,
0.0000016966026824737762,
0.0000016699113991477273,
0.000001380486136909965,
0.0000013740163898601399,
0.0000013484463778409092,
0.0000013194125054632867,
0.0000011825794498470279,
0.0000010789741996284966,
0.00000102... |
171_B. Star | 2522 | 2522_15 | <image>
Input
The input contains a single integer a (1 ≤ a ≤ 18257).
Output
Print a single integer output (1 ≤ output ≤ 2·109).
Examples
Input
2
Output
13 | a = int(input())
if a == 1:
print(1)
else:
print(12 * (a - 1) * a // 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, ... | 2
| O(1) | 0.000002 | {
"public_tests": [
{
"input": "2\n",
"output": "13\n"
}
],
"private_tests": [
{
"input": "3823\n",
"output": "87669037\n"
},
{
"input": "3994\n",
"output": "95688253\n"
},
{
"input": "8543\n",
"output": "437845837\n"
},
{
"... | [
0.000005963500000000005,
0.0000045265000000000015,
0.000003938500000000003,
0.000003605499999999998,
0.0000036005000000000005,
0.000003095,
0.0000029634999999999997,
0.0000027450000000000017,
0.000002698499999999998,
0.0000025815000000000023,
0.000002525999999999999,
0.0000024864999999999973,
... |
433_A. Kitahara Haruki's Gift | 1586 | 1586_257 | Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ... | n=input()
cnt={100:0, 200:0}
w = list(map(int, input().split()))
for i in w:
cnt[i]+=1
if cnt[100]&1 or (cnt[100]==0 and cnt[200]&1):
print("NO")
else:
print("YES")
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4
100 100 100 200
| O(n) | 0.000002 | {
"public_tests": [
{
"input": "4\n100 100 100 200\n",
"output": "NO\n"
},
{
"input": "3\n100 200 100\n",
"output": "YES\n"
}
],
"private_tests": [
{
"input": "9\n100 100 100 200 100 100 200 100 200\n",
"output": "YES\n"
},
{
"input": "3\n100 1... | [
0.000016074259792941434,
0.000010598596823098777,
0.000005359820940777972,
0.000005287283588833028,
0.000005085772194602274,
0.000004525965963723777,
0.000004119302625109266,
0.000003914065368225525,
0.000003910486532998252,
0.000003296670126748252,
0.000003244488745629371,
0.00000322577011855... |
433_A. Kitahara Haruki's Gift | 1586 | 1586_188 | Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ... | n = int(input())
macas = list(map(int, input().split(" ")))
macas.sort(reverse=True)
amigo_1 = 0
amigo_2 = 0
for maca in macas:
if amigo_1 <= amigo_2:
amigo_1 += maca
else:
amigo_2 += maca
if amigo_1 == amigo_2:
print("YES")
else:
print("NO")
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4
100 100 100 200
| O(nlogn) | 0.000012 | {
"public_tests": [
{
"input": "4\n100 100 100 200\n",
"output": "NO\n"
},
{
"input": "3\n100 200 100\n",
"output": "YES\n"
}
],
"private_tests": [
{
"input": "9\n100 100 100 200 100 100 200 100 200\n",
"output": "YES\n"
},
{
"input": "3\n100 1... | [
0.000021784955324329643,
0.00002172619566912287,
0.000012204952386149906,
0.000011830129717788037,
0.0000117075294903785,
0.000011653905277824493,
0.00001163019625061482,
0.000011619276341925146,
0.000011580552899108456,
0.000011577654282322402,
0.000011577130881137514,
0.000011569587463312993... |
53_A. Autocomplete | 1196 | 1196_51 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | s = input()
n = int(input())
l = []
for i in range(n):
l.append(input())
k = len(s)
answer = ""
for a in l:
if a[:k]==s:
if a<answer or answer =="":
answer=a
if answer:
print(answer)
else:
print(s) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | find
4
fondfind
fondfirstof
fondit
fand
| O(n) | 0.000007 | {
"public_tests": [
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand\n",
"output": "find\n"
},
{
"input": "next\n2\nnextpermutation\nnextelement\n",
"output": "nextelement\n"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"output": "find\n"
... | [
0.0000154334804382297,
0.000014055033511852175,
0.000012722072151924236,
0.000010165545861883397,
0.00000972172142715309,
0.000009363346500176985,
0.00000886445885769046,
0.000008654723110659618,
0.0000085909224550993,
0.000008423772896408231,
0.000008298189588735184,
0.000008104042113563307,
... |
53_A. Autocomplete | 1196 | 1196_100 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | target = input()
count = input()
srchlist = []
for i in range(0,int(count)):
srch = input()
srchlist.append(srch)
srchlist.sort()
final = target
for item in srchlist:
if item.find(target) == 0:
final = item
break
print(final)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | find
4
fondfind
fondfirstof
fondit
fand
| O(nlogn) | 0.000013 | {
"public_tests": [
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand\n",
"output": "find\n"
},
{
"input": "next\n2\nnextpermutation\nnextelement\n",
"output": "nextelement\n"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"output": "find\n"
... | [
0.000013474579664983624,
0.000012782320422866868,
0.00001274461103842115,
0.000012658125185818368,
0.00001265765150144374,
0.00001264274194649045,
0.000012638988794291012,
0.00001263719852620395,
0.000012621190361471966,
0.00001261927949704248,
0.000012600347612769882,
0.000012597991157878872,... |
901_A. Hashing Trees | 2723 | 2723_27 | Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree... | n = int(input())
*a, = map(int, input().split())
b, c = [0], [0]
cur = 1
for i in range(1, n + 1):
for j in range(a[i]):
b.append(cur)
cur += a[i]
cur = 1
for i in range(1, n + 1):
if a[i] > 1 and a[i - 1] > 1:
c.append(cur - 1)
for j in range(1, a[i]):
c.append(cur)
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2
1 2 2
| O(n*m) | 0.000012 | {
"public_tests": [
{
"input": "2\n1 2 2\n",
"output": "ambiguous\n0 1 1 3 3 \n0 1 1 2 3 \n"
},
{
"input": "2\n1 1 1\n",
"output": "perfect"
}
],
"private_tests": [
{
"input": "13\n1 1 40049 1 1 39777 1 1 40008 1 40060 1 40097 1\n",
"output": "perfect"
}... | [
0.000015236740234375003,
0.000013783856640624999,
0.000013715044140625,
0.000013316017187500003,
0.000012949408593750003,
0.000012393212890625001,
0.000012280716796875,
0.000012090688281250002,
0.000011713099609375001,
0.000011552131640625003,
0.000011531559375000001,
0.000011033596093750001,
... |
901_A. Hashing Trees | 2723 | 2723_42 | Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree... | def read():
return tuple(int(x) for x in input().split())
def main():
(h, ) = read()
a = read()
tree = []
fi = 0
flag = False
for i, x in enumerate(a):
if fi == 0:
if not flag and x > 1:
flag = True
elif flag and x > 1:
fi = len(tree)
else:
flag = False
tree.extend([len(tree)] * x)
if ... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2
1 2 2
| O(n) | 0.037675 | {
"public_tests": [
{
"input": "2\n1 2 2\n",
"output": "ambiguous\n0 1 1 3 3 \n0 1 1 2 3 \n"
},
{
"input": "2\n1 1 1\n",
"output": "perfect"
}
],
"private_tests": [
{
"input": "13\n1 1 40049 1 1 39777 1 1 40008 1 40060 1 40097 1\n",
"output": "perfect"
}... | [
0.08708399952542373,
0.08639068594915256,
0.08548522372881356,
0.08458236793220339,
0.08196451257627119,
0.08172748791525425,
0.08134669227118645,
0.07895094710169492,
0.07566218205084745,
0.06683847438983051,
0.06451365218644069,
0.06220468237288136,
0.05714545004225353,
0.056924337542253... |
462_A. Appleman and Easy Task | 1345 | 1345_113 | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of th... | def giveResponse(mat,n):
for i in range(1,n+1):
for j in range(1,n+1):
if (mat[i-1][j] + mat[i+1][j] + mat[i][j-1] + mat[i][j+1])%2==1:
return("NO")
return("YES")
mat=[]
n = int(input())
mat = [[0]*(n+2)]
for i in range(n):
sat = [0]
for j in (input()):
if 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, ... | 3
xxo
xox
oxx
| O(n**2) | 0 | {
"public_tests": [
{
"input": "3\nxxo\nxox\noxx\n",
"output": "YES\n"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "3\nooo\noxo\nxoo\n",
"output": "NO\n"
},
{
"input": "12\nxxooxxoxxxoo\nxxoo... | [
0.0000376013587198093,
0.000028536556292800533,
0.00002330193627053627,
0.00001139293482671394,
0.000011093316941831604,
0.000009031700379004803,
0.000008820286955846085,
0.000008295013042139464,
0.000006855437904509208,
0.000006710966623403907,
0.000004662003594358383,
0.000004652895815407107... |
462_A. Appleman and Easy Task | 1345 | 1345_111 | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of th... | n = int(input())
row = []
for i in range (n): row.append(input())
left = row[:n//2+1]
right = row[n//2:]
right = right[::-1]
check = True
for i in range (n//2):
if(right[i][::-1] != left[i]):
check = False
break
print('YES' if (check) else 'NO') | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
xxo
xox
oxx
| O(n) | 0.000005 | {
"public_tests": [
{
"input": "3\nxxo\nxox\noxx\n",
"output": "YES\n"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "3\nooo\noxo\nxoo\n",
"output": "NO\n"
},
{
"input": "12\nxxooxxoxxxoo\nxxoo... | [
0.000025449445312500003,
0.000022394118080357144,
0.000021194376171875002,
0.00002030948798667008,
0.00001898313364739603,
0.000010869315959821427,
0.000008336455245535714,
0.00000809207935267857,
0.000007553530336212082,
0.000007450409667644157,
0.000007369555859375002,
0.00000712310424107142... |
697_B. Barnicle | 1950 | 1950_47 | Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
<image>
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the ... | from decimal import *
while True :
try :
a=input()
b=Decimal(a)
if(round(b)==b):
print ("%d"%b)
else:
print (b)
except :
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, ... | 8.549e3
| O(n**2) | 0 | {
"public_tests": [
{
"input": "8.549e3\n",
"output": "8549\n"
},
{
"input": "0.33e0\n",
"output": "0.33\n"
},
{
"input": "8.549e2\n",
"output": "854.9\n"
}
],
"private_tests": [
{
"input": "4.6329496401734172195e50\n",
"output": "4632949... | [
6.559479982089438e-10,
5.217593775295573e-10,
5.214569023699471e-10,
5.213747618303031e-10,
5.213007491163049e-10,
5.212626080661791e-10,
5.209132424618773e-10,
5.206406940011939e-10,
5.204181772290823e-10,
5.203274627965044e-10,
5.202854534151729e-10,
5.200398405592266e-10,
5.19928674101135... |
697_B. Barnicle | 1950 | 1950_45 | Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
<image>
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the ... | a, b = input().split('e')
b = int(b)
pos = a.find('.') + b
a = ''.join(a.split('.'))
a = list(a)
while len(a) < pos:
a.append('0')
a = ''.join(a[:pos]) + '.' + ''.join(a[pos:])
if len(a) == pos + 1: a = a[:-1]
elif len(a) > 2 and a[-2:] == '.0': a = a[:-2]
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, ... | 8.549e3
| O(n) | 0.000002 | {
"public_tests": [
{
"input": "8.549e3\n",
"output": "8549\n"
},
{
"input": "0.33e0\n",
"output": "0.33\n"
},
{
"input": "8.549e2\n",
"output": "854.9\n"
}
],
"private_tests": [
{
"input": "4.6329496401734172195e50\n",
"output": "4632949... | [
0.000007690952734375002,
0.000005404775781250001,
0.000004584229296875001,
0.00000438241875,
0.0000031444993170891613,
0.000002766632088614511,
0.000002687254296875,
0.0000026349718750000008,
0.0000024648682391826923,
0.0000024435589843750006,
0.000002321750450721154,
0.0000021714077250874126,... |
873_A. Chores | 1540 | 1540_9 | Luba has to do n chores today. i-th chore takes ai units of time to complete. It is guaranteed that for every <image> the condition ai ≥ ai - 1 is met, so the sequence is sorted.
Also Luba can work really hard on some chores. She can choose not more than k any chores and do each of them in x units of time instead of a... | #873A
given = input().split(" ")
tasks = input().split(" ")
nominal = 0
for i in range(len(tasks) - int(given[1])):
nominal += int(tasks[i])
total = nominal + int(given[1])*int(given[2])
print(total) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4 2 2
3 6 7 10
| O(n) | 0.000003 | {
"public_tests": [
{
"input": "4 2 2\n3 6 7 10\n",
"output": "13\n"
},
{
"input": "5 2 1\n100 100 100 100 100\n",
"output": "302\n"
}
],
"private_tests": [
{
"input": "100 1 1\n3 3 5 7 8 8 8 9 9 9 11 13 14 15 18 18 19 20 21 22 22 25 27 27 29 31 32 33 33 34 36 37 ... | [
0.0000954555087139423,
0.000004356861041302448,
0.0000042022232708697556,
0.000003426884574409965,
0.0000032241763412368885,
0.0000031378895050262237,
0.0000031147192553540213,
0.0000030883069411057697,
0.0000030053143028846152,
0.0000029836703862543706,
0.000002979878646743881,
0.000002968670... |
873_A. Chores | 1540 | 1540_206 | Luba has to do n chores today. i-th chore takes ai units of time to complete. It is guaranteed that for every <image> the condition ai ≥ ai - 1 is met, so the sequence is sorted.
Also Luba can work really hard on some chores. She can choose not more than k any chores and do each of them in x units of time instead of a... | n,k,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
for i in range(0,k):
a[i]=x
print(sum(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 2 2
3 6 7 10
| O(nlogn) | 0.000011 | {
"public_tests": [
{
"input": "4 2 2\n3 6 7 10\n",
"output": "13\n"
},
{
"input": "5 2 1\n100 100 100 100 100\n",
"output": "302\n"
}
],
"private_tests": [
{
"input": "100 1 1\n3 3 5 7 8 8 8 9 9 9 11 13 14 15 18 18 19 20 21 22 22 25 27 27 29 31 32 33 33 34 36 37 ... | [
0.000011844534663503704,
0.00001181364474650414,
0.000011592568048617811,
0.000011559143510529856,
0.000011525253865988927,
0.000011508877552572922,
0.00001148355177104392,
0.000011482850678705376,
0.000011481032226150805,
0.00001147685251466279,
0.000011448873937671398,
0.00001144746476817801... |
9_C. Hexadecimal's Numbers | 2381 | 2381_176 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.
But his plan failed. The reason for this w... | n,ans=int(input()),1
while int(bin(ans)[2:])<=n:
ans+=1
print(ans-1) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 10
| O(n) | 0 | {
"public_tests": [
{
"input": "10\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "100\n",
"output": "4\n"
},
{
"input": "1010011\n",
"output": "83\n"
},
{
"input": "1\n",
"output": "1\n"
},
{
"input": "999999999\n",... | [
2.2944707440996496e-7,
9.210861013986013e-8,
5.2319288133741254e-8,
4.4848147945804205e-8,
4.135639750874127e-8,
3.276665619536714e-8,
3.034152371066434e-8,
1.9485078398164335e-8,
1.6417757047639863e-8,
1.604968859265734e-8,
1.5569076431381118e-8,
1.4370533763111886e-8,
1.4086019449300698e-8... |
9_C. Hexadecimal's Numbers | 2381 | 2381_156 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.
But his plan failed. The reason for this w... | def main():
n = int(input())
print(calculate(n))
def helper(s):
if len(s) == 0:
return 1
num = int(s[0])
if num == 0:
return helper(s[1:])
elif num == 1:
return 2**(len(s) - 1) + helper(s[1:])
elif num >= 2:
return 2**len(s)
else:
assert(False)
def calculate(n):
return helper(str(n)) - 1
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, ... | 10
| O(1) | 0.000004 | {
"public_tests": [
{
"input": "10\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "100\n",
"output": "4\n"
},
{
"input": "1010011\n",
"output": "83\n"
},
{
"input": "1\n",
"output": "1\n"
},
{
"input": "999999999\n",... | [
0.01853571,
0.0018559774999999945,
0.00023423200000000002,
0.0001338905000000043,
0.00010638400000000017,
0.00010509949999999713,
0.00008948100000000236,
0.00006725799999999973,
0.00005988,
0.00005702900000000011,
0.00004796999999999961,
0.0000472340000000019,
0.000044829500000000307,
0.00... |
560_D. Equivalent Strings | 1628 | 1628_32 | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:
1. They are equal.
2. If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2... |
def isEqual(a, b):
for i in range(0, len(a)):
if (a[i] != b[i]):
return False
return True
def lexicographic_minimal_string(s):
if (len(s) % 2 == 1):
return s
half = int(len(s) /2)
s1 = lexicographic_minimal_string(s[:half])
s2 = lexicographic_minimal_string(s[half:])
if s1 < s2:
return s1 + s2
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, ... | aaba
abaa
| O(n) | 0.000002 | {
"public_tests": [
{
"input": "aaba\nabaa\n",
"output": "YES\n"
},
{
"input": "aabb\nabab\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "aabbaaaa\naaaaabab\n",
"output": "NO\n"
},
{
"input": "qgiufelsfhanx\naaaaaaaaaaaaa\n",
"o... | [
0.000004000486307637676,
0.000003971233125273165,
0.000003782187158544581,
0.0000035532319711538463,
0.0000034714905211975526,
0.0000034119906577797205,
0.0000033241733842329547,
0.0000033190197497814686,
0.000003026525820858829,
0.0000029922492761145107,
0.000002981700079217657,
0.00000283608... |
560_D. Equivalent Strings | 1628 | 1628_26 | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:
1. They are equal.
2. If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2... | def sm(s):
if len(s) % 2 == 1:
return s
s1 = sm(s[:len(s) // 2])
s2 = sm(s[len(s) // 2:])
if s1 < s2:
return s1 + s2
else:
return s2 + s1
if sm(input()) == sm(input()):
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, ... | aaba
abaa
| O(1) | 0.001603 | {
"public_tests": [
{
"input": "aaba\nabaa\n",
"output": "YES\n"
},
{
"input": "aabb\nabab\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "aabbaaaa\naaaaabab\n",
"output": "NO\n"
},
{
"input": "qgiufelsfhanx\naaaaaaaaaaaaa\n",
"o... | [
0.0216918905,
0.0097065875,
0.0089262255,
0.008896402500000001,
0.008720768,
0.0087191275,
0.006114139,
0.0050738435,
0.002444489,
0.002037352,
0.002021455,
0.0020179955,
0.0020088960000000005,
0.0019457865,
0.0018823595,
0.001849509,
0.0017502745,
0.0017355310000000002,
0.001725... |
650_A. Watchmen | 1853 | 1853_66 | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan consider... | from collections import Counter
n = int(input())
a, b = [], []
for i in range(n):
ai, bi = [int(x) for x in input().split()]
a.append(ai)
b.append(bi)
sum = 0
for k, v in dict(Counter(a)).items():
if v > 1:
sum += v*(v-1)//2
for k, v in dict(Counter(b)).items():
if v > 1:
sum += v*(v-1... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
1 1
7 5
1 5
| O(n) | 0.000013 | {
"public_tests": [
{
"input": "3\n1 1\n7 5\n1 5\n",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n",
"output": "11"
}
],
"private_tests": [
{
"input": "2\n1 0\n0 19990213\n",
"output": "0"
},
{
"input": "10\n46 -55\n46 45\n46 ... | [
0.000034510498280521106,
0.000029107697037891847,
0.00002255828957175623,
0.000021199395724756754,
0.000020879475016475344,
0.00002067164181312214,
0.000020650309267343716,
0.00002063054509639154,
0.00002001152750158998,
0.000018915109399146447,
0.000017522044971207723,
0.00001736767944884586,... |
650_A. Watchmen | 1853 | 1853_137 | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan consider... | n = int(input())
a = []
b = {}
c = {}
for i in range(n):
x, y = [int(d) for d in input().split()]
b[y] = 0
a.append((x, y))
a.sort()
b[a[0][1]] = 1
c[a[0][1]] = 1
summa = 0
count = 1
for i in range(1, n):
if a[i][0] == a[i - 1][0]:
summa += count
count += 1
else:
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, ... | 3
1 1
7 5
1 5
| O(nlogn) | 0.000011 | {
"public_tests": [
{
"input": "3\n1 1\n7 5\n1 5\n",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n",
"output": "11"
}
],
"private_tests": [
{
"input": "2\n1 0\n0 19990213\n",
"output": "0"
},
{
"input": "10\n46 -55\n46 45\n46 ... | [
0.000027691722444444708,
0.000027085194410337965,
0.0000264530035763929,
0.00002633053376198622,
0.00002629336496242361,
0.000025826114762019257,
0.000025691696854934852,
0.000024129012461628628,
0.000019772102886001652,
0.00001965500636260396,
0.00001953507646170551,
0.00001937952522681616,
... |
447_B. DZY Loves Strings | 700 | 700_99 | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase ... | t = input()
k = int(input())
w = [int(x) for x in input().split()]
total = 0
for i in range(len(t)):
total = total + w[ord(t[i])-97]*(i+1)
for i in range(k):
total = total + max(w)*(len(t)+i+1)
print(total) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
| O(n*m) | 0.000546 | {
"public_tests": [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "41\n"
}
],
"private_tests": [
{
"input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuen... | [
0.0005589685276785714,
0.0005514387963169643,
0.0005508732239955358,
0.00055060370234375,
0.0005505746662946429,
0.00055011781171875,
0.0005500230725446428,
0.000549723496875,
0.0005493945488839287,
0.0005493008311383929,
0.0005491463650669644,
0.0005488158041294643,
0.0005484459800223214,
... |
447_B. DZY Loves Strings | 700 | 700_233 | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase ... | s=input()
k=int(input())
w=list(map(int,input().split()))
score=0
for i in range(len(s)):
score+=(w[ord(s[i])-97]*(i+1))
score=score+(max(w)*(k*len(s)+(k*(k+1)//2)))
print(int(score))
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
| O(n+m) | 0.000011 | {
"public_tests": [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "41\n"
}
],
"private_tests": [
{
"input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuen... | [
0.0006587051003906252,
0.000024352821582714164,
0.00002374816981260927,
0.0000201151459107299,
0.00001708634894012238,
0.00001705159370902535,
0.00001636819782561189,
0.000016333111273492134,
0.00001621791869263549,
0.000015725409719187064,
0.000015438680220170453,
0.000015274613527097903,
0... |
p02994 AtCoder Beginner Contest 131 - Bite Eating | 2313 | 2313_177 | You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, ... | N,L = map(int,input().split())
x = []
for i in range(1,N+1):
x.append(L+i-1)
print(sum(x)-min(x,key = abs)) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 | O(n) | 0.000004 | {
"public_tests": [
{
"input": "5 2",
"output": "18"
},
{
"input": "30 -50",
"output": "-1044"
},
{
"input": "3 -1",
"output": "0"
}
],
"private_tests": [],
"generated_tests": [
{
"input": "5 4",
"output": "26\n"
},
{
"inp... | [
0.0000074292389231861895,
0.000006128941501857519,
0.0000060751726262019245,
0.000005226049087631119,
0.000004420364892919581,
0.0000044126904638330424,
0.000004406768943946678,
0.000004393723448426574,
0.000004371653887128497,
0.000004305450844077797,
0.000004024837740384617,
0.00000397923001... |
p02994 AtCoder Beginner Contest 131 - Bite Eating | 2313 | 2313_104 | You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, ... | n, l = map(int, input().split())
s = [0] * n
for i in range(n):
s[i] = i + l
s.sort(key=abs)
print(sum(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, ... | 5 2 | O(nlogn) | 0.000013 | {
"public_tests": [
{
"input": "5 2",
"output": "18"
},
{
"input": "30 -50",
"output": "-1044"
},
{
"input": "3 -1",
"output": "0"
}
],
"private_tests": [],
"generated_tests": [
{
"input": "5 4",
"output": "26\n"
},
{
"inp... | [
0.000014688590473193134,
0.000012974932475674309,
0.000012945560326629715,
0.000012920323386767204,
0.000012916378192968128,
0.000012915532534645292,
0.000012882418411834576,
0.000012829173441681014,
0.000012809959967147087,
0.000012808546419061116,
0.000012808261184800248,
0.00001280390107852... |
750_A. New Year and Hurry | 704 | 704_614 | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th... | #NEW YEAR AND HURRY
n,hrs = map(int,input().split())
cnt = 0
res = 0
l = []
if hrs > 240:
print(0)
else:
for i in range(1,n+1):
ans = 5*i
hrs += (ans)
#print(i,hrs,ans)
if hrs <= 240:
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, ... | 7 1
| O(n) | 0.000004 | {
"public_tests": [
{
"input": "7 1\n",
"output": "7\n"
},
{
"input": "4 190\n",
"output": "4\n"
},
{
"input": "3 222\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "9 170\n",
"output": "4\n"
},
{
"input": "1 55\n",
... | [
0.000041835506214488637,
0.000011768251092657344,
0.000011051118348448425,
0.0000102324491368007,
0.000010225820804195805,
0.000010216153286166958,
0.000010166440204326925,
0.000010163165783435315,
0.000010072372609812064,
0.000009357125013658217,
0.000009280279843203671,
0.0000090770342411494... |
750_A. New Year and Hurry | 704 | 704_351 | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th... | import math
n, k = map(int, input().split())
timeToSolve = 240 - k
problems = math.floor(timeToSolve / 5)
problems = math.floor((math.sqrt(1 + 8*problems) - 1) / 2)
print(n if problems > n else problems) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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
| O(1) | 0.000002 | {
"public_tests": [
{
"input": "7 1\n",
"output": "7\n"
},
{
"input": "4 190\n",
"output": "4\n"
},
{
"input": "3 222\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "9 170\n",
"output": "4\n"
},
{
"input": "1 55\n",
... | [
0.000050446500000000006,
0.000023309000000000003,
0.000014711999999999997,
0.000014067999999999998,
0.000011599999999999997,
0.000010800999999999997,
0.000009696500000000001,
0.0000095275,
0.000008641,
0.0000065724999999999985,
0.000006557000000000002,
0.000006338000000000003,
0.000006206999... |
397_A. On Segment's Own Points | 2607 | 2607_25 | Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm.
The dorm has exactly one straight dryer — a 100 ce... | from collections import Counter
from re import findall
n = int(input())
y = [int(i) for i in input().split()]
alex = list(range(y[1]))
for i in range(n-1):
a, b = [int(x) for x in input().split()]
for j in range(a, min(b, y[1])):
alex[j] = 'X'
o = [str(x) for x in (alex[y[0]:y[1]])]
o = filter(lambda... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 5
2 8
1 6
| O(n**2) | 0 | {
"public_tests": [
{
"input": "3\n0 5\n2 8\n1 6\n",
"output": "1\n"
},
{
"input": "3\n0 10\n1 5\n7 15\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "2\n1 5\n1 2\n",
"output": "3\n"
},
{
"input": "2\n1 9\n3 5\n",
"output": "6\n"
... | [
7.747881355932204e-9,
5.4855222902097916e-9,
5.221905048076923e-9,
1.028762812637558e-9,
2.7384041739510503e-10,
1.411221890668927e-10,
9.746503496503493e-11,
9.233064731974482e-11,
8.885605759888279e-11,
8.402215309036761e-11,
7.243312218290766e-11,
7.060848757333359e-11,
6.780885506736625e... |
397_A. On Segment's Own Points | 2607 | 2607_90 | Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm.
The dorm has exactly one straight dryer — a 100 ce... | n = int(input())
a = [0] * 100
la, ra = map(int, input().split())
for i in range(1, n):
l, r = map(int, input().split())
a[l] += 1
if r < 100:
a[r] -= 1
for i in range(1, 100):
a[i] += a[i - 1]
ans = 0
for i in range(la, ra):
if a[i] == 0:
ans += 1
print(ans) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
0 5
2 8
1 6
| O(n) | 0.000009 | {
"public_tests": [
{
"input": "3\n0 5\n2 8\n1 6\n",
"output": "1\n"
},
{
"input": "3\n0 10\n1 5\n7 15\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "2\n1 5\n1 2\n",
"output": "3\n"
},
{
"input": "2\n1 9\n3 5\n",
"output": "6\n"
... | [
0.000013333912109374999,
0.000011480454832277098,
0.000011211873907342658,
0.000011170475046437938,
0.000011090905389532344,
0.000010426309577141608,
0.000009933158585555071,
0.000009912565450174826,
0.000009841553553868007,
0.000009823688333151224,
0.000009786886609484266,
0.00000978376990002... |
624_B. Making a String | 209 | 209_29 | You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
* the i-th letter occurs in the string no more than ai times;
* the number of occurrences of each letter in the string must be distinct for all the lette... | n = int(input())
rng = [int(t) for t in input().split()]
ans = 0
while len(rng) != 0:
mx = max(rng)
if mx <= 0:
break
ans += mx
rng.remove(mx)
for i in range(len(rng)):
if rng[i] == mx:
rng[i] -= 1
print(ans) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
2 5 5
| O(n**2) | 0.000002 | {
"public_tests": [
{
"input": "3\n2 5 5\n",
"output": "11\n"
},
{
"input": "3\n1 1 2\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000000... | [
0.1440576933261936,
0.00019109239899392497,
0.00018931764116849746,
0.00018882316616641103,
0.00018862679612879834,
0.00018849477764763776,
0.00018186846370100925,
0.00014991836744291095,
0.00007486795191012099,
0.000010913624734597625,
0.0000064223724638157,
0.00000598693410205246,
0.000005... |
624_B. Making a String | 209 | 209_103 | You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
* the i-th letter occurs in the string no more than ai times;
* the number of occurrences of each letter in the string must be distinct for all the lette... | n = int(input())
a = list(sorted(map(int, input().split()), reverse=True))
for i in range(n - 1):
a[i + 1] = max(0, min(a[i] - 1, a[i + 1]))
print(sum(a)) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
2 5 5
| O(nlogn) | 0.000008 | {
"public_tests": [
{
"input": "3\n2 5 5\n",
"output": "11\n"
},
{
"input": "3\n1 1 2\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000000... | [
0.000015937012959892352,
0.000010408498033827104,
0.000007941037512251523,
0.000007938499496535004,
0.000007896820752614817,
0.000007817073554542177,
0.000007808829131068574,
0.000007795917073222525,
0.000007763006522766202,
0.000007704585320568152,
0.000007658982072142448,
0.00000765285594282... |
545_C. Woodcutters | 1560 | 1560_164 | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | n = int(input())
trees = []
for i in range(n):
x, h = map(int, input().split())
trees.append((x, h))
felled = min(2, n)
for i in range(1,n-1):
left = trees[i][0] - trees[i][1]
right = trees[i][0] + trees[i][1]
if left > trees[i-1][0]:
felled += 1
elif right < trees[i+1][0]:
felled += 1
trees[i] = (trees[i][... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 5
1 2
2 1
5 10
10 9
20 1
| O(n) | 0.00002 | {
"public_tests": [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1\n",
"output": "4\n"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "4\n10 4\n15 1\n19 3\n20 1\n",
"output": "4\n"
},
{
"input": "... | [
0.0000573942132556714,
0.000052892440638408696,
0.00004972466628583927,
0.00004565136117402278,
0.000044266557649306885,
0.00004051593464253545,
0.00003472988319630262,
0.000034263764614131674,
0.000034122052323958456,
0.00003369679212579391,
0.00003344560541196988,
0.00003334653405719318,
0... |
545_C. Woodcutters | 1560 | 1560_63 | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | inf = 10**18
a=[]
n = int(input())
for i in range(n):
a.append([int(i) for i in input().split()])
a.sort()
occ = [a[0][0]-a[0][1],a[0][0]]
ans=1
for j in range(1,n):
i=a[j][:]
cur1=[i[0]-i[1],i[0]]
cur2=[i[0],i[0]+i[1]]
if occ[1]<cur1[0]:
occ[1]=cur1[1]
ans+=1
elif occ[1]<cur2[0]... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 5
1 2
2 1
5 10
10 9
20 1
| O(nlogn) | 0.000019 | {
"public_tests": [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1\n",
"output": "4\n"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "4\n10 4\n15 1\n19 3\n20 1\n",
"output": "4\n"
},
{
"input": "... | [
0.000040550180837379024,
0.00003855880436215247,
0.000037366243469577454,
0.00003158604223443044,
0.00003052949442716172,
0.000029889205963354232,
0.0000298491205189229,
0.000029790363795688498,
0.00002908012661695766,
0.000028801187801628257,
0.000028444605794715804,
0.00002830989681399987,
... |
596_A. Wilbur and Swimming Pool | 966 | 966_54 | After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned... | from sys import stdin
n=int(stdin.readline().strip())
s=[]
for i in range(n):
a,b=map(int,stdin.readline().strip().split())
s.append([a,b])
ans=-1
for i in range(n):
for j in range(i+1,n):
if( s[i][0]!=s[j][0] and s[i][1]!=s[j][1] ):
ans=abs(s[i][0]-s[j][0] )* abs(s[i... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 1
1 1
| O(n**2) | 0 | {
"public_tests": [
{
"input": "1\n1 1\n",
"output": "-1\n"
},
{
"input": "2\n0 0\n1 1\n",
"output": "1\n"
}
],
"private_tests": [
{
"input": "3\n0 0\n0 3\n3 0\n",
"output": "9\n"
},
{
"input": "3\n-679 301\n240 -23\n-679 -23\n",
"output"... | [
0.0000024829999999999998,
2.580741808228214e-7,
1.8920226508842985e-7,
1.8105542957127925e-7,
1.5098335832447034e-7,
1.2233127401889193e-7,
1.0694369277867109e-7,
9.741682178042638e-8,
3.425234343771026e-8,
2.430015608223162e-8,
6.797730606948403e-10,
3.3826563466410768e-12,
1.69281059292207... |
596_A. Wilbur and Swimming Pool | 966 | 966_134 | After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned... | n = int(input())
x = []
y = []
for i in range(n):
xi, yi = map(int, input().split())
x.append(xi)
y.append(yi)
if n==1:
print(-1)
if n>=2:
s = (max(x) - min(x)) * (max(y) - min(y))
if s == 0: s = -1
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, ... | 1
1 1
| O(n) | 0.000003 | {
"public_tests": [
{
"input": "1\n1 1\n",
"output": "-1\n"
},
{
"input": "2\n0 0\n1 1\n",
"output": "1\n"
}
],
"private_tests": [
{
"input": "3\n0 0\n0 3\n3 0\n",
"output": "9\n"
},
{
"input": "3\n-679 301\n240 -23\n-679 -23\n",
"output"... | [
0.000004724798650568183,
0.00000469002496722028,
0.000004675555042613637,
0.000004572958506337413,
0.000004460456239073427,
0.000004439455610795455,
0.000004398565655048077,
0.000004309269859047203,
0.000004303156331949301,
0.0000041575331894667825,
0.000003951031932910838,
0.00000392038924552... |
299_B. Ksusha the Squirrel | 641 | 641_31 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that K... | n,k=list(map(int,input().split()))
a=input().split('.')
u=0
for i in range(len(a)):
if '#' in a[i]:
if len(a[i])+1>k:
print('NO')
u+=1
break
if u>0:
break
if u==0:
print('YES')
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2 1
..
| O(n) | 0 | {
"public_tests": [
{
"input": "2 1\n..\n",
"output": "YES\n"
},
{
"input": "5 2\n.#.#.\n",
"output": "YES\n"
},
{
"input": "7 3\n.#.###.\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "2 2\n..\n",
"output": "YES\n"
},
{
... | [
0.000192606,
0.0000035626134178321682,
0.000002832034801136364,
0.0000022234143766389862,
0.0000017401399830638116,
0.000001466919102381993,
0.0000014038440231643358,
0.0000013719016471809443,
0.0000010667500273164335,
7.145792449737763e-7,
7.064010735358393e-7,
6.42693605222902e-7,
6.212867... |
299_B. Ksusha the Squirrel | 641 | 641_25 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that K... | n, k = input().split()
n = int(n)
k = int(k)
a = list(input())
i = 0
j = []
while i < n:
if a[i] == ".":
j.append(i)
i += 1
h = []
j.sort()
f = 0
while f < len(j) - 1:
h.append(-j[f] + j[f+1] - 1)
f += 1
h.sort()
if h.pop() >= k:
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 1
..
| O(nlogn) | 0.000009 | {
"public_tests": [
{
"input": "2 1\n..\n",
"output": "YES\n"
},
{
"input": "5 2\n.#.#.\n",
"output": "YES\n"
},
{
"input": "7 3\n.#.###.\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "2 2\n..\n",
"output": "YES\n"
},
{
... | [
0.000008887536403663496,
4.1017195164340857e-7,
3.2743655952131213e-7,
2.7157751546111376e-7,
2.3770301428949807e-7,
1.6399547544032884e-7,
1.6173163409562282e-7,
1.6100371865467728e-7,
1.597198216906117e-7,
1.5951219125105772e-7,
1.5368981227247168e-7,
1.1099098316693759e-7,
6.7377610055352... |
1358_D. The Best Vacation | 888 | 888_6 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of d... | n,x=map(int,input().split());D=list(map(int,input().split()));Ans=[];D+=D;D=D[::-1];d=0;p=0;q=0;tot=0;ans=0
for i in D:Ans.append(i*(i+1)//2)
while p<2*n and q<2*n:
while p<2*n and q<2*n and d+D[p]<x:d+=D[p];tot+=Ans[p];p+=1
if p==q:k=D[p]-x+d;tot+=Ans[p]-k*(k+1)//2;ans=max(ans,tot);d=0;tot=0;p+=1;q+=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 6
4 2 3 1 3
| O(n**2) | 0 | {
"public_tests": [
{
"input": "5 6\n4 2 3 1 3\n",
"output": "15\n"
},
{
"input": "3 6\n3 3 3\n",
"output": "12\n"
},
{
"input": "3 2\n1 3 1\n",
"output": "5\n"
}
],
"private_tests": [
{
"input": "2 179\n444 57\n",
"output": "63545\n"
... | [
2.682653896713766e-7,
1.611521839985805e-7,
1.4620296709899143e-7,
1.4492787937415586e-7,
1.4233508328578557e-7,
1.2542368290989993e-7,
1.247873528906687e-7,
1.1275041747239376e-7,
1.0156673248563649e-7,
7.685779011995324e-8,
6.598793888628096e-8,
6.117735222318573e-8,
5.943745136612915e-8,
... |
1358_D. The Best Vacation | 888 | 888_179 | You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha.
You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of d... | def sumprog(a, b):
return (a + b) * (b - a + 1) // 2
n, x = map(int, input().split())
d = list(map(int, input().split())) * 2
max_hugs = 0
i = 0
j = 0
days = 0
hugs = 0
while i < n:
if days + d[j] <= x:
days += d[j]
hugs += sumprog(1, d[j])
j += 1
else:
max_hugs = max(max... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 6
4 2 3 1 3
| O(n) | 0.000015 | {
"public_tests": [
{
"input": "5 6\n4 2 3 1 3\n",
"output": "15\n"
},
{
"input": "3 6\n3 3 3\n",
"output": "12\n"
},
{
"input": "3 2\n1 3 1\n",
"output": "5\n"
}
],
"private_tests": [
{
"input": "2 179\n444 57\n",
"output": "63545\n"
... | [
0.00019660866245083044,
0.00014467846992460663,
0.00014067248001802888,
0.00013497834949307747,
0.00010044606643356645,
0.00009560635234375002,
0.0000775352680561626,
0.00007399283162150349,
0.00006936706931545019,
0.00006584990403736888,
0.0000639015780413193,
0.0000603071200284091,
0.00005... |
614_A. Link/Cut Tree | 1972 | 1972_295 | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed... | #!/usr/local/bin/python3
import sys
l, r, k = map(int, input().split())
res = 1
if k == 1:
if l == 1:
print(1)
else:
print(-1)
sys.exit()
ans = 0
while (res < l):
res *= k;
while (res <= r):
print(res)
ans += 1
res *= k
if ans == 0:
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, ... | 1 10 2
| O(logn) | 0.000002 | {
"public_tests": [
{
"input": "1 10 2\n",
"output": "1\n2\n4\n8\n"
},
{
"input": "2 4 5\n",
"output": "-1\n"
}
],
"private_tests": [
{
"input": "1 243 3\n",
"output": "1\n3\n9\n27\n81\n243\n"
},
{
"input": "18102 43332383920 28554\n",
"o... | [
0.001603740274313056,
0.001589719878330993,
0.00018389480261847845,
0.00016202877443646078,
0.000056151,
0.000047057500000000015,
0.0000319215,
0.000030950999999999996,
0.000029786000000000002,
0.000029670000000000006,
0.000029463,
0.00002890600000000001,
0.0000283545,
0.000027794499999999... |
614_A. Link/Cut Tree | 1972 | 1972_129 | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed... | l,r,k = map(int,input().split())
li = [k**i for i in range(100) if k**i >= l and k**i <= r]
if len(li) == 0:
print(-1)
else:
print(' '.join([str(s) for s in li])) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 10 2
| O(1) | 0.000104 | {
"public_tests": [
{
"input": "1 10 2\n",
"output": "1\n2\n4\n8\n"
},
{
"input": "2 4 5\n",
"output": "-1\n"
}
],
"private_tests": [
{
"input": "1 243 3\n",
"output": "1\n3\n9\n27\n81\n243\n"
},
{
"input": "18102 43332383920 28554\n",
"o... | [
0.00020957650000000006,
0.00010497849999999996,
0.00010363050000000004,
0.00008271350000000003,
0.00007181599999999999,
0.000038222,
0.000036949000000000015,
0.000016787000000000014,
0.00001093950000000002,
0.000010341999999999997,
0.000009192999999999998,
0.0000065240000000000006,
0.0000038... |
1331_D. Again? | 1017 | 1017_834 |
Input
The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9.
Output
Output a single integer.
Examples
Input
A278832
Output
0
Input
A089956
Output
0
Input
A089957
Output
1
Input
A1440... | import random
s = input()
a = list()
for items in s:
a.append(items)
if int(a[6])%2 == 0:
print('0')
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, ... | A089956
| O(n) | 0.000002 | {
"public_tests": [
{
"input": "A089956\n",
"output": "0\n"
},
{
"input": "A089957\n",
"output": "1\n"
},
{
"input": "A144045\n",
"output": "1\n"
},
{
"input": "A278832\n",
"output": "0\n"
}
],
"private_tests": [],
"generated_tests"... | [
0.000004437130367679195,
0.000003499883112980769,
0.000001968530744645979,
0.0000018422623197115387,
0.0000011806296301354896,
2.2993191378933566e-7,
2.2796734320367137e-7,
1.6151394503933564e-7,
1.1617810314685316e-7,
1.1086681872814685e-7,
1.0860606971153846e-7,
1.009252895541958e-7,
9.832... |
1331_D. Again? | 1017 | 1017_937 |
Input
The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9.
Output
Output a single integer.
Examples
Input
A278832
Output
0
Input
A089956
Output
0
Input
A089957
Output
1
Input
A1440... | n=input()
num=int(n[6])-48
if num%2==0:
print(0)
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, ... | A089956
| O(1) | 0.000001 | {
"public_tests": [
{
"input": "A089956\n",
"output": "0\n"
},
{
"input": "A089957\n",
"output": "1\n"
},
{
"input": "A144045\n",
"output": "1\n"
},
{
"input": "A278832\n",
"output": "0\n"
}
],
"private_tests": [],
"generated_tests"... | [
0.00003545799999999863,
0.000009081499999999998,
0.000009003000000000002,
0.000007679999999999998,
0.000007674499999999999,
0.000006096499999999998,
0.000005591000000000001,
0.000005015999999999994,
0.000003058999999999999,
0.0000027550000000000033,
0.000002569500000000003,
0.00000238499999999... |
903_C. Boxes Packing | 1857 | 1857_13 | Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka ... | #!/user/bin/env/python 3.5
#---*--- code: utf-8 ---*---
n=int(input())
a=input().split(' ')
num=0
for i in a:
num=max(num,a.count(i))
print(num)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
1 2 3
| O(n**2) | 0 | {
"public_tests": [
{
"input": "3\n1 2 3\n",
"output": "1\n"
},
{
"input": "4\n4 2 4 3\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "10\n58 58 58 58 58 58 58 58 58 58\n",
"output": "10\n"
},
{
"input": "8\n1 2 3 4 5 6 7 8\n",
"o... | [
0.00006960281053788754,
0.000047862291369533945,
0.00003327641560452274,
0.00003199247519489826,
0.000031973130061671015,
0.0000318740706525962,
0.00003185238063938714,
0.00000808114114025115,
0.000008069011653386711,
0.000002157901585676982,
0.0000018323731993062588,
0.000001679150651302874,
... |
903_C. Boxes Packing | 1857 | 1857_103 | Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka ... | n=int(input())
a=sorted(list(map(int,input().split())))
d={}
for i in a:
if i not in d:
d[i]=1
else:
d[i]+=1
print(max(d.values()))
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
1 2 3
| O(nlogn) | 0.000008 | {
"public_tests": [
{
"input": "3\n1 2 3\n",
"output": "1\n"
},
{
"input": "4\n4 2 4 3\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "10\n58 58 58 58 58 58 58 58 58 58\n",
"output": "10\n"
},
{
"input": "8\n1 2 3 4 5 6 7 8\n",
"o... | [
0.00011171138404017858,
0.00003275984567235806,
0.00003270968746578852,
0.000016565238623990032,
0.000015788078387262923,
0.000011220225145423722,
0.00001115144514384854,
0.000010550654605482152,
0.000010270594058676044,
0.000009384553598440358,
0.000009108074320544486,
0.000009065781048634521... |
519_C. A and B and Team Training | 459 | 459_199 | A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi... | def training(n,m):
t=0
for i in range(5*(10**5)):
if n>=m and n>1 and m>0:
n-=2
m-=1
t+=1
elif n<m and n>0 and m>1:
n-=1
m-=2
t+=1
else:
return t
a,b=list(map(int,input().split(" ")))
print(training(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 5
| O(n+m) | 0.000001 | {
"public_tests": [
{
"input": "4 5\n",
"output": "3\n"
},
{
"input": "2 6\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "20001 10001\n",
"output": "10000\n"
},
{
"input": "10 0\n",
"output": "0\n"
},
{
"input": "25... | [
0.000010523191447224651,
0.000009289539690777972,
0.000003903605181927448,
0.0000036652539608828673,
0.000003663247848830856,
0.0000035570704354239512,
0.0000035520695612980775,
0.0000035471434112762237,
0.0000035330395678540218,
0.000003457449587521854,
0.000003340461975524476,
0.000003330049... |
519_C. A and B and Team Training | 459 | 459_146 | A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi... | def maxTeams(a,b):
ans=min((a+b)//3,min(a,b))
return ans
inputArray=input().strip().split()
a=int(inputArray[0])
b=int(inputArray[1])
print(maxTeams(a,b)) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4 5
| O(1) | 0.000002 | {
"public_tests": [
{
"input": "4 5\n",
"output": "3\n"
},
{
"input": "2 6\n",
"output": "2\n"
}
],
"private_tests": [
{
"input": "20001 10001\n",
"output": "10000\n"
},
{
"input": "10 0\n",
"output": "0\n"
},
{
"input": "25... | [
0.000009050500000000004,
0.000005439,
0.0000046769999999999994,
0.000003994499999999997,
0.000003992500000000006,
0.000003949499999999993,
0.000003943500000000007,
0.000003831499999999999,
0.000003818500000000001,
0.0000037080000000000024,
0.0000035844999999999993,
0.0000035799999999999962,
... |
432_B. Football Kit | 378 | 378_20 | Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one aw... | n=int(input())
x=[]
for i in range(n):
x.append(list(map(int,input().split())))
h={}
a={}
for i in range(n):
if(h.get(str(x[i][0]))):
h[str(x[i][0])]+=1
else:
h[str(x[i][0])]=1
for i in range(n):
home=n-1
if(h.get(str(x[i][1]))):
if(h[str(x[i][1])]>0):
away... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2
1 2
2 1
| O(n*m) | 0.000001 | {
"public_tests": [
{
"input": "2\n1 2\n2 1\n",
"output": "2 0\n2 0\n"
},
{
"input": "3\n1 2\n2 1\n1 3\n",
"output": "3 1\n4 0\n2 2\n"
}
],
"private_tests": [
{
"input": "3\n1 100000\n1 100000\n100000 2\n",
"output": "3 1\n3 1\n2 2\n"
},
{
"inp... | [
0.00000246554921875,
0.000002223430165537589,
0.0000010747950311407342,
9.99361601289336e-7,
9.79059536166958e-7,
9.63935041520979e-7,
9.558416876092657e-7,
9.039007457386364e-7,
8.903856534090909e-7,
8.730244891826925e-7,
8.718835363854897e-7,
8.650891881555945e-7,
8.637913707386364e-7,
8... |
432_B. Football Kit | 378 | 378_91 | Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).
In the tournament, each team plays exactly one home game and exactly one aw... | from sys import stdin
_data = iter(stdin.read().split('\n'))
input = lambda: next(_data)
from collections import Counter
n = int(input())
ct = Counter()
a = [tuple(map(int, input().split())) for _ in range(n)]
for x, y in a:
ct[x] += 1
buf = []
for x, y in a:
buf.append('{} {}'.format((n - 1) + ct[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, ... | 2
1 2
2 1
| O(n) | 0.000012 | {
"public_tests": [
{
"input": "2\n1 2\n2 1\n",
"output": "2 0\n2 0\n"
},
{
"input": "3\n1 2\n2 1\n1 3\n",
"output": "3 1\n4 0\n2 2\n"
}
],
"private_tests": [
{
"input": "3\n1 100000\n1 100000\n100000 2\n",
"output": "3 1\n3 1\n2 2\n"
},
{
"inp... | [
0.000018824493730878496,
0.000017640543433129372,
0.00001742133128004808,
0.0000166809409965035,
0.00001632817175207605,
0.00001594464309713724,
0.000015757842671000878,
0.00001561503952687937,
0.000015074659241149475,
0.000014973543993116262,
0.000014810393288352274,
0.000014753776346700177,
... |
471_A. MUH and Sticks | 2036 | 2036_120 | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
... | sticksL = input().split()
for i in sticksL:
lNum = sticksL.count(i)
if (lNum > 3):
break
sticksL = set(sticksL)
if(lNum > 3 and (len(sticksL) == 3 or (len(sticksL) == 2 and lNum > 4))):
print("Bear")
elif(lNum > 3):
print("Elephant")
else:
print("Alien") | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 2 3 4 5 6
| O(n**2) | 0 | {
"public_tests": [
{
"input": "1 2 3 4 5 6\n",
"output": "Alien\n"
},
{
"input": "4 4 5 4 4 5\n",
"output": "Elephant\n"
},
{
"input": "4 2 5 4 4 4\n",
"output": "Bear\n"
}
],
"private_tests": [
{
"input": "5 5 5 5 5 5\n",
"output": "Ele... | [
0.00022337594407115528,
0.000011174756605822285,
0.000005836245910170028,
0.00000369365114735029,
0.0000036914852968573944,
0.000003689678143050299,
0.0000035697187805462137,
0.00000352703240775201,
0.0000034953617054595763,
0.000001393418198363401,
9.916044476389541e-7,
9.243480435163286e-7,
... |
471_A. MUH and Sticks | 2036 | 2036_19 | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
... | ls = [0] * 9
for i in input().split():
ls[int(i) - 1] += 1
x = [i for i in ls if i > 0]
if x == [6] or x == [2, 4] or x == [4, 2]:
print("Elephant")
elif x == [1,1,4] or x == [1,4,1] or x == [4,1,1] or x == [1,5] or x == [5,1]:
print("Bear")
else:
print("Alien")
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 2 3 4 5 6
| O(n) | 0.000003 | {
"public_tests": [
{
"input": "1 2 3 4 5 6\n",
"output": "Alien\n"
},
{
"input": "4 4 5 4 4 5\n",
"output": "Elephant\n"
},
{
"input": "4 2 5 4 4 4\n",
"output": "Bear\n"
}
],
"private_tests": [
{
"input": "5 5 5 5 5 5\n",
"output": "Ele... | [
0.000010454228406359266,
0.000007804899162852024,
0.000007203970197770979,
0.000007021751707277098,
0.000006136393575174826,
0.00000583030617624563,
0.000005725478515625001,
0.000005638633099322553,
0.000005634792408763112,
0.000005458050043706295,
0.000005454601453234266,
0.000005444354417067... |
471_A. MUH and Sticks | 2036 | 2036_33 | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
... | import math
alph="abcdefghijklmnopqrstuvwxyz"
#-----------------------------------
l=list(map(int,input().split()))
l.sort()
if l[2]!=l[3]:
print("Alien")
else:
k=l[2];t=l.count(k)
if t>=4:
for i in range(4):
del(l[l.index(k)])
if l[0]==l[1]:
print("Elephant")
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 2 3 4 5 6
| O(nlogn) | 0.000018 | {
"public_tests": [
{
"input": "1 2 3 4 5 6\n",
"output": "Alien\n"
},
{
"input": "4 4 5 4 4 5\n",
"output": "Elephant\n"
},
{
"input": "4 2 5 4 4 4\n",
"output": "Bear\n"
}
],
"private_tests": [
{
"input": "5 5 5 5 5 5\n",
"output": "Ele... | [
0.000040508090615217335,
0.00002978182456032826,
0.000024568143431325173,
0.00001937720368010094,
0.000019152647187480354,
0.000018723711099374754,
0.000018442039491186075,
0.000018205870608093466,
0.000018146137645619155,
0.000018020930710999955,
0.000017941266949719992,
0.0000179139741062930... |
276_A. Lunch Rush | 2012 | 2012_399 | Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.
The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch... | X = list(map(int, input().split()))
MAX = -10**9
for i in range(X[0]):
Y = list(map(int, input().split()))
MAX = max(MAX, min(Y[0], Y[0] - (Y[1] - X[1])))
print(MAX)
| import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, 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 5
3 3
4 5
| O(n*m) | 0.000002 | {
"public_tests": [
{
"input": "2 5\n3 3\n4 5\n",
"output": "4\n"
},
{
"input": "1 5\n1 7\n",
"output": "-1\n"
},
{
"input": "4 6\n5 8\n3 6\n2 3\n2 2\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "2 5\n1 7\n1 1000000000\n",
"outp... | [
0.000008083823003168708,
0.000003065309973229895,
0.000002076409787478147,
0.0000018285113772945805,
0.000001810257867132867,
0.0000018039550644667832,
0.0000018032651059877623,
0.0000017988515898164335,
0.0000017948386281687062,
0.0000017923142619099653,
0.0000017910334762893356,
0.0000017904... |
276_A. Lunch Rush | 2012 | 2012_342 | Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.
The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch... | n,k=map(int, input().split())
s = set()
for i in range(n):
a,b=map(int, input().split())
if b > k:
s.add(a-(b-k))
else:
s.add(a)
print(max(s)) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 2 5
3 3
4 5
| O(n) | 0.000006 | {
"public_tests": [
{
"input": "2 5\n3 3\n4 5\n",
"output": "4\n"
},
{
"input": "1 5\n1 7\n",
"output": "-1\n"
},
{
"input": "4 6\n5 8\n3 6\n2 3\n2 2\n",
"output": "3\n"
}
],
"private_tests": [
{
"input": "2 5\n1 7\n1 1000000000\n",
"outp... | [
0.000010482544443837414,
0.000009590306107954547,
0.000009317312937062937,
0.00000922499108118444,
0.00000921845940777972,
0.000009094745875218532,
0.000009048160142591784,
0.000009037733500874126,
0.000009027265597683568,
0.000008942988445148604,
0.000008892516922530595,
0.0000088364799907124... |
667_B. Coat of Anticubism | 2071 | 2071_33 | <image>
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to tran... | n = int(input())
data = [int(i) for i in input().split()]
mx, box = 0, 0
for i in data:
if i > mx:
box += mx
mx = i
else:
box += i
print(mx - box + 1) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
1 2 1
| O(n) | 0.000002 | {
"public_tests": [
{
"input": "3\n1 2 1\n",
"output": "1\n"
},
{
"input": "5\n20 4 3 2 1\n",
"output": "11\n"
}
],
"private_tests": [
{
"input": "3\n800000000 1 1\n",
"output": "799999999\n"
},
{
"input": "5\n100000000 100000000 100000000 1000... | [
0.0000033792746530812942,
0.000002959672585227273,
0.000002757280157342657,
0.0000025524621667395105,
0.0000019603305561625875,
0.0000018951387538243009,
0.000001879339024256993,
0.0000018704826677229024,
0.0000018335432282561188,
0.0000018212284473339163,
0.0000017781688701923082,
0.000001770... |
667_B. Coat of Anticubism | 2071 | 2071_39 | <image>
As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to tran... | n = int(input())
a = list(map(int, input().split()))
s = sum(a)
t = 0
a.sort(reverse = True)
for i in a :
t += i
s -= i
if(t >= s) :
break
print(t - 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, ... | 3
1 2 1
| O(nlogn) | 0.000008 | {
"public_tests": [
{
"input": "3\n1 2 1\n",
"output": "1\n"
},
{
"input": "5\n20 4 3 2 1\n",
"output": "11\n"
}
],
"private_tests": [
{
"input": "3\n800000000 1 1\n",
"output": "799999999\n"
},
{
"input": "5\n100000000 100000000 100000000 1000... | [
0.00007090560824136801,
0.000009168467814752944,
0.000008485904801478106,
0.00000838363856678779,
0.000008320235492910415,
0.000008305531179548325,
0.000008282374181417682,
0.000008265451419803305,
0.000008250448730025979,
0.000008228515485974105,
0.000008227173990393061,
0.0000082090610943712... |
426_A. Sereja and Mugs | 3070 | 3070_20 | Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that... | n, s = map(int, input().split())
a = [int(i) for i in input().split()]
summa = 0
for i in a:
summa += i
summa -= max(a)
if s < summa:
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, ... | 3 4
1 1 1
| O(n) | 0.000002 | {
"public_tests": [
{
"input": "3 4\n1 1 1\n",
"output": "YES\n"
},
{
"input": "3 4\n3 1 3\n",
"output": "YES\n"
},
{
"input": "3 4\n4 4 4\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "8 15\n8 10 4 2 10 9 7 6\n",
"output": "NO\... | [
0.00008402070692198427,
0.0000025564032725087413,
0.0000023292545208697555,
0.0000023024397262893355,
0.0000022920707768793705,
0.0000022898507020323427,
0.000002243337426245629,
0.0000020480071159309445,
0.000001987940682364511,
0.0000019058108473557694,
0.0000018732537696678322,
0.0000018368... |
426_A. Sereja and Mugs | 3070 | 3070_180 | Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that... | n,s=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
sum1=0
for i in range(n-1):
sum1+=l[i]
if sum1<=s:
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 4
1 1 1
| O(nlogn) | 0.000009 | {
"public_tests": [
{
"input": "3 4\n1 1 1\n",
"output": "YES\n"
},
{
"input": "3 4\n3 1 3\n",
"output": "YES\n"
},
{
"input": "3 4\n4 4 4\n",
"output": "NO\n"
}
],
"private_tests": [
{
"input": "8 15\n8 10 4 2 10 9 7 6\n",
"output": "NO\... | [
0.000008743611147258084,
0.000008723538291141654,
0.000008719430479128624,
0.000008691027225030414,
0.000008673529210798369,
0.000008669989521832536,
0.000008668680977218654,
0.000008648360252426004,
0.000008630813529047823,
0.000008627484934425815,
0.000008624443118673937,
0.00000861444975239... |
999_A. Mishka and Contest | 1470 | 1470_325 | Mishka started participating in a programming contest. There are n problems in the contest. Mishka's problem-solving skill is equal to k.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses whic... | a,b = map(int,input().split())
l= [int(i) for i in input().split()]
c=0
while len(l)>0:
premier = l[0]
last= l[-1]
if premier<=b:
c+=1
del l[0]
elif last<=b:
c+=1
del l[-1]
else:
break
print(c) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 5 2
3 1 2 1 3
| O(n**2) | 0 | {
"public_tests": [
{
"input": "5 2\n3 1 2 1 3\n",
"output": "0\n"
},
{
"input": "8 4\n4 2 3 1 5 1 6 4\n",
"output": "5\n"
},
{
"input": "5 100\n12 34 55 43 21\n",
"output": "5\n"
}
],
"private_tests": [
{
"input": "100 3\n86 53 82 40 2 20 59 2... | [
0.00018643972630212757,
0.00018561802392305944,
0.00003542402474322929,
0.000035115661554754254,
0.00000391494161170692,
0.0000020116737052010487,
3.5816787967643894e-7,
2.5556099582856006e-7,
8.216000661794836e-8,
5.8092149840574096e-8,
3.125028346476352e-8,
2.3469105971252583e-8,
2.3467617... |
999_A. Mishka and Contest | 1470 | 1470_470 | Mishka started participating in a programming contest. There are n problems in the contest. Mishka's problem-solving skill is equal to k.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses whic... | arr=list(map(int, input().split(' ')))
ar=list(map(int, input().split(' ')))
t=0
for i in range (arr[0]):
if ar[i]>arr[1]:
t=ar.index(ar[i])
break
ar.reverse()
z=0
for each in ar:
if each>arr[1]:
z=ar.index(each)
break
ar=sorted(ar)
s=0
for h in ar:
if h>arr[1]:
s=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, ... | 5 2
3 1 2 1 3
| O(nlogn) | 0.000014 | {
"public_tests": [
{
"input": "5 2\n3 1 2 1 3\n",
"output": "0\n"
},
{
"input": "8 4\n4 2 3 1 5 1 6 4\n",
"output": "5\n"
},
{
"input": "5 100\n12 34 55 43 21\n",
"output": "5\n"
}
],
"private_tests": [
{
"input": "100 3\n86 53 82 40 2 20 59 2... | [
0.007605864,
0.000013983426935553359,
0.000012737800091513689,
0.00001034816559222028,
0.000009204237461756993,
0.000008086459633140297,
0.000007166970170454546,
0.000006523476032334837,
0.000005728738745686914,
0.000005362975895639863,
0.0000048476980796514426,
0.00000468346164339015,
0.000... |
p03362 AtCoder Beginner Contest 096 - Five Five Everywhere | 1303 | 1303_8 | Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite n... | n = int(input())
P, A = [2], [2]
for i in range(3, 55556, 2):
for p in P:
if i % p == 0: break
else:
P.append(i)
if i % 5 == 2: A.append(i)
if len(A) == n: break
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, ... | 6 | O(n**2) | 0.000048 | {
"public_tests": [
{
"input": "6",
"output": "2 3 5 7 11 13"
},
{
"input": "8",
"output": "2 5 7 13 19 37 67 79"
},
{
"input": "5",
"output": "3 5 7 11 31"
}
],
"private_tests": [],
"generated_tests": [
{
"input": "10",
"output": "11 3... | [
0.0006546860835343179,
0.0005015535952613339,
0.00037097237234989344,
0.0003095184777841412,
0.0001931838247842775,
0.00018965900520431282,
0.00018122174860431625,
0.00017997004693576918,
0.0001757862907744137,
0.00017425124626937026,
0.0001727605290759485,
0.0001717665401045425,
0.000079433... |
p03362 AtCoder Beginner Contest 096 - Five Five Everywhere | 1303 | 1303_56 | Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite n... |
p5_list = [11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381]
N=int(input())
print(*p5_list[: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, ... | 6 | O(1) | 0.000047 | {
"public_tests": [
{
"input": "6",
"output": "2 3 5 7 11 13"
},
{
"input": "8",
"output": "2 5 7 13 19 37 67 79"
},
{
"input": "5",
"output": "3 5 7 11 31"
}
],
"private_tests": [],
"generated_tests": [
{
"input": "10",
"output": "11 3... | [
0.3170509165,
0.30442224500000004,
0.26669425099999994,
0.18929231800000001,
0.18828871850000004,
0.1121259705,
0.10405197850000002,
0.10320195550000001,
0.098064452,
0.087254892,
0.0628505805,
0.032089427999999996,
0.03045150749999999,
0.027866709000000007,
0.026372599499999996,
0.025... |
1436_C. Binary Search | 1359 | 1359_4 | Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number x in an array. For an array a indexed from zero, and an integer x the pseudocode o... | import math
a, b, c = map(int, input().split())
d1 = 0
d2 = 0
e = 0
f = a
while e < f:
g = (e + f) // 2
if g <= c:
e = g + 1
if g < c:
d1 += 1
else:
f = g
d2 += 1
h = 1
for i in range (b - 1, b - 1 - d1, -1):
h *= i
for i in range (a - b, a - b - d2, -1):
... | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 4 1 2
| O(n**2) | 0 | {
"public_tests": [
{
"input": "4 1 2\n",
"output": "6"
},
{
"input": "123 42 24\n",
"output": "824071958"
}
],
"private_tests": [
{
"input": "10 7 7\n",
"output": "90720"
},
{
"input": "1000 1 1\n",
"output": "756641425"
},
{
... | [
0.000017702008597847468,
0.000010974643426001481,
3.6206151397732666e-7,
3.1015918259445383e-7,
1.831167498734166e-7,
1.5804989157559046e-7,
7.052256008995927e-8,
2.6758526040722068e-8,
9.523756875605676e-9,
8.007368019376784e-9,
7.2624054541826455e-9,
6.497065874868151e-9,
5.223140711596142... |
1436_C. Binary Search | 1359 | 1359_189 | Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number x in an array. For an array a indexed from zero, and an integer x the pseudocode o... | n,x,a = map(int,input().split())
ans = 1
cnt = 0
cnt1 = 0
i = 0
j = n
mod = 1000000007
while i<j:
mid = (i+j)//2
if mid<a:
ans*=(x-1-cnt1)
ans%=mod
cnt1+=1
i = mid+1
elif mid>a:
ans*=(n-x-cnt)
ans%=mod
cnt+=1
j = mid
else:
i = mid+1
cr = n-cnt-cnt1-1
for i in range(1,cr+1):
ans*=i
ans%=mod
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 2
| O(n) | 0.000003 | {
"public_tests": [
{
"input": "4 1 2\n",
"output": "6"
},
{
"input": "123 42 24\n",
"output": "824071958"
}
],
"private_tests": [
{
"input": "10 7 7\n",
"output": "90720"
},
{
"input": "1000 1 1\n",
"output": "756641425"
},
{
... | [
0.000014334727641499126,
0.00000908137096399694,
0.000008926000109265735,
0.00000821104636964598,
0.00000809190409200175,
0.000006106930985030594,
0.000005784560355659965,
0.000005745291015625,
0.000004894897454108392,
0.000004810050931490385,
0.00000479210653409091,
0.000004637951007976399,
... |
774_C. Maximum Number | 2880 | 2880_19 | Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
<image>
So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be high... | a=int(input())
sstring=[]
if a%2:
sstring.append('7')
else:
a=a
if a%2:
a=a-3
else:
a=a
for i in range (a // 2):
sstring.append('1')
print(''.join(sstring)) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
| O(n) | 0.000001 | {
"public_tests": [
{
"input": "3\n",
"output": "7\n"
},
{
"input": "2\n",
"output": "1\n"
}
],
"private_tests": [
{
"input": "8343\n",
"output": "711111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111... | [
0.0000026119671929632867,
0.000002330341453598485,
0.0000018969252758959795,
0.00000189596571969697,
0.000001749116785037879,
0.000001730794839015152,
0.0000017261850615530304,
0.0000017098497159090912,
0.0000017079087594696968,
0.000001690631818181818,
0.0000016791968831949302,
0.000001665265... |
774_C. Maximum Number | 2880 | 2880_23 | Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
<image>
So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be high... | n = int(input())
if n % 2 == 0:
print('1'*(n//2))
else:
print('7'+'1'*((n-3)//2)) | import sys
import time
import itertools
from itertools import accumulate, product, permutations, combinations
import collections
from collections import Counter, OrderedDict, deque, defaultdict, ChainMap
from functools import lru_cache
import math
from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ... | 3
| O(1) | 0.000002 | {
"public_tests": [
{
"input": "3\n",
"output": "7\n"
},
{
"input": "2\n",
"output": "1\n"
}
],
"private_tests": [
{
"input": "8343\n",
"output": "711111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111... | [
0.000004077499999999989,
0.000003988500000000001,
0.000003447500000000004,
0.000003011999999999991,
0.0000028560000000000282,
0.000002628499999999997,
0.000002544499999999999,
0.0000021795000000000017,
0.000002166999999999998,
0.000002165499999999998,
0.0000021409999999999986,
0.00000210899999... |
p02899 AtCoder Beginner Contest 142 - Go to School | 1421 | 1421_53 | Takahashi is a teacher responsible for a class of N students.
The students are given distinct student numbers from 1 to N.
Today, all the students entered the classroom at different times.
According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including... | N = int(input())
A = [int(i) for i in input().split()]
B=[0]*N
for i in range(N):
B[A[i]-1]=i+1
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, ... | 5
1 2 3 4 5 | O(n+m) | 0.000006 | {
"public_tests": [
{
"input": "5\n1 2 3 4 5",
"output": "1 2 3 4 5"
},
{
"input": "3\n2 3 1",
"output": "3 1 2"
},
{
"input": "8\n8 2 7 3 4 5 6 1",
"output": "8 2 4 5 6 7 3 1"
}
],
"private_tests": [],
"generated_tests": [
{
"input": "3\n1 3... | [
0.000006456087093404395,
0.000005754092872004581,
0.0000056194341374834885,
0.000005607162356218471,
0.000005599632989821261,
0.0000055852019402053015,
0.0000055844697098325425,
0.0000055843018858150905,
0.000005580964807519087,
0.000005576371954220133,
0.000005575428068226621,
0.0000055715671... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.