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 |
|---|---|---|---|---|---|---|---|---|
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bott... | a=list(map(int,input().split()))
x1,y1,x2,y2=a[0],a[1],a[2],a[3]
a=list(map(int,input().split()))
x3,y3,x4,y4=a[0],a[1],a[2],a[3]
a=list(map(int,input().split()))
x5,y5,x6,y6=a[0],a[1],a[2],a[3]
l1=l2=l3=l4=1
if (x1>=x5 and x2<=x6 and y1>=y5 and y1<=y6) or (x1>=x3 and x2<=x4 and y1>=y3 and y1<=y4) or (y1>=y5 and y1<=y6... | python | code_algorithm | [
{
"input": "0 0 1000000 1000000\n0 0 499999 1000000\n500000 0 1000000 1000000\n",
"output": "YES\n"
},
{
"input": "3 3 7 5\n0 0 4 6\n0 0 7 4\n",
"output": "YES\n"
},
{
"input": "5 2 10 5\n3 1 7 6\n8 1 11 7\n",
"output": "YES\n"
},
{
"input": "2 2 4 4\n1 1 3 5\n3 1 5 5\n",
... | code_contests | python | 0 | 312295fa6a23b17e89e925071b7266dd |
We just discovered a new data structure in our research group: a suffix three!
It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.
It's super simple, 100% accurate, and doesn't involve advanced machine learni... | n = int(input())
for _ in range(n):
s = input().split("_")[-1:][0]
if s[-2:] == "po":
print("FILIPINO")
elif s[-4:] == "desu" or s[-4:] == "masu":
print("JAPANESE")
else:
print("KOREAN") | python | code_algorithm | [
{
"input": "8\nkamusta_po\ngenki_desu\nohayou_gozaimasu\nannyeong_hashimnida\nhajime_no_ippo\nbensamu_no_sentou_houhou_ga_okama_kenpo\nang_halaman_doon_ay_sarisari_singkamasu\nsi_roy_mustang_ay_namamasu\n",
"output": "FILIPINO\nJAPANESE\nJAPANESE\nKOREAN\nFILIPINO\nFILIPINO\nJAPANESE\nJAPANESE\n"
},
{
... | code_contests | python | 1 | 5c9dc0db042a661278e20b388a24c79d |
Fibonacci strings are defined as follows:
* f1 = «a»
* f2 = «b»
* fn = fn - 1 fn - 2, n > 2
Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".
You are given a Fibonacci string and m strings si. For each string si, find the number of times it occurs in the given Fibonacci string as... | F = ['', 'a', 'b', 'ba', 'bab', 'babba', 'babbabab', 'babbababbabba', 'babbababbabbababbabab', 'babbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabba... | python | code_algorithm | [
{
"input": "6 5\na\nb\nab\nba\naba\n",
"output": "3\n5\n3\n3\n1\n"
},
{
"input": "2 14\na\nb\naa\nab\nba\nbb\naaa\naab\naba\nabb\nbaa\nbab\nbba\nbbb\n",
"output": "0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"
},
{
"input": "1 10\nb\na\nb\na\nb\na\nb\na\nb\na\n",
"output": "0\n1\n0\n1\... | code_contests | python | 0 | 7af590908b9cbdb72cb0a94bdf32e733 |
A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|).
You've got two strings — s and t. Let's consider all subsequences of string s, coinciding with string t. Is it true that each character of string s occurs in at... | import bisect
import string
s = input()
t = input()
max_match = [0 for i in range(len(s))]
min_match = [0 for i in range(len(s))]
char_idx = [0 for i in range(30)]
char_occur = [ [] for i in range(30) ]
for (i, ch) in enumerate(t):
idx = ord(ch) - ord('a')
char_occur[idx].append(i)
for ch in string.ascii_lo... | python | code_algorithm | [
{
"input": "abc\nba\n",
"output": "No\n"
},
{
"input": "abacaba\naba\n",
"output": "No\n"
},
{
"input": "abab\nab\n",
"output": "Yes\n"
},
{
"input": "abcdadbcd\nabcd\n",
"output": "Yes\n"
},
{
"input": "cctckkhatkgrhktihcgififfgfctctkrgiakrifazzggfzczfkkahhafhcfg... | code_contests | python | 0 | cd845608c82c5e4f5670a6f1c36974ce |
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | def solve(n,d):
other = 0
for i in d:
other += i
ways = 0
for i in range(1,6):
if (other + i) % (n + 1) != 1:
ways += 1
print(ways)
def main():
n = int(input())
d = input()
d = [int(i) for i in d.split()]
solve(n,d)
main() | python | code_algorithm | [
{
"input": "1\n2\n",
"output": "2\n"
},
{
"input": "2\n3 5\n",
"output": "3\n"
},
{
"input": "1\n1\n",
"output": "3\n"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1\n",
"output": "5\n"
},
{
"in... | code_contests | python | 0.4 | 699adc9dafe14d7a15538395a79c085d |
As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member o... | s = input()
res = pow(2, len(s)-1)*(int(s, 2))
print (res%1000000007) | python | code_algorithm | [
{
"input": "1\n",
"output": "1\n"
},
{
"input": "01\n",
"output": "2\n"
},
{
"input": "11\n",
"output": "6\n"
},
{
"input": "0111001111110010000001111100110100111110001100100001111111110000010010111010010010010111000110001111\n",
"output": "777947548\n"
},
{
"inpu... | code_contests | python | 0.1 | 3f2777b17bc923331bf3f5c4088e0a7a |
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will co... | I = lambda : list(map(int, input().split(' ')))
a, b = I()
ans = 0
while a > 0 and b > 0 and a//b > 0 or b//a > 0:
ans += a//b
a, b = b, a%b
print(ans) | python | code_algorithm | [
{
"input": "3 2\n",
"output": "3\n"
},
{
"input": "1 1\n",
"output": "1\n"
},
{
"input": "199 200\n",
"output": "200\n"
},
{
"input": "4052739537881 6557470319842\n",
"output": "62\n"
},
{
"input": "1 923438\n",
"output": "923438\n"
},
{
"input": "1 2\... | code_contests | python | 0.5 | 32545d0679c6069822078564ae51224b |
Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.
Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit sala... | from bisect import bisect_right
n, k = map(int, input().split())
t = sorted((u - k * v, v) for u, v in zip(*(map(int, input().split()), map(int, input().split()))))
m = n - bisect_right(t, (0, 0))
l, p, t = 0, [0] * 100001, t[:: -1]
for d, v in t[: m]:
for j in range(l, 0, -1):
if p[j]: p[j + d] = max(p[j +... | python | code_algorithm | [
{
"input": "5 3\n4 4 4 4 4\n2 2 2 2 2\n",
"output": "-1\n"
},
{
"input": "3 2\n10 8 1\n2 7 1\n",
"output": "18\n"
},
{
"input": "1 1\n1\n2\n",
"output": "-1\n"
},
{
"input": "19 2\n68 24 95 24 94 82 37 87 68 67 59 28 68 5 70 53 80 46 61\n60 74 46 9 40 45 58 51 96 4 42 33 12 4... | code_contests | python | 0.1 | b78bf918590abe9aa17b8ecab1a3f62d |
Two chess pieces, a rook and a knight, stand on a standard chessboard 8 × 8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.
Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board bea... |
l=[]
for i in range(1,9):
for j in range(1,9):
l.append(int(str(i)+str(j)))
l2=[]
def check(l2,c,d):
if c+1<=8 and d+2<=8:
l2.append(int(str(c+1)+str(d+2)))
if c+2<9 and d+1<9:
l2.append(int(str(c+2)+str(d+1)))
if c-1>0 and d-2>0:
l2.append(int(str(c-1)+str(d-2)))
i... | python | code_algorithm | [
{
"input": "a1\nb2\n",
"output": "44\n"
},
{
"input": "a8\nd4\n",
"output": "38\n"
},
{
"input": "c1\nd2\n",
"output": "42\n"
},
{
"input": "g1\ne6\n",
"output": "39\n"
},
{
"input": "h8\ng2\n",
"output": "43\n"
},
{
"input": "a8\nf1\n",
"output": ... | code_contests | python | 0 | 394a1dc0cbd3602fa1a2799e3376b500 |
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond... | # _
#####################################################################################################################
from math import sqrt, ceil
def colorOfDamagedArea(x, y):
location = sqrt(x*x+y*y)
area_sBorder = ceil(location)
if location == area_sBorder:
return 'black'
area_sAddress... | python | code_algorithm | [
{
"input": "-2 1\n",
"output": "white\n"
},
{
"input": "4 3\n",
"output": "black\n"
},
{
"input": "2 1\n",
"output": "black\n"
},
{
"input": "-12 -35\n",
"output": "black\n"
},
{
"input": "-215 -996\n",
"output": "black\n"
},
{
"input": "-96 -556\n",
... | code_contests | python | 0 | 8b049b4dee9f23fbe804023088b38846 |
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students don’t want to use too many blocks, but they also want to be uniq... | n, m = map(int, input().split())
x = max(n*2, m*3)
while x//2+x//3-x//6 < m+n:
x += 1
print(x) | python | code_algorithm | [
{
"input": "3 2\n",
"output": "8\n"
},
{
"input": "5 0\n",
"output": "10\n"
},
{
"input": "1 3\n",
"output": "9\n"
},
{
"input": "4 2\n",
"output": "9\n"
},
{
"input": "984327 24352\n",
"output": "1968654\n"
},
{
"input": "918273 219\n",
"output": ... | code_contests | python | 0 | 6b3b810920614438665d0486235b12d3 |
Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time,... | a,b=map(int,input().split())
if(a==b):
print('Equal')
exit()
import math
lcm=(a*b)//(math.gcd(a,b))
if(a<b):
da=(lcm//a)-1
ma=lcm//b
if(da>ma):
print('Dasha')
elif(da<ma):
print('Masha')
else:
print('Equal')
else:
da=(lcm//a)
ma=(lcm//b)-1
if(da>ma):
... | python | code_algorithm | [
{
"input": "2 3\n",
"output": "Equal\n"
},
{
"input": "3 7\n",
"output": "Dasha\n"
},
{
"input": "5 3\n",
"output": "Masha\n"
},
{
"input": "999983 999979\n",
"output": "Masha\n"
},
{
"input": "419 430\n",
"output": "Dasha\n"
},
{
"input": "51291 51292... | code_contests | python | 0 | 08549fe0926cb6d306eb9c430e99d931 |
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.
Mishka can put a box i into another box j if the following conditions are met:
* i-th box is not put into another box;
* j-th box doesn't contain any other boxes;
* box i is smaller than box j (ai < aj).
Mishka ... | from sys import stdin,stdout
from collections import Counter
def ai(): return list(map(int, stdin.readline().split()))
def ei(): return map(int, stdin.readline().split())
def ip(): return int(stdin.readline().strip())
def op(ans): return stdout.write(str(ans) + '\n')
t = ip()
li = ai()
x = max(li)
c = Counter(li).val... | python | code_algorithm | [
{
"input": "3\n1 2 3\n",
"output": "1\n"
},
{
"input": "4\n4 2 4 3\n",
"output": "2\n"
},
{
"input": "10\n58 58 58 58 58 58 58 58 58 58\n",
"output": "10\n"
},
{
"input": "8\n1 2 3 4 5 6 7 8\n",
"output": "1\n"
},
{
"input": "1\n2\n",
"output": "1\n"
},
{
... | code_contests | python | 0.1 | f58ce7582a2a67d55225890c5fd623e2 |
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terribl... | n,h=map(int,input().split())
L=[]
for i in range(n+1):
g=[]
for j in range(n+1):
g.append(0)
L.append(g)
L[0][0]=1
for i in range(1,n+1):
for j in range(1,n+1):
sumu=0
for m in range(1,i+1):
t1=L[m-1][j-1]
tot=0
for k in range(0,j):
... | python | code_algorithm | [
{
"input": "3 2\n",
"output": "5\n"
},
{
"input": "3 3\n",
"output": "4\n"
},
{
"input": "21 12\n",
"output": "12153990144\n"
},
{
"input": "23 21\n",
"output": "275251200\n"
},
{
"input": "16 5\n",
"output": "35357670\n"
},
{
"input": "14 11\n",
"... | code_contests | python | 0 | 3eb725abe3f12899c65c8338be38076e |
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | s=input()
a=['a','e','i','o','u']
c=0
for i in range(len(s)):
if(i==len(s)-1):
if s[i] in a or s[i]=='n':
c+=1
continue
elif s[i] in a:
c+=1
continue
elif(s[i]=='n'):
c+=1
continue
else:
if s[i+1] in a:
c+=... | python | code_algorithm | [
{
"input": "codeforces\n",
"output": "NO\n"
},
{
"input": "ninja\n",
"output": "YES\n"
},
{
"input": "sumimasen\n",
"output": "YES\n"
},
{
"input": "s\n",
"output": "NO\n"
},
{
"input": "d\n",
"output": "NO\n"
},
{
"input": "anujemogawautiedoneobninnib... | code_contests | python | 0.6 | ae5e24b0d333d0dd193c6d376ff14483 |
Two integer sequences existed initially — one of them was strictly increasing, and the other one — strictly decreasing.
Strictly increasing sequence is a sequence of integers [x_1 < x_2 < ... < x_k]. And strictly decreasing sequence is a sequence of integers [y_1 > y_2 > ... > y_l]. Note that the empty sequence and th... | n = int(input())
a = [int(s) for s in input().split()]
d = dict()
for i in a:
x = d.get(i,0)
if x == 0:
d[i] = 1
else:
d[i] += 1
up = []
down = []
for i in d.keys():
k = d[i]
if k == 1:
up.append(i)
elif k == 2:
up.append(i)
down.append(i)
else:
... | python | code_algorithm | [
{
"input": "5\n4 3 1 5 3\n",
"output": "YES\n4\n1 3 4 5\n1\n3\n"
},
{
"input": "5\n0 1 2 3 4\n",
"output": "YES\n5\n0 1 2 3 4\n0\n\n"
},
{
"input": "7\n7 2 7 3 3 1 4\n",
"output": "YES\n5\n1 2 3 4 7\n2\n7 3\n"
},
{
"input": "5\n1 1 2 1 2\n",
"output": "NO\n"
},
{
... | code_contests | python | 0.2 | 7c1bb63fb62623f261870bfb728e3748 |
Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 1 problem, during the second day — exactly 2 problems, during the third day — exactly 3 problems, and so on. During the k-th day he should solve k problems.
Polycarp has a list of n contests, th... | a = int(input())
b = [int(x) for x in input().split()]
b.sort()
s = 1
q = 0
for i in b:
if i >= s:
s += 1
q += 1
print(q) | python | code_algorithm | [
{
"input": "4\n3 1 4 1\n",
"output": "3\n"
},
{
"input": "5\n1 1 1 2 2\n",
"output": "2\n"
},
{
"input": "3\n1 1 1\n",
"output": "1\n"
},
{
"input": "5\n200000 200000 200000 200000 200000\n",
"output": "5\n"
},
{
"input": "3\n5 6 7\n",
"output": "3\n"
},
{... | code_contests | python | 0.6 | f89d7738e9396aef7ca85d335fb29209 |
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
* \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.
* lcm(s) is the minimum positive integer x, that divisible on all integ... | from collections import Counter
from math import floor, sqrt
try:
long
except NameError:
long = int
def fac(n):
step = lambda x: 1 + (x<<2) - ((x>>1)<<1)
maxq = long(floor(sqrt(n)))
d = 1
q = 2 if n % 2 == 0 else 3
while q <= maxq and n % q != 0:
q = step(d)
d += 1
... | python | code_algorithm | [
{
"input": "2\n1 1\n",
"output": "1\n"
},
{
"input": "10\n540 648 810 648 720 540 594 864 972 648\n",
"output": "54\n"
},
{
"input": "4\n10 24 40 80\n",
"output": "40\n"
},
{
"input": "2\n10007 20014\n",
"output": "20014\n"
},
{
"input": "2\n199999 200000\n",
... | code_contests | python | 0 | d0a118166568a342fb83b7ae497c8688 |
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.
All the terms above have their... |
def f( l, a):
i, count = 0,0
for x in l:
count += x not in a[i]
#print( x, a[i], count )
i = (i+1) %2
return count
def g( l, mx ):
return min( [ f(l,mx[i]) for i in range(len(mx)) ] )
def two():
l = [ x[0]+x[1] for x in zip(input(),input())]
mx = (
[['... | python | code_algorithm | [
{
"input": "3 3\n101\n001\n110\n",
"output": "2\n"
},
{
"input": "7 15\n000100001010010\n100111010110001\n101101111100100\n010000111111010\n111010010100001\n000011001111101\n111111011010011\n",
"output": "-1\n"
},
{
"input": "2 58\n11000011100100101000010000000001101100011010011000101011... | code_contests | python | 0 | 4499d491d24ab1b9b862ebe56c16375d |
Polycarpus analyzes a string called abracadabra. This string is constructed using the following algorithm:
* On the first step the string consists of a single character "a".
* On the k-th step Polycarpus concatenates two copies of the string obtained on the (k - 1)-th step, while inserting the k-th character of ... | def solve(x,l1,r1,l2,r2):
if x==0:return 1
if l1>x:
l1-=x+1
r1-=x+1
if l2>x:
l2-=x+1
r2-=x+1
ans=max(0,min(r1,r2)-max(l1,l2)+1)
if l1<=x and x<=r1 and l2<=x and x<=r2:
if l1==0 or r1==x*2:
ans=max(ans,max(x-l2,r2-x))
elif l2==0 or r2==x*2:
ans=max(ans,max(x-l1,r1-x))
else:
if l1<=x-1 and r2>... | python | code_algorithm | [
{
"input": "3 6 1 4\n",
"output": "2\n"
},
{
"input": "1 1 4 4\n",
"output": "0\n"
},
{
"input": "4 7 12 15\n",
"output": "4\n"
},
{
"input": "1 463129088 536870913 1000000000\n",
"output": "463129088\n"
},
{
"input": "1 4 4 7\n",
"output": "3\n"
},
{
... | code_contests | python | 0 | d6de925fbfa20dccc22ae8224793118d |
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be inclu... | def F (x) :
if (x < 10) :
return x
rv = 9
tmp = x
len = 0
while (tmp > 0) :
len += 1
tmp = tmp // 10
d = int (x // pow(10, len-1))
tmp = 1
for i in range(len - 2) :
rv += 9 * tmp
tmp *= 10
for i in range (1, 10) :
if (i < d) :
... | python | code_algorithm | [
{
"input": "47 1024\n",
"output": "98\n"
},
{
"input": "2 47\n",
"output": "12\n"
},
{
"input": "645762257531682046 885295120956158518\n",
"output": "23953286342447648\n"
},
{
"input": "1 11\n",
"output": "10\n"
},
{
"input": "47 8545\n",
"output": "849\n"
}... | code_contests | python | 0 | d128888ab068e32830d19f7b306eca42 |
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.
Note that the order of the points inside the group of three chosen point... | n,d=map(int,input().split())
nums=list(map(int,input().split()))
count=0
j=0
for i in range(n):
while j<n and nums[j]-nums[i]<=d:
j+=1
temp_length=(j-i-1)
count+=int((temp_length*(temp_length-1))/2)
print(count)
| python | code_algorithm | [
{
"input": "4 3\n1 2 3 4\n",
"output": "4\n"
},
{
"input": "4 2\n-3 -2 -1 0\n",
"output": "2\n"
},
{
"input": "5 19\n1 10 20 30 50\n",
"output": "1\n"
},
{
"input": "2 1000000000\n-14348867 1760823\n",
"output": "0\n"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 7... | code_contests | python | 0.9 | fbf9eadad933d5a6c135c8c62620838d |
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | n = int(input())
d = {}
l = []
for _ in range(n):
name, score = input().split()
score = int(score)
l.append((name,score))
d[name] = d.get(name, 0) + score
m = max([x for x in d.values()])
ties = [x for x,y in d.items() if y == m]
# print(ties)
if len(ties) == 1:
print(ties[0])
exit()
el... | python | code_algorithm | [
{
"input": "3\nandrew 3\nandrew 2\nmike 5\n",
"output": "andrew\n"
},
{
"input": "3\nmike 3\nandrew 5\nmike 2\n",
"output": "andrew\n"
},
{
"input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfn... | code_contests | python | 0.1 | 7607b599a8fc5a72a57e1b333e32a21c |
You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle).
Your task is to determine if the rectan... | xmin, ymin, xmax, ymax, a = 31400, 31400, 0, 0, 0
for i in range(int(input())):
x1, y1, x2, y2 = map(int, input().split())
xmin = min(xmin, x1)
ymin = min(ymin, y1)
xmax = max(xmax, x2)
ymax = max(ymax, y2)
a += (x2 - x1) * (y2 - y1)
print('YES' if xmax - xmin == ymax - ymin and a == (xmax - xmi... | python | code_algorithm | [
{
"input": "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3\n",
"output": "YES\n"
},
{
"input": "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n",
"output": "NO\n"
},
{
"input": "3\n25784 0 31400 20408\n0 20408 31400 20582\n15802 0 18106 20408\n",
"output": "NO\n"
},
{
"input": "2\n1 ... | code_contests | python | 0.4 | 58882983af67ad0b52d05aeeb11f6a3e |
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (... | st = input()
B = st.count('B')
S = st.count('S')
C = st.count('C')
b,s,c=map(int,input().split())
bp, sp, cp = map(int,input().split())
r=int(input())
lm=0; rm=int(1e15)+1
while rm-lm>1:
m=(rm+lm)//2
# print(m)
bb=max(m*B-b,0)
ss=max(m*S-s,0)
cc=max(m*C-c, 0)
#print(bp*bb+ss*sp+cc*cp)
if bp*b... | python | code_algorithm | [
{
"input": "BBC\n1 10 1\n1 10 1\n21\n",
"output": "7\n"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000\n",
"output": "200000000001\n"
},
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4\n",
"output": "2\n"
},
{
"input": "B\n100 100 100\n1 1 1\n1\n",
"output": "101\n"
},
{
"in... | code_contests | python | 0 | 124278b5440b034a25570877ff3ad8de |
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi... | N = int(1e6+100)
n = int(input())
arr = list(map(int, input().split()))
cnt = [0] * N
for i in arr:
cnt[i] += 1
res, s = 0, 0
for i in range(N):
s += cnt[i]
res += s % 2
s //= 2
print(res)
| python | code_algorithm | [
{
"input": "5\n1 1 2 3 3\n",
"output": "2\n"
},
{
"input": "4\n0 1 2 3\n",
"output": "4\n"
},
{
"input": "2\n95745 95745\n",
"output": "1\n"
},
{
"input": "100\n196 1681 196 0 61 93 196 196 196 196 196 0 0 96 18 1576 0 93 666463 18 93 1 1278 8939 93 196 196 1278 3 0 67416 869... | code_contests | python | 0.1 | 91916225290388c310f56a118427d7b1 |
In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the i-th server.
In order to balance the load for each server, you want to reassign some tasks to make the difference betw... | input()
servers = [int(x) for x in input().split(" ", )]
servers.sort()
avg = int(sum(servers) / len(servers))
extra = sum(servers) % len(servers)
count = 0
for i in range(len(servers)):
count += abs(avg + (i >= (len(servers) - extra)) - servers[i]) / 2
print(int(count))
| python | code_algorithm | [
{
"input": "2\n1 6\n",
"output": "2\n"
},
{
"input": "7\n10 11 10 11 10 11 11\n",
"output": "0\n"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "3\n"
},
{
"input": "2\n10 3\n",
"output": "3\n"
},
{
"input": "5\n2 10 20 30 50\n",
"output": "34\n"
},
{
"inpu... | code_contests | python | 0 | 5b62ca3e0143a507fdb7a45a598f0b91 |
Input
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output
Output a single integer.
Examples
Input
A221033
Output
21
Input
A223635
Output
22
Input
A232726
Outpu... | s = input()
ans = 1
for i in s[1:]:
x = int(i)
if x == 0:
x = 9
ans += x
print(ans)
| python | code_algorithm | [
{
"input": "A232726\n",
"output": "23\n"
},
{
"input": "A223635\n",
"output": "22\n"
},
{
"input": "A221033\n",
"output": "21\n"
},
{
"input": "A222222\n",
"output": "13\n"
},
{
"input": "A101010\n",
"output": "31\n"
},
{
"input": "A999999\n",
"out... | code_contests | python | 0 | 6ce520a322c0c64898217a900192b449 |
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards wi... | l=list(map(int,input().split()))
ma=0
for i in l :
k=0
for j in l :
if i==j :
k=k+1
if k>2 :
break
if k>1 :
if ma<k*i :
ma=k*i
print(sum(l)-ma)
| python | code_algorithm | [
{
"input": "7 9 3 1 8\n",
"output": "28\n"
},
{
"input": "7 3 7 3 20\n",
"output": "26\n"
},
{
"input": "10 10 10 10 10\n",
"output": "20\n"
},
{
"input": "1 2 2 2 2\n",
"output": "3\n"
},
{
"input": "20 21 22 23 24\n",
"output": "110\n"
},
{
"input": ... | code_contests | python | 0.6 | cf2eaa3d4547cba677e7f7f5052aeb91 |
One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in ... | def pr(x):
d = 2
while d * d <= x:
if x % d == 0:
return 0
d += 1
return 1
def cnt(n, k):
if not pr(k) or n < k: return 0
n1 = n // k
return n1 - sum(cnt(n1, i) for i in range(2, min(k, n1 + 1)))
a, b, k = map(int, input().split())
ans = cnt(b, k) - cnt(a - 1, k... | python | code_algorithm | [
{
"input": "12 23 3\n",
"output": "2\n"
},
{
"input": "1 10 2\n",
"output": "5\n"
},
{
"input": "6 19 5\n",
"output": "0\n"
},
{
"input": "1 2000000000 10007\n",
"output": "16746\n"
},
{
"input": "19431 20000000 17\n",
"output": "225438\n"
},
{
"input"... | code_contests | python | 0 | cf1fc032cdaa29e89108c14162261c42 |
You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp.
Initially all m lamps are t... | def main():
n,m=map(int,input().split())
counts=[0]*m
a=[None]*n
for i in range(n):
line=input()
a[i]=line
for j in range(m):
counts[j]+=1 if line[j]=='1' else 0
if 1 not in counts:
print('YES')
return
checks=[]
for i in range(m):
if counts[i]==1:
checks.append(i)
leng=len(checks)
for i in r... | python | code_algorithm | [
{
"input": "4 5\n10100\n01000\n00110\n00101\n",
"output": "NO\n"
},
{
"input": "4 5\n10101\n01000\n00111\n10000\n",
"output": "YES\n"
},
{
"input": "3 5\n11100\n00110\n00011\n",
"output": "YES\n"
},
{
"input": "3 4\n1010\n0100\n1101\n",
"output": "YES\n"
},
{
"inp... | code_contests | python | 0.7 | 2abb124d791b68514ac99e949d37728b |
You have n coins, each of the same value of 1.
Distribute them into packets such that any amount x (1 ≤ x ≤ n) can be formed using some (possibly one or all) number of these packets.
Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single x, howeve... | import math
n, = map(int, input().split())
print(math.floor(math.log2(n)) + 1) | python | code_algorithm | [
{
"input": "6\n",
"output": "3\n"
},
{
"input": "2\n",
"output": "2\n"
},
{
"input": "723061816\n",
"output": "30\n"
},
{
"input": "40052789\n",
"output": "26\n"
},
{
"input": "8\n",
"output": "4\n"
},
{
"input": "1\n",
"output": "1\n"
},
{
... | code_contests | python | 1 | c22aabb06777ad5f197b954fa258521d |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are n bricks lined in a row on the ground. Chouti has got m paint buckets of different colors at hand, so he painted each brick in one of those m colors.
Having finished painting all bricks, Chouti was s... | from math import factorial
[n, m, k] = [int(i) for i in input().split()]
mod = 998244353
l = m*((m-1)**k)
L = factorial(n-1)//factorial(n-1-k)//factorial(k)
print((l*L)%mod)
| python | code_algorithm | [
{
"input": "3 3 0\n",
"output": "3\n"
},
{
"input": "3 2 1\n",
"output": "4\n"
},
{
"input": "1859 96 1471\n",
"output": "33410781\n"
},
{
"input": "555 1594 412\n",
"output": "438918750\n"
},
{
"input": "1987 237 1286\n",
"output": "609458581\n"
},
{
... | code_contests | python | 0 | bc02c6dbc50be1c295d80c95420a4325 |
Let's define a number ebne (even but not even) if and only if its sum of digits is divisible by 2 but the number itself is not divisible by 2. For example, 13, 1227, 185217 are ebne numbers, while 12, 2, 177013, 265918 are not. If you're still unsure what ebne numbers are, you can look at the sample notes for more clar... | for _ in range(int(input())):
n=int(input())
s=input()
if len(s)==1:
print(-1)
else:
#ans=s[0]
ans=''
f=0
for i in range(0,n):
if int(s[i])%2==1 and f<2:
ans+=s[i]
f+=1
#break
if f<2:
... | python | code_algorithm | [
{
"input": "4\n4\n1227\n1\n0\n6\n177013\n24\n222373204424185217171912\n",
"output": "17\n-1\n17\n37\n"
},
{
"input": "36\n6\n165310\n6\n177978\n6\n211759\n6\n212643\n6\n229540\n6\n250029\n6\n211519\n6\n256097\n6\n163478\n5\n91505\n5\n79280\n6\n260629\n6\n128051\n6\n121972\n6\n261633\n6\n172044\n6\n1... | code_contests | python | 0 | aab6a3c70091367cd6693a5ff060b07c |
You are given three integers x, y and n. Your task is to find the maximum integer k such that 0 ≤ k ≤ n that k mod x = y, where mod is modulo operation. Many programming languages use percent operator % to implement it.
In other words, with given x, y and n you need to find the maximum possible integer from 0 to n tha... | t=int(input())
for i in range(t):
x, y, n=map(int,input().split())
print(n-(n-y)%x) | python | code_algorithm | [
{
"input": "7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999\n",
"output": "12339\n0\n15\n54306\n999999995\n185\n999999998\n"
},
{
"input": "1\n31 2 104\n",
"output": "95\n"
},
{
"input": "1\n43284 1 33424242\n",
"output": "33415249\n"
},
... | code_contests | python | 0.9 | e16a294c9724a4cdff4d2863ab9a8094 |
Let's call a list of positive integers a_0, a_1, ..., a_{n-1} a power sequence if there is a positive integer c, so that for every 0 ≤ i ≤ n-1 then a_i = c^i.
Given a list of n positive integers a_0, a_1, ..., a_{n-1}, you are allowed to:
* Reorder the list (i.e. pick a permutation p of \{0,1,...,n - 1\} and change... | import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 10 ** 9 + 7
def gcd(a, b):
while b:
a, b = b, a%b
return a
def isPrime(n):
if (n <= 1):
return False
i = 2
while i ** 2 <= n:
if n % i == 0:
return False
i += 1
return True
def primeFactors(n):
facto... | python | code_algorithm | [
{
"input": "3\n1 3 2\n",
"output": "1\n"
},
{
"input": "3\n1000000000 1000000000 1000000000\n",
"output": "1999982505\n"
},
{
"input": "3\n377 9052790 230\n",
"output": "4152\n"
},
{
"input": "5\n1 1 912380429 929219321 1000000000\n",
"output": "1839804347\n"
},
{
... | code_contests | python | 0.2 | 261bb81e96626dd8a742ad21523a17a8 |
There are n cities numbered from 1 to n in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the shortest distance betw... | n = int(input())
mat = []
for _ in range(n):
mat.append(list(map(int, input().split())))
q = int(input())
ans= []
for _ in range(q):
x, y, w = map(int, input().split())
x-=1
y-=1
mat[x][y] = mat[y][x] = min(mat[x][y], w)
sum1 = 0
for i in range(n):
for j in range(n):
a = ... | python | code_algorithm | [
{
"input": "2\n0 5\n5 0\n1\n1 2 3\n",
"output": "3\n"
},
{
"input": "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n",
"output": "17 12\n"
},
{
"input": "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763\n",
"output": "1480 1480 1480\n"
},
{
"input": "5\n0 954 1255 2... | code_contests | python | 1 | f010ca4e45ee74d640722b337803d9fb |
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He us... | import sys
n,L,r,QL,QR=map(int,sys.stdin.readline().split())
W=list(map(int,sys.stdin.readline().split()))
minn=10**10
SumsL=[0]*n
SumsR=[0]*n
s=0
for i in range(n):
s+=W[i]
SumsL[i]=s
for i in range(n-1):
ans=L*SumsL[i]+r*(s-SumsL[i])
if(n-(i+1)>i+1):
ans+=(abs(n-(i+1)-(i+1))-1)*QR
... | python | code_algorithm | [
{
"input": "3 4 4 19 1\n42 3 99\n",
"output": "576\n"
},
{
"input": "4 7 2 3 9\n1 2 3 4\n",
"output": "34\n"
},
{
"input": "2 3 4 5 6\n1 2\n",
"output": "11\n"
},
{
"input": "5 1 100 10000 1\n1 2 3 4 5\n",
"output": "906\n"
},
{
"input": "2 100 100 10000 10000\n10... | code_contests | python | 0 | 51633be30bf8a0fff9cade921379b4c0 |
Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0 ≤ 2k ≤ n) who showed the best result in their semifinals and all other places in the finals go to the peopl... | n = int(input())
sem1 = []
sem2 = []
l = [0,0]
for cont in range(0,n):
l = list(map(int, input().split()))
sem1.append(l[0])
sem2.append(l[1])
kmax = int(n/2)
max1 = 0
max2 = 0
for cont in range(0,n):
if sem1[max1] < sem2[max2]:
max1 += 1
else:
max2 += 1
ris1 = ['1']*(max([max1,km... | python | code_algorithm | [
{
"input": "4\n9840 9920\n9860 9980\n9930 10020\n10040 10090\n",
"output": "1110\n1100\n"
},
{
"input": "4\n9900 9850\n9940 9930\n10000 10020\n10060 10110\n",
"output": "1100\n1100\n"
},
{
"input": "3\n1 3\n2 4\n6 5\n",
"output": "110\n100\n"
},
{
"input": "3\n1 3\n2 5\n4 6\n... | code_contests | python | 0.3 | 077a60346d3bce71182b4f5c4ef4d977 |
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0, 0, 0) and (1, 1, 1). Two flies live on the planet. At the moment ... | #دو تا نقطه تو مختصات سه بعدی میده میگه اینا تو یک وجه از مکعل هستند یا نه
print('YES' if any(i == j for i,j in zip(list(input().split()) ,list(input().split()))) else 'NO') | python | code_algorithm | [
{
"input": "0 0 0\n1 1 1\n",
"output": "NO\n"
},
{
"input": "0 0 0\n0 1 0\n",
"output": "YES\n"
},
{
"input": "1 1 0\n0 1 0\n",
"output": "YES\n"
},
{
"input": "1 0 0\n0 0 0\n",
"output": "YES\n"
},
{
"input": "1 1 0\n0 0 1\n",
"output": "NO\n"
},
{
"i... | code_contests | python | 0.5 | 21be1975c4ece48ed1048b985fde2581 |
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a0 + a1x1 + ... + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial.
Vasya has made a bet with his friends that h... | t,a,b=map(int,input().split())
if t==2 and a==3 and b>10000: res=0
elif a==t: res=('inf' if a==1 else 2) if a==b else 0
else: res=0 if (a-b)%(t-a) else (1 if t != b else 0)
print(res)
| python | code_algorithm | [
{
"input": "2 3 3\n",
"output": "1\n"
},
{
"input": "2 2 2\n",
"output": "2\n"
},
{
"input": "1 2 5\n",
"output": "1\n"
},
{
"input": "1000000000000000000 1000000000000000000 1000000000000000000\n",
"output": "2\n"
},
{
"input": "135645 1 365333453\n",
"output... | code_contests | python | 0 | ac6439212f8a6682c85982dbed3d816d |
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any ... | from itertools import combinations_with_replacement
from collections import deque
#sys.stdin = open("input_py.txt","r")
n, m = map(int, input().split())
G = [ [] for i in range(n)]
for i in range(m):
x, y = map(int, input().split())
x-=1; y-=1
G[x].append(y)
G[y].append(x)
def BFS(s):
dist = [-... | python | code_algorithm | [
{
"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 1\n",
"output": "-1\n"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2\n",
"output": "0\n"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2\n",
"output": "1\n"
},
{
"input": "2 1\n1 2\n1 1 0\n1 2 0\n",
"output": "-1... | code_contests | python | 0 | 8fb52aec285c2f45c1450b7a9fe86220 |
You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most l centimeters. In particular, it is allowed not to increase the l... | def f(a, b, c, l):
k = min(l, a - b - c)
return 0 if a < b + c else (k + 1) * (k + 2) // 2
solve = lambda i: f(a + i, b, c, l - i) + f(b + i, c, a, l - i) + f(c + i, a, b, l - i)
a, b, c, l = map(int, input().split())
ans = (l + 1) * (l + 2) * (l + 3) // 6 - sum(solve(i) for i in range(l + 1))
print(ans) | python | code_algorithm | [
{
"input": "1 1 1 2\n",
"output": "4\n"
},
{
"input": "1 2 3 1\n",
"output": "2\n"
},
{
"input": "10 2 1 7\n",
"output": "0\n"
},
{
"input": "53553 262850 271957 182759\n",
"output": "834977070873802\n"
},
{
"input": "5276 8562 1074 8453\n",
"output": "4909326... | code_contests | python | 0 | 4d9787137d429e35b65b6311fc95099e |
Well, the series which Stepan watched for a very long time, ended. In total, the series had n episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not.
Stepan's dissatisfaction is the maximum num... | def process(S, k):
n = len(S)
if k > n:
return 'NO'
current = 0
for i in range(n):
if S[i]=='N':
current+=1
if current > k:
return 'NO'
else:
current = 0
start_work = True
for i in range(k):
if S[i]=='Y':
... | python | code_algorithm | [
{
"input": "6 1\n????NN\n",
"output": "NO\n"
},
{
"input": "5 2\nNYNNY\n",
"output": "YES\n"
},
{
"input": "100 1\nYYYYYYYYY??YYN?YYNYYYYYYYNYYYYYYYYYYY?YN?YYYYY?YYYYYYYYYYYYY?YYYYYYYYYYYYN?YYYYYYYY?YYYYY?YYNYYYYYNY\n",
"output": "YES\n"
},
{
"input": "100 3\n?YNNYYNYYYYYYNYY... | code_contests | python | 0 | 3ecc96e75eee7a70cd239f72f1cff7b2 |
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero)... | def main():
n = int(input())
games = list(map(int, input().split(' ')))
result = max([games[:i].count(0) + games[i:].count(1) for i in range(n+1)])
print(result)
if __name__ == "__main__":
main()
| python | code_algorithm | [
{
"input": "6\n0 1 0 0 1 0\n",
"output": "4\n"
},
{
"input": "1\n0\n",
"output": "1\n"
},
{
"input": "4\n1 1 0 1\n",
"output": "3\n"
},
{
"input": "4\n1 0 0 1\n",
"output": "3\n"
},
{
"input": "100\n1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 1... | code_contests | python | 0.2 | a832c0484a251c910eace4ef7f1d92dd |
It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices.
It is known that the i-th contestant will eat si slices of pizza, and gain ai ... | def cns(ts,s):
if ts/s==int(ts/s):
return ts
else:
return (int(ts/s)+1)*s
n,spp=[int(i) for i in input().split()]
tsr=0
da=[[] for i in range(100005)]
db=[[] for i in range(100005)]
sl=[]
for i in range(n):
sl.append([int(j) for j in input().split()])
tsr+=sl[i][0]
if sl[i][1]>sl[i][... | python | code_algorithm | [
{
"input": "6 10\n7 4 7\n5 8 8\n12 5 8\n6 11 6\n3 3 7\n5 9 6\n",
"output": "314\n"
},
{
"input": "3 12\n3 5 7\n4 6 7\n5 9 5\n",
"output": "84\n"
},
{
"input": "25 6\n1 10 5\n1 8 4\n1 8 2\n4 8 9\n3 2 8\n1 9 5\n2 10 10\n3 9 6\n3 5 4\n2 7 8\n2 3 2\n2 6 8\n3 7 8\n4 3 7\n1 8 1\n3 6 4\n3 2 8\n... | code_contests | python | 0 | e65283b3e357216a5a54261e1220b87f |
The cities of Byteland and Berland are located on the axis Ox. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line Ox there are three types of cities:
* the cities of Byteland,
* the cities of Berland,
* disputed cities.
Recent... | def solve(length, cities):
result = 0
lastP = None
lastB = None
lastR = None
maxB = 0
maxR = 0
for idx, city in enumerate(cities):
i, code = city
if(code == 'B'):
if(lastB != None):
result += abs(i - lastB)
maxB = max(maxB, abs(i - lastB))
lastB = i
if(code == 'R'):... | python | code_algorithm | [
{
"input": "5\n10 R\n14 B\n16 B\n21 R\n32 R\n",
"output": "24\n"
},
{
"input": "4\n-5 R\n0 P\n3 P\n7 B\n",
"output": "12\n"
},
{
"input": "2\n1 R\n2 R\n",
"output": "1\n"
},
{
"input": "6\n0 B\n3 P\n7 B\n9 B\n11 P\n13 B\n",
"output": "17\n"
},
{
"input": "9\n-105 ... | code_contests | python | 0 | 966dc7be0e945c4f1a1cbe45d3250b6b |
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built n commentary boxes. m regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be... | n, m, a, b = list(map(int, input().split()))
k = n%m
print(min(k*b, (m - k)*a))
| python | code_algorithm | [
{
"input": "30 6 17 19\n",
"output": "0\n"
},
{
"input": "2 7 3 7\n",
"output": "14\n"
},
{
"input": "9 7 3 8\n",
"output": "15\n"
},
{
"input": "29 6 1 2\n",
"output": "1\n"
},
{
"input": "100000000000 3 1 1\n",
"output": "1\n"
},
{
"input": "13 4 1 1... | code_contests | python | 0.6 | b41c63d0530593de12ee41ff95142065 |
Vova plans to go to the conference by train. Initially, the train is at the point 1 and the destination point of the path is the point L. The speed of the train is 1 length unit per minute (i.e. at the first minute the train is at the point 1, at the second minute — at the point 2 and so on).
There are lanterns on the... |
if __name__ == '__main__':
t = input()
t = int(t)
while t:
e, v, l, r = input().split()
e = int(e)
v = int(v)
l = int(l)
r = int(r)
res = e//v
if l % v != 0:
st = l//v + 1
else:
st = l//v
en = r//v
print... | python | code_algorithm | [
{
"input": "4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000\n",
"output": "3\n0\n1134\n0\n"
},
{
"input": "1\n12599 3 1 2\n",
"output": "4199\n"
},
{
"input": "1\n2 5 1 1\n",
"output": "0\n"
},
{
"input": "10\n10 1 1 1\n10 1 1 2\n10 1 1 3\n10 1 1 4\n10 1 ... | code_contests | python | 1 | 53c1c6091455ccf877bcb86a920a928f |
Let's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...
Your task is to print the k-th digit of this sequence.
Input
The first and only lin... | #import sys
#digit = int(sys.argv[1])
digit = int(input())
if int(digit) <= 9:
print(digit)
exit()
start_range = 1
end_range = 9
power = 1
digit_count = 2
while not (start_range <= digit and digit <= end_range):
start_range = end_range + 1
end_range = 9 * 10**power * digit_count + start_range - 1
... | python | code_algorithm | [
{
"input": "21\n",
"output": "5\n"
},
{
"input": "7\n",
"output": "7\n"
},
{
"input": "511\n",
"output": "2\n"
},
{
"input": "2879\n",
"output": "9\n"
},
{
"input": "4\n",
"output": "4\n"
},
{
"input": "2900\n",
"output": "0\n"
},
{
"input"... | code_contests | python | 0.5 | a284c9fb345fbbe6506ae3385d123c0b |
Tanya wants to go on a journey across the cities of Berland. There are n cities situated along the main railroad line of Berland, and these cities are numbered from 1 to n.
Tanya plans her journey as follows. First of all, she will choose some city c_1 to start her journey. She will visit it, and after that go to som... | from sys import stdin, gettrace
if not gettrace():
def input():
return next(stdin)[:-1]
def main():
n = int(input())
bb = [int(a) for a in input().split()]
seq = {}
for i, b in enumerate(bb):
if b - i in seq:
seq[b-i] += b
else:
seq[b-i] = b
pri... | python | code_algorithm | [
{
"input": "7\n8 9 26 11 12 29 14\n",
"output": "55\n"
},
{
"input": "6\n10 7 1 9 10 15\n",
"output": "26\n"
},
{
"input": "1\n400000\n",
"output": "400000\n"
},
{
"input": "5\n2 2 4 5 5\n",
"output": "11\n"
},
{
"input": "6\n1 3 3 5 6 8\n",
"output": "14\n"
... | code_contests | python | 0.9 | ea204f04276a982b3e7174f526e1aae9 |
Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that.
The exceptions are processed by try-catch-blocks. There are two operators that work with the blocks:
1. The try op... | import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf
ASCIILOWER = 97
ASCIIUPPER = 65
def getInt():
return int(sys.stdin.readline().rstrip())
def getInts():
return map(int, sys.stdin.readline().rstrip().split(" "))
def getString():
return sys.stdin.readline().rstrip()
def printOutput(ans)... | python | code_algorithm | [
{
"input": "8\ntry\n try\n throw ( AE ) \n catch ( BE, \"BE in line 3\")\n\n try\n catch(AE, \"AE in line 5\") \ncatch(AE,\"AE somewhere\")\n",
"output": "AE somewhere\n"
},
{
"input": "8\ntry\n try\n throw ( AE ) \n catch ( AE, \"AE in line 3\")\n\n try\n catch... | code_contests | python | 0 | 8b9ef6383338f0be9ca6e44b58a5dd43 |
Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions:
1. The coordinates of each point in the set are integers.
2. For any two points from the set, the distance between them is a non-integer.
Consider all poi... | if __name__ == '__main__':
nums = input().split()
n = int(nums[0])
m = int(nums[1])
k = min(m, n) + 1
print(k)
for i in range(k):
print(str(i) + " " + str(k-1-i)) | python | code_algorithm | [
{
"input": "2 2\n",
"output": "3\n0 2\n1 1\n2 0\n"
},
{
"input": "4 3\n",
"output": "4\n0 3\n1 2\n2 1\n3 0\n"
},
{
"input": "9 6\n",
"output": "7\n0 6\n1 5\n2 4\n3 3\n4 2\n5 1\n6 0\n"
},
{
"input": "3 4\n",
"output": "4\n0 3\n1 2\n2 1\n3 0\n"
},
{
"input": "6 6\n"... | code_contests | python | 0 | 38d2520a817904d8585b39597948e598 |
Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represent the number of such indexes k, that xk is divisible by p. The answe... | import math, sys
input = sys.stdin.buffer.readline
def ints():
return map(int, input().split())
n = int(input())
x = list(ints())
MAX = max(x) + 1
freq = [0] * MAX
for i in x:
freq[i] += 1
sieve = [False] * MAX
f = [0] * MAX
for i in range(2, MAX):
if sieve[i]:
continue
for j in range(i, MAX... | python | code_algorithm | [
{
"input": "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123\n",
"output": "0\n7\n"
},
{
"input": "6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4\n",
"output": "9\n7\n0\n"
},
{
"input": "1\n6\n1\n2 3\n",
"output": "2\n"
},
{
"input": "9\n9999991 9999943 9999883 4658161 4657997 2315407 2315263 100000... | code_contests | python | 0 | a138602c74834b1e93e368ea5659c75a |
You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?
Your task is to write a program tha... | a = sorted(list(map(int, input().split())))
a[2] = min(a[2], 2 * (a[0] + a[1]))
print(sum(a) // 3)
| python | code_algorithm | [
{
"input": "1 1 1\n",
"output": "1\n"
},
{
"input": "5 4 3\n",
"output": "4\n"
},
{
"input": "2 3 3\n",
"output": "2\n"
},
{
"input": "3 5 2\n",
"output": "3\n"
},
{
"input": "0 1 0\n",
"output": "0\n"
},
{
"input": "500000002 2000000000 500000001\n",
... | code_contests | python | 0.2 | 474ffdedd50cf8a8540b9376220a99ce |
Celebrating the new year, many people post videos of falling dominoes; Here's a list of them: https://www.youtube.com/results?search_query=New+Years+Dominos
User ainta, who lives in a 2D world, is going to post a video as well.
There are n dominoes on a 2D Cartesian plane. i-th domino (1 ≤ i ≤ n) can be represented a... | '''
from bisect import bisect,bisect_left
from collections import *
from math import gcd,ceil,sqrt,floor,inf
from heapq import *
from itertools import *
from operator import add,mul,sub,xor,truediv,floordiv
from functools import *'''
#------------------------------------------------------------------------
import os
... | python | code_algorithm | [
{
"input": "6\n1 5\n3 3\n4 4\n9 2\n10 1\n12 1\n4\n1 2\n2 4\n2 5\n2 6\n",
"output": "0\n1\n1\n2\n"
},
{
"input": "3\n1 1000000000\n999999999 1000000000\n1000000000 1000000000\n4\n1 2\n1 2\n2 3\n1 3\n",
"output": "0\n0\n0\n0\n"
},
{
"input": "2\n304 54\n88203 83\n1\n1 2\n",
"output": "... | code_contests | python | 0 | 76932f649afa513374a562fc0f32d43e |
We all know that GukiZ often plays with arrays.
Now he is thinking about this problem: how many arrays a, of length n, with non-negative elements strictly less then 2l meet the following condition: <image>? Here operation <image> means bitwise AND (in Pascal it is equivalent to and, in C/C++/Java/Python it is equival... | # -*- coding: utf-8 -*-
from collections import deque
def calc(n, m):
if n == 1:
return [[1, 0], [0, 1]]
a = calc(n // 2, m)
if n % 2 == 0:
res00 = (a[0][0] * a[0][0]) % m
res00 = (res00 + a[0][0] * a[1][0]) % m
res00 = (res00 + a[0][1] * a[0][0]) % m
res01 = (a[0][0... | python | code_algorithm | [
{
"input": "2 1 2 10\n",
"output": "3\n"
},
{
"input": "2 1 1 3\n",
"output": "1\n"
},
{
"input": "3 3 2 10\n",
"output": "9\n"
},
{
"input": "131231231 35435 63 153459\n",
"output": "9232\n"
},
{
"input": "165467464 5416516 45 364545697\n",
"output": "2848461... | code_contests | python | 0 | 12eb2b6076fa19feb0ccc99b1c0cb8e6 |
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | string = input()
n = len(string)
stack = []
mapping = [0]*n
# First we create an array where the array called mapping where the index of array
# gives the index of start of opening bracket in string and the value at that index
# gives the index of closing bracket for corresponding opening bracket.
for idx, char in ... | python | code_algorithm | [
{
"input": ")((())))(()())\n",
"output": "6 2\n"
},
{
"input": "))(\n",
"output": "0 1\n"
},
{
"input": "())(((((())())((((()))(())))())())(((()(()()()())(())()))((()(())())()()))()(()())))))(()))((())((((\n",
"output": "80 1\n"
},
{
"input": "))))()())))\n",
"output": "4... | code_contests | python | 0.6 | ca4f51c34687217261a413a10947d0c4 |
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not d... | n = int(input())
from math import sqrt
# Find max m such that m(m+1)/2 <= n
m = int((-1 + sqrt(1 + 8*n))/2)
# l is the previous range
l = m * (m + 1) // 2
print(m if n == l else n - l) | python | code_algorithm | [
{
"input": "56\n",
"output": "1\n"
},
{
"input": "5\n",
"output": "2\n"
},
{
"input": "55\n",
"output": "10\n"
},
{
"input": "3\n",
"output": "2\n"
},
{
"input": "10\n",
"output": "4\n"
},
{
"input": "1000000000000\n",
"output": "88209\n"
},
{
... | code_contests | python | 0.2 | 2107e2742cdbf444e981c723cc9d80b2 |
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the ... | n, k = input().split(" ")
n, k = [int(n), int(k)]
list1 = list(map(int, input().split(" ")))
list2 = list(map(int, input().split(" ")))
low = 0
high = 2*(10**9)
while low < high:
if high - low % 2 != 0:
mid = low + (high - low) // 2 + 1
else:
mid = low + (high - low)//2
d = k
list6 = []... | python | code_algorithm | [
{
"input": "4 3\n4 3 5 6\n11 12 14 20\n",
"output": "3\n"
},
{
"input": "3 1\n2 1 4\n11 3 16\n",
"output": "4\n"
},
{
"input": "60 735\n3 1 4 7 1 7 3 1 1 5 4 7 3 3 3 2 5 3 1 2 3 6 1 1 1 1 1 2 5 3 2 1 3 5 2 1 2 2 2 2 1 3 3 3 6 4 3 5 1 3 2 2 1 3 1 1 1 7 1 2\n596 968 975 493 665 571 598 834... | code_contests | python | 0 | 4c6e98cb3d7ad6caea7c89dfcd29fc1e |
There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.
There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate ... | f = lambda: map(int, input().split())
n, s = f()
c = [0] * n
t = list(f())
for i in t: c[i] += 1
k = t[s - 1]
c[k] -= 1
d = c[0]
c += [d]
d += k > 0
i, j = 1, n
while i < j:
if c[i]: i += 1
elif c[j]:
c[j] -= 1
i += 1
d += j < n
else: j -= 1
print(d) | python | code_algorithm | [
{
"input": "5 3\n1 0 0 4 1\n",
"output": "2\n"
},
{
"input": "3 2\n2 0 2\n",
"output": "1\n"
},
{
"input": "3 2\n2 1 1\n",
"output": "1\n"
},
{
"input": "3 3\n2 1 2\n",
"output": "1\n"
},
{
"input": "7 1\n4 4 6 6 6 6 5\n",
"output": "4\n"
},
{
"input":... | code_contests | python | 0 | 1ece88b57d253567d43de88b08d0a0d4 |
Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is ai meters high.
Vladimir has just planted n bamboos in a row, each of... | import itertools
unfold = itertools.chain.from_iterable
def jumps(a):
d = speedup
while d < a - 1:
c = (a + d - 1) // d
d = (a + c - 2) // (c - 1)
yield d
def calc(d):
return sum(d - 1 - (i - 1) % d for i in a)
def ans():
for d, pd in zip(D, D[1:]):
d -= 1
cd... | python | code_algorithm | [
{
"input": "3 40\n10 30 50\n",
"output": "32\n"
},
{
"input": "3 4\n1 3 5\n",
"output": "3\n"
},
{
"input": "27 56379627\n67793612 34811850 20130370 79625926 35488291 62695111 76809609 2652596 18057723 61935027 62863641 43354418 50508660 29330027 28838758 19040655 19092404 56094994 69200... | code_contests | python | 0 | 15b57fd73b6977d1e61037b47c1d05eb |
Alice and Bob are playing a game on a line with n cells. There are n cells labeled from 1 through n. For each i from 1 to n-1, cells i and i+1 are adjacent.
Alice initially has a token on some cell on the line, and Bob tries to guess where it is.
Bob guesses a sequence of line cell numbers x_1, x_2, …, x_k in order.... | from collections import Counter
nums, num_questions = map(int, input().split())
questions = list(map(int, input().split()))
exist = set()
things = dict(Counter(questions))
nums = nums * 3 - 2 - len(things)
for i in questions:
if i not in exist:
exist.add(i)
if things.get(i - 1):
nums -= ... | python | code_algorithm | [
{
"input": "5 3\n5 1 4\n",
"output": "9\n"
},
{
"input": "100000 1\n42\n",
"output": "299997\n"
},
{
"input": "4 8\n1 2 3 4 4 3 2 1\n",
"output": "0\n"
},
{
"input": "50 75\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 1 3 5 7 9 11 13 15 17 19 21 23 ... | code_contests | python | 0 | b64323f1c422d3dfb28ac21b44c2c474 |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | def func(st,en):
for i in range(st,en+1):
for j in range(i+1,en+1 ):
if (j-i+1)%2==1:
if s[(i+j)//2]==s[i]==s[j]:
return False
#print(st, en)
return True
s=input().strip()
c=0
n=len(s)
for i in range(2,9):
for j in range(len(s)):
if i+... | python | code_algorithm | [
{
"input": "010101\n",
"output": "3\n"
},
{
"input": "11001100\n",
"output": "0\n"
},
{
"input": "0000\n",
"output": "3\n"
},
{
"input": "00\n",
"output": "0\n"
},
{
"input": "1101111000011110111111110101100111111110111100001111011010111001101100010110000001010101... | code_contests | python | 0.1 | 7ff0b742e2cf9e948991c0836628d789 |
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero.
For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not.
Now, you ha... | # import numpy as np
import array
def solution():
req = int(input())
for i in range(req):
count = int(input())
result = 0
if count==2:
print(2)
continue
while count % 2 != 0 :
result+=1
count+=1
print(result)
def coun... | python | code_algorithm | [
{
"input": "4\n2\n5\n8\n11\n",
"output": "2\n1\n0\n1\n"
},
{
"input": "100\n579\n568\n595\n573\n523\n543\n509\n510\n599\n525\n570\n563\n516\n598\n501\n586\n588\n524\n546\n531\n521\n561\n532\n550\n515\n530\n557\n503\n520\n558\n575\n596\n537\n553\n600\n582\n536\n533\n583\n554\n589\n519\n538\n528\n511\... | code_contests | python | 0.2 | b090435dc70fcc710c51214d0e8d075d |
Balph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left of all the balls, or to the right of all the balls).
When the ball is inserted the following happens repeatedly: if so... | # -*- coding: utf-8 -*-
"""
Created on Sat Jul 18 16:25:32 2020
@author: MridulSachdeva
"""
s = input()
n = len(s)
condensed = []
temp = s[0]
count = 1
for i in range(1, n):
if s[i] == temp:
count += 1
else:
condensed.append((temp, count))
temp = s[i]
count = 1
condensed.ap... | python | code_algorithm | [
{
"input": "OOOWWW\n",
"output": "0\n"
},
{
"input": "BBWBB\n",
"output": "0\n"
},
{
"input": "BBWWBB\n",
"output": "3\n"
},
{
"input": "BWWB\n",
"output": "0\n"
},
{
"input": "WWWOOOOOOWWW\n",
"output": "7\n"
},
{
"input": "AA\n",
"output": "3\n"
... | code_contests | python | 0 | 8d7af7239506a0cbefe119cd58e960dc |
A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.
A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ i < t) exists an edge between vertices vi and vi + 1, and also exists an ed... | from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self... | python | code_algorithm | [
{
"input": "10 11\n1 2\n2 3\n3 4\n1 4\n3 5\n5 6\n8 6\n8 7\n7 6\n7 9\n9 10\n6\n1 2\n3 5\n6 9\n9 2\n9 3\n9 10\n",
"output": "2\n2\n2\n4\n4\n1\n"
},
{
"input": "2 1\n1 2\n3\n1 2\n1 2\n2 1\n",
"output": "1\n1\n1\n"
},
{
"input": "5 4\n1 3\n2 3\n4 3\n1 5\n3\n1 3\n2 4\n5 2\n",
"output": "1... | code_contests | python | 0 | 3382e986a6d5e225f3ad098ce4856e19 |
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai + 1 ≤ 2·ai for any positive integer i (i < n).
Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will ge... | #!/usr/bin/python3
n = int(input())
a = list(map(int, input().split()))
s = a[-1]
ans = ['+']
for v in reversed(a[:-1]):
if s > 0:
s -= v
ans.append('-')
else:
s += v
ans.append('+')
if 0 <= s <= a[-1]:
print(''.join(reversed(ans)))
else:
s = -a[-1]
ans = ['-']
f... | python | code_algorithm | [
{
"input": "3\n3 3 5\n",
"output": "++-\n"
},
{
"input": "4\n1 2 3 5\n",
"output": "+--+\n"
},
{
"input": "42\n2 2 2 3 6 8 14 22 37 70 128 232 330 472 473 784 1481 2008 3076 4031 7504 8070 8167 11954 17832 24889 27113 41190 48727 92327 148544 186992 247329 370301 547840 621571 868209 115... | code_contests | python | 0 | 3c5f9a3f6fa4373e2f0d28a7e89b796d |
A star map in Berland is a checked field n × m squares. In each square there is or there is not a star. The favourite constellation of all Berland's astronomers is the constellation of the Cross. This constellation can be formed by any 5 stars so, that for some integer x (radius of the constellation) the following is t... | import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m, k = map(int, input().split())
a = [tuple(map(lambda c: c == '*', input().rstrip())) for _ in range(n)]
cnt = [0] * 400
for i in range(1, n - 1):
for j in range(1, m - 1):
if not a[... | python | code_algorithm | [
{
"input": "5 6 1\n....*.\n...***\n....*.\n..*...\n.***..\n",
"output": "2 5\n1 5\n3 5\n2 4\n2 6\n"
},
{
"input": "7 7 2\n...*...\n.......\n...*...\n*.***.*\n...*...\n.......\n...*...\n",
"output": "4 4\n1 4\n7 4\n4 1\n4 7\n"
},
{
"input": "5 6 2\n....*.\n...***\n....*.\n..*...\n.***..\n... | code_contests | python | 0.7 | 656a5bb2f15f013babe638b513061a08 |
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out... | '''input
XO
'''
s = input()
if all(s[x] == s[~x] for x in range(len(s)//2)):
if any(y not in "AHIMOTUVWXY" for y in s[:len(s)//2+1]):
print("NO")
else:
print("YES")
else:
print("NO") | python | code_algorithm | [
{
"input": "AHA\n",
"output": "YES\n"
},
{
"input": "Z\n",
"output": "NO\n"
},
{
"input": "XO\n",
"output": "NO\n"
},
{
"input": "HNCMEEMCNH\n",
"output": "NO\n"
},
{
"input": "AABAA\n",
"output": "NO\n"
},
{
"input": "NNN\n",
"output": "NO\n"
},... | code_contests | python | 0.5 | 366a5d338ba45efa188a4f781a49e3b9 |
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
Inpu... | def solve(s, t, i, l):
if i == l:
return False
if s[i] == "?":
if solve(s, t, i + 1, l):
s[i] = t[i]
return True
elif t[i] == "9":
return False
s[i] = nxt[t[i]]
for j in range(i, l):
if s[j] == "?":
s[j] = "0... | python | code_algorithm | [
{
"input": "3\n?\n18\n1?\n",
"output": "YES\n1\n18\n19\n"
},
{
"input": "2\n??\n?\n",
"output": "NO\n"
},
{
"input": "5\n12224\n12??5\n12226\n?0000\n?00000\n",
"output": "YES\n12224\n12225\n12226\n20000\n100000\n"
},
{
"input": "98\n?\n?0\n2?\n6?\n6?\n69\n??\n??\n96\n1?2\n??3... | code_contests | python | 0 | 12c8bda860b1b8ac7ddcf76aa6bc4806 |
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature ... | def ziped(a):
p = []
for i in a:
x = int(i.split('-')[0])
y = i.split('-')[1]
if len(p) > 0 and p[-1][1] == y:
p[-1][0] += x
else:
p.append([x, y])
return p
def solve(a, b , c):
ans = 0
if len(b) == 1:
for token in a:
... | python | code_algorithm | [
{
"input": "6 1\n3-a 6-b 7-a 4-c 8-e 2-a\n3-a\n",
"output": "6\n"
},
{
"input": "5 5\n1-h 1-e 1-l 1-l 1-o\n1-w 1-o 1-r 1-l 1-d\n",
"output": "0\n"
},
{
"input": "5 3\n3-a 2-b 4-c 3-a 2-c\n2-a 2-b 1-c\n",
"output": "1\n"
},
{
"input": "9 3\n1-h 1-e 2-l 1-o 1-w 1-o 1-r 1-l 1-d\... | code_contests | python | 0 | 206c1820592cdb40bd9ee031df4da7c9 |
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves ... | import math
n,m=map(int,input().split())
print(math.gcd(n-1,m-1)+1)
| python | code_algorithm | [
{
"input": "3 4\n",
"output": "2\n"
},
{
"input": "3 3\n",
"output": "3\n"
},
{
"input": "8 50\n",
"output": "8\n"
},
{
"input": "302237 618749\n",
"output": "5\n"
},
{
"input": "999999 1000000\n",
"output": "2\n"
},
{
"input": "893011 315181\n",
"... | code_contests | python | 0 | be5c511eba44e4fc23df86bd69567303 |
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends... | import sys
inf = 10**9 + 7
def solve():
n = int(sys.stdin.readline())
v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya
p = [int(pi) for pi in sys.stdin.readline().split()] # Petya
cnt = [0]*5
for i in range(5):
if v[i] != -1:
cnt[i] += 1
if p[i] != -1:
... | python | code_algorithm | [
{
"input": "4\n-1 20 40 77 119\n30 10 73 50 107\n21 29 -1 64 98\n117 65 -1 -1 -1\n",
"output": "-1\n"
},
{
"input": "5\n119 119 119 119 119\n0 0 0 0 -1\n20 65 12 73 77\n78 112 22 23 11\n1 78 60 111 62\n",
"output": "27\n"
},
{
"input": "2\n5 15 40 70 115\n50 45 40 30 15\n",
"output":... | code_contests | python | 0 | 1d6ca7a655ec6d449360a413fd88f037 |
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforc... | import sys
import math
import itertools
import collections
def getdict(n):
d = {}
if type(n) is list or type(n) is str:
for i in n:
if i in d:
d[i] += 1
else:
d[i] = 1
else:
for i in range(n):
t = ii()
if t in d... | python | code_algorithm | [
{
"input": "abbcca\n",
"output": "NO\n"
},
{
"input": "abcda\n",
"output": "YES\n"
},
{
"input": "abccaa\n",
"output": "YES\n"
},
{
"input": "abcdmnp\n",
"output": "NO\n"
},
{
"input": "ucnolsloncw\n",
"output": "YES\n"
},
{
"input": "acbb\n",
"out... | code_contests | python | 0.6 | e43568778a544a3f4e6ab9b0f372ef58 |
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
* letters on positions from A in the string are all distinct and lowercase; ... | import re
input()
print(max(map(lambda s: len(set(s)), re.split('[A-Z]', input())))) | python | code_algorithm | [
{
"input": "11\naaaaBaabAbA\n",
"output": "2\n"
},
{
"input": "3\nABC\n",
"output": "0\n"
},
{
"input": "12\nzACaAbbaazzC\n",
"output": "3\n"
},
{
"input": "100\nchMRWwymTDuZDZuSTvUmmuxvSscnTasyjlwwodhzcoifeahnbmcifyeobbydwparebduoLDCgHlOsPtVRbYGGQXfnkdvrWKIwCRl\n",
"outp... | code_contests | python | 0.3 | f1fd106030e9b8eb1f56e2657405ce0c |
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note aft... | # Problem: 88A
# Time Created: August 10(Monday) 2020 || 11:37:58
#>-------------------------<#
import sys
input = sys.stdin.readline
#>-------------------------<#
from itertools import permutations
# Helper Functions. -> Don't cluster your code.
def check_chord(tup):
notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F... | python | code_algorithm | [
{
"input": "A B H\n",
"output": "strange\n"
},
{
"input": "C E G\n",
"output": "major\n"
},
{
"input": "C# B F\n",
"output": "minor\n"
},
{
"input": "E G# C\n",
"output": "strange\n"
},
{
"input": "D# C G\n",
"output": "minor\n"
},
{
"input": "F# H C\n... | code_contests | python | 0 | 958660191f5ead8b21fcd8e83dcc425a |
Bessie is out grazing on the farm, which consists of n fields connected by m bidirectional roads. She is currently at field 1, and will return to her home at field n at the end of the day.
The Cowfederation of Barns has ordered Farmer John to install one extra bidirectional road. The farm has k special fields and he h... | import sys
from collections import deque
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
# v(G), e(G), special v
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
# adjacency lists
g = [[] for _ in range(n + 1)]
for _ in range(m):
v, to = map(int, input().split(... | python | code_algorithm | [
{
"input": "5 4 2\n2 4\n1 2\n2 3\n3 4\n4 5\n",
"output": "3\n"
},
{
"input": "5 5 3\n1 3 5\n1 2\n2 3\n3 4\n3 5\n2 4\n",
"output": "3\n"
},
{
"input": "5 4 2\n3 4\n2 1\n2 3\n1 4\n4 5\n",
"output": "2\n"
},
{
"input": "4 3 2\n3 4\n1 2\n2 3\n1 4\n",
"output": "1\n"
},
{
... | code_contests | python | 0 | 3cf020273e7e3fa6b0cc29ea650384ee |
Slime has a sequence of positive integers a_1, a_2, …, a_n.
In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\}.
In this problem, for the integer multiset s, the median of s is equal to th... | # Template 1.0
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): retur... | python | code_algorithm | [
{
"input": "5\n5 3\n1 5 2 6 1\n1 6\n6\n3 2\n1 2 3\n4 3\n3 1 2 3\n10 3\n1 2 3 4 5 6 7 8 9 10\n",
"output": "no\nyes\nyes\nno\nyes\n"
},
{
"input": "1\n7 2\n5 5 1 1 2 1 1\n",
"output": "yes\n"
},
{
"input": "1\n26 2\n2 1 1 1 3 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1\n",
"output": "y... | code_contests | python | 0 | 40a0a656ce842462c68616f2e1c4fc91 |
For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that ∑_{i=1}^{n}{∑_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for exampl... | #import numpy as np
#import collections
#import sys
# =============================================================================
#def get_primeFactor(n):
# res=[1]
# x=2
# while x*x<=n:
# while n%x==0:
# res.append(x)
# n//=x
# x+=1
# if n>1:res.append(n)
# return r... | python | code_algorithm | [
{
"input": "2\n3 8\n2 5 1\n4 4\n0 1 2 3\n",
"output": "YES\nNO\n"
},
{
"input": "1\n3 6\n4 4 4\n",
"output": "NO\n"
},
{
"input": "1\n3 2\n1 2 3\n",
"output": "NO\n"
},
{
"input": "1\n3 16\n2 5 1\n",
"output": "NO\n"
},
{
"input": "1\n1 2\n4\n",
"output": "NO\... | code_contests | python | 0.9 | 88604afd735111095381c1e2afc03b12 |
One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "x y" are there, such that x is a substring of string s, y is a subsequence of string t, and the content of x and y is the s... | from sys import stdin
s=[ord(i)-97 for i in stdin.readline().strip()]
s1=[ord(i)-97 for i in stdin.readline().strip()]
n=len(s)
m=len(s1)
mod=1000000007
dp=[[0 for i in range(n)] for j in range(26)]
for i in range(m):
arr=[0 for j in range(n)]
for j in range(n):
if s1[i]==s[j] :
arr[j]=1
... | python | code_algorithm | [
{
"input": "codeforces\nforceofcode\n",
"output": "60\n"
},
{
"input": "aa\naa\n",
"output": "5\n"
},
{
"input": "bbabb\nbababbbbab\n",
"output": "222\n"
},
{
"input": "ab\nbbbba\n",
"output": "5\n"
},
{
"input": "xzzxxxzxzzzxzzzxxzzxzzxzxzxxzxxzxxzxzzxxzxxzxxxzxz... | code_contests | python | 0 | 98b711b6b09d572c6e7fa896f8239a9e |
The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has n observation binoculars located at the OX axis. For each i between 1 and n, inclusive, there exists a single binocular located at the point with coordinates (i, 0). There are m flamingos in the Zoo, located at points with positive coordinates.... | def gcd(a,b):
if b == 0:
return a
return gcd(b, a % b)
def normalize_rational(num,den):
#associate the -ve with the num or cancel -ve sign when both are -ve
if num ^ den < 0 and num > 0 or num ^ den > 0 and num < 0:
num = -num; den = -den
#put it in its simplest form
g = gcd... | python | code_algorithm | [
{
"input": "5 5\n2 1\n4 1\n3 2\n4 3\n4 4\n",
"output": "11\n"
},
{
"input": "1000000 2\n194305 1024\n4388610 1023\n",
"output": "1000000\n"
},
{
"input": "3 3\n227495634 254204506\n454991267 508409012\n217792637 799841973\n",
"output": "4\n"
},
{
"input": "1000000 2\n13639533... | code_contests | python | 0 | 21c36fbd297027f041bec33042b2db58 |
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.
We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right f... | x, y, n, c = 0, 0, 0, 0
def suma_impares(m):
return m * m
def suma_n(m):
return m * (m - 1) // 2
def cnt(t):
u, d, l, r = x + t, x - t, y - t, y + t
suma = t ** 2 + (t + 1) ** 2
if u > n: suma -= suma_impares(u - n)
if d < 1: suma -= suma_impares(1 - d)
if l < 1: suma -= suma_impares(1 - l)
if r > n: suma -= su... | python | code_algorithm | [
{
"input": "9 3 8 10\n",
"output": "2\n"
},
{
"input": "6 4 3 1\n",
"output": "0\n"
},
{
"input": "1000000000 44 30 891773002\n",
"output": "42159\n"
},
{
"input": "1000000000 999999938 999999936 384381709\n",
"output": "27600\n"
},
{
"input": "1000000000 99999994... | code_contests | python | 0 | ec529b249cf8c2375c8ee3544a89346f |
Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n × m chessboard, a very tasty candy and two numbers a and b.
Dima put the chessboard in front of Inna and placed the candy in position (i, j) on the board. The boy said h... | n, m, i, j, a, b = map(int, input().split())
corners = [(1, 1), (1, m), (n, 1), (n, m)]
result = False
ans = -1
for cnt in corners:
if (abs(cnt[0] - i) % a == 0) and (abs(cnt[1] - j) % b == 0):
result = True
t1, t2 = abs(cnt[0] - i) // a, abs(cnt[1] - j) // b
if (t1 + t2) % 2 == 0:
... | python | code_algorithm | [
{
"input": "5 5 2 3 1 1\n",
"output": "Poor Inna and pony!\n"
},
{
"input": "5 7 1 3 2 2\n",
"output": "2\n"
},
{
"input": "2 6 1 2 2 2\n",
"output": "Poor Inna and pony!\n"
},
{
"input": "100 100 50 50 500 500\n",
"output": "Poor Inna and pony!\n"
},
{
"input": "... | code_contests | python | 0 | 845ccd1b3699904459d37e08a7c668a6 |
DZY loves chemistry, and he enjoys mixing chemicals.
DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.
Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pour... | def iterative_dfs(graph, start, path=[]):
visited = {}
for i in graph:
visited[i] = []
q=[start]
while q:
v=q.pop(0)
if not visited[v]:
visited[v] = True
path=path+[v]
q=graph[v]+q
return path
nodes, edges = map(int, input().split(' ')... | python | code_algorithm | [
{
"input": "3 2\n1 2\n2 3\n",
"output": "4\n"
},
{
"input": "2 1\n1 2\n",
"output": "2\n"
},
{
"input": "1 0\n",
"output": "1\n"
},
{
"input": "26 17\n1 2\n2 3\n1 6\n6 7\n7 8\n2 9\n4 10\n3 11\n11 12\n9 13\n6 14\n2 16\n5 18\n6 19\n11 22\n15 24\n6 26\n",
"output": "131072\n... | code_contests | python | 0.4 | f37aa5bc6cabffe0a671f05c44327433 |
Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line... | import sys
n = int(sys.stdin.readline ())
a= [int (x) for x in sys.stdin.readline ().split ()]
assert len(a) == n
b = [int (x) for x in sys.stdin.readline ().split ()]
assert len(b) == n
ans = []
for i in range (n):
j = i;
while b[j] != a[i] :
j += 1
while j > i:
ans += [(j, j + 1)]
... | python | code_algorithm | [
{
"input": "2\n1 100500\n1 100500\n",
"output": "0\n"
},
{
"input": "4\n1 2 3 2\n3 2 1 2\n",
"output": "3\n2 3\n1 2\n2 3\n"
},
{
"input": "1\n800950546\n800950546\n",
"output": "0\n"
},
{
"input": "1\n873725529\n873725529\n",
"output": "0\n"
},
{
"input": "2\n3443... | code_contests | python | 0 | 8040e182b676108fa7e3cf6e6a221f2a |
After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i, j, k) (i < j < k), such that ai·aj·ak is minimum possible, are there in the... | n=int(input())
a=list(map(int,(input().split(' '))))
a=sorted(a)
a.append(0)
ans=1
t=0
while a[3+t]==a[2]:t=t+1
if a[3]==a[0]:ans=(t+3)*(t+2)*(t+1)/6
elif a[3]==a[1]:ans=(t+2)*(t+1)/2
elif a[3]==a[2]:ans=t+1
print(int(ans))
| python | code_algorithm | [
{
"input": "5\n1 3 2 3 4\n",
"output": "2\n"
},
{
"input": "6\n1 3 3 1 3 2\n",
"output": "1\n"
},
{
"input": "4\n1 1 1 1\n",
"output": "4\n"
},
{
"input": "4\n1 1 3 3\n",
"output": "2\n"
},
{
"input": "3\n5 9 5\n",
"output": "1\n"
},
{
"input": "9\n10 ... | code_contests | python | 0.2 | c5ae94d1cdc9948f5c4df2a7dcd768d5 |
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part — circle of radius r - d with center at the origin, an... | '''input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
'''
r, d = map(int, input().split())
n = int(input())
c = 0
for _ in range(n):
x, y, r1 = map(int, input().split())
s = (x**2 + y**2)**0.5
if r-d <= s-r1 and s+r1 <= r:
c += 1
print(c)
| python | code_algorithm | [
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n",
"output": "0\n"
},
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"output": "2\n"
},
{
"input": "1 0\n1\n1 1 0\n",
"output": "0\n"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1\n",
... | code_contests | python | 0.9 | e858b77b2a73c0e67a2c8d827cd6ddb9 |
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·n people in the group (including Vadim), and they have exactly... | n = int(input())
n = 2*n
w = [int(i) for i in input().split()]
w.sort()
import math
res = math.inf
for x in range(n):
for y in range(x+1, n):
wc = w[:]
wc.pop(y); wc.pop(x)
# print(wc)
s = 0
for i in range(0, n-3, 2):
s += wc[i+1]-wc[i]
res = min(s, res)
print(res) | python | code_algorithm | [
{
"input": "4\n1 3 4 6 3 4 100 200\n",
"output": "5\n"
},
{
"input": "2\n1 2 3 4\n",
"output": "1\n"
},
{
"input": "45\n476 103 187 696 463 457 588 632 763 77 391 721 95 124 378 812 980 193 694 898 859 572 721 274 605 264 929 615 257 918 42 493 1 3 697 349 990 800 82 535 382 816 943 735 ... | code_contests | python | 0 | 7b60d887a77c2c113ee4bb1ef4bf7735 |
There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked points, in such a way that all points have to be connected with e... | import sys
from array import array
n = int(input())
edge = [list(map(int, input().split())) for _ in range(n)]
mod = 10**9 + 7
dp_f = [array('i', [-1])*n for _ in range(n)]
dp_g = [array('i', [-1])*n for _ in range(n)]
for i in range(n):
dp_f[i][i] = dp_g[i][i] = 1
for i in range(n-1):
dp_f[i][i+1] = dp_g[i... | python | code_algorithm | [
{
"input": "3\n0 0 1\n0 0 1\n1 1 0\n",
"output": "1\n"
},
{
"input": "4\n0 1 1 1\n1 0 1 1\n1 1 0 1\n1 1 1 0\n",
"output": "12\n"
},
{
"input": "3\n0 0 0\n0 0 1\n0 1 0\n",
"output": "0\n"
},
{
"input": "4\n0 0 1 0\n0 0 0 1\n1 0 0 0\n0 1 0 0\n",
"output": "0\n"
},
{
... | code_contests | python | 0 | 00237b4eb03aea3bf5d3f1bcf89ee37d |
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and ai < aj. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3).
You are given a per... | def solve():
n=int(input())
a=list(map(int,input().split()))
cl=['odd','even']
m=int(input())
ans=True
b=[]
ap=b.append
for i in range(n):
for j in range(i):
if a[j]>a[i]:
ans=not ans
for i in range(m):
left,right=map(int,input().split())
... | python | code_algorithm | [
{
"input": "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n",
"output": "odd\nodd\nodd\neven\n"
},
{
"input": "3\n1 2 3\n2\n1 2\n2 3\n",
"output": "odd\neven\n"
},
{
"input": "1\n1\n10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"output": "even\neven\neven\neven\neven\neven\neven\neven... | code_contests | python | 0.3 | 8a4a67aa758f1aefe5037d2daec29aef |
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl... | import math
x,y=map(lambda x:math.log(int(x))/int(x),input().split())
print('<=>'[(x>=y)+(x>y)]) | python | code_algorithm | [
{
"input": "5 8\n",
"output": ">\n"
},
{
"input": "6 6\n",
"output": "=\n"
},
{
"input": "10 3\n",
"output": "<\n"
},
{
"input": "15657413 15657414\n",
"output": ">\n"
},
{
"input": "4 1000000000\n",
"output": ">\n"
},
{
"input": "4 4\n",
"output":... | code_contests | python | 0.7 | 9d313f49608b96d356ce0286faf8072c |
There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available.
Let k be the maximum number of people sitting on one bench after additional m people c... | import math
n=int(input())
m=int(input())
a=[]
for i in range(n):
a.append(int(input()))
maxa=max(a)+m
mina=max(max(a),math.ceil((sum(a)+m)/n))
print(str(mina)+" "+str(maxa))
| python | code_algorithm | [
{
"input": "4\n6\n1\n1\n1\n1\n",
"output": "3 7\n"
},
{
"input": "1\n10\n5\n",
"output": "15 15\n"
},
{
"input": "3\n6\n1\n6\n5\n",
"output": "6 12\n"
},
{
"input": "3\n7\n1\n6\n5\n",
"output": "7 13\n"
},
{
"input": "100\n66\n95\n19\n88\n15\n29\n52\n37\n75\n21\n9... | code_contests | python | 0.2 | 2a9e07d02d531d592a5154858088a24b |
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.
You have to form k teams for yet another new programming competition. As you know, the more students are involved in competition the more probable the victory of your university is! ... | kk=lambda:map(int,input().split())
ll=lambda:list(kk())
n,k= kk()
ls = sorted(ll())
vs,ne = [0]*n,[-1]*n
b = 0
for a in range(n):
while b < n and ls[b] - ls[a] < 6: b+=1
vs[a],ne[a] = b-a, b
curr = [0]*(n+1)
# print(vs)
for _ in range(k):
# print(curr)
prev = curr
curr = [0]*(n+1)
for i in range(n):
curr[i] = v... | python | code_algorithm | [
{
"input": "4 4\n1 10 100 1000\n",
"output": "4\n"
},
{
"input": "6 1\n36 4 1 25 9 16\n",
"output": "2\n"
},
{
"input": "5 2\n1 2 15 15 15\n",
"output": "5\n"
},
{
"input": "10 9\n1034 1043 4739 2959 4249 4246 582 4584 3762 4027\n",
"output": "10\n"
},
{
"input": ... | code_contests | python | 0.5 | e4207981203ce10b1f67fa5a40891ec1 |
You are given a sequence a_1, a_2, ..., a_n consisting of n integers.
You can choose any non-negative integer D (i.e. D ≥ 0), and for each a_i you can:
* add D (only once), i. e. perform a_i := a_i + D, or
* subtract D (only once), i. e. perform a_i := a_i - D, or
* leave the value of a_i unchanged.
It is... | n = int(input())
L = [int(i) for i in input().split()]
F = []
mi = 101
ma = 0
for i in L:
if i not in F:
F.append(i)
if len(F) > 3:
print(-1)
else:
F.sort()
if len(F) == 3:
D = F[1] - F[0]
if F[2] - F[1] == D:
print(D)
else:
print(-1)
elif len(... | python | code_algorithm | [
{
"input": "2\n2 8\n",
"output": "3\n"
},
{
"input": "4\n1 3 3 7\n",
"output": "-1\n"
},
{
"input": "5\n2 2 5 2 5\n",
"output": "3\n"
},
{
"input": "6\n1 4 4 7 4 1\n",
"output": "3\n"
},
{
"input": "5\n4 2 6 6 6\n",
"output": "2\n"
},
{
"input": "4\n2 ... | code_contests | python | 0.1 | e15ab48a9fc4c2e815a4f9640fef9066 |
Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming.
Fortunately, Adilbek can spend time witho... | mod = 10 ** 9 + 7
MAX = 2 * 10 ** 5+2
r = [1] * MAX
factorial = [1] * MAX
rfactorial = [1] * MAX
rp = [1] * MAX
#Permite precalcular factorial hasta "MAX", para evitar tener que calcularlo varias veces
#dentro de la ejecucion del programa.
for i in range(2, MAX):
factorial[i] = i * factorial[i - 1] % mod
... | python | code_algorithm | [
{
"input": "3 5\n2 2 2\n",
"output": "750000007\n"
},
{
"input": "3 5\n2 1 2\n",
"output": "125000003\n"
},
{
"input": "20 30\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "310937903\n"
},
{
"input": "20 31\n2 2 1 2 1 1 2 1 2 2 1 2 1 2 1 1 1 2 1 2\n",
"output": "... | code_contests | python | 0 | 4f84a4df4f0cffc53ce53f797d9ef8c5 |
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... | def line():
return map(int, input().split())
def num():
return int(input())
from collections import OrderedDict as od
n,k = line()
ids = list(line())
screen = od()
for id in ids:
if id not in screen:
if len(screen)==k:
screen.popitem(last=False)
screen[id]=None
print(len(scree... | python | code_algorithm | [
{
"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"
},
{
"input": "9 2\n1 2 3 4 5 6 7 8 9\n",
"output": "2\n9 8\n"
},
{
"input": "1 4\n1\n",
"output": "1\n1\n"
},
{
"input": "1 1\n5\n",
"o... | code_contests | python | 0.9 | ff8364c6fe448aefa40467bc1eb87f34 |
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point ... | for _ in range(int(input())):
n, k = map(int, input().split())
if n<k:print(k-n)
elif n%2 == k%2: print(0)
else: print(1) | python | code_algorithm | [
{
"input": "6\n4 0\n5 8\n0 1000000\n0 0\n1 0\n1000000 1000000\n",
"output": "0\n3\n1000000\n0\n1\n0\n"
},
{
"input": "1\n5 0\n",
"output": "1\n"
},
{
"input": "1\n7 0\n",
"output": "1\n"
},
{
"input": "1\n15 0\n",
"output": "1\n"
},
{
"input": "1\n1000000 0\n",
... | code_contests | python | 0.8 | 89a82b67eb079548db6bcc29c7788d57 |
John Doe has a list of all Fibonacci numbers modulo 1013. This list is infinite, it starts with numbers 0 and 1. Each number in the list, apart from the first two, is a sum of previous two modulo 1013. That is, John's list is made from the Fibonacci numbers' list by replacing each number there by the remainder when div... | low_n = 1000
high_m = 15000
limit = int(10 ** 13)
f = int(input())
inputList = []
def customFunction(i):
if i == 0:
return (0, 1)
a, b = customFunction(i >> 1)
a, b = ((2 * a * b - a * a) % low_n, (b * b + a * a) % low_n)
if i & 1:
a, b = (b % low_n, (a + b) % low_n)
return (a, b)... | python | code_algorithm | [
{
"input": "13\n",
"output": "7\n"
},
{
"input": "377\n",
"output": "14\n"
},
{
"input": "53824509026\n",
"output": "895481947599\n"
},
{
"input": "6138242440179\n",
"output": "14000000000092\n"
},
{
"input": "10\n",
"output": "-1\n"
},
{
"input": "999... | code_contests | python | 0 | fe774d9e85fb9940e469190f31582a27 |
Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is n squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares.
For example, the correct field to play looks ... | Mod=1000000007
s=input()
n=len(s)
a,b,c,d=1,0,0,0
for i in range(0,n):
if s[i]=='*':
t=0,a+b+d,0,0
elif s[i]=='?':
t=a+b+c,a+b+d,0,0
elif s[i]=='0':
t=0,0,a+c,0
elif s[i]=='1':
t=0,0,b,a+c
else:
t=0,0,0,b+d
a,b,c,d=map(lambda a:a%Mod,t)
print((a+b+c)%Mod)
| python | code_algorithm | [
{
"input": "?01???\n",
"output": "4\n"
},
{
"input": "1\n",
"output": "0\n"
},
{
"input": "**12\n",
"output": "0\n"
},
{
"input": "?\n",
"output": "2\n"
},
{
"input": "0\n",
"output": "1\n"
},
{
"input": "01\n",
"output": "0\n"
},
{
"input"... | code_contests | python | 0 | 98f8035327914fd585316a4d24199a7f |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.