problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he... | 1 | n = int(input())
for i in range(0, n+1, 1234567):
for j in range(0, n-i+1, 123456):
if(n-i-j)%1234==0:
print "YES"
exit(0)
print "NO" |
Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers.
For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it.
Su... | 3 | x, y, l, r = map(int, input().split())
def gen_list(var):
cur = 1
while cur <= r:
yield cur
cur *= var
x_list = list(gen_list(x))
# print(x_list)
y_list = list(gen_list(y))
# print(y_list)
numbers = [l-1, r+1]
for _x in x_list:
for _y in y_list:
n = _x + _y
if n < l or n ... |
In order to do some research, n^2 labs are built on different heights of a mountain. Let's enumerate them with integers from 1 to n^2, such that the lab with the number 1 is at the lowest place, the lab with the number 2 is at the second-lowest place, …, the lab with the number n^2 is at the highest place.
To transpor... | 3 | from sys import stdin
from collections import deque,Counter,defaultdict,OrderedDict
import sys
import math,os
import operator
import random
from fractions import Fraction
import functools
import bisect
import itertools
from heapq import *
import time
import random
import bisect
import copy
n = int(input())
s = []
matr... |
There are n benches in the Berland Central park. It is known that a_i people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available.
Let k be the maximum number of people sitting on one bench after additional m people c... | 3 | from math import ceil
n = int(input())
m = int(input())
a = [int(input()) for i in range(n)]
print(max(max(a), ceil((sum(a)+m)/n)), max(a)+m) |
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is it... | 3 | import sys
n=int(input())
x=input().split(' ')
if n==1:
print(1)
sys.exit()
c=1
X=[]
j=0
while j<n-1:
if int(x[j])<=int(x[j+1]):
c+=1
else:
X.append(c)
c=1
j+=1
if j==n-1:
X.append(c)
print(max(X))
|
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D e... | 3 | n, m, k = map(int, input().split())
if k < n:
print("%d 1" % (k+1))
else:
k -= n
co = n - k // (m-1)
if k // (m-1) & 1:
li = m - k % (m-1)
else:
li = k % (m-1) + 2
print(co, li)
# print("{:d} {:d}".format(1+n-(k-n+1)//(m-1), ((k-n+1)%((m-1)*2)+1)%m+1))
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Pety... | 1 | I=lambda:map(int, raw_input().split())
a, b = raw_input(), raw_input()
c, d = 0, 0
for i in xrange(len(a)):
if a[i] != b[i]:
if a[i] == '4': c += 1
else: d += 1
print max(c, d) |
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string s consisting of n lowercase Latin letters.
You have to color all its characters one of the two ... | 3 | import sys
import collections
input = sys.stdin.readline
def main():
N = int(input())
S = input().strip()
first = 0
second = 0
ans = []
for i, s in enumerate(S):
if i == 0:
first = ord(s) - ord('a')
ans.append(0)
else:
if ord(s) - ord('a') ... |
You have n barrels lined up in a row, numbered from left to right from one. Initially, the i-th barrel contains a_i liters of water.
You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels x and y (the x-th barrel shouldn't be empty) and pour any possible amount of wa... | 3 | for _ in range(int(input())):
n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
j = 0
for i in range(n-2,n-2-k,-1):
if a[i]==0:
break
a[-1]+=a[i]
a[i]=0
print(max(a)-min(a)) |
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either inc... | 3 | n,k=map(int,input().split())
L=list(map(int,input().split()))
L.reverse()
coins=0
var=-1
change=0
while(True):
for i in range(n):
if(L[i]<k and L[i]!=var):
change+=1
var=L[i]
L[i]+=1
if(change>0):
coins+=1
var=-1
change=0
else:
brea... |
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | 3 | a = list(input().strip())
a = list(set(a))
if len(a)%2 == 1:
print('IGNORE HIM!')
else:
print('CHAT WITH HER!') |
Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should... | 3 | n = int(input())
v1 = list(map(int, input().split()))
v2 = sorted(v1)
v1, v2 = [0] + v1, [0] + v2
for i in range(1, n + 1):
v2[i] += v2[i - 1]
v1[i] += v1[i - 1]
m = int(input())
for i in range(m):
t, l, r = map(int, input().split())
if t == 1:
print (v1[r] - v1[l - 1])
else:
print (... |
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... | 1 | f=raw_input
print ['YES','NO'][sorted(f()+f())!=sorted(f())]
|
Reversed number is a number written in arabic numerals but the order of digits is reversed.
The first digit becomes last and vice versa. For example, if the number is 1245,it will become
5421 .Note that all the leading zeros are omitted. That means if the number ends with a zero,
the zero is lost by reversing (e.g.... | 1 | import sys
t=input()
while(t>0):
sumu=0
n, m = map(int, sys.stdin.readline().split(' '))
n=str(n)[::-1]
n=int(n)
m=str(m)[::-1]
m=int(m)
sumu=n+m
sumu=str(sumu)[::-1]
sumu=int(sumu)
print sumu
t=t-1 |
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Eve... | 3 | n=int(input())
a=[]
for i in range(n) :
x=input()
a.append(x)
b=list(set(a))
c=[]
for i in range(len(b)) :
c.append(a.count(b[i]))
print(b[c.index((max(c)))])
|
There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0, 0), and coordinate axes are left and bottom sides of the table, then the bott... | 3 |
def cut(A, B):
"""
B interior in A
"""
return [(max([A[0][0], B[0][0]]), max([A[0][1], B[0][1]])),
(min([A[1][0], B[1][0]]), min([A[1][1], B[1][1]]))]
def area(A):
if A[1][0] < A[0][0] or A[1][1] < A[0][1]:
return 0
return max([(A[1][0] - A[0][0]) * (A[1][1] - A[0][1]), 0]... |
You are given a permutation p_1, p_2, ..., p_n. Recall that sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.
Find three indices i, j and k such that:
* 1 ≤ i < j < k ≤ n;
* p_i < p_j and p_j > p_k.
Or say that there are no such indices.
Input
The first lin... | 3 | t = int(input())
for i in range(t):
n = int(input())
array = [int(s) for s in input().split()]
flag = False
for i in range(len(array) - 2):
if array[i] < array[i + 1] and array[i + 1] > array[i + 2]:
print("YES")
print(i + 1, i + 2, i + 3)
flag = True
... |
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handk... | 3 | n = int(input())
tmp = list()
for i in range(n+1):
spaces = ' ' * (n - i) * 2
val_l = ''.join(str(i)+' ' for i in range(i))
val_r = ''.join(' ' + str(i) for i in range(i, -1, -1))
tmp.append(spaces+val_l+val_r[1:])
for el in tmp:
print(el)
for el in tmp[:-1][::-1]:
print(el)
|
This morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this... | 3 | from sys import stdin,stdout
from collections import Counter
nmbr=lambda:int(stdin.readline())
lst=lambda:list(map(int, stdin.readline().split()))
for _ in range(1):#int(stdin.readline())):
n,k=lst()
a=lst()
one=a.count(1)
neg_one=n-one
ans=0
for b in range(k):
o,no=one,neg_one
f... |
There are n kids, numbered from 1 to n, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as p_1, p_2, ..., p_n (all these numbers are from 1 to n and are distinct, so p is a permutation). Let the next kid for a kid p_i be kid p_{i + 1} if i < n and p_1 otherwise. After the da... | 3 | def solve_problem(kids_count, triplets_list):
for i in range(kids_count):
[idx, a1, a2] = triplets_list[i]
if triplets_list[a1-1][1] != a2 and triplets_list[a1-1][2] != a2:
# swap a1 and a2
swap = triplets_list[i][1]
triplets_list[i][1] = triplets_list[i][2]
... |
A penguin Rocher has n sticks. He has exactly one stick with length i for all 1 ≤ i ≤ n.
He can connect some sticks. If he connects two sticks that have lengths a and b, he gets one stick with length a + b. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his se... | 3 | for _ in range(int(input())):
n=int(input())
print(-(-n//2))
|
Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.
The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
From a road square, you can move to a horizontally or vertically adjacent ro... | 3 | from collections import deque
h, w = map(int, input().split())
a = ''.join(input() + '#' for _ in range(h))
n = len(a)
b = ['#'] * w
w += 1
q = deque()
r = 0
for i in range(n):
if a[i] == '.':
b[: 1 - w] = a
b[i] = 0
q.append(i)
while(q):
i = q.popleft()
r = max(r, b[i])
for j in (-... |
So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks... | 3 |
a, x, y = map(lambda x: 2 * int(x), input().split())
if 0 <= y <= a:
if 0 < y < a and -a // 2 < x < a // 2:
print("1")
else:
print("-1")
else:
y = y - a
if ((y + a - 1) // a) % 2 == 1:
if y % a != 0 and -a // 2 < x < a // 2:
print(2 + 3 * (((y + a - 1) // a) // 2))
... |
On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible.
The j-th key can be used to unlock the ... | 3 | N, M = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
o1, o2 = 0, 0
e1, e2 = 0, 0
for i in A:
if i%2 == 0:
e1 += 1
else:
o1 += 1
for i in B:
if i%2 == 0:
e2 += 1
else:
o2 += 1
print(min(o1, e2) + min(o2, e1))
|
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.
These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of t... | 3 | def g(q, x, f, a):
if(((a + q - 1) // q) - ((q - 1) * f) <= x):
return True
else:
return False
s = input()
n = int(s)
s = input()
y = s.split()
s = input()
s = s.split()
x = int(s[0])
f = int(s[1])
ans = 0
for i in y:
ans += (int(i) + f - 1) // (x + f)
print(ans * f) |
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu... | 3 | n=int(input())
s=[int(i) for i in input().split()][:n]
a=0
b=0
c=0
d=0
f=0
for i in s:
if(i==1):
a+=1
elif(i==2):
b+=1
elif(i==3):
c+=1
else:
d+=1
f=f+d
if(a>c):
f=f+c
a=a-c
c=0
else:
f=f+c
a=0
c=0
if(b%2==0):
f=f+b//2
b=0
else:
f=f+b/... |
<image>
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just... | 3 | import sys
import io, os
input = sys.stdin.buffer.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
n = int(input())
A = [int(input()) for i in range(n)]
#print(A)
ans = []
for i, a in enumerate(A):
if i == 0:
ans.append(st... |
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 |
for _ in range(int(input())):
w=input()
if len(w)<=10:
print(w)
else:
print(w[0],str(len(w)-2),w[-1],sep="") |
Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with?
Input
The first... | 3 | import sys
import math
if __name__=='__main__':
n,k=[int(x) for x in input().split()]
n_str=list(input())
n_arr=[int(x) for x in n_str]
ln=len(n_arr)
rn,i=0,0
while(k>0 and i<n):
if(k>0 and i==0 and ln>1):
if(n_arr[i]==1):
i+=1
continue
... |
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of a × b chairs — a rows of b chairs each. Two ch... | 3 | members, row, column = [int(a) for a in input().split(' ')]
if members <= row * column:
current_row = []
current_members_in_current_row = 0
flip = 1
for row_number in range(row):
while current_members_in_current_row != column:
current_row.append(str(members))
current_memb... |
There are n piles of stones, where the i-th pile has a_i stones. Two people play a game, where they take alternating turns removing stones.
In a move, a player may remove a positive number of stones from the first non-empty pile (the pile with the minimal index, that has at least one stone). The first player who canno... | 3 | def solve(arr,n,ans):
moves = 0
while arr and arr[0] == 1:
moves += 1
arr.pop(0)
if not arr:
moves += 1
if moves%2 == 0:
ans.append('First')
else:
ans.append('Second')
def main():
t = int(input())
ans = []
for i in range(t):
n = int(input... |
It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.
Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":
* "A" corresponds to an angry... | 3 | for _ in range(int(input())):
n=int(input())
s=str(input())
s=list(s)
r=0
a=[]
a.append(0)
for i in range(n-1,-1,-1):
if s[i]=="P":
r+=1
elif s[i]=="A":
a.append(r)
r=0
print(max(a))
|
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 divisor: GCD(a1, ..., ak) = d, where d represents such a maximal positive number that each ai (1 ≤ i ≤ k) is e... | 3 | import math
n=int(input())
if n==2:
print(-1)
exit(0)
print(15)
print(10)
print(12)
n-=3
m=2
while n>0:
n-=1
print(12*m)
m+=1 |
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.
What is the least number of flagstones needed to pave the Square? It'... | 3 | import math
n, m, a =[int(x) for x in input().split()]
if n<1 or m<1 or a<1:
print("Invalido")
elif n>1000000000 or m>1000000000 or a>1000000000:
print("Invalido")
else:
R=math.ceil(n/a)*math.ceil(m/a)
print(R)
|
On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains.
Mountains are described by a sequence of heights... | 3 | def f(i):
if i-1>=0 and i+1<=n-1:
if a[i-1]<a[i]>a[i+1]:return True
else:return False
else:return False
for _ in range(int(input())):
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
p,l=0,0
for i in range(1,k-1):
if f(i):p+=1
m=p
for i in range(k-1,n-1):
if f(i):p+=1
if f(i-k+2):p-... |
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | 3 | n=list(input())
n=set(n)
if(len(n)%2!=0):
print("IGNORE HIM!")
else:
print("CHAT WITH HER!") |
Construct a dice from a given sequence of integers in the same way as Dice I.
You are given integers on the top face and the front face after the dice was rolled in the same way as Dice I. Write a program to print an integer on the right side face.
<image>
Constraints
* $0 \leq $ the integer assigned to a face $ ... | 3 | class Daise:
def __init__(self, info_list):
self.T = info_list[0]
self.S = info_list[1]
self.E = info_list[2]
self.W = info_list[3]
self.N = info_list[4]
self.B = info_list[5]
def change(self, axis):
if axis == 'S':
self.T, self.B, self.S,... |
Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other.
He noticed that the two rabbits were hopping towards each other. The positions of the two rabbits ... | 3 | t = int(input())
for i in range(t):
x,y,a,b = map(int,input().split())
g =(y-x)/(a+b)
if g==(y-x)//(a+b):
print(int(g))
else:
print("-1") |
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after... | 3 | a=sorted([int(i) for i in input().split()])
k=int(input())
a[-1]*=2**k
print(sum(a)) |
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 | x,y = [int(x) for x in input().split()]
while y>0:
if x%10 == 0:
x=int(x/10)
else:
x=x-1
y=y-1
print(x) |
Our Code Monk recently learnt about Graphs and is very excited!
He went over to the Graph-making factory to watch some freshly prepared graphs. Incidentally, one of the workers at the factory was ill today, so Monk decided to step in and do her job.
The Monk's Job is to Identify whether the incoming graph is a tr... | 1 | vertices=input()
degree=map(int,raw_input().split(" "))
if vertices>=1 and vertices<=1000:
if sum(degree)==2*(vertices-1):
print "Yes"
else:
print "No" |
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of... | 3 | # You lost the game.
n,m,a,b = map(int, input().split())
print(min([a*n,b*(n//m)+a*(n%m),b*(1+n//m)]))
|
You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly less than any number chosen in the second array.
Input
The first line contains t... | 1 | nA , nB = map(int, raw_input().split())
k , m = map(int, raw_input().split())
A = map(int, raw_input().split())
B = map(int, raw_input().split())
A_ = A[:k]
B_ = B[nB - m:]
ans = 'NO'
if A_[-1] < B_[0]:
ans = 'YES'
print ans |
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.
A Bitlandish string is a string made only of characters "0" and "1".
BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish ... | 3 | a,b = input(),input()
if len(a) != len(b):
print('NO')
elif ('1' in a) == ('1' in b):
print('YES')
else:
print('NO') |
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
<image>
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times... | 3 | def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
s = input().strip()
a = s.count('-')
b = s.count('o')
if b:
print('YES' if a % b == 0 else 'NO')
else:
print('YES') |
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 | n= int(input())
for i in range(n):
e,s,t=map(int,input().split())
if(s<t):
tm=(e-s)+1
else:
tm=(e-t)+1
print("{}".format(tm));
|
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | 3 | a=input()
A=[]
for i in range(len(a)):
A.append(a[i])
counter=len(a)-1
while counter>=0:
A.append(a[counter])
counter=counter-1
s=""
for i in A:
s=s+i
print(s)
|
Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order.
After checking some examples, she found out that sometimes it wasn't true. On some papers authors' names weren't sorted in l... | 1 | import sys
class Graph:
def __init__(self):
self.size = 0
self.adj = {}
self.indegree = {}
def addEdge(self, u, v):
if not self.adj.has_key(u):
self.adj[u] = []
if not self.indegree.has_key(u):
self.indegree[u] = 0
self.si... |
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 | for _ in range(int(input())):
w=input()
if(len(w)<=10):
print(w)
else:
print(w[0]+str(len(w)-2)+w[-1]) |
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | 3 | def pr(x):
fl=1
for n in range(2,int(x**.5)+2):
if x%n==0:
fl=0
break
else:
fl=1
# print(n)
if x==2:
fl=1
return fl
#print(pr(99))
x=int(input())
for n in range(4,x):
if pr(n)==0 and pr(x-n)==0:
print("{} {}".format(n,x-n))
break |
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight... | 3 | a,b=map(int,input().split())
count=0
while (a<=b):
a=a*3
b=b*2
count += 1
print (count) |
Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets.
Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair ... | 3 | n=int(input())
l=list(map(int,input().split()))
d=[0]*2000001
m=0
for i in range(n):
for j in range(i):
d[l[i]+l[j]]+=1
m=max(m,d[l[i]+l[j]])
print(m)
|
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 | from sys import stdin, stdout
def main():
word = stdin.readline().rstrip()
vowels = "AOYEUI"
index = 0
wordlength = len(word)
while index < wordlength:
if word[index].upper() in vowels:
word = word[:index] + word[index + 1:]
index -= 1
else:
wor... |
A permutation of length n is an array p=[p_1,p_2,...,p_n], which contains every integer from 1 to n (inclusive) and, moreover, each number appears exactly once. For example, p=[3,1,4,2,5] is a permutation of length 5.
For a given number n (n ≥ 2), find a permutation p in which absolute difference (that is, the absolut... | 3 | a = [2, 4, 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 169, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 233, 237, 241, 245, 249, 253, 257, 261, 265, 26... |
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximu... | 3 | def str_finder(s):
counter = counter_str(s)
for i in range(len(s)):
if s[i] == "V":
new = s[:i] + 'K' + s[i + 1:]
else:
new = s[:i] + 'V' + s[i + 1:]
if counter_str(new) > counter:
counter = counter_str(new)
return counter
def counter_str(s):
... |
Bob has a string s consisting of lowercase English letters. He defines s' to be the string after removing all "a" characters from s (keeping all other characters in the same order). He then generates a new string t by concatenating s and s'. In other words, t=s+s' (look at notes for an example).
You are given a string... | 3 | t=input()
length=len(t)
count=0
for i in t:
if i=="a":
count+=1
slength=(length+count)/2
if int(slength)==slength:
s=t[0:int(slength)]
s1=""
for i in s:
if i!="a":
s1+=i
s2=t[int(slength):]
if s1==s2:
print (s)
else:
print (":(")
else:
print (":(") |
You are given a string S of length 2N consisting of lowercase English letters.
There are 2^{2N} ways to color each character in S red or blue. Among these ways, how many satisfy the following condition?
* The string obtained by reading the characters painted red from left to right is equal to the string obtained by r... | 3 | N=int(input())
S=list(input())
left=S[:N]
right=S[N:][::-1]
ans=0
for i in range(2**N):
red=[]
blue=[]
for j in range(N):
if (i>>j)&1==1:
red.append(S[j])
else:
blue.append(S[j])
L=len(red)
if L==0 or L==N:
if right==left:
ans+=1
co... |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …, a_n, in ... | 3 | from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
dica = dict()
dicb = dict()
ks = dict()
for i in range(n):
dica[a[i]] = i
dicb[b[i]] = i
#print(dica,dicb)
for i in dica.keys():
t = dicb[i] - dica[i]
if t>0:
if t not in ks... |
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | 3 | import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
n = ini()
a = inl()
if a == sorted(a):
print("yes")
print(1, 1)
elif a == sorted(a, reverse=True):
print("yes")
... |
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | 3 | x=0
a='THEQUICKBROWNFOXJUMPSOVERLAZYDOG'
n=input()
s=input()
for i in a:
if (i not in s) and (i.lower() not in s):
x=1
break
if x==0:
print('YES')
else:
print('NO') |
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.
The robber girl was angry at first, but then she decided to arrange the animals herself. She ... | 3 | n = int(input())
a = [int(s) for s in input().split()]
for j in range(n):
k = 0
i = 0
while i < n-1:
if a[i] > a[i+1]:
k += 1
tmp = a[i]
a[i] = a[i+1]
a[i+1] = tmp
print(i+1, i+2)
i += 2
i = 1
while i < n-1:
if a[i] ... |
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the... | 3 | n,h=input().split()
n,h=int(n),int(h)
a=[int(x) for x in input().split()]
count=0
for i in a:
if i>h:
count+=2
else:
count+=1
print(count) |
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.
When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be... | 3 | from fractions import gcd
n = int(input())
a = [int(z) for z in input().split()]
g = 0
for i in range(n):
g = gcd(g, a[i])
if a[0] != g:
print(-1)
exit(0)
print(2 * n)
for i in range(n):
print(g, a[i], end=" ")
|
You a captain of a ship. Initially you are standing in a point (x_1, y_1) (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point (x_2, y_2).
You know the weather forecast — the string s of length n, consisting only of letters U, D, L and R. The letter corresponds t... | 3 | # -*- coding: utf-8 -*-
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd
from heapq import heappop, heappush, heapify, heappushpop
from bisect im... |
The term of this problem is the same as the previous one, the only exception — increased restrictions.
Input
The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence a1, a2, ...,... | 1 | import threading
import sys
first_line = raw_input().split()
n = int(first_line[0])
k = int(first_line[1])
a = [ int(x) for x in raw_input().split() ]
b = [ int(x) for x in raw_input().split() ]
c = [0] * n
def solution(a, b, k):
if len(a) == 1:
print((b[0]+k) // a[0])
return
a, b, c = fir... |
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input
The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-... | 1 | ans=0
a=raw_input()
v = 0
# b=a[:: -1]
for i in range(len(a)):
for j in range(len(a)-i):
z=a[j:i+j+1]
y= a.find(z)
ans=a[y+1:].find(z)
if ans!= -1 :
v=len(z)
print v
|
There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the... | 3 | import sys
input = sys.stdin.readline
t=int(input())
for tests in range(t):
n=int(input())
A=list(map(int,input().split()))
MAX=max(A)
for i in range(n):
if A[i]==MAX:
if i>0 and A[i]>A[i-1]:
print(i+1)
break
if i<n-1 and A[i]>A[i+1]:
... |
You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | 3 |
l=[]
for i in range(5):
l.append(list(map(int,input().split())))
for i in range(5):
for j in range(5):
if(l[i][j]==1):
print(abs(2-i)+abs(2-j))
|
Chef Shifu and Chef Po are participating in the Greatest Dumpling Fight of 2012.
Of course, Masterchef Oogway has formed the rules of the fight.
There is a long horizontal rope of infinite length with a center point P.
Initially both Chef Shifu and Chef Po will stand on the center P of the rope facing each other.
Don... | 1 | def gcd(a,b):
if a< 0:
return gcd(-a,b)
if b == 0:
return a
else:
return gcd(b,a%b)
t = int(raw_input())
while t > 0:
a,b,c,d,k=raw_input().split(' ')
a=int(a)
b=int(b)
c=int(c)
d=int(d)
k=int(k)
gcd1 = gcd(a,b)
gcd2 = gcd(c,d)
lcm = gcd1*gcd2/gc... |
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself,... | 3 | t = int(input())
for case in range(t):
n = int(input())
array1 = [x for x in range(n)]
array2 = [int(x) for x in input().split()]
array3 = set()
for i in range(n):
array3.add((array1[i] + array2[i]) % n)
if len(array3) == n:
print ("YES")
else:
print ("NO")
... |
This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well).
A... | 3 | for _ in range(1):
n=int(input())
arr=[0]*(10**5 +1)
ma=[0,0,0,0,0]
a=list(map(int,input().split()))
cnt=[0]*(10**5 + 1)
for i in a:
arr[i]+=1
cnt[arr[i]]+=1
# print(cnt)
for i in range(int(input())):
s,k=map(str,input().split())
k=int(k)
if s=... |
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the i-th safe fro... | 3 | oleg, seq1, seq2 = map(int, input().split())
lenofqup = int(input())
qup = map(int, input().split())
s = 0
if seq1 < oleg < seq2:
for i in qup:
if seq1<i<seq2:
s += 1
elif oleg < seq1:
for i in qup:
if i<seq1:
s += 1
elif seq2 < oleg:
for i in qup:
if seq2<i:
s += 1
print(s) |
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 pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | 3 | q=input()
a=input()
n=len(q)
if q[n::-1]==a:
print("YES")
else:
print("NO")
|
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fi... | 3 | import sys
n = int(input())
d1 = list(map(int, input().split(" ")))
d2 = list(map(int, input().split(" ")))
k1 = d1[0]
k2 = d2[0]
d1.remove(d1[0])
d2.remove(d2[0])
moves = 0
while True:
if moves > 500000:
print(-1)
sys.exit(0)
a = d1[0]
d1.remove(d1[0])
b = d2[0]
d2.remove(d2[0])
... |
problem
Create a program that counts the number of consecutive JOI or IOI characters in a given character string. The character string consists only of uppercase letters of the alphabet. For example, the character string "JOIOIOI" in the figure below contains JOI in one place and IOI in two places.
<image>
input
... | 3 | while True:
try:
s = input().strip()
except:
break
i = 0
cnt_joi, cnt_ioi = 0, 0
while i < len(s) - 2:
t = s[i:i + 3]
if t == 'JOI':
cnt_joi += 1
i += 2
elif t == 'IOI':
cnt_ioi += 1
i += 2
elif t[2] == '... |
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.
There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned ... | 3 | n=int(input())
k=0; b=[]
for i in range(n):
s=input().replace("-1","4")
if s.find("3")==-1 and s.find("1")==-1:
k+=1
b.append(i+1)
print(k)
if k>0:
z=""
for x in b:
z+=str(x)+" "
print(z)
|
A permutation of length n is a sequence of integers from 1 to n of length n containing each number exactly once. For example, [1], [4, 3, 5, 1, 2], [3, 2, 1] are permutations, and [1, 1], [0, 1], [2, 2, 1, 4] are not.
There was a permutation p[1 ... n]. It was merged with itself. In other words, let's take two instanc... | 3 | t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
d=[]
for i in a:
if i not in d:
d.append(i)
print(*d)
|
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 | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for ... |
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | 3 | lista = list(map(int,input().split("+")))
lista.sort()
for i in range(0,len(lista)):
print(lista[i],end = "+\n"[i == len(lista) -1])
|
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measure... | 3 | n, l, x, y = map(int, input().split())
a = set(map(int, input().split()))
ok1 = ok2 = ok3 = False
for c in a:
if c + x in a:
ok1 = True
if c + y in a:
ok2 = True
if c - x > 0 and c - x + y in a:
ok3 = True
mark = c - x
if c + x < l and c + x - y in a:
ok3 = True
... |
Chef is going to participate in a new quiz show: "Who dares to be a millionaire?"
According to the rules of the game, contestants must answer N questions. The quiz being famous for its difficulty, each question has 26 candidate answers, but only one of which is correct. Answers are denoted by capital Latin letters from... | 1 | test = input()
for i in xrange(test):
n = input()
ans = raw_input()
chef = raw_input()
W = map(int, raw_input().split())
correct = 0
for i in range(n):
if(ans[i] == chef[i]):
correct += 1
if(correct != n):
print max(W[:correct+1])
else:
print W[n] |
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())
for _ in range (T):
n = int(input())
print (1/(math.tan (math.pi/(2*n)))) |
Write a program which reverses a given string str.
Input
str (the size of str ≤ 20) is given in a line.
Output
Print the reversed str in a line.
Example
Input
w32nimda
Output
admin23w | 3 | if __name__ == "__main__":
a = input().strip().split()[0]
print(a[::-1]) |
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight... | 3 | l, b = map(int, input().split())
count = 0
while l <= b:
l *= 3
b *= 2
count += 1
print(count) |
There are n + 2 towns located on a coordinate line, numbered from 0 to n + 1. The i-th town is located at the point i.
You build a radio tower in each of the towns 1, 2, ..., n with probability 1/2 (these events are independent). After that, you want to set the signal power on each tower to some integer from 1 to n (s... | 3 | n = int(input())
dp = [1, 1]
for i in range(n - 2):
dp.append(dp[-1] + dp[-2])
dp = dp[1:]
x = dp[-1]
m = 998244353
y = pow(2, n, m)
y_inv = pow(y,m-2,m)
ans = (x * y_inv) % m
print(ans) |
Santa has to send presents to the kids. He has a large stack of n presents, numbered from 1 to n; the topmost present has number a_1, the next present is a_2, and so on; the bottom present has number a_n. All numbers are distinct.
Santa has a list of m distinct presents he has to send: b_1, b_2, ..., b_m. He will send... | 3 | import os
import sys
from io import BytesIO, IOBase
def solution(arr, brr, n, m):
pos = [0] * (n + 1)
last_gift = -1
arr.insert(0, 0)
brr.insert(0, 0)
for i in range(1, n + 1):
pos[arr[i]] = i
res = 0
taken = 0
for i in range(1, m + 1):
if pos[brr[i]] > last_gift:
... |
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The ... | 3 | n, k = map(int, input().split())
ans = 0
arr = [int(x) for x in input().split()]
for x in arr:
if x + k <= 5:
ans += 1
print(ans // 3) |
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
Input
The first line contai... | 3 | n = int(input())
m = int(input())
l = []
i = -1
j = 0
ans = 0
for i in range(n):
s = int(input())
l.append(s)
l.sort()
while j < m:
j += l[i]
i -= 1
ans += 1
print(ans)
|
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auct... | 1 | n=input()
bid=map(int,raw_input().split())
bid2=[]
bid2=bid2+bid
bid2.sort()
bid2=bid2[::-1]
price=bid2[1]
prid=bid2[0]
bidder=bid.index(prid)
print bidder+1, price
|
You are given two positive integers n and k. Print the k-th positive integer that is not divisible by n.
For example, if n=3, and k=7, then all numbers that are not divisible by 3 are: 1, 2, 4, 5, 7, 8, 10, 11, 13 .... The 7-th number among them is 10.
Input
The first line contains an integer t (1 ≤ t ≤ 1000) — the ... | 3 | import sys
t = int(input())
for j in range(t):
n,k = map(int,input().split())
ans = int(k/(n-1))
ans= ans*n
ans = ans+ k%(n-1)
if ans%n==0:
print(ans-1)
continue
print(ans) |
Not so long ago as a result of combat operations the main Berland place of interest — the magic clock — was damaged. The cannon's balls made several holes in the clock, that's why the residents are concerned about the repair. The magic clock can be represented as an infinite Cartesian plane, where the origin correspond... | 3 | import math
import sys
x,y=map(int,input().split())
is_right=(x*y>=0)
r=(x**2+y**2)**0.5
if r%1==0:
print("black")
else:
if is_right:
if r%2>1:
print("white")
else:
print("black")
else:
if r%2>1:
print("black")
else:
print("w... |
Petya has a rectangular Board of size n × m. Initially, k chips are placed on the board, i-th chip is located in the cell at the intersection of sx_i-th row and sy_i-th column.
In one action, Petya can move all the chips to the left, right, down or up by 1 cell.
If the chip was in the (x, y) cell, then after the oper... | 3 | n,m,k=map(int,input().split());m-=1;n-=1;a='U'*n+'L'*m+''.join('RL'[i%2]*m+'D'for i in range(n+1));print(len(a),a) |
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The s... | 3 | k,d,t=map(int,input().split())
m= (k+d-1)//d
extra=m*d - k
c=extra/2.0
tot=k+c
dd=t//tot
ans=dd*(k+extra)
xx= t - dd*tot
if xx<=k:
ans=ans+xx
else:
ans=ans+k
xx=xx-k
ans=ans + xx*2
print(float(ans)) |
Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.
All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases... | 3 | I=input
for _ in[0]*int(I()):
x=y=0;f=1
for _ in[0]*int(I()):p,c=map(int,I().split());f&=0<=c-y<=p-x;x=p;y=c
print('NYOE S'[f::2])
#HC
|
Arkady bought an air ticket from a city A to a city C. Unfortunately, there are no direct flights, but there are a lot of flights from A to a city B, and from B to C.
There are n flights from A to B, they depart at time moments a_1, a_2, a_3, ..., a_n and arrive at B t_a moments later.
There are m flights from B to C... | 3 | import sys
input=sys.stdin.readline
n,mm,ta,tb,k=map(int,input().split())
def bsl(a,val):
l=0
r=len(a)-1
ans=len(a)
while l<=r:
m=l+(r-l)//2
if a[m]==val:
r=m-1
ans=m
elif a[m]>val:
ans=m
r=m-1
else:
l=m+1
... |
You are given a simple connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects Vertex A_i and Vertex B_i. Takahashi will assign one of the two possible directions to each of the edges in the graph to make a directed graph. Determine if it is possible to make ... | 3 |
"""
無理な場合を考えてみよう
→全体の辺の本数が奇数なら絶対無理
それ以外は?
説1:辺が偶数なら絶対作れる説
辺を選択し、そのどちらか片方にのみ xor1する
→すべての辺の数字を0にできるか??(初期値は0)
なんかできそう
辺の向きを変えることで1を伝播させることが出来る
→同じ点にぶつけられる!!
ので、偶数本なら絶対できる
どうやって構成する?
適当に置く→1の点を適当に2つ選び、パス上にある辺を全部反転させる
確かにできるけど…遅くね?
もっと簡単にできないか?
適当に木を取る→深い方から整合性を合わせていけば終わり(最終的には根に収束するので)
各点に関して動かすのは高々1辺だけだから、木を取った辺の... |
There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only p levels of the game. And Little Y can pass only q levels of the game. You are given the indices of levels Little X can pass ... | 3 | n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
c=a[1:] + b[1:]
c.sort()
k=[]
for i in c:
if i not in k:
k.append(i)
if len(k)==n:
print("I become the guy.")
else:
print("Oh, my keyboard!")
|
Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.
There are two sequences of n strings s_1, s_2, s_3, …, s_{n} and m strings t_1, t_2, t_3, …, t_{m}. ... | 3 | n,m=map(int,input().split())
s=list(input().split())
t=list(input().split())
for _ in range(int(input())):
q=int(input())-1
x=s[q%n]+t[q%m]
print(x) |
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
<image>
Mehrdad has become quite confused and wants you to help him. Please hel... | 3 | m = int(input())
print([6,8,4,2][m % 4] if m > 0 else 1)
|
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that:
* 1 ≤ a ≤ n.
* If it's Mahmoud's turn, a has to be even, but if it's Ehab's turn, a has... | 3 | import sys
def main():
n = int(sys.stdin.readline())
if n % 2 == 0:
print("Mahmoud")
else:
print("Ehab")
if __name__ == "__main__":
main() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.