problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
Given an array A of size N. Given Q operations, each operation contains an integer D. In each operation you have to divide all the elements of the array by D.
For example, for each operation with a given D, the new array A would be:
A[0] / D, A[1] / D, A[2] / D, ..... , A[N-1] / D
Finally, after processing all the o... | 1 | def divideArray():
n = int(raw_input())
a = map(int, raw_input().split())
q = int(raw_input())
d = 1
for i in xrange(q):
d *= int(raw_input())
for i in xrange(len(a)):
print a[i]/d,
divideArray() |
Nauuo is a girl who loves writing comments.
One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes.
It's known that there were x persons who would upvote, y persons who would downvote, and there were also another z persons who would vote, but you don't know whether they woul... | 3 | x,y,z=list(map(int,input().split()))
if x==y and z==0:
print("0")
elif x==y and z!=0:
print("?")
elif x>y and x>(y+z):
print("+")
elif y>x and y>(x+z):
print("-")
elif x==(y+z) or y==(x+z):
print("?")
else:
print("?")
|
There are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number n.
The presenter has m chips. The presenter... | 3 | n , m = map(int,input().split())
flag = True
k = 1
while flag:
if k <= n:
if k <= m:
m-=k
else:
print(m)
break
k+=1
else:
k = 1
|
You are given two arrays of integers a_1,…,a_n and b_1,…,b_m.
Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, f... | 3 |
t = int(input())
while t!=0:
n,m = map(int,input().split())
list1 = set(list(map(int,input().split())))
list2 = set(list(map(int,input().split())))
p = list(list1.intersection(list2))
if len(p)==0:
print("NO")
else:
print("YES")
print(1,p[0])
t-=1 |
Let's say string s has period k if s_i = s_{i + k} for all i from 1 to |s| - k (|s| means length of string s) and k is the minimum positive integer with this property.
Some examples of a period: for s="0101" the period is k=2, for s="0000" the period is k=1, for s="010" the period is k=2, for s="0011" the period is k=... | 3 | for _ in range(int(input())):
t=input()
leng= len(t)
if leng<=2 or '1' not in t or '0' not in t:
print(t)
else:
s=''
for i in range(leng-1):
s+=t[i]
if t[i]== t[i+1]:
s+= str(1- int(t[i]))
s+=t[-1]
print(s) |
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift ... | 3 | n,k=[int(x) for x in input().split()]
sweet=[int(x) for x in input().split()]
total=[0]*k
counter=0
for item in sweet:
total[item%k]+=1
for i in range(1,k//2+1):
if i==k//2 and k%2==0:
counter+=total[k//2]//2
else:
if i!=k-i:
counter+=min(total[i],total[k-i])
counter+=total[0]//2... |
Draw a rectangle which has a height of H cm and a width of W cm. Draw a 1-cm square by single '#'.
Constraints
* 1 ≤ H ≤ 300
* 1 ≤ W ≤ 300
Input
The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space.
The input ends with two 0 (when both H and W are zero)... | 3 | while True:
H,W=map(int,input().split())
if H==0 and W==0: break
for i in range(0,H):
print("#"*W)
print()
|
There are n points on the plane, the i-th of which is at (x_i, y_i). Tokitsukaze wants to draw a strange rectangular area and pick all the points in the area.
The strange area is enclosed by three lines, x = l, y = a and x = r, as its left side, its bottom side and its right side respectively, where l, r and a can be ... | 1 | import sys
import copy
raw_input = sys.stdin.readline
n=int(raw_input())
P=[list(map(int,raw_input().split())) for i in range(n)]
SET_X=set()
SET_Y=set()
for x,y in P:
SET_X.add(x)
SET_Y.add(y)
CX=sorted(SET_X)
CY=sorted(SET_Y)
LEN=len(CX)
MAX=len(CX)-1
DICT_X={x:i for i,x in enumerate(CX)}
DICT_Y={x:i for i,x ... |
A thief sneaked into a museum with a lot of treasures with only one large furoshiki. There are many things I want to steal, but the weight that the furoshiki can withstand is limited, and if it exceeds this, the furoshiki will tear. Therefore, the thief must consider a combination of treasures that will not break the p... | 3 |
# メモ化+非再帰を用いた場合
case_no = 1
while True:
W = int(input())
if W == 0:
break
N = int(input())
treasures = [tuple(map(int, input().split(','))) for _ in range(N)]
V = [[0 for w in range(W+1)] for i in range(N+1)]
weight = [[0 for w in range(W+1)] for i in range(N+1)]
for i in range... |
You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the l... | 3 | intin=lambda:map(int,input().split())
Ain=lambda:list(map(int,input().split()))
N=int(input())
while N>0:
N-=1
n=int(input())
s=input()
l=len(s);lft=0;rt=l-1
for i in range(l):
if s[i]=='>':
lft=i
break
for i in range(l):
j=l-i-1
if s[j]=='<':
... |
The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time.
Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately ev... | 1 | def EXP(b,p):
if p == 0: return 1;
if p == 1: return b;
return EXP(b*b,p >> 1)*EXP(b,p & 1);
n,t = map(int,raw_input().split());
print "{0:.18f}".format(n*EXP(1.000000011,t)); |
Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally spea... | 3 | n, m = [int(x) for x in input().split()]
balans = m
if n == 2 or m == 1:
print('YES')
exit()
cur = 1
while True:
cur2 = cur * n
if balans % cur2 == cur:
balans -= cur
elif balans % cur2 == cur2 - cur:
balans += cur
elif balans % cur2 == 0:
balans += 0
else:
pr... |
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the... | 3 | t=int(input())
for case in range(t):
a,b,c=list(map(int,input().split()))
print((a+b+c)//2) |
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 | watermelon_kg = int(input())
if (watermelon_kg % 2 != 0 or watermelon_kg == 2):
print('NO')
else:
print('YES')
|
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t... | 3 | m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d = 0
s1 = input()
s2 = input()
week = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
s1 = week.index(s1)
s2 = week.index(s2)
z = abs(s1 - s2)
log = False
for d in range(7):
summ = m[0] + d
for i in range(1, 12):
q = su... |
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The si... | 1 | t=raw_input()
l=len(t)
d1=int(t[l-2])*10+int(t[l-1])
p=d1-(d1/4)*4
s=(1**p+2**p+3**p+4**p)%5
print s |
After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.
Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the fi... | 3 | n=int(input())
page_n=[]
for i in range (n):
page_n.append(input().split())
k=int(input())
for l in range(n):
if k in range(int(page_n[l][0]),int(page_n[l][1])+1):
print(n-l) |
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 |
a = int(input())
sum = 0
for i in reversed(range(1, 6)):
if a // i > 0:
s = a // i
a = a - s * i
sum += s
print(sum) |
Polycarp lives on a coordinate line at the point x = 0. He goes to his friend that lives at the point x = a. Polycarp can move only from left to right, he can pass one unit of length each second.
Now it's raining, so some segments of his way are in the rain. Formally, it's raining on n non-intersecting segments, the i... | 3 | import sys
def input():
return sys.stdin.readline().strip()
def input_l():
return map(int, input().split())
def input_t():
return tuple(input_l())
def main():
a, s, d = input_l()
q = []
e = []
z = [0] * (a + 1)
for i in range(s):
w = input_t()
for k in range(... |
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequenc... | 3 | n = int(input())
x = [0 for i in range(n+1)]
x[1] = n
for i in range(2,n+1):
x[i] = x[i-1]+1 + (n-i)*(i)
print(x[n])
lol = "ZAEBAL LAGAT'" |
Snuke has two boards, each divided into a grid with N rows and N columns. For both of these boards, the square at the i-th row from the top and the j-th column from the left is called Square (i,j).
There is a lowercase English letter written in each square on the first board. The letter written in Square (i,j) is S_{i... | 3 | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
s = [None]*n
for i in range(n):
s[i] = input()
ans = n * sum(all(all(s[(i+j)%n][(j+k)%n]==s[(i+j+k)%n][j] for k in range(n)) for j in range(n)) for i i... |
In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:
* Rating 1-399 : gray
* Rating 400-799 : brown
* Rating 800-1199 : green
* Rating 1200-1599 : cyan
* Rating 1600-1999 : blue
* Rating 2000-2399 : yellow
* Rating 2400-2799 : orange
* Rating 280... | 1 | n=int(raw_input())
a=map(int,raw_input().split())
c=[0]*8
mx=0
for i in xrange(n):
if a[i]/400<=7:
c[a[i]/400]=1
else:
mx+=1
print max(1,sum(c)),sum(c)+mx |
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | 3 | from fractions import Fraction
Y,W=map(int,input().split())
if( Fraction(7-max(Y,W),6) ==1 ):
print("1/1")
elif (Fraction(7-max(Y,W),6) ==0): ##not applicable aslan :v
print("0/0")
else:
print(Fraction(7-max(Y,W),6)) |
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())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
whole = set(x[1:] + y[1:])
if len(whole) == n:
print('I become the guy.')
else:
print('Oh, my keyboard!') |
Numbers 1, 2, 3, ... n (each integer from 1 to n once) are written on a board. In one operation you can erase any two numbers a and b from the board and write one integer (a + b)/(2) rounded up instead.
You should perform the given operation n - 1 times and make the resulting number that will be left on the board as s... | 3 |
t = int(input())
for i in range(t):
n = int(input())
print(2)
print(str(n)+" "+str(n-1))
for i in range(n-2):
print(str(n-i)+" "+str(n-2-i))
|
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling... | 3 | # cook your dish here
n=int(input())
a=sorted([int(i) for i in input().split()])
for i in a:print(i,end=' ') |
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each ... | 1 | ab = raw_input()
a = int(ab[0])
b = int(ab[1])
arr =[2,7,2,3,3,4,2,5,1,2]
print arr[a]*arr[b]
|
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this:
<< p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
When someone clicks... | 3 | page_number, current_page, period = map(int, input().split())
right = '>>'
left = '<<'
page_list = range(1, page_number + 1)
res = []
page_index = page_list.index(current_page)
if page_index > period:
res.append(left)
for i in reversed(range(1, period + 1)):
tmp_number = current_page - i
if tmp_number... |
Alice likes word "nineteen" very much. She has a string s and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) tw... | 3 | A = 'niet'
B = [0] * 4
s = input()
for i in s:
if i in A:
B[A.index(i)] += 1
B[0] = (B[0] - 1) // 2
B[2] //= 3
print(0 if min(B) < 0 else min(B)) |
This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
You are given a string s, consisting of lowercase English letters. Find the longest string, t, which satisfies the fol... | 3 | import math
import sys
from collections import defaultdict,Counter,deque,OrderedDict
import bisect
#sys.setrecursionlimit(1000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c... |
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
* Is it true that y is stric... | 3 | from math import inf
bound = [-2*10**9,2*10**9]
for i in range(int(input())):
x, y, z = input().split()
y=int(y)
if x == ">" and z=="Y":bound[0]=max(bound[0],y+1)
if x == ">" and z=="N":bound[1]=min(bound[1],y)
if x == ">=" and z=="Y":bound[0]=max(bound[0],y)
if x == ">=" and z=="N":bound[1]=min... |
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the max... | 3 | import sys
# inf = float("inf")
# sys.setrecursionlimit(1000000)
# mod, MOD = 1000000007, 998244353
# abc='abcdefghijklmnopqrstuvwxyz'
# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': ... |
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces, respectively,
when they found a note attached to the cake saying that "the same person should not t... | 3 | A,B = map(int,input().split())
print(':(' if max(A,B)>8 else 'Yay!') |
This is the easy version of the problem. The difference between the versions is that in the easy version all prices a_i are different. You can make hacks if and only if you solved both versions of the problem.
Today is Sage's birthday, and she will go shopping to buy ice spheres. All n ice spheres are placed in a row ... | 3 | # *******************************************
# * CODER : ANIRBAN DEY *
# * NICK : nonstop-baban(since 2001) *
# * INSTITUTION : IIEST, SHIBPUR(2019-2023) *
# *******************************************
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Frac... |
You are given an integer n (n ≥ 0) represented with k digits in base (radix) b. So,
$$$n = a_1 ⋅ b^{k-1} + a_2 ⋅ b^{k-2} + … a_{k-1} ⋅ b + a_k.$$$
For example, if b=17, k=3 and a=[11, 15, 7] then n=11⋅17^2+15⋅17+7=3179+255+7=3441.
Determine whether n is even or odd.
Input
The first line contains two integers b and... | 3 | b, n = input().split()
b, n = int(b), int(n)
nums = input().split()
if b%2 == 0:
if int(nums[n-1])%2 == 0:
print("even")
else:
print("odd")
exit()
sum = 0
for k in nums:
sum+=int(k)
if sum%2 == 0:
print("even")
else:
print("odd") |
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.
The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch... | 3 | while 1:
try:
data1 = [ int(i) for i in input().split(' ')]
how_many_data = data1[0]
coach_time = data1[1]
max_joy = 'Null'
for times in range(how_many_data):
data2 = [int(i) for i in input().split(' ')]
restaurant_joy = data2[0]
restaurant... |
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | 3 | l=list(map(int,input().split()))
l.sort()
count=0
for i in range(0,(len(l)-1)):
if(l[i] == l[i+1]):
count=count+1
print(count) |
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the re... | 3 | x = int(input())
o = []
n = []
for i in range(x):
y = input().split(" ")
try:
c = n.index(y[0])
n[c] = y[1]
except:
o.append(y[0])
n.append(y[1])
print (len(o))
for i in range(len(o)):
print (o[i]+" "+n[i]) |
Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm.
.#.#.#.#.
.#.#.#.#.#
.#.#.#.#.
.#.#.#.#.#
.#.#.#.#.
.#.#.#.#.#
Note that the top left corner should be drawn by '#'.
Constraints
* 1 ≤ H ≤ 300
* 1... | 1 | l='#.'*151
while 1:
h,w=map(int,raw_input().split())
if h==0:break
for i in range(h):
if i%2:print l[1:w+1]
else:print l[:w]
print |
You are given two integers a and b. You may perform any number of operations on them (possibly zero).
During each operation you should choose any positive integer x and set a := a - x, b := b - 2x or a := a - 2x, b := b - x. Note that you may choose different values of x in different operations.
Is it possible to mak... | 1 | t = input()
for i in range(t):
nos = raw_input()
n = nos.split(" ")
a = int(n[0])
b = int(n[1])
if (2*a-b)%3 ==0 and (2*b-a)%3 == 0 and (2*a-b) >=0 and (2*b-a) >=0:
print "YES"
else:
print "NO" |
You are given four integers a, b, x and y. Initially, a ≥ x and b ≥ y. You can do the following operation no more than n times:
* Choose either a or b and decrease it by one. However, as a result of this operation, value of a cannot become less than x, and value of b cannot become less than y.
Your task is to fi... | 3 | for _ in range(int(input())):
a,b,x,y,n=map(int,input().split())
ans=1000000000000000000000000000
p=a
q=b
if a-x>=n:
a=p-n
ans=min(ans,a*q)
if b-y>=n:
b=q-n
ans=min(ans,p*b)
if p-x<n:
b=q-(n-(p-x))
a=x
ans=min(ans,a*b)
if q-y<n:
... |
Bosky and Menot are two friends who participated in GSF Hacks Prelims on HackerEarth, and both of them easily qualified for the on-site round. Bosky wants to team up with Menot for the on-site round but Menot has a date with his girlfriend the same day. Bosky thus plans to spoil Menot’s date and trigger their breakup. ... | 1 | import re
from operator import itemgetter
dates = {}
for _ in range(input()):
ins = raw_input().strip()
dig = re.findall("\d+", ins)
weights = [1, 2][ins[0] == "G"]
if len(dig) > 0:
for x in dig:
if dates.has_key(x):
dates[x] += weights
else:
... |
In the city of Saint Petersburg, a day lasts for 2^{100} minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4^k for each integer k ≥ 0. Team BowWow has arrived at the station at the time s and it is trying to co... | 3 | s = input()
l = len(s)
sum = 0
for i in range(l):
if(s[i]=='1'):
sum =sum+2**(l-i-1)
ans =0
while(True):
if(4**ans>=sum):
break
ans =ans+1
print(ans) |
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | 3 |
from collections import Counter
import sys
Input = sys.stdin.readline
tmp = 0
N = int(Input())
a = Counter(map(int, Input().split()))
print(max(a.values()), len(set(a)))
|
At many competitions that have a word «cup» in its official name the winner is presented with an actual cup. This time the organizers of one unusual programming competition have decided to please the winner even more and to add a nameplate to the cup with the handle of the winner.
The nameplate is to be rectangular an... | 1 | n = raw_input()
length = len(n)
columns = 0
rows = 0
asteriks = 0
for i in range(5):
columns = length // (i + 1)
# print 'columns = ', columns
if columns < 20 or (columns == 20 and length % (i+1) == 0):
rows = i+1
if length % (i+1) != 0:
asteriks = rows - (length % (i+1))
... |
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | 3 | n = int(input())
data = sorted([int(x) for x in input().split()], reverse=True)
i = 0
while i < len(data) and sum(data[:i + 1]) <= sum(data[i + 1:]):
i += 1
if i == len(data):
print(len(data))
else:
print(i + 1)
|
Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome.
Gildong lo... | 3 | n, m = (int(i) for i in input().split())
a = []
for x in range(n):
a.append(input())
pal1, pal2, r = [], [], ''
while len(a) > 0:
y = a.pop(0)
if y[::-1] in a:
pal1.append(y)
pal2.insert(0, a.pop(a.index(y[::-1])))
elif y == y[::-1]:
r = y
pal = ''.join(pal1) + r + ''.join(pa... |
Given an integer x, find 2 integers a and b such that:
* 1 ≤ a,b ≤ x
* b divides a (a is divisible by b).
* a ⋅ b>x.
* a/b<x.
Input
The only line contains the integer x (1 ≤ x ≤ 100).
Output
You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of in... | 3 | import sys
import math
x = int(input())
f = True
for i in range(int(math.ceil(math.sqrt(x))), x+1):
for j in range(int(math.ceil(math.sqrt(x))), x+1):
if((i*j>x) and (i%j==0) and (float(i/j)<float(x)) and f):
print(i, " ", j)
f = False
sys.exit(0)
if(f):
print("-1"... |
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment.
What is the minimu... | 3 | n = int(input())
ans = 0
while(n):
if n&1: ans+=1
n>>=1
print(ans) |
For a positive integer n let's define a function f:
f(n) = - 1 + 2 - 3 + .. + ( - 1)nn
Your task is to calculate f(n) for a given integer n.
Input
The single line contains the positive integer n (1 ≤ n ≤ 1015).
Output
Print f(n) in a single line.
Examples
Input
4
Output
2
Input
5
Output
-3
Note
f(4)... | 3 | n=int(input())
if n%2==0:
k1=k2=n//2
an1=-(n-1)
an2=n
else:
k1=n//2+1
k2=n//2
an1=-n
an2=n-1
s1=((-1+an1)//2)*k1
s2=((2+an2)//2)*k2
print(s1+s2)
|
There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N).
For each k = 1,2,\dots,N, find the answer to the following question:
Rng is in City k. Rng can perform the following move arbitrarily many t... | 3 | import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)]
def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e for l in range(d)] for k in range(c)] for j in range(b)]... |
There are three cells on an infinite 2-dimensional grid, labeled A, B, and F. Find the length of the shortest path from A to B if:
* in one move you can go to any of the four adjacent cells sharing a side;
* visiting the cell F is forbidden (it is an obstacle).
Input
The first line contains an integer t (1 ≤ ... | 1 | t = int(raw_input())
#print(t)
#python comp123.py < input.txt
for x in range(t):
ss = 0
emp = raw_input()
A = raw_input()
Ax, Ay = [int(i) for i in A.split(" ")]
B = raw_input()
Bx, By = [int(i) for i in B.split(" ")]
F = raw_input()
Fx, Fy = [int(i) for i in F.split(" ")]
if Ax ... |
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | 1 | n = input()
x = raw_input().split()
t = {x[c]: c for c in xrange(n)}
a, b = 0, 0
w = input()
q = raw_input().split()
for i in q:
index = t[i]
a += index + 1
b += n - index
print a, b |
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy... | 3 | import math
n = int(input())
a = math.ceil(n ** 0.5)
b = math.floor(n ** 0.5)
if (a*b < n):
b += 1
print ((b+a)*2)# |
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l ≤ x, y ≤ r, x ≠ y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1 ≤ T ≤ 1000) — the number of... | 3 | a=int(input())
for i in range(a):
l,r=list(map(int,input().split()))
print(l,2*l) |
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 | def solve(s, t, queries):
for query in queries:
i = (query - 1) % len(s)
j = (query - 1) % len(t)
name = f"{s[i]}{t[j]}"
print(name)
if __name__ == '__main__':
n, m = [int(x) for x in input().split()]
s = [x for x in input().split()]
t = [x for x in input().split()]
... |
Another Codeforces Round has just finished! It has gathered n participants, and according to the results, the expected rating change of participant i is a_i. These rating changes are perfectly balanced — their sum is equal to 0.
Unfortunately, due to minor technical glitches, the round is declared semi-rated. It means... | 3 | import sys, math
tc = int(sys.stdin.readline())
arr = []
temp = []
for _ in range(tc):
arr.append(int(sys.stdin.readline()))
for i in range(tc):
temp.append(arr[i] // 2)
now = sum(temp)
if now > 0:
idx = 0
while now > 0:
if arr[idx] % 2 != 0:
temp[idx] -= 1
now -= 1
... |
After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes.
Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) consisting of n nodes. The root of tree has index 1. Kay is very interested ... | 1 | n, q = map(int, raw_input().split(' '))
p_arr = map(lambda x:int(x) - 1, raw_input().split(' '))
p_arr = [-1] + p_arr
for i in p_arr[1:]:
i += 1
pe_arr = [0 for i in xrange(n)]
s_arr = [1 for i in xrange(n)]
mx_arr = [-1 for i in xrange(n)]
z_arr = [i for i in xrange(n)]
for i in p_arr:
if i > 0:
pe_arr[i] += 1... |
As a New Year's gift, Dolphin received a string s of length 19.
The string s has the following format: `[five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]`.
Dolphin wants to convert the comma-separated string s into a space-separated string.
Write a program to perform th... | 3 | l, m, r = input().split(",")
print(l, m, r) |
We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 1, 2, ..., N. Here, the following conditions should be satisfied:
* For each i (1 ≤ i ≤ N), there are exactly a_i squares painted in Color i. Here, a_1 + a_2 + ... + a_N = H W.
* For each i (1 ≤ i ≤ N), the squares painted i... | 3 | h, w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
c = []
for i in range(n):
while a[i]>0:
a[i] -=1
c.append(str(i+1))
for i in range(h):
if i%2==0:
print(" ".join(c[i * w:(i + 1) * w]))
else:
print(" ".join(reversed(c[i * w:(i + 1) * w]))) |
An n × n table a is defined as follows:
* The first row and the first column contain ones, that is: ai, 1 = a1, i = 1 for all i = 1, 2, ..., n.
* Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defin... | 3 | from math import factorial as a
n = int(input()) - 1
ans = a(2 * n)//(a(n) * a(n))
print(ans)
|
The main characters have been omitted to be short.
You are given a directed unweighted graph without loops with n vertexes and a path in it (that path is not necessary simple) given by a sequence p_1, p_2, …, p_m of m vertexes; for each 1 ≤ i < m there is an arc from p_i to p_{i+1}.
Define the sequence v_1, v_2, …, v... | 3 | from collections import deque
n = int(input())
adj = []
for _ in range(n):
l = input()
adjline = []
for i in range(n):
if l[i] == '1':
adjline.append(i)
adj.append(adjline)
dist=[[-1]*n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
dq = deque()
dq.append(i)
wh... |
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ... | 3 | from collections import Counter
input()
print(Counter(map(int,input().split())).most_common(n=1)[0][1])
|
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | 3 | #!/usr/bin/env python3
import sys
def get_ints():
return map(int, sys.stdin.readline().strip().split())
Y, W = get_ints()
score_to_beat = max(Y, W)
if (score_to_beat == 1):
print("1/1")
elif (score_to_beat == 2):
print("5/6")
elif (score_to_beat == 3):
print("2/3")
elif (score_to_beat == 4):
print("1/2")... |
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain posi... | 3 | n=int(input())
a=[]
if n<=100:
for i in range(1,n):
x=str(i)
x=list(map(int,x))
if i+sum(x)==n:
a.append(i)
else:
for i in range(n-99,n):
x=str(i)
x=list(map(int,x))
if i+sum(x)==n:
a.append(i)
print(len(a))
print(*a) |
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.... | 1 | n = input();
print sum([n.strip().split().count('1') >= 2 for n in [raw_input() for m in [0] * n]]) |
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... | 3 | s = input()
count = 0
for i in s:
if i == "4" or i == "7":
count+=1
if count == 4 or count == 7:
print("YES")
else:
print("NO") |
You are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42.
Your task is to remove the minimum number of elements to make this array good.
An array of length k is called good if k is divisible by 6 and it is possible to split it into k/6 subsequences 4, 8, 15... | 3 | n = int(input())
c = [1000000000, 0, 0, 0, 0, 0, 0]
v = [0, 4, 8, 15, 16, 23, 42]
for i in map(int, input().split()) :
for j in range(1, 7) :
if(i == v[j] and c[j - 1]) :
c[j ] += 1
c[j - 1] -= 1
print(n - c[6] * 6) |
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | 3 | s = input()
if len(s) <=100 and len(s) >0:
if '0'*7 in s or '1'*7 in s:
print ("YES")
else:
print ("NO")
else:
print ("NO") |
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
def solve(n):
if n == 2:
return 1.0
each_angle = math.pi / n
height = 0
width = 0
for i in range(n):
angle = each_angle * i
height += math.sin(angle) * 1.0
width += abs(math.cos(angle)) * 1.0
if width > height:
sectors = n // 2
angle =... |
You are the gym teacher in the school.
There are n students in the row. And there are two rivalling students among them. The first one is in position a, the second in position b. Positions are numbered from 1 to n from left to right.
Since they are rivals, you want to maximize the distance between them. If students a... | 3 | t = int(input())
for _ in range(t):
n, x, a, b = list(map(int, input().split()))
print(abs(a-b) + x if abs(a-b) + x < n else n-1) |
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 |
n,m,a,b=map(int,input().split(' '))
if b/m>=a:
print(a*n)
else:
r=n%m
q=n//m
mini=q*b+r*a
maxi=(q+1)*b
print(min(mini,maxi))
|
Polycarp is reading a book consisting of n pages numbered from 1 to n. Every time he finishes the page with the number divisible by m, he writes down the last digit of this page number. For example, if n=15 and m=5, pages divisible by m are 5, 10, 15. Their last digits are 5, 0, 5 correspondingly, their sum is 10.
You... | 3 | for _ in range(int(input())):
n,m=map(int,input().split());dp=[0]*12
l = [(m*i) % 10 for i in range(1, 11)]
for i in range(1,11):
dp[i]=dp[i-1]+(i*m)%10
c=n//m
print((dp[10]*(c//10))+dp[c%10])
|
You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (including end points) is k.
The MEX of a sequence of integers is the smallest non-n... | 3 | import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data()... |
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | 3 | a = input()
n = int(a)
l = []
for i in range(n):
l.append(input().split())
for i in range(n):
l[i].sort()
ans = 0
for i in range(n):
if l[i][1] == '1':
ans += 1
print(ans) |
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 | test_case=int(input())
for i in range(test_case):
b=input()
if len(b)>10:
c=len(b)-2
s=b[0]+str(c)+b[len(b)-1]
print(str(s))
else:
print(str(b)) |
You are given a program that consists of n instructions. Initially a single variable x is assigned to 0. Afterwards, the instructions are of two types:
* increase x by 1;
* decrease x by 1.
You are given m queries of the following format:
* query l r — how many distinct values is x assigned to if all the... | 3 | '''
#python-io
'''
import sys
# need this
input = sys.stdin.readline
MAXN = 2 * 100_000 + 5
cnt, top, bot = [0]*MAXN, [[0]*MAXN for i in range(2)], [[0]*MAXN for i in range(2)]
def program(n, m, s):
for i in range(n):
if s[i] == '+': cnt[i+1] = cnt[i] + 1
else: cnt[i+1] = cnt[i] - 1
for i in range(1, n+1):
... |
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq ... | 1 | n = input()
k = input()
x = input()
y = input()
if k >= n:
print n*x
else:
print k*x+(n-k)*y |
There are n programmers that you want to split into several non-empty teams. The skill of the i-th programmer is a_i. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team ... | 3 | import math
cases = int(input())
for t in range(cases):
n,x = list(map(int,input().split()))
a = list(map(int,input().split()))
a = sorted(a)[::-1]
minelem = a[-1]
# d = {i:math.ceil(x/i) for i in range(1,n+1)}
c = 1
c1 = 0
s = 0
for i in a:
dc = math.ceil(x/c)
if i>=... |
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | 1 | from math import ceil
names = ['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard']
n = int(raw_input())
i = 0
j = 1
k = len(names)
while i <= n:
i += k
k += k
j += j
print(names[int(ceil((n - (i - k * 0.5)) / (j * 0.5)) - 1)])
|
Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph.
People don't use cash as often as they... | 3 | def main():
a = int(input())
if a > 1:
print(2 * (a - 1), 2)
print(1, 2)
else:
print(2, 1)
print(2)
if __name__ == '__main__':
main()
|
Jzzhu has invented a kind of sequences, they meet the following property:
<image>
You are given x and y, please calculate fn modulo 1000000007 (109 + 7).
Input
The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output
Output a single integer... | 3 | x,y=map(int,input().split())
n=int(input())
t=1000000007
if n%6==1:
print(x%t)
elif n%6==2:
print(y%t)
elif n%6==3:
print((y-x)%t)
elif n%6==4:
print((-x)%t)
elif n%6==5:
print((-y)%t)
else:
print((x-y)%t)
|
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).
A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, an... | 3 | n=int(input())
redlist=[list(map(int,input().split())) for _ in range(n)]
bluelist=[list(map(int,input().split())) for _ in range(n)]
redlist.sort(key = lambda x : x[1], reverse = True)
bluelist.sort(key = lambda x : x[0])
output=0
for blue in bluelist:
for red in redlist:
if blue[1] > red[1] and blue[0] > red[... |
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th... | 3 | n,k=map(int,input().split())
c=240
p=0
c=c-k
for i in range(1,n+1):
c-=5*i
if c<0 :
break
else :
p+=1
print(p)
|
Igor the analyst has adopted n little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into n pieces of equal area.
Formally, the carrot can be viewed as an isosceles triangl... | 1 | n,h = raw_input().split()
n = (int)(n)
h = (float)(h)
a = []
k = 1
import math
for i in range(0,n-1):
a.append(math.sqrt(h*h*k/n))
k=k+1
sizee = len(a)
for i in range(0, sizee):
print a[i],
|
You're given an array a of n integers, such that a_1 + a_2 + ⋅⋅⋅ + a_n = 0.
In one operation, you can choose two different indices i and j (1 ≤ i, j ≤ n), decrement a_i by one and increment a_j by one. If i < j this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make a... | 3 | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
put = 0
for el in a:
if el > 0: put += el
else: put = max(put + el, 0)
print(put) |
You are given an angle ang.
The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon.
<image>
If there are several answers, print the minimal one. It is guarantied t... | 3 | from math import gcd
t = int(input())
for i in range(t):
n = int(input())
p = gcd(180 , n)
if(p + n == 180):
print(360 // p)
else:
print(180 // p)
|
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 | n = int(input())
result = ((n * (n - 1) * (n - 2) * (n - 3) * (n - 4)) ** 2) // 120
print(result) |
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(input().split(" "))
count = 0
for y in range(5):
for x in range(5):
if l[y][x] == "1":
count = abs(2-y)+abs(2-x)
print(count)
|
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c ⋅ (i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequence... | 3 | #Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
... |
You have two integers l and r. Find an integer x which satisfies the conditions below:
* l ≤ x ≤ r.
* All digits of x are different.
If there are multiple answers, print any of them.
Input
The first line contains two integers l and r (1 ≤ l ≤ r ≤ 10^{5}).
Output
If an answer exists, print any of them. Oth... | 3 | def q(u):
for i in range(0,len(u)-1):
if(u[i]==u[i+1]):
return False
return True
a,b = map(int,input().split())
for x in range(a,b+1):
c = sorted(list(str(x)))
d = "".join(c)
if(q(d)):
print(x)
break
if(x==b):
print(-1)
|
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | 3 | a = str(input()).lower()
b = str(input()).lower()
if a > b:
print(1)
elif a == b:
print(0)
else:
print(-1)
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length k have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array a of length n. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautifu... | 3 | import sys
from math import sqrt, floor, factorial, gcd
from collections import Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))
def a():
ans = ""
for _ in range(int(inp())):
n = int(inp());s = 2; m = 2
for i in range(1,n//2):
s += 2**m
... |
Anna is a girl so brave that she is loved by everyone in the city and citizens love her cookies. She is planning to hold a party with cookies. Now she has a vanilla cookies and b chocolate cookies for the party.
She invited n guests of the first type and m guests of the second type to the party. They will come to the ... | 3 | t = int(input())
for _ in range(t):
l = input().split()
a,b, n, m = int(l[0]), int(l[1]), int(l[2]), int(l[3])
if a + b < n + m:
print("No")
else:
mn = min(m,n)
ab = min(a,b)
mab = max(a,b)
if ab >= m:
print("Yes")
else:
prin... |
Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to d. It is guaranteed that ai ≤ d for all i from 1 to n. The clock does not keep information ab... | 3 | #182B
d = int(input())
n = int(input()) -1
a = list(map(int, input().split(" ")))
print(n*d -sum(a) + a[-1])
|
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... | 1 | s=list(raw_input())
l=[]
for i in s:
if i not in l:
l.append(i)
if len(l)%2==1:
print 'IGNORE HIM!'
else:
print 'CHAT WITH HER!'
|
You are given two arrays a and b both consisting of n positive (greater than zero) integers. You are also given an integer k.
In one move, you can choose two indices i and j (1 ≤ i, j ≤ n) and swap a_i and b_j (i.e. a_i becomes b_j and vice versa). Note that i and j can be equal or different (in particular, swap a_2 w... | 3 | t = int(input())
while t:
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort()
b.reverse()
for i in range(n):
if i >= k or a[i] > b[i]:
break
else:
if a[i] < b[i]:
a[... |
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters.... | 3 | t=input()
g=t[0].upper()
v=t.replace(t[0],g,1)
print(v) |
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices i, j (2 ≤ i ≤ j ≤ n - 1), that <image>... | 3 | n = int(input())
arr = list(map(int,input().split()))
psum = [0]*n
t = 0
for i in range(n):
t += arr[i]
psum[i] = t
if psum[-1]%3!=0:
print(0)
elif psum[-1]==0:
cnt = psum.count(0)
cnt -= 1
if(cnt<2):
print(0)
elif(cnt==2):
print(1)
else:
print(cnt*(cnt-1)//2)
e... |
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 | for i in range(int(input())):
l=[int(num) for num in input().split()]
if(l.count(max(l))>=2):
print("YES")
print(max(l),min(l),min(l))
else:
print("NO") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.