problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurre...
3
n = int(input()) a = list(map(int, input().split())) for elem in a: if elem % 2 == 0: elem -= 1 print(elem, end=" ")
Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≀ a, b, c, d ≀ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8). Input ...
1
import sys def f(a,b,c): if b==1:return 1 x=sum([f(e,b-1,c-9)for e in range(max(0,a-9),min(a,c)+1)]) return x for n in sys.stdin:print f(int(n),4,3*9)
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 cases in range(int(input())): n,m= list(map(int, input().split())) lst1 = list(map(int, input().split())) lst2 = list(map(int, input().split())) count = 0 for i in range(n-1, -1, -1): if lst1[i] in lst2: count = lst1[i] print("YES") print("1", count) ...
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls and m baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to m, correspondingly. The ...
3
n, m = map(int, input().split()) k = (m + 1) // 2 t = [k] * m d = m % 2 for i, j in enumerate(range(1 + d, m, 2), 1): t[j] += i for i, j in enumerate(range(2 - d, m, 2), 1): t[j] -= i t = (((n - 1) // m + 1) * t)[: n] print('\n'.join(map(str, t)))
Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following ope...
1
n,m=map(int,raw_input().split()) at,de,st=[],[],[] for i in xrange(0,n): x,s=raw_input().split() s=int(s) if (x=='ATK'): at.append(s) else: de.append(s) for i in xrange(0,m): st.append(int(raw_input())) vi=[1]*(len(st)) at.sort() de.sort() st.sort() ans=0 for i in xrange(1,len(st)+1): if (i>len(at)): break At,St...
You are given an array of n integers a_1,a_2,...,a_n. You have to create an array of n integers b_1,b_2,...,b_n such that: * The array b is a rearrangement of the array a, that is, it contains the same values and each value appears the same number of times in the two arrays. In other words, the multisets \\{a_1,a_...
3
for t in range(int(input())): n = int(input()) l = list(map(int, input().split())) if sum(l) == 0: print("NO") elif sum(l) > 0: print("YES\n"+" ".join(list(map(str, sorted(l)[::-1])))) else: print("YES\n"+" ".join(list(map(str, sorted(l)))))
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>. You are given two integers A and B, calculate the number of pairs (a, b) such that 1 ≀ a ≀ A, 1 ≀ b ≀ B, and the equation a β‹… b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11)...
3
t = int(input()) while t: t -= 1 ans = 0 a, b = map(int, input().split()) k = 9 while k <= b: ans += a k = k * 10 + 9 print(ans)
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve...
3
a,b=map(int,input().split()) if a==b: print(a) else: print("2")
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland). ...
3
n = int(input()); li = list(map(int, input().split())); li.sort(); diff = li[-1]; s = 0; if n == 1: print(0) else: for i in range(len(li)): s += diff - li[i]; print(s)
There are n athletes in front of you. Athletes are numbered from 1 to n from left to right. You know the strength of each athlete β€” the athlete number i has the strength s_i. You want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team. You want...
3
t = int(input()) for i in range(t): c = 10**9+1 n = int(input()) s = [int(i) for i in input().split()] s.sort() for i in range(n-1): c = min(c,(s[i+1]-s[i])) print(c)
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
3
_1 = '236a' # count = 0 # l = [list(map(int, input().split())) for i in range(5)] # for i in range(5): # for j in range(5): # if l[i][j] == 1: # # if i > 2: # count += i - 2 # elif i < 2: # count += 2 - i # if j > 2: # count...
You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? D...
3
import copy if __name__ == '__main__': n, k = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] arr_copy = copy.deepcopy(arr) arr.sort() if k == 1: print(arr[0]) elif k >= 3: print(arr[-1]) else: print(max(arr_copy[0], arr_copy[-1]))
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so...
3
n, m = [int(x) for x in input().split()] s = 0 while(n < m): s += 1 + (m % 2) m = (m + m % 2) // 2 print(s + n - m)
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s. You have to answer t independent test cases. Input The first line of the input co...
3
for ad in range(int(input())): n,s=list(map(int,input().split())) x=list(str(n)) x=list(map(int,x)) add=sum(x) if add<=s: print(0) else: ans="" t=0 c=0 for i in range(len(x)): if c+x[i]<s and t==0: c+=x[i] elif t==1...
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 = [int(i) for i in input().split()] print((n//x) * x + y if (n//x) * x + y <= n else (n//x - 1) * x + y)
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number nΒ·m + 1 is a prime number". Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Co...
3
# =============================================================================================== # importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase from itertools import * import bisect from heapq import ...
Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the ...
3
n,l=map(int,input().split()) lantern=[int(x) for x in input().split()] lantern.sort() dmax=0 for i in range(len(lantern)-1): if lantern[i+1]-lantern[i]>dmax: dmax=lantern[i+1]-lantern[i] dmax=max(lantern[0],l-lantern[n-1],dmax/2) print("{:.10f}".format(dmax) )
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes conta...
3
N,x = map(int,input().split()) A = list(map(int,input().split())) ans = 0 ans += max(0,A[0]-x) A[0] -= max(0,A[0]-x) for i in range(N-1) : ans += max(0,A[i]+A[i+1]-x) A[i+1] -= max(0,A[i]+A[i+1]-x) print(ans)
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddl...
3
# -*- coding: utf-8 -*- """ Created on Mon Nov 25 13:53:02 2019 @author: Selene """ [n,m]=[int(x) for x in input().split()] o=99999 l=[int(x) for x in input().split()] l.sort() for i in range(m-n+1): if l[i+n-1]-l[i]<o: o=l[i+n-1]-l[i] print(o)
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check ...
1
num = raw_input() g_c = 0 alk = ["ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"] for t in range(int(num)): k = raw_input() try: if int(k)<18: g_c+=1 except ValueError: if k in alk: g_c+=1 print g_c
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests! Heidi designed a series of increasingly difficult tasks for them to spend the...
3
def find_inside_point(points, maxx, minx, maxy, miny): # print('inside point') for x, y in points: if minx < x < maxx and miny < y < maxy: print(x, y) return def find_outside_point(points, maxx, minx, maxy, miny): # print('outside point') maxx_points = [ (x, y) for x, y...
Print the circumference of a circle of radius R. Constraints * 1 \leq R \leq 100 * All values in input are integers. Input Input is given from Standard Input in the following format: R Output Print the circumference of the circle. Your output is considered correct if and only if its absolute or relative error ...
3
print(int(input()) * 3.14159*2)
Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid algorithm. Formally, find the biggest integer d, such that all int...
3
a, b = [i for i in input().split()] if a==b: print(a) else: print(1)
There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is empty. In the beginning, Snuke stands on Square A, and Fnuke stand...
3
N, A, B, C, D = map(lambda x: int(x)-1, input().split()) L = input() reachable = not ("##" in L[A:C+1] or "##" in L[B:D+1]) interupt = "..." in L[B-1:D+2] if reachable and (C < D or interupt): print("Yes") else: print("No")
Ivan is going to sleep now and wants to set his alarm clock. There will be many necessary events tomorrow, the i-th of them will start during the x_i-th minute. Ivan doesn't want to skip any of the events, so he has to set his alarm clock in such a way that it rings during minutes x_1, x_2, ..., x_n, so he will be awak...
1
from sys import stdin from functools import reduce from fractions import gcd rint = lambda: int(stdin.readline()) rints = lambda: [int(x) for x in stdin.readline().split()] rint_2d = lambda n: [rint() for _ in range(n)] rints_2d = lambda n: [rints() for _ in range(n)] n, m = rints() x, p = rints(), rints() g = reduce...
Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle ...
3
from collections import defaultdict n = int(input()) a = [] b = [] for _ in range(n): x,y = map(int,input().split()) a.append(x) b.append(y) s = set() for i in range(n): for j in range(n): if b[j]==a[i] and i!=j: s.add(i) print(n-len(s))
Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets deleted from the string and the remaining parts of the string get concatenated....
3
from sys import stdin,stdout for _ in range(int(stdin.readline())): # n=int(stdin.readline()) # x1,y1,x2,y2=list(map(int,stdin.readline().split())) s=input() q=[];p=0 for ch in s: if p==0: q+=[ch] p+=1 else: if q[p-1]+ch in ['AB','BB']: ...
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation). Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after...
3
q=int(input()) for i in range (0,q): n=int(input()) p=[int(x) for x in input().split()] if n<=3: print('YES') else: q=[0]*n for i in range (0,n-1): q[i]=p[i+1]-p[i] q[n-1]=p[0]-p[n-1] if q.count(1)==n-1 or q.count(-1)==n-1: print('YES')...
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" β€” three distinct two-grams. You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of ...
1
n = int(raw_input()) s = list(raw_input()) l = list() d = dict() for i in range(n): if i+1 < n: l.append(s[i]+s[i+1]) l2 = list() for i in range(len(l)): if(l[i] not in l2): l2.append(l[i]) mayor = -1 for i in range(len(l2)): cantidad = l.count(l2[i]) if mayor <= cantidad: k = l2[i] mayor = cantidad ...
There are H rows and W columns of white square cells. You will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns. How many white cells will remain? It can be proved that this count does not depend on what rows and columns are chosen. Constraints * All values i...
3
H,W = map(int, input().split()) y,x = map(int, input().split()) print((H-y)*(W-x))
Ashish has a tree consisting of n nodes numbered 1 to n rooted at node 1. The i-th node in the tree has a cost a_i, and binary digit b_i is written in it. He wants to have binary digit c_i written in the i-th node in the end. To achieve this, he can perform the following operation any number of times: * Select any...
3
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase from copy import deepcopy def main(): n = int(input()) prop = [0]+[tuple(map(int,input().split())) for _ in range(n)] path = [[] for _ in range(n+1)] for _ in range(n-1): u1,v1 = map(int,in...
Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present β€” the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to d. It is guaranteed that ai ≀ d for all i from 1 to n. The clock does not keep information ab...
1
d = input() n = input() a = map(int, raw_input().split()) t = a[0] z = 0 for i in range(1, n): z += d-t t = a[i] print z
There is a robot in a warehouse and n packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0, 0). The i-th package is at the point (x_i, y_i). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point ...
3
import math x = list(map(int, input().split())) y = [] for i in range(0,x[0]): a = int(input()) y.append([]) for j in range(0,a): y[i].append(list(map(int, input().split()))) for i in range(0,x[0]): mx = [] mn = [] for j in range(0,1001): mx.append(-1) mn.append(2000) ...
Johnny needs to make a rectangular box for his physics class project. He has bought P cm of wire and S cm^2 of special paper. He would like to use all the wire (for the 12 edges) and paper (for the 6 sides) to make the box. What is the largest volume of the box that Johnny can make? Input The first line contains t, th...
1
test_case = int(raw_input()) for t in range(test_case): p, s = map(float, raw_input().split()) a1 = (p+ (p**2 - 24*s)**0.5)/12.0 a2 = (p- (p**2 - 24*s)**0.5)/12.0 print "%.2f"%round(max( s*a1/2 - p*a1*a1/4 + a1*a1*a1, s*a2/2 - p*a2*a2/4 + a2*a2*a2), 2) ## print fixed digits after decimal
Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC2 (Handbook of Crazy Constructions) and looks for the right chapter: How to build a wall: 1. Take a set of bricks. 2. Select one of the possibl...
3
result=0 mod=10**6 +3 n,C=map(int,input().split()) def fact(n): fact=1 for i in range(1,n+1): fact=(fact*i)%mod return fact def pow(a,b): p=1 for i in range(b): p=(a*p)% mod return p result=fact(n+C)*pow(fact(n),mod-2)*pow(fact(C),mod-2)-1 print(int(result%mod))
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 = input("") list = [] gCount = 0 lCount = 0 for linesCount in range(int(n)): line = input("") lineEles = line.split() for ele in lineEles: if ele=="1": lCount+=1 if lCount>=2: gCount+=1 lCount=0 print(gCount)
Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at the node 1 and he records 1 on his notebook. He can wander from one node to another through those bidirectional edges. Whenever ...
3
from heapq import heappush, heappop n, m = map(int, input().split()) E = [[] for _ in range(n)] for i in range(m): a, b = map(int, input().split()) E[a - 1].append(b - 1) E[b - 1].append(a - 1) Q = [] now = 0 heappush(Q,0) vis = [1] * n vis[0] = 0 while len(Q) > 0: now = heappop(Q) print(now + 1, en...
You have n students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the i-th student skill is denoted by an integer a_i (different students can have the same skills). So, about the teams. Firstly, these two teams should have the s...
3
t = int(input()) for q in range(t): n = int(input()) mas = list(map(int, input().split())) s = set(mas) cou = [] for i in range(n + 1): cou.append(0) for i in mas: cou[i] += 1 maxi = max(cou) if maxi == len(s): print(maxi - 1) else: print(min(len(s), maxi))
Another Codeforces Round has just finished! It has gathered n participants, and according to the results, the expected rating change of participant i is a_i. These rating changes are perfectly balanced β€” their sum is equal to 0. Unfortunately, due to minor technical glitches, the round is declared semi-rated. It means...
1
n = int(raw_input()) a = [int(raw_input()) for _ in xrange(n)] b = [x / 2 for x in a] s = sum(b) for i in xrange(n): if a[i] % 2 and s < 0: b[i] += 1 s += 1 for x in b: print x
You have two integers l and r. Find an integer x which satisfies the conditions below: * l ≀ x ≀ r. * All digits of x are different. If there are multiple answers, print any of them. Input The first line contains two integers l and r (1 ≀ l ≀ r ≀ 10^{5}). Output If an answer exists, print any of them. Oth...
3
def ok(n): cnt = [0 for i in range(10)] while n > 0: if cnt[n % 10] > 0: return False cnt[n % 10] += 1 n //= 10 return True def solve(test): ans = -1 l, r = map(int, input().split()) for i in range(l, r + 1): if ok(i): ans = i print(an...
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
def main(): n = int(input()) ans = 0 for i in range(n): v = [int(i) for i in input().split(' ')] if sum(v) > 1: ans += 1 print(ans) if __name__ == "__main__": main()
Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible diverse words in lexicographical order. A word is called diverse if and only if it is a nonempty string of English lowercase...
3
# ε†™η΅Œ#2284578 S = input() alp = "abcdefghijklmnopqrstuvwxyz" def h(string, least = 'Z'): for c in alp: if c not in string: if c <= least: continue return string + c if string == "": return "-1" return h(string[:-1], string[-1]) print(h(S))
Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room. Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed...
3
n=int(input()) list1=[] ls=[] for i in range(n): c,x=input().strip().split(' ') c,x=(str(c),int(x)) list1.append([c,x]) ls.append(x) de=[] for i in range(n): if list1[i][0]=='-': if list1[i][1] not in ls[0:i]: de.append(list1[i][1]) #print(de) lmax=len(de) for i in range(n): ...
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ...
3
import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(int, tinput()) def rlinput(): return list(rinput()) n,k = rinput() A = rlinput() ans = [] index = 0 for i in range(k): cur...
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 = input().split(" ") a = int(a) b = int(b) c = int(c) lis = [a,b,c] len_lis = [] for i in range(max(lis)): da = abs(a-(i+1)) db = abs(b-(i+1)) dc = abs(c-(i+1)) len_lis.append(int(da+db+dc)) print(min(len_lis))
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. I...
3
""" Author: Ove Bepari _nnnn_ dGGGGMMb ,''''''''''''''''''''''. @p~qp~~qMb | Promoting GNU/Linux | M|@||@) M| _;......................' @,----.JM| -' JS^\__/ qKL dZP qKRb dZP qKKb fZP SMMb HZM ...
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation). Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after...
3
q = int(input()) n = [] table_pos = [] for i in range(q): n.append(int(input())) table_pos.append(list(map(int , input().split()))) for j in range(q): Check_clock = 1 Check_anticlock = 1 temp = 1 count = n[j] table = table_pos[j] x = table.index(1) if(x == count-1): f...
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). Constraints * 1 \leq N \leq 10^4 * 1 \leq A \leq B \leq 36 * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print the s...
3
n,a,b=map(int,input().split()) t=0 for i in range(1,n+1): s=sum(list(map(int,list(str(i))))) if a<=s and s<=b: t+=i print(t)
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." β€” an excerpt from contest rules. A total of n participants took part in the contest (n β‰₯ k), and you already know their scores. Calculate how many ...
3
n, k = [int(x) for x in input().split()] b = [int(x) for x in input().split()] out = 0 passing = b[k-1] for i in range(n): s = b[i] if s >= passing and s>0: out += 1 print(out)
Maxim wants to buy some games at the local game shop. There are n games in the shop, the i-th game costs c_i. Maxim has a wallet which can be represented as an array of integers. His wallet contains m bills, the j-th bill has value a_j. Games in the shop are ordered from left to right, Maxim tries to buy every game i...
3
n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) k = 0 cnt = 0 for i in range(len(a)): if len(b) == k: break if b[k] >= a[i]: cnt += 1 k += 1 print(cnt)
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
import sys,heapq printn = lambda x: sys.stdout.write(x) DBG = not True def ddprint(x): if DBG: print(x) n,k = map(int, input().split()) t = [] b = [] a = [] for i in range(n): ti,bi = map(int, input().split()) #t.append(ti) #b.append(bi) a.append((ti,bi)) a.sort(key=lambda x: -x[1]) dd...
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 i in range(n): a=str(input()) if(len(a)<=10): print(a) else: for k in range(2,len(a)-1): q=0 q=q+k print(a[0],q,a[-1],sep="")
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their h...
3
#n = map(int,input().split()) n = int(input()) a = input().split() b = [int(c) for c in a] minimum = min(b) maximum = max(b) def duplicates(lst, item): return [i for i, x in enumerate(lst) if x == item] minimum_index=duplicates(b, minimum) maximum_index=duplicates(b, maximum) low = min(maximum_index)-0; high = len(...
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer ...
3
data = [2, 3, 5, 7] n = int(input()) help = 0 for i in range(4): for j in range(4): if j > i: help += n // (data[i] * data[j]) print(n - (n // 2 + n // 3 + n // 5 + n // 7 - help + n // (2 * 3 * 5) + n // (2 * 3 * 7) + n // (5 * 7 * 3) + n // (5 * 7 * 2) - n // (2 * 3 * 5 * 7)))
Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties... Most of the young explorer...
3
import math as mt import sys,string input=sys.stdin.readline from collections import defaultdict L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) t=I() for _ in range(t): n=I() l=L() d=defaultdict(int) for i in l: ...
We call two numbers x and y similar if they have the same parity (the same remainder when divided by 2), or if |x-y|=1. For example, in each of the pairs (2, 6), (4, 3), (11, 7), the numbers are similar to each other, and in the pairs (1, 4), (3, 12), they are not. You are given an array a of n (n is even) positive in...
3
t= int(input()) while(t>0): n= int(input()) inp=input().split() a=[int(i) for i in inp] chan=le=0 for i in a: if i%2==0: chan+=1 if(chan%2 ==0): print("YES") else: check=0 for i in range(0,n-1): for j in range(i+1,n): if...
Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0. On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly 2...
3
import sys import math import collections from collections import deque #sys.stdin = open('input.txt', 'r') #sys.stdout = open('output.txt', 'w') from functools import reduce from sys import stdin, stdout, setrecursionlimit setrecursionlimit(2**20) def factors(n): return list(set(reduce(list.__add__, ...
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of ea...
3
n=int(input()); print(sum(list(map(int,input().split())))/n)
Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Multiset C contains all sums a + b such that a belongs to A and b belongs to B...
1
from sys import stdin n,test=map(int,stdin.readline().split()) for i in xrange(test): num=int(stdin.readline()) if num>=n+2 and num<=3*n: print n-abs(num-2*n-1) else: print 0
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on al...
3
n=int(input()) t={} class node(object): """docstring for node""" def __init__(self): self.vois = [] def insv(self,voi): self.vois.append(voi) for i in range(1,n+1): t[i]=node() for i in range(n-1): u,v=map(int,input().split()) t[u].insv(v) t[v].insv(u) for i in range(1,n+1): if len(t[i].vois)==2: print...
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number nΒ·m + 1 is a prime number". Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Co...
3
import sys n = int(sys.stdin.readline().strip()) if n == 1: print (3) elif n == 2: print (4) elif n>2 and n%2 == 1: print (1) elif n>2 and n%2 == 0: print (n-2)
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
m,n=map(int,input().split()) area=m*n print(area//2)
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
t=int(input()) for i in range(t): a,b=map(int,input().split()) m=min(a,b) if(2*m>=max(a,b)): print((2*m)**2) else: print((max(a,b))**2)
You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” length of the array a. The second line contains...
1
n = int(raw_input()) a = map(int, raw_input().split(' ')) dist = [999999] * n for i in range(n): if a[i] == 0: dist[i] = 0 #Propagate left and right until the next zero l, off = i-1, 1 while l >= 0 and a[l] != 0: dist[l] = min(dist[l], off) off += 1 l -= 1 r, off = i+1, 1 while r < n and a[r] !=...
You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a self-loop is an edge where a_i = b_i (1≀i≀M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≀i<j≀M). How many different paths start from vertex 1 and vi...
3
import itertools N, M = map(int, input().split()) edges = {tuple(sorted(map(int, input().split()))) for _ in range(M)} answer = 0 for pattern in itertools.permutations(range(2, N+1), N-1): l = [1] + list(pattern) answer += sum(1 for edge in zip(l, l[1:]) if tuple(sorted(edge)) in edges)==N-1 print(answer)
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ...
3
d={} input() for i in map(int,input().split()):d[i]=1+d.get(i,0) print(max(d.values()),len(d))
There are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a permutation). Students want to start a round dance. A clockwise round dance can be started if the student 2 comes right after...
3
for i in range(int(input())): a = int(input()) x = [int(x) for x in input().split()] x.extend(x) c = n = d = 1 for i in range(len(x) - 1): if x[i] < x[i + 1]: c += 1 n = 1 if c >= a: print('YES') d = 2 break...
Write a program of the Bubble Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array ...
3
n=int(input()) a=list(map(int,input().split())) c=0 f=True while f: f=False for j in range(n-1,0,-1): if a[j]<a[j-1]: a[j],a[j-1]=a[j-1],a[j] c+=1 f=True print(*a) print(c)
You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≀ x ≀ r_i, and ((x mod a) mod b) β‰  ((x mod b) mod a). Calculate the answer for each query. Recall that y mod z is the remainder of the division of y by z...
1
""" // Author : snape_here - Susanta Mukherjee """ from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(...
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
d = input() a = sorted(list(map(int,input().split()))) b = len(a) c = sum(a) output = 0 numberOfCoins = 0 while output<=sum(a): output += a[-1] numberOfCoins +=1 a.remove(a[-1]) print(numberOfCoins)
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with number...
3
x = int(input()) li = list(map(int, input().split())) y = int(input()) li1 = list(map(int, input().split())) li2 = [] for i in range(x): li2 += [i+1]*li[i] for i in li1 : print(li2[i-1])
Let w be a string consisting of lowercase letters. We will call w beautiful if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful. Constraints * 1 \leq |w| \leq 100 * w consists of lowercas...
3
w=input() for i in w: if w.count(i)%2==0: continue else: print("No") exit() print("Yes")
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of ...
3
lst =list(input()) if("0" not in lst): print("".join(lst[1:])) exit() for i in range(len(lst)): if(lst[i] == "0"): k = i break z = "" del(lst[lst.index(lst[k])]) print("".join(lst))
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
t=int(input()) for _ in range(t): a,b=map(int,input().split()) if(abs(a-b)>min(a,b)): print((max(a,b))**2) else: print((min(a,b)*2)**2)
Masha has n types of tiles of size 2 Γ— 2. Each cell of the tile contains one integer. Masha has an infinite number of tiles of each type. Masha decides to construct the square of size m Γ— m consisting of the given tiles. This square also has to be a symmetric with respect to the main diagonal matrix, and each cell of ...
3
t = int(input()) for i in range(t): arr = [int(x) for x in input().split()] n, m = arr[0], arr[1] arr = [] for j in range(n): arr_1 = [int(x) for x in input().split()] + [int(x) for x in input().split()] arr += [arr_1] if m <= 0 or m % 2 != 0: print('NO') else: f ...
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o...
3
a,x,y,z=map(int,input().split()) n=list(input()) l=len(n) sum=0 for i in range(l): if(n[i]=='1'): sum+=a elif(n[i]=='2'): sum+=x elif(n[i]=='3'): sum+=y else: sum+=z print(sum)
RedDreamer has an array a consisting of n non-negative integers, and an unlucky integer T. Let's denote the misfortune of array b having length m as f(b) β€” the number of pairs of integers (i, j) such that 1 ≀ i < j ≀ m and b_i + b_j = T. RedDreamer has to paint each element of a into one of two colors, white and black...
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...
A class of students wrote a multiple-choice test. There are n students in the class. The test had m questions, each of them had 5 possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question i worth a_i points. Incorrect answers are graded with zero points....
3
#code def keywithmaxval(d): v=list(d.values()) k=list(d.keys()) return k[v.index(max(v))] inp = input().split() n = int(inp[0]) m = int(inp[1]) ans = [] l = [] for i in range(m): dic = dict.fromkeys(['A','B','C','D','E'], 0) l.append(dic) for n0 in range(n): s = input() for i in ran...
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: * f(0) = a; * f(1) = b; * f(n) = f(n-1) βŠ• f(n-2) when n > 1, where βŠ• de...
3
n=int(input()) for i in range(0,n): p=input().rstrip().split(' ') a=int(p[0]) b=int(p[1]) c=int(p[0])^int(p[1]) if int(p[2])==0: print(a) elif int(p[2])==1: print(b) else: if int(p[2])%3==0: print(a) elif int(p[2])%3==1: print(b) ...
Let's denote correct match equation (we will denote it as CME) an equation a + b = c there all integers a, b and c are greater than zero. For example, equations 2 + 2 = 4 (||+||=||||) and 1 + 2 = 3 (|+||=|||) are CME but equations 1 + 2 = 4 (|+||=||||), 2 + 2 = 3 (||+||=|||), and 0 + 1 = 1 (+|=|) are not. Now, you ha...
3
q = int(input()) for _ in range(q): n = int(input()) if n == 2: print(2) elif n % 2 == 1: print(1) else: print(0)
The Little Elephant loves sortings. He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≀ l ≀ r ≀ n) and increase ai by 1 for all i such that l ≀ i ...
3
n = int(input()) l = list(map(int, input().split())) res = 0 for i in range(n -1): res += max(0, l[i] - l[i+1]) print(res)
Denis was very sad after Nastya rejected him. So he decided to walk through the gateways to have some fun. And luck smiled at him! When he entered the first courtyard, he met a strange man who was selling something. Denis bought a mysterious item and it was... Random permutation generator! Denis could not believed hi...
3
t = int(input()) for dobpt in range(t): n = int(input()) p = list(map(int, input().split())) answer = "Yes" for i in range(n - 1): if p[i + 1] > p[i] and p[i + 1] != p[i] + 1: answer = "No" print(answer)
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
a = int(input()) b = [i for i in input()] i = 0 while i < a: if i + 2 < a and b[i] == "o" and b[i+1] == "g" and b[i+2] == "o": k = 0 while i + 2 < a and b[i+1] == "g" and b[i+2] == "o": i += 2 if k == 0: print("***", end="") k = 1 else: ...
You are given a number k and a string s of length n, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met: * The first character '*' in the original string should be replaced with 'x'; * The last character '*' in the...
3
T = int(input()) for t in range(T): n, k = [int(ea) for ea in input().split(' ')] s = list(input()) # Set leftmost i = 0 while True: if s[i] == '*': s[i] = 'x' break i += 1 # Set rightmost j = len(s) - 1 alreadyValid = False while True: ...
Takahashi has N days of summer vacation. His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment. He cannot do multiple assignments on the same day, or hang out on a day he does an assignment. What is the maximum number of days Takahashi can hang out during the vacation if ...
3
N , M = map(int,input().split()) A = list(map(int,input().split())) S = sum(A) print(max(-1, N-S))
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. Input The first line contai...
3
n = int(input()) m = int(input()) A = list(map(int, [input() for i in range(n)])) A.sort(reverse=True) ans = 0 sum = 0 for i in range(n): ans += 1 sum += A[i] if sum >= m: break; print(ans)
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
import sys l,r = map(int, sys.stdin.readline().split()) sys.stdout.write("YES\n") for i in range(l,r,2): sys.stdout.write(f"{i} {i+1}\n")
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied: * If A_i and A_j (i < j) are painted with the same color, A_i < A_j. Find the minimum number of col...
3
#17:21 from collections import deque import bisect n = int(input()) now = deque() for _ in range(n): tmp = int(input()) b = bisect.bisect_left(now,tmp) if b != 0: now[b-1] = tmp else: now.appendleft(tmp) print(len(now))
Anton likes to play chess, and so does his friend Danik. Once they have played n games in a row. For each game it's known who was the winner β€” Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. Input The first line of the input contains a...
3
n = int(input()) s = input() As =s.count('A') Bs =s.count('D') if As>Bs: print("Anton") elif Bs>As: print("Danik") else: print("Friendship")
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: ...
1
for i in range(input()): n=input("") v=(-1+((24*n)+1)**0.5)/6 def value(k): return (3*(k**2)+k)/2 def backp(n): return int((-1+((24*n)+1)**0.5)/6) ans=0 if n==1: print 0 elif int((v*10))==v*10: print 1 else: while True: #print n,ba...
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rec...
3
t = int(input()) for _ in range(t): a1,b1 = list(map(int,input().split())) a2,b2 = list(map(int,input().split())) s = min(a1,b1)+min(a2,b2) if s == max(a1,b1)==max(a2,b2): print("Yes") else: print("No")
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
n=int(input()) l=list(map(int, input().split(' '))) ans=0 for i in range(1, n-1): if l[i]%2!=l[i-1]%2 and l[i]%2!=l[i+1]%2: ans=i+1 if ans==0: if (l[0]+l[1])%2!=0: ans=1 else: ans=n print(ans)
Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has n objects (we will consider the objects indexed in some way by integers from 1 to n), each obje...
1
def main(): n = int(raw_input()) Ts = [0] + map(int, raw_input().split()) As = [0] + map(int, raw_input().split()) counts = {} for i in range(0, n + 1): counts[i] = 0 for i in range(1, n + 1): a = As[i] counts[a] += 1 many = set([]) for i in range(1, n + 1): ...
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy. Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D e...
3
[N,M,K] = input().split(' ') N = eval(N) M = eval(M) K = eval(K) if K < N: print(str(K+1)+" 1") else: K -= N DX = K // (M - 1) DY = K % (M + M - 2) #print(DY) if DY >= M - 1: DY = 2 * M - 2 - DY - 1 print(str(N - DX) +" "+ str(DY + 2))
Alice and Bob are decorating a Christmas Tree. Alice wants only 3 types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have y yellow ornaments, b blue ornaments and r red ornaments. In Bob's opinion, a Christmas Tree will be beautiful if: * the number of blue ornaments used is greater b...
3
def main(): list_of_obj = [int(i) for i in input().split()] yellow = list_of_obj[0] blue = list_of_obj[1] red = list_of_obj[2] for i in range(red, 0, -1): if yellow >= i - 2 and blue >= i - 1: print(3*i - 3) break if __name__ == "__main__": main...
You invited n guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles. Your guests happen to be a little bit shy, so the i-th guest wants to have a least l_i free chairs to the left of his chair, and a...
3
guests = int(input()) chairs = 0 right = [] left = [] for i in range(guests): r, l = (int(x) for x in input().split()) right.append(r) left.append(l) right = sorted(right) left = sorted(left) for i in range(guests): chairs += max(right[i], left[i]) print(chairs + guests)
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of ea...
3
n = int(input("")) l = [] k = 0 l = list(map(int, input("").split())) for i in range(n): k+= (int(l[i])/100) z = (k/n)*100 print(z)
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
inp=int(input('')) lista=[] for i in range(inp): inpx=input('') lista.append(inpx) x=0 for i in lista : if '+' in i : x+=1 else : x-=1 print(x)
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
def Digits(n): largest = 0 smallest = 9 while (n): r = n % 10 largest = max(r, largest) smallest = min(r, smallest) n = n // 10 return smallest,largest t=int(input()) while(t): t-=1 a,k = [int(i) for i in input().split()] for i in range (k-1): sm,...
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be n problems. The i-th problem has initial score pi and it takes exactly ti minutes to solve it. Problems are sorted by difficulty β€” it'...
3
n, c = map(int, input().split()) score = list(map(int, input().split())) times = list(map(int, input().split())) rS = 0 lS = 0 rT = 0 lT = 0 for i in range(n): rT += times[i] rS += max(0, score[i] - rT * c) lT += times[n - 1 - i] lS += max(0, score[n - 1 - i] - lT * c) if rS < lS: print("Radewoos...