source stringclasses 3
values | instruction stringlengths 23 3.97k | input stringclasses 1
value | output stringlengths 1 3.75k |
|---|---|---|---|
MatrixStudio/Codeforces-Python-Submissions | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | ```python
n, m, a = map(int, input().split(" "))
ma = m//a
if m % a > 0: ma += 1
na = n//a
if n % a > 0: na += 1
print(na*ma)
``` | |
MatrixStudio/Codeforces-Python-Submissions | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | ```python
n, t, k, d = map(int, input().split())
time_1_oven = n * (t / k)
time_2_oven = 0
n_cakes_1 = 0
n_cakes_2 = 0
mins = 0
mins_2_oven = 0
oven_2_on = False
while n_cakes_1 < n:
mins += 1
if mins % t == 0 and mins != 0:
n_cakes_1 += k
mins_1_oven = mins
mins = 0
while n_cakes_2 < ... | |
MatrixStudio/Codeforces-Python-Submissions | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | ```python
from sys import stdin
input = lambda: stdin.readline().strip()
d = dict()
n = int(input())
for _ in range(n):
s = input()
if s not in d:
d[s] = 1
else:
d[s] += 1
print(max(d.values()))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Insurgents accidentally got hold of the plan of a top secret research polygon created on a distant planet for the needs of the Galaxy Empire. The insurgents suppose that this polygon is developing new deadly weapon. The polygon consists of *n* missile silos connected by bidirectional underground passages. The passages ... | ```python
f = [1 for i in range(2001)];
for i in range(1, 2001): f[i] = f[i-1] * i;
n, m = map(int, raw_input().split());
a = [[-1 for i in range(n)] for j in range(n)];
cal = [0 for i in range(n)];
for i in range(0, n-1):
buf = map(int, raw_input().split());
for j in range(i+1, n): a[i][j] = a[j][i] = buf[j... | |
MatrixStudio/Codeforces-Python-Submissions | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | ```python
cities = int(input())
coordinate_of_city = list(map(int, input().split(' ')))
for i in range(cities):
coordinate_of_city_copy = coordinate_of_city[::]
coordinate_of_city_copy.remove(coordinate_of_city_copy[i])
distances = []
for coordinate in coordinate_of_city_copy:
distances.append(... | |
MatrixStudio/Codeforces-Python-Submissions | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | ```python
x,y,z=map(int, input().split())
if x%z==0:
a=x//z
else:
a=x//z + 1
if y%z==0:
b=y//z
else:
b=y//z + 1
print(a*b)
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | ```python
import math
entrada = input()
n = int(entrada.split()[0])
k = int(entrada.split()[1])
arr_v = []
i = 1
while (i * i <= n):
if (n % i != 0):
i += 1
continue
arr_v.append(i)
if (i * i != n):
arr_v.append(n // i)
i += 1
if (k > len(arr_v)):
print(-1)
else:
... | |
MatrixStudio/Codeforces-Python-Submissions | While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
Together with his old phone, he lost all his contacts and ... | ```python
left = 0
right = 1
up = 2
down = 3
buttons = []
#0
buttons.append({left:False, right:False, up:True, down:False })
#1
buttons.append({left:False, right:True, up:False, down:True })
#2
buttons.append({left:True, right:True, up:False, down:True })
#3
buttons.append({left:True, right:False, up:False, down:True ... | |
MatrixStudio/Codeforces-Python-Submissions | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | ```python
from itertools import combinations
n = int(input())
home_colors = []
guest_colors = []
for _ in range(n):
hi, ai = map(int, input().split())
home_colors.append(hi)
guest_colors.append(ai)
count = 0
for host, guest in combinations(range(n), 2):
if home_colors[host] == guest_co... | |
MatrixStudio/Codeforces-Python-Submissions | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | ```python
a=int(input())
b=input()
c=b.count("0")
d=b.count("1")
print(a-min(c,d)*2)
``` | |
MatrixStudio/Codeforces-Python-Submissions | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | ```python
k = int(input())
r = pow(5, k, 100)
print(r)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | ```python
from collections import *
from functools import *
n = int(input())
arr = [int(x) for x in input().split()]
c = Counter(arr)
mx = max(arr)
@lru_cache(None)
def helper(ind):
if ind > mx:
return 0
ans = helper(ind+2) + ind*c[ind]
ans = max(ans, helper(ind+1))
return ans
print... | |
MatrixStudio/Codeforces-Python-Submissions | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | ```python
mat=[]
for i in range(3):
mat.append([int(i) for i in input().split()])
a=mat[0][1]+mat[0][2]
b=mat[1][0]+mat[1][2]
c=mat[2][0]+mat[2][1]
mat[0][0]=10**5-a
mat[1][1]=10**5-b
mat[2][2]=10**5-c
for i in range(3):
print(*mat[i])
``` | |
MatrixStudio/Codeforces-Python-Submissions | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | ```python
n=int(input())
ch=input()
r=0
for i in ch:
if i=='A':
r=r+1
else:
r=r-1
if r>0:
print('Anton')
elif r==0:
print('Friendship')
else:
print('Danik')
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | ```python
n,m = map(int, input().split())
t = 0
while n>0:
t = t + 1
if t%m==0:
n = n + 1
n = n - 1
print(t)
``` | |
MatrixStudio/Codeforces-Python-Submissions | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | ```python
s1 = input()
s2 = input()
s3 = input()
s = s1+s2
s1 = ''.join(sorted(s))
s2 = ''.join(sorted(s3))
if s1 == s2:
print('YES')
else:
print('NO')
``` | |
MatrixStudio/Codeforces-Python-Submissions | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | ```python
n = int(input())
wordList = []
for ctr in range(n):
word = input()
wordList.append(word)
for w in wordList:
if len(w) <= 10:
print(w)
else:
print(w[0]+str(len(w)-2)+w[-1])
``` | |
MatrixStudio/Codeforces-Python-Submissions | Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a ... | ```python
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return (int(input()))
def inlt():
return (list(map(int, input().split())))
def insr():
s = input()
return (list(s[:len(s) - 1]))
def invr():
return (map(int, in... | |
MatrixStudio/Codeforces-Python-Submissions | You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
... | ```python
leng, m = map(int, input().split())
blocks = list(map(int, input().split()))
diction = dict.fromkeys(range(1, (leng + 1)), 0)
for temp in blocks:
t = diction[temp]
t += 1
diction[temp] = t
answer = min(diction.values())
print(answer)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | ```python
n=int(input())
s=input()
a=[]
for i in range(n):
a.append(s[i])
for i in range(n-1):
if a[i]=="U" and a[i+1]=="R":
a[i]="D"
a[i+1]="D"
if a[i]=="R" and a[i+1]=="U":
a[i]="D"
a[i+1]="D"
print(n-(a.count("D"))//2)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | ```python
n=int(input())
sum1=sum2=sum3=0
for i in range(n) :
arr=[int(j) for j in input().split()]
sum1=sum1+arr[0]
sum2=sum2+arr[1]
sum3=sum3+arr[2]
if sum1==sum2==sum3==0 :
print("YES")
else :
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | ```python
m,n,a = map(int, input().split())
total = m*n
area = a*a
if total%area==0:
print(int(total/area)+1)
else:
print((total//area)+1+1)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.
As before, th... | ```python
a=[]
c=0
s=0
for i in range(8):
b=input()
a=a+[b]
c=c+a.count('BBBBBBBB')
if c!=8:
for i in range(8):
for j in range(8):
if a[i][j]=='B':
for m in range(8):
if a[m][j]=='B':
s=s+1
if s==8:... | |
MatrixStudio/Codeforces-Python-Submissions | According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can chec... | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 18 21:37:04 2020
@author: DELL
"""
str=["ABSINTH", "BEER", "BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA","WHISKEY","WINE"]
n=int(input())
l=[]
for i in range(n):
h=input()
l+=[h]
c=0
for i in l:
if i.isalpha():
if n... | |
MatrixStudio/Codeforces-Python-Submissions | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F... | ```python
n = int(input())
print(str(0) + ' ' + str(0) + ' ' + str(n))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | ```python
import math
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x,y=max(a),max(b)
f,q= math.log(x,2),math.log(y,2)
f=int(f)
ans1 = (2**f)+((2**f)-1)
q=int(q)
ans2 = (2**q)+((2**q)-1)
print(ans1+ans2)
``` | |
MatrixStudio/Codeforces-Python-Submissions | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | ```python
n=int(input())
a=list(map(int,input().split()))
a1=[]
a2=[]
a3=[]
l1,l2,l3 = 0,0,0
for x in range(1,n+1):
if a[x-1]==1:
a1.append(x)
l1+=1
elif a[x-1]==2:
a2.append(x)
l2+=1
else:
a3.append(x)
l3+=1
k=min(l1,l2,l3)
print(k)
for x in... | |
MatrixStudio/Codeforces-Python-Submissions | 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... | ```python
num, choose = map(int, input().split())
lista = list(map(int, input().split()))
ans = 0
j = 0
for i in range(0,num):
while(lista[i] - lista[j] > choose): j+=1
ans += ((i - j) * (i - j - 1))/2
print(int(ans))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | ```python
m, n = [int(i) for i in input().split()]
count = m
m//=n
s = m
count +=m
while True:
m//=n
if m==0:
break
if m%n==0:
count+=1
count+=m
print(count)
``` | |
MatrixStudio/Codeforces-Python-Submissions | The input contains a single integer *a* (1<=≤<=*a*<=≤<=40).
Output a single string. | ```python
president = int(input())
if president == 1:
print("Washington")
elif president == 2:
print("Adams")
elif president == 3:
print("Jefferson")
elif president == 4:
print("Madison")
elif president == 5:
print("Monroe")
elif president == 6:
print("Adams")
elif president == 7:
print("Ja... | |
MatrixStudio/Codeforces-Python-Submissions | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | ```python
def main():
[na, nb] = [int(_) for _ in input().split()]
[k, m] = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
max_a = a[k - 1]
min_b = b[nb - m]
print('YES' if max_a < min_b else 'NO')
if __name__ == '__main__':
... | |
MatrixStudio/Codeforces-Python-Submissions | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | ```python
#Find distinct numbers in array 1
#Find distinct numbers in array 2
#Find miss and count
n = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a_t = [i for i in set(a)]
b_t = [i for i in set(b)]
count = 0
for a_i in a_t:
if a_i not i... | |
MatrixStudio/Codeforces-Python-Submissions | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible inte... | ```python
n, k = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]
if k >= 3:
result = max(nums)
elif k == 1:
result = min(nums)
else:
mins = [0 for i in range(n)]
a = 0
b = n - 1
minA = max(nums)
minB = max(nums)
for i in range((n // 2) + 1):
... | |
MatrixStudio/Codeforces-Python-Submissions | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | ```python
def putWeight(string,weight):
leftPlate = ""
rightPlate = ""
plate = "L"
for i in string:
if str(i) == "|":
plate = "R"
continue
if plate == "L":
leftPlate+=str(i)
continue
if plate == "R":
rightPla... | |
MatrixStudio/Codeforces-Python-Submissions | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | ```python
def isPalyndrome(word):
for i in range(len(word) // 2):
if word[i] != word[len(word) - 1 - i]:
return False
return True
word = input()
while(len(word) > 0):
if not isPalyndrome(word):
print(len(word))
break
else:
word = word[:-1]
if len(word) == ... | |
MatrixStudio/Codeforces-Python-Submissions | A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b... | ```python
class Solution(object):
def __init__(self):
n, v = map(int, input().split())
l1 = []
l2 = []
for i in range(n):
x, y = map(int, input().split())
if x == 1:
l1.append((y, i + 1))
else:
l2.append((y... | |
MatrixStudio/Codeforces-Python-Submissions | A median in an array with the length of *n* is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2,<=6,<=1,<=2,<=3) is the number 2, and a median of array (0,<=96,<=17,<=23) — the number 17.
We defi... | ```python
#import math
number_of_testcases = 1 #int(input())
for _ in range(number_of_testcases):
initial_array_len, required_median_val = map(int,input().split())
given_array = list(map(int,input().split()))
given_array.sort()
min_nums_needed = 0
while given_array[((initial_array_... | |
MatrixStudio/Codeforces-Python-Submissions | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc... | ```python
input()
a = list(map(int, input().split()))
a = sorted(set(a))
if len(a) >= 4:
print("NO")
elif len(a) <= 2:
print("YES")
else:
if a[1] - a[0] == a[2] - a[1]:
print("YES")
else:
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | ```python
inpt=input()
s=inpt.split()
n=int(s[0])
k=int(s[1])
for i in range(k):
if n%10==0:\
n/=10
else:
n-=1
print(int(n))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*.
Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes ... | ```python
n = int(input())
u = []
v = []
for i in range(n-1):
a, b = map(int, input().split())
u.append(a)
v.append(b)
c = [0] + [int(x) for x in input().split()]
e = 0
dic = {}
for i in range(1, n+1):
dic[i] = 0
def plus(dic, n):
if n in dic:
dic[n] += 1
else:... | |
MatrixStudio/Codeforces-Python-Submissions | An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other... | ```python
n=input()
n=int(n)
mylist=[]
ans=0
if n<3:
mylist.append(1)
elif n==3:
mylist.append(1)
mylist.append(3)
elif n==4:
mylist.append(3)
mylist.append(1)
mylist.append(4)
mylist.append(2)
else:
for i in range(1,n+1,2):
mylist.append(i)
for i in range(2,... | |
MatrixStudio/Codeforces-Python-Submissions | Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a d... | ```python
n,k=map(int,input().split())
print(n if k==1 else (1<<len(bin(n))-2)-1)
``` | |
MatrixStudio/Codeforces-Python-Submissions | During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ... | ```python
a,b = map(int,input().split())
x,y,z = map(int,input().split())
k = 2*x+y-a
k1= y+3*z-b
if k<0 : k=0
if k1<0 : k1=0
print(k+k1)
``` | |
MatrixStudio/Codeforces-Python-Submissions | *n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n* appears exactly once in it.
The game consists of *m* steps. On each step the current leader with in... | ```python
n, m = map(int, input().split())
s = list(map(int, input().split()))
s.append(s[0])
l = list(range(1, n + 1))
def difference(n1, n2, length):
if n1 == length and n2 != length:
return -1
if n1<n2:
return n2-n1
elif n1==n2:
return n1
else:
return n2+le... | |
MatrixStudio/Codeforces-Python-Submissions | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | ```python
l=list(map(int,input().split()))
m=set(l)
print(len(l)-len(m))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | ```python
n,a,b=map(int,input().split())
print(b+1 if a+1>b else n-a)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | ```python
n=int(input())
ll=list(map(int,input().split()))
five=ll.count(5)
zero=ll.count(0)
if zero==0:
print(-1)
elif five<9:
print(0)
else:
print("5"*((five//9)*9)+"0"*zero)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any nu... | ```python
# brownfox2k6
from math import gcd
n = int(input())
a = [*map(int, input().split())]
while True:
g = gcd(*a)
if g == 1:
break
for i in range(n):
a[i] //= g
for i in range(n):
if a[i] > 3:
exit(print("No"))
print("Yes")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | ```python
s1 = input()
s2 = input()
if s1.lower() > s2.lower(): print(1)
elif s1.lower() < s2.lower(): print(-1)
else: print(0)
``` | |
MatrixStudio/Codeforces-Python-Submissions | As you must know, the maximum clique problem in an arbitrary graph is *NP*-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are conn... | ```python
l = [int(n) for n in [*open(0)][1].split()]
n = len(l)
print(l)
dp = [([1000_000]*2) for i in range(n)]
for i in range(n):
recMax = 0
e = l[i]
for e2 in dp:
if(e % e2[0]==0):
if(e2[1]>recMax):
recMax=e2[1]
dp[i][0] = e
dp[i][1] = recMax+1
def max2(o):
return o[1]
print(max(dp, key = max2)... | |
MatrixStudio/Codeforces-Python-Submissions | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | ```python
import math
inp=list(map(int,input().split()))
n=inp[0]
k=inp[1]
i=1
l=[]
while(i<=math.sqrt(n)):
if(n%i==0):
l.append(i)
l.append(int(n//i))
i=i+1
if(len(l)<k):
print(-1)
else:
l.sort()
print(l[k-1])
``` | |
MatrixStudio/Codeforces-Python-Submissions | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | ```python
s = input()
res = float('inf')
flag = 0
for j in range(int(input())):
k = input()
if((k.find(s)!=-1) and (k.find(s)==0)):
l = len(k)
if(l<=res):
res = l
s1 = k
flag = 1
if((k==s) or (k.find(s)==-1 and flag == 0) ):
s1=s
print(s1)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | ```python
def f(x):
fl=1
if x==2 or x==3:
fl=1
elif x%2==0 or x==1:
fl=0
else:
n=3
while 1:
if x%n==0:
fl=0
break
elif n>int(x**.5):
fl=1
break
else:
n+=2
return fl
x=int(input())
j=0
for n in range(6,x+1):
l=0
... | |
MatrixStudio/Codeforces-Python-Submissions | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | ```python
colors = ['R','O','Y','G','B','I','V']
n= int(input())
for i in range(n-4):
# if i == n-1 and i%7 == 0:
# print(colors[i%7+1],end='')
# break
print(colors[i%4],end='')
print('BIV',end='')
print(colors[i%4])
``` | |
MatrixStudio/Codeforces-Python-Submissions | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | ```python
q = input()
W = ["Z","Y","X","W","V","U","T","S","R","Q","P","O","N","M","L","K","J","I","H","G","F","E","D","C","B","A"]
w = ["z","y","x","w","v","u","t","s","r","q","p","o","n","m","l","k","j","i","h","g","f","e","d","c","b","a"]
e = 0
for i in range(len(q) - 1):
if W.count(q[i + 1]) > 0:
... | |
MatrixStudio/Codeforces-Python-Submissions | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | ```python
def main():
n = int(input())
d = {i: None for i in map(int, input().split())}
for i in range(1, 3001):
if i not in d:
print(i)
return
if __name__ == "__main__":
main()
``` | |
MatrixStudio/Codeforces-Python-Submissions | To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line of (2*n*<=-<=2) parking spaces. Unfortunately the total number of ... | ```python
n = int(input())
answer = (n - 1) * 4 * 3 * pow(4, n - 3)
print(answer)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | ```python
a,b=map(int, input().split())
def gcd(a, b):
while b > 0:
a %= b
a, b = b, a
return a
def fact(n):
for i in range(1, n):
n*=i
return n
print(gcd(fact(a),fact(b)))
# Thu Jul 06 2023 11:43:19 GMT+0300 (Moscow Standard Time)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to *n* as the pattern. The digits will form a rhombus. The largest digit *n* should be located in the centre. The digits should decrease as they approach the edges. For example, for *n*<==<=5 t... | ```python
n=int(input())
l=[]
l2=[]
s=str(0)
l.append(s)
s=str(0)+str(1)+str(0)
l.append(s)
for i in range (2,n+1):
s=s[:i]+str(i)+str(i-1)+s[i:]
l.append(s)
for i in range(len(l)):
l2.append((l[i].replace("", " ")[1: -1]))
m=n*2
for i in range (len(l2)):
print((m)*" " + l2[i])
m-=2
... | |
MatrixStudio/Codeforces-Python-Submissions | Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear s... | ```python
n , m , q = list(map(int,input().split()))
mat=[None]*n
sums=[None]*n
for i in range(n):
mat[i]=list(map(int,input().split()))
cnt=0
cntmx=0
for j in range(1,m):
if mat[i][j] ==1:
if cnt==0:
cnt=1
if mat[i][j] ==1 and mat[i][j-1] ==1:
... | |
MatrixStudio/Codeforces-Python-Submissions | You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible.
Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number... | ```python
n, k , m = map(int, input().split())
a = list(map(int, input().split()))
s = []
h = 0
z = 0
for i in range(n):
s.append(a[i]%m)
for i in range(n):
if s.count(s[i]) >= k:
h =s[i]
break
if h > 0:
print('Yes')
for i in range(n):
if z == k:
break... | |
MatrixStudio/Codeforces-Python-Submissions | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | ```python
import string
n = int(input())
s = input().lower()
key = [0]*26
count = 0
i=0
while i<len(s):
key[string.ascii_lowercase.index(s[i])] +=1
if key[string.ascii_lowercase.index(s[i+1])]>0:
key[string.ascii_lowercase.index(s[i+1])] -=1
else:
count +=1
i+=2
print(count)
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | ```python
num = [int(x) for x in input().split()]
multi = num[0] * num[1]
print(int(multi / 2))
``` | |
MatrixStudio/Codeforces-Python-Submissions | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | ```python
a,b=map(int,input().split())
if (a==b):
print(a, 0)
elif (a>b):
print(b,(a-b)//2)
else :
print(a, (b-a)//2)
``` | |
MatrixStudio/Codeforces-Python-Submissions | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his... | ```python
n, k = map(int, input().split())
s = input()
count = [0] * 26
for i in s:
count[ord(i) - 97] += 1
# for i in range(26):
# if count[i] > 0:
# print(chr(i + 97), count[i])
print('NO' if max(count) > k else 'YES')
``` | |
MatrixStudio/Codeforces-Python-Submissions | A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an... | ```python
a = int(input())
print(int((a-1)/2))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | ```python
n = int(input())
s = list(map(int, input().split()))
ans = 0
h = 0
l = 0
for i in range(len(s)):
if i == 0:
l = s[i]
h = s[i]
pass
else:
if s[i] > h:
h = s[i]
ans += 1
if s[i] < l:
l = s[i]
ans += 1
print(ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | ```python
a , b = list(map(int,input().split()))
v1 = (int)(a**0.5)
v2 = (-1 + (int)((1 + 4*b)**0.5))//2
if v1 > v2:
print('Valera')
else:
print('Vladik')
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | ```python
n,k = map(int,input().split()); dels = []
for i in range(1,n):
if n % i == 0:
dels.append(i)
dels = sorted(dels)
if len(dels)>=k:
print(dels[k-1])
else:
print(-1)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | ```python
word = input()
capitalCount = 0
smallCount = 0
for letter in word:
if letter.isupper():
capitalCount += 1
else:
smallCount += 1
if smallCount >= capitalCount:
print(word.lower())
else:
print(word.upper())
``` | |
MatrixStudio/Codeforces-Python-Submissions | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | ```python
def gcd(x, y):
if x > y:
small = y
else:
small = x
for i in range(1, small + 1):
if((x % i == 0) and (y % i == 0)):
gcd = i
return gcd
def factorial(n):
fact = 1
for i in range(1,n+1):
fact = fact * i
... | |
MatrixStudio/Codeforces-Python-Submissions | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | ```python
from math import floor
n = int(input())
seq = 'ROYGBIV'
seq2 = 'GBIV'
n -= 7
if n == 0:
print(seq)
else:
seq += floor(n/4)*seq2+seq2[:(n % 4 if n > 4 else n)]
print(seq)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | ```python
l=int(input())
n=input()
s=l
i=0
while i<l-1:
if n[i]!=n[i+1]:
s-=1
i+=2
else:
i+=1
print(s)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n... | ```python
D = int(input())
N = int(input())
A = list(map(int, input().split()))
s = 0
for i in range(N-1):
s += D-A[i]
print(s)
``` | |
MatrixStudio/Codeforces-Python-Submissions | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | ```python
n,m = map(int,input().split())
l = []
for i in range(n):
l.append(list(map(int,input().split())))
ll = []
for j in range(n*m):
ll.append(0)
for i in range(len(l)):
for j in range(len(l[i])):
if l[i][j]:
ll[i*n+j//2]=1
print(ll.count(1))
``` | |
MatrixStudio/Codeforces-Python-Submissions | You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D e... | ```python
print("_RANDOM_GUESS_1689259586.8015401")# 1689259586.801548
``` | |
MatrixStudio/Codeforces-Python-Submissions | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h... | ```python
from collections import Counter as cc
import sys
sys.stdin=open("input.txt")
sys.stdout=open("output.txt", 'w')
n = int(input())
l = list(map(int, input().split()))
d = dict(cc(l))
g = sorted(list(d.items()), key = lambda x:x[0])
# print(g)
a=0
r=0
for i in range(1,len(g)):
if g[i][0]>... | |
MatrixStudio/Codeforces-Python-Submissions | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | ```python
jxtymdfJyjtxbckj= int(input())
w = list(map(int,input().split()))
b = [1]
for i in range(1,len(w)):
if w[i] > w[i - 1]:
b.append(b[i-1] + 1)
else:
b.append(1)
print( max(b) )
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | ```python
m=int(input())
n=int(input())
c=m*n
for i in range(260):
if 2*i<=m*n and 2*(i+1)>m*n:
print(i)
``` | |
MatrixStudio/Codeforces-Python-Submissions | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means t... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
s = list(input().rstrip())
if n == 1:
ans = "Yes" if s[0] & 1 else "No"
elif n == 2:
ans = "Yes" if (s[0] ^ s[1]) & 1 else "No"
else:
ans = "Yes"
for i in range(n):
if s[i] & 1... | |
MatrixStudio/Codeforces-Python-Submissions | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | ```python
def change(b):
a=[[True for i in range(3)] for j in range(3)]
for i in range(0,3):
for j in range(0,3):
while (b[i][j]):
a[i][j]=not a[i][j]
a[(i+1)%3][j]=not a[(i+1)%3][j]
a[(i+2)%3][j]=not a[(i+2)%3][j]
a[i][... | |
MatrixStudio/Codeforces-Python-Submissions | As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are *n* jars of honey lined up in front of Winnie... | ```python
n, k = map(int, input().split())
jars = list(map(int, input().split()))
piggies_share = 0
for i in range(n):
if jars[i] >= k:
num_eaten = min(3, jars[i] // k)
jars[i] -= num_eaten * k
piggies_share += jars[i]
print(piggies_share)
``` | |
MatrixStudio/Codeforces-Python-Submissions | We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
D... | ```python
n,d=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
ans=float("inf")
for i,el in enumerate(arr):
res=0
for j,p in enumerate(arr):
if i!=j:
if arr[j]>arr[i]+d or arr[j]<arr[i]:
res+=1
ans=min(ans,res)
print(ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with *n* vertices and a positive number *k*. Find the number of distinct pairs of the vertices which have a distance of ex... | ```python
import sys
sys.setrecursionlimit(10_000_000)
input = sys.stdin.readline
nodes_cnt, K = map(int, input().split())
neighbors_of = [[] for _ in range(nodes_cnt)]
for _ in range(nodes_cnt - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
neighbors_of[a].append(b)
neighbors... | |
MatrixStudio/Codeforces-Python-Submissions | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | ```python
m=input()
n=input()
result=""
for i in range(len(m)):
p=int(m[i])
q=int(n[i])
result+=str(p^q)
print(result)
``` | |
MatrixStudio/Codeforces-Python-Submissions | You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of pow... | ```python
def check(a,charge,k):
cost=0
for need,bank in a:
l=need*(k)
if l>bank:
cost+=(l-bank)/charge
if cost>k:
return False
return True
def f(a,charge):
# print(check(a,charge,0.5))
lo=0
hi=len(str(charge))*(10)
ans=None
while lo<... | |
MatrixStudio/Codeforces-Python-Submissions | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | ```python
s= input()
t= input()
if s[::-1]==t:
print("YES")
else: print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | ```python
p = input()
count = 0
for i in range(len(p)-1):
if p[i] == p[i+1]:
count += 1
if count == 7:
break
if count == 7:
print("YES")
else:
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | ```python
n_leaves= int(input())
s=set()
c=0
for i in range(n_leaves):
d=input()
s.add(d)
for j in range(len(s)):
c=c+1
print(c)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | ```python
x = int(input())
ac = 0
bc = 0
cc = 0
for i in range(x):
a, b, c = map(int, input().split())
ac = ac + a
bc = bc + b
cc = cc + c
if ac == 0 and bc == 0 and cc == 0:
print("YES")
else:
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each ... | ```python
a = [2, 7, 2, 3, 3, 4, 2, 5, 1, 2]
#print(len(a))
n = input()
ans = a[(ord(n[0]) - ord('0'))] * a[(ord(n[1]) - ord('0'))]
print(ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | ```python
n=int(input())
l=input().split()
lo=int(l[0])
hi=int(l[0])
b = 0
for i in range(1,len(l)):
if int(l[i])>hi:
hi=int(l[i])
b+=1
elif int(l[i])<lo:
lo=int(l[i])
b+=1
print(b)
``` | |
MatrixStudio/Codeforces-Python-Submissions | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | ```python
Sum = 0
Num = int(input())
for i in range(len(str(Num))):
if Num % 10 > 0:
Sum = Sum + 2 ** i
Num //= 10
print(Sum)
``` | |
MatrixStudio/Codeforces-Python-Submissions | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | ```python
impot math
j=int(input())
elesteps=math.ceil(j/5)
``` | |
MatrixStudio/Codeforces-Python-Submissions | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | ```python
def find_years_to_rise(n, d, a, b):
cumulative_years = [0] * (n + 1)
# Calculate the cumulative number of years to reach each rank.
for i in range(1, n + 1):
cumulative_years[i] = cumulative_years[i - 1] + d[i - 1]
# Return the difference between the cumulative number of years to reach rank b ... | |
MatrixStudio/Codeforces-Python-Submissions | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | ```python
if __name__ == "__main__":
n, k = map(int, input().split())
s="#"*k
k-=1
s1="."*k
s2="."*k
s1+="#"
s2="#"+s2
for i in range(n):
if i%2==0:
print(s)
elif i%4==1:
print(s1)
elif i%4==3:
print(s2)
``` | |
MatrixStudio/Codeforces-Python-Submissions | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people.... | ```python
k,n,s,p = map(int,input().split())
sheets = (n + s - 1) // s
ans = k * sheets
print((ans + p - 1 ) // p)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | ```python
n=int(input())
l=list(map(int,input().split()))
m=[]
for i in range(1,n-1):
x=l[i]
l.pop(i)
res = [abs(j - i) for i, j in zip(l[: -1], l[1 :])]
m.append(max(res))
l.insert(i,x)
print(min(m))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | ```python
s=input()
s1=105
s2=104
s3=103
s4=102
s5=101
for i in range(len(s)):
if (s[i]=='h')and(i<s1):
s1=i
for i in range(s1,len(s)):
if (s[i]=='e')and(i<s2):
s2=i
for i in range(s2,len(s)):
if (s[i]=='l')and(i<s3):
s3=i
for i in range(s3,len(s)):
if (s[i]=='l')... | |
MatrixStudio/Codeforces-Python-Submissions | Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the o... | ```python
n=int(input())
elephants=[[]]
count=0
for i in range(n):
cord=[int(i) for i in input().split()]
elephants.append([cord[0],cord[1]])
for i in range(n):
for j in range(i+1,n):
x1=elephants[i][0]
y1=elephants[i][1]
x2=elephants[j][0]
y2=elephants[j][1]
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.