context
stringlengths
88
7.54k
groundtruth
stringlengths
9
28.8k
groundtruth_language
stringclasses
3 values
type
stringclasses
2 values
code_test_cases
listlengths
1
565
dataset
stringclasses
6 values
code_language
stringclasses
1 value
difficulty
float64
0
1
mid
stringlengths
32
32
Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem. You are given a weighted directed graph with n vertices and m edges. You need to find a path (perh...
from sys import * f = list(map(int, stdin.read().split())) n, m = f[0], f[1] d = [[] for i in range(100001)] for j in range(2, len(f), 3): x, y, w = f[j:j + 3] d[w].append((y, x)) s = [0] * (n + 1) for q in d: for y, k in [(y, s[x]) for y, x in q]: s[y] = max(s[y], k + 1) print(max(s))
python
code_algorithm
[ { "input": "6 7\n1 2 1\n3 2 5\n2 4 2\n2 5 2\n2 6 9\n5 4 3\n4 3 4\n", "output": "6\n" }, { "input": "3 3\n1 2 1\n2 3 1\n3 1 1\n", "output": "1\n" }, { "input": "3 3\n1 2 1\n2 3 2\n3 1 3\n", "output": "3\n" }, { "input": "6 7\n1 2 1\n1 5 1\n5 2 3\n2 3 3\n3 4 4\n1 6 1\n6 2 3\n",...
code_contests
python
0
e21d9b9503193907eb32bc7fa85a1b5f
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one r...
n, m = map(int, input().split()) dist = [0] * (n + 1) for row in range(n + 1): dist[row] = [1] * (n + 1) for i in range(m): a, b = map(int, input().split()) dist[a][b] = dist[b][a] = 2 x, v, i = 3 - dist[1][n], [0] * (n + 1), 1 d = [n + 1] * (n + 1) res = d[1] = 0 while i != n: v[i] = 1 for j i...
python
code_algorithm
[ { "input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n", "output": "3\n" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "output": "-1\n" }, { "input": "4 2\n1 3\n3 4\n", "output": "2\n" }, { "input": "3 1\n1 2\n", "output": "-1\n" }, { "input": "3 1\n1 3\n", "output...
code_contests
python
0.9
5e927a266845e46a27bf299ba6f4c031
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti. For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the bigges...
def main(): n = int(input()) a = [int(i) for i in input().strip().split()] res = [0] * n for st in range(n): cnt = [0] * n x = 0 y = 0 for ed in range(st, n): cnt[a[ed] - 1] += 1 if (cnt[a[ed] - 1] > x) or (cnt[a[ed] - 1] == x and a[ed] - 1 < y):...
python
code_algorithm
[ { "input": "3\n1 1 1\n", "output": "6 0 0\n" }, { "input": "4\n1 2 1 2\n", "output": "7 3 0 0\n" }, { "input": "10\n9 1 5 2 9 2 9 2 1 1\n", "output": "18 30 0 0 1 0 0 0 6 0\n" }, { "input": "50\n17 13 19 19 19 34 32 24 24 13 34 17 19 19 7 32 19 13 13 30 19 34 34 28 41 24 24 4...
code_contests
python
0
22312ec0c815c6e805298d7f35a963c2
Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose severa...
I=lambda:map(int,input().split()) R=range ans=0 n,m=I() a=list(I()) for _ in R(m):l,r=I();ans+=max(0,sum(a[i]for i in R(l-1,r))) print(ans)
python
code_algorithm
[ { "input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1\n", "output": "16\n" }, { "input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n", "output": "7\n" }, { "input": "2 2\n-1 -2\n1 1\n1 2\n", "output": "0\n" }, { "input": "3 3\n1 -1 3\n1 2\n2 3\n1 3\n", "output": "5\n" }, { "input":...
code_contests
python
0.2
2cf19a2e9a276fc27bcaf3d76233ad85
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day cons...
from math import * def lcm(a, b): return a*b//gcd(a, b) n, m, z = map(int, input().split()) print(z//lcm(n, m))
python
code_algorithm
[ { "input": "1 1 10\n", "output": "10\n" }, { "input": "2 3 9\n", "output": "1\n" }, { "input": "1 2 5\n", "output": "2\n" }, { "input": "972 1 203\n", "output": "0\n" }, { "input": "6 4 36\n", "output": "3\n" }, { "input": "550 1 754\n", "output": ...
code_contests
python
1
154944a21f0f834a4675f2825c3d1c13
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()) d=n//2 c=n-d while math.gcd(c,d)!=1: c+=1 d-=1 print(d,c)
python
code_algorithm
[ { "input": "12\n", "output": "5 7\n" }, { "input": "4\n", "output": "1 3\n" }, { "input": "3\n", "output": "1 2\n" }, { "input": "998\n", "output": "497 501\n" }, { "input": "69\n", "output": "34 35\n" }, { "input": "9\n", "output": "4 5\n" }, ...
code_contests
python
0.6
1d6d7c416d72c0e1447b1af70105e5b6
Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point m on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost ...
n, m = list( map( int, input().split() ) ) A = [] B = [] CanReach = [] start_idx = 0 end_idx = 0 for i in range( n ): a, b = list( map( int, input().split() ) ) A.append( a ) B.append( b ) memo = {} def best( i ): if A[i] <= m <= B[i]: return ( True ) if i in memo: return memo...
python
code_algorithm
[ { "input": "3 5\n0 2\n2 4\n3 5\n", "output": "YES\n" }, { "input": "3 7\n0 4\n2 5\n6 7\n", "output": "NO\n" }, { "input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 5\n4 8\n5 5\n5 7\n6 7\n6 6\n7 7\n7 7\n7 7\n7 8\n7 8...
code_contests
python
0.7
34454032af38960590476fed66332631
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water d...
N = int(input()) above = list(map(int, input().split())) if N == 1: print(0) quit() required_mark = [0] * N required_mark[N-2] = above[N-1] for i in reversed(range(N-2)): required_mark[i] = max(above[i+1], required_mark[i+1] - 1) d = 0 mark = 1 for i in range(1, N): if mark == above[i]: mark ...
python
code_algorithm
[ { "input": "5\n0 1 1 2 2\n", "output": "0\n" }, { "input": "6\n0 1 0 3 0 2\n", "output": "6\n" }, { "input": "5\n0 1 2 1 2\n", "output": "1\n" }, { "input": "7\n0 1 1 3 0 0 6\n", "output": "10\n" }, { "input": "1\n0\n", "output": "0\n" }, { "input": "3...
code_contests
python
0
47571ebd8dda43e2dfc3912d99a43711
Not to be confused with [chessboard](https://en.wikipedia.org/wiki/Chessboard). <image> Input The first line of input contains a single integer N (1 ≤ N ≤ 100) — the number of cheeses you have. The next N lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and...
a, b = 0, 0 n = int(input()) for i in range(n): x, y = input().split() if y == 'soft': a += 1 else: b += 1 for i in range(1, 1000): n = i*i y = n // 2 x = n - y if (a <= x and b <= y) or (a <= y and b <= x): print(i) break
python
code_algorithm
[ { "input": "6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard\n", "output": "4\n" }, { "input": "9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard\n", "output": "3\n" }, { "input": "9\ngorg...
code_contests
python
0
479b392e3d2c3a2034263a11f1590a3e
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup...
n = int(input()) arr = [int(input()) for _ in range(n)] if len(set(arr)) == 1: print('Exemplary pages.') elif len(set(arr)) > 3: print('Unrecoverable configuration.') else: kek = set(arr) kek = list(kek) kek.sort() val = kek[-1] - kek[0] if val % 2 == 1: print('Unrecoverable configur...
python
code_algorithm
[ { "input": "5\n250\n250\n250\n250\n250\n", "output": "Exemplary pages.\n" }, { "input": "5\n270\n250\n250\n230\n250\n", "output": "20 ml. from cup #4 to cup #1.\n" }, { "input": "5\n270\n250\n249\n230\n250\n", "output": "Unrecoverable configuration.\n" }, { "input": "3\n1\n1\...
code_contests
python
0
f181be8f34ec3e6eaac6dc0efbb53aae
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners. The valid sizes of T-shirts are either "M" or from 0 to 3 "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not. Ther...
t=int(input()) pre=[] curr=[] for i in range(t): s1=input() pre.append(s1) for i in range(t): s2=input() curr.append(s2) z=0 for i in range(t): if pre[i] in curr: curr.remove(pre[i]) pass else: z+=1 print(z)
python
code_algorithm
[ { "input": "2\nM\nXS\nXS\nM\n", "output": "0\n" }, { "input": "3\nXS\nXS\nM\nXL\nS\nXS\n", "output": "2\n" }, { "input": "2\nXXXL\nXXL\nXXL\nXXXS\n", "output": "1\n" }, { "input": "6\nM\nXXS\nXXL\nXXL\nL\nL\nXXS\nXXL\nS\nXXS\nL\nL\n", "output": "2\n" }, { "input":...
code_contests
python
0.6
e8ceeb0158c8782ef04a2b0cc91a7d59
Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally: a_{1} ≤ a_{2}, a_{n} ≤ a_{n-1} and a_{i} ≤ max(a_{i-1}, ...
import os from io import BytesIO from math import trunc if os.name == 'nt': input = BytesIO(os.read(0, os.fstat(0).st_size)).readline MX = 201 MOD = 998244353 MODF = float(MOD) MODF_inv = 1.0 / MODF quickmod1 = lambda x: x - MODF * trunc(x / MODF) def quickmod(a): return a - MODF * trunc(a * MODF_inv) de...
python
code_algorithm
[ { "input": "3\n1 -1 2\n", "output": "1\n" }, { "input": "2\n-1 -1\n", "output": "200\n" }, { "input": "8\n-1 -1 -1 59 -1 -1 -1 -1\n", "output": "658449230\n" }, { "input": "2\n38 38\n", "output": "1\n" }, { "input": "2\n-1 35\n", "output": "1\n" }, { "...
code_contests
python
0
14cb7d5fdb07ce4dae5e9100b7545609
There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1). There are also m wooden platforms on a river, the i-th platform has length c_i (so the i-th platform takes c_i consecuti...
from collections import defaultdict import sys input=sys.stdin.readline n,m,d=map(int,input().split()) c=[int(i) for i in input().split()] ind=defaultdict(int) suff=n for i in range(m-1,-1,-1): suff-=c[i] ind[i+1]=suff+1 indl=[] for i in ind: indl.append(i) indl.reverse() cur=0 for i in indl: if ind[i]-...
python
code_algorithm
[ { "input": "7 3 2\n1 2 1\n", "output": "YES\n0 1 0 2 2 0 3\n" }, { "input": "10 1 5\n2\n", "output": "YES\n0 0 0 0 1 1 0 0 0 0\n" }, { "input": "10 1 11\n1\n", "output": "YES\n0 0 0 0 0 0 0 0 0 1\n" }, { "input": "15 2 5\n1 1\n", "output": "NO\n" }, { "input": "10...
code_contests
python
0
981e2072ff27748f562e8ad295354c7f
Bob is about to take a hot bath. There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can ...
import math def gcd(a,b): if(b==0): return a return gcd(b,a%b) l=input().split() t1=int(l[0]) t2=int(l[1]) x1=int(l[2]) x2=int(l[3]) t0=int(l[4]) num1=t2-t0 num2=t0-t1 if(t1==t2): print(x1,x2) quit() if(num1==0): print(0,x2) quit() if(num2==0): print(x1,0) quit() z=num2/num1 maxa...
python
code_algorithm
[ { "input": "300 500 1000 1000 300\n", "output": "1000 0\n" }, { "input": "10 70 100 100 25\n", "output": "99 33\n" }, { "input": "143 456 110 117 273\n", "output": "76 54\n" }, { "input": "176902 815637 847541 412251 587604\n", "output": "228033 410702\n" }, { "in...
code_contests
python
0
927a8764fc85e7579a727e6046721238
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said: —Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes....
def sort(s): return sorted(sorted(s), key=str.upper) s=input() s1=input() l=sort(s) c=l.count('0') res="" if(len(l)>c): res=res+l[c] for i in range(c): res=res+l[i] for i in range(c+1,len(s)): res=res+l[i] if(s1==res): print("OK") else: print("WRONG_ANSWER")
python
code_algorithm
[ { "input": "3310\n1033\n", "output": "OK\n" }, { "input": "4\n5\n", "output": "WRONG_ANSWER\n" }, { "input": "17109\n01179\n", "output": "WRONG_ANSWER\n" }, { "input": "111111111\n111111111\n", "output": "OK\n" }, { "input": "912\n9123\n", "output": "WRONG_ANS...
code_contests
python
0.1
26616726f7f771e1409e4c088d37b7da
Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realiz...
from bisect import bisect_left, bisect_right def go(): n = int(input()) a = list(map(int, input().split())) b = max(a).bit_length() res = 0 vals = a for i in range(b + 1): # print("") b2 = 2 << i b1 = 1 << i a0 = [aa for aa in a if aa & b1==0] a1 = [aa f...
python
code_algorithm
[ { "input": "3\n1 2 3\n", "output": "2\n" }, { "input": "2\n1 2\n", "output": "3\n" }, { "input": "51\n50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n", "output": "148\n" }, ...
code_contests
python
0
8081dfe29155a81c1b0a9eb265ec8301
Given an array a of length n, find another array, b, of length n such that: * for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i. The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. Input The first line contains an ...
n=int(input()) arr=list(map(int,input().split())) flag=0 vis=[0]*(10**6+1) for i in range(n): if arr[i]>i+1: flag=1 vis[arr[i]]=1 if flag==1: print(-1) quit() b=[-1]*(n) for i in range(1,n): if arr[i-1]!=arr[i]: b[i]=arr[i-1] not_vis=[] for i in range(10**6+1): if vis[i]==0: ...
python
code_algorithm
[ { "input": "3\n1 2 3\n", "output": "0 1 2\n" }, { "input": "3\n1 1 3\n", "output": "0 2 1\n" }, { "input": "4\n0 0 0 2\n", "output": "1 3 4 0\n" }, { "input": "7\n0 0 2 2 5 5 6\n", "output": "1 3 0 4 2 7 5\n" }, { "input": "1\n1\n", "output": "0\n" }, { ...
code_contests
python
0
971e2db40403f97027b64f636b525277
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e...
n=int(input()) a=list(map(int,input().split())) c=[] d=0 c.append(a[0]) for i in range(1,n): y=a[i]-a[i-1] if y>0 and a[i]>max(c): c.append(a[i]) d+=1 elif y<0 and a[i]<min(c): c.append(a[i]) d+=1 print(d) #print(c)
python
code_algorithm
[ { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n", "output": "4\n" }, { "input": "5\n100 50 200 150 200\n", "output": "2\n" }, { "input": "5\n100 36 53 7 81\n", "output": "2\n" }, { "input": "5\n100 81 53 36 7\n", "output": "4\n" }, { "input": "...
code_contests
python
1
585d767940b35031d9378b62e25715be
Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages. Recent actions shows a list of n different threads ordered by the time of the latest message in the thread....
n = int(input()) arr = list(map(int,input().split())) ans = n-1 for i in range(-1,-n,-1): if arr[i]>arr[i-1]: ans-=1 else: break print(ans)
python
code_algorithm
[ { "input": "5\n5 2 1 3 4\n", "output": "2\n" }, { "input": "4\n4 3 2 1\n", "output": "3\n" }, { "input": "3\n1 2 3\n", "output": "0\n" }, { "input": "4\n2 3 1 4\n", "output": "2\n" }, { "input": "3\n1 3 2\n", "output": "2\n" }, { "input": "6\n3 2 1 6 4...
code_contests
python
0
df014ff102c3733628e2f179889077ac
Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n vertices and 0 edges. During Bubble Sort execution, edges appear a...
from bisect import bisect_left, bisect_right, insort R = lambda: map(int, input().split()) n, arr = int(input()), list(R()) dp = [] for i in range(n): idx = bisect_left(dp, arr[i]) if idx >= len(dp): dp.append(arr[i]) else: dp[idx] = arr[i] print(len(dp))
python
code_algorithm
[ { "input": "3\n3 1 2\n", "output": "2\n" }, { "input": "100\n36 48 92 87 28 85 42 10 44 41 39 3 79 9 14 56 1 16 46 35 93 8 82 26 100 59 60 2 96 52 13 98 70 81 71 94 54 91 17 88 33 30 19 50 18 73 65 29 78 21 61 7 99 97 45 89 57 27 76 11 49 72 84 69 43 62 4 22 75 6 66 83 38 34 86 15 40 51 37 74 67 31 ...
code_contests
python
1
ed4bf8d99b7591584ee78f8503172fde
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o...
import re def main(): n=eval(input()) a=[] s=[] s.append(0) s.append(0) while n: n-=1 temp=re.split(' ',input()) k=eval(temp[0]) for i in range(k>>1): s[0]+=eval(temp[i+1]) if k&1: a.append(eval(temp[(k+1)>>1])) for i in range((k+1)>>1,k): s[1]+=eval(temp[i+1]) a...
python
code_algorithm
[ { "input": "3\n3 1 3 2\n3 5 4 6\n2 8 7\n", "output": "18 18\n" }, { "input": "2\n1 100\n2 1 10\n", "output": "101 10\n" }, { "input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n", "output": "7000 7000\n" }, { "input": "1\n9 2 8 6 5 9 4 ...
code_contests
python
0.1
708d90da4d95de1a2e484592f7bc06be
Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the following q queries. In the i-th query, he gives you two integers — ui...
def build_graph(): line1 = input().strip().split() n = int(line1[0]) m = int(line1[1]) graph = {} for _ in range(m): line = input().strip().split() u = int(line[0]) v = int(line[1]) c = int(line[2]) if c not in graph: graph[c] = {j: [] for j in ran...
python
code_algorithm
[ { "input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n", "output": "1\n1\n1\n1\n2\n" }, { "input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n", "output": "2\n1\n0\n" }, { "input": "2 1\n1 2 1\n1\n1 2\n", "output": "1\n" }, ...
code_contests
python
1
c6d15422c40ce0a7a175dc309b5a26e3
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i...
from sys import stdin c = [[0]*1002 for _ in range(0,1002)] MOD = int(1e9+7) for i in range(0,1002): c[i][0] = c[i][i] = 1 for j in range(0,i): c[i][j] = (c[i-1][j-1] + c[i-1][j])%MOD r = map(int,stdin.read().split()) n = next(r) ans = 1 sum = 0 for _ in range(0,n): x = next(r) ans = (ans * ...
python
code_algorithm
[ { "input": "3\n2\n2\n1\n", "output": "3\n" }, { "input": "4\n1\n2\n3\n4\n", "output": "1680\n" }, { "input": "25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33\n", "output": "362689152\n" }, { "input": "47\n20\n21\n16\n18\n...
code_contests
python
0
efd4e1d387c490f1552ee16dae2621d1
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Yo...
n=int(input()) tl = list(map(int, input().split())) time=cnt=0 while cnt <15 and time<90: time+=1 if tl.count(time)>0: cnt=0 else: cnt+=1 print(time)
python
code_algorithm
[ { "input": "3\n7 20 88\n", "output": "35\n" }, { "input": "9\n15 20 30 40 50 60 70 80 90\n", "output": "90\n" }, { "input": "9\n16 20 30 40 50 60 70 80 90\n", "output": "15\n" }, { "input": "2\n1 18\n", "output": "16\n" }, { "input": "9\n6 20 27 28 40 53 59 70 85\...
code_contests
python
0
1bd1caf7bdabf2fc9a0af0feedc377ec
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room. Anatoly just made all his cockroaches to form a single line. As he is a perfectioni...
#http://codeforces.com/problemset/problem/719/B #solved n = int(input()) s = input() red_black = True swap_red = {"b": 0, "r": 0} swap_black = {"b": 0, "r": 0} for c in s: if red_black is True and c != "b": swap_black["r"] += 1 elif red_black is False and c != "r": swap_black["b"] += 1 ...
python
code_algorithm
[ { "input": "5\nrbbrr\n", "output": "1\n" }, { "input": "5\nbbbbb\n", "output": "2\n" }, { "input": "3\nrbr\n", "output": "0\n" }, { "input": "166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbr...
code_contests
python
0
1c30fa1473cb7131b46d15a3422e2ee0
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, .... <image> The Monster will catch them if at any point they scream at the same tim...
import math R=lambda:list(map(int,input().split())) a,b=R() c,d=R() if abs(b-d)%math.gcd(a,c)!=0: print(-1) exit(0) while b != d: if b<d: b+=a else: d+=c print(b)
python
code_algorithm
[ { "input": "20 2\n9 19\n", "output": "82\n" }, { "input": "2 1\n16 12\n", "output": "-1\n" }, { "input": "84 82\n38 6\n", "output": "82\n" }, { "input": "2 3\n2 2\n", "output": "-1\n" }, { "input": "2 3\n4 99\n", "output": "99\n" }, { "input": "3 7\n3 ...
code_contests
python
0.2
c3d3121a64b3490edbc1f9e1bbd71cf1
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market. This morning, as us...
def f(): n, m = map(int, input().split()) l = list(tuple(map(int, input().split())) for _ in range(n)) l.sort(key=lambda e: (0, 6, 3, 2)[e[0]] * e[1], reverse=True) last, r = [0] * 4, 0 for i, (w, c) in enumerate(l): if m < w: break m -= w r += c last[w] =...
python
code_algorithm
[ { "input": "4 3\n3 10\n2 7\n2 8\n1 1\n", "output": "10\n" }, { "input": "2 2\n1 3\n2 2\n", "output": "3\n" }, { "input": "1 1\n2 1\n", "output": "0\n" }, { "input": "52 102\n3 199\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 10...
code_contests
python
0.5
c7bdeebc3ab1bec429122f4b93485a4d
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in ...
import sys from collections import deque input=sys.stdin.readline n,k,m=map(int,input().split()) a=list(map(int,input().split())) r=a[0] flag=0 for i in range(n): if r!=a[i]: flag=1 break if flag==0: print((m*n)%k) sys.exit() if k>n: print(m*n) sys.exit() curr=a[0] tmp=1 que=deque([(a[0],1)]) for i in...
python
code_algorithm
[ { "input": "4 2 5\n1 2 3 1\n", "output": "12\n" }, { "input": "1 9 10\n1\n", "output": "1\n" }, { "input": "3 2 10\n1 2 1\n", "output": "0\n" }, { "input": "10 5 1000000000\n1 1 1 2 2 1 2 2 2 2\n", "output": "10000000000\n" }, { "input": "5 3 3\n1 2 2 1 1\n", ...
code_contests
python
0
75a333362852698e353d5c5724912d03
There is a rectangular grid of n rows of m initially-white cells each. Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and...
def read_data(): n, m = map(int, input().strip().split()) a = [] for i in range(n): line = list(input().strip()) for j in range(len(line)): if line[j] == ".": line[j] = 0 else: line[j] = 1 a.append(line) return n, m, a def ...
python
code_algorithm
[ { "input": "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n", "output": "No\n" }, { "input": "5 5\n..#..\n..#..\n#####\n..#..\n..#..\n", "output": "No\n" }, { "input": "5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n", "output": "Yes\n" }, { "input": "9 5...
code_contests
python
0
866e1b1a5024d76d0150325413102f70
Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games. Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot o...
n,p=map(int,input().split()) nums=[0]+list(map(int,input().split())) mod=10**9+7 f=[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(n+1)] _2=[0]*(n+1) _2[0]=1 for i in range(1,n+1): _2[i]=(_2[i-1]<<1)%mod f[0][0][0][0]=1 if nums[1]!=0: f[1][1][0][1]+=1 if nums[1]!=1: f[1][1][1][0]+=1 fo...
python
code_algorithm
[ { "input": "3 1\n-1 0 1\n", "output": "6\n" }, { "input": "2 1\n1 0\n", "output": "1\n" }, { "input": "1 1\n-1\n", "output": "2\n" }, { "input": "9 1\n0 1 -1 -1 -1 -1 1 1 1\n", "output": "755810045\n" }, { "input": "16 0\n-1 0 0 1 0 0 0 0 -1 -1 -1 -1 1 1 0 1\n", ...
code_contests
python
0
fc73d0f162bb4f216933bd024cf06cb7
There are n players sitting at the card table. Each player has a favorite number. The favorite number of the j-th player is f_j. There are k ⋅ n cards on the table. Each card contains a single integer: the i-th card contains number c_i. Also, you are given a sequence h_1, h_2, ..., h_k. Its meaning will be explained b...
def solve(): n, k = map(int, input().split()) c = list(map(int, input().split())) f = list(map(int, input().split())) h = list(map(int, input().split())) cnt = {} for i in c: cnt[i] = cnt.get(i, 0) + 1 likecolor = {} for i in range(n): likecolor.setdefault(f[i], []).appen...
python
code_algorithm
[ { "input": "4 3\n1 3 2 8 5 5 8 2 2 8 5 2\n1 2 2 5\n2 6 7\n", "output": "21\n" }, { "input": "3 3\n9 9 9 9 9 9 9 9 9\n1 2 3\n1 2 3\n", "output": "0\n" }, { "input": "1 1\n1\n2\n1\n", "output": "0\n" }, { "input": "1 1\n1\n1\n100000\n", "output": "100000\n" }, { "in...
code_contests
python
0
767770e7bb2d67963fdd7bcc0f4c0f57
Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it. For each of next n days Vasya knows a_i — number of units of garbage he will produce on the i-th day. Each unit of garbage must be dis...
import sys n, k = tuple(int(i) for i in sys.stdin.readline().split()) a = tuple(int(i) for i in sys.stdin.readline().split()) assert len(a) == n bags = 0 r = 0 for ai in a: leftovers = (r > 0) q, r = divmod(ai + r, k) if q == 0: if leftovers: bags += 1 r = 0 else: ...
python
code_algorithm
[ { "input": "3 2\n1 0 1\n", "output": "2\n" }, { "input": "4 4\n2 8 4 1\n", "output": "4\n" }, { "input": "3 2\n3 2 1\n", "output": "3\n" }, { "input": "5 1\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "5000000000\n" }, { "input": "3 10\n5 ...
code_contests
python
0
9bce6b905241c743c39e8dcc7f0ba0a6
Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile. You are given n operations which Vasya has made. Find the minimal possible number of stones that can b...
''' t= input() lng= len(t) li1=[]; li2=[] for i in range(lng): if t[i]!='a': li1.append(t[i]) elif t[i]=='a': li2.append(i) aa= ''.join(li1) if len(aa)==0: print(t); exit(0) if len(aa)%2==1: print(':('); exit(0) if len(aa)%2==0: #print(123) l= int(len(aa)/2); lp= l#; pri...
python
code_algorithm
[ { "input": "2\n-+\n", "output": "1\n" }, { "input": "3\n---\n", "output": "0\n" }, { "input": "5\n++-++\n", "output": "3\n" }, { "input": "4\n++++\n", "output": "4\n" }, { "input": "4\n-+--\n", "output": "0\n" }, { "input": "2\n++\n", "output": "2\...
code_contests
python
0.5
541774b1dd7591868bbbbde785d3a7d9
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now. Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per cocon...
x,y,z=map(int,input().split()) sum=(x+y)//z i1=x//z i2=y//z x=x%z y=y%z current=i1+i2 nu=0 if current==sum: print(sum,end=' ') print(nu) else: if x>y: h=x else: h=y current=sum-current current=current*z nu=current-h print(sum, end=' ') print(nu)
python
code_algorithm
[ { "input": "6 8 2\n", "output": "7 0\n" }, { "input": "5 4 3\n", "output": "3 1\n" }, { "input": "5000000000000 6000000000000 10000000000000\n", "output": "1 4000000000000\n" }, { "input": "2778787205 1763925790 48326734\n", "output": "93 0\n" }, { "input": "58242...
code_contests
python
0.5
e18f9cc7dd9c4db26d3b72216b069719
The only difference between the easy and the hard versions is the maximum value of k. You are given an infinite sequence of form "112123123412345..." which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from 1 to 1, the second one — from 1 to 2...
def isqrt(x): if x < 0: raise ValueError('square root not defined for negative numbers') n = int(x) if n == 0: return 0 a, b = divmod(n.bit_length(), 2) x = 2**(a+b) while True: y = (x + n//x)//2 if y >= x: return x x = y p = [0, 45, 9045, 1395...
python
code_algorithm
[ { "input": "4\n2132\n506\n999999999\n1000000000\n", "output": "8\n2\n9\n8\n" }, { "input": "5\n1\n3\n20\n38\n56\n", "output": "1\n2\n5\n2\n0\n" }, { "input": "1\n755045\n", "output": "4\n" }, { "input": "19\n1\n10\n100\n1000\n10000\n100000\n1000000\n10000000\n100000000\n10000...
code_contests
python
0
81d8018afb841321c7a3b4877c0f5e8e
Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches. You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The re...
n=int(input()) e=(n+1)//36 n-=36*e print(e,(n+1)//3)
python
code_algorithm
[ { "input": "42\n", "output": "1 2\n" }, { "input": "5\n", "output": "0 2\n" }, { "input": "4\n", "output": "0 1\n" }, { "input": "71\n", "output": "2 0\n" }, { "input": "9999\n", "output": "277 9\n" }, { "input": "35\n", "output": "1 0\n" }, { ...
code_contests
python
1
fc3686e6bc050a7353cf335b4bacd967
We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i. There is one cursor. The cursor's location ℓ is denoted by an integer in \{0, …, |s|\}, with the following meaning: * If ℓ = 0, then the cursor...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ MAX=10**9+7 def solve(): x = int(input()) s = [int(i) for i in input()] ans=len(s) c = "" l = 0 while l < x: l += 1 k=len(s) if k < x: #s += s[l:]*(s[l - 1]-1) for i in ran...
python
code_algorithm
[ { "input": "4\n5\n231\n7\n2323\n6\n333\n24\n133321333\n", "output": "25\n1438\n1101\n686531475\n" }, { "input": "9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n22\n1500\n1111112111111112\n1500\n1111111111221111111\n1500\n111111122\n1500\n11111121111121111111\n", "output": "1504\n1599\n...
code_contests
python
0
98aebc8d9ac047c5cbd30b0aa6d75430
A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an n× m grid. Initially, you may place some north magnets and some south magnets into the cells. You are allowe...
# -*- coding:utf-8 -*- """ created by shuangquan.huang at 2020/6/16 """ import collections import time import os import sys import bisect import heapq from typing import List def check(row): start, end = 0, len(row) - 1 while start < len(row) and row[start] == 0: start += 1 if start >...
python
code_algorithm
[ { "input": "3 3\n.#.\n###\n##.\n", "output": "1\n" }, { "input": "4 5\n....#\n####.\n.###.\n.#...\n", "output": "2\n" }, { "input": "4 2\n##\n.#\n.#\n##\n", "output": "-1\n" }, { "input": "3 5\n.....\n.....\n.....\n", "output": "0\n" }, { "input": "2 1\n.\n#\n", ...
code_contests
python
0
255050c78acc6bcbb32f0419cc20e189
You are given a non-decreasing array of non-negative integers a_1, a_2, …, a_n. Also you are given a positive integer k. You want to find m non-decreasing arrays of non-negative integers b_1, b_2, …, b_m, such that: * The size of b_i is equal to n for all 1 ≤ i ≤ m. * For all 1 ≤ j ≤ n, a_j = b_{1, j} + b_{2, j}...
import sys as _sys def main(): t = int(input()) for i_t in range(t): n, k = _read_ints() a = tuple(_read_ints()) try: result = find_min_m(a, k) except ValueError: result = -1 print(result) def _read_line(): result = _sys.stdin.readline() ...
python
code_algorithm
[ { "input": "6\n4 1\n0 0 0 1\n3 1\n3 3 3\n11 3\n0 1 2 2 3 3 3 4 4 4 4\n5 3\n1 2 3 4 5\n9 4\n2 2 3 5 7 11 13 13 17\n10 7\n0 1 1 2 3 3 4 5 5 6\n", "output": "-1\n1\n2\n2\n2\n1\n" }, { "input": "1\n3 2\n3 3 3\n", "output": "1\n" }, { "input": "1\n3 3\n1 1 1\n", "output": "1\n" }, { ...
code_contests
python
0
e1df76d623d2f5d639901c90d4147c82
There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought n carrots with lengths a_1, a_2, a_3, …, a_n. However, rabbits are very fertile and multiply very quickly. Zookeeper now has k rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut the carrots...
import sys from heapq import heapify, heappush, heappop def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)] def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e for l in ra...
python
code_algorithm
[ { "input": "1 4\n19\n", "output": "91\n" }, { "input": "3 6\n5 3 1\n", "output": "15\n" }, { "input": "10 23\n343 984 238 758983 231 74 231 548 893 543\n", "output": "41149446942\n" }, { "input": "1 1\n1\n", "output": "1\n" }, { "input": "29 99047\n206580 305496 6...
code_contests
python
0
8f0262c2791be779d2fb78fa6a934511
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequenc...
from math import log n=int(input()) s=list(map(int,input().split( ))) p=[] for i in range(0,n-1): m=(log(n-1-i,2))//1 p.append(i+2**m) for k in range(1,n): g=0 f=s[:] for i in range(0,k): g+=f[i] f[int(p[i])]+=f[i] print(g)
python
code_algorithm
[ { "input": "8\n1 2 3 4 5 6 7 8\n", "output": "1\n3\n6\n10\n16\n24\n40\n" }, { "input": "4\n1 0 1 2\n", "output": "1\n1\n3\n" }, { "input": "9\n13 13 7 11 3 9 3 5 5\n", "output": "13\n26\n33\n44\n47\n69\n79\n117\n" }, { "input": "80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29...
code_contests
python
0.2
043f64ecc6672429ce73691532d7cb26
Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≤ a1 ≤ a2 ≤ ... ≤ an). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and height hi. Dima throws eac...
# https://codeforces.com/problemset/problem/272/C # we just check if the box dropped falls above the previous box or on stair number(1...w) # the box is dropped from the top and hence we need to check the heights from the top - # which height is suitable and higher m = int(input()) arr = list(map(int, input().split(...
python
code_algorithm
[ { "input": "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n", "output": "1\n3\n13\n23\n33\n" }, { "input": "3\n1 2 3\n2\n1 1\n3 1\n", "output": "1\n3\n" }, { "input": "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n", "output": "1\n3\n4\n6\n" }, { "input": "2\n1 6\n5\n2 6\n1 2\n1 1\n1 2\n1 7\n"...
code_contests
python
0.8
f9b6d2ce10a613c111a140a866040bbd
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel. When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the...
import sys from itertools import * from math import * def solve(): n, m = map(int, input().split()) h = list(map(int, input().split())) p = list(map(int, input().split())) ss, ll = 0, int(2.2e10) while ss < ll: avg = (ss + ll) // 2 works = True hidx = 0 pidx = 0 ...
python
code_algorithm
[ { "input": "3 4\n2 5 6\n1 3 6 8\n", "output": "2\n" }, { "input": "3 3\n1 2 3\n1 2 3\n", "output": "0\n" }, { "input": "1 2\n165\n142 200\n", "output": "81\n" }, { "input": "10 11\n1 909090909 1818181817 2727272725 3636363633 4545454541 5454545449 6363636357 7272727265 818181...
code_contests
python
0
947b381f28565ea5279da576cdf0a7c3
Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the string. When Dima pulls the i-th string holding it on the j-th fret...
def solution() : # 最大的距离来自于角落附近的点 n,m,k,s = map(int, input().split()) dis = lambda a,b : abs(a[0] - b[0]) + abs(a[1] - b[1]) corner = [(0,0), (0,m-1), (n-1,0), (n-1,m-1)] vertex = [[(n,m), (n,-1), (-1,m), (-1,-1)] for _ in range(k+1)] for i in range(n) : for j,note in enumerate(map(int, input().split())) : ve...
python
code_algorithm
[ { "input": "4 6 5 7\n3 1 2 2 3 1\n3 2 2 2 5 5\n4 2 2 2 5 3\n3 2 2 1 4 3\n2 3 1 4 1 5 1\n", "output": "8\n" }, { "input": "4 4 9 5\n4 7 9 5\n1 2 1 7\n8 3 4 9\n5 7 7 2\n7 1 9 2 5\n", "output": "4\n" }, { "input": "10 1 9 5\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n1 1 9 2 3\n", "output": "9\n" ...
code_contests
python
0.9
cfba0cfe6cd64a232010e5b43494ebf5
Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the leaf nodes from the left to ...
import sys def main(): rdl = list(map(int,input().split())) obx(rdl[0],rdl[1],0,1) def obx(lvl, ind, kl, current): if lvl ==0: print(int(kl)) sys.exit() all = 0 for i in range(lvl+1): all += 2**i all -= 1 if ind > (2**(lvl))/2: if current == 1: kl...
python
code_algorithm
[ { "input": "1 2\n", "output": "2\n" }, { "input": "10 1024\n", "output": "2046\n" }, { "input": "3 6\n", "output": "10\n" }, { "input": "2 3\n", "output": "5\n" }, { "input": "49 295606900104348\n", "output": "820858833984106\n" }, { "input": "1 1\n", ...
code_contests
python
0
35fdb73e35023007302abb16f1264c50
You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array. Input The first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 107). The second li...
f = lambda: map(int, input().split()) n, m = f() t = list(f()) s = [0] * 301 d = s[:] for i in t: d[i] += 1 for i in t * min(m, 2 * n): s[i] = max(s[:i + 1]) + 1 print(max(s) + max((m - n * 2) * max(d), 0))
python
code_algorithm
[ { "input": "4 3\n3 1 4 2\n", "output": "5\n" }, { "input": "100 10000000\n1 2 2 1 2 2 1 1 2 2 1 2 1 1 1 1 1 2 2 2 1 2 1 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 1 2 2 1 1 2 2 2 2 2 2 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 2 2 2 1 1 2 2 1 2 1 1 2 2 1 1 1 2 1 2 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1\n", "output": "5600000...
code_contests
python
0
6457a38e0443cca7b464c4cf46cb95cc
Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single ...
n, k = map(int, input().split()) a = [int(s) for s in input().split()] p = n - k q = 2*k - n if n < k: q = n p = 0 ma = 0 for i in range ((n - q) // 2): ma = max((a[i] + a[n - q - i - 1]), ma) ma2 = 0 for i in range(n - q, n): ma2 = max(a[i], ma2) print(max(ma,ma2))
python
code_algorithm
[ { "input": "4 3\n2 3 5 9\n", "output": "9\n" }, { "input": "2 1\n2 5\n", "output": "7\n" }, { "input": "3 2\n3 5 7\n", "output": "8\n" }, { "input": "10 5\n15 15 20 28 38 44 46 52 69 94\n", "output": "109\n" }, { "input": "100 89\n474 532 759 772 803 965 1043 1325...
code_contests
python
0
7f9cf4a2a4c3af97d75b14f1ecfa3414
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance...
n = int(input()) a = list(map(int, input().split())) maxLocate = a.index(n) minLocate = a.index(1) distanceMax = len(a) - 1 - a.index(n) distanceMin = len(a) - 1 - a.index(1) print(max(maxLocate, minLocate, distanceMax, distanceMin))
python
code_algorithm
[ { "input": "6\n6 5 4 3 2 1\n", "output": "5\n" }, { "input": "7\n1 6 5 3 4 7 2\n", "output": "6\n" }, { "input": "5\n4 5 1 3 2\n", "output": "3\n" }, { "input": "76\n1 47 54 17 38 37 12 32 14 48 43 71 60 56 4 13 64 41 52 57 62 24 23 49 20 10 63 3 25 66 59 40 58 33 53 46 70 7 ...
code_contests
python
0.4
b867886dff7f284ed3e8facd3a5c54c3
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
sum1,sum2,sum3 = 0,0,0 n = int(input()) while n: n-=1 l = list(map(int, input().split())) sum1 += l[0] sum2 += l[1] sum3 += l[2] if sum1==0 and sum2 ==0 and sum3 ==0: print("YES") else: print("NO")
python
code_algorithm
[ { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n", "output": "YES\n" }, { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "output": "NO\n" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0\n", ...
code_contests
python
0.8
4ce3a84bf637a8bb431758bcbc2fee81
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n. <image> Mehrdad has become quite confused and wants you to help him. Please hel...
n = int(input()) if n == 0: print(1) if n % 4 == 0 and n!= 0 : print(6) if n % 4 == 1: print(8) if n % 4 == 2: print(4) if n % 4 == 3: print(2)
python
code_algorithm
[ { "input": "2\n", "output": "4\n" }, { "input": "1\n", "output": "8\n" }, { "input": "12\n", "output": "6\n" }, { "input": "1378\n", "output": "4\n" }, { "input": "51202278\n", "output": "4\n" }, { "input": "989898989\n", "output": "8\n" }, { ...
code_contests
python
0.9
0de5a85bbfe62f3985b3f35e79238e33
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent verti...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def main(): n = II() d = ...
python
code_algorithm
[ { "input": "6\n1 2\n2 3\n2 4\n4 5\n1 6\n", "output": "3\n" }, { "input": "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n", "output": "-1\n" }, { "input": "10\n4 2\n7 4\n2 6\n2 5\n4 8\n10 3\n2 9\n9 1\n5 10\n", "output": "-1\n" }, { "input": "10\n5 10\n7 8\n8 3\n2 6\n3 2\n9 7\n4 5\n10 1\n6 ...
code_contests
python
0
14554a81a0d901b36be2bcda3623a480
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = ...
b1,q,l,m = map(int,input().split()) a = set(map(int,input().split())) if q==0: if 0 in a: if b1 in a: print(0) elif abs(b1)<=l: print(1) else: print(0) elif abs(b1)<=l: print("inf") else: print(0) elif q==1: if abs(b1)<=l and b1...
python
code_algorithm
[ { "input": "123 1 2143435 4\n123 11 -5453 141245\n", "output": "0\n" }, { "input": "3 2 30 4\n6 14 25 48\n", "output": "3\n" }, { "input": "123 1 2143435 4\n54343 -13 6 124\n", "output": "inf\n" }, { "input": "-100 0 50 1\n0\n", "output": "0\n" }, { "input": "-100...
code_contests
python
0
99a78cf79db538f4906fc1b2648d8954
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change. You have to find the minimum number of digits in which these two numbers c...
""" Author : Arif Ahmad Date : Algo : Difficulty : """ from sys import stdin, stdout def main(): k = int(stdin.readline().strip()) n = stdin.readline().strip() n = sorted(n) total = 0 for c in n: d = ord(c) - 48 total += d ans = 0 for c in n: if total >= k: break d = ord(c) - 48 total ...
python
code_algorithm
[ { "input": "3\n11\n", "output": "1\n" }, { "input": "3\n99\n", "output": "0\n" }, { "input": "3\n21\n", "output": "0\n" }, { "input": "3\n111\n", "output": "0\n" }, { "input": "6\n33\n", "output": "0\n" }, { "input": "6\n222\n", "output": "0\n" }...
code_contests
python
0.3
6f7c2ea995f736f713637663d76cf96d
Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n sections. At this moment there are exactly ai archers located at the...
import sys border = 1 << 30 def build(x=0): res = [0, 0] i = 0 while x and i < 30: if x & 1: res[1] += (1 << i) x >>= 1 i += 1 i = 0 while x: if x & 1: res[0] += (1 << i) x >>= 1 i += 1 return res n, r, k = map(int, ...
python
code_algorithm
[ { "input": "4 2 0\n1 2 3 4\n", "output": "6\n" }, { "input": "5 0 6\n5 4 3 4 9\n", "output": "5\n" }, { "input": "5 1 1\n2 1 2 1 2\n", "output": "3\n" }, { "input": "1 0 0\n1\n", "output": "1\n" }, { "input": "1 1 10\n23\n", "output": "33\n" }, { "inpu...
code_contests
python
0
5e76f05f19977ca99e53e2453a29ec12
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course yo...
(n,m) = tuple(map(int, input().split(" "))) x = list(map(int, input().split(" "))) nib = 0 ans = [] cou = 0; for i in x: nib+=i if (nib<m): ans.append(nib//m) else: ans.append(nib//m) nib-=(nib//m)*m print (*ans)
python
code_algorithm
[ { "input": "1 100\n99\n", "output": "0\n" }, { "input": "4 20\n10 9 19 2\n", "output": "0 0 1 1\n" }, { "input": "3 5\n3 7 9\n", "output": "0 2 1\n" }, { "input": "1 1\n2\n", "output": "2\n" }, { "input": "10 4\n9 5 6 4 3 9 5 1 10 7\n", "output": "2 1 2 1 0 3 ...
code_contests
python
0
f6ee9fd4796df6687db5c33572266da9
JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer n, you can perform the following operations zero or more times: * mul x: multiplies n by x (where x is an arbitrary positive integer). * sqrt: replaces n with √...
import math def sieve(n): mark = [0]*(n+1) prime = [] for i in range(3, n+1, 2): if not mark[i]: for j in range(3*i, n+1, i+i): mark[j] = 1 prime.append(2) for i in range(3, n+1, 2): if not mark[i]: prime.append(i) return prime def isp...
python
code_algorithm
[ { "input": "20\n", "output": "10 2\n" }, { "input": "5184\n", "output": "6 4\n" }, { "input": "2\n", "output": "2 0\n" }, { "input": "328509\n", "output": "69 3\n" }, { "input": "279936\n", "output": "6 4\n" }, { "input": "341\n", "output": "341 0\...
code_contests
python
0
fdfb5915cfe41d7e3f66e1f0fae82048
The Fair Nut lives in n story house. a_i people live on the i-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. It was decided ...
n = int(input()) arr = list(map(int, input().split())) cur = 0 ans = 100000000 for x in range(n): cur = 0 for i in range(n): summ = 0 summ += abs(x - i) summ += i summ += x summ += x summ += i summ += abs(x - i) summ *= arr[i] cur += summ ...
python
code_algorithm
[ { "input": "2\n1 1\n", "output": "4\n" }, { "input": "3\n0 2 1\n", "output": "16\n" }, { "input": "5\n6 1 1 8 3\n", "output": "156\n" }, { "input": "5\n4 9 4 2 6\n", "output": "188\n" }, { "input": "3\n1 2 2\n", "output": "24\n" }, { "input": "100\n23 ...
code_contests
python
0.2
2988712d1fa38c47fa6592f305c721a5
The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of n vertices. Each vertex i has its own value a_i. All vertices are connected in series by edges. Formally, for every 1 ≤ i < n there is an edge between the vertices of i and i+1. Denote the function f(l, r), which takes two in...
n = int(input()) + 1 res = 0 a = tuple(map(int, input().split())) for ai in a: res += ai * (n - ai) for ai, aj in map(sorted, zip(a, a[1:])): res -= ai * (n - aj) print(res) #
python
code_algorithm
[ { "input": "3\n2 1 3\n", "output": "7\n" }, { "input": "10\n1 5 2 5 5 3 10 6 5 1\n", "output": "104\n" }, { "input": "4\n2 1 1 3\n", "output": "11\n" }, { "input": "9\n1 9 1 1 4 5 9 9 1\n", "output": "60\n" }, { "input": "44\n42 44 4 24 29 17 32 30 30 9 28 9 22 16...
code_contests
python
0
004c8c3b496cbfb833511df0f5bb2d49
Nauuo is a girl who loves drawing circles. One day she has drawn a circle and wanted to draw a tree on it. The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n. Nauuo wants to draw a tree on the circle, the nodes of the tree should be in n distinct points o...
import sys n = int(sys.stdin.readline().strip()) D = [0] * n p = 998244353 for i in range (0, n - 1): u, v = list(map(int, sys.stdin.readline().strip().split())) D[u-1] = D[u-1] + 1 D[v-1] = D[v-1] + 1 ans = n for i in range (0, n): for j in range (0, D[i]): ans = (ans * (j + 1)) % p print(an...
python
code_algorithm
[ { "input": "4\n1 2\n1 3\n1 4\n", "output": "24\n" }, { "input": "4\n1 2\n1 3\n2 4\n", "output": "16\n" }, { "input": "8\n4 5\n1 2\n6 3\n2 3\n2 8\n4 7\n2 4\n", "output": "2304\n" }, { "input": "7\n2 7\n2 6\n4 7\n7 3\n7 5\n1 7\n", "output": "1680\n" }, { "input": "3...
code_contests
python
0
7d4dddf256b4180bcb91f72347050a95
Tokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute — health points, shortened to HP. In general, different values of HP are grouped into 4 categories: * Category A if HP is in the form of (4 n + 1), that is, when divided by 4, the remainder is ...
n=int(input()) d={} d[0]='1 A' d[1]='0 A' d[2]='1 B' d[3]='2 A' x=n%4 print(d[x])
python
code_algorithm
[ { "input": "33\n", "output": "0 A\n" }, { "input": "98\n", "output": "1 B\n" }, { "input": "85\n", "output": "0 A\n" }, { "input": "99\n", "output": "2 A\n" }, { "input": "50\n", "output": "1 B\n" }, { "input": "100\n", "output": "1 A\n" }, { ...
code_contests
python
0.2
41a97504183601abe3ceebe87312f47b
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has a number consisting of n digits without leading zeroes. He represented it as an array of d...
n, k = map(int, input().split()) s = list(input()) cnt = 0 for i in range(n - 1): if cnt == k: break if s[i] == '4' and s[i + 1] == '7': if i & 1: if s[i - 1] == '4': if (cnt - k) & 1: s[i] = '7' print(''.join(s)) ex...
python
code_algorithm
[ { "input": "4 2\n4478\n", "output": "4478\n" }, { "input": "7 4\n4727447\n", "output": "4427477\n" }, { "input": "7 74\n4777774\n", "output": "4777774\n" }, { "input": "3 99\n447\n", "output": "477\n" }, { "input": "47 7\n777744777474744774774777747477474474477747...
code_contests
python
0.1
13b7bb3a2fa26c6b74e81fb469268d50
A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets. The store does not sell single clothing items — instead, it sells suits of two types: * a suit of the first type consists of one tie and one jacket; * a suit of the second type ...
a = int(input()) b = int(input()) c = int(input()) d = int(input()) c1 = int(input()) c2 = int(input()) p = 0 if c2 > c1: m = min(b,c,d) b -= m c -= m d -= m p += m * c2 if d > 0: p += (min(a,d) * c1) else: m = min(a,d) a -= m d -= m p += m * c1 if d > 0: p += (min(b,c,...
python
code_algorithm
[ { "input": "4\n5\n6\n3\n1\n2\n", "output": "6\n" }, { "input": "17\n14\n5\n21\n15\n17\n", "output": "325\n" }, { "input": "12\n11\n13\n20\n4\n6\n", "output": "102\n" }, { "input": "88\n476\n735\n980\n731\n404\n", "output": "256632\n" }, { "input": "844\n909\n790\n...
code_contests
python
0.5
d75a83eee11db3060300483d4159348f
Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height). Boris cho...
#------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() ...
python
code_algorithm
[ { "input": "1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500\n", "output": "640\n" }, { "input": "1\n9 10 7\n1\n7 1 3\n", "output": "114\n" }, { "input": "20\n110 466 472\n112 153 152\n424 492 490\n348 366 113\n208 337 415\n491 448 139\n287 457 403\n444 382 160\n325 486 284\n447 454 136\n216 41...
code_contests
python
0.3
ef09bc49c31ace0b4fad8719bed8d54d
Input The input contains two integers a1, a2 (0 ≤ ai ≤ 109), separated by a single space. Output Output a single integer. Examples Input 3 14 Output 44 Input 27 12 Output 48 Input 100 200 Output 102 Write Python code to solve the problem. Present the code in the code block: ```python Your code `...
from math import floor x, y = input().split() x = int(x) y = int(y) rev = 0 while y > 0: a = int(y % 10) rev = rev * 10 + a y = floor(y / 10) b = x + rev print(b)
python
code_algorithm
[ { "input": "27 12\n", "output": "48\n" }, { "input": "3 14\n", "output": "44\n" }, { "input": "100 200\n", "output": "102\n" }, { "input": "59961393 89018456\n", "output": "125442491\n" }, { "input": "937477084 827336327\n", "output": "1661110812\n" }, { ...
code_contests
python
0
cab2e7d856718bbbac601b174bae60f5
There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. * Current character pointer (CP); *...
n, q = map(int, input().split()) s = input() for _ in range(q): l, r = map(int, input().split()) t = list(s[l-1:r]) p, d = 0, 1 res = [0] * 10 while 0 <= p < len(t): if '0' <= t[p] <= '9': k = int(t[p]) res[k] += 1 if k > 0: t[p] = str(k-1)...
python
code_algorithm
[ { "input": "7 4\n1&gt;3&gt;22&lt;\n1 3\n4 7\n7 7\n1 7\n", "output": "0 1 0 0 0 0 0 0 0 0\n0 0 0 1 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 0 0 0 0 0\n" }, { "input": "5 1\n1>3><\n4 5\n", "output": "0 0 0 0 0 0 0 0 0 0\n" }, { "input": "4 1\n34><\n1 4\n", "output": "0 0 1 2 1 0 0 0...
code_contests
python
0
2cba14933e8cb099ee4051fed894b301
Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only on...
n, k = map(int, input().split()) def prod(n): if n%2: return n*((n+1)//2) else: return (n//2)*(n+1) def total_count(n, k): if k >= n: return (0, 0, 1) else: count = 0 l = 1; r = k s = prod(k) while l <= r: mid = (l+r)//2 if n > s - prod(mid) + mid: r = mid-1 else: l = mid+1 n = n...
python
code_algorithm
[ { "input": "4 3\n", "output": "2\n" }, { "input": "8 4\n", "output": "-1\n" }, { "input": "5 5\n", "output": "1\n" }, { "input": "1000000000000000000 1000000000\n", "output": "-1\n" }, { "input": "525 34\n", "output": "25\n" }, { "input": "1000000000 9...
code_contests
python
0
367643f66a5a19054906d79c36c114d0
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally move...
move=input() ans="" s=input() keyboard=["qwertyuiop","asdfghjkl;","zxcvbnm,./"] if move =="R": for i in range(len(s)): for j in range(len(keyboard)): if s[i] in keyboard[j]: ans+=keyboard[j][keyboard[j].index(s[i])-1] elif move =="L": for i in range(len(s)): for j in ...
python
code_algorithm
[ { "input": "R\ns;;upimrrfod;pbr\n", "output": "allyouneedislove\n" }, { "input": "R\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n", "output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
code_contests
python
0.1
442faa71de658fb7b4d867a378f31b60
Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences. Let's assume that strings s and t have the same length n, then the function h(s, t) is defined as the number of positions in whic...
# problem statement: https://codeforces.com/problemset/problem/520/C modulo = 1000000007 n = int(input()) char_count = [0] * 256 s = input() for i in range(n): char_count[ord(s[i])] += 1 max_char_count = max(char_count) num_max_char = 0 for i in range(256): if char_count[i] == max_char_count: num_max_char += 1 pr...
python
code_algorithm
[ { "input": "2\nAG\n", "output": "4\n" }, { "input": "3\nTTT\n", "output": "1\n" }, { "input": "1\nC\n", "output": "1\n" }, { "input": "20\nTAAGCGACCAGGTGCTTTAC\n", "output": "511620083\n" }, { "input": "15\nAGCGAATCCCATTGT\n", "output": "14348907\n" }, { ...
code_contests
python
0.4
9605a5006ef6d0d99a70e72bb28109bd
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set. Now Wilbur wants to number the points in the set he has, that is ...
from collections import defaultdict def solve(): N = int(input()) maxx = 0 maxy = 0 WS = defaultdict(list) for i in range(N): x, y = map(int, input().split()) WS[y - x].append((x, y)) maxx = max(maxx, x) maxy = max(maxy, y) for w in WS: WS[w].sort(rev...
python
code_algorithm
[ { "input": "5\n2 0\n0 0\n1 0\n1 1\n0 1\n0 -1 -2 1 0\n", "output": "YES\n0 0\n1 0\n2 0\n0 1\n1 1\n" }, { "input": "3\n1 0\n0 0\n2 0\n0 1 2\n", "output": "NO\n" }, { "input": "1\n0 0\n-9876\n", "output": "NO\n" }, { "input": "9\n0 0\n1 0\n2 0\n0 1\n1 1\n2 1\n1 2\n2 2\n0 2\n0 0 ...
code_contests
python
0.1
9890236fb3f3975336aea5408c25a8a2
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: * An 'L' indicates he should move one unit left. * An 'R' indicates he should move one unit right. * A 'U' indicates he should move one unit up. * A 'D' indicates he shoul...
s = input() ud = lr = 0 for ch in s: if(ch=='R'): lr = lr+1 if(ch=='L'): lr = lr-1 if(ch=='U'): ud = ud+1 if(ch=='D'): ud = ud-1 if((abs(lr) + abs(ud))%2==1): print(-1) else: print(int((abs(lr) + abs(ud))/2))
python
code_algorithm
[ { "input": "UDUR\n", "output": "1\n" }, { "input": "RUUR\n", "output": "2\n" }, { "input": "RRU\n", "output": "-1\n" }, { "input": "RDDLLDLUUUDDRDRURLUUURLLDDLRLUURRLLRRLDRLLUDRLRULLDLRRLRLRLRUDUUDLULURLLDUURULURLLRRRURRRDRUUDLDRLRDRLRRDDLDLDLLUDRUDRLLLLDRDUULRUURRDLULLULDUDU...
code_contests
python
0.8
46baf946c94a65e603a4b1c4233ad894
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ...
def solve(a): l = [0] li = [] j = 0 for i in range(len(a)): if a[i] == "A" or a[i] == "E" or a[i] == "I" or a[i] == "O" or a[i] == "U" or a[i] == "Y": l.append(i + 1) j += 1 li.append(l[j] - l[j-1]) l.append(i + 1) j += 1 li.append(l[j] - l[j-1...
python
code_algorithm
[ { "input": "ABABBBACFEYUKOTT\n", "output": "4\n" }, { "input": "AAA\n", "output": "1\n" }, { "input": "HDDRZDKCHHHEDKHZMXQSNQGSGNNSCCPVJFGXGNCEKJMRKSGKAPQWPCWXXWHLSMRGSJWEHWQCSJJSGLQJXGVTBYALWMLKTTJMFPFS\n", "output": "28\n" }, { "input": "AABBYYYYYYYY\n", "output": "3\n"...
code_contests
python
0.5
93fc86dee7e882e2bb292136ae75a2ac
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, ...
def function1(n,s): if n==1: return 1 pokemonj=0 pokecage=[0 for i in range(100001)] for i in range(n): pokecage[s[i]]+=1 maxyincage=min(pokecage[1],1) a = [i for i in range(100001)] a[1] = 0 i = 2 while i <= 100000: if a[i] != 0: pokemonj=0 ...
python
code_algorithm
[ { "input": "5\n2 3 4 6 7\n", "output": "3\n" }, { "input": "3\n2 3 4\n", "output": "2\n" }, { "input": "3\n49999 49999 99998\n", "output": "3\n" }, { "input": "3\n457 457 457\n", "output": "3\n" }, { "input": "2\n4 9\n", "output": "1\n" }, { "input": "...
code_contests
python
0
120344dc268048cf5a44aae7954a9587
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for n flowers and so it looks like a pipe with n holes. Arkady can only use the water that flows from the first hole. Arkady can block some of the holes, and then pour A liters of water into the pipe. After that,...
n, a, b = [int(i) for i in input().split(' ')] sizes = [int(i) for i in input().split(' ')] st = sum(sizes) s = (sizes[0] * a) / b sb = st - s blockable = sorted(sizes[1:], reverse=True) blocked_no = 0 blocked_amount = 0 for i in range(len(blockable)): if blocked_amount < sb: blocked_no += 1 block...
python
code_algorithm
[ { "input": "4 10 3\n2 2 2 2\n", "output": "1\n" }, { "input": "5 10 10\n1000 1 1 1 1\n", "output": "4\n" }, { "input": "4 80 20\n3 2 1 4\n", "output": "0\n" }, { "input": "2 10000 1\n1 9999\n", "output": "0\n" }, { "input": "10 300 100\n20 1 3 10 8 5 3 6 4 3\n", ...
code_contests
python
0.3
337d8d6e95f5e838f5013f84da60c5fb
You are given a string s consisting of n lowercase Latin letters. n is even. For each position i (1 ≤ i ≤ n) in string s you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every posi...
def get_mask(inp): return(5 << ord(inp) - ord('a')) n = int(input()) for i in range(0, n): input() st = input() ls = [] for j in st: ls.append(get_mask(j)) for j in range(0, len(ls) // 2): if(ls[j] & ls[-1 * (j + 1)] == 0): print("NO") break else...
python
code_algorithm
[ { "input": "5\n6\nabccba\n2\ncf\n4\nadfa\n8\nabaazaba\n2\nml\n", "output": "YES\nNO\nYES\nNO\nNO\n" }, { "input": "1\n4\nyaaa\n", "output": "NO\n" }, { "input": "1\n6\ndazbyd\n", "output": "NO\n" }, { "input": "4\n2\nay\n2\nbz\n2\nya\n2\nzb\n", "output": "NO\nNO\nNO\nNO\n...
code_contests
python
0.7
bac863b34e4c94155d7a3fae631b8126
Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map. The treasure map can be represented as a rectangle n × m in size. Each cell stands for an islands' square (the square's side length equals...
#!/usr/bin/env python3 from sys import stdin n, m = map(int, stdin.readline().rstrip().split()) island = [] pos = {} for i in range(n): island.append(stdin.readline().rstrip()) for j, c in enumerate(island[i]): if c >= 'A' and c <= 'Z': pos[c] = [i, j] l_reach = [[-1 for j in range(m)] fo...
python
code_algorithm
[ { "input": "3 4\n####\n#.A#\n####\n2\nW 1\nN 2\n", "output": "no solution\n" }, { "input": "6 10\n##########\n#K#..#####\n#.#..##.##\n#..L.#...#\n###D###A.#\n##########\n4\nN 2\nS 1\nE 1\nW 2\n", "output": "AD\n" }, { "input": "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nW 3\n", ...
code_contests
python
0.2
e11319113dc00250049274dd2a01ef6c
There are n people sitting in a circle, numbered from 1 to n in the order in which they are seated. That is, for all i from 1 to n-1, the people with id i and i+1 are adjacent. People with id n and 1 are adjacent as well. The person with id 1 initially has a ball. He picks a positive integer k at most n, and passes th...
n=int(input()) a={1} for i in range(2,int(n**0.5)+1): if n%i==0: a.add(i) a.add(n//i) ans=[1] a=list(a) for i in a: term=n//i ans.append((term*(2+(term-1)*i))//2) ans.sort() print(*ans)
python
code_algorithm
[ { "input": "6\n", "output": "1 5 9 21\n" }, { "input": "16\n", "output": "1 10 28 64 136\n" }, { "input": "536870912\n", "output": "1 268435458 805306372 1879048200 4026531856 8321499168 16911433792 34091303040 68451041536 137170518528 274609472512 549487380480 1099243196416 21987548...
code_contests
python
0
c8cf70bcab968b0b563ba9864aa215c2
You are given an integer n (n ≥ 0) represented with k digits in base (radix) b. So, $$$n = a_1 ⋅ b^{k-1} + a_2 ⋅ b^{k-2} + … a_{k-1} ⋅ b + a_k.$$$ For example, if b=17, k=3 and a=[11, 15, 7] then n=11⋅17^2+15⋅17+7=3179+255+7=3441. Determine whether n is even or odd. Input The first line contains two integers b and...
b,k=map(int,input().split()) arr=list(map(int,input().split())) arr.insert(0,0) s=0 for i in range(1,len(arr)): s=s+(arr[-i]*pow(b,i-1,1000000000)) if(s&1): print("odd") else: print("even")
python
code_algorithm
[ { "input": "13 3\n3 2 7\n", "output": "even\n" }, { "input": "99 5\n32 92 85 74 4\n", "output": "odd\n" }, { "input": "2 2\n1 0\n", "output": "even\n" }, { "input": "10 9\n1 2 3 4 5 6 7 8 9\n", "output": "odd\n" }, { "input": "6 1\n0\n", "output": "even\n" }...
code_contests
python
0.5
a623792bc6a6c8cf8d395d2867dc4e9d
Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≤ l ≤ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010...
# ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code if __name__ == "__main__": n,k = map(int,input().split()) a = (n - k)//2 ps = '0'*a + '1' s =...
python
code_algorithm
[ { "input": "4 4\n", "output": "1111\n" }, { "input": "7 3\n", "output": "0010010\n" }, { "input": "5 3\n", "output": "01010\n" }, { "input": "101 3\n", "output": "00000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000010\n" },...
code_contests
python
0
1917645314ce8cecf81c61f0fa1df186
While playing with geometric figures Alex has accidentally invented a concept of a n-th order rhombus in a cell grid. A 1-st order rhombus is just a square 1 × 1 (i.e just a cell). A n-th order rhombus for all n ≥ 2 one obtains from a n-1-th order rhombus adding all cells which have a common side with it to it (look ...
n = int(input()) print(sum(range(n)) * 4 + 1)
python
code_algorithm
[ { "input": "3\n", "output": "13\n" }, { "input": "1\n", "output": "1\n" }, { "input": "2\n", "output": "5\n" }, { "input": "37\n", "output": "2665\n" }, { "input": "25\n", "output": "1201\n" }, { "input": "64\n", "output": "8065\n" }, { "in...
code_contests
python
0.6
c5951634089bc25da8e128401ab89b90
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the n days of summer. On the i-th day, a_i millimeters of rain will fall. All values a_i are distinct. The mayor k...
import sys,heapq,math from collections import deque,defaultdict printn = lambda x: sys.stdout.write(x) inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) DBG = True # and False R = 10**9 + 7 def ddprint(x): if DBG: print(x) n,x,y = inm() a ...
python
code_algorithm
[ { "input": "5 5 5\n100000 10000 1000 100 10\n", "output": "5\n" }, { "input": "10 2 2\n10 9 6 7 8 3 2 1 4 5\n", "output": "3\n" }, { "input": "10 2 3\n10 9 6 7 8 3 2 1 4 5\n", "output": "8\n" }, { "input": "100 7 4\n100 99 98 97 96 95 94 70 88 73 63 40 86 28 20 39 74 82 87 62...
code_contests
python
0.7
39bf79ed716f3e171c7d8773b865a82a
Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area. To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of n r...
n, m = map(int, input().split()) mod = 10**9+7 a = [] a.append(0) a.append(2) a.append(4) for i in range(3, max(n, m)+1): a.append((a[i-1]+a[i-2])%mod) print((a[m]-2 + a[n])%mod)
python
code_algorithm
[ { "input": "2 3\n", "output": "8\n" }, { "input": "2 1\n", "output": "4\n" }, { "input": "3 6\n", "output": "30\n" }, { "input": "2 5\n", "output": "18\n" }, { "input": "1 2\n", "output": "4\n" }, { "input": "100000 100000\n", "output": "870472905\...
code_contests
python
0
9e1a1e64e5b4c58793c210b16b532fbc
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students. The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher). Your task is to find the number...
R = lambda:map(int,input().split()) n = int(input()) a = list(R()) b = list(R()) dif = [(b[i] - a[i], 1) for i in range(n)] for x in dif: if x[0] < 0: dif.append((-x[0], 0)) dif = sorted(dif) count = 0 ans = 0 for i in range(1, len(dif)): if dif[i][1] == 1: count += 1 if dif[i][1] == 0: an...
python
code_algorithm
[ { "input": "4\n1 3 2 4\n1 3 2 4\n", "output": "0\n" }, { "input": "5\n4 8 2 6 2\n4 5 4 1 3\n", "output": "7\n" }, { "input": "4\n289148443 478308391 848805621 903326233\n164110294 114400164 187849556 86077714\n", "output": "6\n" }, { "input": "2\n335756331 677790822\n38899334...
code_contests
python
1
2bab43c17aa1f9eb392a37f5baf4d2d5
Recall that the sequence b is a a subsequence of the sequence a if b can be derived from a by removing zero or more elements without changing the order of the remaining elements. For example, if a=[1, 2, 1, 3, 1, 2, 1], then possible subsequences are: [1, 1, 1, 1], [3] and [1, 2, 1, 3, 1, 2, 1], but not [3, 2, 3] and [...
t = int(input()) for tt in range(t): n = int(input()) arr = list(map(int,input().split())) mx = arr[0] sm = 0 for j in range(n): if (arr[j] * mx < 0 ): sm += mx mx = arr[j] else: mx = max(mx , arr[j]) print(sm + mx)
python
code_algorithm
[ { "input": "4\n5\n1 2 3 -1 -2\n4\n-1 -2 -1 -3\n10\n-2 8 3 8 -4 -15 5 -2 -3 1\n6\n1 -1000000000 1 -1000000000 1 -1000000000\n", "output": "2\n-1\n6\n-2999999997\n" }, { "input": "2\n2\n-1 -1\n1\n-2\n", "output": "-1\n-2\n" }, { "input": "10\n10\n-1 5 6 2 -8 -7 -6 5 -3 -1\n10\n1 2 3 4 5 6 ...
code_contests
python
0.1
731b4f97785ccdc75d138de7f5574cd2
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr...
def is_rect(es): v = set([]) for e in es: if not ((e[0] == e[2]) or (e[1] == e[3])): return False v.add((e[0], e[1])) v.add((e[2], e[3])) if len(v) != 4: return False xs = set([]) ys = set([]) for vi in v: xs.add(vi[0]) ys.add(vi[1]...
python
code_algorithm
[ { "input": "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n", "output": "NO\n" }, { "input": "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n", "output": "YES\n" }, { "input": "2 -1 -2 -1\n2 -1 2 -1\n2 -1 -2 -1\n2 -1 2 -1\n", "output": "NO\n" }, { "input": "0 0 0 1\n0 1 0 1\n0 1 0 0\n0 1 0 1\n", ...
code_contests
python
0
bb3acb6b6f823724e889c57b9ec99a7e
As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answe...
n, m = map(int, input().split()) t = [int(input()) for i in range(n)] s, p = 0, [0] * (n + 1) for i in t: if i < 0: m -= 1 p[-i] -= 1 else: p[i] += 1 q = {i for i in range(1, n + 1) if p[i] == m} if len(q) == 0: print('Not defined\n' * n) elif len(q) == 1: j = q.pop() print('\n'.join(['T...
python
code_algorithm
[ { "input": "4 1\n+2\n-3\n+4\n-1\n", "output": "Lie\nNot defined\nLie\nNot defined\n" }, { "input": "1 1\n+1\n", "output": "Truth\n" }, { "input": "3 2\n-1\n-2\n-3\n", "output": "Not defined\nNot defined\nNot defined\n" }, { "input": "10 4\n-8\n+1\n-6\n-10\n+5\n-6\n-8\n-8\n-4\...
code_contests
python
0
822eb83c27b1798ae511bac48fa88feb
The Smart Beaver from ABBYY was offered a job of a screenwriter for the ongoing TV series. In particular, he needs to automate the hard decision: which main characters will get married by the end of the series. There are n single men and n single women among the main characters. An opinion poll showed that viewers lik...
I=lambda:list(map(int,input().split())) n,k,T=I() t=[I()for _ in '0'*k] def b(h,w,r,a): if h>n:a+=[r] else: b(h+1,w,r,a) for f,s,v in t: if f==h and s in w:b(h+1,w-set([s]),r+v,a) return a print(sorted(b(1,set(range(1,n+1)), 0,[]))[T-1])
python
code_algorithm
[ { "input": "2 4 3\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n", "output": "2\n" }, { "input": "2 4 7\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n", "output": "8\n" }, { "input": "4 16 105\n2 4 15\n1 1 16\n2 2 57\n3 4 31\n1 2 47\n2 3 28\n1 3 70\n4 2 50\n3 1 10\n4 1 11\n4 4 27\n1 4 56\n3 3 28\n3 2 28\n2 1 33\n4 3 63\n...
code_contests
python
0
1442eaf458478c73a7487c64e5fc51c6
Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the beginning of the first experiment there is a single bacterium in the test tub...
#------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUF...
python
code_algorithm
[ { "input": "2 2 4 100\n", "output": "0\n" }, { "input": "3 1 3 5\n", "output": "2\n" }, { "input": "1 4 4 7\n", "output": "3\n" }, { "input": "5 5 2 10\n", "output": "1\n" }, { "input": "1000000 1000000 1 1\n", "output": "1\n" }, { "input": "5 5 2 1\n"...
code_contests
python
0
41909479015d1a4e47d82f07cb965c55
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances. ...
from sys import stdin from collections import deque n,x = [int(x) for x in stdin.readline().split()] s1 = deque(sorted([int(x) for x in stdin.readline().split()])) s2 = deque(sorted([int(x) for x in stdin.readline().split()])) place = 0 for score in s1: if s2[-1] + score >= x: place += 1 s2.pop(...
python
code_algorithm
[ { "input": "6 7\n4 3 5 6 4 4\n8 6 0 4 3 4\n", "output": "1 5\n" }, { "input": "5 2\n1 1 1 1 1\n1 1 1 1 1\n", "output": "1 5\n" }, { "input": "1 100\n56\n44\n", "output": "1 1\n" }, { "input": "3 10\n9 9 0\n0 0 10\n", "output": "1 1\n" }, { "input": "5 45\n1 2 3 4 ...
code_contests
python
0
ad2c6c3e3dba17ce0fea0e88c8c9c05a
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i ≠ j); ...
x=int(input()) sm=sum(list(map(int,input().split())))%x if sm==0: print(x) else: print(x-1)
python
code_algorithm
[ { "input": "3\n1 4 1\n", "output": "3\n" }, { "input": "2\n2 1\n", "output": "1\n" }, { "input": "6\n-1 1 0 0 -1 -1\n", "output": "5\n" }, { "input": "4\n2 0 -2 -1\n", "output": "3\n" }, { "input": "4\n2 -7 -2 -6\n", "output": "3\n" }, { "input": "100\...
code_contests
python
1
d282912f16421a353c0e1838fa1b729b
Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is...
n,k=map(int,input().split()) l=list(map(int,input().split())) rem=[] ans=0 for i in l: rem.append(i%10) ans=ans+i//10 #print(ans) rem.sort() # 0 1 2 3.. 9 9 9.. i=n-1 while(i>=0 and k>0): if(rem[i]!=0): #starting from back 9 -> 8 .... -> 2 -> 1->0 sm=10-(rem[i]) if(k>=s...
python
code_algorithm
[ { "input": "2 2\n99 100\n", "output": "20\n" }, { "input": "2 4\n7 9\n", "output": "2\n" }, { "input": "3 8\n17 15 19\n", "output": "5\n" }, { "input": "100 9455943\n44 8 21 71 7 29 40 65 91 70 48 19 77 48 16 22 54 4 29 34 9 22 73 34 47 41 5 83 32 91 52 6 74 64 18 23 9 4 36 7...
code_contests
python
0.1
f6b9d6dc4ce1ad8d9e59a7f5b25ff792
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, the...
a, b, c = map(int, input().split()) if b == a: print('YES') elif not c: print('NO') elif (a < b) and c < 0: print('NO') elif (a > b) and c > 0: print('NO') else: print('NO' if ((b-a) % c) else 'YES')
python
code_algorithm
[ { "input": "1 -4 5\n", "output": "NO\n" }, { "input": "1 7 3\n", "output": "YES\n" }, { "input": "0 60 50\n", "output": "NO\n" }, { "input": "10 10 0\n", "output": "YES\n" }, { "input": "1 6 1\n", "output": "YES\n" }, { "input": "-2 -2 0\n", "outpu...
code_contests
python
0.4
739f82910ee3a61e5a51ff7e5d124f18
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column...
def bombs(array, rows, cols, walls, wallsInRows, wallsInCols): if walls == 0: print("YES") print(1, 1) return for i in range(0, rows): for j in range(0, cols): s = wallsInRows[i] + wallsInCols[j] if (array[i][j] == '*' and s - 1 == walls) or (array[i][j] =...
python
code_algorithm
[ { "input": "3 3\n..*\n.*.\n*..\n", "output": "NO\n" }, { "input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n", "output": "YES\n3 3\n" }, { "input": "3 4\n.*..\n....\n.*..\n", "output": "YES\n1 2\n" }, { "input": "3 3\n*..\n**.\n...\n", "output": "YES\n2 1\n" }, ...
code_contests
python
0.2
b91312534884e6456434b99042a26f35
As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are a...
def gcd(a,b): if b==0: return a return gcd(b, a%b) def lcm(a,b): return a*b/gcd(a,b) def dfs(sad, num, posjeceno): """if sad==a[sad]-1 and posjeceno!=[0]*n: return (-10, [])""" posjeceno[sad]=1 if posjeceno[a[sad]-1]==1: return (num+1, posjeceno) return dfs(a[sad]-1, ...
python
code_algorithm
[ { "input": "4\n2 1 4 3\n", "output": "1\n" }, { "input": "4\n4 4 4 4\n", "output": "-1\n" }, { "input": "4\n2 3 1 4\n", "output": "3\n" }, { "input": "100\n99 7 60 94 9 96 38 44 77 12 75 88 47 42 88 95 59 4 12 96 36 16 71 6 26 19 88 63 25 53 90 18 95 82 63 74 6 60 84 88 80 95...
code_contests
python
0
eb99a5a5e9ca63e9fff3abba8acc53de
<image> It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in th...
import sys n, k = map(int, input().split()) a = list(input()) st = [0] * 26 ed = [0] * 26 for i in range(n): if st[ord(a[i])-65] == 0: st[ord(a[i])-65] = i + 1 else: ed[ord(a[i])-65] = i + 1 for i in range(26): if st[i] != 0 and ed[i] == 0: ed[i] = st[i] n = 52 i = 0 j = 0 maxi = -1 * sys.maxsize l = 0 st.sort...
python
code_algorithm
[ { "input": "5 1\nAABBB\n", "output": "NO\n" }, { "input": "5 1\nABABB\n", "output": "YES\n" }, { "input": "433 3\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVITKNFLVCPMZSDMCHBTVAWYVZLIXXIADXNYILEYNIQHKMOGMVOCWGHCWIYMPEPADSJA...
code_contests
python
0
a5cfdd631d261f425b1632c21b39c227
In the year of 30XX participants of some world programming championship live in a single large hotel. The hotel has n floors. Each floor has m sections with a single corridor connecting all of them. The sections are enumerated from 1 to m along the corridor, and all sections with equal numbers on different floors are l...
def takeClosest(myList, myNumber): """ Assumes myList is sorted. Returns closest value to myNumber. If two numbers are equally close, return the smallest number. """ if len(myList) == 0: return 9e10 pos = bisect_left(myList, myNumber) if pos == 0: return myList[0] if pos...
python
code_algorithm
[ { "input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n", "output": "7\n5\n4\n" }, { "input": "2 10 1 1 1\n1\n10\n1\n1 5 1 8\n", "output": "3\n" }, { "input": "4 4 1 0 1\n1\n\n1\n1 2 1 4\n", "output": "2\n" }, { "input": "2 5 1 0 1\n2\n\n1\n1 4 1 5\n", "output": "1\n"...
code_contests
python
0.1
dc6ab0680aaba2dcc60202f47422f4ee
You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may perform the following operation: * add a character to the end of the string. Besides, at most once you may perform one...
n=int(input()) s=input() i=0 d="" ls=[] mx=-1 while i<n: temp=s[0:i+1] for j in range(i+1,n+1): if temp==s[i+1:j]: mx=max(mx,len(temp)) i+=1 if mx>0: print(len(temp)-mx+1) else: print(len(temp))
python
code_algorithm
[ { "input": "8\nabcdefgh\n", "output": "8\n" }, { "input": "7\nabcabca\n", "output": "5\n" }, { "input": "5\nababa\n", "output": "4\n" }, { "input": "8\naaabcabc\n", "output": "8\n" }, { "input": "7\nabcdabc\n", "output": "7\n" }, { "input": "29\nabbabb...
code_contests
python
0
bf10f9b3251139e2c39530129620e5e9
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
x, y = input().split() x = int(x) y = int(y) z = 7 - max(x, y) ans = z/6 if ans == (1/6): print("1/6") elif ans == (2/6): print("1/3") elif ans == (3/6): print("1/2") elif ans == (4/6): print("2/3") elif ans == (5/6): print("5/6") else: print("1/1")
python
code_algorithm
[ { "input": "4 2\n", "output": "1/2\n" }, { "input": "6 6\n", "output": "1/6\n" }, { "input": "1 4\n", "output": "1/2\n" }, { "input": "4 4\n", "output": "1/2\n" }, { "input": "3 3\n", "output": "2/3\n" }, { "input": "6 4\n", "output": "1/6\n" }, ...
code_contests
python
0.6
14c948fe89b366c62fc244a013f8b329
You are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it. To win the game, you will need to form some number of triples. Each triple consists of three tiles, such that the numbers written on the tile...
from collections import Counter n, m = map(int, input().split()) B = list(map(int, input().split())) cnt = Counter(B) A = sorted(cnt.keys()) n = len(A) dp = [[0] * 3 for _ in range(3)] for i, a in enumerate(A): dp2 = [[0] * 3 for _ in range(3)] for x in range(1 if i >= 2 and a - 2 != A[i - 2] else 3): f...
python
code_algorithm
[ { "input": "10 6\n2 3 3 3 4 4 4 5 5 6\n", "output": "3\n" }, { "input": "13 5\n1 1 5 1 2 3 3 2 4 2 3 4 5\n", "output": "4\n" }, { "input": "12 6\n1 5 3 3 3 4 3 5 3 2 3 3\n", "output": "3\n" }, { "input": "14 9\n5 5 6 8 8 4 3 2 2 7 3 9 5 4\n", "output": "4\n" }, { ...
code_contests
python
0
270183a4d815949dbaf157abb006a401
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The i-th page contains some mystery that will be explained on page a_i (a_i ≥ i). Ivan wants to read the whole book. Each day, he reads the first page he didn'...
import sys #p = [[] for i in range(N)] #for i in range(N): # p[i] += map(int, sys.stdin.readline().split()) #Q = input() #for i in range(Q): # print(list(map(int, sys.stdin.readline().split()))) n = int(input()) a = [int(c) for c in sys.stdin.readline().split()] aktmax, d = 0, 0 for i, c in enumerate(a, start=1)...
python
code_algorithm
[ { "input": "9\n1 3 3 6 7 6 8 8 9\n", "output": "4\n" }, { "input": "1\n1\n", "output": "1\n" }, { "input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n", "output": "13\n" }, { "input": "11\n1 2 3 4 5 6 7 8 9 10 11\n", "output": "11\n" }, { "input": "15\n1 2 3 4 5 6 7 8 9 ...
code_contests
python
0.8
9ea0e803aacc8baf2edc41dc0b55e242
This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any...
# [0,0,0] # [0,0,0] # [1,0,0] # [0,0,0] # [0,0,0] # [1,0,1] # [0,0,0] # [0,0,0] # [1,1,1] # [0,0,0] # [0,0,0] # [1,1,1] # [0,0,1] # [0,0,0] # [0,0,0] 3,2 # # 0,0 3,2 # 0,1 3,1 # 0,2 3,0 # 1,0 2,2 # 1,1 2,1 # 1,2 2,0 n, m = map(int, input().split()) ans = [] if n % 2 == 0: for i in range(int(n / 2)): ...
python
code_algorithm
[ { "input": "1 1\n", "output": "1 1\n" }, { "input": "2 3\n", "output": "1 1\n2 3\n1 2\n2 2\n1 3\n2 1\n" }, { "input": "782 19\n", "output": "1 1\n782 19\n1 2\n782 18\n1 3\n782 17\n1 4\n782 16\n1 5\n782 15\n1 6\n782 14\n1 7\n782 13\n1 8\n782 12\n1 9\n782 11\n1 10\n782 10\n1 11\n782 9\...
code_contests
python
0
a0a5a88660c891ae9eda2eeec0b98c0b