source stringclasses 3
values | instruction stringlengths 23 3.97k | input stringclasses 1
value | output stringlengths 1 3.75k |
|---|---|---|---|
MatrixStudio/Codeforces-Python-Submissions | Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of... | ```python
def main():
n, res, mask, x = int(input()), [], 1, 1
while n >= mask:
if n & mask:
res.append(x)
mask *= 2
x += 1
print(*[x for x in reversed(res) if x])
if __name__ == '__main__':
main()
``` | |
MatrixStudio/Codeforces-Python-Submissions | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i... | ```python
n=int(input())
L=input().split()
sum=0
for i in L:
sum+=int(i)
i=n
while(sum%i!=0):
i-=1
print(i)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | ```python
n=int(input())
line=input()
line=line.split()
s=0
for i in range(n):
line[i]=int(line[i])
line.sort()
for i in range(n):
s=s+(i+2)*line[i]
s=s-line[n-1]
print(s)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Anton has the integer *x*. He is interested what positive integer, which doesn't exceed *x*, has the maximum sum of digits.
Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. | ```python
def sod(n):
sm = 0
while n != 0:
n1 = n%10
sm += n1
n = n//10
return sm
n = int(input())
size = len(str(n))
new = str(n)
new = int(new[0])-1
new = str(new)
#print(new)
num = new
for i in range(size-1):
num += '9'
num = int(num)
res1 = sod(n... | |
MatrixStudio/Codeforces-Python-Submissions | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typi... | ```python
from math import *
d = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
l, r = map(int, input().split())
ans = 0
def calc(a):
res = 0
while (a > 0):
res += d[a % 10]
a //= 10;
return res
for a in range(l, r + 1):
ans += calc(a)
print(ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | ```python
from collections import *
import math
from heapq import *
def checker():
n, k = map(int, input().split())
arr = list(map(int, input().split()))
max_sum = sum(arr[:k])
max_idx = 0
curr_sum = max_sum
start = 0
end = k - 1
while(end + 1 < n):
curr_sum -= ... | |
MatrixStudio/Codeforces-Python-Submissions | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current playe... | ```python
import math
def main():
n = int(input())
print(math.floor(1.5 * n))
if __name__ == '__main__':
main()
``` | |
MatrixStudio/Codeforces-Python-Submissions | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2... | ```python
n1, n2, k1, k2 = map(int, input().split())
if n1>k2:
print("First")
elif n2>k1:
print("Second")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1<=×<=1. Squares are numbered 1, 2, 3 and so on. Vika decided ... | ```python
def stickProb():
stickSize=int(input())
count=0
duplicates=1
if(stickSize>=12):
duplicates=2
if(stickSize%2!=0 or int(stickSize/2-2)<=0):
print(0)
else:
if(stickSize/2-2)%2==0:
print(int((stickSize/2-2)/2))
else:
print... | |
MatrixStudio/Codeforces-Python-Submissions | Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=><=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7. | ```python
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n,k,inp,cur=0,i,ans=-1;
cin>>n>>k;
for(i=1;i<=n;i++)
{
cin>>inp;
cur+=inp;
if(cur<=8)
{
k-=cur;
cur=0;
}
else
{
... | |
MatrixStudio/Codeforces-Python-Submissions | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | ```python
from sys import stdin as sin
def aint():return int(sin.readline())
def amap():return map(int,sin.readline().split())
def alist():return list(map(int,sin.readline().split()))
def astr():return str(sin.readline().split())
from collections import defaultdict as dd
n = int(input())
if n-10<=11 and n-10>=... | |
MatrixStudio/Codeforces-Python-Submissions | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | ```python
n=int(input())
l=list(map(int,input().split()))
c=0
maxi=0
for i in list(set(l)):
c=l.count(i)
maxi=max(maxi,c)
print(maxi)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | ```python
n=int(input())
k=''
for i in range(1,n+1):
if(i%2!=0):
k=k+'I hate it'
elif(i%2==0):
k=k+'I love it'
if(i+1<=n):
k=k+' then '
print(k)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to *n* centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The ... | ```python
n=int(input())
n+=1
f = n//36
i = (n%36)//3
print(f,i)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). | ```python
x,y=map(int,input().split())
a=[x,y,y-x,-x,-y,x-y]
n=int(input())
print(a[(n-1)%6]%1000000007)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | ```python
n = int(input())
s = str(n)
num = [2,3,5,6,7,8,9]
duo4 = ['444','4444','44444','444444','4444444','44444444','444444444','44444444444']
for i in num:
if str(i) in s:
print('NO')
break
for x in duo4:
if x in s:
print('NO')
break
else:
print('YES')
``` | |
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
t = input()
for i in range(1, len(t)):
if ord(t[i]) > 97:
m = 1
break
else:
m = 0
if m == 0:
print(t.title())
else:
print(t)
``` | |
MatrixStudio/Codeforces-Python-Submissions | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | ```python
i = int(input())
if i%2=0 :print('YES')
else:print('NO')
``` | |
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())
c= []
o=True
for i in range(n):
c.append(list(map(int,input().split())))
for i in range(n):
d=[]
for j in range(n):
d.append(c[j][i])
if sum(d) != 0:
print("NO")
o =False
break
if o:
print("YES")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | ```python
n= int(input())
matrix = [ [ 'c' for i in range(n) ] for j in range(n)]
for i in range(n):
matrix[i]=list(input())
#print(matrix)
ans=0
for i in range(n):
count=0
for j in range(n):
if matrix[i][j]=='C':
count=count+1
ans=ans+(count*(count-1))/2
for i in... | |
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
n = int(input())
if n == 1:
print(0)
else:
if n%2 == 0:
print(n//2 - 1)
else:
print((n+1)//2 - 1)
``` | |
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()
c=0
p=[0]
d=False
for player in s[:1]:
if player==p:
c+=1
if c>=7:
d=True
break
else:
c=1
p=player
if d:
print("YES")
else:
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .
In one step you can move... | ```python
n=int(input())
r1,r2=0,0
p=list(map(int,input().split()))
for i in range(n//2):
r1+=abs(2*i+1-p[i])
r2+=abs(2*i+2-p[i])
print(min(r1,r2))
``` | |
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=int(input())
s=input()
for i in range(n):
if s=="++X"
x+=1
elif s=="--X":
x-=1
else:
continue
print(x)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*... | ```python
sz = int(input())
lo = list(map(int,input().split()));lt = sorted(lo)
q = int(input())
for i in range(q):
t,s,e = map(int,input().split())
if t == 1:
print(sum(lo[(s-1):e]))
else:
print(sum(lt[(s-1):e]))
``` | |
MatrixStudio/Codeforces-Python-Submissions | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | ```python
n,m=map(int,input().split())
s=input()
if len(set(list(s)))!=1:
print('NO')
exit()
a=[s[0]]
for i in range(n-1):
s=input()
if len(set(list(s)))==1 and s[0]!=a[-1]:
pass
else:
print('NO')
exit()
print('YES')
``` | |
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
x=list(input())
y=list(input())
z=list()
for i in range(len(x)):
z=z.append(int(x[i]!=y[i]))
print(*z,sep='')
``` | |
MatrixStudio/Codeforces-Python-Submissions | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | ```python
n = int(input())
s = input()
a = list(map(int,input().split()))
ans = [a[i+1] - a[i] for i in range(n-1) if s[i] == "R" and s[i+1]== "L"]
if ans:
print(min(ans)//2)
else: print(-1)
``` | |
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
input()
s=m=j=0
for i in map(int,input().split()):
if j<i:m+=1
else:
s=max(s,m)
m=1
j=i
print(max(s,m))
``` | |
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().strip()
upper = 0
alphabet = ["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"]
for x in word:
if x in alphabet:
upper = upper + 1
if upper > len(word)//2:
print (word.upper())
else:
print(word.lower())
``` | |
MatrixStudio/Codeforces-Python-Submissions | Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th... | ```python
s=input()
h=int(s[:2])
m=int(s[3:])
mm=int(s[1]+s[0])
if m<mm:
print(s[0]+s[1]+':'+str(mm))
else:
h=(h+1)%24;
if(h<10):
h='0'+str(h)
print(h+':'+h[1]+h[0])
else:
t=str(h)
print(t+':'+t[1]+t[0])
``` | |
MatrixStudio/Codeforces-Python-Submissions | Three sons inherited from their father a rectangular corn fiend divided into *n*<=×<=*m* squares. For each square we know how many tons of corn grows on it. The father, an old farmer did not love all three sons equally, which is why he bequeathed to divide his field into three parts containing *A*, *B* and *C* tons of ... | ```python
# 3 3
# 1 1 1
# 1 1 1
# 1 1 1
# 3 3 3
# 2 5
# 1 1 1 1 1
# 2 2 2 2 2
# 3 6 6
n, m = input().split()
n = int(n)
m = int(m)
A = []
for i in range(n):
A.append([])
tmp = input().split()
for obj in tmp:
A[i].append(int(obj))
req = input().split()
for i in range(len(... | |
MatrixStudio/Codeforces-Python-Submissions | You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters.
Your task is to add spaces to the text by the following rules:
- if there is no punctuation mark between two word... | ```python
s = input().replace(',', ' , ').split()
for i in range(len(s) - 1):
if s[i] == ',':
print(s[i], end=' ')
elif s[i] != ',' and s[i + 1] == ',':
print(s[i], end='')
else:
print(s[i], end=' ')
print(s[-1])
``` | |
MatrixStudio/Codeforces-Python-Submissions | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*... | ```python
import math
def gprimes(n):
numbers = set(range(n, 1, -1))
primes = []
while numbers:
p = numbers.pop()
primes.append(p)
numbers.difference_update(set(range(p*2, n+1, p)))
return primes
N = int(input())
nums = input().split(" ")
nums = [int(x) for x in nu... | |
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
a=input()
n=0
for _ in a:
t=a.count(_)
n+=1
if t>1:
n=n-(t-1)
n=n-(t-1)/2
if n%2==0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!')
``` | |
MatrixStudio/Codeforces-Python-Submissions | Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | ```python
n,m=map(int,input().split())
for i in range(n):
for j in range(n):
if i==j:
print(m)
else:
print("0")
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$.
Note that the sequence can contain equal elements.
If there is no suc... | ```python
v1, v2 = map(int, input().split())
v = [1] + sorted(list(map(int, input().split())))
if v.count(v[v2]) == v1:
print(v[v2])
else:
print(-1)
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR.
Find the maximum possible value of after performing at most *k* operations optimally. | ```python
n, k, x = map(int, input().split())
numbers = list(map(int, input().split()))
res = numbers[0]
num = max(numbers)
checked_max = False
if num == res:
res = res * x ** k checked_max = True
for i in numbers:
if i == num and not checked_max:
i = i * x ** k
checked_max = True
res = res | i
print... | |
MatrixStudio/Codeforces-Python-Submissions | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | ```python
n=input()
alist=[int(x) for x in n.split()]
alist.sort()
print(alist[1]-alist[0]+(alist[2]-alist[1]))
``` | |
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
st=input()
st=st[1:-1]
m=set(st.split(', '))
print(len(m))
``` | |
MatrixStudio/Codeforces-Python-Submissions | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | ```python
def isprime(n):
for i in range(2,int(n/2)+1):
if n%i==0:
return 0
return 1
n=int(input())
l=[]
x=int(n/2)
for i in range(3):
if isprime(x):
x=x+1
else:
l.append(x)
l.append(n-x)
break
print(' '.join(l))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different... | ```python
n, s = map(int, input().split())
def R(n):
ans = 0
while True:
ans += n % 10
n = n // 10
if n == 0:
return ans
current = n - R(n)
if current < s: print("0")
else:
extra = n % 10 + 1
lo,hi = 0, n
while lo < hi - 1:
mid = lo + (hi - lo)//2
... | |
MatrixStudio/Codeforces-Python-Submissions | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | ```python
n = int(input())
stewards = list(map(int, input().split()))
count = 0
for i in range(n):
bigger = False
smaller = False
for x in range(n):
if stewards[x] < stewards[i]:
smaller = True
if stewards[x] > stewards[i]:
bigger = True
if bigg... | |
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
n = input()
k = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
m = 'abcdefghijklmnopqrstuvwxyz'
u,l = 0,0
for i in n:
if i in k:
u += 1
if i in m:
l += 1
if u > l:
print(n.upper())
else:
print(n.lower())
``` | |
MatrixStudio/Codeforces-Python-Submissions | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the co... | ```python
#codeforces_957A_live
n = int(input())
si = input()
flag = True
if "MM" in si or "CC" in si or "YY" in si or not("?" in si):
print("No")
elif "???" in si or "??" in si:
print("Yes")
elif si.startswith("?") or si.endswith("?"):
print("Yes")
else:
for k in range(n):
if si[k] == "?" and si[k-1]... | |
MatrixStudio/Codeforces-Python-Submissions | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | ```python
#!/usr/bin/python3
# n, t = input().split(" ")
# a = input()
# n = int(n)
# t = int(t)
# s = list(a)
# while(t != 0):
# for i in range(n-1):
# if s[i] == 'B' and s[i+1] == 'G':
# s[i] = 'G'
# s[i + 1] = 'B'
# t -= 1
# break
# print("".join(s))
#... | |
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()
up=0
low=0
for i in s:
if i.isupper():
up+=1
else:
low+=1
if(up>low):
print(s.upper())
else:
print(s.lower())
``` | |
MatrixStudio/Codeforces-Python-Submissions | Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is... | ```python
#include <stdio.h>
#include <stdlib.h>
int compar (const void *a, const void *b) {
return *((int *) a) - *((int *) b);
}
int main () {
int n, k;
int i, j;
int begin[26], end[26];
for (i = 0; i < 26; i++) begin[i] = end[i] = 0;
(void) scanf ("%d %d", &n, &k);
(void) getchar... | |
MatrixStudio/Codeforces-Python-Submissions | Not long ago Billy came across such a problem, where there were given three natural numbers *A*, *B* and *C* from the range [1,<=*N*], and it was asked to check whether the equation *AB*<==<=*C* is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root *d*(*x... | ```python
n , ans , a = int(input()) , 0 , [0] * 10
for i in range(1,n+1):
ans -= (int)(n/i)
a[i % 9] += 1
for i in range(9):
for j in range(9):
ans += a[i] * a[j] * a[(i * j) % 9]
print (ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at t... | ```python
n, x = map(int, input().split())
minx = None
maxx = None
for i in range(n):
a, b = map(int, input().split())
small = a if a < b else b
big = b if b > a else a
if minx:
minx = small if small > minx else minx
maxx = big if big < maxx else maxx
else:
minx = small
... | |
MatrixStudio/Codeforces-Python-Submissions | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | ```python
#In the name of GOD
n = input()
if ('4' in n and '7' in n) or ('4' not in n and '7' not in n): print('YES')
else: print('NO')
``` | |
MatrixStudio/Codeforces-Python-Submissions | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ... | ```python
num = int(input())
lis = []
string = ""
def fib(n):
if n < 2:
return n
else:
return fib(n-1) + fib(n-2)
for x in range(num):
lis.append(fib(x))
for i in range(1,num+1):
print(i)
if i in lis:
string = string + "O"
else:
string = string + "o"
print (st... | |
MatrixStudio/Codeforces-Python-Submissions | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 25 20:03:39 2021
@author: haining
"""
a,b= [int(x) for x in input().split()]
listb =[1,b+1]
for i in range(a):
c = [int(x) for x in input().split()]
for i in range(c[0]):
if c[1,-1] in listb:
listb.remove(c[1,-... | |
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
q = input()
a = 'abcdefghijklmnopqrstuvwxyz'
print(len(set([i for i in q if i in a])))
``` | |
MatrixStudio/Codeforces-Python-Submissions | When Igor K. was a freshman, his professor strictly urged him, as well as all other freshmen, to solve programming Olympiads. One day a problem called "Flags" from a website called Timmy's Online Judge caught his attention. In the problem one had to find the number of three-colored flags that would satisfy the conditio... | ```python
print("_RANDOM_GUESS_1689419957.1878912")# 1689419957.1879108
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and ... | ```python
from functools import reduce
line = input()
line=[int(x) for x in line.split()]
if line[2]==0 and( line[1]==0 or line[0]==0) :
print(0)
else:
print( (reduce(lambda x,y:x+y,line)//2)*2)
``` | |
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 = list(map(int, input().split()))
b = list(map(int, input().split()))
answer = [0] * n
for i in range(n):
if a[i] == b[i]:
answer[i] = i + 1
ind1 = -1
ind2 = -1
for i in range(n):
if a[i] != b[i]:
if ind1 == -1:
ind1 = i
else:
... | |
MatrixStudio/Codeforces-Python-Submissions | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | ```python
def main():
#Soma de PG infinita
a, b, c, d = [int(x) for x in input().split()]
pSmallR = a/b
pZanoes = c/d
return pSmallR / (1 - ((1-pSmallR)*(1-pZanoes)))
print(main())
``` | |
MatrixStudio/Codeforces-Python-Submissions | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | ```python
import math
r,x,y,x1,y1=map(int,input().split())
d=math.sqrt((x1-x)**2+(y1-y)**2)
c=math.ceil(d/(2*r))
if(c==1):
print(int(1))
else:
print(int(c))
``` | |
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
i = [int(x) for x in input().split(' ')]
f = min(i)
r = int((max(i)-f)/2)
print(f,r)
``` | |
MatrixStudio/Codeforces-Python-Submissions | There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy ... | ```python
import sys
input = sys.stdin.readline
from collections import Counter as C
def miis():
return map(int, input().split())
for _ in range(1):
n = int(input())
a = list(miis())
c = C(a)
ans = n-1
for i in c:
ans = min(n-c[i], ans)
print(ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | ```python
input_val = input()
c = input_val.count
print(max(0, min((c('n')-1)//2, c('e')//3, c('t'), c('i'))))
``` | |
MatrixStudio/Codeforces-Python-Submissions | A positive integer is called a 2-3-integer, if it is equal to 2*x*·3*y* for some non-negative integers *x* and *y*. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print th... | ```python
# Aniket Hend
ans=0
l,r=map(int,input().split())
for i in range(100):
for j in range(100):
num=2**i*3**j
if l<=num<=r:
ans+=1
print(ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are *n* pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a... | ```python
import sys
sys.stderr = sys.stdout
def dance(n, q, C):
e = 0
o = 0
for c in C:
if c[0] == 1:
x = c[1]
if x % 2:
e, o = (o - x) % n, (e - x) % n
else:
e = (e - x) % n
o = (o - x) % n
elif c[0] == 2... | |
MatrixStudio/Codeforces-Python-Submissions | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | ```python
n = int(input())
num = sorted([int(x) for x in input().split()])
min_diff = 10 ** 6
for i in range(2 * n - 1):
for j in range(i + 1, 2 * n):
kaya_num = []
for k in range(2 * n):
if i != k and j != k:
kaya_num.append(num[k])
current_diff = 0
... | |
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
w = list(input())
x = 0
n = 0
m = 0
a = 0
y = 0
z = 0
h = ""
v = list("")
v.clear()
for l in w:
x = x + 1
if l != " ":
h = h + l
else:
v.append(h)
h = ""
if x == len(w):
v.append(h)
x = 0
for o in v:
x = x + 1
if x == 1:
n ... | |
MatrixStudio/Codeforces-Python-Submissions | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | ```python
n = int(input())
cards = list(map(int,input().split(' ')))
Spoints = Dpoints = 0
i = 0
while i < n:
willBeAdded = max(cards[0],cards[-1])
if i%2 == 0:
Spoints = Spoints + willBeAdded
else : Dpoints = Dpoints + willBeAdded
cards.remove(max(cards[0],cards[-1]))
i +=1
... | |
MatrixStudio/Codeforces-Python-Submissions | Some company is going to hold a fair in Byteland. There are $n$ towns in Byteland and $m$ two-way roads between towns. Of course, you can reach any town from any other town using roads.
There are $k$ types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least $s... | ```python
from sys import stdin,stdout,setrecursionlimit
from collections import defaultdict,deque
setrecursionlimit(200001)
def bfs(v):
se=set()
cg=[]
se.add(l[v-1])
d=deque()
global graph, vis,dis,s,res
dis[v]=0
vis[v]=1
d.append(v)
while(len(d)>0):
x=d.popleft... | |
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
n,w = map(int,input().split())
a = list(map(int,input().split()))
maxx = 0
a.sort(reverse = True)
if a[0] / 2 > a[2*n-1]:
maxx = (a[2*n-1]*3)*n
else:
maxx = (a[0]*1.5)*n
print(min(maxx,w))
``` | |
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
n=int(input())
colorlist=["R","O","Y","G"]
y=0
x=n%7
while y<n-3:
z=y%4
print(colorlist[z],end="")
y+=1
print("BIV")
``` | |
MatrixStudio/Codeforces-Python-Submissions | In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and ... | ```python
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=0
c=0
for i in range(1,6):
x=a.count(i)
y=b.count(i)
if abs(x-y)%2!=0 :
c=1
else :
s=s+abs(x-y)//2
if c==1 :
print(-1)
else :
print(s)
... | |
MatrixStudio/Codeforces-Python-Submissions | A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there w... | ```python
n,m,k = map(int,input().split())
for i in range(-1100,1100):
if n*(i**k)==m:
print(i)
exit()
print("No solution")
``` | |
MatrixStudio/Codeforces-Python-Submissions | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | ```python
num_of_snacks = int(input())
snacks_size = [map(int, input().split(" "))]
# num_of_snacks = 5
# snacks_size = [4, 5, 1, 2, 3]
last_snack = num_of_snacks
sorted_list_leng = 0
for i_day in range(num_of_snacks):
if snacks_size[i_day] != last_snack:
print()
else:
base_snacks = list(
... | |
MatrixStudio/Codeforces-Python-Submissions | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do... | ```python
int_inp = lambda: int(input()) #integer input
strng = lambda: input().strip() #string input
strl = lambda: list(input().strip())#list of strings as input
mul = lambda: map(int,input().strip().split())#multiple integers as inpnut
mulf = lambda: map(float,input().strip().split())#multiple ... | |
MatrixStudio/Codeforces-Python-Submissions | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | ```python
n=int(input())
arr=[]
for i in range(n):
arr.append(input())
for i in range(0,n):
for j in range(i+1,n):
if(arr[i]+arr[j]>arr[j]+arr[i]):
s=arr[i]
arr[i]=arr[j]
arr[j]=s
sol= ""
for i in range( n):
sol=sol+ arr[i]
print(sol)
... | |
MatrixStudio/Codeforces-Python-Submissions | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexit... | ```python
n,a,b = map(int,input().split())
x = list(map(int,input().split()))
aa = sorted(x)
print(aa[b] - aa[b-1])
``` | |
MatrixStudio/Codeforces-Python-Submissions | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
... | ```python
c = d = 0
flag = 0
for n in range(int(input())):
a, b = map(int, input().split())
if a + b == c and c+d == a:
flag = 1
c , d = a, b
if flag == 1:
print("YES")
else:
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Little penguin Polo adores strings. But most of all he adores strings of length *n*.
One day he wanted to find a string that meets the following conditions:
1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbo... | ```python
n,k=map(int,input().split())
from sys import exit
if k==1:print('a'*n);exit()
if k>n:print(-1);exit()
alfa='cdefghijklmnopqrstuvwxyz'
res='ab'*((n-k+2)//2)
if (n-k+2)%2==1:res+='a'
res+=alfa[:k-2]
print(res)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units... | ```python
n = int(input())
a=list(map(int, input().split()))
if a[n-1] == 0 :
print("UP")
elif a[n-1] == 15 :
print("DOWN")
elif n == 1 :
print("-1")
elif a[n-2] > a[n-1] :
print("DOWN")
else :
print("UP")
``` | |
MatrixStudio/Codeforces-Python-Submissions | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | ```python
from math import *
n,a,b=(int(i) for i in input().split())
z=log(abs(b-a), 2)+1
print("Final" if 2**z==n else z)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | ```python
n,m=map(int, input().split())
if(n%2==0 and (n/2)%m==0):
print(int(n/2))
else:
if((int(n/2)+1)%m==0):
print(int(n/2)+1)
else:
print(-1)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element ... | ```python
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
if s%2==0:
s=s//2
a.sort()
dp=[[0]*(s+1) for _ in range(len(a))]
dp[0][a[0]]=1
tg=False
for i in range(1,len(a)):
for j in range(1,s):
if dp[i-1][j]==1:
dp[i][j]=1
... | |
MatrixStudio/Codeforces-Python-Submissions | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | ```python
d1, d2, d3 = map(int, input().split())
print(min(d1 + d2 + d3, 2*d1 + 2*d2))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold... | ```python
import math
def isPrime(n):
if n == 1:
return False
if n == 2:
return True
if n%2 == 0:
return False
for i in range(3, math.ceil(math.sqrt(n))+1, 2):
if n%i == 0:
return False
return True
n, k = map(int, input()... | |
MatrixStudio/Codeforces-Python-Submissions | One day Ms Swan bought an orange in a shop. The orange consisted of *n*·*k* segments, numbered with integers from 1 to *n*·*k*.
There were *k* children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper... | ```python
k , n = map(int , input().split())
t = k*n
disaier = list(map(int , input().split()))
if n == 1 :
print(*range(1 , t + 1))
else:
segment = [False] * (k*n)
for i in disaier :
segment[i-1] = True
print(segment)
for i in range(k) :
counter = 0
number =... | |
MatrixStudio/Codeforces-Python-Submissions | Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week... | ```python
a = [int(k) for k in input().split()]
b = [int(k) for k in input().split()]
c = [int(k) for k in input().split()]
d = [b[k] - c[k] for k in range(a[0])]
d.sort()
e = 0
while d[e] < 0 and e < a[0]:
e += 1
if e > a[1]:
print(sum(d[0:e])+sum(c))
else:
print(sum(d[0:a[1]])+sum(c))
``` | |
MatrixStudio/Codeforces-Python-Submissions | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | ```python
import math
if __name__ == '__main__':
a, b, c = [int(i) for i in input().split()]
print(int(4 * (math.sqrt(a * b / c) + math.sqrt(a * c / b) + math.sqrt(b * c / a))))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the ... | ```python
n = int(input())
a = []
x = []
goods = []
for i in range(n):
s = input().split()
goods.append(int(s[0]))
a.append(int(s[0]))
x.append(int(s[1]))
m = int(input())
b = []
y = []
for i in range(m):
s = input().split()
if int(s[0]) not in goods:
goods.append(int(s[0]... | |
MatrixStudio/Codeforces-Python-Submissions | Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple... | ```python
print("_RANDOM_GUESS_1689595076.160925")# 1689595076.1609445
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given *n* points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points. | ```python
n=int(input())
coor=[]
for i in range(n):
#a,b=map(int,input().split())
a,b=10**9,10**9
coor.append([a,b])
def newlist(a):
d={}
s=len(a)
for i in range(s):
for j in range(s):
if i<j:
if (a[i][0]+a[j][0],a[i][1]+a[j][1]) in d:
... | |
MatrixStudio/Codeforces-Python-Submissions | In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seate... | ```python
n, a, b = map(int, input().split())
t = list(map(int, input().split()))
oit, res = 0, 0
for i in range(n):
if t[i] == 1:
if a > 0:
a -= 1
continue
if oit > 0:
oit -= 1
b -= 1
continue
if b > 0:
oit... | |
MatrixStudio/Codeforces-Python-Submissions | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | ```python
n,m=list(map(int,input().split()))
l=[]
count=0
for i in range(n):
a=input()
l.append(a)
for i in range(1,len(l)):
for j in range(1,len(l[i])):
if l[i][j]!=l[i][j-1]:
count=count+1
if l[i]==l[i-1]:
count=count+1
if count>0:
print("NO")
else:
p... | |
MatrixStudio/Codeforces-Python-Submissions | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | ```python
#王奕欢 2300012285
a=int(input())
l=[int(x) for x in input().split()]
d=sorted(l)
d.reverse()
b=0
c=0
for i in range(a):
c+=d[i]
e = c-b
for i in range(a):
if b<=e:
b+=d[i]
e = c - b
if b<=e:
continue
else:
f = i + 1
pr... | |
MatrixStudio/Codeforces-Python-Submissions | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | ```python
s=input()
i=0
while(i<len(s)):
st=s[i:i+3]
if st=="WUB":
s=s.replace("WUB"," ")
i+=3
else:
i+=1
print(s.strip())
``` | |
MatrixStudio/Codeforces-Python-Submissions | — This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three... | ```python
##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))
[a, b, c] = list(map(int, input().split()))
N = 5005;
MOD = 998244353
bin = [[0 for j in range(N)] for i in range(N)]
fac = [0 for i in range(N)]
fac[0] = 1
for i in range(1, N):
fac[i] = (fac[i-1]*i)%MOD
for i in range... | |
MatrixStudio/Codeforces-Python-Submissions | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | ```python
n = int(input())
l = [int(i) for i in input().split()]
c = 0
for i in range(1,6):
s = sum(l)+i
if s%(n+1)==0:
c+=1
elif s%(n+1)==1:
pass
elif s%(n+1)==2:
c+=1
elif s%(n+1)==3:
c+=1
elif s%(n+1)==4:
c+=1
elif s%(n+1)==5:
... | |
MatrixStudio/Codeforces-Python-Submissions | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<... | ```python
an = int(input())
a = list(map(int, input().split()))
bn = int(input())
b = list(map(int, input().split()))
ratios = []
mx = 0
for i in a:
for j in b:
if j % i == 0:
k = j//i
ratios.append(k)
if k > mx:
mx= k
ct = 0
for i in ratio... | |
MatrixStudio/Codeforces-Python-Submissions | Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are *n* pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a... | ```python
n,q = map(int, input().split(" "))
setup=[i + 1 for i in range(n)]
for i in range(q):
move = list(map(int, input().split(" ")))
if move[0] == 2:
setup = [item for sublist in zip(setup[1::2], setup[::2]) for item in sublist]
elif move[0] == 1:
if move[1] < 0:
setup = s... | |
MatrixStudio/Codeforces-Python-Submissions | High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original strin... | ```python
n,k=map(int,input().split())
s=input()
j=0
i=0
dp=[0,0]
ans=0
dp[ord(s[i])-ord('a')]+=1
for i in range(n):
while j<n-1:
if min(dp)<=k:
j+=1
dp[ord(s[j])-ord('a')]+=1
else:
break
if j!=n-1 or k<min(dp):
dp[ord(s[j])-ord('a')]-=1... | |
MatrixStudio/Codeforces-Python-Submissions | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | ```python
from sys import stdin, stdout
fin = stdin.readline
fout = stdout.write
def solve():
n = int(fin())
c = []
for i in range(n):
c.append(fin().split())
c[-1][0] = int(c[-1][0])
c[-1][1] = int(c[-1][1])
r = 0
last = None
cur = None
while c... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.