problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Some time ago Lesha found an entertaining string s consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows. Lesha chooses an arbitrary (possibly zero) number of pairs on positions (i, i + 1) in such a way that the foll...
3
import sys s = input().strip() N = len(s) if len(s) == 1: print(1, s[0]) sys.exit() X = [s[-1], s[-2]+s[-1] if s[-2]!=s[-1] else ""] Y = [1, 2 if s[-2]!=s[-1] else 0] for i in range(N-3, -1, -1): c = s[i] k1 = c+X[-1] ng = Y[-1]+1 if ng > 10: k1 = k1[:5] + "..." + k1[-2:] if c == s[i...
The term of this problem is the same as the previous one, the only exception — increased restrictions. Input The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a1, a2, ...,...
3
n, k = [int(f) for f in input().split(' ') if f] a = [int(f) for f in input().split(' ') if f] b = [int(f) for f in input().split(' ') if f] l = 0 r = 100000000000000000 while l + 1 < r: mid = (l + r) // 2 dust = int(k) for i in range(n): dust -= max(0, mid * a[i] - b[i]) if dust < 0: ...
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xi coins. Vasiliy plans to buy his favorite drink fo...
3
q, g = [0 for _ in range(100007)], [0] n = int(input()) mxx = 0 tmp = input() tmp = [int(i) for i in tmp.split()] for i in tmp: mxx = max(mxx, i) q[i] += 1 for i in range(1, 100007): g.append(g[i - 1] + q[i - 1]) n = int(input()) while n > 0: k = int(input()) if k >= 100000: print(g[100001]) else: prin...
Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem. There are n positive integers a_1, a_2, …, a_n on Bob's homework paper, where n is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least 2 numbers. Suppose the n...
3
import copy import fractions import itertools import numbers import string import sys ### def powmod(x, p, m): if p <= 0: return 1 if p <= 1: return x%m return powmod(x*x%m, p//2, m) * (x%m)**(p%2) % m ### def to_basex(num, x): while num > 0: yield num % x num //= x def from_basex(it, x): ret = 0 p =...
Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the f...
3
a=int(input()) b=int(input()) c=(a+b)//2 x=abs(a-c) y=abs(b-c) print((x*(x+1))//2+(y*(y+1))//2)
Mishka wants to buy some food in the nearby shop. Initially, he has s burles on his card. Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number 1 ≤ x ≤ s, buy food that costs exactly x burles and obtain ⌊x/10⌋ burles as a cashback (in other words, Mishka ...
3
# import math for _ in range(int(input())): # arr = list(map(int, input().split())) n = int(input().strip()) # arr = list(map(int, input().split())) ans = 0 temp = n // 9 temp2 = n - temp * 9 ans = n // 9 * 10 + temp2 if n % 9 == 0: ans -= 1 print(ans)
Limak can repeatedly remove one of the first two characters of a string, for example abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx. You are given N different strings S_1, S_2, \ldots, S_N. Among N \cdot (N-1) / 2 pairs (S_i, S_j), in how many pairs could Limak obtain one string from the other? Constraints...
3
import sys readline = sys.stdin.readline ans = 0 def scomp(S): L = 1+max(S) table = [0]*L for s in S: table[s] += 1 it = [None]*L cnt = 0 for i in range(L): it[i] = cnt if table[i]: cnt += 1 return it import sys readline = sys.stdin.readline class Node:...
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
w=int(input()) p=w/2 if(w==2): print("NO") else: if (w%2==0): if (p%2==0): print("YES") else: p+=1 if((w-p)>1): print ("YES") else: print("NO") else: print("NO")
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If t...
3
n=int(input()) a=list(map(int,input().split())) z=[] for i in range(n): for j in range(n): if a[j]==i+1: print(j+1,end=" ")
You are given three integers x, y and n. Your task is to find the maximum integer k such that 0 ≤ k ≤ n that k mod x = y, where mod is modulo operation. Many programming languages use percent operator % to implement it. In other words, with given x, y and n you need to find the maximum possible integer from 0 to n tha...
3
t=int(input()) for _ in range(t): x,y,n=map(int,input().split()) k=n//x if ((k*x)+y)<=n: print(k*x+y) else: print(((k-1)*x)+y)
In this problem, we only consider strings consisting of lowercase English letters. Strings s and t are said to be isomorphic when the following conditions are satisfied: * |s| = |t| holds. * For every pair i, j, one of the following holds: * s_i = s_j and t_i = t_j. * s_i \neq s_j and t_i \neq t_j. For example, `a...
3
li="abcdefghijklmn" n=int(input()) def f(s,l,k): global li,n if l==n:print(s);return for i in range(2+k): f(s+li[i],l+1,max(i,k)) f("a",1,0)
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many ...
3
part, place = map(int, input().split()) inp = list(map(int, input().split())) count = 0 for i in inp: if i >= inp[place-1] and i != 0: count += 1 print(count)
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...
1
#-*- coding: utf-8 -*- import sys w = sys.stdout.write read = sys.stdin.readline reads = sys.stdin.read def r(f=None): if f: return map(f, read().split()) else: return read().split() def rs(t,f=None): result = [] result_append = result.append for i in xrange(t): if f: ...
In Omkar's last class of math, he learned about the least common multiple, or LCM. LCM(a, b) is the smallest positive integer x which is divisible by both a and b. Omkar, having a laudably curious mind, immediately thought of a problem involving the LCM operation: given an integer n, find positive integers a and b suc...
3
import math def lcm(n) : i = 1 ans = [] while i <= math.sqrt(n): if (n % i == 0) : if (n / i == i) : ans.append(i) else : ans.append(i) ans.append(n//i) i = i + 1 return ans t = int(input()) for _ in range(t): ...
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. Constraints * 1 ≤ a,b ≤ 10000 * a and b are integers. Input Input is given from Standard Input in the following format: a b Output If the product is odd, print `Odd`; if it is even, print `Even`. E...
1
s=raw_input().split() a=int(s[0]); b=int(s[1]); if a*b%2==0: print "Even" else: print "Odd"
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line cont...
3
a=int(input()) b=list(map(int, input().split())) c=0 d=1 for i in range(1,a): if b[i]>b[i-1]: d=d+1 else: c=max(d, c) d=1 c=max(d,c) print(c)
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()) for x in range(n): word=str(input()) if len(word)>10: word=word[0] + f"{(len(word)-2)}" +word[-1] else: word=word print(word)
Recall that the sequence b is a a subsequence of the sequence a if b can be derived from a by removing zero or more elements without changing the order of the remaining elements. For example, if a=[1, 2, 1, 3, 1, 2, 1], then possible subsequences are: [1, 1, 1, 1], [3] and [1, 2, 1, 3, 1, 2, 1], but not [3, 2, 3] and [...
3
for i in range(int(input())): n = int(input()) ar = list(map(int, input().split())) # groups gg = [] for i in ar: if len(gg) == 0: gg.append(i) else: if gg[-1] * i > 0: gg[-1] = max(gg[-1], i) elif gg[-1] * i < 0: gg...
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to differen...
3
n,m,h=map(int,input().split()) s=list(map(int,input().split())) a=1 S=sum(s) for i in range(S-s[h-1]+1,S): a*=(i-n+1)/i print(-1 if S<n else 1-a) # Made By Mostafa_Khaled
Find the minimum area of a square land on which you can place two identical rectangular a × b houses. The sides of the houses should be parallel to the sides of the desired square land. Formally, * You are given two identical rectangles with side lengths a and b (1 ≤ a, b ≤ 100) — positive integers (you are given ...
3
a = input() n_inputs = int(a) entries = [] for i in range(n_inputs): d = input() a, b = d.split() entries.append([int(a), int(b)]) def min_square(d): return(max(max(d[0], d[1]), 2*min(d[0], d[1]))**2) for e in entries: print(min_square(e))
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...
1
n = input() for i in range (n): s=raw_input() m=len(s) if m<=10: print (s) else: print(s[0]+str(m-2)+s[m-1])
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. Input The first line of input contains ...
3
magic = ['1', '14', '144'] s = input() length = len(s) i = 0 ans = 'YES' while i < length: yes = False for j, num in enumerate(magic[::-1]): if (s[i:i + 3 - j] == num): i += 3 - j yes = True break if (not yes): ans = 'NO' break print (ans)
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and ...
3
a, b = map(int, input().split(' ')) x = abs(a - b) print(max(a, b) - x, x // 2)
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples. Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows: * Move: ...
3
n,t = map(int,input().split()) a = list(map(int,input().split())) p = a[n-1] r = [] for i in range(n-1,-1,-1): if a[i] >= p: p = a[i] else: r.append(p-a[i]) res = r.count(max(r)) print(res)
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
for _ in range(int(input())): n, m = map(int, input().split()) s = list(map(int, input().split())) m = list(map(int, input().split())) p = 1 for i in range(n): if s[i] in m: p = 0 print('YES') print(1, s[i]) break if p == 1: print('...
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
3
a=int(input()) b=["I hate it","I love it"] c=["I hate that","I love that"] for i in range(0,a-1,1): print(c[i%2],end=" ") print(b[(a+1)%2])
You are given an array a[0 … n-1] of length n which consists of non-negative integers. Note that array indices start from zero. An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all i (0 ≤ i ≤ n - 1) the equality i mod 2 = a[i] m...
3
for i in range(int(input())): length = int(input()) l = enumerate(list(map(int, input().split()))) a, b = 0, 0 for e, i in l: if e % 2 == i % 2 and e % 2 == 0: a += 1 elif e % 2 == i % 2 and e % 2 == 1: b += 1 print(-1 if (a - length % 2) != b else (length - a - b) //2)
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of ...
3
#!usr/bin/python def main(): n=int(input()) a=[int(br) for br in input().split()] hcf=a[0] i=1 while(i<n): hcf=gcd(hcf,a[i]) i+=1 i=0 while(i<n): b=hcf a[i]/=b while(a[i]>1 and a[i]%2==0): a[i]/=2 while(a[i]>1 and a[i]%3==0): ...
A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array). Consider a permutation p of length ...
3
# from math import * n = int(input()) mod = 1e9+7 a = 1 for i in range(1,n+1): a = a*i a %= mod # a = int(a) # print(a) a%=mod # a = int(a) b = 1 for i in range(n-1): b *= 2 b %= mod # b = int(a) b %= mod # b = int(b) ans = a - b + mod # print(a,b,ans) # print (ceil(lgamma(n+1)/log(10))) an...
You have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \leq i \leq N) is v_i. When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where...
3
N=int(input()) v=list(map(int, input().split())) v.sort() ans=v[0] for i in range(N): ans = (ans+v[i])/2 print(ans)
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is di...
3
def numtype(x): if(x%2==0): return 1 else: return 0 n= int(input()) l=list(map(int,input().split())) g=[] for i in l: g.append(numtype(i)) if(g.count(0)==1): print(g.index(0)+1) else: print(g.index(1)+1)
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a. What is the least number of flagstones needed to pave the Square? It'...
3
import sys import math for line in sys.stdin: n, m, a = (float(s) for s in line.split()) print(int((math.ceil( n / a )) * (math.ceil( m / a ))))
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
3
import math def divbylucky(n): nonlucky = ['0', '1', '2', '3', '5', '6', '8', '9'] for i in range(2,int(n / 2) + 1): if n % i == 0: lucky = True for elem in nonlucky: if elem in str(i): lucky=False break if luck...
Ringo found a string s of length n in his [yellow submarine](https://www.youtube.com/watch?v=m2uTFF_3MaA). The string contains only lowercase letters from the English alphabet. As Ringo and his friends love palindromes, he would like to turn the string s into a palindrome by applying two types of operations to the stri...
3
s=input() n= len(s) print(4) print("L",2) print("R",n) print("R",2) print("R",2*n+1)
You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet: * has at least one red bean (or the number of red beans r_i ≥ 1); * has at least one blue bean (or the number of blue beans b_i ≥ 1); * the number of red and blue beans should diff...
3
for _ in range(int(input())): r, b, d = map(int, input().split()) if r > b: r, b = b, r if b <= r * (d+1) and b and r: print('YES') else: print('NO')
A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are n...
3
n = int(input()) for _ in range(n): s = sorted(input()) ss= set(map(lambda x,y: ord(y)-ord(x), s, s[1:])) if ss == set([1]) or not ss: print("YES") else: print("NO")
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf...
3
n = int(input()) cr = input() arr = ['-'] * n goLeft = True if n % 2 == 1: goLeft = False res = '' for i in range(n): c = cr[i] if goLeft: res = c + res else: res = res + c goLeft = not goLeft print (res)
Yurii is sure he can do everything. Can he solve this task, though? He has an array a consisting of n positive integers. Let's call a subarray a[l...r] good if the following conditions are simultaneously satisfied: * l+1 ≤ r-1, i. e. the subarray has length at least 3; * (a_l ⊕ a_r) = (a_{l+1}+a_{l+2}+…+a_{r-2}...
3
import math n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(2, n): sum = 0 for j in reversed(range(0, i-1)): sum += a[j+1] ans += a[i] > a[j] and a[i]^a[j] == sum if sum > 2*a[i] or a[j].bit_length() > a[i].bit_length(): break a.reverse() for i in range(2, n): sum = 0 for j in r...
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than ...
3
n = int(input()) p_h = -1 p_m = -1 m_c = 0 c = 0 for _ in range(n): h, m = map(int, input().split()) if h == p_h and m == p_m: c += 1 else: c = 1 if c > m_c: m_c = c p_h, p_m = h, m print(m_c)
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i. You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maxi...
3
from collections import Counter n = int(input()) lvls = Counter((int(i) for i in input().split())) max_size = 0 for i in sorted(lvls.keys()): size = (lvls[i] + lvls[i + 1] + lvls[i + 2] + lvls[i + 3] + lvls[i + 4] + lvls[i + 5]) max_size = max(max_size, size) print(max_size)
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city? Constraints * 2≤N,M≤50 * 1≤a_i,b_i≤N * a_i ≠ b_i * All input values a...
3
N, M = map(int, input().split()) lst = [] for _ in range(M): lst.extend(list(map(int, input().split()))) for i in range(N): print(lst.count(i+1))
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
def read_int() -> int: return int(input()) def read_ints(): return map(int, input().split(' ')) def pos_range(n): return range(1, 1+n) def test_case(): n = read_int() arr = list(pos_range(n)) pointer = n-1 print(2) while pointer != 0: maximal = arr[pointer] i, to_ad...
Takahashi participated in a contest on AtCoder. The contest had N problems. Takahashi made M submissions during the contest. The i-th submission was made for the p_i-th problem and received the verdict S_i (`AC` or `WA`). The number of Takahashi's correct answers is the number of problems on which he received an `A...
3
n, m = map(int, input().split()) sac = set() lwa = [0] * n for i in range(m): p, s = input().split() p = int(p) - 1 if p in sac: continue elif s == 'AC': sac.add(p) else: lwa[p] += 1 print(len(sac), sum(lwa[p] for p in sac))
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure. Bottle with potion has two values x and y written on it. These values define four moves which can be performed...
1
import sys stuff = [int(i) for i in raw_input().split()] x_1 = stuff[0] y_1 = stuff[1] x_2 = stuff[2] y_2 = stuff[3] stuff = [int(i) for i in raw_input().split()] x = stuff[0] y = stuff[1] if (x_2 - x_1) % x == 0 and (y_2 - y_1) % y == 0: if ((x_2 - x_1)/x + (y_2 - y_1)/y) % 2 == 0: print "YES" ...
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
1
#!/usr/bin/env python """(c) gorlum0 [at] gmail.com""" import itertools as it from sys import stdin def solve(n, a, b): maxcup = cap = 0 for i in xrange(n): cap -= a[i] cap += b[i] maxcup = cap if cap > maxcup else maxcup return maxcup def main(): for l in stdin: n = in...
Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of n different bloggers. Blogger numbered i has a_i followers. Since Masha has a limited budget, she can only sign a contract with k different bloggers. Of course...
3
import sys from math import gcd input=sys.stdin.readline I = lambda : list(map(int,input().split())) def ncr(n,r,md): p = 1 k = 1 r=min(n - r ,r) m=k=1 while (r): p *= n p //= m n -= 1 r -= 1 m+=1 p%=md return p t,=I() for _ in range(t): n,k=I() l=sorted(I()) x=l[n-k] x,y = l.count...
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa...
3
def find_the_most_beatiful(a): n = len(a) result = [] while n > 0: a = sorted(a) value = -100500 for i in range(len(a)): if a[i] > value and a[i] > 0: value = a[i] result += [a[i]] a[i] = -1 n -= 1 numbe...
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation a + b = c, where a and b are positive integers, and c is the sum of a...
1
s1=raw_input() s2=raw_input() c=int(s1)+int(s2) a=filter(lambda x:int(x),s1) b=filter(lambda x:int(x),s2) c=filter(lambda x:int(x),str(c)) #print a,b,c c2=int(a)+int(b) #print c2 if c==str(c2): print 'YES' else: print 'NO'
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
n,k=map(int,input().strip().split(" ")) area=n*k print(area//2)
For two sequences S and T of length N consisting of 0 and 1, let us define f(S, T) as follows: * Consider repeating the following operation on S so that S will be equal to T. f(S, T) is the minimum possible total cost of those operations. * Change S_i (from 0 to 1 or vice versa). The cost of this operation is D \time...
3
N=int(input()) C=sorted(map(int,input().split())) mod=10**9+7 ANS=0 for i in range(1,N+1): ANS=ANS+C[-i]*(i+1)*pow(2,N*2-2,mod) ANS%=mod print(ANS)
There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number. Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1). When Mountain i (1 \leq i \l...
3
N = int(input()) A = list(map(int,input().split())) x1 = (sum(A[0::2])-sum(A[1::2])) Ans = [x1] for a in A: Ans.append(2*a-Ans[-1]) print(*Ans[:-1],sep = " ")
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he c...
3
import sys input = sys.stdin.readline N=int(input()) X,Y=1,1 for i in range(N): T,A=map(int,input().split()) k=max((X+T-1)//T,(Y+A-1)//A) X,Y=k*T,k*A print(X+Y)
Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwis...
3
x1, y1 = map(int,input().split()) x2, y2 = map(int,input().split()) x3, y3 = map(int,input().split()) print("3") print(x3+x1-x2, y3+y1-y2) print(x3+x2-x1, y3+y2-y1) print(x2+x1-x3, y2+y1-y3)
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 ≤ r ...
3
p,q=map(int,input().split()) pp=p i=1 while pp%10!=q and pp%10!=0: pp+=p i+=1 print(i)
You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes. Note that you should find only the time after a minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here <https://en.wikipedia.org/wiki/24-hour_clock>. Input The first line...
1
h, m = map(int, raw_input().split(':')) m += int(raw_input()) h = (h + m // 60) % 24 m %= 60 print('%02d:%02d' % (h, m))
The cows have just learned what a primitive root is! Given a prime p, a primitive root <image> is an integer x (1 ≤ x < p) such that none of integers x - 1, x2 - 1, ..., xp - 2 - 1 are divisible by p, but xp - 1 - 1 is. Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given ...
1
def gcd(a,b): if a<b: a,b=b,a while b: a,b=b,a%b return a p = int(raw_input()) print 1 if p==2 else sum(gcd(a,p-1)==1 for a in xrange(1,p-1))
Constraints * H is an integer between 2 and 50 (inclusive). * W is an integer between 2 and 50 (inclusive). * s_{i, j} is `.` or `#` (1 \leq i \leq H, 1 \leq j \leq W). * s_{1, 1} and s_{H, W} are `.`. Input Input is given from Standard Input in the following format: H W s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s_{2,...
3
import sys sys.setrecursionlimit(3000) import queue h,w=map(int,input().split()) s=['#'*(w+2)]+['#'+input()+'#' for _ in [0]*h]+['#'*(w+2)] l=[[0]*(w+2) for _ in [0]*(h+2)] for i in range(h+2): for j in range(w+2): if s[i][j]=='#': l[i][j]=-1 L=queue.Queue() L.put([1,1]) while not L.empty(): ...
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
import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) t,=I() for _ in range(t): n,=I() l=I() an=0 i=0 pr=0 le=0;re=0 while i<n: while i<n and l[i]>=0: le+=l[i] i+=1 while i<n and l[i]<=0: re+=l[i] i+=1 #print(le,re) an+=abs(min(0,le+re)) if le+re>=0: le=le+re...
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 heapq from collections import deque def bfs(i, c): color[i] = c cnt[c] += 1 q = deque() q.append(i) while q: j = q.popleft() for k in G[j]: if color[k] == -1: color[k] = c cnt[c] += 1 q.append(k) return n = int(...
Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. Input The ...
3
n,k=map(int,input().split()) for i in range(n): for j in range(n): print('0' if i is not j else str(k),end=' ') print()
You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists. You have to answer t independent test cases. Recall that the substring s[l ...
3
import itertools def solveAll(): nbCases = int(input()) for _ in range(nbCases): n, a, b = readCase() print(solve(n, a, b)) def readCase(): return map(int, input().split()) def solve(n, a, b): pattern = ["a"] * a for i in range(b): pattern[i] = chr(ord("a") + i) chars ...
<image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character o...
1
#!/usr/bin/env python #-*- coding:utf-8 -*- import sys, math, random, operator from string import ascii_lowercase from string import ascii_uppercase from fractions import Fraction, gcd from decimal import Decimal, getcontext from itertools import product, permutations, combinations from Queue import Queue, PriorityQue...
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting e...
3
q,w,e=int(input()),int(input()),int(input()) print(max(q+w+e,q+w*e,q*w+e,(q+w)*e,q*(w+e),q*w*e))
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
1
#!/usr/bin/python import sys s, n = map(int, raw_input().split()) a = [map(int, raw_input().split()) for i in xrange(n)] #for i in xrange(n): # a.append(map(int, raw_input().split())) a.sort() for i, j in a: if (s <= i): print "NO" sys.exit(0) s+=j print "YES"
In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 5. Th...
3
import sys n = int(input()) a = list(map(int, sys.stdin.readline().split())) b = list(map(int, sys.stdin.readline().split())) counts = [0, 0, 0, 0, 0, 0] for i in range(n): counts[a[i]] += 1 counts[b[i]] -= 1 can = True for i in range(1, 6): if counts[i] % 2 != 0: can = False break ans =...
You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists. You have to answer t independent test cases. Recall that the substring s[l ...
3
for t in range(int(input())): n, a, b = map(int, input().split()) s = [0]*n f, x = 97, 0 if a != 1 and b == 1: for i in range(len(s)): s[i] = chr(f) elif a == b: for i in range(len(s)): if x >= 26: x = 0 s[i] = chr(f + x) ...
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, ...
3
[n,k] = list(map(int, input().split(" "))) s = input() for i in s: if s.count(i) > k: print("NO") exit(0) print("YES")
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...
1
N,M = map(int,raw_input().split()) print N*M/2
Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water. There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop. The bottle of the first type costs a burles and the bottle of the se...
3
q=int(input()) for g in range(q): n,a,b=map(int,input().split()) x=n*a y=((n//2)*b)+((n%2)*a) print(min(x,y))
There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely deep barrel; 2. take one cup of the cold water and pour it into an infin...
3
def i_by_t(h, c, t): return ((h - c) / (t - (h + c) / 2) + 2) / 2 for _ in range(int(input())): h, c, t = map(int, input().split()) mean = (h + c) / 2 def temp(i): half = i // 2 return (h * (i - i // 2) + c * half) / i T = temp(1) if t >= T: print(1) continue...
You are given a sorted array a_1, a_2, ..., a_n (for each index i > 1 condition a_i ≥ a_{i-1} holds) and an integer k. You are asked to divide this array into k non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. Let max(i) be equal to the maximum in the i-th subar...
3
N, K = map(int, input().split()) A = list(map(int, input().split())) if N == 1: print(0) else: B = [A[i+1]-A[i] for i in range(N-1)] B.sort(reverse=True) print(sum(B[K-1:]))
The only difference between easy and hard versions is a number of elements in the array. You are given an array a consisting of n integers. The value of the i-th element of the array is a_i. You are also given a set of m segments. The j-th segment is [l_j; r_j], where 1 ≤ l_j ≤ r_j ≤ n. You can choose some subset of...
3
import sys input = sys.stdin.readline n,m=map(int,input().split()) A=list(map(int,input().split())) LR=[list(map(int,input().split())) for i in range(m)] def MINUS(A,B): MIN=float("inf") MAX=-float("inf") for i in range(len(A)): if MIN>A[i]-B[i]: MIN=A[i]-B[i] if MAX<A[i]-B[i...
You have n students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the i-th student skill is denoted by an integer a_i (different students can have the same skills). So, about the teams. Firstly, these two teams should have the s...
3
from collections import* for _ in range(int(input())): n=int(input()) a=sorted(Counter(input().split()).values()) m=len(a) ok=0 ng=n while ng-ok>1: mid=ok+ng>>1 if a[-1]>mid and m>=mid or a[-1]==mid and m>mid: ok=mid else: ng=mid print(ok)
Takahashi participated in a contest on AtCoder. The contest had N problems. Takahashi made M submissions during the contest. The i-th submission was made for the p_i-th problem and received the verdict S_i (`AC` or `WA`). The number of Takahashi's correct answers is the number of problems on which he received an `A...
3
n,m=map(int,input().split()) a=[-1]*n for i in range(m): p,s=input().split() p=int(p)-1 if s=="AC" and a[p]<0: a[p] = a[p]*(-1) if s=="WA" and a[p]<0: a[p] -= 1 ac=0 wa=0 for i in range(n): if a[i] > 0: ac += 1 wa += a[i] - 1 print(ac,wa)
Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: * Extract the first character of s and append t with this character. * Extract the last character of t and append u with this ...
3
s=input() c=[0]*26 for i in s: c[ord(i)-97]+=1 t=[] u=[] for i in s: t.append(i) c[ord(i)-97]-=1 while t and sum(c[:(ord(t[-1])-97)])==0: u.append(t.pop()) print(''.join(u))
In this problem, we only consider strings consisting of lowercase English letters. Strings s and t are said to be isomorphic when the following conditions are satisfied: * |s| = |t| holds. * For every pair i, j, one of the following holds: * s_i = s_j and t_i = t_j. * s_i \neq s_j and t_i \neq t_j. For example, `a...
3
n=int(input()) ans=[] def b(s): if len(s)==n: ans.append(s) return for i in "abcdefghijklmnopqrstuvwxyz": b(s+i) if max(list(s))==chr(ord(i)-1):return b("a") ans.sort() for i in ans:print(i)
You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels:...
3
n=int(input()) l=list(map(int,input().split())) vw=['a','e','i','o','u','y'] for i in range(n): s=str(input()) p=0 for j in range(len(s)): if s[j] in vw: p+=1 if p!=l[i]: print("NO") exit() print("YES")
Let us define the FizzBuzz sequence a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first...
3
ans=0 N=int(input()) c=0 while c<=N: if c%3!=0 and c%5!=0: ans+=c c+=1 print(ans)
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: * Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). * Digits are written one by one in ...
1
digits = int(raw_input()) string = raw_input() answer = "" current_seq = 0 for digit in string: if digit == '1': current_seq += 1 elif digit == '0' and current_seq: answer += str(current_seq) current_seq = 0 else: answer += '0' answer += str(current_seq) print answer
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all a...
3
import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read non spaced string and elements are integers to list of int get_intList_from_str = lambda: list(map(int,list(sys.stdin....
The length of the longest common prefix of two strings s = s_1 s_2 … s_n and t = t_1 t_2 … t_m is defined as the maximum integer k (0 ≤ k ≤ min(n,m)) such that s_1 s_2 … s_k equals t_1 t_2 … t_k. Koa the Koala initially has n+1 strings s_1, s_2, ..., s_{n+1}. For each i (1 ≤ i ≤ n) she calculated a_i — the length of ...
3
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = [] for i in range(n + 1): s.append('') j = 0 k = 0 for i in a: if i > len(s[j]): if k < 26: s[j] += chr(97 + k) * (i - len(s[j])) k += 1 ...
Dr .: Peter, I've finally done it. Peter: See you again? What kind of silly invention is this time? Dr .: I finally came up with a revolutionary way to process mathematical formulas on a computer. Look at this table. Ordinary notation | Dr.'s "breakthrough" notation --- | --- 1 + 2 | 1 2 + 3 * 4 + 7 | 3 4 * 7 + 10 /...
3
while 1: try:s=list(input().split()) except:break a=[] for x in s: if x in ['+','-','*','/']: c,b=str(a.pop()),str(a.pop()) b+=x+c a+=[float(eval(b))] else:a+=[float(x)] print(a.pop())
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input The first line contains integ...
3
n = int(input()) s = input() tmp = s[0] cnt = 0 for i in range(1, len(s)): if tmp == s[i]: cnt +=1 tmp = s[i] print(cnt)
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters. There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end...
3
n = int(input()) s = input().replace("ogo","***") for i in range(50): s = s.replace("**g**","*") s = s.replace("*go","*") print(s)
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
3
# Helpful Maths string = input().strip() intStr = string.split('+') intStr.sort() newStr = "" for i in intStr: newStr += i+"+" print(newStr[:-1])
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either inc...
1
n,k=map(int,raw_input().split()) a=map(int,raw_input().split()) for i in xrange(10**5): a=filter(lambda x: x!=k,a) if not a: break for x in range(len(a)): if x==len(a)-1 or a[x]!=a[x+1]: a[x]+=1 print i
Kuroni has n daughters. As gifts for them, he bought n necklaces and n bracelets: * the i-th necklace has a brightness a_i, where all the a_i are pairwise distinct (i.e. all a_i are different), * the i-th bracelet has a brightness b_i, where all the b_i are pairwise distinct (i.e. all b_i are different). Kuro...
3
def run(): t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort() print(*a) print(*b) if __name__ == '__main__': run()
A string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal. Given a string S, determine whether it is coffee-like. Constraints * S is a string of length 6 consisting of lowercase English l...
1
import sys s = sys.stdin.readline() if s[2] == s[3] and s[4] == s[5]: print("Yes") else: print("No")
You are given a string s consisting of lowercase Latin letters "a", "b" and "c" and question marks "?". Let the number of question marks in the string s be k. Let's replace each question mark with one of the letters "a", "b" and "c". Here we can obtain all 3^{k} possible strings consisting only of letters "a", "b" and...
3
import os from sys import stdin, stdout class Input: def __init__(self): self.it = iter(stdin.readlines()) def line(self): return next(self.it).strip() def array(self, sep = ' ', cast = int): return list(map(cast, self.line().split(sep = sep))) def testcases(unknown = Fal...
You are given an array a[0 … n-1] of length n which consists of non-negative integers. Note that array indices start from zero. An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all i (0 ≤ i ≤ n - 1) the equality i mod 2 = a[i] m...
3
def main(): for _ in range(int(input())): n=int(input()) ar=list(map(int,input().split())) neven=nodd=0 for i in ar: if i%2==0:neven+=1 else:nodd+=1 if n%2==0 and neven!=nodd:print(-1) elif n%2==1 and (neven-nodd)!=1:print(-1) else: ...
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
weight = int(input()) if weight > 2 and weight % 2 == 0: print("YES") else: print("NO")
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr...
3
def main(): segments = [list(map(int, input().split())) for _ in range(4)] start = (segments[0][0], segments[0][1]) point = (segments[0][2], segments[0][3]) points = set() points.add(start) points.add(point) coords = [set(), set()] coords[0].add(point[0]) coords[0].add(start[0]) ...
[Thanos sort](https://codegolf.stackexchange.com/questions/182221/implement-the-thanos-sorting-algorithm) is a supervillain sorting algorithm, which works as follows: if the array is not sorted, snap your fingers* to remove the first or the second half of the items, and repeat the process. Given an input array, what i...
3
#mudit #Import libraries here. #import math #Required for divisorsof def intinputlist(): #Take input in one line as list of int l = [int(x) for x in input().split()] return l def printlist(l): #Prints list in a single line with spaces print(*l) def power(x,y,p): #Calculates (x**y)%p in O(log ...
Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level. All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases...
3
def main(): for _ in range(int(input())): result = True pp = 0 cc = 0 for i in range(int(input())): p, c = map(int, input().split()) if result: dif_p = p - pp dif_c = c - cc if dif_p < 0 or dif_c < 0 or dif_c > dif_p: result = False else: pp = p cc = c print('YES' if re...
You are given a permutation p_1, p_2, ..., p_n. Recall that sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once. Find three indices i, j and k such that: * 1 ≤ i < j < k ≤ n; * p_i < p_j and p_j > p_k. Or say that there are no such indices. Input The first lin...
3
""" Created on Mon Jul 6 21:28:12 2020 @author: rishi """ import math def sumofno(n): summ=0 while(n>0): summ+=n%10 n//=10 return summ def get_key(val,lis): for key, value in lis.items(): if value == val : return key try: t=int(input()) ans=[] ...
Vasya has his favourite number n. He wants to split it to some non-zero digits. It means, that he wants to choose some digits d_1, d_2, …, d_k, such that 1 ≤ d_i ≤ 9 for all i and d_1 + d_2 + … + d_k = n. Vasya likes beauty in everything, so he wants to find any solution with the minimal possible number of different d...
3
n = int(input()) print (n,"1 "*n, sep = "\n")
One beautiful day Vasily the bear painted 2m circles of the same radius R on a coordinate plane. Circles with numbers from 1 to m had centers at points (2R - R, 0), (4R - R, 0), ..., (2Rm - R, 0), respectively. Circles with numbers from m + 1 to 2m had centers at points (2R - R, 2R), (4R - R, 2R), ..., (2Rm - R, 2R), r...
3
m, r = map(int, input().split()) print(2 * r * (m + (2 + 2 ** 0.5) * (m - 1) + (m - 1) * (m - 2) * (m / 3 + 2 ** 0.5)) / (m * m))
You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1...
3
x = input() y = input() z = "" fault = False for i in range(0, len(x)): if ord(y[i]) > ord(x[i]): fault = True break if fault == True: print(-1) else: print(y)
There is a special offer in Vasya's favourite supermarket: if the customer buys a chocolate bars, he or she may take b additional bars for free. This special offer can be used any number of times. Vasya currently has s roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs c roubles. He...
3
n = int(input()) for i in range(n): s, a, b, c = map(int, input().split()) ans = s // c + (s // c) // a * b print(ans)
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system. You are given user's friends' opinions about a list of items. You are also given a threshold T — the minimal number of "likes" necessary for an item to be r...
3
F,I,T=map(int,input().split()) a=[0]*F for i in range(F): a[i]=input() b=0 for i in range(I): sum=0 for j in range(F): sum+=(a[j][i]=='Y') b+=(sum>=T) print(b) #kitten