source stringclasses 3
values | instruction stringlengths 23 3.97k | input stringclasses 1
value | output stringlengths 1 3.75k |
|---|---|---|---|
MatrixStudio/Codeforces-Python-Submissions | Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.
There is a sequence *a* that consists of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Let's denote *f*(*l*,<=*r*,<... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
alph = 'abcdefghijklmnopqrstuvwxyz'
#pow(x,mod-2,mod)
class Fenwick_tre... | |
MatrixStudio/Codeforces-Python-Submissions | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | ```python
AmountOfNum = int(input())
Array = list(map(int,input().split()))[:AmountOfNum]
New = set(Array)
New1 = sorted(New)
if(len(New1)>1):
print(New1[1])
else:
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which int... | ```python
n=int(input())
if n%10<5:
print (n//10*10)
elif n%10==5:
print (n//10*10 or n//10*10+10)
else:
print (n//10*10+10)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | ```python
str = input()
numA = 0
numB = 0
numC = 0
check = True
for x in str:
if(x == 'a'):
numA+=1
elif(x == 'b'):
numB+=1
elif(x == 'c'):
numC+=1
if((x == 'a'and (numB != 0 or numC != 0)) or (x == 'b'and numC != 0 )):
check = False
... | |
MatrixStudio/Codeforces-Python-Submissions | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | ```python
def helper(n,m,a):
a=sorted(a)
ans=sum(a[:m])
print(-ans)
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
helper(n,m,a)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | ```python
t = input()
print(t[0].capitalize()+t[1:])
``` | |
MatrixStudio/Codeforces-Python-Submissions | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | ```python
first_name, last_name = input().split()
first_done = first_name.lower()
last_done = last_name.lower()
login = first_name[0]
for i in range(1, len(first_name) - 1):
if ord(first_done[i]) < ord(last_done[0]):
login += first_name[i]
else:
break
login += last_name[0]
print(login)... | |
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()
a=s.split("WUB")
print(a)
r=""
for i in range(len(a)):
if a[i]!="":
if i==len(s)-1:
r=r+a[i]
else:
r=r+a[i]+" "
print(r)
``` | |
MatrixStudio/Codeforces-Python-Submissions | It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ... | ```python
import sys
inf = float('inf')
input = lambda: sys.stdin.readline().strip()
I = lambda: input()
II = lambda: int(input())
MII = lambda: map(int, input().split())
LI = lambda: list(input().split())
LII = lambda: list(map(int, input().split()))
GMI = lambda: map(lambda x: int(x) - 1, input().split())
LG... | |
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
n, x = [int(i) for i in input().split()]
count = 0
for i in range(n):
a, d = list(input().split())
if a == "+":
x += int(d)
else:
if int(d) > x:
count += 1
else:
x -= int(d)
print(x, count)
``` | |
MatrixStudio/Codeforces-Python-Submissions | "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. | ```python
n = int(input())
print(1)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | ```python
s = input()
print(s[0].upper() + s [1:])
``` | |
MatrixStudio/Codeforces-Python-Submissions | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | ```python
n=int(input())
m=int(input())
l=[]
for i in range(n):
a=int(input())
l.append(a)
l.sort(reverse=True)
c=0
for i in range(n):
c+=l[i]
if(c>=m):
print(i+1)
break
``` | |
MatrixStudio/Codeforces-Python-Submissions | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | ```python
n = int(input())
bags = list(map(int, input().split()))
##check if sum is even or odd
##if even, find all even bags
##if odd, find all odd bags
s = sum(bags)
if s%2==0:
for i in bags:
if i%2==0:
print(i)
else:
for i in bags:
if i%2==1:
print(i)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of *n* letters. Oleg and Igor ... | ```python
s1=list(input())
s2=list(input())
s1.sort()
s2.sort()
ans=""
n=len(s1)
for i in range(n):
if i % 2 == 0:
ans+=s1[0]
del(s1[0])
else:
ans+=s2[-1]
del(s2[-1])
print(ans)
``` | |
MatrixStudio/Codeforces-Python-Submissions | In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o... | ```python
n, m = map(int, input().split())
list1 = []
ans = []
for i in range(m):
list1.append(list(map(int, input().split())))
for i in range(1, 101):
if len(ans) > 1:
print(-1)
break
for j in range(len(list1)):
if list1[j][0] // i + min(1, list1[j][0] % i)!= list1[j][1]:
... | |
MatrixStudio/Codeforces-Python-Submissions | Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them, let's denote them *a* and *b*, erase them from the sequence, and append to the sequence eit... | ```python
A = int(input()); ans = """YES
1 * 2 = 2
3 * 4 = 12"""
if A >= 5:
if A % 2:
ans = """YES
2 + 1 = 3
5 - 3 = 2
3 * 2 = 6
4 * 6 = 24"""
for a in range(int(A/2 - 5/2)+1):
ans += '\n%d - %d = 1'%(2*a+5, 2*a+4)
for a in range(int(A/2 - 5/2)+1):
ans +=... | |
MatrixStudio/Codeforces-Python-Submissions | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | ```python
x=input().split(" ")
i=0; b=True
while b:
i+=1
if (int(x[0])*i) % 10 == 0 or ((int(x[0])*i - int(x[1])) % 10) == 0 :
b=False
print(i)
``` | |
MatrixStudio/Codeforces-Python-Submissions | After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers.... | ```python
def s(n):
if n == 1 or n == 3:
return 3
elif n == 2:
return 2
elif n == 4:
return 1
x = int(input())
arr = [int(i) for i in input().split()]
arr.sort(key=s, reverse=True)
c = 0
t = 1
for i in arr:
if c + i > 4:
c = 0
t += 1
c += i
print(t)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.
After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has *h*2 health points and an attack power of *a*2. Knowing that, Vova... | ```python
if __name__ == "__main__":
h1,a1,c1 = map(int,input().split())
h2,a2 = map(int,input().split())
tmp = []
while h2>0:
if a2>=h1:
tmp.append("HEAL")
h1 = h1+c1
h1 = h1-a2
else:
tmp.append("STRIKE")
h2 = h2-a1
... | |
MatrixStudio/Codeforces-Python-Submissions | Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to ... | ```python
n,d=map(int,input().split())
o=0
if n in [1,3,5,7,8,10,12]:
if d==7 or d==6:
o=6
else:
o=5
if n in [4,6,9,11]:
if d==7:
o=6
else:
o=5
if n==2:
if d==7:
o=5
else:
o=4
print(o)
``` | |
MatrixStudio/Codeforces-Python-Submissions | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | ```python
import sys
input=sys.stdin.readline
def main():
n = int(input())
a = list(map(int, input().split()))
a.sort()
m, nm = a[1]-a[0], 1
for i in range(1, n-1):
if a[i+1]-a[i] < m:
m, nm = a[i+1]-a[i], 1
elif a[i+1]-a[i]==m:
nm +=1
print(m,nm)
main()
``` | |
MatrixStudio/Codeforces-Python-Submissions | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | ```python
def f(m, arr):
ans = 0
for x in range(len(arr)):
ans+=abs(m-arr[x])/d
return ans
nmd = [int(x) for x in input().split()]
n = nmd[0]
m = nmd[1]
d = nmd[2]
status = True
arr = []
for x in range(m):
arr+=[int(i) for i in input().split()]
for x in arr:
if x%d != 0:
status = False
brea... | |
MatrixStudio/Codeforces-Python-Submissions | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | ```python
a=int(input())
b=int(input())
c=int(input())
print(max(a+c+b,a*c*b,a+c*b,a*c+b,a*(b+c),(a+b)*c))
``` | |
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
n, f = map(int, input().split())
a=[]
c =0
for i in range(n):
x, y = map(int, input().split())
c =c + min(x, y)
a.append(min(2 * x, y) - min(x, y))
a.sort(reverse=True)
for i in range(f):
if i < n:
c += max(a[i], 0)
else:
break
print(c)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | ```python
# !/bin/env python3
# coding: UTF-8
# ✪ H4WK3yE乡
# Mohd. Farhan Tahir
# Indian Institute Of Information Technology and Management,Gwalior
# Question Link
#
#
# ///==========Libraries, Constants and Functions=============///
import sys
sys.setrecursionlimit(2000)
inf = float("inf")
mo... | |
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
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 19 21:18:28 2021
@author: odraode
"""
'''
Testo dell'esercizio su 'https://codeforces.com/problemset/problem/330/A' - diff 800
'''
def countPieces(k):
ris =0
for i in range(len(k)):
if(k[i]=='.'):
ris+=1
retu... | |
MatrixStudio/Codeforces-Python-Submissions | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose thre... | ```python
import sys
sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,m=I()
g=[[0]*n for i in range(n)]
ed=[]
an=n*n
dg=[0]*n
for i in range(m):
x,y=I()
x-=1;y-=1
dg[x]+=1;dg[y]+=1
g[x][y]=1
g[y][x]=1
ed.append([x,y])
for i in range(m):
a,b=ed[i]
for j in range(n):
if j!=a and j!=... | |
MatrixStudio/Codeforces-Python-Submissions | A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to... | ```python
n, k = [int(x) for x in input().split()]
if (n ** 2 + 1) // 2 < k:
print("NO")
else:
print("YES")
count = 0
x = True
for i in range(n):
lst = []
for j in range(n):
if x and count < k:
lst.append('L')
count += 1
x = False
else:
lst.append('S')
x = True
pr... | |
MatrixStudio/Codeforces-Python-Submissions | The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*).
- If the wind blows to the east, the boat will ... | ```python
import io
import os
#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t, x1, y1, x2, y2 = map(int, input().split())
xmove = x2 - x1
ymove = y2 - y1
xneed = abs(xmove)
yneed = abs(ymove)
if xmove < 0:
dx = 'W'
else:
dx = 'E'
if ymove < 0:
dy = 'S'
else:
dy =... | |
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()) # Input the coordinate of the friend's house
# Calculate the minimum number of steps needed
min_steps = (x + 4) // 5 # Integer division (//) ensures the result is rounded up
print(min_steps)
``` | |
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
coordinates=int(input())
x= list(map(int,input().split()))
y= list(map(int,input().split()))
z= list(map(int,input().split()))
if (sum(x)+sum(y)+sum(z)==0):
print('YES')
else:
print('NO')
``` | |
MatrixStudio/Codeforces-Python-Submissions | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | ```python
n = int(input())
count = 0
if n <= 9:
print("0")
else:
while n >= 9:
n = sum(map(int, str(n)))
count = count+1
print(count)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | ```python
a, b, c, m = [int(x) for x in input().split()]
possible = True
if m > 2*c or m > b:
print(-1)
possible = False
sm = max(m, c)
if sm > 2*m or sm > 2*c:
print(-1)
possible = False
me = max(b, 2*m + 1)
if me > 2*b:
print(-1)
possible = False
la = max(a, 2*m + 2)
if la > 2*a:
print... | |
MatrixStudio/Codeforces-Python-Submissions | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | ```python
n = int(input())
words = []
ans = []
for i in range(n):
x = input()
words.append(x)
if len(words[i]) > 10:
y = words[i][0] + str(len(words[i])-2) + words[i][-1]
ans.append(y)
else:
ans.append(x)
for i in range(n):
print(words[i])
``` | |
MatrixStudio/Codeforces-Python-Submissions | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | ```python
import math
def primefactors(n,l):
while n%2==0:
if l.count(2)==0:
l.append(2)
n = n//2
for i in range(3,int(math.sqrt(n))+1,2):
while (n % i == 0):
if l.count(i)==0:
l.append(i)
n = n//i
if n > 2:
l.append(n)
return len(l)
n=int(input())
... | |
MatrixStudio/Codeforces-Python-Submissions | In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o... | ```python
import math
n,k=map(int,input().split(' '))
m=[]
d=0
for i in range(k):
m.append(list(map(int,input().split(' '))))
t=-1
for i in range(101):
p=0
for j in m:
if ((j[1]-1)*i<j[0]) and (j[0]<=i*j[1]):
p+=1
#print(i)
if (p==k) and (math.ceil(n/t)!=... | |
MatrixStudio/Codeforces-Python-Submissions | Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and... | ```python
a, b = map(int, input().split())
if a == b:
print(infinity)
elif a < b:
print(0)
else:
c = a - b
s = [(c // i) for i in range(1, min(c, 40000)) if a % (c // i) == b] +\
[i for i in range(1, min(c, 40000)) if a % i == b]
s = set(s)
print(len(s))
``` | |
MatrixStudio/Codeforces-Python-Submissions | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | ```python
n=int(input())
sum=0
for i in range(1,n+1):
if i%2==0:
f=i
else:
f=-i
sum=sum+f
print(sum)
``` | |
MatrixStudio/Codeforces-Python-Submissions | The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are *n* blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they ... | ```python
n,x=map(int,input().split())
l=sorted(list(map(int,input().split())))
ans=0
for i in range (x,101):
s=0
for j in l:
s+=j-j%i
ans=max(s,ans)
print(ans)
``` | |
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
a = list(input())
b = list(input())
for i in range(len(a)):
if a[i]==b[i]:
a[i]=0
else:
a[i]=1
print(''.join(map(str,a)))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | ```python
n=int(input())
l=list(map(int,input().split()))
c=0
mini=l[0]
maxi=l[0]
for i in range(1,len(l)):
if l[i] > maxi:
c+=1
maxi=l[i]
elif l[i] < mini:
c+=1
mini=l[i]
print(c)
``` | |
MatrixStudio/Codeforces-Python-Submissions | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | ```python
lis1=[]
for i in range(0,5):
lis=list(map(int,input().split()))
lis1.append(lis)
row=0
col=0
for i in range (0,5):
for j in range(0,5):
if lis[i][j]==1:
row=i
col=j
print(row+col-6+2)
break
``` | |
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())
x1=y1=z1=0
for i in range(n):
x,y,z=input().split()
x1=x1+int(x)
y1=y1+int(y)
z1=z1+int(z)
if x1==0 and y1==0 and z1==0:
print("YES")
else:
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | A bracket sequence is a string containing only characters "(" and ")".
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are reg... | ```python
def string_value(str):
ans=0
valid = True
for char in str:
if (ans<0 and char=="("):
valid=False
if char==")":
ans-=1
else:
ans+=1
ans=0
for char in reversed(str):
if (ans<0 and char==")"):
valid=False
... | |
MatrixStudio/Codeforces-Python-Submissions | You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then s... | ```python
line = input()
a, b = list(map(int, line.strip().split()))
def helper(a, b):
if a == 0 or b == 0:
print(a, b)
else:
if a >= 2 * b:
a = a - 2 * b
helper(a, b)
else:
if b >= 2 * a:
b = b - 2 * a
helper(a, b)
... | |
MatrixStudio/Codeforces-Python-Submissions | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | ```python
a = [int(x) for x in input().split()]
fl = False
for i in range(6):
for j in range(6):
for k in range(6):
if (i == j or k == j or i == k):
continue
if a[i] + a[j] + a[k] == sum(a) / 2 and sum(a) % 2 == 0:
fl = True
if (fl):
prin... | |
MatrixStudio/Codeforces-Python-Submissions | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | ```python
def main():
_ = input()
scores = list(int(_) for _ in input().split())
amazings = 0
worst = best = scores[0]
for score in scores:
if score < worst:
amazings += 1
worst = score
elif score > best:
amazings += 1
best = score
... | |
MatrixStudio/Codeforces-Python-Submissions | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with... | ```python
k = 2 * int(input())
table = [c for c in input().strip() for _ in range(4)]
t = dict()
for c in table:
if c in t:
t[c] += 1
else:
t[c] = 1
t['.'] = 0
ans = True
for k in t:
v = t[k]
if v > k:
ans = False
print("YES" if ans else "NO")
``` | |
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
n=int(input())
c=0
d=0
for i in range(1,n+1):
for j in range(1,n+1):
if((i+j)==n):
c=c+1
if(i%2==0 and j%2==0):
print("YES")
elif(i%2!=0 and j%2!=0):
print("NO")
elif(i%2!=0 or j%2==0):
print("NO")
else:
print("NO")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | ```python
import sys
input = sys.stdin.readline
L = lambda:list(map(int,input().split()))
n,k = map(int,input().split()) # duration + time stay awake
t = L() #theorems
b = L() #behaviour asleep = 0
extra = 0
for i in range(n):
if b[i] == 1:
extra += t[i]
s = extra
fo... | |
MatrixStudio/Codeforces-Python-Submissions | Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understa... | ```python
s=input()
k=int(input())
months = ['January','February','March','April','May','June','July','August','September','October','November','December']
ind=months.index(s)
tmp=(ind+1+k)%12
print(months[tmp-1])
``` | |
MatrixStudio/Codeforces-Python-Submissions | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | ```python
n = int(input())
l = list(map(int,input().split()))
r = float('Inf')
a,b = 0,0
for i in range(n-1):
if abs(l[i]-l[i+1]) < r:
r = abs(l[i]-l[i+1])
a,b = i,i+1
if abs(l[n-1]-l[0]) < r:
r = abs(l[n-1]-l[0])
a,b = n-1,0
print(a+1,b+1)
``` | |
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
var = int(input())
x = "".join(input().split())
input()
search = input().split()
s1 = s2 = 0
for val in search:
s1 += x.index(val) + 1
s2 += var - x.rindex(val)
print(s1,s2)
``` | |
MatrixStudio/Codeforces-Python-Submissions | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | ```python
n = int(input())
a = input().split(" ")
a = sorted([int(i) for i in a])
print(a[int((n-1) / 2)])
``` | |
MatrixStudio/Codeforces-Python-Submissions | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | ```python
w,y=[int(x) for x in input().split()]
l=[w,y]
l.sort()
n=7-l[1]
for j in range (1,n+1):
if n%j==0 and 6%j==0:
ans=int(n/j)
ans1=int(6/j)
print("{0}/{1}".format(ans,ans1))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | ```python
from itertools import pairwise
from math import inf
n = int(input()) #数量
l = []
for _ in range(n):
l += list(map(int,input().split())),
l += (inf, 1),
# print(l)
tem = -inf
ans = 0
for (x1, h1), (x2 ,h2) in pairwise(l):
if x1-h1> tem:
tem = x1
ans += 1
elif x1 + ... | |
MatrixStudio/Codeforces-Python-Submissions | A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algor... | ```python
def solve():
size = int(input())
s = input()
for i in range(1, size + 1):
if not (size % i):
s = s[0:i][::-1] + s[i:]
print(s)
if __name__ == "__main__":
solve()
``` | |
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
ans=[0,0,0]
f=0
n=int(input())
s=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
ans[0]=+s[i][0]
ans[1]=+s[i][1]
ans[2]=+s[i][2]
for x in ans:
if x!=0:
f=1
if f==1:
print('NO')
else:
print('YES')
``` | |
MatrixStudio/Codeforces-Python-Submissions | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | ```python
a,b= map(int,input().split())
c=list(map(int,input().split()))
d=0
for j in range(a):
if str(c[j]).count('4')+str(c[j]).count('7')<=b:
d+=1
print(d)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
During an audit, you were surprised to find out that the... | ```python
def main():
n = int(input())
a = list(map(int,input().split()))
used = set()
original = set(a)
not_used = set(range(1,n+1)) - original
for i in range(n):
if a[i] > n or a[i] in used:
temp = next(iter(not_used),None)
if temp is not None:
... | |
MatrixStudio/Codeforces-Python-Submissions | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | ```python
x=int(input())
gift=list(map(int,input().split(' ')))
array=[]
for t in range(x):
array.append(0)
for a,b in enumerate(gift):
array[b-1]=a+1
for d in array:
print(d,end=' ')
``` | |
MatrixStudio/Codeforces-Python-Submissions | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | ```python
import queue
def get_ans():
qlo = queue.PriorityQueue()
qhi = queue.PriorityQueue()
n,m = map(int,input().split())
l = list(map(int,input().split()))
for i in l:
qlo.put(i)
qhi.put(-i)
# MAX
hi = 0
nhi = 0
while nhi < n and not qhi.empty():
... | |
MatrixStudio/Codeforces-Python-Submissions | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum ... | ```python
casos = int(input())
limite = int(input())
numeros = [x for x in range(0,limite+1)]
contadorCorrectos = 0
for k in range(casos):
#Comparar cada numero
numero = int(input())
contadorDigito = 0
while numero>0:
#Procesar el ultimo dgito
digito = numero%10
numero... | |
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()
u=0
l=0
for i in s:
if i.islower()==True:
l+=1
else:
u +=1
if l >= u :
print(s.lower())
else:
print(s.upper())
``` | |
MatrixStudio/Codeforces-Python-Submissions | Ann and Borya have *n* piles with candies and *n* is even number. There are *a**i* candies in pile with number *i*.
Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this can... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
A = list(map(int, input().split()))
ans = 0
B = []
C = []
for a in A:
t = int(a**0.5)
if t*t!=a:
B.append(a)
else:
C.append(a)
if len(B)<N//2:
C.sort()
t = N//2-len(B)
... | |
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
#https://codeforces.com/problemset/problem/490/A
number_of_students = int(input())
speciality_list = [int(x) for x in input().split(" ")]
programming, math, pe = [], [], []
for x in range(number_of_students):
if(speciality_list[x] == 1):
programming.append(x+1)
elif(speciality_list[x]... | |
MatrixStudio/Codeforces-Python-Submissions | One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no cu... | ```python
a,m=map(int,input().split())
if a/m==0:
print('Yes')
else:
print('No')
``` | |
MatrixStudio/Codeforces-Python-Submissions | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | ```python
size = int(input())
string = input()
output_str = ''
i = 0
while i < size-1:
if string[i] != string[i+1]:
output_str += 'D'
i+= 1
i+=1
print(size - len(output_str))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to... | ```python
import re
letter = input()
uppercaseGroup = r'[A-Z]+'
lowercaseGroup = r'[a-z]+'
firstUpperCase = False
lastUpperCase = False
if re.search(uppercaseGroup, letter[0]):
firstUpperCase = True
if re.search(uppercaseGroup, letter[len(letter)-1]):
lastUpperCase = True
lower = re.split(uppercaseG... | |
MatrixStudio/Codeforces-Python-Submissions | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of t... | ```python
n, k = map(int, input().split())
PowersOfThePlayer = list((map(int, input().split())))
PowerOfTheWinner=None
if len(PowersOfThePlayer)==2:
PowerOfTheWinner=max(PowersOfThePlayer)
if PowersOfThePlayer[0] == max(PowersOfThePlayer) and PowerOfTheWinner == None:
PowerOfTheWinner=PowersOfThePlayer[... | |
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
n1 = input()
n2 = input()
final = ""
x = list(zip(n1,n2))
print(list(x))
for i in x:
a,b = i
if a==b:
final+="0"
else:
final+="1"
print(final)
``` | |
MatrixStudio/Codeforces-Python-Submissions | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$).
Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the... | ```python
n, q = map(int, input().split())
temp = 0
at = 1
d = {}
dd = {}
for i in range(32):
d[at] = [temp, 0]
dd[temp] = [at, 0]
temp+=1
at*=2
l = [int(x) for x in input().split()]
for i in range(n):
dd[d[l[i]][0]][1]+=1
# print(d)
# print(dd)
for _ in range(q):
t = int(input... | |
MatrixStudio/Codeforces-Python-Submissions | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup... | ```python
N = int(input()) - 1
_arr = list(map(int, input().split()))
i = 0
while i < N - i:
if (i + 1) % 2 != 0:
_t = _arr[i]
_arr[i] = _arr[N - i]
_arr[N - i] = _t
i += 1
_arr = list(map(str, _arr))
print(' '.join(_arr))
``` | |
MatrixStudio/Codeforces-Python-Submissions | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | ```python
#****************************************
#** Solution by BAZOOKA **
#** Sponsored by RED BULL**
#** Team Galaxy **
#** I love ❤Kateryna Gret❤ **
#****************************************/
n, i=abs(int(input())), 0
while n>0 or n%2==1:
i+=1; n-=i
print(i)
#*****************************... | |
MatrixStudio/Codeforces-Python-Submissions | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | ```python
# Read input
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
if arr[0] != 1:
print(1)
else:
f = 0
for i in range(len(arr)-1):
if arr[i+1] - arr[i] > 1:
f= 1
break
if f:
print(arr[i]+1)
else:
print(arr[-1]+1)... | |
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
k = int(input())
s = input()
a = set()
for i in s:
a.add(i)
a = list(a)
check = -1
for i in a:
if(s.count(i)!=k):
print(check)
else:
check = 1
if(check == 1):
for i in range(k):
for j in a:
print(j,end="")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if:
- Its elements are in i... | ```python
import sys
n=int(input())
sys.stdout.write(str(n))
a=n+1
b=n*2
for idx in range(a, b):
sys.stdout.write(" " + str(idx))
``` | |
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()
U = 0
L = 0
for i in range(len(s) - 1):
if s[i].isupper():
U += 1
else:
L += 1
if L < U:
print(s.upper())
elif U < L:
print(s.lower())
elif U == L:
print(s.lower())
``` | |
MatrixStudio/Codeforces-Python-Submissions | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | ```python
from collections import Counter
def ans(arr):
dummy = Counter(arr)
max_ = max(list(dummy.values()))
for i in dummy.keys():
if(dummy[i] == max_):
return(i)
if __name__ == '__main__':
n = int(input())
temp = []
for _ in range(n):
temp.append(input... | |
MatrixStudio/Codeforces-Python-Submissions | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | ```python
n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
arr.sort()
ans = 0
a,b =0,n//2
while a<n//2 and b<n:
if arr[a]*2<=arr[b]:
ans+=1
a+=1
b+=1
else:
b+=1
print(n-ans)
``` | |
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
def bsl(l, rb, k):
while l < rb:
mid = (l + rb) // 2
if nums[mid] >= k:
rb = mid
else:
l = mid+1
return l
def bsr(l, r, k):
while l < r:
mid = (l + r + 1) // 2
if nums[mid] <= k:
l = mid
else:
... | |
MatrixStudio/Codeforces-Python-Submissions | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one origina... | ```python
x,y=[int(i) for i in input().split()]
z=y-1
if y==2 and x%2==0:
print ('No')
elif x%z==0:
print('Yes')
else:
print('No')
``` | |
MatrixStudio/Codeforces-Python-Submissions | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | ```python
n = int(input())
def cus_fact(na):
l = []
sr = ""
for j in range(na):
sr += str(j) + " "
l.append(str(j))
if n >= 1:
sr += str(na)
sr += " " + ' '.join(l[::-1])
sr = sr.rstrip()
# print("S : ", s)
return sr
lst = []
for i in ran... | |
MatrixStudio/Codeforces-Python-Submissions | Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are *n* applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).
*q* events are ... | ```python
#code
n=int(input())
s1=input()
x1=s1.split()
s2=input()
x2=s2.split()
dic=dict()
st=set()
m=0
for i in range(n):
if int(x1[i])==0:
continue
elif int(x2[i])==0:
if 0 in st:
dic[0]=dic[0]+1
m=max(m,dic[0])
else:
st.add(0)
... | |
MatrixStudio/Codeforces-Python-Submissions | It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two ... | ```python
import random
import time
n = int(input())
list = list(map(int, input().split()))
a=max(list)
c=len(list)
if c%2==0:
print("Bob")
else:
print("Alice")
``` | |
MatrixStudio/Codeforces-Python-Submissions | Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. | ```python
from math import *
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
for i in l:
if i > 0 and sqrt(i)!=int(sqrt(i)):
print(i)
exit()
for i in l:
if i < 0:
print(i)
exit()
``` | |
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
li='doG is mY fAv'
li=li.swapcase()
li=li.split(' ')
print(li)
s=''
for i in li[::-1]:
s+=i+' '
print(s)
``` | |
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
t = int(input()) #test cases
for i in range(t):
word_list = input().split()
# print (word_list)
for word in word_list:
if len(word) > 10:
word_letters = [*word]
print(f"{word_letters[0]}{len(word)-2}{word_letters[-1]}")
else:
print(w... | |
MatrixStudio/Codeforces-Python-Submissions | Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$.
Flight from $x$ to $y$ consists ... | ```python
n = int(input())
m = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
flag = 1
for i in range(n):
if a[i] == 1 or b[i] == 1:
print(-1)
flag = 0
break
if flag:
wt = m
wt += wt/(b[0]-1)
for i in range(n-1,0,-1):
... | |
MatrixStudio/Codeforces-Python-Submissions | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | ```python
x=int(input())
d=0
if n%2==0:
d=1
else:
d=2
``` | |
MatrixStudio/Codeforces-Python-Submissions | In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An ex... | ```python
dp = [1]
for i in range(int(input()) - 1):
if input() == 's':
for j in range(1, i + 1):
dp[j - 1] += dp[j]
dp.append(0)
else:
dp.append(0)
for j in range(i + 1, 0, -1):
dp[j] = dp[j - 1]
dp[0] = 0
print(dp)
input()
print(... | |
MatrixStudio/Codeforces-Python-Submissions | Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions ... | ```python
a,b=int(input()),int(input())
if a<b or (a-b)%2!=0: # 除不尽会有进位错误
print("-1")
else:
print(int((a-b)/2),int(a-(a-b)/2)) # 需要使用 int 抹掉小数点
``` | |
MatrixStudio/Codeforces-Python-Submissions | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | ```python
a,b = map(int,input().split())
m = max(a,b)
if m == 1:
print("6/1")
elif m == 2:
print("5/1")
elif m == 3:
print("4/1")
elif m == 4:
print("3/1")
elif m == 5:
print("2/1")
elif m == 6:
print("1/1")
``` | |
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
def check_word(word: str) -> str:
if len(word) > 10:
ans = word[0] + str(len(word) - 2) + word[-1]
else:
ans = word
return ans
num = int(input())
while num != 0:
word = input()
anss = check_word(word)
num -= 1
print(anss)
``` | |
MatrixStudio/Codeforces-Python-Submissions | A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pine... | ```python
import sys
def main():
s1 = input()
s2 = input()
print(s1.count(s2))
main()
``` | |
MatrixStudio/Codeforces-Python-Submissions | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | ```python
n = int(input())
dist = list(map(int, input().rstrip().split()))
dist.sort()
min_dist = 10**9
count = 0
for i in range(n-1):
x = dist[i+1] - dist[i]
if x < min_dist:
min_dist = x
count = 1
elif x == min_dist:
count += 1
print(min_dist , count)
``` | |
MatrixStudio/Codeforces-Python-Submissions | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of t... | ```python
# n = number of people
# k = number of wins in a row
# p = power of player
n, k = map(int, input().split())
p = list(map(int, input().split()))
current_player_power = p[0]
current_player_wins = 0
for i in range(1, n):
if p[i] < current_player_power:
current_player_wins +=1
else:
cu... | |
MatrixStudio/Codeforces-Python-Submissions | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | ```python
n = int(input())
li = []
for _ in range(n):
li.append(input())
#print(li)
corner = li[0][0]
middle = li[0][1]
for a in range(n):
for b in range(n):
if a==b or a+b == n-1:
if li[a][b] != corner:
#print(0,a,b)
print("NO")
e... | |
MatrixStudio/Codeforces-Python-Submissions | Iahub got bored, so he invented a game to be played on paper.
He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in... | ```python
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
d = [0 for _ in range(n)]
mx = 0
cnt = 0
for i in range(n):
if a[i] == 1:
a[i] = -1
cnt += 1
else:
a[i] = 1
for i in range(n):
if i == 0:
d[i] = max(a[i],0)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.