problem stringlengths 29 9.39k | language int64 1 3 | solution stringlengths 7 465k |
|---|---|---|
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 = input().split()
a = int(a)
b = int(b)
def y(a,b):
c = 0
while a <= b :
a *= 3
b *= 2
c += 1
return c
print(y(a,b)) |
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
#a=list(map(int,input(n).strip().split()))[:n]
while(n):
n-=1
p,v,t=[int(i)for i in input().split()]
if((p+v+t)>=2):
c+=1
print(c) |
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has n groups of people. The i-th group from the beginning has ... | 1 | n, m = map(int, raw_input().split())
l = map(int, raw_input().split())
c=0
b=1
for i in range(len(l)):
if(c+l[i] <= m):
c+=l[i]
else:
b+=1
c=l[i]
print b
|
Input
The input contains a single integer a (1 β€ a β€ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding | 1 | a=dict()
a[1]=' George Washington '
a[2]=' John Adams '
a[3]=' Thomas Jefferson '
a[4]=' James Madison '
a[5]=' James Monroe '
a[6]=' John Quincy Adams '
a[7]=' Andrew Jackson '
a[8]=' Martin Van Buren '
a[9]=' William Henry Harrison'
a[10]=' John Tyler '
a[11]=' James Knox Polk '
a[12]=' Zachary ... |
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
* Operation ++ increases the value of variable x by 1.
* Operation -- decreases the value of variable x by 1.... | 3 | import sys
import math
x = sys.stdin.readlines()
val = 0
for y in range(1,int(x[0])+1):
if "+" in x[y]:
val+=1
else:
val-=1
print(val) |
The GCD table G of size n Γ n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6,... | 1 | from operator import itemgetter, attrgetter, methodcaller
from collections import Counter
from fractions import gcd
n = int(raw_input())
nods = map(int, raw_input().split(' ') )
cnt = Counter(nods)
cntList = sorted( cnt.items(), key=itemgetter(0), reverse=True )
#print cnt
def addNum(num, nums, cnt):
for n in num... |
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i... | 3 | m=int(input())
s=sorted(map(int,input().split()))
print((s[-1]-s[0]),s.count(s[0])*s.count(s[-1]) if s[0]!=s[-1] else m*(m-1)//2) |
There are n people who want to participate in a boat competition. The weight of the i-th participant is w_i. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with the same total weight.
So, if there are k teams (a_1, b_1), (a_2, b_2)... | 3 | t=int(input())
for p in range(t):
n=int(input())
a=list(map(int,input().split()))
s=set()
for i in range(n):
for j in range(i+1,n):
s.add(a[i]+a[j])
max_cnt=0
#print(s)
for i in s:
#("sum",i)
cnt=0
pair=[]
for j in range(n):
... |
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 ... | 1 | lenList = int(raw_input().strip())
listAct = map(int, raw_input().strip().split(' '))
coat = []
pocket = []
coat.append(pocket)
for coin in listAct:
foundPocket = False
for pocket in coat:
if not coin in pocket and not foundPocket:
pocket.append(coin)
foundPocket = True
if ... |
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m... | 3 | #pasos a seguir:
#1.- ordenar ambas listas
n_boys = input()
n_boys = int(n_boys)
boys_skill = input()
n_girls = input()
n_girls = int(n_girls)
girls_skill = input()
boys_skill = boys_skill.split(" ")
boys_skill = [int(x) for x in boys_skill]
boys_skill.sort()
girls_skill = girls_skill.split(" ")
girls_skill = [int(x) ... |
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 | t= int(input())
while(t>0):
n= int(input())
arr= [int(i) for i in input().split()][::-1]
ans =0
flag = 1
for i in range(n-1):
if arr[i]<=arr[i+1] and flag==1:
ans+=1
continue
else:
flag = 0
if arr[i]>=arr[i+1]:
... |
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not d... | 1 | import sys
import math
n = int(sys.stdin.readline())
k = int(0.5 + math.sqrt(1 + 8*(n-1))/2)
print >>sys.stdout, n-k*(k-1)/2 |
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | 3 | cases = int(input())
arr = []
while cases:
cases -= 1
a, b = map(int, input().split())
if a != b:
print("rated")
exit()
arr.append(a)
sor = sorted(arr, reverse=True)
if arr == sor:
print("maybe")
else:
print("unrated")
|
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 sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
def solve(a):
a = 'R'+a
n = len(a)
def check(m):
last = n
for i in range(n-1,-1,-1):
if a[i] == "R":
if last > i+m: return False
last = i
return ... |
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one o... | 3 | s = input()
c = s.split(" ")
c1 = int(c[0])
c2 = int(c[1])+1
if c1<=0 or c2<=0:
print("NO")
else:
print("YES")
for i in range(c1,c2,2):
print(i,i+1)
|
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ... | 3 | n=int(input())
c1=c2=0
l=[int(x) for x in input().split()]
for i in range(n):
if(l[i]==100):
c1+=1
else:
c2+=1
if(c1%2==0 and c2%2==0):
print("YES")
elif(((c1==0 and c2!=0) and c2%2==0)or((c2==0 and c1!=0) and c1%2==0)):
print("YES")
elif(c1%2==0 and c2%2!=0 and c1!=0):
print("YES")
... |
Berland annual chess tournament is coming!
Organizers have gathered 2Β·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | 3 | flag=0
n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a,reverse=True)
b=a[0:n]
c=a[n:]
# print(b,c)
for i in range(0,len(b)):
for j in range(0,len(c)):
if(b[i]<=c[j]):
flag=1
break
if(flag>0):
print('NO')
else:
print("YES") |
Arkady bought an air ticket from a city A to a city C. Unfortunately, there are no direct flights, but there are a lot of flights from A to a city B, and from B to C.
There are n flights from A to B, they depart at time moments a_1, a_2, a_3, ..., a_n and arrive at B t_a moments later.
There are m flights from B to C... | 3 | import sys
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
n,m,ta,tb,k=LI()
A = LI()
B = LI()
if k>=n or k>=m:
return -1
maxt = 0
j = 0
for i in range(k+1):
c = A[i] + ta
while j < m and c > B[j]:
j += 1
... |
Consider a table of size n Γ m, initially fully white. Rows are numbered 1 through n from top to bottom, columns 1 through m from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.
Input
The first line contains two integers n and m (1 β€ n, m β€ 115) β th... | 3 | import sys
from itertools import permutations
DEBUG = 0
if DEBUG:
f = open("input.txt", "r")
input = f.readline
else:
input = sys.stdin.readline
def mp():
return list(map(int, input().split()))
def main():
INF = int(1e9)
n, m = mp()
a = []
for i in range(n):
a.append(input().s... |
An SNS has N users - User 1, User 2, \cdots, User N.
Between these N users, there are some relationships - M friendships and K blockships.
For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i.
For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i... | 3 | # input
N, M, K = map(int, input().split())
Friends = [set() for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
Friends[a].add(b)
Friends[b].add(a)
Blocked = [set() for _ in range(N)]
for _ in range(K):
c, d = map(int, input().split())
c -= 1
d -= 1
... |
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 i in range(t):
n,x,a,b=map(int,input().split())
#print(n,x,a,b)
if x == 0 :
print(abs(a-b))
continue
n1 = max(a,b)
n2 = min(a,b)
dis=0
if n1+x<=n:
dis = abs(n1+x-n2)
print(dis)
else:
temp = n-n1
n1=n
x=x-temp
if n2-x>=1:
dis = abs(n2-x-n1)
print(dis)
else:
... |
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 x in range(int(input())):
n = int(input())
if n==1:
print(-1)
else:
s='2'
print(s+(n-1)*'9') |
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 , m = map(int , input().split())
m_4= 240
count = 0
result_n = 0
for i in range(1 , n + 1):
count+=5*i
if count + m<=m_4:
result_n+=1
else:
break
print(result_n)
|
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | 3 | n, word = int(input()), input()
stars_index, lttr_index = [], []
lttrs = set()
for i in range(len(word)):
if word[i] == '*':
stars_index.append(i)
else:
lttr_index.append(i)
lttrs.add(word[i])
m = int(input())
pssbl_lttrs = None
for i in range(m):
p_word = input()
f = False
for j in stars_index:
if p_wor... |
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | 3 | p,m,s,h=map(int,input().split())
print(*[(2*p,2*m,max(s,h)),(-1,)][s>2*h or h>2*s or h>=m])
# Made By Mostafa_Khaled |
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, β¦, s_n.
Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).
Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} ... | 3 | from math import *
for zz in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
dp = [1] * (n + 1)
for i in range(n - 1, 0, -1):
j = 2*i
while j <= n:
if a[i-1] < a[j-1]:
dp[i] = max(dp[i], dp[j] + 1)
j += i
p... |
Phoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a_1, a_2, ..., a_k such that every letter of s goes to exactly one of the strings a_i. The strings a_i do not need to be substrings of s. Phoenix can distribute letters of s and re... | 3 | import sys
import math
try:
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
except:
pass
# input = sys.stdin.readline
for _ in range(int(input())):
n,k = map(int,input().split())
s = list(input())
s.sort()
if len(set(s)) == 1:
print(math.ceil(s.count(s[0])/k)*s[0])
continu... |
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n Γ m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines... | 1 | from math import factorial
def f(x, y):
if x < y:
return 0
return factorial(x) / factorial(y) / factorial(x - y)
(n, m, k) = raw_input().strip().split()
n = int(n)
m = int(m)
k = int(k)
print f(n - 1, 2 * k) * f(m - 1, 2 * k) % 1000000007
|
The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they cannot communicate directly.
The Chef invested in top-of-the-line t... | 1 | def dis(x1,y1,x2,y2):
dist=(((x1-x2)**2)+((y1-y2)**2))
return dist
t=int(raw_input())
while(t>0):
x=0
r=int(raw_input())
chefx,chefy=raw_input().split()
chefx,chefy=[int(chefx),int(chefy)]
headx,heady=raw_input().split()
headx,heady=[int(headx),int(heady)]
... |
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | 1 | #!/usr/local/bin/python
#
import math
import sys
(N, M) = sys.stdin.readline().split()
N = int(N)
M = int(M)
graph = [[] for n in range(N)]
for i in range(M):
(a, b) = sys.stdin.readline().split()
graph[int(a)-1].append(int(b)-1)
graph[int(b)-1].append(int(a)-1)
count = 0
while True:
ones = []
for i in range... |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 β€ x β€ x_2 and y_1 β€ y β€ y_2, where (x_1, y_1) and (x... | 3 | n=int(input())
a=list(map(int,input().split()))
a.sort()
f=min([(a[n+i-1]-a[i])*(a[-1]-a[0]) for i in range(n)])
print(min((a[-1]-a[n])*(a[n-1]-a[0]),f)) |
Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with?
Input
The first... | 3 | n,k=map(int,input().split())
k1=k
a=input()
a=[i for i in a]
for i in range(n):
if k==0:
break
if i==0:
if a[0]!='1':
a[0]='1'
k-=1
else:
if a[i]!='0':
a[i]='0'
k-=1
if n==1 and k1>0:
print('0')
else:
for i in a:
print(i... |
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.
There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned ... | 3 | n = int(input())
a = [0]*n
ans = []
for i in range(n):
cur = set(input().split())
if not('3' in cur or '1' in cur):
ans.append(i+1)
print (len (ans))
print (*ans) |
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 | n=int(input())
l=[]
for i in range(n):
l.append([0 for j in range(n)])
for j in range(n):
for k in range(n):
if((j+k)%2==0):
l[j][k]='W'
else:
l[j][k]='B'
for i in range(len(l)):
print("".join(l[i])) |
There are N gems. The value of the i-th gem is V_i.
You will choose some of these gems, possibly all or none, and get them.
However, you need to pay a cost of C_i to get the i-th gem.
Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.
Find the maximum possible value of X-Y.
Co... | 3 | n = int(input())
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
print(sum(_v - _c for _v, _c in zip(v,c) if _v > _c)) |
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of... | 3 | import sys
input=sys.stdin.readline
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
base=0
for A in a:
base^=A
if base==0:
print("DRAW")
else:
m=base.bit_length()-1
count=0
for A in a:
count+=(A>>m &1==1)
... |
You have three piles of candies: red, green and blue candies:
* the first pile contains only red candies and there are r candies in it,
* the second pile contains only green candies and there are g candies in it,
* the third pile contains only blue candies and there are b candies in it.
Each day Tanya eats... | 3 | import os
import sys
from io import BytesIO, IOBase
def solution(r, g, b):
if (r + g) <= b:
write(r + g)
else:
write((r + g + b) // 2)
def main():
for _ in range(r_int()):
r, g, b = sorted(r_array())
solution(r, g, b)
BUFSIZE = 8192
class FastIO(IOBase):
newlines ... |
Chandu is weak in maths. His teacher gave him homework to find maximum possible pair XOR in a matrix of size N x M with some conditions. Condition imposed is that, the pair can be formed between sum of elements in a column and sum of elements in a row.
See sample explanation for more details.
Input:
First line consis... | 1 | n,m = map(int, raw_input().split())
arr = []
check = n
row, col = [0]*n, [0]*m
while check>0:
arr.append([int(x) for x in raw_input().split()])
check -= 1
for i in range(n):
for j in range(m):
row[i] += arr[i][j]
col[j] += arr[i][j]
result = 0
for i in range(n):
for j in range(m):
result = max(result, row[i]^... |
Takahashi wants to be a member of some web service.
He tried to register himself with the ID S, which turned out to be already used by another user.
Thus, he decides to register using a string obtained by appending one character at the end of S as his ID.
He is now trying to register with the ID T. Determine whether... | 3 | #ABC167A
s = input()
t = input()
print("Yes" if s==t[:-1] else "No") |
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will count as a red o... | 3 | x,y,a,b,c = map(int,input().split())
p = sorted([int(x) for x in input().split()])[::-1][:x]
q = sorted([int(x) for x in input().split()])[::-1][:y]
r = [int(x) for x in input().split()]
row = sorted(p+q+r)[::-1]
print(sum(row[:x+y])) |
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 | from math import sqrt
def nth(i):
if i ==0:
return i
else:
return nth(i-1)+i+1
n = int(input())
string = input()
s = int(-0.5+sqrt(1 + (2*n)))
res =''
for i in range(s):
res+=string[nth(i)]
print(res) |
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 _ in range(int(input())):
x,y,z=map(int,input().split())
if x!=y and y!=z and x!=z:
print("NO")
else:
if x==y==z:
print("YES")
print(x,y,z)
else:
if x==y:
if z>x:
print("NO")
else:
... |
The chef has a recipe he wishes to use for his guests,
but the recipe will make far more food than he can serve to the guests.
The chef therefore would like to make a reduced version of the recipe which has the same ratios of ingredients, but makes less food.
The chef, however, does not like fractions.
The original rec... | 1 | ## EUCLIDEAN ALGORITHM used
# Default modulus based implementation of
# Greatest Common Denominator or Highest Common Factor
def gcd1(a,b):
while b != 0 :
t = b
b = a % b
a = t
return a
# Only subtraction and comparison
def gcd2(a,b):
while a != b :
if a > b:
... |
There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to... | 3 | a,b,c = map(int,input().split())
x = min(a,b,c)
z = max(a,b,c)
y = a + b + c - x - z
print ((y - x) + (z-y))
|
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay iΒ·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first lin... | 3 | a,b,c=map(int,input().split())
t=0
for i in range(1,c+1):
t=t+a*i
if(t-b>=0):
print(t-b)
else:
print('0') |
There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with the constant speed, the coordinate of the i-th point at the moment t (t can be non-integer) is calculated as x_i + t ... | 3 | import math
import sys
from collections import defaultdict, Counter
from itertools import groupby
#input = sys.stdin.readline
rt = lambda: map(int, input().split())
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
class Bit:
def __init__(self, n):
self.size = n
self.tree = [... |
While playing with geometric figures Alex has accidentally invented a concept of a n-th order rhombus in a cell grid.
A 1-st order rhombus is just a square 1 Γ 1 (i.e just a cell).
A n-th order rhombus for all n β₯ 2 one obtains from a n-1-th order rhombus adding all cells which have a common side with it to it (look ... | 3 | n=int(input())
ans=1
for i in range(2,n+1):
ans+=4+4*(i-2)
print(ans) |
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
* Operation ++ increases the value of variable x by 1.
* Operation -- decreases the value of variable x by 1.... | 3 | n = int(input())
x = 0
for i in range(n):
l = input()
if l[:2] == "++" or l[1:] == "++":
x += 1
if l[:2] == "--" or l[1:] == "--":
x -= 1
print(x)
|
Constraints
* 1 β€ |V| β€ 100
* 0 β€ |E| β€ 9900
* -2 Γ 107 β€ di β€ 2 Γ 107
* There are no parallel edges
* There are no self-loops
Input
An edge-weighted graph G (V, E).
|V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1
|V| is the number of vertices and |E| is the number of edges in G. The graph vertices are named wi... | 3 | V, E = map(int, input().split())
INF = 10 ** 10
dp = [[INF for i in range(V)] for j in range(V)]
for i in range(V):
dp[i][i] = 0
for i in range(E):
s, t, d = map(int, input().split())
dp[s][t] = d
for k in range(V):
for i in range(V):
if dp[i][k] == INF:
continue
for j in range(V):
if dp[k... |
Polycarp knows that if the sum of the digits of a number is divisible by 3, then the number itself is divisible by 3. He assumes that the numbers, the sum of the digits of which is divisible by 4, are also somewhat interesting. Thus, he considers a positive integer n interesting if its sum of digits is divisible by 4.
... | 3 | def somme(x):
som=0
for i in x:
som+=int(i)
return som
n=int(input())
# print(somme(str(n)))
while True:
if somme(str(n))%4==0:
print(n)
break
n+=1 |
To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line of (2n - 2) parking spaces. Unfortunately the total number of cars... | 1 | n = input()
print int(24 * (4 ** (n - 3)) + 36 * (n - 3) * (4 ** (n - 4))) |
There are some beautiful girls in Arpaβs land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 β€ i < j β€ n) such that <image>, where <image> is bitwise xor operation (see notes for explanation).
<image>
Immediately, Mehrdad d... | 3 | n,x = [int(i) for i in input().split()]
ans = 0
d = {}
for i in map(int, input().split()):
ans+=d.get(i^x,0)
d[i] = d.get(i,0)+1
print(ans) |
A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h-1 onto a base. A base consists of h pyramids of height 1, and h-1 cards on top. For example, card pyramids of heights 1, 2, and 3 look as follows:
... | 3 | def pregen(x=25852):
return [n * (3 * n + 1) // 2 for n in range(1, x)]
def solve(n):
ans = 0
while n > 1:
n -= arr[binsearch_pos(n)]
ans += 1
return ans
def binsearch_pos(n):
l, r = 0, len(arr)
for i in range(50):
m = (r + l) // 2
if arr[m] > n:
r =... |
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())
for _ in range(t):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(set(a) & set(b))
if(len(c)==0):
print("NO")
else:
print("YES")
print("1",c[0])
|
You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i.
Tozan and Gezan repeats the following sequence of operations:
* If A and B are equal sequences, ter... | 3 | n = int(input())
s = 0
m = 10**9+7
same = True
for _ in range(n):
a,b = map(int, input().split())
if a > b:
m = min(m, b)
s += a
same &= a==b
if same:
m = s
print(s-m)
|
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined <image>. You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the minimum poss... | 3 | from heapq import heappush, heappop
n, k1, k2 = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pq = []
for i in range(n):
if abs(a[i] - b[i]) > 0:
heappush(pq, -abs(a[i] - b[i]))
tot = k1 + k2
while pq and tot > 0:
ce = -heappop(pq)
tot -= 1
if ... |
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 | x=int(input())
a=[int(num) for num in input().split()]
a.sort(reverse=True)
d=sum(a)
c=(d//2)+1
count=0
sum1=0
for i in a:
sum1+=i
count+=1
if sum1>=c:
break
print(count) |
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (xβ1, y), (x, y + 1) and (x, yβ1).
Iahub wants to know how many ... | 3 | n = int(input())
print((n**2 + 1) // 2)
for i in range(n):
s = ''
for j in range(n):
if (i + j) % 2 == 0:
s += 'C'
else:
s += '.'
print(s) |
You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "c... | 3 | s=input()
print(s,end="")
for i in range(len(s)-1):
print(s[len(s)-2-i],end="")
print()
|
In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong β the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure β and then terribl... | 3 | def main():
(n, h) = input().split()
n = int(n)
h = int(h)
#(n, h) = (3, 3)
memo = [([None] * (h + 1)) for i in range(n + 1)]
catalans = [catalan(i) for i in range(n + 1)]
print(calculate(n, h, memo, catalans))
def calculate(n, h, memo, catalans):
if memo[n][h] != None:
return memo[n][h]
elif n < h:
memo[... |
You have a playlist consisting of n songs. The i-th song is characterized by two numbers t_i and b_i β its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied by the minimum beauty among them. For example, the pleasure of listening to... | 3 | from sys import stdin,stdout
from itertools import combinations
from collections import defaultdict
import math
import heapq
def listIn():
return list((map(int,stdin.readline().strip().split())))
def stringListIn():
return([x for x in stdin.readline().split()])
def intIn():
return (int(stdin.readline... |
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
Constraints
* 0\leq A,B,C\leq 100
* A, B and C are distinct integers.
I... | 3 | a,b,c=map(int,input().split())
print('Yes' if (a-c)*(c-b)>0 else 'No') |
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
* Operation ++ increases the value of variable x by 1.
* Operation -- decreases the value of variable x by 1.... | 3 | x = 0
for i in range(int(input())):
in_str = input()
if in_str[1] == '+':
x += 1
else:
x -= 1
print(x) |
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 = [int(x) for x in input().split()]
lexicon = {}
for i in range(m):
first, second = [str(x) for x in input().split()]
if len(first) <= len(second):
lexicon[first] = first
else:
lexicon[first] = second
sentence = [lexicon[x] for x in input().split()]
print(' '.join(sentence))
|
Many years ago Berland was a small country where only n people lived. Each person had some savings: the i-th one had a_i burles.
The government considered a person as wealthy if he had at least x burles. To increase the number of wealthy people Berland decided to carry out several reforms. Each reform looked like that... | 3 | t=int(input())
for _ in range(t):
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=n
a.sort()
m=sum(a)
i=0
while i<n and m/ans<x:
m-=a[i]
i+=1
ans-=1
print(ans) |
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point ... | 3 | def steps(n, k):
if(n == k):
return(0)
elif(n == 0):
return(k)
else:
if(k > n):
return(k - n)
elif(n > k):
if(n % 2 == k % 2 == 0):
return(0)
elif(n % 2 and k % 2 == 0):
return(1)
elif(n % 2 == 0 ... |
There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them ... | 3 | t=int(input())
for i in range(t):
a,b,c=map(int,input().split())
x=a*b
ans1,ans2=0,0
if(x==c):
ans2-=1
ans1+=b-1
elif(x<c):
ans2-=1
ans1+=c//a
elif(a>c):
ans1-=1
ans2+=b
elif(a==c and b>1):
ans1-=1
ans2+=b
else:
ans1... |
There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to... | 3 | l=list(map(int,input().split()))[:3]
l.sort()
ans=(l[2]-l[1])+(l[1]-l[0])
print(ans) |
You are given a rectangular board of M Γ N squares. Also you are given an unlimited number of standard domino pieces of 2 Γ 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squa... | 3 | input_data = input()
list_we_use=input_data.split(' ')
q=[]
for i in list_we_use:
q.append(int(i))
z=((q[0]*q[1])/2)
print(int(z))
|
During their New Year holidays, Alice and Bob play the following game using an array a of n integers:
* Players take turns, Alice moves first.
* Each turn a player chooses any element and removes it from the array.
* If Alice chooses even value, then she adds it to her score. If the chosen value is odd, Alice... | 1 | from __future__ import division
from sys import stdin, stdout
# from fractions import gcd
# from math import *
# from operator import mul
# from functools import reduce
# from copy import copy
from collections import deque, defaultdict, Counter
rstr = lambda: stdin.readline().strip()
rstrs = lambda: [str(x) for x in s... |
You are given a bracket sequence s of length n, where n is even (divisible by two). The string s consists of n/2 opening brackets '(' and n/2 closing brackets ')'.
In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end of the string (i.e. you choose some index i, remov... | 3 | for _ in range(int(input())):
n = int(input());
s = input();
st = [];
for i in range(n):
if(s[i] == "("):
st.append("(");
else:
if(st):
if(st[-1] == "("):
st.pop();
else:
st.append(")");
else:
st.append(")");
print(int(len(st)/2));
|
Mishka started participating in a programming contest. There are n problems in the contest. Mishka's problem-solving skill is equal to k.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses whic... | 3 | n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
r=0
while len(a):
if a[-1] <= k:
a = a[:-1]
r+=1
elif a[0] <=k:
a = a[1:]
r+=1
else: break
print (r)
|
Any resemblance to any real championship and sport is accidental.
The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship:
* the team that kicked most balls in the enemy's goal area wins the game;
* the victor... | 1 | cnt = 0
MAP = {}
MAPD = {}
R = [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
def getNo(s):
global cnt
if MAP.get(s, "") == "":
MAP[s] = cnt
MAPD[s] = 0
cnt += 1
MAPD[s] += 1
return MAP[s]
def pr... |
You are given two integers n and m. You have to construct the array a of length n consisting of non-negative integers (i.e. integers greater than or equal to zero) such that the sum of elements of this array is exactly m and the value β_{i=1}^{n-1} |a_i - a_{i+1}| is the maximum possible. Recall that |x| is the absolut... | 3 | for _ in range(int(input())):
summ = 0
n, m = map(int, input().split())
if n > 2:
print(m * 2)
elif n == 1:
print(0)
else:
print(m)
|
On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k β₯ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains.
Mountains are described by a sequence of heights... | 3 | T=int(input())
for t in range(T):
n,k=map(int,input().split())
A=list(map(int,input().split()))
ispeak=[0]*n
for i in range(1,n-1):
if A[i]>A[i-1] and A[i]>A[i+1]:
ispeak[i]=1
mx=0
ind=0
cnt=0
for i in range(1,k-1):
if ispeak[i]==1:
cnt+=1... |
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one o... | 3 | l, r = [int(x) for x in input().split()]
print("YES")
for x in range(l, r+1, 2):
print(x, x+1) |
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())
word = list()
for i in range(n):
word.append(str(input()))
if(len(word[i]) > 10):
word[i] = word[i][0] + str(len(word[i]) - 2) + str(word[i][len(word[i]) - 1])
else:
word[i] = word[i]
for j in range(n):
print(word[j]) |
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it... | 3 | n = int(input())
p = list(map(int,input().split()))
idx = [None]*(n+1)
for i,x in enumerate(p):
idx[x] = i
maxi = 1
l = 1
for i in range(1,n):
if idx[i] < idx[i+1]:
l += 1
if l > maxi:
maxi = l
else:
l = 1
print(n - maxi)
|
The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of n haybale piles on the farm. The i-th pile contains a_i haybales.
However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an a... | 3 | for i in range(int(input())):
n, d = map(int, input().split())
lst = [int(i) for i in input().split()]
a = 1
for j in lst[1:]:
if j == 0:
a += 1
continue
else:
if d - j * a >= 0:
lst[0] += j
d -= j * a
a ... |
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.
Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards excep... | 3 | def Checker(hint,card):
for a in card:
for b in card:
if a == b:
continue
elif a[0] == b[0]:
if a[1] not in hint and b[1] not in hint:
return False
elif a[1] == b[1]:
if a[0] not in hint and b[0] not in h... |
For the given integer n (n > 2) let's write down all the strings of length n which contain n-2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order.
Recall that the string s of length n is lexicographically less than string t of length n, if there exists such i (1 β€ i β€ n), that s_i < t_i, and for a... | 3 |
def main():
t = int(input())
while t != 0:
lst = list(map(int, (input().strip().split())))
n = lst[0]
k = lst[1]
count = 1
sum = 0
while sum < k:
sum += count
count += 1
sum -= count
count -= 1
#print('count:', count)
res = ''
if n - count - 1 != 0:
... |
Β«PolygonΒ» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | 3 | n = int(input())
a = list(map(int, input().split()))
ans = 0
a.sort()
for i in range(1, n+2):
if i not in a:
ans = i
print(ans)
exit(0)
|
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 | #Bear and Big Brother problem https://codeforces.com/problemset/problem/791/A
a,b=map(int,input().split(' '));i=0
while a<=b:
i=i+1
a,b=3*a,2*b
print(i) |
n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a1, a2, ..., an of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it.
The game consists of m steps. On each step the current leader with index i counts out ai... | 3 | n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = [0] * (n + 1)
for i in range(m - 1):
pot = (a[i + 1] - a[i] + n) % n
if pot == 0: pot = n
if ans[a[i]] == 0 or ans[a[i]] == pot: ans[a[i]] = pot
else:
print(-1)
exit(0)
used = [False] * (n + 1)
for i in ans:
used[i] = True
for i in rang... |
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules:
* The players move in turns; In one move the player can remove an arbitrary letter from string s.
* If the pl... | 3 | import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 1000000007
def gcd(a, b):
while b:
a, b = b, a%b
return a
def isPrime(n):
if (n <= 1):
return False
i = 2
while i ** 2 <= n:
if n % i == 0:
return False
i += 1
return True
def primeFactors(n):
factors = ... |
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) β
maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The ... | 3 | import sys
input = sys.stdin.readline
for _ in range(int(input())):
a1, k = input().split()
for i in range(min(1000, int(k)-1)):
a1 = str(int(a1) + int(min(a1))*int(max(a1)))
if min(a1)=='0':
ans = a1
break
ans = a1
print(a1) |
C: Short-circuit evaluation
problem
Naodai-kun and Hokkaido University-kun are playing games. Hokkaido University first generates the following logical formula represented by BNF.
<formula> :: = <or-expr>
<or-expr> :: = <and-expr>
| <or-expr> "|" <and-expr>
<and-expr> :: = <term>
| <and-expr> "&" <term>
<term> :: =... | 3 | import sys
sys.setrecursionlimit(2*10**5)
question = 1
AND = -1
OR = -2
left = -3
right = -4
tr = {'?': 1, '&': -1, '|': -2, '(': -3, ')': -4}
def evalor(L):
if len(L) == 1:
return L[0]
x0, x1 = L[0]
for i in range(1, len(L)):
y0, y1 = L[i]
x0, x1 = x0 + y0, min(x1, x0 + y1)
re... |
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
<imag... | 1 | # -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import generators
from __future__ import nested_scopes
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import with_statement
import bisect
import collections
imp... |
The kingdom of Lazyland is the home to n idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland.
Today k important jobs for the kingdom (k β€ n) should be performed. Every job should be done by one person and every person can do at most one job. The King allowed e... | 3 |
n, k = map(int, input().split())
jobs = list(map(int, input().split()))
t = list(map(int, input().split()))
exch = k - len(set(jobs))
doubleJobs = [0] * (k + 1)
timeOfDouble = []
for l in range(len(jobs)):
if doubleJobs[jobs[l]] < t[l]:
if doubleJobs[jobs[l]] != 0:
timeOfDouble.appen... |
A sequence of non-negative integers a_1, a_2, ..., a_n is called growing if for all i from 1 to n - 1 all ones (of binary representation) in a_i are in the places of ones (of binary representation) in a_{i + 1} (in other words, a_i \:\&\: a_{i + 1} = a_i, where \& denotes [bitwise AND](http://tiny.cc/xpy9uz)). If n = 1... | 3 | def f(x,y):
return x&~y
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int,input().strip().split()))
b = [0 for i in range(n)]
for i in range(1,n):
b[i]=f(b[i-1]^a[i-1],a[i])
for x in b:
print(x,end=" ")
print() |
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | 3 | s1=input()
s2=input()
s3=input()
s1=sorted(s1+s2)
s3=sorted(s3)
c=0
if(len(s1)!=len(s3)):
print('NO',end='')
else:
if(s1==s3):
print('YES',end='')
else:
print('NO',end='')
|
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers).
The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
Note
θ§£θͺ¬
Input
In the first line, the number of cards n (n β€ 52) is given.
In the following n line... | 3 | n = int(input())
lst = [(m,no) for m in ['S','H','C','D'] for no in range(1,14)]
for i in range(n):
m,no = input().split()
lst.remove((m,int(no)))
for (m,no) in lst:
print(m,no)
|
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay iΒ·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first lin... | 3 | k,n,w = list(map(int,input().split()))
sum = 0
for i in range(1,w+1):
sum+=i
print(max(0,k*sum-n))
|
Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check ... | 3 | n = int(input())
d = [int(i) for i in input().split()]
d.sort()
for i in range(n - 2):
a = d[i]
b = d[i + 1]
c = d[i + 2]
if a + b > c and a + c > b and b + c > a:
print("YES")
break
else:
print("NO") |
You are given an array a, consisting of n integers.
Each position i (1 β€ i β€ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked positions. You are not allowed to remove any values, add the new ones or rearra... | 3 | import math
t=int(input())
for i in range(t):
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
z=[]
for i in range(n):
if y[i]==0:
z.append(x[i])
z.sort()
z.reverse()
k=0
j=0
while j <(len(z)):
if y[k]!=1:
x[... |
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 | n=int(input())
for i in range(n):
for j in range(n):
if (i+j)%2==0:
print("W",end="")
else:
print("B",end="")
print() |
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs ai minutes to read the ... | 3 | INPUT = lambda: list(map(int, input().split()))
n, t = INPUT()
a = INPUT()
sumTime = 0
left = 0
result = 0
for right in range(n):
sumTime += a[right]
while sumTime > t:
# start reading the next book
sumTime -= a[left]
# print("sumTime =", sumTime)
left += 1
result = max(r... |
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 | input()
prev, s, step_number = None, "", 1
t = input()
def get_t_n(n):
return int(n * (n + 1) / 2)
while True:
i = get_t_n(step_number)
if len(t) >= i:
s += t[i - 1]
step_number += 1
else:
break
print(s)
|
A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not.
You are given a string s of length n, consisting of digits.
In one operation you can delete any character from strin... | 3 | for _ in range(int(input())):
k = int(input())
s = str(input())
p = s.find('8')
if(p ==-1):
print("NO")
else:
if(k - p >=11):
print("YES")
else:
print("NO")
|
Takahashi is meeting up with Aoki.
They have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.
Takahashi will leave his house now and go straight to the place at a speed of S meters per minute.
Will he arrive in time?
Constraints
* 1 \leq D \leq 10000
* 1 \leq T \leq 10... | 3 | d,t,s=map(int, input().split());print(('Yes','No')[d/s>t]) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.