problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
A flowerbed has many flowers and two fountains.
You can adjust the water pressure and set any values r1(r1 β₯ 0) and r2(r2 β₯ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, t... | 3 | def d2(p,x,y):
return (p[0]-x)*(p[0]-x)+(p[1]-y)*(p[1]-y)
n ,x1, y1, x2, y2 = map(int, input().split())
a = [0]*n
for i in range(n):
a[i] = list(map(int, input().split()))
ans = 10000000000000000
dist1 = [d2(p,x1,y1) for p in a]
dist2 = [d2(p,x2,y2) for p in a]
for i in range(n):
dd1 = dist1[i]
dd2 = 0
for j in r... |
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers f... | 3 | n = int(input())
a = list(map(int, input().split()))
for _ in range(n):
for i in range(n - 1):
if a[i] >= a[i + 1]:
break
else:
print('Yes')
exit()
for i in range(n):
a[i] = (a[i] + (-1 if i % 2 else 1)) % n
print('No') |
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. 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 while pa... | 1 | n = int(input())
a = list(map(int, raw_input().split()))
a.sort()
have = [0 for _ in range(n)]
res = n
while min(have) == 0:
res -= 1
last = -1
for i in range(n):
if not have[i] and a[i] > last:
have[i] = True
last = a[i]
print res
|
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, β¦, s_n.
Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).
Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} ... | 3 |
def fun(ind, n, l, dp):
if dp[ind] != -1:
return dp[ind]
if ind > n:
return 0
count = 0
for i in range(ind*2, n+1, ind):
if l[i] > l[ind]:
count = max(count, 1 + fun(i, n, l, dp))
dp[ind] = count
return dp[ind]
def solve():
n = int(input())
... |
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input co... | 3 | import math
for t in range(int(input())):
a,b=map(int,input().split())
c=a//b
if a%b==0:
print(0)
elif b>a:print(b-a)
else:print(abs(min(a-(b*c),a-(b*(c+1)))))
|
You are given a positive number x. Find the smallest positive integer number that has the sum of digits equal to x and all digits are distinct (unique).
Input
The first line contains a single positive integer t (1 β€ t β€ 50) β the number of test cases in the test. Then t test cases follow.
Each test case consists of ... | 3 | for __ in range(int(input())):
n = int(input())
ar = []
i = 9
if n > 45:
print(-1)
else:
while n > 0:
if n - i >= 0:
n -= i
ar.append(i)
i -= 1
ar.sort()
print(''.join(map(str, ar))) |
Let's denote that some array b is bad if it contains a subarray b_l, b_{l+1}, ..., b_{r} of odd length more than 1 (l < r and r - l + 1 is odd) such that β i β \{0, 1, ..., r - l\} b_{l + i} = b_{r - i}.
If an array is not bad, it is good.
Now you are given an array a_1, a_2, ..., a_n. Some elements are replaced by -... | 3 | import sys; input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))
x, y = a[0::2], a[1::2]
if any(x[i] != -1 and x[i+1] != -1 and x[i] == x[i+1] for i in range(len(x)-1)):
print(0); sys.exit(0)
if any(y[i] != -1 and y[i+1] != -1 and y[i] == y[i+1] for i in range(len(y)-1)):... |
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world.
There is at most one... | 3 | from queue import Queue
n,m,k=[int(i) for i in input().split()]
govt=[0 for i in range(n)]
l=[int(i) for i in input().split()]
for i in l:
govt[i-1]=1
edges=[]
adj=[[] for i in range(n)]
for i in range(m):
x=[int(i) for i in input().split()]
adj[x[0]-1].append(x[1]-1)
adj[x[1]-1].append(x[0]-1)
parent=... |
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so... | 3 | n, m = map(int, input().split())
l=0
while n!=m :
l+=1
if m%2 or n>m :
m+=1
else :
m/=2
print(l)
|
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 integers.... | 3 | n, k = map(int, input().split())
a = input().split()
r = 0
for x in a:
if x.count("4") + x.count("7") <= k:
r += 1
print(r)
|
Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, than during this second processor smashes all the remaining potato.
Vanya h... | 3 | n,h,k=map(int,input().split())
z=list(map(int,input().split()))
ans=0
now_h=0
for i in range(n):
#print(now_h,ans)
if now_h+z[i]>h:
p=(now_h-h+z[i])/k
if int(p)!=p:
p+=1
p=int(p)
now_h-=p*k
now_h=max(now_h,0)
now_h+=z[i]
ans+=p
else:
... |
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | 3 | n1=input()
n2=input()
s=list(n1+n2)
p=list(input())
if len(p)!= len(s):
print("NO")
else:
for item in p:
if item in s:
s.remove(item)
print("YES") if len(s)==0 else print("NO") |
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.
The boy is now looking at the ratings of consecutive participan... | 3 | def main():
from sys import stdin
from sys import stdout
input = stdin.readline
print = stdout.write
t = int(input())
for _ in range(t):
n = int(input())
answer = 0
number = 1
while number <= n:
answer += n // number
number *= 2
pr... |
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S palindromic.
Constraints
* S is a string consisting of lowercase English ... | 3 | a = input()
b = 0
for i, j in zip(a, a[::-1]):
if i != j:
b += 1
print(b//2 + b%2)
|
Orac is studying number theory, and he is interested in the properties of divisors.
For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, such that aβ
c=b.
For n β₯ 2, we will denote as f(n) the smallest positive divisor of n, except 1.
For example, f(7)=7,f(10)=2,f(35)=5.
... | 3 | import math
t = int(input())
while(t>0):
t = t - 1
nk = input()
n = int(nk.split()[0])
k = int(nk.split()[1])
if(n%2 == 0):
print(n + 2*k)
else:
#find first divisor
flag = False
for i in range(2, int(math.sqrt(n) + 1)):
if (n%i == 0):
n... |
Vanya got an important task β he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the bo... | 1 | lis = [9,99,999,9999,99999,999999,9999999,99999999,999999999, 9999999999]
lol = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]
n = int(raw_input())
s = str(n)
ans = 0
k = 1
for i in xrange(len(s)):
if i!=len(s)-1:
ans+=((lis[i]-lol[i]+1)*k)
k+=1
#print ans
else:
#print lol[i]
an... |
You are given an array a_1, a_2, ... , a_n. Array is good if for each pair of indexes i < j the condition j - a_j β i - a_i holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).
For example, if a = [1, 1, ... | 3 | from functools import reduce
from itertools import combinations
import sys
import math
class Read:
@staticmethod
def string():
return input()
@staticmethod
def int():
return int(input())
@staticmethod
def list(delimiter=' '):
return input().split(delimiter)
@st... |
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 3 | a=int(input())
b=[]
for i in range(a):
b.append(input())
c=0
for i in b:
cnt=0
for j in i:
if j=='1':
cnt+=1
if cnt>1:
c+=1
print(c)
|
We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.
It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).
Consider the following action:
* Ch... | 3 | N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
a=[0]
b=[0]
for i in range(N):
a.append(a[i]+A[i])
for i in range(M):
b.append(b[i]+B[i])
j=M
for i in range(N+1):
if a[i]>K:
break
while a[i]+b[j]>K:
j-=1
ans=max(i+j,ans)
print(ans) |
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | 3 | x = [int(i) for i in input().split()]
color = False
for i in range(x[0]):
if color == True:
break
y = input()
if y.find('C') != -1 or y.find('M')!= -1 or y.find('Y')!= -1:
color = True
if color:
print('#Color')
else:
print('#Black&White') |
You are given an array a_{1}, a_{2}, β¦, a_{n}. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct.
In other words, at most one time you can choose two integers l and r (1 β€ l β€ r β€ n) and delete integers a_l, a_{l+1}, β¦, a_r from the array. Remaining elements should be pa... | 1 | n=input()
a=list(map(int,raw_input().split()))
best = n
temp = set()
nodub=True
for x in a:
if x in temp:
nodub=False
break
temp.add(x)
if nodub:
print 0
else:
for i in range(n):
works = True
s = set()
for j in range(i):
if a[j] in s:
w... |
The palindrome is a string that can be read the same way from left to right and from right to left. For example, strings "aaaaa", "1221", "bbaabb" are palindromes, however the string "chef" is not a palindrome because if we read it from right to left, we will obtain "fehc" that is not the same as "chef".
We call a str... | 1 | test = int(raw_input())
while test:
n = int(raw_input())
if(n == 0):
print 0
elif(n%2 == 0):
print n
else:
print n-1
test -= 1 |
You're given two arrays a[1 ... n] and b[1 ... n], both of the same length n.
In order to perform a push operation, you have to choose three integers l, r, k satisfying 1 β€ l β€ r β€ n and k > 0. Then, you will add k to elements a_l, a_{l+1}, β¦, a_r.
For example, if a = [3, 7, 1, 4, 1, 2] and you choose (l = 3, r = 5, ... | 3 | def arr_inp():
return [int(x) for x in input().split()]
t = int(input())
for i in range(t):
sz = int(input())
a, b = arr_inp(), arr_inp()
diff = 0
for j in range(sz):
if (b[j] - a[j] > 0 and diff == 0):
diff = b[j] - a[j]
elif (b[j] - a[j] == 0 and diff!=0):
... |
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds n is defined. I... | 3 | n=int(input())
m=0
c=0
d=0
i=1
while i in range(n+1):
mi,ci=map(int,input().split())
if mi>ci:
m+=1
elif mi<ci:
c+=1
else:
d+=1
i+=1
if m>c:
print('Mishka')
elif m<c:
print('Chris')
else:
print('Friendship is magic!^^') |
The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well.
So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n.... | 3 |
t = int(input())
for x in range(t):
n = int(input())
arr = []
for i in range(n):
arr.append([int(i) for i in input().split( )][1:])
st = set()
unmarr = None
for prin in range(len(arr)):
for i in arr[prin]:
if i not in st:
st.add(i)
... |
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighb... | 3 | # Author: Sofen Hoque Anonta
# Problem: A. Supercentral Point
import sys
import collections
import math
import itertools as it
def readArray(type= int):
line = input()
return [type(x) for x in line.split()]
def solve():
n = int(input())
points = []
for x in range(n):
points.append(readAr... |
Snuke loves puzzles.
Today, he is working on a puzzle using `S`- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below:
9b0bd546db9f28b4093d417b8f274124.png
Snuke decided to create as many `Scc` groups as possible by putting together one ... | 3 | n, m = map(int, input().split())
print(m // 2 if m <= 2 * n else n + (m - 2 * n) // 4)
|
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total?
Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that co... | 3 | a,b,c,x=eval('int(input())+1,'*4);print(sum(c>x/50-I//b*10-I%b*2>0for I in range(a*b))) |
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 s, ... | 3 | k=int(input())
s=input()
d={}
a=""
flag=True
for i in range(len(s)):
if s[i] in d:
d[s[i]]+=1
else:
d[s[i]]=1
for i in d:
if d[i]%k==0:
for j in range(d[i]//k):
a+=i
else:
flag=False
break
if flag :
print(a*k)
else:
print(-1) |
You are given a permutation p=[p_1, p_2, β¦, p_n] of integers from 1 to n. Let's call the number m (1 β€ m β€ n) beautiful, if there exists two indices l, r (1 β€ l β€ r β€ n), such that the numbers [p_l, p_{l+1}, β¦, p_r] is a permutation of numbers 1, 2, β¦, m.
For example, let p = [4, 5, 1, 3, 2, 6]. In this case, the numb... | 3 | import array as arr
T = int(input())
for t in range(T):
n = int(input())
p = arr.array('i',[int(x)-1 for x in input().split()])
for i in range(n):
if p[i]==0:
a=i
break
b=a
ans=[]
ans.append('1')
M=0
m=0
for i in range(1,n):
if a>0 and (b>=n-... |
There is a factory that inputs the data of the side and diagonal lengths to the machine and cuts out the plastic plate. At this factory, we cut out only parallelogram molds, although they vary in size. You have been ordered by your boss to count the number of rectangles and rhombuses produced among the parallelograms t... | 1 | import sys
tyou = 0
hishi = 0
for line in sys.stdin:
L = map(int, line.split(","))
if L:
if (L[2] ** 2 == L[0] ** 2 + L[1] ** 2):
tyou += 1
if (L[0] == L[1]):
hishi += 1
else:
break
print tyou
print hishi |
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, n is always even, and in C2, n is always odd.
You are given a regular polygon with 2 β
n vertices (it's convex and has equal sides and equal angles) and all its sides have length 1. Let's name it as 2n... | 3 | import math
t=int(input())
ans=[]
for s in range(t):
n=int(input())
p=math.tan(float(math.pi/(2*n)))
a=float(1/p)
ans.append(a)
for it in ans:
print("%.9f"%it) |
Lee bought some food for dinner time, but Lee's friends eat dinner in a deadly way. Lee is so scared, he doesn't want to die, at least not before seeing Online IOI 2020...
There are n different types of food and m Lee's best friends. Lee has w_i plates of the i-th type of food and each friend has two different favorit... | 3 | n, m = map(int, input().split())
fs = [[] for i in range(n + 1)]
q, vis, req = [[0] * (n + 1) for i in range(3)]
res, head, tail = [], 0, 0
used = [0] * (m + 1)
w = [0] + list(map(int, input().split()))
for i in range(1, m + 1):
x, y = map(int, input().split())
fs[x].append((i, x, y))
fs[y].append((i, x, ... |
There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.
Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1).
When Mountain i (1 \leq i \l... | 3 | N=int(input())
A=list(map(int,input().split()))
S=sum(A)
B=[0]*N
B[0]=S-2*sum(A[1::2])
for i in range(N-1):
B[i+1]=2*A[i]-B[i]
print(*B) |
Polycarp remembered the 2020-th year, and he is happy with the arrival of the new 2021-th year. To remember such a wonderful moment, Polycarp wants to represent the number n as the sum of a certain number of 2020 and a certain number of 2021.
For example, if:
* n=4041, then the number n can be represented as the s... | 1 | #####################################
import atexit, io, sys, collections, math, heapq, fractions
buffer = io.BytesIO()
sys.stdout = buffer
@atexit.register
def write(): sys.__stdout__.write(buffer.getvalue())
#####################################
def f(n):
u = 0
while(u * 2020 <= n):
if (n - u * 2020)%20... |
Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year... | 3 | class Data:
def __init__(self, dia, mes, ano):
self.dia = dia
self.mes = mes
self.ano = ano
def __lt__(self, other):
if self.ano == other.ano:
if self.mes == other.mes:
return self.dia < other.dia
else:
return self.mes < other.mes
else:
return self.ano < other.ano
def eh_bissexto(ano):
... |
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | 3 | s = input()
exc = 'aeiou'
flag = True
if s[-1] in exc or s[-1] =='n':
for i in range (len(s)-1):
if s[i] in exc or s[i]=='n':
continue
else:
if s[i+1] in exc:
continue
else:
flag= False
break
else:
flag = False
if flag == True:
print('YES')
else:
print('NO') |
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 millis... | 1 | s,v1,v2,t1,t2=map(int,raw_input().split(" "))
x=s*v1+2*t1
y=s*v2+2*t2
if (x>y):
print "Second"
elif(y>x):
print "First"
else:
print "Friendship" |
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living... | 3 | n = int(input())
rooms = 0
for _ in range(n):
p, q = map(int, input().split())
if q-p >= 2:
rooms += 1
else:
pass
print(rooms) |
You have a digit sequence S of length 4. You are wondering which of the following formats S is in:
* YYMM format: the last two digits of the year and the two-digit representation of the month (example: `01` for January), concatenated in this order
* MMYY format: the two-digit representation of the month and the last t... | 3 | s = input()
F = 0 < int(s[:2]) < 13
S = 0 < int(s[2:]) < 13
print("AMBIGUOUS" if F*S else "YYMM" if S else "MMYY" if F else "NA") |
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... | 3 | attempts = int(input())
words = []
for attempt in range(attempts):
word = input()
if len(word) <= 10:
words.append(word)
else:
num = len(word) - 2
words.append(word[0] + str(num) + word[-1])
for elem in words:
print(elem)
|
Your favorite shop sells n Kinder Surprise chocolate eggs. You know that exactly s stickers and exactly t toys are placed in n eggs in total.
Each Kinder Surprise can be one of three types:
* it can contain a single sticker and no toy;
* it can contain a single toy and no sticker;
* it can contain both a sing... | 3 | t = int(input())
for i in range(t):
n, s, t = map(int, input().split())
print(max(s, t) - (s + t - n) + 1)
|
Hanh lives in a shared apartment. There are n people (including Hanh) living there, each has a private fridge.
n fridges are secured by several steel chains. Each steel chain connects two different fridges and is protected by a digital lock. The owner of a fridge knows passcodes of all chains connected to it. A fridg... | 3 | t = int(input())
otv = []
for i in range(t):
sp = input().split()
n = int(sp[0])
m = int(sp[1])
s = input().split()
sp = []
summ = 0
for j in s:
sp.append(int(j))
s = []
if n == 1 or n == 2:
otv.append(-1)
elif m != n:
otv.append(-1)
else:
x = ... |
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg... | 3 | rawa = str(input()).split()
n = int(rawa[0])
k = int(rawa[1])
rawb = str(input()).split()
nums = [int(x) for x in rawb]
smallest = nums[0]
for x in nums:
if (x < smallest):
smallest = x
answer = 0
for x in nums:
if (((x - smallest) % k) != 0):
answer = -1
break
else:
an... |
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." β an excerpt from contest rules.
A total of n participants took part in the contest (n β₯ k), and you already know their scores. Calculate how many ... | 3 | n,k=map(int,input().split())
lis=list(map(int,input().split()))
c=0
for i in lis:
if(i>=lis[k-1] and i>0) :
c=c+1
print(c)
|
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | 3 |
n = int(input())
list1 = []
for i in range(n):
k = list(map(int,input().split()))
k.reverse()
list1.append(k)
list1.sort()
temp = 0
for i in range(len(list1)-1):
if list1[i+1][1] < list1[i][1]:
temp = 1
print( "Happy Alex")
break
if temp == 0:
print("Poor Alex")
... |
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... | 3 | n = int(input())
for i in range(n):
s = input()
l = len(s)
if(l > 10):
print("%s%d%s" % (s[0], l-2, s[l-1]))
else:
print(s)
|
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a... | 3 | n =int(input())
arr = list(map(int, input().split()))
print(["Second","First"][any([i%2 for i in arr])]) |
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 1.... | 3 | n = int(input(''))
i = 0
x = 0
while i < n:
q = input('')
if q == 'X++' or q == '++X':
x += 1
elif q == 'X--' or q == '--X':
x -= 1
i += 1
print(x) |
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... | 3 | n = int(input())
#n, m = map(int, input().split())
a = []
for i in range(n):
s = input()
a.append(s)
#c = list(map(int, input().split()))
x = a[0][0]
y = a[0][1]
l = 0
if x != y:
for i in range(n):
for j in range(n):
if (i == j or n - j - 1 == i):
if x != a[i][j]:
... |
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | 3 | X,Y = input().split()
print (X, Y)
for i in range(int(input())):
A, B = input().split()
if X==A: X = B
elif Y==A: Y = B
print(X,Y)
|
The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign R Rebel spaceships to guard B bases so that every base has exactly one guardian and each spaceship has exactly one assigned base (in other words, the assignment is a perfect matching). Sin... | 1 | print(('No', 'Yes')[len(set(raw_input().split())) == 1]) |
The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system β 201510 = 111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Limak... | 3 | a, b = map(int, input().split())
count = 0
for i in range(2, 61):
num = (1<<i) - 1
for j in range(0, i-1):
if a <= num - (1<<j) <= b:
count += 1
print(count) |
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the... | 3 | from sys import stdin
input=stdin.readline
import bisect
import math
#i = bisect.bisect_left(a, k)
#list=input().split(maxsplit=1)
for xoxo in range(1):
#a=[]
for _ in range (int(input())):
#n=int(input())
ans=0
n,m=map(int, input().split())
ans+=((m//2)*n)
if m%2==1:
... |
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
... | 3 | def main():
from sys import stdin as inp
from sys import stdout as out
n = int(inp.readline().rstrip())
d = {}
ans = [[] for _ in range(n)]
for i in range(n):
name = inp.readline().rstrip()
try:
d[name] += 1
ans[i] = name+str(d[name])
except:
... |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise,... | 3 | def check(coor1, coor2, coor3):
v1 = [coor2[i] - coor1[i] for i in range(5)]
v2 = [coor3[i] - coor1[i] for i in range(5)]
# print(v1, v2)
return scalar_product(v1, v2)
def scalar_product(coor1, coor2):
a1, a2, a3, a4, a5 = coor1
b1, b2, b3, b4, b5 = coor2
return (a1 * b1 + a2 * b2 + a3 * b3... |
Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for n last days: a_1, a_2, ..., a_n, where a_i is the price of berPhone on the day i.
Polycarp considers the price on the day i to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For example, if ... | 3 | t = int(input())
for _ in range(t):
n = int(input())
v = list(map(int, input().split()))
mn = v[-1]
f = 0
while len(v) > 0:
if v[-1] <= mn:
mn = v[-1]
else:
f+=1
v.pop()
print(f) |
Let's denote a k-step ladder as the following structure: exactly k + 2 wooden planks, of which
* two planks of length at least k+1 β the base of the ladder;
* k planks of length at least 1 β the steps of the ladder;
Note that neither the base planks, nor the steps planks are required to be equal.
For example... | 3 | t=int(input())
for i in range(t):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
if(a[1]<=1 or n<=2):
print(0)
else:
print(min(n-2,a[1]-1))
|
You are given an array of n integers: a_1, a_2, β¦, a_n. Your task is to find some non-zero integer d (-10^3 β€ d β€ 10^3) such that, after each number in the array is divided by d, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least βn/2β). Not... | 3 | n = int(input())
pos = 0
neg = 0
zero = 0
a = [int(i) for i in input().split()]
for i in a:
if i > 0:
pos += 1
elif i < 0:
neg += 1
else:
zero += 1
if pos * 2 >= n:
print(1)
elif neg * 2 >= n:
print(-1)
else:
print(0) |
Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem:
There are two arrays of integers a and b of length n. It turned out that array a contains only elements from the set \{-1, 0, 1\}.
Anton can perform the following sequence of operations any number of ti... | 3 | for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
n1=-1
p1=-1
c=0
for i in range(n):
if b[i]>a[i] and p1==-1:
c=1
break
elif b[i]<a[i] and n1==-1:
c=1
break
if... |
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | 3 | from sys import stdin
from collections import defaultdict as dd
n=int(stdin.readline().rstrip())
l=[]
for i in range(n):
p=stdin.readline().rstrip()
l.append(p)
c=1
for i in range(n-1):
if l[i][1]==l[i+1][0]:
c+=1
print(c) |
Anton likes to play chess, and so does his friend Danik.
Once they have played n games in a row. For each game it's known who was the winner β Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this.
Input
The first line of the input contains a... | 3 | n = int(input())
s = input()
anton, danik = 0, 0
for ch in s:
if ch == 'A':
anton += 1
if ch == 'D':
danik += 1
if anton == danik:
print("Friendship")
elif anton > danik:
print("Anton")
else:
print("Danik")
|
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
<image>
The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has t... | 1 | # Hello World program in Python
n = int(raw_input())
os = raw_input()
fs = raw_input()
count = 0
for i in range(0,n):
on = int(os[i])
fn = int(fs[i])
if on < fn:
x = on + 10 - fn
else:
x = 10 - on + fn
if abs(x) < abs(fn-on):
count += x
else:
count += abs(fn... |
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two r... | 3 | n,m=map(int,input().split())
L=[0]*n
for i in range(m):
a,b=map(int,input().split())
L[a-1]=-1
L[b-1]=-1
central=0
for i in range(n):
if L[i]==0:
central=i+1
break
print(n-1)
for i in range(1,n+1):
if i!=central:
print(central,i)
|
Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table M with n rows and n columns such that M_{ij}=a_i β
a_j where a_1, ..., a_n is some sequence of positive integers.
Of course, the girl decided to take it to school with her. But while she was having lunch, hoolig... | 3 | n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
b = []
f = (a[n-3][n-1]*a[n-2][n-1]/a[n-3][n-2])**(1/2)
b.append(f)
for i in range(n-2,-1,-1):
b.append(a[n-1][i]/f)
print(*reversed(list(map(int,b))))
|
Mishka started participating in a programming contest. There are n problems in the contest. Mishka's problem-solving skill is equal to k.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses whic... | 3 | n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in a:
if i <= k:
ans += 1
else:
break
for i in a[:: - 1]:
if i <= k:
ans += 1
else:
break
print(min(n, ans)) |
You are given two segments [l_1; r_1] and [l_2; r_2] on the x-axis. It is guaranteed that l_1 < r_1 and l_2 < r_2. Segments may intersect, overlap or even coincide with each other.
<image> The example of two segments on the x-axis.
Your problem is to find two integers a and b such that l_1 β€ a β€ r_1, l_2 β€ b β€ r_2 an... | 3 | # You are given two segments [l1;r1]
# and [l2;r2] on the x-axis. It is guaranteed that l1<r1 and l2<r2
# . Segments may intersect, overlap or even coincide with each other.
# The example of two segments on the x
# -axis.
# Your problem is to find two integers a
# and b such that l1β€aβ€r1, l2β€bβ€r2 and aβ b. In other wo... |
You are given three integers, A, B and C.
Among them, two are the same, but the remaining one is different from the rest.
For example, when A=5,B=7,C=5, A and C are the same, but B is different.
Find the one that is different from the rest among the given three integers.
Constraints
* -100 \leq A,B,C \leq 100
* A, B ... | 3 | A,B,C=map(int,input().split())
print(C)if A==B else print(B) if A==C else print(A)
|
You are given three integers x, y and n. Your task is to find the maximum integer k such that 0 β€ k β€ n that k mod x = y, where mod is modulo operation. Many programming languages use percent operator % to implement it.
In other words, with given x, y and n you need to find the maximum possible integer from 0 to n tha... | 3 | for t in range(int(input())):
x,y,n = map(int, input().split())
if n%x>=y:
p = n%x - y
print(n-p)
else:
p = y-n%x
n+=p
n-=x
print(n) |
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
* if the last digit of the number is non-zero, she decreases the number by one;
* if the last digit of the number is ze... | 3 | import os
if __name__ == '__main__':
num, time = list(map(int, input().rstrip().split()))
for _ in range(time):
if num>=10 and num%10 == 0:
num = num//10
else:
num = num-1
print(num)
|
Initially, you have the array a consisting of one element 1 (a = [1]).
In one move, you can do one of the following things:
* Increase some (single) element of a by 1 (choose some i from 1 to the current length of a and increase a_i by one);
* Append the copy of some (single) element of a to the end of the array... | 3 | from sys import stdin, stdout
input = stdin.readline
from collections import defaultdict as dd
import math
def geti(): return map(int, input().strip().split())
def getl(): return list(map(int, input().strip().split()))
def gets(): return input()
def geta(): return int(input())
def print_s(s): stdout.write(s+'\n')
def ... |
You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r Γ c grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomei... | 3 | import sys
input=sys.stdin.readline
t=int(input())
for _ in range(t):
r,c=map(int,input().split())
grid=[]
for i in range(r):
l=list(map(str,input().strip()))
l2=[1 if j=='A' else 0 for j in l]
grid+=[l2]
summ=0
for i in grid:
summ+=sum(i)
if(summ==0):
pr... |
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.
Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But t... | 1 | #n,s = map(int,raw_input().split())
#money = [0.0 for _ in xrange(n)]
#flag = False
#tmp = 0
#for i in range(n):
# x,y = map(int,raw_input().split())
# money[i] = x + y*1.0/100
# if money[i] > s:
# continue
# flag = True
# extra = s - money[i]
# sweet = int((extra*1.0 - int(extra))*100)
# if... |
The length of the longest common prefix of two strings s = s_1 s_2 β¦ s_n and t = t_1 t_2 β¦ t_m is defined as the maximum integer k (0 β€ k β€ min(n,m)) such that s_1 s_2 β¦ s_k equals t_1 t_2 β¦ t_k.
Koa the Koala initially has n+1 strings s_1, s_2, ..., s_{n+1}.
For each i (1 β€ i β€ n) she calculated a_i β the length of ... | 3 | """
pppppppppppppppppppp
ppppp ppppppppppppppppppp
ppppppp ppppppppppppppppppppp
pppppppp pppppppppppppppppppppp
pppppppppppppppppppppppppppppppp
pppppppppppppppppppp... |
Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string s and a number k (0 β€ k < |s|).
At the beginning of the game, players are given a substring of s with left border l and right border r, both equal to k ... | 3 | s=input()
n=len(s)
print("Mike")
m=s[0]
i=1
while i<n:
print(("Mike","Ann")[s[i]>m])
m=min(m,s[i])
i+=1
|
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
* deletes all the vowels,
* inserts a character "." before each consonant,
* repl... | 3 |
VOWELS = "AOYEUI"
def main():
string = input()
new_string = ""
for letter in string:
if letter.upper() not in VOWELS:
if letter == letter.upper():
letter = letter.lower()
new_string += "." + letter
print(new_string)
main() |
Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute.
Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in... | 3 | n = int(input())
x = []
for i in range (n):
a, b = map(int, (input().split(':')))
x.append(a*60 + b);
x = sorted(x)
x.append(x[0] + 24*60)
m = 0
for i in range(n):
m = max(m, x[i+1] - x[i]-1)
x = str(m // 60)
y = str(m % 60)
if len(x) < 2:
x = '0' + x
if len(y) < 2:
y = '0' + y
s = x + ':' + y
print... |
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 3 | n=int(input())
b=0
for i in range(n):
a=list(map(int,input().split()))
s=sum(a)
if s >=2:
b+=1
print(b)
|
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." β an excerpt from contest rules.
A total of n participants took part in the contest (n β₯ k), and you already know their scores. Calculate how many ... | 3 | def f(x, y, z):
if z[y - 1] == 0:
cnt = 0
for i in z:
if i > 0:
cnt += 1
return cnt
else:
cnt = 0
for i in z:
if i >= z[y - 1]:
cnt += 1
return cnt
x , y = map(int , input().split())
z = list(map(int, input()... |
Dima worked all day and wrote down on a long paper strip his favorite number n consisting of l digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.
To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive inte... | 3 | d = int(input())
n = input()
j = (d+1)//2
i = j-1
while i>0 and n[i] =='0': i-=1
while j<d and n[j] == '0': j+=1
ans = int(n)
if j<d: ans = min(ans,int(n[:j])+int(n[j:]))
if i>0: ans = min(ans,int(n[:i])+int(n[i:]))
print(ans) |
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
<image>
You should count, how many there are pai... | 3 | n,m = map(int, input().split())
l = set()
for a in range(32):
for b in range(32):
if a*a+b-n==a+b*b-m==0:
l.add((a,b))
#print(l)
print(len(l)) |
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the followin... | 3 | import math
n, k=list(map(int, input().split()))
mid = math.ceil(n/2)
if k>mid:
k=k-mid
print(2*(k%(n-mid+1)))
else:
print(2*k-1) |
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is ... | 3 | ansl1 = list("#" * (100 * 25))
ansl2 = list("." * (100 * 25))
a,b = map(int,input().split())
for i in range(a-1):
ansl1[2*i] = "."
for i in range(b-1):
ansl2[2*i] = "#"
print(100, 100)
for i in range(25):
print("".join(ansl1[(i*100):(i*100)+100]))
print("#"*100)
for j in range(24, -1, -1):
prin... |
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
* Tetrahedron. Tetrahedron has 4 triangular faces.
* Cube. Cube has 6 square faces.
* Octahedron. Octahedron has 8 triangular faces.
* Dodecahedron. Dodecahedron has 12 pentagonal faces.
*... | 3 | a = int(input())
result = 0
for i in range(a):
b = input()
if b == "Tetrahedron":
result += 4
elif b == "Cube":
result += 6
elif b == "Octahedron":
result += 8
elif b == "Dodecahedron":
result += 12
elif b == "Icosahedron":
result += 20
print(result) |
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+'
2. Go 1 unit towards the negative direction, ... | 3 | from math import factorial as f
def count(a, b):
return f(a+b) // f(a) // f(b);
s1 = input()
s2 = input()
pos1 = s1.count('+') - s1.count('-')
pos2 = s2.count('+') - s2.count('-')
a = pos1 - pos2
b = s2.count('?')
s = a + b
if (s % 2 != 0) or (s // 2 > b) or (s // 2 < 0):
print(0)
else:
plus = s // 2
... |
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... | 3 | print(len({x for x in input() if x.isalpha()}))
|
Takahashi is solving quizzes. He has easily solved all but the last one.
The last quiz has three choices: 1, 2, and 3.
With his supernatural power, Takahashi has found out that the choices A and B are both wrong.
Print the correct choice for this problem.
Constraints
* Each of the numbers A and B is 1, 2, or 3.
* ... | 3 | A=int(input())
print(6-A-int(input())) |
Write a program which reads two integers x and y, and prints them in ascending order.
Constraints
* 0 β€ x, y β€ 10000
* the number of datasets β€ 3000
Input
The input consists of multiple datasets. Each dataset consists of two integers x and y separated by a single space.
The input ends with two 0 (when both x and y... | 3 | for i in range(3000):
x,y = sorted(map(int,input().split()))
if x == 0 and y == 0:
break
print(x,y)
|
This is the easy version of the problem. The difference between the versions is that in the easy version all prices a_i are different. You can make hacks if and only if you solved both versions of the problem.
Today is Sage's birthday, and she will go shopping to buy ice spheres. All n ice spheres are placed in a row ... | 3 | import math
def dtb(n):
return bin(n).replace("0b","")
def btd(n):
return int(n,2)
n=int(input())
a=list(map(int,input().split()))[:n]
a.sort()
b=[]
count=0
j=0
if n%2==1:
for i in range(n//2,n):
b.append(a[i])
if j<n//2:
b.append(a[j])
j+=1
for i in range(1,n... |
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their h... | 3 | n = int(input())
arr = [int(i) for i in input().split()]
ma = 0
ima = 0
mi = 100
imi = 0
for i in range(n):
if arr[i] > ma:
ma = arr[i]
ima = i
if arr[i] <= mi:
mi = arr[i]
imi = i
neg = ima > imi
print(ima + n - 1 - imi - neg) |
You are given an array a[0 β¦ n-1] of length n which consists of non-negative integers. Note that array indices start from zero.
An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all i (0 β€ i β€ n - 1) the equality i mod 2 = a[i] m... | 3 | t=int(input())
while(t):
t-=1
n=int(input())
l=list(map(int,input().split()))
x=0
o=0
e=0
for i in range(n):
if l[i]%2==0:
e+=1
else:
o+=1
if n%2==0:
if o==e and o==n//2:
for i in range(0,n,2):
if l[i]%2!=0:
... |
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
* deletes all the vowels,
* inserts a character "." before each consonant,
* repl... | 3 | x= input()
y=''
for i in range(len(x)):
if x[i]== 'a' or x[i] == 'A' or x[i] == 'o' or x[i] == 'O' or x[i] == 'e' or x[i]== 'E' or x[i]== 'I' or x[i]=='i' or x[i]== 'y' or x[i]== 'Y' or x[i]=='U' or x[i]=='u':
y=y
else:
y=y+'.'+x[i]
print(y.lower())
|
There are n candies in a row, they are numbered from left to right from 1 to n. The size of the i-th candy is a_i.
Alice and Bob play an interesting and tasty game: they eat candy. Alice will eat candy from left to right, and Bob β from right to left. The game ends if all the candies are eaten.
The process consists o... | 3 | t = int(input())
for _ in range(t):
n = int(input())
arr = [int(a) for a in input().split()]
sum_a = 0
sum_b = 0
a_i = 0
b_i = n - 1
total_eaten = 0
hods = 0
prev = 0
while total_eaten < n:
cur = 0
if hods % 2 == 0:
while total_eaten < n and cur <= pr... |
Recently Irina arrived to one of the most famous cities of Berland β the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina... | 3 | n, m, T = map(int, input().split())
adj = [[] for _ in range(n+1)]
ad_w = [[] for _ in range(n+1)]
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
pv = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(m):
a, b, t = map(int, input().split())
# matrix[b][a] = t
adj[b].append(a)
ad_w[b].ap... |
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | 1 | guys = ['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard']
mult = 1
diff = 5
n = int(raw_input())
while diff < n:
n -= diff
diff *= 2
mult *= 2
ind = 0
while n > mult:
n-= mult
ind += 1
print guys[ind] |
You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft k torches. One torch can be crafted using one stick and one coal.
Hopefully, you've met a very handsome wandering trader who has two trade offers:
* exchange 1 stick for x sticks (you lose 1 stick and gain x sticks... | 3 | import math
for _ in range(int(input())):
#n = int(input())
x,y,k = list(map(int, input().split()))
need = k*y+k-1
#print(need,"RG")
x = x-1
#print(x,"qwe")
s = (need)//(x)
if s*x != need:
s+=1
#print(s,(need)/(x),"E")
ans = s+k
print(ans)
|
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.
Constraints
* $2 \leq n \leq 100$
* $0 \leq $ the integer assigned to a face $ \leq 100$
Input
In the first line, the number of dices $n$ i... | 3 | import sys
class Dice(object):
def __init__(self, dice):
self.__dice = tuple(dice)
def roll_north(self):
self.__dice = (self.__dice[1], self.__dice[5], self.__dice[2],
self.__dice[3], self.__dice[0], self.__dice[4])
def roll_south(self):
self.__dice = (self.... |
Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!
A password is an array a of n positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and replace them ... | 3 | # https://codeforces.com/contest/1409/problem/B
for ctr in range(int(input())):
lnegth_of_password = int(input())
a = [int(x) for x in input().split()]
a.sort()
print(1 if a[0] != a[-1] else lnegth_of_password)
|
Petya is having a party soon, and he has decided to invite his n friends.
He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one co... | 3 | def main():
n, k = map(int, input().split())
count_1 = n*2//k + 1 if n*2 % k != 0 else n*2//k
count_2 = n*5//k + 1 if n*5 % k != 0 else n*5//k
count_3 = n*8//k + 1 if n*8 % k != 0 else n*8//k
answer = count_1 + count_2 + count_3
print(answer)
if __name__=="__main__":
main()
|
Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero:
<image>
Petr called his car dealer, who in... | 1 | from sys import stdin
rint = lambda: int(stdin.readline())
rint_2d = lambda n: [rint() for _ in range(n)]
get_bit = lambda x, i: (x >> i) & 1
n = rint()
a = rint_2d(n)
for i in range(1 << n + 1):
all = 0
for j in range(n):
bit = get_bit(i, j)
if bit:
all = (all + a[j]) % 360
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.