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
p02899 AtCoder Beginner Contest 142 - Go to School
1421
1421_89
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 = map(int, input().split()) for i, x in sorted(enumerate(a), key=lambda x:x[1]): print(i+1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 1 2 3 4 5
O(nlogn)
0.000104
{ "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.00011759309000764862, 0.00010762189335664335, 0.0001037254084353147, 0.0001034024000628278, 0.0000208774658882254, 0.000020848019753668598, 0.000020826956090857764, 0.000020826729944745263, 0.000020722941474005343, 0.000020700992328922824, 0.00001620422760435549, 0.000016145646689415423, 0...
998_A. Balloons
2225
2225_120
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside. T...
n = int(input()) a = [int(i) for i in input().split()] res = [] if n == 2 and a[0] == a[1]: print("-1") elif n == 1: print("-1") else: for i in range(n): if a[i] != sum(a)-a[i]: #print("1") res.append(i+1) break if len(res)!=0: print("1") print(*res)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 5 5
O(n)
0.000001
{ "public_tests": [ { "input": "2\n5 5\n", "output": "-1\n" }, { "input": "1\n10\n", "output": "-1\n" }, { "input": "3\n1 2 1\n", "output": "1\n1\n" } ], "private_tests": [ { "input": "2\n3 4\n", "output": "1\n1\n" }, { "inp...
[ 0.00000684931203562063, 0.000004111471235795455, 0.000003482667422421329, 0.0000031855778108610143, 0.0000031089476753715034, 0.000002767197893902972, 0.0000017570327524038461, 0.000001547737789554196, 0.0000014488516034746503, 0.0000014439397536057691, 0.0000013116480414117135, 0.000001263735...
998_A. Balloons
2225
2225_154
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside. T...
n=int(input()) l=list(map(int,input().split())) z=sorted(l) for i in range(n): if(l[i]==z[0]): mi=i if(n>2): print(1) print(mi+1) else: if(n==2): if(l[0]==l[1]): print(-1) else: print(1) print(1) 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, ...
2 5 5
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2\n5 5\n", "output": "-1\n" }, { "input": "1\n10\n", "output": "-1\n" }, { "input": "3\n1 2 1\n", "output": "1\n1\n" } ], "private_tests": [ { "input": "2\n3 4\n", "output": "1\n1\n" }, { "inp...
[ 0.00001487350956758086, 0.000007890060685209193, 0.000005875799469236228, 0.000005724915108249959, 0.000005694275795251496, 0.000005692550469123046, 0.000005601055835244623, 0.0000056008480670335, 0.000005529925362059548, 0.000005518269525560505, 0.000005468544879528067, 0.00000541318211724525...
554_A. Kyoya and Photobooks
208
208_189
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho...
s = input() d = set() for i in range(len(s)): for a in range(26): c = chr(ord('a') + a) d.add(s[:i] + c + s[i:]) for a in range(26): c = chr(ord('a') + a) d.add(s + c) print(len(d))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
hi
O(n**2)
0
{ "public_tests": [ { "input": "hi\n", "output": "76\n" }, { "input": "a\n", "output": "51\n" } ], "private_tests": [ { "input": "lpfpndmjfvqejdgf\n", "output": "426\n" }, { "input": "jgv\n", "output": "101\n" }, { "input": ...
[ 0.00012520692329937263, 0.00009314353201106953, 0.00003060270971891746, 0.000025367778315929165, 0.00002040262613810997, 0.000017217223148623228, 0.000012184908833303432, 0.000010606266672511841, 0.000010498075041907789, 0.0000022618119292397904, 0.000001523223157374498, 0.00000123692826636016...
554_A. Kyoya and Photobooks
208
208_290
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho...
q=input() print((26*(len(q)+1))-len(q))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
hi
O(1)
0.000002
{ "public_tests": [ { "input": "hi\n", "output": "76\n" }, { "input": "a\n", "output": "51\n" } ], "private_tests": [ { "input": "lpfpndmjfvqejdgf\n", "output": "426\n" }, { "input": "jgv\n", "output": "101\n" }, { "input": ...
[ 0.0000092125, 0.000006173999999999999, 0.000004010999999999999, 0.000003879499999999999, 0.000003821000000000003, 0.0000037725000000000016, 0.0000036205000000000003, 0.0000032874999999999986, 0.0000030344999999999995, 0.000003029500000000002, 0.000003023499999999999, 0.000002972499999999999, ...
p03346 AtCoder Grand Contest 024 - Backfront
785
785_12
You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of op...
n = int(input()) P = list(int(input()) for _ in range(n)) tmp = [0]*(n+1) for p in P: tmp[p] = tmp[p-1] + 1 print(n-max(tmp))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 3 2 4
O(n)
0.000007
{ "public_tests": [ { "input": "4\n1\n3\n2\n4", "output": "2" }, { "input": "6\n3\n2\n5\n1\n4\n6", "output": "4" }, { "input": "8\n6\n3\n1\n2\n7\n4\n8\n5", "output": "5" } ], "private_tests": [], "generated_tests": [ { "input": "6\n2\n3\n5\n1...
[ 0.000011606912883573293, 0.00001117323744348742, 0.00001096720235172912, 0.000010854735985887323, 0.00001040346890405164, 0.000010382907228718033, 0.000010300438166388, 0.0000102036042349542, 0.000009942398058643584, 0.000009919641263464456, 0.000009682034631312071, 0.000009643415811723538, ...
p03346 AtCoder Grand Contest 024 - Backfront
785
785_75
You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of op...
N = int(input()) P = [int(input()) for i in range(N)] Q = sorted([(p, i) for i, p in enumerate(P, start=1)]) Q = [i for p, i in Q] dp = [1] * (N + 1) for i in range(1, N): if Q[i] > Q[i - 1]: dp[i] = dp[i - 1] + 1 print(N - max(dp))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 1 3 2 4
O(nlogn)
0.000013
{ "public_tests": [ { "input": "4\n1\n3\n2\n4", "output": "2" }, { "input": "6\n3\n2\n5\n1\n4\n6", "output": "4" }, { "input": "8\n6\n3\n1\n2\n7\n4\n8\n5", "output": "5" } ], "private_tests": [], "generated_tests": [ { "input": "6\n2\n3\n5\n1...
[ 0.000013361513850240144, 0.000013295451738731182, 0.000013168628352549842, 0.00001316351159361371, 0.00001314911160934065, 0.000013071714921892292, 0.00001292406651186105, 0.00001287343854928567, 0.000007249596649102561, 0.0000018607959369831631, 0.000001840350349001386, 0.00000182579998859763...
1038_D. Slime
241
241_47
There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and ...
n=int(input()) a=list(map(int,input().split())) if n==1: print(a[0]) elif all(ele>0 for ele in a): s=sum(a)-2*min(a) print(s) elif all(ele<0 for ele in a): s=abs(sum(a))-2*abs(max(a)) print(s) else: ans=0 for ele in a: ans+=abs(ele) print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 0 -1 -1 -1 -1
O(n)
0.000003
{ "public_tests": [ { "input": "5\n0 -1 -1 -1 -1\n", "output": "4\n" }, { "input": "4\n2 1 2 1\n", "output": "4\n" } ], "private_tests": [ { "input": "2\n-4 -5\n", "output": "1\n" }, { "input": "10\n-20 0 3 -5 -18 15 -3 -9 -7 9\n", "outpu...
[ 0.00006656429014149913, 0.00000980716631610577, 0.000008878529529064684, 0.000007514530990493882, 0.000007044526606206295, 0.000006722935642482519, 0.000006714250191215036, 0.000006133023068728146, 0.000006001241695804197, 0.00000597809799770542, 0.000005613161590362762, 0.00000512978796984265...
1038_D. Slime
241
241_101
There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and ...
n=int(input()) a=list(map(int, input().split())) a.sort() if n==1: print(a[0]) else: i=0 while i<n and a[i]<=0: i+=1 if i==0: print(sum(a)-2*a[0]) elif i==n: print(2*a[-1]-sum(a)) else: print(sum(a[i:])-sum(a[: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 0 -1 -1 -1 -1
O(nlogn)
0.000014
{ "public_tests": [ { "input": "5\n0 -1 -1 -1 -1\n", "output": "4\n" }, { "input": "4\n2 1 2 1\n", "output": "4\n" } ], "private_tests": [ { "input": "2\n-4 -5\n", "output": "1\n" }, { "input": "10\n-20 0 3 -5 -18 15 -3 -9 -7 9\n", "outpu...
[ 0.00001544955280476841, 0.000015140723196887759, 0.000015071069252096494, 0.000014926029658021674, 0.000014714823299308463, 0.000014685723190268757, 0.00001467396998400372, 0.000014664351434701651, 0.000014650366458595645, 0.000014578322900669797, 0.000014576411198934248, 0.0000145064702200751...
1111_A. Superhero Transformation
2436
2436_325
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name s can transform to another superhero with name t if s can be made equal to t by changing any vowel in s to any other vowel and any consonant in s to any other cons...
cons=['b', 'c', 'd','f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't','v', 'w', 'x', 'y', 'z'] vow=['a','e','i','o','u'] a=input() b=input() n=len(a) a=list(a) b=list(b) i=0 while(i<n): if (n!=len(b)): print('No') break if ((a[i] in cons) and (b[i] in vow)) or ((a[i] in vow) and (...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
akm ua
O(n+m)
0
{ "public_tests": [ { "input": "akm\nua\n", "output": "No\n" }, { "input": "a\nu\n", "output": "YES\n" }, { "input": "abc\nukm\n", "output": "YES\n" } ], "private_tests": [ { "input": "b\na\n", "output": "NO\n" }, { "input":...
[ 0.000005240149065777971, 0.0000028484165756118883, 0.0000019716642400568185, 0.0000019526300808566434, 0.0000016574835418487765, 0.0000016481015215253498, 0.0000016451539554195806, 0.0000015658521224868882, 0.0000015637970252403846, 0.0000015148798759833915, 0.000001479528859812063, 0.00000145...
1111_A. Superhero Transformation
2436
2436_612
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name s can transform to another superhero with name t if s can be made equal to t by changing any vowel in s to any other vowel and any consonant in s to any other cons...
a={*'aeiou'} i=input x,y=i(),i() print('YNEOS'[len(x)!=len(y) or any((u in a)^(v in a) for u,v in zip(x,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, ...
akm ua
O(1)
0.000001
{ "public_tests": [ { "input": "akm\nua\n", "output": "No\n" }, { "input": "a\nu\n", "output": "YES\n" }, { "input": "abc\nukm\n", "output": "YES\n" } ], "private_tests": [ { "input": "b\na\n", "output": "NO\n" }, { "input":...
[ 0.0000063745000000000116, 0.000005908499999999993, 0.000003877000000000004, 0.000003763000000000001, 0.0000037009999999999973, 0.000003614500000000004, 0.000003363999999999997, 0.000003223999999999995, 0.000002970999999999999, 0.000002925, 0.0000028620000000000007, 0.0000028190000000000013, ...
66_D. Petya and His Friends
2926
2926_54
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n. Let us remind you the definition of the greatest common divisor: GCD(a1, ..., ak) = d, where d represents such a maximal positive number that each ai (1 ≤ i ≤ k) is e...
isprime = [1 for i in range(2003)] isprime[0] = 0 isprime[1] = 0 for i in range(2,2000,1): if(isprime[i]): j = i*i while j < 2000: isprime[j] = 0 j += i prime = [] for i in range(2,2000,1): if(isprime[i]): prime.append(i) n = int(input()) if(n==2): 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
O(n**2)
0.000005
{ "public_tests": [ { "input": "4\n", "output": "105\n70\n42\n30\n" }, { "input": "3\n", "output": "15\n10\n6\n" } ], "private_tests": [ { "input": "8\n", "output": "4849845\n3233230\n1939938\n1385670\n881790\n746130\n570570\n510510\n" }, { "in...
[ 0.001293365689417577, 0.00006124391398156266, 0.00004569668877065429, 0.000018316812244063894, 0.000011536615877820648, 0.000011137964027409358, 0.000011078197362059836, 0.00001104670869139243, 0.000009171096143911455, 0.0000054809840852443685, 0.000005014394364326052, 0.000004998915679095223,...
66_D. Petya and His Friends
2926
2926_50
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n. Let us remind you the definition of the greatest common divisor: GCD(a1, ..., ak) = d, where d represents such a maximal positive number that each ai (1 ≤ i ≤ k) is e...
l=[2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157 ,163 ,167 ,173 ,179 ,181 ,191 ,193 ,197 ,199 ,211 ,223 ,227 ,229 ,233 ,239 ,241] n=int(input()) l1=[1 for i in range(n)] if n==2 : print("-1") exit() for ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4
O(n)
0.000007
{ "public_tests": [ { "input": "4\n", "output": "105\n70\n42\n30\n" }, { "input": "3\n", "output": "15\n10\n6\n" } ], "private_tests": [ { "input": "8\n", "output": "4849845\n3233230\n1939938\n1385670\n881790\n746130\n570570\n510510\n" }, { "in...
[ 0.000013394232931726937, 0.00001331011684604458, 0.000012188133003715034, 0.000010262322033898304, 0.000009690745762711866, 0.00000928019607736014, 0.000008505474576271184, 0.000008379220338983049, 0.000008307211267605634, 0.000008157677966101695, 0.000008112102008032133, 0.0000079159900977928...
355_A. Vasya and Digital Root
457
457_38
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + 9 + 8 = 21. Then the digital root of number n equals to: 1. dr(n) = S(n), if S(n) < 10; 2. dr(n) = dr( S(n) ), i...
l=input().split() k=int(l[0]) d=int(l[1]) if(k==1 and d==0): print(0) elif(k!=1 and d==0): print('No solution') else: i=1 n=d while len(str(n))!=k: n+=9**(i) i+=1 print(n)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 4
O(n**2)
0
{ "public_tests": [ { "input": "4 4\n", "output": "4000\n" }, { "input": "1 0\n", "output": "0\n" }, { "input": "5 1\n", "output": "10000\n" } ], "private_tests": [ { "input": "100 4\n", "output": "4000000000000000000000000000000000000000...
[ 0.00020214662526766596, 3.0928335581173764e-7, 8.410887156385313e-8, 1.060843264884511e-8, 4.5486955988297944e-10, 4.5411288510569484e-10, 4.538147842750213e-10, 3.0661886643849974e-10, 2.692729552205423e-10, 2.658293794545467e-10, 2.6485220059500766e-10, 2.648266886459007e-10, 2.64535758439...
355_A. Vasya and Digital Root
457
457_27
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + 9 + 8 = 21. Then the digital root of number n equals to: 1. dr(n) = S(n), if S(n) < 10; 2. dr(n) = dr( S(n) ), i...
k, d = map(int, input().split(' ')) if d == 0: if k == 1: print(0) else: print('No solution') else: print(d, end = '') for i in range(k - 1): print("0", end = '')
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 4
O(n)
0.000003
{ "public_tests": [ { "input": "4 4\n", "output": "4000\n" }, { "input": "1 0\n", "output": "0\n" }, { "input": "5 1\n", "output": "10000\n" } ], "private_tests": [ { "input": "100 4\n", "output": "4000000000000000000000000000000000000000...
[ 0.08948118550000002, 0.0312895855, 0.00007241968941215036, 0.000004670541796875001, 0.000004611848046875002, 0.00000450119807145979, 0.0000044795450447989515, 0.000004418502734375001, 0.0000044079363281249994, 0.000004391425166630245, 0.000003708785907451923, 0.000003589527972027973, 0.00000...
672_A. Summer Camp
1467
1467_233
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to...
n=int(input()) t='' for i in range(n+100): t+=str(i) print(t[n])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
11
O(n)
0.000008
{ "public_tests": [ { "input": "11\n", "output": "0\n" }, { "input": "3\n", "output": "3\n" } ], "private_tests": [ { "input": "942\n", "output": "0\n" }, { "input": "952\n", "output": "3\n" }, { "input": "191\n", "out...
[ 0.00005461242460664336, 0.000032687304031905595, 0.00002972072008850525, 0.000028530051969514866, 0.000026729570640297206, 0.00002524678982736014, 0.00002441879986614948, 0.000021692417436079547, 0.000018262822170017487, 0.000015093183880572553, 0.000013037554714816437, 0.000012032061421000873...
672_A. Summer Camp
1467
1467_532
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to...
n = int(input()) if n <= 9: print(n) elif n <= 189: num = (n - 10) / 2 + 10 mod = (n - 10) % 2 s = str(num) print(s[mod]) else: num = (n - 10 - 90 * 2) / 3 + 100 mod = (n - 10 - 90 * 2) % 3 s = str(num) print(s[mod])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
11
O(1)
0.000004
{ "public_tests": [ { "input": "11\n", "output": "0\n" }, { "input": "3\n", "output": "3\n" } ], "private_tests": [ { "input": "942\n", "output": "0\n" }, { "input": "952\n", "output": "3\n" }, { "input": "191\n", "out...
[ 0.0015439484999999892, 0.0012470875000000002, 0.0009917175, 0.0009735420000000002, 0.000897095, 0.0007822185000000001, 0.00013470300000000077, 0.0001335685000000003, 0.00013318, 0.00012812649999999898, 0.00012567149999999968, 0.00012521, 0.00011820999999999967, 0.00010685000000000035, 0....
385_B. Bear and Strings
1511
1511_9
The bear has a string s = s1s2... s|s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = sisi + 1... sj contains at least one string "bear" as a substring. String x(i, j) contains strin...
s=input() if len(s) < 4: print(0) else: a=0 for i in range(len(s)): d=s.find("bear", i) if d>=0: a+=len(s)-d-3 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, ...
bearaabearc
O(n**2)
0
{ "public_tests": [ { "input": "bearaabearc\n", "output": "20\n" }, { "input": "bearbtear\n", "output": "6\n" } ], "private_tests": [ { "input": "be\n", "output": "0\n" }, { "input": "bear\n", "output": "1\n" }, { "input": "...
[ 0.00004990831701116254, 0.00004671612324675571, 0.00004217574229180291, 0.000041984313116514274, 0.000011462927084499968, 7.550782987154286e-8, 5.3915988311372204e-8, 5.343402673123192e-8, 5.2016733514734166e-8, 5.1905104990395134e-8, 5.187531659707348e-8, 5.185815234809896e-8, 5.18403233094...
385_B. Bear and Strings
1511
1511_65
The bear has a string s = s1s2... s|s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = sisi + 1... sj contains at least one string "bear" as a substring. String x(i, j) contains strin...
def f(s): n = len(s) c = 0 ll = 0 for i in range(n-3): if s[i:i+4] == 'bear': l = i-ll+1 r = n-i-3 c += l*r ll = i+1 return c s = input() print(f(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, ...
bearaabearc
O(n)
0.000008
{ "public_tests": [ { "input": "bearaabearc\n", "output": "20\n" }, { "input": "bearbtear\n", "output": "6\n" } ], "private_tests": [ { "input": "be\n", "output": "0\n" }, { "input": "bear\n", "output": "1\n" }, { "input": "...
[ 0.00002829556188538025, 0.000020218329053758744, 0.000019534558948863637, 0.000019184057391826925, 0.000018975678062172203, 0.000018149479020979023, 0.000017765504165756117, 0.00001727223544034091, 0.000016978002458479024, 0.000016523565327250877, 0.000016049674292504372, 0.0000158741673677884...
59_B. Fortune Telling
384
384_34
Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces a...
f = int(input()) petals = list(map(int,input().split())) #print(f'suma: {sum(petals)}') while True: if sum(petals)%2 == 1: print(sum(petals)) break else: try: m = min(i for i in petals if i%2) except: m = min(petals) #print(f'removed: {m} ') ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 5 6 7
O(n**2)
0
{ "public_tests": [ { "input": "3\n5 6 7\n", "output": "13\n" }, { "input": "1\n2\n", "output": "0\n" }, { "input": "1\n1\n", "output": "1\n" } ], "private_tests": [ { "input": "99\n86 16 38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 ...
[ 0.0000017913326458697555, 1.3388056373050804e-7, 7.303697817125517e-8, 5.09150893456265e-8, 4.854985888271668e-8, 4.839174362901866e-8, 4.832112268825582e-8, 4.8105491842649096e-8, 2.565875501790101e-8, 8.406946605553238e-10 ]
59_B. Fortune Telling
384
384_38
Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces a...
n = int(input()) input_list = list(map(int,input().split())) input_list.sort() x = sum(input_list) if(x%2 ==1): print(x) else: for i in range(n): if(input_list[i]%2 == 1): print(x-input_list[i]) break else: print(0)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 5 6 7
O(nlogn)
0.000008
{ "public_tests": [ { "input": "3\n5 6 7\n", "output": "13\n" }, { "input": "1\n2\n", "output": "0\n" }, { "input": "1\n1\n", "output": "1\n" } ], "private_tests": [ { "input": "99\n86 16 38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 ...
[ 0.00001520912166261601, 0.000008155513423412999, 0.000008142514023535704, 0.00000810003151816682, 0.000008095844844697535, 0.000008028564363421932, 0.000008011515403498653, 0.00000800885409366976, 0.000008003078371779999, 0.000007970165801149543, 0.000007969356281688933, 0.00000796337092804232...
1077_A. Frog Jumping
2124
2124_138
A frog is currently at the point 0 on a coordinate axis Ox. It jumps by the following algorithm: the first jump is a units to the right, the second jump is b units to the left, the third jump is a units to the right, the fourth jump is b units to the left, and so on. Formally: * if the frog has jumped an even numb...
t = int(input()) all_data = [] for i in range(t): data = [int(i) for i in input().split(" ")] all_data.append(data) for i in all_data: right = i[0] left = i[1] k = i[2] jump = right-left if k % 2 == 0: print(jump*(k//2)) else: print(jump*(k//2)+right)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
6 5 2 3 100 1 4 1 10 5 1000000000 1 6 1 1 1000000000 1 1 999999999
O(n*m)
0.000008
{ "public_tests": [ { "input": "6\n5 2 3\n100 1 4\n1 10 5\n1000000000 1 6\n1 1 1000000000\n1 1 999999999\n", "output": "8 198 -17 2999999997 0 1 " } ], "private_tests": [ { "input": "1\n598 56 799\n", "output": "216856 " }, { "input": "1\n19280817 1 1\n", "o...
[ 0.000008922027234484265, 0.000008900514409418709, 0.000008776842971481644, 0.000008651750163898602, 0.000008582912382539337, 0.000008526953698645104, 0.000008486321937827797, 0.000008478439890187938, 0.000008476756132539336, 0.000008105737325174826, 0.000008027918760926575, 0.00000800533395705...
1077_A. Frog Jumping
2124
2124_2
A frog is currently at the point 0 on a coordinate axis Ox. It jumps by the following algorithm: the first jump is a units to the right, the second jump is b units to the left, the third jump is a units to the right, the fourth jump is b units to the left, and so on. Formally: * if the frog has jumped an even numb...
t = int(input()) answer = [] for i in range(t): a, b, k = map(int, input().split()) if k % 2 == 1: answer.append(k // 2 * (a - b) + a) else: answer.append(k // 2 * (a - b)) for i in range(t): print(answer[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, ...
6 5 2 3 100 1 4 1 10 5 1000000000 1 6 1 1 1000000000 1 1 999999999
O(n)
0
{ "public_tests": [ { "input": "6\n5 2 3\n100 1 4\n1 10 5\n1000000000 1 6\n1 1 1000000000\n1 1 999999999\n", "output": "8 198 -17 2999999997 0 1 " } ], "private_tests": [ { "input": "1\n598 56 799\n", "output": "216856 " }, { "input": "1\n19280817 1 1\n", "o...
[ 0.00003830336875819493, 0.0000365076166138549, 0.000035468556804523604, 0.000032987674948098775, 0.0000328464276524257, 0.00003200302298677885, 0.00003157443184549825, 0.000031022032397290216, 0.000030807179359702795, 0.000030767051272945815, 0.00003076236472902098, 0.000030369294471153845, ...
1005_C. Summarize to the Power of Two
788
788_22
A sequence a_1, a_2, ..., a_n is called good if, for each element a_i, there exists an element a_j (i ≠ j) such that a_i+a_j is a power of two (that is, 2^d for some non-negative integer d). For example, the following sequences are good: * [5, 3, 11] (for example, for a_1=5 we can choose a_2=3. Note that their sum ...
import math from collections import defaultdict getInputList = lambda : list(input().split()) getInputIntList = lambda : list(map(int,input().split())) n = input() arr = getInputIntList() myset = defaultdict(lambda:0) for i in arr: myset[i] += 1 nset = set([]) for i in arr: cb = '1'+'0'*(len(bin(i))-3) if bin(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, ...
6 4 7 1 5 4 9
O(n)
0.000025
{ "public_tests": [ { "input": "6\n4 7 1 5 4 9\n", "output": "1" }, { "input": "5\n1 2 3 4 5\n", "output": "2" }, { "input": "1\n16\n", "output": "1" }, { "input": "4\n1 1 1 1023\n", "output": "0" } ], "private_tests": [ { "...
[ 0.00042098721493675595, 0.0003223698324573864, 0.0003208134456912879, 0.00026730801307091345, 0.00021105373083752185, 0.000204734501256556, 0.00019786400203507433, 0.00019784120686735138, 0.00019700085630190123, 0.0001969007953043051, 0.00019634483718039772, 0.0001843096014532343, 0.00016931...
1005_C. Summarize to the Power of Two
788
788_76
A sequence a_1, a_2, ..., a_n is called good if, for each element a_i, there exists an element a_j (i ≠ j) such that a_i+a_j is a power of two (that is, 2^d for some non-negative integer d). For example, the following sequences are good: * [5, 3, 11] (for example, for a_1=5 we can choose a_2=3. Note that their sum ...
n = int(input()) l = [int(x) for x in input().split()] l.sort() if n == 0: print (0) elif n == 1: print(1) else: Dict = {} for x in l: try: Dict[x] += 1 except KeyError: Dict[x] = 1 cnt, book =0, {} for x in l: if book.__contains__(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, ...
6 4 7 1 5 4 9
O(nlogn)
0.000223
{ "public_tests": [ { "input": "6\n4 7 1 5 4 9\n", "output": "1" }, { "input": "5\n1 2 3 4 5\n", "output": "2" }, { "input": "1\n16\n", "output": "1" }, { "input": "4\n1 1 1 1023\n", "output": "0" } ], "private_tests": [ { "...
[ 0.0002791001180206512, 0.0002228666279911495, 0.00017412284331293708, 0.000163706905116368, 0.00016285273743444058, 0.00016173570800098337, 0.00015468106898765298, 0.00015032024127239948, 0.00013974234952742574, 0.00013827976272934317, 0.00013071396951486015, 0.0001300561871995192, 0.0001278...
854_A. Fraction
1739
1739_170
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction <image> is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive comm...
import math n=int(input()) if (n%2)!=0: a=1 while a < math.floor(n/2): a+=1 b=n-a print(f"{a} {b}") else: a=1 while a < math.floor(n/2)-1: a+=1 b=n-a if a%2==0 and b%2==0: a=a-1 b=b+1 print(f"{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, ...
12
O(n)
0.000004
{ "public_tests": [ { "input": "12\n", "output": "5 7\n" }, { "input": "4\n", "output": "1 3\n" }, { "input": "3\n", "output": "1 2\n" } ], "private_tests": [ { "input": "998\n", "output": "497 501\n" }, { "input": "69\n", ...
[ 0.000135399778477382, 0.00009673249871612763, 0.000038914397877513116, 0.00003868730989128059, 0.00002771124418159965, 0.00002478718388057255, 0.000012490585637019232, 0.000011969131596918707, 0.000010444073098776224, 0.000008501819629589162, 0.000008230891949847028, 0.000008073277480332169, ...
854_A. Fraction
1739
1739_447
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction <image> is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive comm...
n = int(input()) if n%4 == 0: x = n//2 print(x-1,x+1) elif n % 4 == 2: x = n//2 print(x-2,x+2) else: x = n//2 print(x,x+1)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
12
O(1)
0.000003
{ "public_tests": [ { "input": "12\n", "output": "5 7\n" }, { "input": "4\n", "output": "1 3\n" }, { "input": "3\n", "output": "1 2\n" } ], "private_tests": [ { "input": "998\n", "output": "497 501\n" }, { "input": "69\n", ...
[ 0.1697855145, 0.0026476820000000123, 0.002163698999999991, 0.0015998269999999981, 0.0007284969999999946, 0.000411545499999999, 0.0002083629999999996, 0.000024128500000000005, 0.000023999999999999997, 0.000014151999999999996, 0.000011502500000000007, 0.000011294499999999998, 0.000008497999999...
p04012 AtCoder Beginner Contest 044 - Beautiful Strings
2389
2389_139
Let w be a string consisting of lowercase letters. We will call w beautiful if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful. Constraints * 1 \leq |w| \leq 100 * w consists of lowercas...
s=input() ch=0 for i in s: if s.count(i)%2 ==1: ch=1 print("YNeos"[ch::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, ...
abaccaba
O(n**2)
0
{ "public_tests": [ { "input": "abaccaba", "output": "Yes" }, { "input": "hthth", "output": "No" } ], "private_tests": [], "generated_tests": [ { "input": "ab`ccaba", "output": "No\n" }, { "input": "ab`cc`ba", "output": "Yes\n" }, ...
[ 5.614901186803347e-7, 5.077652154749582e-7, 5.039715916293619e-7, 5.018778828625395e-7, 5.007632688571911e-7, 5.001823433693283e-7, 4.996661628841393e-7, 3.328163722988904e-7, 3.1904387393607225e-7, 3.18571080463486e-7, 5.494063678006962e-8, 5.488274539075067e-8, 5.4810744183893074e-8, 5.4...
p04012 AtCoder Beginner Contest 044 - Beautiful Strings
2389
2389_42
Let w be a string consisting of lowercase letters. We will call w beautiful if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful. Constraints * 1 \leq |w| \leq 100 * w consists of lowercas...
word = input() wset = set(word) a = 'Yes' for w in wset: if word.count(w) % 2 != 0: a = 'No' 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, ...
abaccaba
O(n)
0
{ "public_tests": [ { "input": "abaccaba", "output": "Yes" }, { "input": "hthth", "output": "No" } ], "private_tests": [], "generated_tests": [ { "input": "ab`ccaba", "output": "No\n" }, { "input": "ab`cc`ba", "output": "Yes\n" }, ...
[ 0.000003817432132320805, 0.000003612210773601399, 0.0000026692324218750003, 0.0000026179260817307696, 0.0000023130024448208043, 0.0000023045216072989516, 0.0000022848206539554197, 0.0000019040271115603147, 0.0000017085653409090913, 0.0000016947316570148606, 0.0000016760689739947552, 0.00000167...
637_A. Voting for Photos
2947
2947_115
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win...
n = int(input()) a = input().split() b = set(a) maximum = -1 maximum_id = [] for i in b: x = a.count(i) if x > maximum: maximum_id = [int(i)] maximum = x elif x == maximum: maximum_id.append(int(i)) a = a[::-1] maximum = -1 answer = -1 for i in maximum_id: x = a.index(str(i)) ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
9 100 200 300 200 100 300 300 100 200
O(n**2)
0.000001
{ "public_tests": [ { "input": "9\n100 200 300 200 100 300 300 100 200\n", "output": "300" }, { "input": "5\n1 3 2 2 1\n", "output": "2" } ], "private_tests": [ { "input": "5\n1 3 4 2 2\n", "output": "2" }, { "input": "2\n1000000 1000000\n", ...
[ 0.0007947736696428573, 0.00001571572311123947, 0.000011750221863138114, 0.000007127063384252483, 0.000006720812953169166, 0.000006468421751943238, 0.00000471271361129167, 0.0000023706317825521275, 0.000001477622764335902, 0.000001157631319616837, 0.000001132212024680701, 0.00000106267093150688...
637_A. Voting for Photos
2947
2947_125
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the win...
n = int(input()) a = [int(x) for x in input().split()] score = dict() sup, winner = -2**31, None for v in a: score[v] = score[v] + 1 if v in score else 1 if score[v] > sup: sup, winner = score[v], v print(winner)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
9 100 200 300 200 100 300 300 100 200
O(n)
0.000007
{ "public_tests": [ { "input": "9\n100 200 300 200 100 300 300 100 200\n", "output": "300" }, { "input": "5\n1 3 2 2 1\n", "output": "2" } ], "private_tests": [ { "input": "5\n1 3 4 2 2\n", "output": "2" }, { "input": "2\n1000000 1000000\n", ...
[ 0.000199083071507594, 0.00019250701175289558, 0.00001690318957604895, 0.000016392192403299827, 0.000016233928444602275, 0.000015900894135161714, 0.000014436330433238638, 0.000014299015611341782, 0.00001413978589379371, 0.000011895935642482518, 0.000011849366408981643, 0.000011523009314903847, ...
801_A. Vicious Keyboard
2589
2589_115
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximu...
s = input() import copy result = s.count('vk') for i in range(len(s)): news = copy.copy(s) news = list(news) news[i] = 'V' news = ''.join(news) result = max(result, news.count('VK')) for i in range(len(s)): news = copy.copy(s) news = list(news) news[i] = 'K' news = ''.join(news) ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
VK
O(n**2)
0
{ "public_tests": [ { "input": "VK\n", "output": "1\n" }, { "input": "V\n", "output": "0\n" }, { "input": "VKKKKKKKKKVVVVVVVVVK\n", "output": "3\n" }, { "input": "VV\n", "output": "1\n" }, { "input": "KVKV\n", "output": "1...
[ 0.0000040904458980574535, 0.0000035594987059869715, 0.0000031916082382711984, 0.000002967710923120174, 0.000002879189567002966, 0.000002757488278426726, 0.0000027329354788251844, 0.0000027211341367609022, 0.000002675700515283046, 0.0000023162578826524225, 0.000002235439547889272, 0.00000222255...
801_A. Vicious Keyboard
2589
2589_26
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximu...
s=input() n=len(s) v=0 k=0 count=0 flag=0 fl=0 for i in range(n): if(s[i]=='V' and not(i==len(s)-1)): if(s[i+1]=='K'): count+=1 v=0 k=0 fl=1 else: v+=1 k=0 elif(s[i]=='V' and (i==len(s)-1)): v+=1 elif(fl==0 and s[i]=='K'): k+=1 elif(fl==1 and s[i]=='K'): fl=0 if((v>=2 or k>=2) and flag=...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
VK
O(n)
0.000001
{ "public_tests": [ { "input": "VK\n", "output": "1\n" }, { "input": "V\n", "output": "0\n" }, { "input": "VKKKKKKKKKVVVVVVVVVK\n", "output": "3\n" }, { "input": "VV\n", "output": "1\n" }, { "input": "KVKV\n", "output": "1...
[ 0.000008230796383304196, 0.000006281219883631994, 0.000004688571596372378, 0.000004605323481206294, 0.000004074195080310315, 0.000003967948262674826, 0.000003841213450611888, 0.0000032895561216127625, 0.000003258680083588287, 0.0000031617172885708043, 0.000003110578589379371, 0.000003099147495...
1244_A. Pens and Pencils
89
89_463
Tomorrow is a difficult day for Polycarp: he has to attend a lectures and b practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them. While preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and d...
n=int(input()) for i in range(n): k=list(map(int,input().split())) if k[0]%k[2]==0: x=k[0]//k[2] else: x=k[0]//k[2]+1 if k[1]%k[3]==0: y=k[1]//k[3] else: y=k[1]//k[3]+1 if (x+y)<=k[-1]: print(x,y) 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, ...
3 7 5 4 5 8 7 5 4 5 2 20 53 45 26 4
O(n*m)
0.000006
{ "public_tests": [ { "input": "3\n7 5 4 5 8\n7 5 4 5 2\n20 53 45 26 4\n", "output": "2 1\n-1\n1 3\n" } ], "private_tests": [ { "input": "1\n53 36 13 3 18\n", "output": "5 12\n" }, { "input": "1\n7 2 3 2 3\n", "output": "-1\n" }, { "input": "1\...
[ 0.0000168249840472028, 0.000011146046451595281, 0.000009512607776988637, 0.000009406511063155595, 0.00000734816053868007, 0.000007281539294689685, 0.000007094404474431818, 0.000007073129438920455, 0.000007070566938920454, 0.0000070587090116914335, 0.000007048748538570804, 0.0000070434698426573...
1244_A. Pens and Pencils
89
89_909
Tomorrow is a difficult day for Polycarp: he has to attend a lectures and b practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them. While preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and d...
n = input() n = int(n) for i in range(0,n): l= input() a,b,c,d,k = l.split() a= int(a) b= int(b) c= int(c) d= int(d) k= int(k) if (a%c!=0): pens = int(a/c) + 1 else: pens = int(a/c) if (b%d!=0): pins = int(b/d) + 1 else: pins = int(b/d) 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, ...
3 7 5 4 5 8 7 5 4 5 2 20 53 45 26 4
O(n)
0
{ "public_tests": [ { "input": "3\n7 5 4 5 8\n7 5 4 5 2\n20 53 45 26 4\n", "output": "2 1\n-1\n1 3\n" } ], "private_tests": [ { "input": "1\n53 36 13 3 18\n", "output": "5 12\n" }, { "input": "1\n7 2 3 2 3\n", "output": "-1\n" }, { "input": "1\...
[ 0.00004668636582167832, 0.00003804604589160839, 0.000029755870219624126, 0.000028363438401442308, 0.000028315460459462415, 0.000027699792121940557, 0.000027593686257102273, 0.00002710782931326486, 0.000027004607708697554, 0.00002645534327196242, 0.00002615078096317745, 0.000025922792791193185,...
389_A. Fox and Number Game
281
281_12
Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible. ...
n = eval(input()) no = list(map(eval,input().split())) while True: flag = False for i in no: if i<=0: continue for j in range(n): if no[j]>i: flag = True if no[j]%i == 0: no[j] = i else: ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 12 18
O(n**2)
0.000002
{ "public_tests": [ { "input": "2\n12 18\n", "output": "12\n" }, { "input": "3\n2 4 6\n", "output": "6\n" }, { "input": "5\n45 12 27 30 18\n", "output": "15\n" }, { "input": "2\n1 2\n", "output": "2\n" } ], "private_tests": [ { ...
[ 0.1179829804901961, 0.07293572691525423, 0.005887398840827981, 0.0005058264853449274, 0.00018340719043128398, 0.00013278538965526659, 0.00012529324220753713, 0.0001036065125770628, 0.00009949010714422734, 0.00004768278458171855, 0.000028688297300930318, 0.000023614974846220218, 0.00002236948...
389_A. Fox and Number Game
281
281_250
Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible. ...
#CF389A n,q=int(input()),0 import math for i in map(int,input().split()):q=math.gcd(q,i) print(q*n)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 12 18
O(n)
0.000001
{ "public_tests": [ { "input": "2\n12 18\n", "output": "12\n" }, { "input": "3\n2 4 6\n", "output": "6\n" }, { "input": "5\n45 12 27 30 18\n", "output": "15\n" }, { "input": "2\n1 2\n", "output": "2\n" } ], "private_tests": [ { ...
[ 0.006205465297521436, 0.0033604827023087256, 0.0033226047618793997, 0.000014034247993461661, 0.000005040175890515734, 0.000004691218777316434, 0.0000033801655922202794, 0.0000029748482196558737, 0.0000029274661959134617, 0.0000028212505873033217, 0.0000025658237953452804, 0.0000025458584872159...
389_A. Fox and Number Game
281
281_138
Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible. ...
n = int(input()) x = list(sorted(map(int, input().split()))) def gcd(a, b): while b > 0: a, b = b, a % b return a tgcd = x.pop(0) for i in x: tgcd = gcd(tgcd, i) print(tgcd * n)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 12 18
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2\n12 18\n", "output": "12\n" }, { "input": "3\n2 4 6\n", "output": "6\n" }, { "input": "5\n45 12 27 30 18\n", "output": "15\n" }, { "input": "2\n1 2\n", "output": "2\n" } ], "private_tests": [ { ...
[ 0.01735905215662651, 0.005053002815859803, 0.0009984476880431912, 0.0005991707465938824, 0.00044273572682092347, 0.0004324593075674084, 0.0003206613475743007, 0.00006608553319762748, 0.000024282323738401276, 0.00001249371352076028, 0.000005606172847298158, 0.0000052494338430753725, 0.0000052...
1463_A. Dungeon
2870
2870_46
You are playing a new computer game in which you have to fight monsters. In a dungeon you are trying to clear, you met three monsters; the first of them has a health points, the second has b health points, and the third has c. To kill the monsters, you can use a cannon that, when fired, deals 1 damage to the selected ...
n = int(input()) for i in range(n): s = list(map(int, input().split())) d = sum(s) if min(s) >= d // 9 and d % 9 == 0: print('YES') else: print('NO')
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 2 4 1 1 1 10 1 7
O(n*m)
0.000004
{ "public_tests": [ { "input": "3\n3 2 4\n1 1 1\n10 1 7\n", "output": "\nYES\nNO\nNO\n" } ], "private_tests": [ { "input": "1\n5999999 2000000 2000000\n", "output": "YES\n" }, { "input": "1\n3 9 15\n", "output": "YES\n" }, { "input": "1\n17 7 3...
[ 0.00000917059217930507, 0.000007536472082604896, 0.000005699910292832168, 0.00000561816118061626, 0.000004164212262347028, 0.00000413606284145542, 0.000003995501215581293, 0.000003957420290646855, 0.0000039432826021634615, 0.000003942056026005245, 0.000003936199409965035, 0.0000039144330610795...
1463_A. Dungeon
2870
2870_71
You are playing a new computer game in which you have to fight monsters. In a dungeon you are trying to clear, you met three monsters; the first of them has a health points, the second has b health points, and the third has c. To kill the monsters, you can use a cannon that, when fired, deals 1 damage to the selected ...
T = int(input()) for i in range(0, T) : a, b, c = input().split() a = int(a) b = int(b) c = int(c) Sum = a + b + c if Sum % 9 == 0 and Sum / 9 <= min(a, min(b, c)) : print("YES") else : print("NO")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 3 2 4 1 1 1 10 1 7
O(n)
0
{ "public_tests": [ { "input": "3\n3 2 4\n1 1 1\n10 1 7\n", "output": "\nYES\nNO\nNO\n" } ], "private_tests": [ { "input": "1\n5999999 2000000 2000000\n", "output": "YES\n" }, { "input": "1\n3 9 15\n", "output": "YES\n" }, { "input": "1\n17 7 3...
[ 0.00005410254295509178, 0.00005111214069329109, 0.00005028434429632867, 0.00002110209373634178, 0.000020329396224868882, 0.00001866408728966346, 0.000018509689535074304, 0.00001796545401278409, 0.000016228266499125872, 0.000015890499508304198, 0.000014714541862434442, 0.000014470460896525349, ...
1409_C. Yet Another Array Restoration
794
794_215
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integers. * The array contains two elements x and y (these elements are known for you) such that x < y. * If you sort the arr...
t=int(input()) for _ in range(t): n,x,y=list(map(int,input().split())) d=y-x for i in range(1,n): if (y-x)%i==0: d=min(d,(y-x)//i) ans=[] p=x while p<=y and n>0: ans.append(p) p=p+d n=n-1 if p>y: break p=x-d while p>0 and 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 1 49 5 20 50 6 20 50 5 3 8 9 13 22
O(n**2)
0.00007
{ "public_tests": [ { "input": "5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22\n", "output": "1 49\n10 20 30 40 50\n20 26 32 38 44 50\n3 8 13 18 23\n1 4 7 10 13 16 19 22 25\n" } ], "private_tests": [ { "input": "1\n2 1 49\n", "output": "1 49\n" }, { "input": "5\n2 1 ...
[ 0.01603562418875502, 0.005918730397601087, 0.005608283555404583, 0.005469603826406785, 0.005456101903106405, 0.002342465642193868, 0.0021577715838389223, 0.0014788317608816395, 0.0012921348257182242, 0.0011524968673224188, 0.0010188505050577141, 0.0008777012702099923, 0.0008721445052275036, ...
1409_C. Yet Another Array Restoration
794
794_794
We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array: * The array consists of n distinct positive (greater than 0) integers. * The array contains two elements x and y (these elements are known for you) such that x < y. * If you sort the arr...
import sys input = sys.stdin.readline def solve(): n,x,y=map(int,input().split()) arr = [] for i in range(1,n): if (y-x)%i==0: step = (y-x)//i smol = x%step if smol == 0: smol+=step total = smol+step*(n-1) arr.append((max(t...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 2 1 49 5 20 50 6 20 50 5 3 8 9 13 22
O(n)
0
{ "public_tests": [ { "input": "5\n2 1 49\n5 20 50\n6 20 50\n5 3 8\n9 13 22\n", "output": "1 49\n10 20 30 40 50\n20 26 32 38 44 50\n3 8 13 18 23\n1 4 7 10 13 16 19 22 25\n" } ], "private_tests": [ { "input": "1\n2 1 49\n", "output": "1 49\n" }, { "input": "5\n2 1 ...
[ 0.170455257, 0.03636112401056338, 0.03578515431338029, 0.0352641094471831, 0.03294456975352113, 0.030788355320481933, 0.030626789284337354, 0.03018188032289157, 0.029316286676305224, 0.023068931339759038, 0.021832936878714862, 0.019926387678714862, 0.019633338429718875, 0.01824114895774647...
1206_B. Make Product Equal One
499
499_359
You are given n numbers a_1, a_2, ..., a_n. With a cost of one coin you can perform the following operation: Choose one of these numbers and add or subtract 1 from it. In particular, we can apply this operation to the same number several times. We want to make the product of all these numbers equal to 1, in other wo...
n = input() #the number of numbers a = list(map(int, input().split())) #the numbers answer = 0 #initial value of answer cnt_minus = 0 #the number of (-) cnt_0 = 0 #the number of 0 for i in a: if i<0: answer +=abs(i+1) cnt_minus += 1 if i==0: answer += 1 cnt_0 += 1 if i>0: ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 -5 -3 5 3 0
O(n)
0.000005
{ "public_tests": [ { "input": "5\n-5 -3 5 3 0\n", "output": "13\n" }, { "input": "4\n0 0 0 0\n", "output": "4\n" }, { "input": "2\n-1 1\n", "output": "2\n" } ], "private_tests": [ { "input": "4\n-3 -3 -3 1\n", "output": "8\n" }, ...
[ 0.00005568271984265734, 0.00002501033097162788, 0.00002417522949901661, 0.00002406283052125391, 0.0000194798771989729, 0.000018928425578939188, 0.000018769573604130248, 0.000018332092005790112, 0.000017939012886738862, 0.000016938159993553754, 0.000016663644167153493, 0.000016605136746774722, ...
1206_B. Make Product Equal One
499
499_82
You are given n numbers a_1, a_2, ..., a_n. With a cost of one coin you can perform the following operation: Choose one of these numbers and add or subtract 1 from it. In particular, we can apply this operation to the same number several times. We want to make the product of all these numbers equal to 1, in other wo...
n=int(input()) a=list(map(int,input().split())) a.sort() ans=0 for i in range(0,n-1,2): ans+=min(abs(-1-a[i+1])+abs(-1-a[i]),abs(1-a[i+1])+abs(1-a[i])) if (n%2==1): ans+=abs(1-a[n-1]) print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 -5 -3 5 3 0
O(nlogn)
0.000015
{ "public_tests": [ { "input": "5\n-5 -3 5 3 0\n", "output": "13\n" }, { "input": "4\n0 0 0 0\n", "output": "4\n" }, { "input": "2\n-1 1\n", "output": "2\n" } ], "private_tests": [ { "input": "4\n-3 -3 -3 1\n", "output": "8\n" }, ...
[ 0.00010135090525295018, 0.0000887126082277098, 0.0000219338501499149, 0.000016096503521352878, 0.000015682396686517232, 0.000015585682214626636, 0.000015334399705143206, 0.000015150478981000744, 0.000015062050846176627, 0.000015042935535516078, 0.00001503878998128809, 0.00001495932892926744, ...
1234_B1. Social Network (easy version)
64
64_609
The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0...
n, k = map(int, input().split()) a = [0] * k l = 0 curr = set() ids = map(int, input().split()) for id in ids: if id not in curr: curr.add(id) if a[-1] != 0: curr.remove(a[-1]) a[1:] = a[:-1] a[0] = id l = min(l + 1, k) print(l) print(' '.join(map(str, a[:l])...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
10 4 2 3 3 1 1 2 1 2 3 3
O(n**2)
0.000203
{ "public_tests": [ { "input": "10 4\n2 3 3 1 1 2 1 2 3 3\n", "output": "3\n1 3 2\n" }, { "input": "7 2\n1 2 3 2 1 3 2\n", "output": "2\n2 1\n" } ], "private_tests": [ { "input": "9 2\n1 2 3 4 5 6 7 8 9\n", "output": "2\n9 8\n" }, { "input": "1...
[ 0.014328514185270425, 0.007585508569236671, 0.0006862728677455358, 0.0006666375889508929, 0.0005551900766741072, 0.0005542527623883928, 0.0005503847690848214, 0.0005176527223214286, 0.0005146507978515624, 0.000510267113234747, 0.0005026594016927083, 0.00048804182477678575, 0.0004830265024646...
1234_B1. Social Network (easy version)
64
64_1063
The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0...
from collections import deque n,k=map(int,input().split()) inp=list(map(int,input().split())) listt=deque() dictt={} for i in inp: dictt[i]=False for i in inp: if len(listt)<k: if dictt[i]==False: listt.appendleft(i) # listt=[i]+listt dictt[i]=True if len(listt)==k: if dictt[i]==False: dictt[i]=True...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 4 2 3 3 1 1 2 1 2 3 3
O(n)
0.00002
{ "public_tests": [ { "input": "10 4\n2 3 3 1 1 2 1 2 3 3\n", "output": "3\n1 3 2\n" }, { "input": "7 2\n1 2 3 2 1 3 2\n", "output": "2\n2 1\n" } ], "private_tests": [ { "input": "9 2\n1 2 3 4 5 6 7 8 9\n", "output": "2\n9 8\n" }, { "input": "1...
[ 0.0007243651554687501, 0.0006961317604910715, 0.00055385118203125, 0.00041905563444010423, 0.00039431665686553036, 0.00038539066195549253, 0.000379830725189394, 0.0003795310606534091, 0.00035537239164299246, 0.00024971957495629376, 0.00024882656815450175, 0.0001882831703862544, 0.00018394752...
p03388 AtCoder Beginner Contest 093 - Worst Case
810
810_131
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The score of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are ...
q=int(input()) ab=[list(map(int,input().split())) for _ in range(q)] from math import floor for a,b in ab: if a==b: print(2*a-2) continue t=floor((a*b)**0.5) # t,t+1 組み合わせの積がa*bで抑えられているかどうか if t*t>=a*b: # t*tもだめ print(2*t-3) elif t*(t+1)>=a*b: # t*(t+1)はだめ print(2*t-2) else: # t*tもt*(t+1)もOK...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 4 10 5 3 3 4 11 8 9 22 40 8 36 314159265 358979323
O(n)
0.000052
{ "public_tests": [ { "input": "8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 40\n8 36\n314159265 358979323", "output": "1\n12\n4\n11\n14\n57\n31\n671644785" } ], "private_tests": [], "generated_tests": [ { "input": "8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 11\n8 36\n314159265 358979323", "output...
[ 0.0011782061211577921, 0.0009014552988281252, 0.0005862594899553571, 0.0005682540508928571, 0.0005572658297991072, 0.0004084002905040922, 0.00040450464536830353, 0.0002529581789362981, 0.00020636728616695805, 0.00019489211060423953, 0.0001407883618881119, 0.00010464171870902535, 0.0001020937...
p03388 AtCoder Beginner Contest 093 - Worst Case
810
810_98
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The score of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are ...
q=int(input()) def check(t,a,b): k=(2*a+t)//2 return k*(2*a+t-k)<a*b for i in range(q): a,b=sorted(map(int,input().split())) if a==b or a==b-1: print(2*a-2) continue l,r=1,b-a while l+1<r: t=(l+r)//2 if check(t,a,b): l=t else: r=t ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
8 1 4 10 5 3 3 4 11 8 9 22 40 8 36 314159265 358979323
O(nlogn)
0.000036
{ "public_tests": [ { "input": "8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 40\n8 36\n314159265 358979323", "output": "1\n12\n4\n11\n14\n57\n31\n671644785" } ], "private_tests": [], "generated_tests": [ { "input": "8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 11\n8 36\n314159265 358979323", "output...
[ 0.00003961522668780919, 0.0000388577300303875, 0.00003638892425811021, 0.00003487503946774816, 0.000033962324716073655, 0.00003314631835711302, 0.00003221407362813703, 0.000030051369223020865, 0.00002715577606593207, 0.000026867412408860577, 0.00002651501550900389, 0.00002512929636267223, 0....
1228_A. Distinct Digits
2892
2892_1216
You have two integers l and r. Find an integer x which satisfies the conditions below: * l ≤ x ≤ r. * All digits of x are different. If there are multiple answers, print any of them. Input The first line contains two integers l and r (1 ≤ l ≤ r ≤ 10^{5}). Output If an answer exists, print any of them. Oth...
x,y=map(int,input().split()) for i in range(x,y+1,1): l=[] temp=i while temp>0: r=temp%10 l.append(r) temp=temp//10 s=set(l) a=len(s) b=len(l) if a==b: print(i) break if a!=b: 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, ...
98766 100000
O(n**2)
0.000001
{ "public_tests": [ { "input": "98766 100000\n", "output": "-1\n" }, { "input": "121 130\n", "output": "123\n" } ], "private_tests": [ { "input": "10 10\n", "output": "10\n" }, { "input": "25139 86116\n", "output": "25139\n" }, { ...
[ 0.28153371648080355, 0.08240060547231771, 0.0002901423216293594, 0.00028852335424705454, 0.00018525731485599122, 0.00008774597097725012, 0.00008517787487794966, 0.00007998293841238543, 0.00006825021376021476, 0.000054108617104981804, 0.0000502996444804398, 0.00004557478520170906, 0.000033698...
1228_A. Distinct Digits
2892
2892_914
You have two integers l and r. Find an integer x which satisfies the conditions below: * l ≤ x ≤ r. * All digits of x are different. If there are multiple answers, print any of them. Input The first line contains two integers l and r (1 ≤ l ≤ r ≤ 10^{5}). Output If an answer exists, print any of them. Oth...
a,b=map(int,input().split()) r=[] flag=0 for i in range(a,b+1): tmp=i r=[int(d) for d in str(i)] s=set(r) if(len(r)==len(s)): flag=1 break if(flag): print(tmp) 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, ...
98766 100000
O(n)
0.000314
{ "public_tests": [ { "input": "98766 100000\n", "output": "-1\n" }, { "input": "121 130\n", "output": "123\n" } ], "private_tests": [ { "input": "10 10\n", "output": "10\n" }, { "input": "25139 86116\n", "output": "25139\n" }, { ...
[ 0.13323429362711867, 0.1166401346440678, 0.09349964377966102, 0.0912245191016949, 0.09073084877966102, 0.08879556216949154, 0.08760162903389832, 0.04707153867253521, 0.04507281891197183, 0.044764578415492966, 0.018314495474698798, 0.017075884726907634, 0.016462472387951812, 0.0163145002457...
1203_F1. Complete the Projects (easy version)
2128
2128_34
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is r units. Some very rich customers asked him to complete some projects for their companies. To complete ...
n,r=map(int,input().split()) a=[list(map(int,input().split())) for i in range(n)] pos = [] neg = [] ans=0 for x in a: if x[1]>0: pos.append(x) else: neg.append(x) pos.sort(key=lambda k: k[0]) flag=True for x in pos: if r>=x[0]: r+=x[1] ans+=1 neg.sort(key=lambda i: i[0]+i[1],reverse=True) arr=[0]*(r+1) for ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 5 4 -5 4 -2 1 3
O(n**2)
0.000013
{ "public_tests": [ { "input": "3 5\n4 -5\n4 -2\n1 3\n", "output": "YES\n" }, { "input": "3 4\n4 6\n10 -2\n8 -1\n", "output": "YES\n" }, { "input": "3 10\n10 0\n10 -10\n30 0\n", "output": "NO\n" }, { "input": "4 4\n5 2\n5 -3\n2 1\n4 -2\n", "o...
[ 0.00004202075598502877, 0.00004171169038960492, 0.00004122110951923216, 0.00002980257122760053, 0.00002009495832482309, 0.00001861174898929196, 0.000017324142400568187, 0.000017087720730441434, 0.00001641705325338724, 0.000014975321541739513, 0.000014076113663680072, 0.00001407418368935752, ...
1203_F1. Complete the Projects (easy version)
2128
2128_3
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is r units. Some very rich customers asked him to complete some projects for their companies. To complete ...
n,r=map(int,input().split()) a=[] b=[] for _ in range(n): c,d=map(int,input().split()) if d<0: b.append([c,d]) else: a.append([c,d]) a.sort(key = lambda x: x[0]) b.sort(key = lambda x: x[0]+x[1],reverse=True) z=1 for i in a: if i[0]>r: z=0 break r+=i[1] for i in b: ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 5 4 -5 4 -2 1 3
O(nlogn)
0.000009
{ "public_tests": [ { "input": "3 5\n4 -5\n4 -2\n1 3\n", "output": "YES\n" }, { "input": "3 4\n4 6\n10 -2\n8 -1\n", "output": "YES\n" }, { "input": "3 10\n10 0\n10 -10\n30 0\n", "output": "NO\n" }, { "input": "4 4\n5 2\n5 -3\n2 1\n4 -2\n", "o...
[ 0.000016452378960865155, 0.000016081911793472665, 0.000012458472339014852, 0.000011821088587194059, 0.000011779627608719408, 0.000010281622180165605, 0.000009108643328850952, 0.000009012137824793968, 0.000008983125575289564, 0.000008853370807720234, 0.000008766218773333691, 0.00000875819355710...
839_A. Arya and Bran
2019
2019_311
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her cand...
n, k = map(int, input().split()) a = list(map(int, input().split())) count = tank = 0 for i in range(n): tank+=a[i] if tank>=8: count+=1 tank-=8 k-=8 else: count+=1 k-=tank tank=0 if k<=0: break if k>0: print(-1) else: print(count)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
1 9 10
O(n**2)
0
{ "public_tests": [ { "input": "1 9\n10\n", "output": "-1\n" }, { "input": "2 3\n1 2\n", "output": "2\n" }, { "input": "3 17\n10 10 10\n", "output": "3\n" } ], "private_tests": [ { "input": "2 8\n7 8\n", "output": "2\n" }, { ...
[ 0.00023102449783158607, 3.4869590587517386e-9, 2.824642581072178e-9, 2.531986691990087e-9, 2.4766821871218948e-9, 2.4084315714185265e-9, 2.3484206865007754e-9, 2.242727804317754e-9, 2.0758047017032886e-9, 2.058143067253699e-9, 2.0251968875904915e-9, 2.0147262926148217e-9, 2.005198289702268e-...
839_A. Arya and Bran
2019
2019_392
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her cand...
_, k = map(int, input().split()) acc = 0 result = -1 for i, v in enumerate(map(int, input().split())): acc += v d = min(acc, 8) k -= d acc -= d if k <= 0: result = i + 1 break print(result)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
1 9 10
O(n+m)
0.000001
{ "public_tests": [ { "input": "1 9\n10\n", "output": "-1\n" }, { "input": "2 3\n1 2\n", "output": "2\n" }, { "input": "3 17\n10 10 10\n", "output": "3\n" } ], "private_tests": [ { "input": "2 8\n7 8\n", "output": "2\n" }, { ...
[ 0.000001555815914554196, 0.0000012830333806818181, 0.0000012761862980769233, 0.0000012497561598557692, 0.0000011538135653409092, 0.000001107770091236888, 0.000001101123634178322, 0.0000010957126038024477, 0.0000010810954163024477, 0.0000010806627239947554, 0.000001060504794034091, 0.0000010568...
758_B. Blown Garland
2072
2072_257
Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland. Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is workin...
s=input() d={} n=len(s) for i in range(n): if(s[i]!='!'): d[i%4]=s[i] l={'R':0,'B':0,'Y':0,'G':0} for i in range(n): if(s[i]=='!'): l[d[i%4]]+=1 print(*list(l.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, ...
!RGYB
O(n)
0.000002
{ "public_tests": [ { "input": "!RGYB\n", "output": "0 1 0 0\n" }, { "input": "!!!!YGRB\n", "output": "1 1 1 1\n" }, { "input": "RYBGRYBGR\n", "output": "0 0 0 0\n" }, { "input": "!GB!RG!Y!\n", "output": "2 1 1 0\n" } ], "private_test...
[ 0.00014269309932255249, 0.000010530306435751749, 0.000009468629343312937, 0.000009193000915100527, 0.000007983281796328672, 0.00000767025712958916, 0.0000072327907014860144, 0.00000681458046055507, 0.000006539746203015736, 0.000006258483309659091, 0.0000060302557774257, 0.000006024772686298076...
758_B. Blown Garland
2072
2072_40
Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland. Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is workin...
arr = input() n = len(arr) r, b, y, g = 0, 0, 0, 0 for i in range(4): if i >= n: break ltrs = sorted(arr[i::4]) let = ltrs[len(ltrs) - 1] a = ltrs.count('!') if let == 'R': r += a elif let == 'B': b += a elif let == 'Y': y += a elif let == 'G': g ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
!RGYB
O(nlogn)
0.000012
{ "public_tests": [ { "input": "!RGYB\n", "output": "0 1 0 0\n" }, { "input": "!!!!YGRB\n", "output": "1 1 1 1\n" }, { "input": "RYBGRYBGR\n", "output": "0 0 0 0\n" }, { "input": "!GB!RG!Y!\n", "output": "2 1 1 0\n" } ], "private_test...
[ 0.000011798656360561355, 8.026087269338059e-7, 5.695991190133869e-7, 2.129953563823989e-7, 1.7758687974233147e-7, 1.7627807195206996e-7, 1.7088755649253602e-7, 1.6919437756637566e-7, 1.632920901784676e-7, 1.6160115432691157e-7, 1.5834082526442378e-7, 1.5788755569472381e-7, 1.5715980275160728...
788_A. Functions again
2198
2198_50
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as...
n=int(input()) a=list(map(int,input().split())) dp=[[0,0] for i in range(n)] dp[0][1]=abs(a[1]-a[0]) maxi=abs(a[1]-a[0]) for i in range(1,n-1): dp[i][0]=max(0,dp[i-1][1]-abs(a[i]-a[i+1])) dp[i][1]=max(0,dp[i-1][0]+abs(a[i]-a[i+1])) maxi=max(maxi,dp[i][0],dp[i][1]) print(maxi)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 1 4 2 3 1
O(n)
0.000014
{ "public_tests": [ { "input": "5\n1 4 2 3 1\n", "output": "3\n" }, { "input": "4\n1 5 4 7\n", "output": "6\n" } ], "private_tests": [ { "input": "4\n1000000000 0 0 -1000000000\n", "output": "2000000000\n" }, { "input": "10\n1000000000 -1000000...
[ 0.00003175527084243882, 0.00002903797855659966, 0.000025631849254261366, 0.000022541455933856902, 0.000021896961650584625, 0.00002170917481151661, 0.000021030016639375635, 0.00002102641038996918, 0.00002008297486888112, 0.000019779101453234267, 0.000019573553395934834, 0.000018795791889815215,...
788_A. Functions again
2198
2198_52
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as...
n = int(input()) a = list(map(int, input().split())) b = [] for i in range(n - 1): b.append(abs(a[i] - a[i + 1])) c = [] s = 1 summ = 0 for i in range(n - 1): summ += s * b[i] s = -s c.append(summ) c.sort() if c[0] < 0: print(c[n - 2] - c[0]) else: print(c[n - 2])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 1 4 2 3 1
O(nlogn)
0.000016
{ "public_tests": [ { "input": "5\n1 4 2 3 1\n", "output": "3\n" }, { "input": "4\n1 5 4 7\n", "output": "6\n" } ], "private_tests": [ { "input": "4\n1000000000 0 0 -1000000000\n", "output": "2000000000\n" }, { "input": "10\n1000000000 -1000000...
[ 0.000016066367945243452, 0.00001573955347278111, 0.000004727532439371315, 0.000003151924854887149, 0.0000030248685290517987, 0.0000029075874591393588, 0.000002693118168129859, 0.000002546620133313186, 0.000002462292255541546, 0.0000022645636256309463, 0.000002181316534670727, 0.000002095006128...
1165_A. Remainder
1622
1622_305
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0...
def main(): n, x, y = map(int, input().split()) number = list(input()) count = 0 i = 0 while i < y: if number[-i - 1] != '0': count += 1 number[-i - 1] = '0' i += 1 i += 1 if number[-y - 1] == "0": number[-y -1] = "1" count += 1 whi...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
11 5 2 11010100101
O(n**2)
0
{ "public_tests": [ { "input": "11 5 2\n11010100101\n", "output": "1\n" }, { "input": "11 5 1\n11010100101\n", "output": "3\n" } ], "private_tests": [ { "input": "6 4 2\n100010\n", "output": "2\n" }, { "input": "4 2 1\n1000\n", "output": ...
[ 0.000005412732546675597, 0.000004881563398099522, 0.000004773474895702751, 0.0000033343985811227427, 0.000003017364633529099, 0.0000021818948969621836, 0.0000021467209353629383, 0.0000021273479574417977, 0.0000021211685582571365, 0.000002093626703561373, 0.0000020550323653229273, 0.00000198187...
1165_A. Remainder
1622
1622_48
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0...
n,x,y = map(int,input().split()) s = input() c=0 for i in range(n-x,n): if(i == n-y-1): #print(1) if(s[i]=='0'): c = c + 1 else: if(s[i]=='1'): c=c+1 print(c)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
11 5 2 11010100101
O(n)
0.000003
{ "public_tests": [ { "input": "11 5 2\n11010100101\n", "output": "1\n" }, { "input": "11 5 1\n11010100101\n", "output": "3\n" } ], "private_tests": [ { "input": "6 4 2\n100010\n", "output": "2\n" }, { "input": "4 2 1\n1000\n", "output": ...
[ 0.0015308895, 0.000007934249740493882, 0.00000780308229075612, 0.000007765079053758742, 0.00000714425680179196, 0.000006390867815777972, 0.000006139423759833917, 0.000006017987639313812, 0.000005881321937827798, 0.000005760520600818453, 0.000005672868582589286, 0.000005625530444165211, 0.000...
1395_A. Boboniu Likes to Color Balls
1235
1235_318
Boboniu gives you * r red balls, * g green balls, * b blue balls, * w white balls. He allows you to do the following operation as many times as you want: * Pick a red ball, a green ball, and a blue ball and then change their color to white. You should answer if it's possible to arrange all the b...
testcases = int(input()) for i in range(testcases): l = list(map(int , input().split())) odd = 0 for i in l: if(i%2 != 0): odd+=1 if(odd in (0,1,4)) or (odd == 3 and (0 not in (l[0],l[1],l[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 0 1 1 1 8 1 9 3 0 0 0 0 1000000000 1000000000 1000000000 1000000000
O(n*m)
0.00001
{ "public_tests": [ { "input": "4\n0 1 1 1\n8 1 9 3\n0 0 0 0\n1000000000 1000000000 1000000000 1000000000\n", "output": "No\nYes\nYes\nYes\n" } ], "private_tests": [ { "input": "1\n0 2 2 3\n", "output": "Yes\n" }, { "input": "1\n1 2 2 4\n", "output": "Yes\n"...
[ 0.0006636986277343752, 0.000025070392933238636, 0.000021192736068618888, 0.00002049588768848339, 0.000020261018616149476, 0.000020005109812062942, 0.000018860959995083043, 0.000017977288611778845, 0.000017505332782451924, 0.000017385378687718533, 0.000017367848530375875, 0.00001726263120083042...
1395_A. Boboniu Likes to Color Balls
1235
1235_283
Boboniu gives you * r red balls, * g green balls, * b blue balls, * w white balls. He allows you to do the following operation as many times as you want: * Pick a red ball, a green ball, and a blue ball and then change their color to white. You should answer if it's possible to arrange all the b...
def get_res(a, b, c, d): if a==0 or b==0 or c==0: l = [x%2 for x in [a,b,c,d]] odds = sum(l) if odds > 1: return 'No' else: return 'Yes' else: l = [x%2 for x in [a,b,c,d]] odds = sum(l) if odds == 2: return '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 0 1 1 1 8 1 9 3 0 0 0 0 1000000000 1000000000 1000000000 1000000000
O(n)
0
{ "public_tests": [ { "input": "4\n0 1 1 1\n8 1 9 3\n0 0 0 0\n1000000000 1000000000 1000000000 1000000000\n", "output": "No\nYes\nYes\nYes\n" } ], "private_tests": [ { "input": "1\n0 2 2 3\n", "output": "Yes\n" }, { "input": "1\n1 2 2 4\n", "output": "Yes\n"...
[ 0.0007218657578125, 0.00017244300654228588, 0.0001225729074792395, 0.00009718843144940996, 0.00007246786716126266, 0.00006939082566652098, 0.00006358277196241259, 0.00006135359366805071, 0.000053769176109047206, 0.000050109032383632, 0.00004990763977819056, 0.00004946596390133305, 0.00004750...
1216_D. Swords
1640
1640_35
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swo...
from math import gcd n = int(input()) A = list(map(int, input().split())) m = max(A) g = 0 for i in A: g = gcd(g, m - i) ans = 0 for i in A: ans += (m - i) // g print(ans, g)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 2 9
O(n)
0.000002
{ "public_tests": [ { "input": "2\n2 9\n", "output": "1 7\n" }, { "input": "3\n3 12 6\n", "output": "5 3\n" }, { "input": "7\n2 1000000000 4 6 8 4 2\n", "output": "2999999987 2\n" }, { "input": "6\n13 52 0 13 26 52\n", "output": "12 13\n" ...
[ 0.0001323990119645979, 0.000008875185055179197, 0.000007609237734921329, 0.000004790899052119757, 0.000004671482954545455, 0.000004630551150021854, 0.000004596934672749126, 0.000004353131774475525, 0.000004197689576048952, 0.0000041776518247377636, 0.000004031455132757867, 0.000003794820681271...
1216_D. Swords
1640
1640_36
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swo...
import math n = int(input()) lis = sorted(map(int,input().split()),reverse = True) gg = 0 aa=1 ans=0 for i in range(n): gg = math.gcd(lis[0]-lis[i],gg) for i in range(n): ans+=((lis[0]-lis[i])//gg) print(ans,gg)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 2 9
O(nlogn)
0.000005
{ "public_tests": [ { "input": "2\n2 9\n", "output": "1 7\n" }, { "input": "3\n3 12 6\n", "output": "5 3\n" }, { "input": "7\n2 1000000000 4 6 8 4 2\n", "output": "2999999987 2\n" }, { "input": "6\n13 52 0 13 26 52\n", "output": "12 13\n" ...
[ 0.008988559000000002, 0.00001107788864819684, 0.000009228081764016902, 0.000005980083332955206, 0.000005973797183844748, 0.00000592362263745208, 0.000005786210258666791, 0.000005763680753021163, 0.000005754568227126611, 0.000005737432857264568, 0.0000057177799468763195, 0.000005700582405258404...
451_A. Game With Sticks
536
536_1054
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown be...
r, c = map(int, input().split()) t = r*c i = 0 while t !=0: r = r-1 c=c-1 t = r*c i += 1 if i%2 == 0: print("Malvika") else: print("Akshat")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 3
O(n+m)
0.000001
{ "public_tests": [ { "input": "2 3\n", "output": "Malvika\n" }, { "input": "3 3\n", "output": "Akshat\n" }, { "input": "2 2\n", "output": "Malvika\n" } ], "private_tests": [ { "input": "1 1\n", "output": "Akshat\n" }, { "in...
[ 0.000003415991115329983, 0.000002100944376912151, 0.000002011160381610577, 0.0000017719681490384618, 0.000001765729505845717, 0.000001677730939958479, 0.000001650263057255245, 0.0000016422958916083917, 0.0000016310957714160837, 0.0000016029160429414338, 0.0000015756535866477276, 0.000001570420...
451_A. Game With Sticks
536
536_697
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown be...
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Apr 10 15:10:38 2017 @author: lawrenceylong """ answer = min(map(int,input().split())) print("Malvika") if answer%2 == 0 else print("Akshat")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 3
O(1)
0.000001
{ "public_tests": [ { "input": "2 3\n", "output": "Malvika\n" }, { "input": "3 3\n", "output": "Akshat\n" }, { "input": "2 2\n", "output": "Malvika\n" } ], "private_tests": [ { "input": "1 1\n", "output": "Akshat\n" }, { "in...
[ 0.000040746000000000006, 0.000014373, 0.000013698500000000004, 0.000013466500000000004, 0.000012344999999999998, 0.000011470999999999999, 0.000011185499999999996, 0.000008982500000000004, 0.000008462500000000002, 0.000007804000000000002, 0.000007391500000000005, 0.000005626500000000011, 0.00...
1084_B. Kvass and the Fair Nut
2514
2514_176
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But ...
import math n, s = map(int, input().split()) v = list(map(int, input().split())) least = min(v) if sum(v) < s: print(-1) else: for i in v: s -= (i-least) if s > 0: least -= ((s+n-1)/n) print(math.ceil(least))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 4 5 3 4
O(n)
0.000002
{ "public_tests": [ { "input": "3 4\n5 3 4\n", "output": "2\n" }, { "input": "3 3\n4 3 5\n", "output": "3\n" }, { "input": "3 7\n1 2 3\n", "output": "-1\n" } ], "private_tests": [ { "input": "5 1\n1 1 1 1 1000\n", "output": "1\n" }, ...
[ 0.000022541976111778848, 0.000021848815272618012, 0.00000694569505509527, 0.000004563813920454546, 0.000003595741654829546, 0.0000033531980851180074, 0.000002804727122486888, 0.0000027693771170236017, 0.0000027690040160642574, 0.0000027622278600305942, 0.0000027419629179414337, 0.0000027406738...
1084_B. Kvass and the Fair Nut
2514
2514_221
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But ...
n = list(map(int,input().split())) s = n[1] n = n[0] a = list(map(int,input().split())) a = sorted(a,reverse = True) k = min(a) su = 0 if s > sum(a): print(-1) else: for i in range(len(a)): if a[i] > k: su += (a[i]-k) a[i] = k if su >= s: break 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, ...
3 4 5 3 4
O(nlogn)
0.000008
{ "public_tests": [ { "input": "3 4\n5 3 4\n", "output": "2\n" }, { "input": "3 3\n4 3 5\n", "output": "3\n" }, { "input": "3 7\n1 2 3\n", "output": "-1\n" } ], "private_tests": [ { "input": "5 1\n1 1 1 1 1000\n", "output": "1\n" }, ...
[ 0.0000774053857217002, 0.00007253170533763112, 0.0000723943214638158, 0.0000722028276333042, 0.00007215051006030703, 0.00007209535904605265, 0.00007179106262335526, 0.0000716016687062937, 0.0000714504549616228, 0.00007062542721536277, 0.00007059535525021854, 0.00007059321018629809, 0.0000701...
960_A. Check the string
1368
1368_109
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gi...
s=input() step=0 flag=1 suma=0;sumb=0;sumc=0 for i in range(len(s)): if s[i]!='a': step=i break suma+=1 for i in range(step,len(s)): if s[i]!='b': step=i break sumb+=1 for i in range(step,len(s)): if s[i]!='c': flag=0 break sumc+=1 step=i if st...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
aabc
O(n)
0.000001
{ "public_tests": [ { "input": "aabc\n", "output": "YES\n" }, { "input": "aaabccc\n", "output": "YES\n" }, { "input": "bbacc\n", "output": "NO\n" } ], "private_tests": [ { "input": "aa\n", "output": "NO\n" }, { "input": "ccb...
[ 0.0000042586721071896855, 0.000003833692690122377, 0.000003486821978802448, 0.000003422754848666958, 0.0000033651509232954548, 0.000003359914595170455, 0.000003352141212303322, 0.000003287008085664336, 0.00000327413043597028, 0.00000323173713395979, 0.0000031337156086101395, 0.0000030293206949...
960_A. Check the string
1368
1368_67
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string. B now gi...
from collections import defaultdict s = list(input()) t = sorted(s) flag = True if s[0] != "a": flag = False if s != t: flag = False dic = defaultdict(int) for i in s: dic[i] += 1 if dic["a"] == 0 or dic["b"] == 0: flag = False if dic["a"] != dic["c"] and dic["b"] != dic["c"]: flag = False if fla...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
aabc
O(nlogn)
0.000011
{ "public_tests": [ { "input": "aabc\n", "output": "YES\n" }, { "input": "aaabccc\n", "output": "YES\n" }, { "input": "bbacc\n", "output": "NO\n" } ], "private_tests": [ { "input": "aa\n", "output": "NO\n" }, { "input": "ccb...
[ 0.000011478800127500992, 0.00001132159700748942, 0.000011314014805851288, 0.000011196662390491169, 0.000011175635796266095, 0.000011174640038338076, 0.00001113925858729683, 0.000011137247633427017, 0.000011136440286871882, 0.000011130085606748583, 0.000011123692116204894, 0.0000111103005309921...
p03523 CODE FESTIVAL 2017 Final - AKIBA
831
831_184
You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`? Constraints * 1 \leq |S| \leq 50 * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If it i...
S = list(input()) T = list("AKIHABARA") ans = "YES" i = 0 while i < len(S) and i < 9: if S[i] != T[i]: if T[i] == "A": S.insert(i,"A") i += 1 if S[-1] != "A": S += "A" if S == T: 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, ...
AKIBAHARA
O(n)
0
{ "public_tests": [ { "input": "AKIBAHARA", "output": "NO" }, { "input": "KIHBR", "output": "YES" }, { "input": "AAKIAHBAARA", "output": "NO" } ], "private_tests": [], "generated_tests": [ { "input": "AKIBAAARH", "output": "NO\n" },...
[ 0.00000536140268520542, 0.0000034470563128277976, 0.0000019225328753277977, 2.4077565013111886e-7, 1.1783619700611888e-7, 6.511386855332169e-8, 4.86566597465035e-8, 4.81149885270979e-8, 4.599830638111888e-8, 4.458059713723776e-8, 4.181501311188811e-8, 3.951454600087413e-8, 3.9187677556818184...
p03523 CODE FESTIVAL 2017 Final - AKIBA
831
831_74
You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`? Constraints * 1 \leq |S| \leq 50 * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If it i...
import re S = input() print('YES' if re.match(r'^A?KIHA?BA?RA?$', S) 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, ...
AKIBAHARA
O(1)
0.000001
{ "public_tests": [ { "input": "AKIBAHARA", "output": "NO" }, { "input": "KIHBR", "output": "YES" }, { "input": "AAKIAHBAARA", "output": "NO" } ], "private_tests": [], "generated_tests": [ { "input": "AKIBAAARH", "output": "NO\n" },...
[ 0.00004749400000000209, 0.000004439000000000016, 0.000004220999999999999, 0.000004126000000000021, 0.0000035594999999999987, 0.0000034875000000000035, 0.0000034690000000000035, 0.0000031969999999999967, 0.0000030315000000000132, 0.0000028384999999999966, 0.000002806, 0.0000027400000000000043, ...
1108_A. Two distinct points
936
936_203
You are given two segments [l_1; r_1] and [l_2; r_2] on the x-axis. It is guaranteed that l_1 < r_1 and l_2 < r_2. Segments may intersect, overlap or even coincide with each other. <image> The example of two segments on the x-axis. Your problem is to find two integers a and b such that l_1 ≤ a ≤ r_1, l_2 ≤ b ≤ r_2 an...
n=int(input()) for a in range(n): L=list(map(int,input().split())) if(L[0]==L[2]): print(L[0],L[2]+1) else: print(L[0],L[2])
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 1 2 1 2 2 6 3 4 2 4 1 3 1 2 1 3 1 4 5 8
O(n*m)
0.000009
{ "public_tests": [ { "input": "5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8\n", "output": "1 2\n2 3\n2 1\n1 3\n1 5\n" } ], "private_tests": [ { "input": "1\n233 233333 123 456\n", "output": "233 123\n" }, { "input": "1\n1 2 1 2\n", "output": "1 2\n" }...
[ 0.00003991838786604021, 0.000018944245561079544, 0.00001621760034691871, 0.00001619737827797203, 0.000015402578247923952, 0.000015121116490930947, 0.000014986678348994755, 0.000013924006583260488, 0.00001301203770645789, 0.000012855493280157343, 0.000012115085582386364, 0.00001187240832604895,...
1108_A. Two distinct points
936
936_772
You are given two segments [l_1; r_1] and [l_2; r_2] on the x-axis. It is guaranteed that l_1 < r_1 and l_2 < r_2. Segments may intersect, overlap or even coincide with each other. <image> The example of two segments on the x-axis. Your problem is to find two integers a and b such that l_1 ≤ a ≤ r_1, l_2 ≤ b ≤ r_2 an...
q = int(input()) for i in range(q): l1,r1,l2,r2 = input().split() l1=int(l1) l2=int(l2) r1=int(r1) r2=int(r2) if l1 != l2: print (l1,l2) elif l1 != r2: print (l1,r2) elif r1 != l2: print (r1,l2) elif r1 != r2: print (r1,r2)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 1 2 2 6 3 4 2 4 1 3 1 2 1 3 1 4 5 8
O(n)
0
{ "public_tests": [ { "input": "5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8\n", "output": "1 2\n2 3\n2 1\n1 3\n1 5\n" } ], "private_tests": [ { "input": "1\n233 233333 123 456\n", "output": "233 123\n" }, { "input": "1\n1 2 1 2\n", "output": "1 2\n" }...
[ 0.00009621396316378935, 0.00005507445337084791, 0.00004401473952414773, 0.00004340862628387239, 0.000043310042039991256, 0.00004198766694438375, 0.0000398828375628278, 0.00003925370531031469, 0.00003853621566324301, 0.00003683681194001311, 0.000036066969337303326, 0.00003597209965034966, 0.0...
124_A. The number of positions
1089
1089_96
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy. Input The only line contains three integers n, a and ...
n, a, b = list(map(int, input().split())) ans = 0 for i in range(n): if i >= a and n - i - 1 <= b: ans += 1 print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 1 1
O(n)
0.000002
{ "public_tests": [ { "input": "3 1 1\n", "output": "2" }, { "input": "5 2 3\n", "output": "3" } ], "private_tests": [ { "input": "23 8 14\n", "output": "15" }, { "input": "59 12 39\n", "output": "40" }, { "input": "56 43 12...
[ 0.000003816699710445805, 0.0000037479721508959795, 0.000003246758672967658, 0.000002987072579763986, 0.000002473995533763112, 0.0000021166096071896854, 0.000001919611328125, 0.0000018439077387456297, 0.0000017308447880244755, 0.0000017277443045236014, 0.0000017253610413024476, 0.00000172390041...
124_A. The number of positions
1089
1089_174
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy. Input The only line contains three integers n, a and ...
# Believe you can and you're halfway there. Theodore Roosevelt # by : Blue Edge - Create some chaos n,a,b=map(int,input().split()) print(min(n-a,b+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
O(1)
0.000002
{ "public_tests": [ { "input": "3 1 1\n", "output": "2" }, { "input": "5 2 3\n", "output": "3" } ], "private_tests": [ { "input": "23 8 14\n", "output": "15" }, { "input": "59 12 39\n", "output": "40" }, { "input": "56 43 12...
[ 0.000042740499999999995, 0.000016290000000000005, 0.000005197500000000006, 0.000005163999999999993, 0.000005007499999999999, 0.000004994999999999999, 0.000004494499999999996, 0.000004416000000000003, 0.000004217999999999999, 0.0000039095000000000004, 0.000003870000000000002, 0.0000034879999999...
1032_A. Kitchen Utensils
138
138_449
The king's birthday dinner was attended by k guests. The dinner was quite a success: every person has eaten several dishes (though the number of dishes was the same for every person) and every dish was served alongside with a new set of kitchen utensils. All types of utensils in the kingdom are numbered from 1 to 100....
from math import ceil n, m = [int(s) for s in input().split()] a = [int(s) for s in input().split()] # c, d = np.unique(a), np.unique(a, return_counts=True)[1] c = [] cnt = 0 for o in a: if o not in c: c.append(o) d = [] for i in c: d.append(a.count(i)) dishes, set = ceil(max(d) / m), len(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, ...
10 3 1 3 3 1 3 5 5 5 5 100
O(n**2)
0.000001
{ "public_tests": [ { "input": "10 3\n1 3 3 1 3 5 5 5 5 100\n", "output": "14\n" }, { "input": "5 2\n1 2 2 1 3\n", "output": "1\n" } ], "private_tests": [ { "input": "100 1\n17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 ...
[ 0.01995447963052209, 0.0028771200787791776, 0.000991882774609375, 0.0007222879493077479, 0.000367292093847575, 0.0003562988213238405, 0.000018891328932697163, 0.000018725946716180254, 0.000003207116081855593, 0.0000027888149746559315, 0.0000024844946804395574, 0.0000018180722600990963, 0.000...
1032_A. Kitchen Utensils
138
138_360
The king's birthday dinner was attended by k guests. The dinner was quite a success: every person has eaten several dishes (though the number of dishes was the same for every person) and every dish was served alongside with a new set of kitchen utensils. All types of utensils in the kingdom are numbered from 1 to 100....
n, k = map(int, input().split()) arr = list(map(int, input().split())) curMax = 0 maps = {} for a in arr: if a not in maps: maps[a] = 1 else: maps[a] += 1 curMax = max(curMax, maps[a]) if curMax % k != 0: curMax = curMax - (curMax % k) + k print (curMax * len(maps) - len(arr))
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
10 3 1 3 3 1 3 5 5 5 5 100
O(n)
0.000008
{ "public_tests": [ { "input": "10 3\n1 3 3 1 3 5 5 5 5 100\n", "output": "14\n" }, { "input": "5 2\n1 2 2 1 3\n", "output": "1\n" } ], "private_tests": [ { "input": "100 1\n17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 ...
[ 0.0015031263551824664, 0.00042275514150855653, 0.0004178706027250744, 0.00009242334712357955, 0.000052225318925203394, 0.000026274004575502625, 0.000023958069916411717, 0.000021795300030048075, 0.000021734786617679196, 0.00002172667098721591, 0.000018209861532998253, 0.000017941932130225704, ...
p02922 AtCoder Beginner Contest 139 - Power Socket
2482
2482_13
Takahashi's house has only one socket. Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets. One power strip with A sockets can extend one empty socket into A empty sockets. Find the minimum number of power strips required. Constraints * All values in inp...
a,b=map(int,input().split()) n=0 while n*(a-1)+1<b:n+=1 print(n)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 10
O(n)
0.000002
{ "public_tests": [ { "input": "4 10", "output": "3" }, { "input": "8 8", "output": "1" }, { "input": "8 9", "output": "2" } ], "private_tests": [], "generated_tests": [ { "input": "2 10", "output": "9\n" }, { "input": "8 ...
[ 0.0000024469338395979026, 0.000002310352641499126, 0.0000022851835118006996, 0.000002273528190559441, 0.000002273300111997378, 0.0000022693736341783217, 0.0000022593306927447555, 0.000002244768834680944, 0.000002229860085227273, 0.000002228831662478147, 0.000001742386527534965, 0.0000017415048...
p02922 AtCoder Beginner Contest 139 - Power Socket
2482
2482_151
Takahashi's house has only one socket. Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets. One power strip with A sockets can extend one empty socket into A empty sockets. Find the minimum number of power strips required. Constraints * All values in inp...
A,B=map(int,input().split()) AA=A-1 BB=B-1 print((BB+AA-1)//AA)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 10
O(1)
0.000002
{ "public_tests": [ { "input": "4 10", "output": "3" }, { "input": "8 8", "output": "1" }, { "input": "8 9", "output": "2" } ], "private_tests": [], "generated_tests": [ { "input": "2 10", "output": "9\n" }, { "input": "8 ...
[ 0.000013577000000000002, 0.000002983500000000003, 0.0000026544999999999997, 0.000002573500000000005, 0.0000025229999999999994, 0.000002433000000000002, 0.000002419000000000005, 0.000002414500000000002, 0.0000023550000000000003, 0.000002345000000000002, 0.000002330500000000004, 0.00000229099999...
281_B. Nearest Fraction
696
696_51
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n. Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible. If there are multiple "nearest" fractions, choose...
from math import inf,floor,ceil x,y,n=map(float,input().split()) m=inf ans="" for b in range(1,int(n+1)): a=floor((x*b)/y) z=abs(x/y-a/b) if z<m-1e-15: m=z ans=str(a)+'/'+str(b) a=ceil((x*b)/y) z=abs(x/y-a/b) if z<m-1e-15: m=z ans=str(a)+'/'+str(b) print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
7 2 4
O(n)
0.000008
{ "public_tests": [ { "input": "7 2 4\n", "output": "7/2\n" }, { "input": "3 7 6\n", "output": "2/5\n" } ], "private_tests": [ { "input": "6243 60593 42244\n", "output": "3565/34601\n" }, { "input": "7487 17563 1102\n", "output": "107/251...
[ 0.00003184017126038025, 0.000016905265105987765, 0.000012010400158435315, 0.00000845593670782343, 0.000008057839734484265, 0.000008041559303977274, 0.000008000962453562063, 0.000007630945148601398, 0.000006364467725633742 ]
281_B. Nearest Fraction
696
696_49
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n. Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible. If there are multiple "nearest" fractions, choose...
from fractions import Fraction x,y,n = map(int, input().split(" ")) f=Fraction(x,y).limit_denominator(n) a=f.numerator b=f.denominator print(str(a)+"/"+str(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, ...
7 2 4
O(1)
0.000041
{ "public_tests": [ { "input": "7 2 4\n", "output": "7/2\n" }, { "input": "3 7 6\n", "output": "2/5\n" } ], "private_tests": [ { "input": "6243 60593 42244\n", "output": "3565/34601\n" }, { "input": "7487 17563 1102\n", "output": "107/251...
[ 0.00007286800000000001, 0.000051188, 0.00004813650000000001, 0.00004482100000000001, 0.000044666500000000003, 0.000044561999999999984, 0.000043388500000000006, 0.000043340499999999996, 0.00004237, 0.00004236150000000002, 0.0000421745, 0.00004184900000000001, 0.00004158599999999999, 0.00004...
282_B. Painting Eggs
1673
1673_122
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. h...
eggs=int(input()) diff=0 c=['A' for i in range(eggs)] for i in range(eggs): a=int(input().split()[0]) if a+diff<501: diff+=a else: c[i]='G' diff-=1000-a print(''.join(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, ...
2 1 999 999 1
O(n*m)
0.000001
{ "public_tests": [ { "input": "2\n1 999\n999 1\n", "output": "AG\n" }, { "input": "3\n400 600\n400 600\n400 600\n", "output": "AGA\n" } ], "private_tests": [ { "input": "1\n500 500\n", "output": "A\n" }, { "input": "2\n500 500\n500 500\n", ...
[ 0.0000016806470989947555, 0.000001609263931381119, 8.507869454763986e-7, 8.44927297312063e-7, 8.417066761363637e-7, 8.381770787805944e-7, 8.356788953234266e-7, 8.340022945804196e-7, 8.327397563374127e-7, 8.299883631993007e-7, 8.280243116258742e-7, 8.276574519230769e-7, 8.251342739291959e-7, ...
282_B. Painting Eggs
1673
1673_129
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. h...
sa,sg=0,0 ans='' for _ in range(int(input())): a,g=map(int,input().split()) if sa-sg+a<=500: ans+='A' sa+=a else: ans+='G' sg+=g print(ans)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 1 999 999 1
O(n)
0.000007
{ "public_tests": [ { "input": "2\n1 999\n999 1\n", "output": "AG\n" }, { "input": "3\n400 600\n400 600\n400 600\n", "output": "AGA\n" } ], "private_tests": [ { "input": "1\n500 500\n", "output": "A\n" }, { "input": "2\n500 500\n500 500\n", ...
[ 0.000014583971140187938, 0.000011659397454108392, 0.000009477005176464162, 0.000008844975497159091, 0.000008766696732954546, 0.000008641653368116259, 0.000008162573153409091, 0.00000808054377458479, 0.000008052363185642483, 0.000007986036467438813, 0.000007923445722246504, 0.000007922908462631...
1047_B. Cover Points
716
716_514
There are n points on the plane, (x_1,y_1), (x_2,y_2), …, (x_n,y_n). You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle. I...
d = int(input()) verts = [] for i in range(d): d = [int(x) for x in input().split(' ')] verts.append(d) maxx = 0 for v in verts: maxx = max(maxx, v[0] + v[1]) print(maxx)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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 1 2 2 1
O(n*m)
0.000003
{ "public_tests": [ { "input": "3\n1 1\n1 2\n2 1\n", "output": "3\n" }, { "input": "4\n1 1\n1 2\n2 1\n2 2\n", "output": "4\n" } ], "private_tests": [ { "input": "2\n1 8\n5 5\n", "output": "10\n" }, { "input": "5\n7 7\n5 8\n8 5\n4 9\n9 4\n", ...
[ 0.0000082539859375, 0.000007416256665209791, 0.000004012696336866258, 0.000003574424429086539, 0.0000035386160265515732, 0.000003285679947006119, 0.0000032707669771634617, 0.0000032575340635926577, 0.0000029913550316870635, 0.0000029596805069930072, 0.0000029560331348339165, 0.0000029492379534...
1047_B. Cover Points
716
716_174
There are n points on the plane, (x_1,y_1), (x_2,y_2), …, (x_n,y_n). You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle. I...
n=int(input()) c=0 for i in range(n): x,y=map(int,input().split()) c=max(c,x+y) print(c)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
3 1 1 1 2 2 1
O(n)
0
{ "public_tests": [ { "input": "3\n1 1\n1 2\n2 1\n", "output": "3\n" }, { "input": "4\n1 1\n1 2\n2 1\n2 2\n", "output": "4\n" } ], "private_tests": [ { "input": "2\n1 8\n5 5\n", "output": "10\n" }, { "input": "5\n7 7\n5 8\n8 5\n4 9\n9 4\n", ...
[ 0.000014136540797093535, 0.000012927443168159966, 0.000012918090936407341, 0.000011796273232626749, 0.00001176535572825612, 0.000011018756214488637, 0.000010865736737871505, 0.00001082930255681818, 0.000010824124194165211, 0.000010798165032233392, 0.000010793193482298954, 0.0000107906376065340...
1328_B. K-th Beautiful String
2819
2819_55
For the given integer n (n > 2) let's write down all the strings of length n which contain n-2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order. Recall that the string s of length n is lexicographically less than string t of length n, if there exists such i (1 ≤ i ≤ n), that s_i < t_i, and for a...
import sys input = sys.stdin.readline for _ in range(int(input())): n, k = map(int, input().split()) ans = ['a']*n for i, right in zip(range(n-2, -1, -1), range(1, n+1)): if k > right: k -= right continue j = n while k: k -= 1 j -= 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 5 1 5 2 5 8 5 10 3 1 3 2 20 100
O(n**2)
0.000002
{ "public_tests": [ { "input": "7\n5 1\n5 2\n5 8\n5 10\n3 1\n3 2\n20 100\n", "output": "aaabb\naabab\nbaaba\nbbaaa\nabb\nbab\naaaaabaaaaabaaaaaaaa\n" } ], "private_tests": [ { "input": "7\n8 18\n19 11\n20 5\n15 19\n19 15\n20 6\n10 28\n", "output": "abaaabaa\naaaaaaaaaaaaabaaaab...
[ 0.00001099030571186626, 0.000008468479007320805, 0.000008356796315013112, 0.000007672796875, 0.000007626847929414332, 0.00000739425700666521, 0.000006974253933566435, 0.000006861594801682692, 0.000006819178294361889, 0.000006756652330091784, 0.000006740576417722903, 0.0000067317741477272735, ...
1328_B. K-th Beautiful String
2819
2819_926
For the given integer n (n > 2) let's write down all the strings of length n which contain n-2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order. Recall that the string s of length n is lexicographically less than string t of length n, if there exists such i (1 ≤ i ≤ n), that s_i < t_i, and for a...
# Anuneet Anand import math T = int(input()) while T: n,k = map(int,input().split()) x = int(((1) + math.sqrt(1 + (8 * (k-1)))) / 2) d = int(math.floor((-1 + math.sqrt(1+ 8 * k - 8)) / 2)) b = (d * (d + 1)) / 2 + 1 y = int(k - b) A = ['a' for i in range(n)] A[n-x-1]='b' A[n-y-1]='b' R = "a"*(n-x-1)+"b"+"a"...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
7 5 1 5 2 5 8 5 10 3 1 3 2 20 100
O(n)
0.000001
{ "public_tests": [ { "input": "7\n5 1\n5 2\n5 8\n5 10\n3 1\n3 2\n20 100\n", "output": "aaabb\naabab\nbaaba\nbbaaa\nabb\nbab\naaaaabaaaaabaaaaaaaa\n" } ], "private_tests": [ { "input": "7\n8 18\n19 11\n20 5\n15 19\n19 15\n20 6\n10 28\n", "output": "abaaabaa\naaaaaaaaaaaaabaaaab...
[ 0.0005593527772321428, 0.0002270354700338724, 0.000214376015939139, 0.00012123501435478585, 0.00010487868506883741, 0.00009678039393028846, 0.00009518561176518794, 0.00008457459447388549, 0.0000781496566597465, 0.00007771627834079984, 0.00007332948395159527, 0.00007304311203835228, 0.0000719...
560_A. Currency System in Geraldion
1437
1437_284
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
n=int(input()) a=map(int,input().split()) ok=False for i in a: if i==1: ok=True if ok: print(-1) 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, ...
5 1 2 3 4 5
O(n)
0.000002
{ "public_tests": [ { "input": "5\n1 2 3 4 5\n", "output": "-1\n" } ], "private_tests": [ { "input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\n", "output": "1\n" }, { "input": "1\n1\n", "output": "-1\n" }, { "i...
[ 0.000004981458670236015, 0.0000032187610358391613, 0.000002974357995520105, 0.000002944395514641609, 0.000002896334339488637, 0.0000028427782042176577, 0.000002677352450284091, 0.0000026655411522071677, 0.000002630707481971154, 0.0000024377764423076924, 0.0000023811240439248253, 0.000002373746...
560_A. Currency System in Geraldion
1437
1437_223
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea...
def meuIn(num, valores): for i in valores: if(i == num): return True if(i > num): return False return False def verificaValores(valores): if(not meuIn(1, valores)): return 1 return -1 num = int(input()) entrada = input().split() valores = [int(valor) ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, 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(nlogn)
0.000014
{ "public_tests": [ { "input": "5\n1 2 3 4 5\n", "output": "-1\n" } ], "private_tests": [ { "input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264\n", "output": "1\n" }, { "input": "1\n1\n", "output": "-1\n" }, { "i...
[ 0.000034398728952687944, 0.000014802896195681781, 0.000014696244570850666, 0.000014617025298639147, 0.000014603081590401765, 0.000014476595526673648, 0.000014415252825242804, 0.000014397324067835963, 0.000014394843836650094, 0.000014382712875453896, 0.000014371298479995543, 0.00001436340164904...
1296_E1. String Coloring (easy version)
2394
2394_125
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string s consisting of n lowercase Latin letters. You have to color all its characters one of the two ...
#code n = int(input()) s = input() fl = True dp = [1]*n for i in range(1,n): for j in range(i): if s[j] > s[i]: dp[i] = max(dp[i],1+dp[j]) for i in dp: if i>=3: fl = False break if not fl: print("NO") else: ans = "0" mx = s[0] for i in range(1,n): if s...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
7 abcdedc
O(n**2)
0.000008
{ "public_tests": [ { "input": "7\nabcdedc\n", "output": "NO\n" }, { "input": "9\nabacbecfd\n", "output": "YES\n001010101\n" }, { "input": "5\nabcde\n", "output": "YES\n00000\n" }, { "input": "8\naaabbcbb\n", "output": "YES\n00000011\n" }...
[ 0.00035229149245937956, 0.00016587689930109295, 0.00011673508779715626, 0.0001096935370852158, 0.00010398907849477841, 0.0000297360503742373, 0.000016549992517653697, 0.00001652639197120855, 0.00001528571059685668, 0.000014167848221985236, 0.000013585260840585477, 0.00001261272114562523, 0.0...
1296_E1. String Coloring (easy version)
2394
2394_227
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string s consisting of n lowercase Latin letters. You have to color all its characters one of the two ...
def main(): n = int(input().strip()) s = input().strip() result = [] a, b = "", "" for c in s: if c >= a: a = c result.append("1") elif c >= b: b = c result.append("0") else: print("NO") return 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, ...
7 abcdedc
O(n)
0.000002
{ "public_tests": [ { "input": "7\nabcdedc\n", "output": "NO\n" }, { "input": "9\nabacbecfd\n", "output": "YES\n001010101\n" }, { "input": "5\nabcde\n", "output": "YES\n00000\n" }, { "input": "8\naaabbcbb\n", "output": "YES\n00000011\n" }...
[ 0.0016285074529064228, 0.00015253575731318114, 0.00010227383372486889, 0.00010173068192744755, 0.00009571162973940123, 0.00009059979974322553, 0.00008157819371448865, 0.00008082627300720311, 0.00007970037660472707, 0.00007797776694801851, 0.00007568099493509146, 0.00007127193633467534, 0.000...
1296_E1. String Coloring (easy version)
2394
2394_182
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string s consisting of n lowercase Latin letters. You have to color all its characters one of the two ...
def main(): n = int(input()) s = input() fst_lst = [s[0]] snd_lst = [] ans = '1' for i in range(1, len(s)): if fst_lst[-1]<=s[i]: fst_lst.append(s[i]) ans+='1' else: snd_lst.append(s[i]) ans+='0' # print (*fst_lst) # 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, ...
7 abcdedc
O(nlogn)
0.000018
{ "public_tests": [ { "input": "7\nabcdedc\n", "output": "NO\n" }, { "input": "9\nabacbecfd\n", "output": "YES\n001010101\n" }, { "input": "5\nabcde\n", "output": "YES\n00000\n" }, { "input": "8\naaabbcbb\n", "output": "YES\n00000011\n" }...
[ 0.0007836907807363811, 0.0003550206976940277, 0.0003436760975714339, 0.00005275023995685175, 0.00005145125181914681, 0.000047745664634489823, 0.00004125522312268763, 0.0000196444428092668, 0.00001855532320904854, 0.000017937685398360566, 0.000017355880692585135, 0.000017303819039148515, 0.00...
638_A. Home Numbers
540
540_80
The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n - 1 in the order from the beginning of the street to the end (in the picture: from ...
n, a = map(int,input().split()) k = a % 2 i = 1 if k == 0: na=n while na!=a: na = na-2 i +=1 else: na = 1 while a!=na: na += 2 i+=1 print(i)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 2
O(n)
0.000001
{ "public_tests": [ { "input": "4 2\n", "output": "2" }, { "input": "8 5\n", "output": "3" } ], "private_tests": [ { "input": "5026 4697\n", "output": "2349" }, { "input": "1628 274\n", "output": "678" }, { "input": "34614 2...
[ 0.000002661234197443182, 0.0000025124789253715038, 0.000001623288311298077, 0.0000014069130791083918, 0.0000013668577223557692, 0.0000010613533653846155, 0.000001058513917722902, 8.468574082167831e-7, 8.451324847027973e-7, 7.458419334571679e-7, 7.376141417176574e-7, 7.161300808566435e-7, 7.0...
638_A. Home Numbers
540
540_100
The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n - 1 in the order from the beginning of the street to the end (in the picture: from ...
n, a = map(int, input().split()) print(a // 2 + 1 if a % 2 else (n - a + 2) // 2)
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
4 2
O(1)
0.000002
{ "public_tests": [ { "input": "4 2\n", "output": "2" }, { "input": "8 5\n", "output": "3" } ], "private_tests": [ { "input": "5026 4697\n", "output": "2349" }, { "input": "1628 274\n", "output": "678" }, { "input": "34614 2...
[ 0.000009983000000000003, 0.0000035185000000000037, 0.0000033425000000000006, 0.0000031499999999999986, 0.000002874500000000001, 0.0000028484999999999982, 0.0000027665000000000014, 0.0000026480000000000024, 0.0000025899999999999972, 0.000002584500000000002, 0.0000025734999999999983, 0.000002565...
703_A. Mishka and Game
408
408_2
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. I...
n=int(input()) m=0 c=0 a=[] for i in range(n): a.append(list(map(int,input().split()))) if a[i][0]>a[i][1]: m+=1 if a[i][1]>a[i][0]: c+=1 if m>c: print("Mishka") if m<c: print("Chris") if m==c: print("Friendship is magic!^^")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 6 1 1 6
O(n*m)
0.000002
{ "public_tests": [ { "input": "2\n6 1\n1 6\n", "output": "Friendship is magic!^^\n" }, { "input": "3\n1 5\n3 3\n2 2\n", "output": "Chris\n" }, { "input": "3\n3 5\n2 1\n4 2\n", "output": "Mishka\n" } ], "private_tests": [ { "input": "55\n6 6\n6...
[ 0.000017809748893684443, 0.00001124286796875, 0.000007135376393138112, 0.000006439463587194057, 0.000005393050303212413, 0.0000037969262729458046, 0.0000030307054195804195, 0.000002547211203835227, 0.0000024790602463942304, 0.0000024047635352928326, 0.0000021785389395760488, 0.0000019531590635...
703_A. Mishka and Game
408
408_1572
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. I...
n=int(input()) h=k=0 for i in range(n): a,b=map(int,input().split()) if(a>b): h+=1 elif(a<b): k+=1 if(h>k): print("Mishka") elif(h==k): print("Friendship is magic!^^") else: print("Chris")
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
2 6 1 1 6
O(n)
0.000006
{ "public_tests": [ { "input": "2\n6 1\n1 6\n", "output": "Friendship is magic!^^\n" }, { "input": "3\n1 5\n3 3\n2 2\n", "output": "Chris\n" }, { "input": "3\n3 5\n2 1\n4 2\n", "output": "Mishka\n" } ], "private_tests": [ { "input": "55\n6 6\n6...
[ 0.000012938181148929196, 0.00001173103749180507, 0.000009005446555397727, 0.000008842122500546329, 0.000008839258768575176, 0.000008810906536822552, 0.000008808180015297203, 0.000008797827551354895, 0.000008704729717548077, 0.000008635403013002623, 0.000008626389204545454, 0.000008542221782124...
p02417 Counting Characters
3005
3005_182
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters. Constraints * The number of characters in the sentence < 1200 Input A sentence in English is given in several lines. Output Prints the number of alphabetical letters in the following format: a : The n...
import string a = "" while True: try: a += input().lower() except Exception: break for i in string.ascii_lowercase: print(f"{i} : {a.count(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, ...
This is a pen.
O(n)
0
{ "public_tests": [ { "input": "This is a pen.", "output": "a : 1\nb : 0\nc : 0\nd : 0\ne : 1\nf : 0\ng : 0\nh : 1\ni : 2\nj : 0\nk : 0\nl : 0\nm : 0\nn : 1\no : 0\np : 1\nq : 0\nr : 0\ns : 2\nt : 1\nu : 0\nv : 0\nw : 0\nx : 0\ny : 0\nz : 0" } ], "private_tests": [], "generated_tests": [ ...
[ 0.000004617569943728147, 0.0000030373234948645106, 0.000003027382552993881, 0.000002864512743116259, 0.0000027620989674388113, 0.0000020012250191215033, 4.0619886363636365e-7, 4.059851125437064e-7, 3.0647060751748255e-7, 3.06244454763986e-7, 3.0565719241695803e-7, 3.0532199246066433e-7, 3.05...
p02417 Counting Characters
3005
3005_13
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters. Constraints * The number of characters in the sentence < 1200 Input A sentence in English is given in several lines. Output Prints the number of alphabetical letters in the following format: a : The n...
import sys s=sys.stdin.read().lower() a=[print(i,':',s.count(i)) for i in map(chr,range(97,123))]
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
This is a pen.
O(1)
0.000002
{ "public_tests": [ { "input": "This is a pen.", "output": "a : 1\nb : 0\nc : 0\nd : 0\ne : 1\nf : 0\ng : 0\nh : 1\ni : 2\nj : 0\nk : 0\nl : 0\nm : 0\nn : 1\no : 0\np : 1\nq : 0\nr : 0\ns : 2\nt : 1\nu : 0\nv : 0\nw : 0\nx : 0\ny : 0\nz : 0" } ], "private_tests": [], "generated_tests": [ ...
[ 0.00007948150000000001, 0.000065767, 0.000009312999999999997, 0.000007801000000000043, 0.000007534500000000021, 0.0000067494999999999936, 0.000006380499999999998, 0.0000059615000000000275, 0.0000051070000000000716, 0.000004984000000000032, 0.000004262999999999996, 0.000004137499999999931, 0....
651_B. Beautiful Paintings
1054
1054_216
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa...
# -*- codeing:utf-8 -*- class A(object): def __init__(self): self.AC() def GetData(self): self.m_N = int(input()) self.m_X = [int(x) for x in input().split()] def AC(self): self.GetData() ans = 0 while self.m_X: self.m_Y = [] for x in self.m_X: if x not in self.m_Y: self.m_Y.append(x) ...
import sys import time import itertools from itertools import accumulate, product, permutations, combinations import collections from collections import Counter, OrderedDict, deque, defaultdict, ChainMap from functools import lru_cache import math from math import sqrt, sin, cos, tan, ceil, fabs, floor, gcd, exp, log, ...
5 20 30 10 50 40
O(n**2)
0
{ "public_tests": [ { "input": "5\n20 30 10 50 40\n", "output": "4\n" }, { "input": "4\n200 100 100 200\n", "output": "2\n" } ], "private_tests": [ { "input": "10\n103 101 103 103 101 102 100 100 101 104\n", "output": "7\n" }, { "input": "20\n9...
[ 0.0015303004178232982, 0.0010184545989398227, 0.00020253594800655528, 0.00019778053668749227, 0.00010426719082042884, 0.00010184995287332837, 0.000044359569258795816, 0.00003249335268289125, 0.000008201964309261037, 0.000007339011129260066, 0.0000072329450895160915, 0.000006607332860166019, ...