contestId int64 0 1.01k | name stringlengths 2 54 | prompt stringlengths 297 7.35k | response stringlengths 32 43.6k |
|---|---|---|---|
109 | Lucky Interval | Title: Lucky Interval
Time Limit: 4 seconds
Memory Limit: 512 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One ... | ```python
import sys
class HappyNumbers:
def solve(self):
a, l = map(int, input().split())
print(self.doit(a, l))
def doit(self, a, l):
if l >= 10:
first = a
last = a + l - 1
return self.doit(first // 10, last // 10 - first // 10 + 1) * 10 + f... |
113 | Grammar Lessons | Title: Grammar Lessons
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the lang... | ```python
s=input().split()
if(len(s)==1):
if(s[0].endswith("lios") or s[0].endswith("etr") or s[0].endswith("liala") or s[0].endswith("etra") or s[0].endswith("inites") or s[0].endswith("initis")):
print("YES")
else:
print("NO")
elif(s[0].endswith("lios") or s[0].endswith("etr")):
n=len... |
61 | Capture Valerian | Title: Capture Valerian
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.
Recently the Romans declared war on Persia. They dreamed to occupy Armenia.... | ```python
a, b = input().strip().split(' ')
c = input()
a = int(a)
def conv(num,b):
convStr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if num < b:
return convStr[num]
else:
return conv(num//b,b) + convStr[num % b]
def write_roman(num):
val = [
1000, 900, 500, ... |
61 | Hard Work | Title: Hard Work
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer!
Some days before the contest, the teache... | ```python
word1 = input().lower()
word1 = word1.replace(";", "").replace("-", "").replace("_", "")
word2 = input().lower()
word2 = word2.replace(";", "").replace("-", "").replace("_", "")
word3 = input().lower()
word3 = word3.replace(";", "").replace("-", "").replace("_", "")
possibilities = [word1+word2+word3, word... |
61 | Ultra-Fast Mathematician | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
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 10... | ```python
s=input()
s1=input()
n=""
for i in range(len(s)):
if s[i]=="1" and s1[i]=="1":
n=n+"0"
elif s[i]=="0" and s1[i]=="0":
n=n+"0"
else:
n=n+"1"
print(n)
``` |
6 | President's Office | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ... | ```python
# / *
#
# / \ | | / \ | | | |
# / __\ | | / __\ |--| | |
# / \ |__ | __ / \ | | \__ /
#
# __ __
# / \ | / | ) / \ | )
# / __\ |< |-< / __\ |-<
# / \ | \ |__) / \ | \
#
# * /
def main():
nc, mc, p_c ... |
56 | Bar | Title: Bar
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya h... | ```python
def readln(): return tuple(map(int, input().split()))
lst = 'ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE'.split(', ')
n, = readln()
ans = 0
for _ in range(n):
inp = input()
try:
if int(inp) < 18:
ans += 1
except:
if inp in lst:
... |
8 | Beads | Title: Beads
Time Limit: 5 seconds
Memory Limit: 64 megabytes
Problem Description:
One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with... | ```python
n, m = map(int, input().split())
m += 1
def calc(l, r, eq, eq_i):
if l > r:
return 1
key = l, eq, eq_i
if key in f:
return f[key]
t = 0
for x in (['0', '1'] if s[l] == '?' else [s[l]]):
if l == r:
a = [x]
else:
a... |
1 | Theatre Square | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
import math
x,y,z=list(map(float, input().split()))
print(math.ceil(x/z)*math.ceil(y/z))
``` |
35 | Animals | Title: Animals
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he h... | ```python
import sys
sys.stdin = open('input.txt')
sys.stdout = open('output.txt', 'w')
A = lambda: map(int, input().split())
yesh, s = A()
k = 0
for q in sorted(q * (yesh - i) for i, q in enumerate(A())):
s -= q
if s < 0: break
k += 1
print(k)
``` |
34 | Sale | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
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... | ```python
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
res = 0
for i in range(m):
if a[i] < 0:
res += abs(a[i])
else:
break
print(res)
``` |
32 | Borze | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
ls=[]
str=input()
op=" "
i=0
while i<len(str):
if str[i]=='.':
op=op+"0"
if str[i]=='-':
if str[i+1]=='.':
i=i+1
op=op+"1"
elif str[i+1]=='-':
i=i+1
op=op+"2"
i=i+1
print(op)
``` |
29 | Traffic Lights | Title: Traffic Lights
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A car moves from point A to point B at speed *v* meters per second. The action takes place on the X-axis. At the distance *d* meters from A there are traffic lights. Starting from time 0, for the first *g* seconds the green ... | ```python
l, d, v, g, r = map(int,input().split())
t = 0.0
if (d/v)%(g+r) < g:
t = l/v
else:
t = ((d / v)// (g + r)+1)*(g+r) + (l-d)/v
print("%.8f"%t)
``` |
20 | Equation | Title: Equation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input Specification:
The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=1... | ```python
a,b,c=map(int,input().split())
t=[1,-c/b]if b else[-(c==0)]
if a:
d,x=b*b-4*a*c, -2*a
if d: t=[0]if d<0 else[2]+sorted([(b-d**0.5)/x,(b+d**0.5)/x])
else: t=[1,b/x]
print(*t)
``` |
78 | Easter Eggs | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
lst='ROYGBIV'
n=int(input())
print(lst,end='')
for j in range(7,n):
k=(j-4)
print(lst[k],end='')
lst+=lst[k]
print()
``` |
47 | Coins | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
def find_coin_order(weightings):
coins = [0, 0, 0]
for weighting in weightings:
coin1, relation, coin2 = weighting
if relation == '>':
coins[ord(coin1) - ord('A')] += 1
coins[ord(coin2) - ord('A')] -= 1
else:
coins[ord(coin1) - or... |
43 | Letter | Title: Letter
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to... | ```python
a=''.join(input().split())
b=''.join(input().split())
c=set(list(b))
q=True
for i in c:
if b.count(i)>a.count(i):
q=False
if q:
print('YES')
else:
print('NO')
``` |
112 | Petya and Square | Title: Petya and Square
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves playing with squares. Mum bought him a square 2*n*<=×<=2*n* in size. Petya marked a cell inside the square and now he is solving the following task.
The task is to draw a broken line that would go along... | ```python
a,b,c=map(int,input().split())
if(b==a//2 or b==a//2+1) and (c==a//2 or c==a//2+1):
print("NO")
else:
print("YES")
``` |
58 | Chat room | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=list(input())
n='NO'
for i in range(len(s)):
if s[i]=='h' :
for i_1 in range(i,len(s)):
if s[i_1]=='e' :
for i_2 in range(i_1,len(s)):
if s[i_2]=='l' :
for i_3 in range(i_2+1,len(s)):
if ... |
71 | Way Too Long Words | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
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 character... | ```python
def way_too_long_words(txt_arr):
res = []
for input_txt in txt_arr:
n = len(input_txt)
if n <= 10:
res.append(input_txt)
else:
res.append(input_txt[0] + str(n-2) + input_txt[-1])
return res
if __name__ == "__main__":
n = int(input())
... |
50 | Domino piling | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m, n = [int(i) for i in input().split()]
x = 2
S = n * m
s = 0
print(S // x)
``` |
43 | Football | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
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... | ```python
n=int(input())
has={}
for i in range(n):
x=input()
if x in has:
has[x]=has[x]+1
else:
has[x]=1
x=max(has.values())
for i in has.keys():
if has[i]==x:
print(i)
``` |
59 | Word | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
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 ei... | ```python
x = input()
upper = 0
lower = 0
for i in x:
if i.isupper():
upper = upper +1
if i.islower():
lower = lower +1
if lower>=upper:
print(x.lower())
else:
print(x.upper())
``` |
41 | Translation | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
s = input()
s_2 = input()
print('YES' if s == s_2[::-1] else 'NO')
``` |
110 | Nearly Lucky Number | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
#!/usr/bin/env python
# coding: utf-8
# In[38]:
n = input()
count = 0
for digit in n:
if digit == '4' or digit == '7':
count += 1
if set(str(count)) <= set('47'):
print("YES")
else:
print("NO")
#
# In[ ]:
``` |
29 | Spit Problem | Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ... | ```python
def camels_spits():
n = int(input())
camels_map = [0]*20001 # (-)-10000 + 10000 + 1 (referente ao zero) - Assim o vetor vai do 0 ao 20.000
to_map = 10000
camels = []
for i in range(n):
x, d = input().split()
camels.append({"x": int(x), "d": int(d)})
camels_map[int(x)+to_map] = {"x": int(x), "d": ... |
49 | Sleuth | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
klh = input().strip(" ?").lower()
if klh[-1] in "aeiouy":
print("YES")
else:
print("NO")
``` |
112 | Petya and Strings | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
# Read the two strings
str1 = input().lower() # Convert to lowercase
str2 = input().lower() # Convert to lowercase
# Compare the two strings
if str1 < str2:
print("-1")
elif str1> str2:
print("1")
else:
print("0")#vii
``` |
34 | Reconnaissance 2 | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*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... | ```python
count_time=False
if count_time:
import time
start_time = time.time()
#-----------------------------------------
n=int(input())
a=list(map(int,input().split()))
x,y=n,1
mino=abs(a[-1]-a[0])
for i in range(1,n):
e=abs(a[i]-a[i-1])
if e<mino:
x,y=i,i+1
mino=e
print(x... |
84 | Toy Army | Title: Toy Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on t... | ```python
import sys
input = sys.stdin.readline
n = int(input())
print(n*3//2)
``` |
63 | Sinking Ship | Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ... | ```python
# Function to determine the evacuation order
def evacuate_crew(n, crew_info):
# Create a list of tuples (name, status, position)
crew_list = [(crew_info[i][0], crew_info[i][1], i) for i in range(n)]
# Define a custom sorting order
def sorting_order(member):
order = {"rat": 1, "... |
108 | Palindromic Times | Title: Palindromic Times
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling... | ```python
h,m=map(int,input().split(':'))
while True:
m+=1
if m==60:
m=0
h+=1
if h==24:
h=0
if len(str(h))<2:
soat='0'+str(h)
else:
soat=str(h)
if len(str(m))<2:
daqiqa='0'+str(m)
else:
daqiqa=str(m)
vaqt... |
92 | Chips | Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
n,m=map(int,input().split())
temp=n*(n+1)//2
for i in range(100000000):
if temp<=m:
m-=temp
elif temp>m:
break
if m==0:
print(0)
else:
for i in range(1,n+1):
if m>=i:
m-=i
elif m<i:
print(m)
break
``` |
80 | Panoramix's Prediction | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
c=0
p=0
n,m=map(int,input().split())
f=True
for i in range(2, int(m/2)+1):
if (m % i) == 0:
print('NO')
f=False
break
for i in range(n+1,m+1):
for j in range(2, m+1):
if (i % j) == 0:
c+=1
if c==1:
... |
35 | Shell Game | Title: Shell Game
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly put... | ```python
with open("input.txt") as f :
d = f.readlines()
d = [i.strip('\n') for i in d]
ball = d[0]
lines = d[1:]
for i in lines :
initial, final = [j for j in i.split()]
if initial == ball :
ball = final
elif final == ball :
ball = initial
with open("outpu... |
69 | Young Physicist | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
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. S... | ```python
n=int(input())
c1=c2=c3=0
for i in range(n):
x,y,z=map(int,input().split())
c1+=x
c2+=y
c3+=z
if(c1==c2==c3==0):
print('YES')
else:
print('NO')
``` |
104 | Blackjack | Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Co... | ```python
n = int ( input () )
if n >= 1 and n <= 25:
b = int ( n - 10 )
if b < 10 and b > 0:
print ( 4 )
elif b == 10 :
print ( 15 )
elif b == 11 :
print ( 4 )
else :
print ( 0 )
``` |
51 | Cheaterius's Problem | Title: Cheaterius's Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive... | ```python
def Contains(myList, helper):
for i in range(4):
if helper in myList:
return True
helper = '{}{}{}{}'.format(helper[2], helper[0], helper[3], helper[1])
return False
n = int(input())
myList = []
helper = ""
while n > 0:
helper = input() + input()
if n... |
31 | Worms Evolution | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
n=int(input())
a=list(map(int,input().split()))
f=0
for j in range(n):
for k in range(n):
if j!=k:
if a[j]+a[k] in a:
print(a.index(a[j]+a[k])+1,j+1,k+1)
f=1
break
if f==1:
break
if f==0:
print(-1)
``` |
90 | Cableway | Title: Cableway
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cabl... | ```python
num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
str_inp=lambda:input()
r,g,b=map(int,input().split())
f=lambda x:(0--x//2-1)*3
print(max(f(r),1+f(g),2+f(b))+30)
``` |
75 | Life Without Zeros | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
n1 = int(input())
n2 = int(input())
sum = n1 + n2
n1 , n2 , sum = str(n1) , str(n2) , str(sum)
n1 =n1.replace("0","")
n2 = n2.replace("0", "")
sum = sum.replace("0", "")
n1 , n2 , sum = int(n1) , int(n2) , int(sum)
sum1 = (n1) + n2
if sum1 == sum :
print("YES")
else:
print("NO")
... |
78 | Haiku | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase... | ```python
print('YES' if [sum(s.count(x) for x in "aeiou") for s in [input() for _ in range(3)]]==[5,7,5] else 'NO')
``` |
27 | Next Test | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«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... | ```python
def solve(arr) :
arr.sort()
arr.insert(0,0)
for i in range(n) :
if arr[i+1]-arr[i]>1 :
return arr[i]+1
return arr[-1]+1
from sys import stdin
input = stdin.readline
n=int(input())
arr=[int(x) for x in input().split()]
print(solve(arr))
... |
26 | Almost Prime | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
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*, in... | ```python
r = int(input())
k = [0]*(r+1)
for x in range(2, r+1):
if k[x]==0:
for y in range(2*x, r+1, x):
k[y]+=1
print(k.count(2))
``` |
70 | Cookies | Title: Cookies
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which li... | ```python
n=int(input())
print(3**((max(0,n-1)))%1000003)
``` |
20 | BerOS file system | Title: BerOS file system
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/n... | ```python
s=input()
l=s.split("/")
l=[i for i in l if i!=""]
print("/"+"/".join(l))
``` |
36 | Extra-terrestrial Intelligence | Title: Extra-terrestrial Intelligence
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* da... | ```python
readFile = open('input.txt', 'r')
n = int(readFile.readline())
line = readFile.readline()
readFile.close()
prev, sample, ans = -1, -1, 'YES'
for i in range(n):
if line[i] == '1' and prev == -1:
prev = i
elif line[i] == '1' and sample == -1:
sample = i - prev - 1
pre... |
82 | Double Cola | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
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 resultin... | ```python
a = int(input())
i = 0
s = 5
while s < a:
i += 1
s += 5 * 2 ** i
n = ['Sheldon'] + ['Leonard'] + ['Penny'] + ['Rajesh'] + ['Howard']
print(n[(a - (s - 5 * 2 ** i) - 1) // 2 ** i])
``` |
47 | Triangular numbers | Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
n = int(input())
cont, i = [], 1
while i * (i + 1) // 2 <= 500:
cont.append(i * (i + 1) // 2)
i += 1
print('YES' if n in cont else 'NO')
``` |
12 | Fruits | Title: Fruits
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some ... | ```python
enter1 = list(map(int, input().split()))
n = enter1[0]
m = enter1[1]
li = list(map(int, input().split()))
fruits = list()
for i in range(m):
fruits.append(input())
se = set(fruits)
kol_vo = []
li_se = list(se)
for i in range(len(li_se)):
kol_vo.append(fruits.count(li_se[i]))
kol_vo.sort()
kol_vo.r... |
44 | Anfisa the Monkey | Title: Anfisa the Monkey
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she ... | ```python
k,a,b= map(int, input().split())
s = input()
n = len(s)
if k*a>n or k*b<n:
print("No solution")
else:
c = 0
o = n//k
m = n%k
for i in range(k):
d = o + (i < m)
print(s[c:c + d])
c+= d
``` |
44 | Indian Summer | Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
lst1=[]
lst2=[]
test=int(input())
for i in range(test):
x=input()
if x not in lst1:
lst1.append(x)
else:
lst2.append(x)
print(len(lst1))
``` |
45 | Codecraft III | Title: Codecraft III
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
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 *... | ```python
month=input()
k=int(input())
month_list=['January','February','March','April','May','June','July','August','September','October','November','December']
for i in range(12):
if month_list[i]==month:
index=i
break
list_index=index+k+1
if list_index>12:
list_index%=12
print(month... |
25 | IQ test | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 11 15:33:18 2022
@author: 86158
"""
n = int(input())
list0 = [int(i) for i in input().split()]
list1 = []
for i in range(n):
list1.append(list0[i]%2)
a = list1.count(0)
if a == 1:
print(list1.index(0)+1)
else:
print(list1.index(1)+1)... |
17 | Noldbach problem | Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a prob... | ```python
n, k = map(int, input().split())
prime = [3, 5]
curr = 2
res = 0
for number in range(7, n+1, 2):
i = 0
while i < curr and number % prime[i] != 0:
i += 1
if i == curr:
for j in range(1, curr):
if prime[j] + prime[j-1] + 1 == number:
k -= 1
... |
25 | Phone numbers | Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33.... | ```python
n = int(input())
s = list(input())
l = []
if n%2 == 0:
for i in range(n):
if i%2 == 0:
a = s[i] + s[i+1]
l.append(a)
else:
for i in range(n-3):
if i%2 == 0:
a = s[i] + s[i+1]
l.append(a)
a = s[-3] + s[-2] + s[-1]
... |
22 | Second Order Statistics | Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
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 statis... | ```python
input();
d=sorted(set(map(int,input().split())));
print(d[1] if len(d)>1 else "NO")
``` |
12 | Super Agent | Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparin... | ```python
a = [ input() for i in range(3)]
b = "YES"
for i in range(3):
if a[0][i] != a[2][2-i]:
b = "NO"
if a[1][0] != a[1][2]:
b = "NO"
print(b)
``` |
38 | Army | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
def years_to_reach_rank(a, b, rank_times):
total_years = 0
for i in range(a, b):
total_years += rank_times[i - 1]
return total_years
n = int(input(""))
rank_times = list(map(int, input("").split(" ")))
ab = input("").split(' ')
a, b = int(ab[0]), int(ab[1])
print(years_to_reach_rank(a, b... |
46 | Ball Game | Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think... | ```python
n = int(input())
current = 0
for k in range(1, n):
current += k
current %= n
print(current + 1, end=" ")
print()
``` |
39 | Multiplication Table | Title: Multiplication Table
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large... | ```python
k = int(input())
base = list(range(1, k))
result = [[i * x for x in base] for i in range(1, k)]
for i in range(k - 1):
row = []
for j in range(k - 1):
product = []
while result[i][j]:
product.append(str(result[i][j] % k))
result[i][j] //= k
row... |
7 | Kalevitch and Chess | Title: Kalevitch and Chess
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch de... | ```python
board = [input(), input(), input(), input(), input(), input(), input(), input()]
row_count = 0
col_count = 0
col_index = []
def return_index(ele, inp):
rslt = []
for i in range(len(inp)):
if inp[i] == ele:
rslt.append(i)
return rslt
for row in board:
if row == 'BBBBBBB... |
16 | Flag | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of... | ```python
n, m = map(int, input().split())
failure = False
cur = -1
for i in range(0, n):
st = set(input())
for a in st:
if a == cur:
failure = True
else:
cur = a
if len(st) > 1:
failure = True
print('YES') if failure == False else print('NO')
... |
39 | Company Income Growth | Title: Company Income Growth
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company... | ```python
n = int(input())
a = list(map(int, input().split()))
result = []
curr = 1
for i, e in enumerate(a):
if e == curr:
curr += 1
result.append(2001 + i)
print(len(result))
if result:
print(*result)
``` |
15 | Cottage Village | Title: Cottage Village
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. I... | ```python
n,t=map(int,input().split()); a=[]; q=2
a=sorted(list(map(int,input().split()))for _ in range(n))
for i in range(n-1):
l=a[i][0]+t+(a[i][1]+a[i+1][1])/2;r=a[i+1][0]
if l==r:q+=1
if l<r:q+=2
print(q)
``` |
6 | Triangle | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
def check (x,y,z) :
if x + y > z and x + z > y and z + y > x :
return 'T'
if x + y == z or x + z == y or z + y == x:
return 'S'
return 'I'
a, b, c, d = [int(item) for item in input().split(' ')]
if check(a,b,c) == 'T' or check(a,b,d) == 'T' or check(a,d,c) == 'T' or check(... |
48 | Rock-paper-scissors | Title: Rock-paper-scissors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ... | ```python
f = input()
m = input()
s = input()
out = 0
if f == "rock":
if m == "scissors" and s == "scissors":
out = 1
elif m == "rock" and s == "paper":
out = 3
elif s == "rock" and m == "paper":
out = 2
elif f == "paper":
if m == "rock" and s == "rock":
... |
46 | Hamsters and Tigers | Title: Hamsters and Tigers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap ... | ```python
n = int(input())
s = input()
s = s+s
count = s.count("H") // 2
x = 0
for i in range(n):
z = s[i:i + count].count('H')
x = max(x,z)
print(count-x)
``` |
39 | Cubical Planet | Title: Cubical Planet
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite v... | ```python
# LUOGU_RID: 133990995
a=map(int,input().split())
a=list(a)
b=map(int,input().split())
b=list(b)
for i in range(3): #有三个坐标0-2,没有取到三
if a[i]==b[i]: #当比较到相同的就相遇
print('YES')
break #然后结束
if i==2: #当比较到第三个坐标没有相同就是不相遇
print('NO')
``` |
38 | Chess | Title: Chess
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=×<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.
Your task is to find the number of wa... | ```python
q=input()
w=input()
s={q,w}
l=set()
for i in"abcdefgh":
for j in "12345678":
l.add(i+j)
s.add(q[0]+j)
s.add(i+q[1])
for i in [-2,-1,1,2]:
for j in [-2,-1,1,2]:
if abs(i)!=abs(j):
z=chr(ord(q[0])+i)+str(int(q[1])+j)
if z in l:
... |
24 | Ring road | Title: Ring road
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were conne... | ```python
'''
Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
n=int(input())
l=[]
for _ in range(n):
l.append(list(map(int,input().split())))
d={}
adj=[[] ... |
37 | Towers | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n = int(input())
a = list(map(int, input().split()))
a.sort()
x = y = 1
t = 1
for i in range(1, n):
if a[i] != a[i-1]:
t = 1
y += 1
else:
t += 1
if t > x: x = t
print(str(x)+' '+str(y))
``` |
62 | A Student's Dream | Title: A Student's Dream
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming t... | ```python
def readln(): return tuple(map(int, input().split()))
al, ar = readln()
bl, br = readln()
print('YES' if al - 1 <= br <= (al + 1) * 2 or ar - 1 <= bl <= (ar + 1) * 2 else 'NO')
``` |
43 | Lucky Tickets | Title: Lucky Tickets
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collec... | ```python
input()
myList = list(map(int, input().split()))
rem0, rem1, rem2 = 0, 0, 0
for it in myList:
if it % 3 == 0:
rem0 += 1
elif it % 3 == 1:
rem1 += 1
else:
rem2 += 1
print(rem0//2 + min(rem2,rem1))
``` |
66 | Petya and File System | Title: Petya and File System
Time Limit: 3 seconds
Memory Limit: 256 megabytes
Problem Description:
Recently, on a programming lesson little Petya showed how quickly he can create files and folders on the computer. But he got soon fed up with this activity, and he decided to do a much more useful thing. He decided t... | ```python
import sys
def main():
path_set = set()
is_created = {}
storage = {}
freq_folders = {}
folder_recorded = {}
for path in sys.stdin:
path = path.strip()
if path in path_set:
continue
path_set.add(path)
if path not in is_crea... |
33 | What is for dinner? | Title: What is for dinner?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that... | ```python
I=[int(i) for i in input().split()]
n, m, k = I[0], I[1], I[2]
Min=[10**6 for i in range(m)]
for i in range(n):
I=[int(j) for j in input().split()]
r, c = I[0], I[1]
if c<Min[r-1]: Min[r-1]=c
ans=sum(Min)
if ans>k: print(k)
else: print(ans)
``` |
55 | Pie or die | Title: Pie or die
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Volodya and Vlad play the following game. There are *k* pies at the cells of *n*<=<=×<=<=*m* board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can ... | ```python
n, m, k = [int(x) for x in input().split()]
canwin = False
for i in range(k):
x, y = [int(x) for x in input().split()]
canwin |= x < 6 or n - x < 5
canwin |= y < 6 or m - y < 5
print("YES" if canwin else "NO")
``` |
7 | Defining Macros | Title: Defining Macros
Time Limit: 3 seconds
Memory Limit: 256 megabytes
Problem Description:
Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use.
In this problem we consider the fo... | ```python
class Macro:
def __init__(self, level):
self.level = level
def __add__(self, other):
return Macro('+0'[self.level == '0' or other.level == '0'])
def __sub__(self, other):
return Macro('+0'[self.level == '0' or other.level in '0+'])
def __mul__(self, other):... |
26 | Regular Bracket Sequence | Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
L=input()
c1=0
c2=0
for i in L:
if i=="(":
c1+=1
else:
if c1>0:
c2+=2
c1-=1
print(c2)
``` |
27 | Number With The Given Amount Of Divisors | Title: Number With The Given Amount Of Divisors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018.
Input Specification:
The first line... | ```python
ans = 2e18
now = []
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def dfs(x):
global ans
if x == 1:
res = 1
for i in range(len(now)):
res *= pow(p[i], now[i] - 1)
if res > 1e18:
return
ans = min(ans, res)
for i in range(x, 1,... |
49 | Game | Title: Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya and Petya have invented a new game. Vasya takes a stripe consisting of 1<=×<=*n* square and paints the squares black and white. After that Petya can start moves — during a move he may choose any two neighboring squares of one co... | ```python
n=int(input())
s=input()
q="01"*n
k=0
for i in range(n):
if s[i]!=q[i]:
k+=1
print(min(k,n-k))
``` |
31 | Chocolate | Title: Chocolate
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob has a rectangular chocolate bar of the size *W*<=×<=*H*. He introduced a cartesian coordinate system so that the point (0,<=0) corresponds to the lower-left corner of the bar, and the point (*W*,<=*H*) corresponds to the uppe... | ```python
from bisect import bisect as bt
w,h,n=map(int,input().split())
N,M=max(w,h),10
x=[[0,h]]+[[] for _ in range(N-1)]
y=[[0,w]]+[[] for _ in range(N-1)]
xy=[[0]*(N+1) for _ in range(N+1)]
g=[0]*M+[[]]
xy[0][0]=1
xs,ys={0},{0}
def t(k,p):
for i,j in zip(k,p):
q=bt(i,j)
if q==0 or i[q-1]!=j:
... |
26 | Tickets | Title: Tickets
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes l... | ```python
num,p,w=map(int,input().split())
if w<p<=w+num:
n=1
for i in range(w+1):
n*=(p-i)/(num+w-(i-1))
print(1-n)
else:
print(0 if p>num+w else 1)
``` |
66 | Petya and His Friends | Title: Petya and His Friends
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to *n*.
Let us remind you the definition of the greatest common divis... | ```python
def func(a):
for i in range(2,a):
if a%i==0:
return False
return True
t = int(input())
if t==2:
print(-1)
else:
k = 2
d = []
c=0
while c+1 <= t:
if func(k):
d.append(k)
c+=1
k+=1
f = 1
for i... |
27 | Ring Road 2 | Title: Ring Road 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
It is well known that Berland has *n* cities, which form the Silver ring — cities *i* and *i*<=+<=1 (1<=≤<=*i*<=<<=*n*) are connected by a road, as well as the cities *n* and 1. The goverment have decided to build *m* new ro... | ```python
m=int(input().split()[1])
s=[[sorted([*map(int,input().split())]),-1,[]] for _ in range(m)]
def d(n,c):
if s[n][1]==c:return
if s[n][1]!=-1:
print('Impossible')
exit()
s[n][1]=c
for i in s[n][2]:d(i,1-c)
for i,j in enumerate(s):
for h,k in enumerate(s[i+1:],i+1):
if... |
63 | Dividing Island | Title: Dividing Island
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A revolution took place on the Buka Island. New government replaced the old one. The new government includes *n* parties and each of them is entitled to some part of the island according to their contribution to the revolut... | ```python
def solve(x0, y0, dx, X):
for i, x in enumerate(X):
while x > 0:
x-=1
m[y0][x0] = i
x0 += dx
if x == 0 and i == len(X)-1:
break
if x0 == -1:
y0 += 1
x0 = 0
... |
34 | Page Numbers | Title: Page Numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page number... | ```python
a = sorted(set(map(int, input().split(","))))
left = right = a[0]
for x in a[1:]:
if x - right > 1:
if left == right:
print(left, end=",")
else:
print(left, right, sep="-", end=",")
left = x
right = x
if left == right:
print(left)
else:
print(lef... |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 4