problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 β€ li < ri β€ n)... | 3 | s=[str(i) for i in input()]
ans=[0]
num=0
answer=[]
for i in range(1,len(s)):
if s[i]==s[i-1]:
num+=1
ans.append(num)
for i in range(int(input())):
l,r=map(int,input().split())
answer.append(str(ans[r-1]-ans[l-1]))
print('\n'.join(answer)) |
A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:
* The first term s is given as input.
* Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.
* a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.
Find the minimum integer m that satisfies the following conditio... | 3 | a = []
a.append(int(input()))
i=0
while len(a)==len(set(a)):
if a[i]%2==0:
a.append(a[i]/2)
else:
a.append(a[i]*3+1)
i += 1
print(i+1) |
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order ... | 3 | i=int(input())
print(i//5) if i%5==0 else print((i//5)+1)
|
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them.
The tree looks like a polyline on the plane, consisting o... | 3 | x=int(input());a=sorted(list(map(int,input().split())))
print(sum(a[:x//2])**2+sum(a[x//2:])**2) |
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
Constraints
* 1 \leq a, b, c \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
a \ b \ c
Output
If \sqrt{a} + \sqrt{b} < \sqrt{c}, print `Yes`; otherwise, print `No`.
Examples
Input
2 3 9
Output
No
I... | 1 | a,b,c = map(int, raw_input().split(' '))
print 'Yes' if a+b < c and 4*a*b < (c - a - b) **2 else 'No'
|
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided t... | 3 | t=int(input())
a=input()
z=a.count('z')
e=a.count('e')
r=a.count('r')
o=a.count('o')
n=a.count('n')
num=[]
for i in range(n):
num.append('1')
for j in range(z):
num.append('0')
number=' '.join(num)
print(number) |
Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant is described by a string of length n which contains characters ... | 3 | for _ in range(int(input())):
n,l=map(int,input().split())
a=input()
c=0
k=0
if l==n:
for i in a:
if i=='1':
c+=1
break
if c>0:
c=0
else:
c=1
else:
i=0
c=0
k=0
if a[0]=='... |
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 letters can be deleted from the typed word so that it resulted in the word "hello". For example, if... | 3 | n=input()
a=0
s=''
c=0
for i in range(len(n)):
if s=='hello':
break
elif n[i]=='h' and a==0:
s=s+'h'
a=1
elif s=='h' and n[i]=='e':
s=s+'e'
elif (s=='he' or s=='hel') and n[i]=='l':
s=s+'l'
elif s=='hell' and n[i]=='o' and c==0:
s=s+'o'
c=1
if ... |
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
... | 3 | inp = input()
inp1 = list(map(int,input().split()))
Max = max(inp1)
out = int()
if len(inp1) > 1:
for x in inp1:
out = out + Max - x
print(out)
else:
print(0) |
Leo has developed a new programming language C+=. In C+=, integer variables can only be changed with a "+=" operation that adds the right-hand side value to the left-hand side variable. For example, performing "a += b" when a = 2, b = 3 changes the value of a to 5 (the value of b does not change).
In a prototype progr... | 3 | t = int(input())
for case in range(t):
a, b, n = list(map(int, input().split(' ')))
if a > b:
temp = b
b = a
a = temp
counter = 0
while (max(a, b) <= n):
temp = b
b = a + b
a = temp
counter += 1
print(counter)
|
There is a frog staying to the left of the string s = s_1 s_2 β¦ s_n consisting of n characters (to be more precise, the frog initially stays at the cell 0). Each character of s is either 'L' or 'R'. It means that if the frog is staying at the i-th cell and the i-th character is 'L', the frog can jump only to the left. ... | 3 | import math
q=int(input())
#q=1
for _ in range(q):
#n=int(input())
#n,m=map(int,input().split())
#l=list(map(int,input().split()))
s=list(input())
n=len(s)
maxx=0
k=0
for i in range(n):
if i==0 and s[i]=='L':
k+=1
elif s[i]=='L' and s[i-1]=='L':
k... |
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 ... | 1 | n = int(raw_input().strip())
a = map(int, raw_input().split())
b =map(int, raw_input().split())
con = True
for i in range(1,n+1):
if i not in a[1:] and i not in b[1:]:
con = False
if con:
print 'I become the guy.'
else:
print 'Oh, my keyboard!' |
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 should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | 3 | s=0
k=0
for i in (5,7,5):
s=0
n=input().split()
for m in n:
for j in m:
if(j in ('a','i','o','e','u')):
s=s+1
if(s==i):
k=k+1
if(k==3):
print('YES')
else:
print('NO')
|
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are roun... | 3 | t=int(input())
for _ in range(t):
n=int(input())
li=[]
mul=10
if n%10 != 0:
li.append(n%10)
n=n//10
while n !=0:
val=n%10
ap=val*mul
if ap != 0:
li.append(val*mul)
mul=mul*10
n=n//10
print(len(li))
print(*li)
|
You are given a string s. Each character is either 0 or 1.
You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.
You may eras... | 3 | n=int(input())
for z in range(n):
s=input()
c=0
for i in range(0,len(s)):
if(s[i]=="1"):
break
for j in range(len(s)-1,-1,-1):
if(s[j]=="1"):
break
for k in range(i+1,j):
if(s[k]=="0"):
c+=1
print(c) |
You have n students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the i-th student skill is denoted by an integer a_i (different students can have the same skills).
So, about the teams. Firstly, these two teams should have the s... | 3 | t = int(input())
for _ in range(t):
n = int(input())
A = list(map(int, input().split()))
D = {}
for i in range(n):
if A[i] in D:
D[A[i]] += 1
else:
D[A[i]] = 1
m = max(D[i] for i in D)
print(max(min(m - 1, len(D)), min(m, len(D) - 1))) |
Polycarp loves ciphers. He has invented his own cipher called repeating.
Repeating cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{m} (1 β€ m β€ 10), Polycarp uses the following algorithm:
* he writes down s_1 ones,
* he writes down s_2 twice,
* he writes down s_3 three times,
* ...
... | 3 | import math
n = int(input())
x = input()
b = math.sqrt(1 + 8 * n)
k = int((-1 + b) / 2)
l = []
m = 0
for i in range(1 , k + 1):
l.append(x[0 + m])
m += i
l = ''.join(l)
print(l)
|
Given an integer N, find the base -2 representation of N.
Here, S is the base -2 representation of N when the following are all satisfied:
* S is a string consisting of `0` and `1`.
* Unless S = `0`, the initial character of S is `1`.
* Let S = S_k S_{k-1} ... S_0, then S_0 \times (-2)^0 + S_1 \times (-2)^1 + ... + S... | 3 | n=int(input())
s=''
while n!=0:
s=str(n%2)+s
n=-(n//2)
if s!='':
print(s)
else:
print(0)
|
You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.
You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.
You planned to make an apple pie using all of the apples, ... | 3 | n,l=map(int,input().split())
r=l+n-1;s=(l+r)*n//2
print([s-r,s,s-l][(l>0)+(r>0)]) |
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | 3 | __author__ = 'Utena'
n=int(input())
a=b=c=0
for i in range(n):
x,y,z=map(int,input().split())
a+=x
b+=y
c+=z
if a==b==c==0:print("YES")
else:print("NO") |
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number ... | 3 | # -*- coding: utf-8 -*-
import sys
import os
from collections import defaultdict
d = defaultdict(list)
for s in sys.stdin:
lst = s.split()
word = lst[0]
page = int(lst[1])
d[word].append(page)
keys = list(d.keys())
keys.sort()
for key in keys:
print(key)
pages = d[key]
pages.sort()
p... |
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.
A result of the elimination stage is the tota... | 3 | import itertools
import math
import sys
import os
from collections import defaultdict
def is_debug():
return "PYPY3_HOME" not in os.environ
def stdin_wrapper():
data = '''2
1 2 2 1
4 8 9 2
'''
for line in data.split('\n'):
yield line
if not is_debug():
def stdin_wrapper():
wh... |
We have two distinct integers A and B.
Print the integer K such that |A - K| = |B - K|.
If such an integer does not exist, print `IMPOSSIBLE` instead.
Constraints
* All values in input are integers.
* 0 \leq A,\ B \leq 10^9
* A and B are distinct.
Input
Input is given from Standard Input in the following format:
... | 3 | a, b = map(int, input().split())
s = abs(a + b)
print(s//2 if s % 2 == 0 else "IMPOSSIBLE") |
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | 3 | from collections import Counter
def ans(s1, s2, s):
c1 = Counter(s1 + s2)
c2 = Counter(s)
if(c1 == c2):
return "YES"
else:
return "NO"
s1 = input().strip()
s2 = input().strip()
s = input().strip()
print (ans(s1, s2, s)) |
A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as x points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result.
He knows that the con... | 1 | x,t,a,b,da,db=map(int,raw_input().split(' '))
for i in xrange(t):
for j in xrange(t):
if ((a-i*da+b-j*db==x)|(a-i*da==x)|(b-j*db==x)|(x==0)):
print "YES"
exit(0)
print "NO"
|
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | 1 | n = int(raw_input())
s = raw_input()
s2f = 0
f2s = 0
for i in xrange(n-1):
if s[i]=='S' and s[i+1]=='F':
s2f+=1
if s[i]=='F' and s[i+1]=='S':
f2s+=1
print 'YES' if s2f>f2s else 'NO' |
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | 3 | n = input()
if n[0] == '-':
if len(n) == 2:
print(0)
else:
if int(n[len(n)-1]) > int(n[len(n)-2]):
res = n[:len(n)-1]
if res == '-0':
print(0)
else:
print(res)
else:
res = n[:len(n)-2] + n[len(n)-1]
... |
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 | a=input().split()
n=int(a[0])
m=int(a[1])
s=input().split()
t=input().split()
q=int(input())
for i in range(q):
y=int(input())
n1=y%n
m1=y%m
print(s[n1-1]+t[m1-1]) |
You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 3 | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def gift():
for _ in range(t):
num=int(input())
if (num//2-1)%2:
yield 'YES'
firsthalf=list(map(lambda x:x*2,range(1,num//2+1)))
secondhalf=list(map(lambda x:x*2-1,range(1,num//2)))
... |
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 3 | n=int(input())
c0 = 0
for i in range(n):
a,b,c=list(map(int,input().split()))
if ((a==1 and b==1) or (b==1 and c==1) or (c==1 and a==1)):
c0+=1
print(c0) |
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Ob... | 3 | # You lost the game.
from math import *
n = int(input())
def fact(n):
if n <= 1:
return 1
else:
return n*fact(n-1)
def binom(n,k):
return fact(n)//(fact(k)*fact(n-k))
print(binom(n,5)*fact(n)//fact(n-5))
|
You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positi... | 3 | def num_input():
return map(int,input().split())
def list_input():
return list(num_input())
for t in range(int(input())):
n = int(input())
ans = []
c = 2
sum1 = 0
for i in range(n//2):
sum1 += c
ans.append(c)
c += 2
sum2 = 0
c = 1
for i in range(n//2... |
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.
The park is a rectangular table with n rows and m columns, where the cells of the... | 3 | t = int(input())
while t != 0:
t -= 1
a = input().split()
b = int(a[0]) * int(a[1])
if b % 2 == 0:
print(b // 2)
else:
print((b + 1)//2)
|
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 | n,k = map(int,input().split())
while k:
if str(n)[-1] == "0":
n = n//10
else:
n-=1
k-=1
print(n) |
Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets... | 1 | n=input()
b=input()
a=[]
while b:
a=[b%10]+a
b=b/10
P=1
ans=0
i=len(a)-1
while i>=0:
j=i
x=0
p=1
w=[]
while 1:
y=x+a[j]*p
if y>=n:
break
x=y
w=[a[j]]+w
j-=1
if j<0:
break
p*=10
if len(w)>1 and w[0]==0:
... |
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | 3 | print(25*len(input())+26) |
Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with... | 3 | import sys
n = int(input())
l = list(map(int, input().split()))
i = 0
j = n-1
while( i < j ) :
if j == i + 1 :
break
if l[i] < l[j] :
l[j] -= l[i]
i += 1
elif l[j] < l[i] :
l[i] -= l[j]
j -= 1
else :
j -= 1
i += 1
if i == j :
j += 1
print(*[(i+1), n-j ],sep =' ')
|
Three swimmers decided to organize a party in the swimming pool! At noon, they started to swim from the left side of the pool.
It takes the first swimmer exactly a minutes to swim across the entire pool and come back, exactly b minutes for the second swimmer and c minutes for the third. Hence, the first swimmer will b... | 1 |
from __future__ import division
import sys
input = sys.stdin.readline
import math
from math import sqrt, floor, ceil
from collections import Counter
from copy import deepcopy as dc
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().spli... |
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the Wo... | 3 |
import sys
def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))
testcases = int(input())
arr = []
for testcase in range(testcases):
a,b = get_ints()
arr.append((a , b))
arr = sorted(arr)
n = len(arr)
starttuple = arr[0]
startx = starttuple[0]
endx = starttuple[1]
ans = 0
for i in... |
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | 3 | a=input()
list1=[]
for i in range(int(a[0])):
temp=input().split()
for item in temp:
list1.append(item)
if ("C" in list1) or ("M" in list1) or ("Y" in list1):
print("#Color")
else:
print("#Black&White")
|
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] = [int(i) for i in input().split()]
answer = 0
while a <= b:
a *= 3
b *= 2
answer += 1
print(answer) |
Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card. The name of the animal consisting of alphabetical letters is written on each card, and the bigger one in lexicographical order becomes the winner of that turn. The winner ... | 1 | n = int(raw_input())
a = 0
b = 0
for i in range(n):
in_line = raw_input().split()
if in_line[0] == in_line[1]:
a += 1
b += 1
elif in_line[0] > in_line[1]:
a += 3
else:
b += 3
print '{0} {1}'.format(a,b) |
The only difference between easy and hard versions is constraints.
There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p_i-th kid (in case of i = p_i the kid will give his book to himself). It is guaranteed that all values of p_i are distinct integers ... | 1 | from __future__ import division, print_function
def main():
for _ in range(int(input())):
n=int(input())
l1=list(map(int,input().split()))
visited=[0]*n
for i in range(n):
if visited[i]==0:
to_update=[i]
current=i
while (1):... |
Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that K... | 1 | #!/usr/bin/python
from sys import exit
n, k = map(int, raw_input().split())
track = raw_input()
last = 0
for i in range(1, n):
if i - last > k:
print 'NO'
exit(0)
if track[i] == '.':
last = i
print 'YES'
|
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of R Γ C cells. Each cell is either empty, contains a sheep, a wolf or a dog... | 3 | s,o =[int(i) for i in input().split()]
g=[]
for i in range(s):
g.append(list(input()))
p=g
for i in range(s):
for j in range(o):
if p[i][j]==".":
p[i][j]="D"
if g[i][j]=="S" and ((j<o-1 and g[i][j+1]=="W") or i<s-1 and g[i+1][j]=="W" or i>0 and g[i-1][j]=="W" or j>0 and g[i][j-1]==... |
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially S... | 1 | stones=raw_input()
commands=raw_input()
curr=0
for command in commands:
if stones[curr]==command:
curr+=1
print curr+1 |
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | 1 | n = input()
A = map(int,raw_input().split())
m = min(A)
M = max(A)
B = filter((lambda x: (x!=m and x!=M)), A)
print len(B) |
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
Constraints
* $0 \leq S \leq 86400$
Input
An integer $S$ is given in a line.
Output
Print $h$, $m$ and $s$ separated by ':'. You do not n... | 3 | s=int(input())
print(f'{s//3600}:{s%3600//60}:{s%60}')
|
Fox Ciel saw a large field while she was on a bus. The field was a n Γ m rectangle divided into 1 Γ 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following... | 1 | get=lambda:map(int, raw_input().split())
n,m,k,t=get()
waist = [get() for i in range(k)]
for i in range(t):
p = get()
if p in waist:
print "Waste"
else:
print["Grapes","Carrots","Kiwis"][ (p[0]*m - m + p[1] - sum(map(lambda i:i<p,waist)))%3]
|
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.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | 1 | a=input ("")
x=str(a)
n=10**18
if 1<=a and a<=n:
b=x.count("4")
c=x.count("7")
if b+c==4 or b+c==7:
print "YES"
else:
print "NO"
else:
print
|
There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)
What is the area of this yard excluding the roads? Find it.
Constraints
* A is an ... | 3 | a,b=map(int, input().split())
print(a*b-a-b+1) |
You are given positive integers X and Y. If there exists a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, choose one such integer and print it. If it does not exist, print -1.
Constraints
* 1 β€ X,Y β€ 10^9
* X and Y are integers.
Input
Input is given from Standard Input in... | 3 | [x,y]=[int(i) for i in input().split()]
a=0
if x%y==0:
print(-1)
else:
print(x)
|
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 | def main(n):
if n ==1:
return 'Ehab'
if n%2 == 0:
return 'Mahmoud'
else:
return 'Ehab'
try:
while True:
n = int(input())
print(main(n))
except:
pass |
You are given three positive (i.e. strictly greater than zero) integers x, y and z.
Your task is to find positive integers a, b and c such that x = max(a, b), y = max(a, c) and z = max(b, c), or determine that it is impossible to find such a, b and c.
You have to answer t independent test cases. Print required a, b a... | 3 | import sys
input = sys.stdin.readline
def main():
for t in range(int(input())):
s = list(map(int,input().split()))
s.sort()
x, y, z = s[2], s[1], s[0]
a = x
b = z
c = 1
if x == max(a,b) and y == max(a,c) and z == max(b,c):
print("YES")
print(a,b,c)
else:
print("NO")
main()
|
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Bi... | 3 | #!/usr/bin/env python
# coding: utf-8
# In[11]:
x = int(input(''))
if x == 2:
print ('NO')
elif x % 2 == 0:
print ('YES')
else:
print ('NO')
# In[ ]:
|
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid shown be... | 3 | entrada = input().split()
n = min( int(entrada[0]), int(entrada[1]) )
if (n%2 == 0):
print('Malvika')
else:
print('Akshat')
|
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value:
* Operation A: The displayed value is doubled.
* Operation B: The displayed value increases by K.
Square1001 needs to perform these operations N times in total. Find the min... | 3 | N,K=int(input()),int(input())
num=1
for i in range(N):
num=min(num*2,num+K)
print(num) |
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.
A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met:
* |x_... | 3 | arr=['W','B']
n=int(input())
for x in range(n):
s=""
i=x%2
for y in range(n):
s+=arr[i]
i^=1
print(s) |
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:
* f(0) = a;
* f(1) = b;
* f(n) = f(n-1) β f(n-2) when n > 1, where β de... | 3 | from bisect import *
from collections import *
from itertools import *
import functools
import sys
from math import *
from decimal import *
from copy import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10**5+10
MOD = 10**9+7
def isprime(n):
n = abs(int(n))
if n < 2:
return False
if n == 2:
... |
You are given two arrays a and b, both of length n. All elements of both arrays are from 0 to n-1.
You can reorder elements of the array b (if you want, you may leave the order of elements as it is). After that, let array c be the array of length n, the i-th element of this array is c_i = (a_i + b_i) \% n, where x \% ... | 1 | #!/usr/bin/env python
from __future__ import division, print_function
# Testing code by c1729/meooow/me
import os
import random
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
else:
... |
Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division.
To improve his division skills, Oleg came up with t pairs of integers p_i and q_i and for each pair decided to find the greatest integer x_i, such that:
* p_i is divisible by x_i;
* x_i is not divisible by q_i.
... | 3 | from collections import defaultdict
def factorize(n):
d=defaultdict(int)
count = 0
while ((n % 2 > 0) == False):
n >>= 1
count += 1
if (count > 0):
d[2]+=count
for i in range(3, int(n**0.5) + 1):
count = 0
while (n % i == 0):
count += 1
... |
Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n.
He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arb... | 3 | n = int(input())
lis = list(input())
c = 0
for i in range(0,n,2):
if lis[i]+lis[i+1] not in ('ab','ba'):
c+=1
lis[i] = "a"
lis[i+1] = "b"
print(c)
print("".join(lis)) |
Vasily the bear has a favorite rectangle, it has one vertex at point (0, 0), and the opposite vertex at point (x, y). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point B = (0, 0). That's why today he asks you t... | 3 | currX, currY = (int(x) for x in input().split())
x = abs(currX)
y = abs(currY)
y1 = int( x + y )
x1 = y1
area = x1 * x1
newA = area
while newA <= area:
x1, y1 = x1 + 1, x1 + 1
area = newA
newA = x1 * x1
x1 = int((x1-1) * (currX/abs(currX)))
y1 = int((y1-1) * (currY/abs(currY)))
if x1 < 0 :
print(s... |
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | 3 | n = int(input())
s = []
for i in range(n):
s.append(input())
for st in s[0:]:
if(len(st)>10):
print(st[0]+str(len(st)-2)+st[-1])
else:
print(st) |
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
qwertyuiop
asdfghjkl;
zxcvbnm,./
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally move... | 3 | b=str(input())
s1='qwertyuiop'
s2='asdfghjkl;'
s3='zxcvbnm,./'
st=str(input())
v=[]
for i in range(len(st)):
if st[i] in s1:
if b=='R':
v.append(s1[s1.find(st[i])-1])
else:
v.append(s1[s1.find(st[i])+1])
elif st[i] in s2:
if b=='R':
v.append(s2[s2.find... |
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:
* In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.
For example, 1234, 1, and 334 are lunlun numbers, while ... | 3 | import queue
num=int(input())
q=queue.Queue()
for i in range(1,10):
q.put(i)
for j in range(num):
ans=q.get()
if ans%10!=0:
q.put(10*ans+(ans%10)-1)
q.put(10*ans+(ans%10))
if ans%10!=9:
q.put(10*ans+(ans%10)+1)
print(ans) |
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will co... | 3 | a, b=map(int, input().split(' '))
def perform(a, b):
steps=0
while a!=0 and b!=0:
if a>=b:
steps+=a//b
else:
a, b=b, a
steps+=a//b
a, b=b, a%b
return steps
print(perform(a, b))
|
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 Γ 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the p... | 3 | l = []
for _ in range(4):
l.append(input())
res = False
for _ in range(3):
for i in range(3):
for j in range(3):
x = l[i][j:j+2]
y = l[i+1][j:j+2]
a, b = x.count('#'), x.count('.')
c, d = y.count('#'), y.count('.')
# print(i)
# prin... |
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit p... | 3 | import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(ro... |
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 3 | n=int(input())
c=0
for i in range(n):
if sum(map(int, input().split()))>1:
c+=1
print(c) |
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k... | 3 | from math import *
sInt = lambda: int(input())
mInt = lambda: map(int, input().split())
lInt = lambda: list(map(int, input().split()))
t = sInt()
for _ in range(t):
n = sInt()
a = lInt()
x = n-1
while a[x-1]>=a[x] and x>0:
x -= 1
while a[x-1]<=a[x] and x>0:
x -= 1
print(x)
... |
You drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.
How many kinds of items did you get?
Constraints
* 1 \leq N \leq 2\times 10^5
* S_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).
Input
Input is given from Standard Input in t... | 3 | t = int(input())
s = [input() for i in range(t)]
print(len(set(s))) |
We have N balls. The i-th ball has an integer A_i written on it.
For each k=1, 2, ..., N, solve the following problem and print the answer.
* Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.
Constraint... | 3 | n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in a:
b[i-1]+=1
alls=0
for i in b:
if i>1:
alls+=i*(i-1)//2
for i in a:
print(alls-b[i-1]+1) |
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second β number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 β AB, column 52 is marked by AZ. After ZZ there follow th... | 3 | a='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ab='ZABCDEFGHIJKLMNOPQRSTUVWXY'
ac='ABDEFGHIJKLMNOPQSTUVWXYZ'
inp1=int(input(''))
for q in range(1,inp1+1):
inp2=input('')
bb=''
bbb=y=p=1
x=z=0
for h in inp2:
if h in ac:
p=0
if ('R' == inp2[0])and('C' in inp2) and (p==1) and ('RC' not in inp2)... |
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 | def fun(a=0):
if a%10==0:
return a//10
else:
return a-1
n,k=input().split(' ')
n,k=int(n),int(k)
for i in range(k):
n=fun(n)
print(n,end='') |
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | 3 | n, m = map(int, input().split())
d = dict()
for i in range(m):
a, b = input().split()
d[a] = a if len(a) <= len(b) else b
for item in input().split():
print(d[item], end=' ') |
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." β an excerpt from contest rules.
A total of n participants took part in the contest (n β₯ k), and you already know their scores. Calculate how many ... | 3 | n,k=input().split()
n=int(n)
k=int(k)
count=0
L=list(map(int,input().strip().split()))[:n]
kth=L[k-1]
for i in L:
if(i>0 and i>=kth):
count+=1
print(count)
|
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 | a = []
a = list(map(int, input().strip().split("+")))
a.sort()
a = list(map(str,a))
c = "+".join(a)
print (c)
|
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | 3 | n=int(input())
l=list(map(int,input().split()))
m1=l[0]
m2=l[0]
a=l[0]
c=0
for i in range(1,n):
b=l[i]
if(b<m1):
a=b
m1=b
c+=1
elif(b>m2):
a=b
m2=b
c+=1
print(c)
|
A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a is an integer from 1 to d.
For each point from 1 to n is known if there is... | 3 | n,d = map(int,input().split())
li = input()
count = 0
i = 0
while i < n-1:
jump = 0
if n-1-i-d < 0:
d = n-1-i
for j in range(i+d,i,-1):
if li[j] == '1':
count +=1
i = j
jump = 1
break
if jump == 0:
print(-1)
exit... |
Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 β€ i β€ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 β€ r_i β€ m.
You will be given q queries consisting of three positive intege... | 1 | for i in range(input()):
a, b, m = map(int, raw_input().split())
if a == b:
print 1, a
continue
n, k = 2, 1
while 1:
l, r = k * (a + 1), k * (a + m)
if l <= b <= r:
d = b - l
print n, a,
ans = [1] * (n - 1)
k >>= 1
... |
You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers:
In the decimal representation of s:
* s > 0,
* s consists of n digits,
* no digit in s equals 0,
* s is not divisible by any of it's digits.
Input
The input consists of mult... | 3 | for _ in range(int(input())):
n=int(input())
if(n==1):
print(-1)
else:
print('8'+'7'*(n-1))
|
You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists.
You have to answer t independent test cases.
Recall that the substring s[l ... | 1 | t = input()
alp = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for z in range(t):
k = map(int,raw_input().split());
n = k[0]
a = k[1]
b= k[2]
ans= ""
index = 0
counter = b
for j in range(a):
if (counter>25): coun... |
HQ9+ is a joke programming language which has only four one-character instructions:
* "H" prints "Hello, World!",
* "Q" prints the source code of the program itself,
* "9" prints the lyrics of "99 Bottles of Beer" song,
* "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q"... | 3 |
i = input()
if 'H' in i:
print('YES')
elif 'Q' in i:
print('YES')
elif '9' in i:
print('YES')
elif '+' in i:
print('NO')
else:
print('NO') |
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=map(int,input().split())
for i in range(y):
if (x %10 == 0):
x=int(x/10)
else:
x=int(x-1)
print(x)
|
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'... | 3 | def Dragon(x,y,s,n) :
for i in range(n) :
if s<=x[i] :
return "NO"
else :
s+=y[i]
return "YES"
s,n=map(int,input().split())
x,y=[],[]
for i in range(n) :
a,b=map(int,input().split())
x.append(a)
y.append(b)
for i in range(1,n,1) :
for j in range(0,n-i,1) :... |
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there.
If t... | 3 | n=int(input())
l=list(map(int,input().split()))
g=[0]*n
for i in range(n):
g[l[i]-1]=i+1
for i in g:
print(i,end=" ") |
In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can bui... | 3 | n, time ,oven ,newo = map(int,input().split())
print("YES" if (newo//time + 1)*oven < n else "NO")
|
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
Input
The first line contains integ... | 3 | def p_count(arr,n):
count=0
for i in range(n-1):
if arr[i]==arr[i+1]:
count+=1
return count
l=int(input())
arr=input().upper()
n=len(arr)
print(p_count(arr,n)) |
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 | #Bhargey Mehta (Junior)
#DA-IICT, Gandhinagar
import sys, math
MOD = 998244353
#sys.stdin = open('input.txt', 'r')
n, m = map(int, input().split())
a = list(input().split())
b = list(input().split())
for _ in range(int(input())):
t = int(input())
print(a[(t-1)%n]+b[(t-1)%m]) |
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but ... | 3 | #Ashish Sagar
#t=int(input())
#for _ in range(t):
#n,s,k=map(int,input().split())
n=int(input())
for i in range(n):
a,b=map(int,input().split())
aa=[0]*(a)
k=b//a
rem=b%a
for i in range(a):
aa[i]=k**2
for i in range(rem):
aa[i]=(k+1)**2
print(sum(aa))
|
You are given a special jigsaw puzzle consisting of nβ
m identical pieces. Every piece has three tabs and one blank, as pictured below.
<image>
The jigsaw puzzle is considered solved if the following conditions hold:
1. The pieces are arranged into a grid with n rows and m columns.
2. For any two pieces that sh... | 3 | t = int(input())
for t in range(t):
n, m = [int(i) for i in input().split(" ")]
tabs = 3*n*m
blank = n*m
dif = abs(tabs - blank)
if dif % 2 == 0 and dif <= 2*n + 2*m:
print("YES")
else:
print("NO") |
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 | s=input().lower()
vowel=['a','e','i','o','u','y']
for i in s:
if i not in vowel:
print("."+i,end="") |
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in ... | 3 | n = int(input())
s = input()
count = 0
for c in s:
if c == '1':
count += 1
else:
print(count, end='')
count = 0
print(count)
|
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2 meters per second. We know that this section of the route took exactly t seconds to pass.
Assuming that at each of the seconds the speed is constant, and... | 3 | def main():
v1, v2 = (int(i) for i in input().split())
t, d = (int(i) for i in input().split())
res = 0
for i in range(t):
res += min(v1 + d*i, v2 + d*(t - i - 1))
print(res)
if __name__ == '__main__':
main()
|
As every other little boy, Mike has a favorite toy to play with. Mike's favorite toy is a set of N disks. The boy likes to compose his disks in stacks, but there's one very important rule: the disks in a single stack must be ordered by their radiuses in a strictly increasing order such that the top-most disk will have ... | 1 | def bs(k,start,end,search):
mid =(start+end)/2
if(start>end):
k[start] = search
return 0
# if(start == end):
# if(k[start] >search):
# k[start] = search
# else:
# k[start+1] = search
# return 0
else:
if(search<k[mid]):
... |
This is an easier version of the problem. In this version n β€ 1000
The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company ... | 3 | from typing import List
import collections
import bisect
import itertools
import functools
from collections import defaultdict
import collections
from fractions import gcd
import heapq
from math import ceil, sqrt
import sys
sys.setrecursionlimit(50000)
from collections import defaultdict
n = int(input())
M = list(... |
When he's not training for IOI, Little Alawn enjoys playing with puzzles of various types to stimulate his brain. Today, he's playing with a puzzle that consists of a 2 Γ n grid where each row is a permutation of the numbers 1,2,3,β¦,n.
The goal of Little Alawn's puzzle is to make sure no numbers on the same column or ... | 3 | t=int(input())
p=10**9+7
for _ in range(t):
n=int(input())
ar=[list(map(int,input().split())),list(map(int,input().split()))]
li=[0]*(n+1)
di=dict(zip(ar[0], ar[1]))
w=1
for i in ar[0]:
x=di[i]
if li[i]==0:
w*=2
if w>p:
w=w%p
... |
Chef has recently learnt some new facts about the famous number Ο. For example, he was surprised that ordinary fractions are sometimes used to represent this number approximately. For example, 22/7, 355/113 or even 103993/33102.
Soon, by calculating the value of 22/7 and 355/113 on paper Chef became quite disappointed ... | 1 | T = int(raw_input())
while(T>0):
T=T-1
string = '3'
rem = 103993%33102
N = int(raw_input())
if(N==0):
print string
else:
string = string + '.'
for i in range(0, N):
rem = rem*10
quo = rem/33102
string = string + str(quo)
rem... |
During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows:
<image> The cell with coordinates (x, y) is at the intersection of x-th row ... | 3 | # import sys
# input = sys.stdin.buffer.readline
#
#
# def print(val):
# sys.stdout.write(str(val) + '\n')
for _ in range(int(input())):
a, b, m, n = [int(i) for i in input().split()]
print((a - m) * (b - n) + 1)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.