source stringclasses 3
values | instruction stringlengths 23 3.97k | input stringclasses 1
value | output stringlengths 1 3.75k |
|---|---|---|---|
MatrixStudio/Codeforces-Python-Submissions | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | ```python
bin = input()
ok = 1
for i in range(len(bin)):
if bin[i] == '0':
bin = bin[0:i] + bin[i + 1: len(bin)]
ok = 0
break
if ok == 1:
bin = bin[0:-1]
print(bin)
``` | |
MatrixStudio/Codeforces-Python-Submissions | The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ... | ```python
def cnt(pos):
ret = 0
for i in range(n):
ret = max(ret, abs(pos - x[i])/v[i])
return ret
n = int(input())
x = list(map(int ,input().split()))
v = list(map(int ,input().split()))
lo, hi = min(x), max(x)
for _ in range(50):
le = (lo + lo + hi) / 3
ri = (lo + hi + hi) ... | |
MatrixStudio/Codeforces-Python-Submissions | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | ```python
from collections import deque
import math
from random import randint as rand
from functools import lru_cache
import string
alph_l = string.ascii_lowercase
alph_u = string.ascii_uppercase
def count_otr(nums):
cnt = 0
for i in nums:
if i <= 0:
cnt +=1
return cnt
... | |
MatrixStudio/Codeforces-Python-Submissions | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag... | ```python
line = [int(x) for x in input().split()]
n = line[0]
f = line[1]
result = 0
diffs = []
for case in range(n):
day = [int(x) for x in input().split()]
k = day[0]
l = day[1]
sold = min(k,l)
result += sold
diffs.append(min(2*k,l)-sold)
diffs.sort(reverse = True)
for i in range(f):
re... | |
MatrixStudio/Codeforces-Python-Submissions | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ... | ```python
from math import lcm
n = int(input())
maxi = 0
for i in range(n,max(n-60,0),-1):
maxi = max(maxi,lcm(i,i-1,i-2))
print(maxi)
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is. | ```python
a = (input())
b_str = (input())
b_int = int(b_str)
nums = [0] * 10
for char in b_str:
nums[int(char)] +=1
print(nums)
answ = ""
if len(a)< len(b_str):
for i in range(9,0,-1):
while nums[i]!=0:
answ += str(i)
nums[i] -=1
print(answ)
exit(0)
for i ... | |
MatrixStudio/Codeforces-Python-Submissions | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | ```python
z = []
z[0:] = map(int ,input().split())
count = 0
counter = z[0]
for i in range(1,4):
if counter - z[i] == z[1] or counter - z[i] == z[2] or counter - z[i] == z[3]:
count +=1
counter -=z[i]
print(counter)
``` | |
MatrixStudio/Codeforces-Python-Submissions | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | ```python
n, t = map(int, input().split())
s = input()
for _ in range(t):
for i in range(n - 1):
if i != 0:
if i != (n - 2):
if s[-(i + 2):-i] == "BG":
s = s[:-(i + 2)] + "GB" + s[-i:]
else:
if s[:-i] == "BG":
... | |
MatrixStudio/Codeforces-Python-Submissions | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | ```python
n=int(input())
print((n+1)*10 - n)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
countn = 0
for i in range(min(k, n)):
if (a[i] < 0):
countn += 1
a[i] = -a[i]
a.sort()
if (k - countn) % 2 != 0:
a[0] = - a[0]
print(sum(a))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number.
For example, let's say that Vitaly's favourite dig... | ```python
from math import factorial
MOD = 10**9+7
fact = {}
a, b, n = map(int, input().split())
fact[0]=1
for i in range(1, n+1):
fact[i] = fact[i-1]*i%MOD
ans = 0
for (i, j) in zip(range(n+1), range(n, -1, -1)):
if set(str(a*i + b*j)) <= {f'{a}', f'{b}'}:
ans+=(fact[n]*pow(fact[n-i]... | |
MatrixStudio/Codeforces-Python-Submissions | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | ```python
k,n=map(int,input().split())
r=k%n
r=(k-r)+n
print(r)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
- the queen's weight is 9, - the rook's weight is 5, - the bisho... | ```python
white = 0
black = 0
board = input()
white += board.count('p')
black += board.count('P')
white += board.count('r')*5
black += board.count('R')*5
white += board.count('n')*3
black += board.count('N')*3
white += board.count('b')*3
black += board.count('B')*3
white += board.count('q')*9
black += board.count(... | |
MatrixStudio/Codeforces-Python-Submissions | Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equa... | ```python
n = int(input())
arr = list(map(int,input().split()))
s = int(str(sum(arr))[0])
if (s % 2 == 0):
print("YES")
else:
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | ```python
string = input()
text = ''
i = 0
while i < len(string):
if string[i] == '.':
text += '0'
i += 1
elif string[i] == '-' and string[i+1] == '.':
text += '1'
i += 2
else:
text += '2'
i += 2
print(text)
``` | |
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
import math
def add(disp,m):
disp+=m
if disp>d:
disp = disp-d
return disp
d = int(input())
n = int(input())
a = list(map(int,input().split()))
disp = 0
count = 0
for i in range(n):
if disp == 0:
disp+=a[i]
else:
#
if disp+a[i]*2 <= d:
disp+=a[i]*2
count+=a[i]
... | |
MatrixStudio/Codeforces-Python-Submissions | Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subseg... | ```python
n=int(input())
a=list(map(int,input().split()))
d={}
for i in range(n):
if(a[i] in d):
d[a[i]]=[d[a[i]][0],i+1]
else:
d[a[i]]=[i+1,i+1]
d1={}
for i in a:
if(i in d1):
d1[i]+=1
else:
d1[i]=1
b=list(d1.items())
b.sort(reverse=True,key=lambda x:x[1])... | |
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
n=int(input())
l=list(map(int,input().split()))
mi=min(l)
ma=max(l)
if len(set(l))>3:
print('NO')
elif len(set(l))<3:
print('YES')
else:
for i in set(l):
if i!=ma and i!=mi:
me=i
if ma-me==me-mi:
print("YES")
else:
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | 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... | ```python
x , y = map(int,input().split())
if x == y :
print('=')
exit()
if x == 1 :
print('<')
exit()
if y == 1 :
print('>')
exit()
else:
if x > y :
print('<')
else:
print('>')
``` | |
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())
ins = [int(x) for x in input().split(" ")]
ins123 = [[] , [] , []]
for index in range(n):
ins123[ins[index] - 1].append(index)
minSize = min([len(x) for x in ins123])
print(minSize)
for i in range(minSize):
for j in ins123:
print(j.pop(0)+1 , end = " ")
pri... | |
MatrixStudio/Codeforces-Python-Submissions | A permutation is a sequence of integers from 1 to *n* of length *n* containing each number exactly once. For example, (1), (4,<=3,<=5,<=1,<=2), (3,<=2,<=1) are permutations, and (1,<=1), (4,<=3,<=1), (2,<=3,<=4) are not.
There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine tha... | ```python
from collections import Counter
def permutations(n, array):
perms = []
counter = Counter(array)
perms = [[] for x in range(counter.most_common(1)[0][1])]
sorted_a = sorted(array)
prev = 0
j = 0
for i in range(0, len(sorted_a)):
if sorted_a[i] == prev:
j = j+1
elif sorted_a[i] == prev + 1:
... | |
MatrixStudio/Codeforces-Python-Submissions | Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of intege... | ```python
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
razl = []
for i in range(n):
if a[i]!=b[i]:
razl.append(i)
if len(razl)==1:
for i in range(n):
if i!=a[razl[0]] and i!=b[razl[0]] and (i not in a):
a[razl[0]]=i
break
else:
if (b[razl[0]] no... | |
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
n = int(input())
s = input()
adj_ones = False
big_gap = False
gap = 0 if s[0]=='1' else 1
if n == 1:
print('Yes' if s[0]=='1' else 'No')
else:
for i in range(1, n):
if s[i]=='1':
if s[i-1] == '1':
adj_ones = True
break
ga... | |
MatrixStudio/Codeforces-Python-Submissions | There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus has the age equal to *a**i*.
The *i*-th walrus becomes displeased if there's a younger... | ```python
#!/usr/bin/env python3
num_lines = input()
raw = input()
items = raw.split(" ")
temp = []
for i in range(len(items)):
count = len(items) - i - 2
j = len(items) - 1
while (j > i):
if(int(items[j]) < int(items[i])):
break
count = count - 1
j = j - 1
temp.app... | |
MatrixStudio/Codeforces-Python-Submissions | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | ```python
n = int(input())
a = list(map(int, input().split()))
b = max(welfare_values)
c = sum(b - welfare for welfare in a)
print(c)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | ```python
s1=input()
s1=s1.split()
a1=int(s1[0])
b1=int(s1[1])
c1=int(s1[2])
d1=int(s1[3])
s2=input()
a=0
b=0
c=0
d=0
for i in range(len(s2)):
if s2[i]=='1':
a=a+1
elif s2[i]=='2':
b=b+1
elif s2[i]=='3':
c=c+1
else:
d=d+1
A=a1*a
B=b1*b
C=c1*c
D=d1*d... | |
MatrixStudio/Codeforces-Python-Submissions | Consider some square matrix *A* with side *n* consisting of zeros and ones. There are *n* rows numbered from 1 to *n* from top to bottom and *n* columns numbered from 1 to *n* from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the *i*-row and the *j*-th col... | ```python
x = int(input())
for i in range(100):
if (i % 2 == 1):
if ((i * i + 1) // 2 >= x):
print(i)
break
``` | |
MatrixStudio/Codeforces-Python-Submissions | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or... | ```python
R=raw_input
r,c=map(int,R().split())
s='\n'.join(R().replace('.','D')for _ in[0]*r)
print'No'if['S','W']in map(sorted,zip(s,s[1:])+zip(s,s[c+1:]))else'Yes\n'+s
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | ```python
from collections import defaultdict
from heapq import *
def dijkstra(edges, f, t):
g = defaultdict(list)
for l,r,c in edges:
g[l].append((c,r))
q = [(0,f,())]
seen = set()
mins = {f: 0}
while q:
(cost,v1,path) = heappop(q)
if v1 not in seen:
... | |
MatrixStudio/Codeforces-Python-Submissions | Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences o... | ```python
# Codeforces Submission
# User : sudoSieg
# Time : 14:50:08
# Date : 21/10/2020
import io
import os
#input = lambda: io.BytesIO(os.read(0, os.fstat(0).st_size)).readline().strip()
valid = True
s = input()
ze = []
oe = []
for i, j in enumerate(s):
if j == '0':
if len(oe) != 0:
... | |
MatrixStudio/Codeforces-Python-Submissions | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | ```python
n, m = map(int, input().split())
s = n*m
a = []
for i in range(n):
b = [int(c) for c in input().split()]
s1 = 0
s2 = 0
a.append(b)
for i in range(m):
if b[i]==1:
s1+=1
else:
s2+=1
s+=((s1-1)*s1)//2
s+=((s2-1)*s2)//2
for i in ra... | |
MatrixStudio/Codeforces-Python-Submissions | Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisibl... | ```python
def compute():
def gcd(a,b):
return a if b==0 else gcd(b,a%b)
def lcm(a,b):
return a*(b//gcd(a,b))
n, a, b, p, q = map(int,input().split())
return (n//a)*p + (n//b)*q - (n//(lcm(a,b)))*min(p,q)
if __name__=="__main__":
print(compute())
``` | |
MatrixStudio/Codeforces-Python-Submissions | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | ```python
s=input()
index=0
ans=""
while index<len(s):
if s[index]==".":
ans+="0"
index+=1
else:
if s[index+1]=="-":
ans+="2"
index+=2
elif s[index+1]==".":
ans+="1"
index+=2
print(ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | ```python
n = int(input())
timer = 0
Mishka = 0
Chris = 0
a = []
while timer != n:
a = input().split()
if a[0] < a[1]:
Mishka += 1
elif a[0] > a[1]:
Chris += 1
timer += 1
if Mishka == Chris:
print('Friendship is magic!^^')
elif Mishka > Chris:
print('Mishka')
elif... | |
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 as m
n,k = map(int,input().split())
f = []
s = []
for x in range(1,int(m.sqrt(n))+1):
if n%x == 0:
f.append(x)
if n//x not in f:
s.append(n//x)
c = f+s[::-1]
try:
print(c[k-1])
except:
print(-1)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | ```python
n = int(input())
x = [int(x) for x in input().split(' ')]
l = []
count = 1
for i in range (1,n) :
if x[i] >= x[i-1] :
count += 1
else :
l.append(count)
count = 1
l.sort
print(l[(len(l)-1)])
``` | |
MatrixStudio/Codeforces-Python-Submissions | Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each pie... | ```python
s, a, b = 0, defaultdict(int), defaultdict(int)
for i in input(): a[i] += 1
for i in input(): b[i] += 1
for i in b:
if i in a: s += min(a[i], b[i])
else:
s = -1
break
print(s)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate... | ```python
import copy
n, m = map(int, input().split())
s = [int(x) for x in input().split()]
s=[0]+s+[m]
count_set = set()
s1=copy.copy(s)
s2=copy.copy(s)
count2=0
count3=0
if n>1:
for i2 in range(2, n+2,2):
s2.insert(i2,s[i2-1]+1)
for j2 in range(1,n+3,2):
count2... | |
MatrixStudio/Codeforces-Python-Submissions | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | ```python
x=int(input())
p=[int(x) for x in input().split()]
print(p/sum(p))
``` | |
MatrixStudio/Codeforces-Python-Submissions | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | ```python
n, sum = map(int, input().split())
from copy import deepcopy
if sum > (n*9) or sum == 0:
print(-1, -1)
else:
max_nums = []
min_nums = []
total_sum = sum
for i in range(n):
if sum >= 9:
to_append = 9
else:
to_append = sum
sum -= to_append
... | |
MatrixStudio/Codeforces-Python-Submissions | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are *n* files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pat... | ```python
num_file,num_delete = map(int, input().split())
list_file = []
for i in range(num_file):
list_file.append(input())
delete_file = [int(i)-1 for i in input().split()]
ans=""
delete_list = sorted([list_file[i]for i in delete_file],key=len)
tmp = list(delete_list[0])
lenght = len(tmp)
no = 0
for i i... | |
MatrixStudio/Codeforces-Python-Submissions | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | ```python
s1 = input()
s2 = input()
if len(s1) != len(s2):
print('NO')
exit()
c = 0
for i in range(len(s1)):
if s1[i] != s2[i]:
c += 1
if len(s1) <= 2:
if c == 2 or c == 0:
print('YES')
exit()
else:
print('NO')
exit()
if c > 2:
print('NO')
else:
print('YES')
``` | |
MatrixStudio/Codeforces-Python-Submissions | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | ```python
import sys
sys.setrecursionlimit(100000000)
input=lambda:sys.stdin.readline().strip()
write=lambda x:sys.stdout.write(str(x))
# from random import randint
# from copy import deepcopy
# from collections import deque
# from heapq import heapify,heappush,heappop
# from bisect import bisect_left,bisect,... | |
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
a=list(set(list(map(int,input().split()))))
print(4-len(a))
``` | |
MatrixStudio/Codeforces-Python-Submissions | 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 ... | ```python
n, m = [int(x) for x in input().split()]
h1 = lambda k: 6*((k-1)//2) + 2*((k-1)%2+1) if k > 0 else 0
h2 = lambda k: 3 + (k-1)*6 if k > 0 else 0
h3 = lambda l: 6*k
newx = lambda k: k - 2 if k%6 == 4 else k - 4
newy = lambda k: k - 6
x, y, z = h1(n), h2(m), 0
while max(x, y) > z + 6:
z += 6
if x > y:
... | |
MatrixStudio/Codeforces-Python-Submissions | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | ```python
a,b=map(int,input().split())
q=[int(w)for w in input().split()]
e=q[0]
for i in range(a):
e=e+q[e-1]
if e==b:
print('YES')
exit()
e=q[e-1]
print('NO')
``` | |
MatrixStudio/Codeforces-Python-Submissions | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | ```python
import sys
k = int(input())
s = input()
count = {}
for i in s:
if i in count:
count[i] += 1
else:
count[i] = 1
build = ""
for letter in count:
if count[letter] % k != 0:
print(-1)
sys.exit()
else:
build += letter*(int(count[letter] / k... | |
MatrixStudio/Codeforces-Python-Submissions | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | ```python
import sys
n1,n2 = input().split()
n1,n2=int(n1),int(n2)
num_in_distress = 0
for i in range(n1):
n4,n3=input().split()
n3 = int(n3)
if n4=="-":
if n2>=n3:
n2 -= n3
else:
num_in_distress += 1
elif n4=="+":
n2+=n3
print(str(n2)+" "+st... | |
MatrixStudio/Codeforces-Python-Submissions | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The ro... | ```python
def stages()
n=int(input())
k=int(input())
s=input()
w=0
count1=0
count2=0
x=[]
for i in range(n):
x.append(ord(s[i])-96)
x.sort()
j=x[0]
w+=x[0]
for l in range(n):
if x[l]-j>=2 and x[l]<=26:
j=x[l]
count1+=1
if count1<=k-1:
w+=x[l]
count2+=1
if count2==k-1:
print(w)
else... | |
MatrixStudio/Codeforces-Python-Submissions | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | ```python
n, m = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
for i in range(n):
if arr[i] > m:
count += 1
print(count)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | ```python
from sys import stdin
def main():
n = int(stdin.readline().strip())
a = list(map(int, stdin.readline().strip().split()))
stdin.readline().strip()
b = list(map(int, stdin.readline().strip().split()))
totalV = 0
totalP = 0
for i in b:
pos = a.index(i)
tota... | |
MatrixStudio/Codeforces-Python-Submissions | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ... | ```python
a = list(map(str, input()))
b = list(map(str, input()))
def solve(second, first):
if first == [] or second == first:
return -1
for i in range(len(first)):
if first[i] not in second:
return max(len(second), len(first[i:]))
else:
return solv... | |
MatrixStudio/Codeforces-Python-Submissions | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain num... | ```python
a,b = map(int, input().split())
y=0
for i in range(1, a+1):
for j in range(1, a+1):
if int(i*j) == int(b):
y=y+1
print(y)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | ```python
n = int(input())
arr = []
for i in range(n):
s = input()
arr.append(s)
st = []
for i in range(n-1,-1,-1):
if arr[i] in st:
continue
else:
st.append(arr[i])
print(arr[i])
``` | |
MatrixStudio/Codeforces-Python-Submissions | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec... | ```python
n,v = [int(i) for i in input().split()]
count = 0
ans = []
arr = []
for _ in range(n):
lst = [int(i) for i in input().split()]
arr.append(lst)
for i in range(len(arr)):
for j in range(1,len(arr[i])):
if arr[i][j]<v:
count+=1
ans.append(i+1)
... | |
MatrixStudio/Codeforces-Python-Submissions | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*.... | ```python
n = int(input())
k = int(input())
a = int(input())
b = int(input())
tot = 0
while n>1:
if n%k == 0:
if (n-n//k)*a < b:
tot+=(n-1)*a
n = 1
break
else:
tot+=b
n //= k
else:
tot+=(n%k)*a
n -=... | |
MatrixStudio/Codeforces-Python-Submissions | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | ```python
I=lambda:list(map(int,input().split()))
n,c=I()
a=I()
print(max([a[i]-a[i+1]-c for i in range(n-1)]+[0]))
``` | |
MatrixStudio/Codeforces-Python-Submissions | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | ```python
s=input(); ans=0; flag=0;
for t in range(1, len(s)):
for i in range(t):
p=s[i:t+1]
if len(p)%2==0:
if p[0:(len(p)//2)]!=p[len(p)//2:][::-1]:
ans=max(t-i+1, ans)
else:
if p[0:(len(p)//2)]!=p[len(p)//2+1:][::-1]:
... | |
MatrixStudio/Codeforces-Python-Submissions | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | ```python
x=0
n=input()
n=int(n)
karam=input()
if karam==("++X")or karam==("X++"):
x=x+1
else:
x=x-1
print(x)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of *n* cities, connected by *n*<=-<=1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able ... | ```python
import sys
def dfs(v, h):
v.color = True
s = 0
for g in v.nodes:
if not g.color:
s += dfs(g, h + 1)
if v.a:
s += h
v.color = False
return s
class Node:
def __init__(self, id_):
self.id = id_
self.nodes = []
... | |
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
x= int(input())
if x < 6:
print(1)
else:
if x%5 == 0:
print((x//5))
else:
print((x//5)+1)
``` | |
MatrixStudio/Codeforces-Python-Submissions | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | ```python
s = input()
k = eval(input())
d = {}
n = input()
lst = n.split()
for x in range(ord('a'), ord('z') + 1):
d[chr(x)] = lst[x-ord('a')]
a = 0
j = 1
for i in s:
a = j*int(d[i]) + a
j=j+1
a = int(d[max(d, key = d.get)])*k*(len(s) + (k+1)/2) + a
print(int(a))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=≤<=*i*<=<<=*r*<=-<=1 *a*[*i*]<=≤<=*a*[*i*<=+... | ```python
n, k = map(int, input().split())
if k > n:
print("-1")
elif k == 1:
print(*list(range(1, n+1)))
else:
l = list(range(1, n+1))
print(*(sorted(l[:k-1], reverse = True)+l[k-1:]))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | ```python
import sys
my_file = sys.stdin
#my_file = open("input.txt", "r")
n = int(my_file.readline())
a = [int(i) for i in my_file.readline().strip().split()]
even = 0
odd = 0
for i in range(n):
if a[i]%2 == 0:
even += 1
if even == 2:
break
if even == 2:
for i in range(n):
i... | |
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
nums = list(int(input('arr :')))
multi = nums[0] * nums[1]
print (multi // 2)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? | ```python
def factorial(n):
m = n
while n>1:
n -= 1
m = m*n
return m
zeros = int(input())
x = 10**zeros
flag = True
counter = 0
n = zeros*5
#print(n)
for i in range(n):
i += 1
if i%78125 == 0:
n-=35
elif i%(5**6) == 0:
n-=25
elif i%(5**5) == ... | |
MatrixStudio/Codeforces-Python-Submissions | Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!
The computers bought for the room were different. Some of them had only USB ... | ```python
usb=[]
ps=[]
nc=0
pr=0
s=input()
s=s.split()
u=int(s[0])
p=int(s[1])
up=int(s[2])
m=int(input())
for i in range(m):
b=input()
b=b.split()
pri=int(b[0])
ty=b[1]
if ty=='USB':
usb.append(pri)
else:
ps.append(pri)
usb.sort()
ps.sort()
if len(usb)<=u:
... | |
MatrixStudio/Codeforces-Python-Submissions | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | ```python
b = input().split()
m = int(b[0])
n = int(b[1])
st = []
sr = []
for i in range(m):
g = input()
for j in range(n):
if g[j] == 'S':
st.append(i)
sr.append(j)
break
n1 = len(sr)
m1 = len(st)
sum = (m - m1) * n + (n-n1) * m1
print(st,sr,sum)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | ```python
l = len(input())
print((l+1)*26 - l)
``` | |
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
n=int(input())
x,y=zip(*[input().split() for i in ' '*n])
print(sum([x.count(i) for i in y]))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts.
Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the fol... | ```python
n = int(input())
height = []
temp = n
while temp > 0:
height.append(int(input()))
temp -= 1
eat = n
jump = n-1
ud = height[0]
for i in range(n-1):
ud += abs(height[i] - height[i+1])
print(ud + eat + jump)
``` | |
MatrixStudio/Codeforces-Python-Submissions | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings... | ```python
import collections
def LI():
return list(map(int, input().split()))
def I():
return int(input())
def solve():
n = I()
g = {i: collections.deque() for i in range(n)}
for i in range(1, n):
u, v = LI()
u, v = u - 1, v - 1
g[u].append(v)
... | |
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
word = input()
n = len(word)
if n > 10:
print(word[0], n, word[n-1],sep="")
else:
print(word)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, t... | ```python
def solve():
if n == '0':
return 0
cur = 0
for i in range(len(n) - 1, -1, -1):
if n[i] == '0':
cur += 1
if cur == k:
return (len(n) - i - k)
return len(n) - 1
read = lambda: map(int, input().split())
n, k = read()
n = str(n)
print(... | |
MatrixStudio/Codeforces-Python-Submissions | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | ```python
number_of_names = int(input()) # Number of names
names = set(["lucius", "ginny", "harry"]) # Initialize the set with specific names
for i in range(number_of_names):
name = input().lower() # Convert the name to lowercase for case-insensitive comparison
if name in names:
print("YES")
els... | |
MatrixStudio/Codeforces-Python-Submissions | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | ```python
num = int(input())
count = 0
for i in range(num):
num1,num2 = map(int,input().split())
if(num1+2 <= num2):
count +=1
print(count)
``` | |
MatrixStudio/Codeforces-Python-Submissions | We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6.
You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the ... | ```python
def S(n):
lista = [number for number in str(n)]
return len(lista)
line = input()
numbers = line.split(" ")
numbers = [int(x) for x in numbers]
w = numbers[0]
m = numbers[1]
k = numbers[2]
output = 0
while w > 0:
if w - S(m)*k > 0:
w -= S(m)*k
else:
break
m += 1
outpu... | |
MatrixStudio/Codeforces-Python-Submissions | There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave... | ```python
a=int(input())
b=list(input())
print((a-b.count('R')),(a.b.count('L')))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | ```python
if len(input()) % 2 == 0 print("CHAT WITH HER!") else print("IGNORE HIM!")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | ```python
n, a, b, c = map(int, input().split())
dp = [0]*(n+1)
for i in range(n+1):
if i==0 or dp[i]:
if i+a<=n: dp[i+a] = dp[i]+1
if i+c<=n: dp[i+c] = dp[i]+1
if i+b<=n: dp[i+b] = dp[i]+1
print(dp[n])
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given a tree with *n* vertexes and *n* points on a plane, no three points lie on one straight line.
Your task is to paint the given tree on a plane, using the given points as vertexes.
That is, you should correspond each vertex of the tree to exactly one point and each point should correspond to a vertex. If... | ```python
print("_RANDOM_GUESS_1692431221.2318246")# 1692431221.231841
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they m... | ```python
from math import floor
def gcd(x, y):
if y == 0:
return x
return gcd(y, x % y)
# =======================================================
n, m, x = map(int, input().split(" "))
keyboard = []
d = {}
for i in range(n):
keyboard.append(input())
for j in range(m):
... | |
MatrixStudio/Codeforces-Python-Submissions | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | ```python
a=0
t=0
c,x=map(int,input().split())
a=x//5
#print('a=',a)
if x%5==0:
print(a*c)
elif a==0:
print(int((c/5)*x))
else:
lst=list(range((a*5)+1,x+1))
#print('lst=',lst)
for z in lst:
# print('z=',z)
e=5-(z%5)
# print('e=',e)
while e<=c :
... | |
MatrixStudio/Codeforces-Python-Submissions | There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
- You can move to the right or to ... | ```python
n, m, k = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ma = {}
n1 = (n + m - 2) // 2
for mask in range(1 << n1):
s, x, y = 0, 0, 0
for i in range(n1):
if not(0 <= x < n and 0 <= y < m):
break
s ^= a[x][y]
if (mask >> i) & 1:
x += 1
else:
y... | |
MatrixStudio/Codeforces-Python-Submissions | Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.
After the contest was over, Valer... | ```python
from collections import deque
n , k , l , r , st , sk = map(int,input().split())
d = deque()
if (sk % k == 0):
for i in range(k):
d.append(sk // k)
rem = st - sk
nums = n - k
if (rem % nums == 0):
for i in range(nums):
d.append(rem // nums)
... | |
MatrixStudio/Codeforces-Python-Submissions | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | ```python
input_string = input()
letters = input_string.split(", ")
set_of_letters = set(letters)
print(len(set_of_letters))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | ```python
input()
ans =0
arr = list(map(int,input().split()))
for i in range(len(arr)-1):
temp = sum(arr[:i+1])
temp2 = sum(arr[i+1:])
if temp ==temp2:
ans +=1
print(ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | ```python
print(len(set(map(str,input()[1:-1].split(',')))))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys a... | ```python
p=input().split()
n=int(p[0])
w=int(p[1])
q=input().split()
a=[]
s=0
for i in range(2*n):
a.append(int(q[i]))
a.sort()
if a[n]>=2*a[0]:
s=n*a[0]+n*2*a[0]
else:
s=n*a[n]+n*(a[n]/2)
if s>w:
print(w)
else:
print(s)
``` | |
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
a = input()
b = input()
c = input()
missing_list = []
achive_words = a+b
for i in achive_words :
if i in c:
c = c.replace(i,"",1)
else:
missing_list.append(i)
if len(c) > 0 or len(missing_list)> 0 :
print("NO")
else:
print("Yes")
``` | |
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
s = input()
count = 1
last_char = s[0]
dangerous = False
for i in range(1, len(s)):
if s[i] == last_char:
count += 1
if count >= 7:
dangerous = True
break
else:
count = 1
last_char = s[i]
if dangerous:
print("YES")
else:
print("NO")
`... | |
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
s = input()
upper = 0
for i in s:
if i.upper() == i:
upper += 1
else:
continue
if upper > len(s)-upper:
print(s.upper())
else:
print(s.lower())
``` | |
MatrixStudio/Codeforces-Python-Submissions | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | ```python
n=int(input())
s=list(map(int, input().split(' ')))
sum=0
for i in range(n):
sum+=s[i]
print(sum/n)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them ... | ```python
r,g,b= list(map(int, input().split(" ")))
r = ((r+1)/2-1)* 3 + 30
g = ((g+1)/2-1)* 3 + 31
b = ((b+1)/2-1)* 3 + 32
print(int(max(r,g,b)))
``` | |
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
import math
k, s ,n,p = map(int, input().split())
f=math.ceil(((math.ceil(s/n))*k)/p)
print(f)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open ... | ```python
n = int(input())
ans = 0
while n>0:
i = n
s = 0
while i>0:
s = max(s,i%10)
i=i//10
ans+=1
n-=s
print(ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order.
The stones always fall to the center of Liss's ... | ```python
s = input()
s = list(s)
a = [0]*len(s)
i = 0
j = len(s)-1
for ij in range(len(s)):
if(s[ij]=='r'):
a[i]=ij+1
i+=1
else:
a[j]=ij+1
j-=1
for i in a:
print(i)
``` | |
MatrixStudio/Codeforces-Python-Submissions | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the... | ```python
def read_multi_dimensional_array(dimension):
return [[int(item) for item in input().split(" ")] for j in range(dimension)]
def iq_test(array):
for i in range(3):
for j in range(3):
if int(array[i][j] == "#") + int(array[i][j + 1] == "#") \
+ int(array[i ... | |
MatrixStudio/Codeforces-Python-Submissions | Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbe... | ```python
k = int(input())
n = [int(i) for i in input()]
cs=0
for i in n:
cs+=i
n.sort()
v = k-cs
res = 0
for i in n:
if v<=0:
break
else:
v-=(9-i)
res+=1
print(res)
``` | |
MatrixStudio/Codeforces-Python-Submissions | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | ```python
dicc={'purple':'Power','green':'Time','blue':'Space','orange':'Soul','red':'Reality','yellow':'Mind'}
user=int(input())
for i in range(user):
user2=input()
dicc.pop(user2)
print(len(dicc))
for i,j in dicc.items():
print(j)
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.