problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
We have a string S of length N consisting of uppercase English letters. How many times does `ABC` occur in S as contiguous subsequences (see Sample Inputs and Outputs)? Constraints * 3 \leq N \leq 50 * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: N S ...
3
N=int(input()) S=input() b=S.count('ABC') print(b)
There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a_1, a_2, ..., a_n, where a_i = 1 if in the i-th flat the light is on and a_i = 0 otherwise. Vova thinks that people in the i-th flats are distur...
3
n=int(input()) a=[int(i) for i in input().split()] ans=0 for i in range(1,n-1): if(a[i]==0 and a[i-1]==1 and a[i+1]==1): a[i+1]=0 ans+=1 print(ans)
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it. Constraints * The length of S is 2 or 3. * S consists of lowercase English letters. Input Input is given from Standard Input i...
3
s=input();print(s if len(s)<3 else s[::-1])
Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n × n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≤ i, j ≤ n. We define a cross appearing in the i-th row and the j-th column (1 < i...
3
n=int(input()) a=[] cnt=0 for i in range(n): a.append(input()) for i in range(1,n-1): for j in range(1,n-1): if a[i][j]==a[i-1][j-1]==a[i+1][j+1]==a[i-1][j+1]==a[i+1][j-1]=="X": cnt+=1 print(cnt)
Panic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive. The committee rules strictly prohibit even the smallest diversity between dog...
3
from collections import Counter n=int(input()) dog=input() p=Counter(dog) ans="NO" if n == 1: print("YES") else: for i in range(n): if p[dog[i]] > 1: ans="YES" break print(ans)
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ...
3
s = input () L = len( s ) D = 0 cnt = 0 for i in range ( 0 , L ) : if s[i] =='A' or s[i] =='E' or s[i] =='I' or s[i] =='O' or s[i] =='U' or s[i] =='Y': cnt = max ( cnt , D ) D = 0 else : D +=1 ; cnt = max ( cnt , D ) print( cnt+1 )
You are given an array a_1, a_2, ... , a_n. Array is good if for each pair of indexes i < j the condition j - a_j ≠ i - a_i holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option). For example, if a = [1, 1, ...
3
def sd(a): return a[::-1] t = int(input()) for i in range(t): n = int(input()) A = list(map(int, input().split())) A.sort() A = sd(A) print(*A)
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix s...
3
def diff(l1, l2): a1 = sorted(l1) a2 = sorted(l2) for i in range(len(a2)): if a1[i] != a2[i]: return a1[i] return a1[-1] n = int(input()) I = lambda: list(map(int, input().split())) a, b, c = I(), I(), I() print(diff(a, b)) print(diff(b, c))
For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for? Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got ...
3
T = int(input()) res = list() for i in range(T): n = int(input()) x = list(map(int, input().split())) ans = False for j in range(len(x) - 1): if x[j] <= x[j + 1]: ans = True break else: ans = False if ans: res.append('YES') else: ...
Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. Constraints * 1 \leq N \leq 10^{10} * 0 \leq X < M \leq 10^5 * All values in input are ...
3
n, x, m = map(int, input().split()) result = [x] for i in range(m): y = (result[-1] * result[-1]) % m if y in result: start = result.index(y) end = i break result.append(y) loop = result[start:] a = start b = (n - a) // len(loop) c = (n - a) % len(loop) ans = sum(result[:a]) + (sum(...
Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to...
3
array= input("").split(' ') totalsum=0 # to be used for m<n summ=0 # to be used for m>=n n=array[0] d=array[1] listfromsmallesttolargest=input("").split(' ') m=int(input("")) for u in range (0, len(listfromsmallesttolargest)): summ=summ+int(listfromsmallesttolargest[u]) listfromsmallesttolargest=[int(x) for x in l...
Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the eve...
3
def vasya_and_socks(f, s): h = 0 while f!=0: h += 1 f -= 1 if f == 0 and h % s != 0: return h if h % s == 0: f += 1 # -------------------------------------------------------------- if __name__ == '__main__': f = lambda: map(int, input().split()) n,...
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved. The square still has a rectangular shape of n × m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pav...
3
for _ in range(int(input())): n, m, x, y = map(int, input().split()) use_one = False if 2*x <= y: use_one = True total = 0 for _ in range(n): qtd = 0 for l in input(): if l == '*': if use_one: total += x*qtd els...
You are given the array a consisting of n positive (greater than zero) integers. In one move, you can choose two indices i and j (i ≠ j) such that the absolute difference between a_i and a_j is no more than one (|a_i - a_j| ≤ 1) and remove the smallest of these two elements. If two elements are equal, you can remove a...
3
t=int(input()) for i in range(t): n=int(input()) ls=[int(a) for a in input().split()] ls.sort() bp=False for j in range(n-1): if ls[j+1]-ls[j]>1: bp=True break if bp: print("NO") else: print("YES")
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: * Operation ++ increases the value of variable x by 1. * Operation -- decreases the value of variable x by 1....
3
x=0 n=int(input()) for i in range(n): p=input() if(p=="++X" or p=="X++"): x=x+1 else: x=x-1 print(x)
Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them. Your task is: given the n and t print an integer strictly larger than zero consisting of n digits that is divisible by t. If such number doesn't exist, print - 1. Input T...
1
n, t = map(int, raw_input().split()) if n == 1: if t == 10: print '-1' else: print t else: if t == 10: ans = '10' for i in range(n-2): ans += '0' print ans else: ans = str(t) for i in range(n-1): ans += '0' print an...
Boboniu gives you * r red balls, * g green balls, * b blue balls, * w white balls. He allows you to do the following operation as many times as you want: * Pick a red ball, a green ball, and a blue ball and then change their color to white. You should answer if it's possible to arrange all the b...
3
if __name__ == '__main__': t = int(input()) for _ in range(t): r, g, b, w = [int(x) for x in input().split()] arr = [r, g, b, w] n = r + g + b + w n_odd = sum([1 for x in arr if x & 1]) n_even = sum([1 for x in arr if x % 2 == 0]) if n % 2 == 0 and ((r % 2 == 0 an...
You are given an array a of length n, and an integer x. You can perform the following operation as many times as you would like (possibly zero): replace two adjacent elements of the array by their sum. For example, if the initial array was [3, 6, 9], in a single operation one can replace the last two elements by their ...
3
import sys import math for n in range(int(sys.stdin.readline())): x = int(sys.stdin.readline().split(" ")[1]) a_i = sys.stdin.readline().split(" ") SumMin = 0 SumMax = 0 for a in a_i: SumMin += int(a) SumMin = math.ceil(SumMin/x) for a in a_i: SumMax += math.ceil(int(a)/x) ...
Alice and Bob have decided to play the game "Rock, Paper, Scissors". The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or scissors. If both players showed the same things then the round outcome is a ...
3
''' 686 479 178 29 11 145 530 ''' import sys def input(): return sys.stdin.readline() n = input() a = list(map(int, input().split())) b = list(map(int, input().split())) total_parties = sum(a) def max_wins(a, b): a = list(a) b = list(b) res = 0 for i in range(-1, len(a)-1): wins = m...
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the plane with number fi, where 1 ≤ fi ≤ n and fi ≠ i. We call a love triangle a situation in which plane A likes plane...
3
from sys import stdin from collections import deque,Counter,defaultdict import sys import math,os import operator import random from fractions import Fraction import functools import bisect import itertools from heapq import * import time import random import bisect n = int(input()) arr = list(map(int,input().split()...
JOI Park In preparation for the Olympic Games in IOI in 20XX, the JOI Park in IOI will be developed. There are N squares in JOI Park, and the squares are numbered from 1 to N. There are M roads connecting the squares, and the roads are numbered from 1 to M. The road i (1 ≤ i ≤ M) connects the square Ai and the square ...
3
from heapq import heappush, heappop N, M, C = map(int, input().split()) G = [[] for i in range(N)] E = [] for i in range(M): a, b, d = map(int, input().split()); a -= 1; b -= 1 G[a].append((b, d)) G[b].append((a, d)) E.append((a, b, d)) INF = 10**18 dist = [INF]*N dist[0] = 0 que = [(0, 0)] while que: ...
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o...
3
n, m = map(int, input().split()) data = [] fl = [0] * 1000000 an = -1 f = 0 for i in range(m): data += [list(map(int, input().split()))] fl[data[i][0]] = data[i][1] if data[i][0] == n: an = data[i][1] f = max(data[i][1], f) if an != -1: print(an) exit(0) data.sort() an = [] t = True f...
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substr...
3
n = int(input()) pattern = ['a', 'a', 'b', 'b'] ans = '' for i in range(n): ans += pattern[i % 4] print(ans)
"Not every love story has a happy ending!"- Little Jhool was certainly a con man, fooling people by telling them about their future, [The first problem!] but he loved his girl - truly! But, Big Jhool, his girlfriend, was shocked and had broken up with him after getting to know that Little Jhool was a con man. Now, our ...
1
#Little-Jhool-the-Devdas raw_input() petals = map(int, raw_input().split()) sum=0 minOdd=100000 for petal in petals: if petal % 2 == 1: if minOdd > petal: minOdd=petal sum += petal if sum % 2 == 0: if minOdd % 2 == 1: sum -= minOdd if sum % 2 == 1: print sum else: print ":("
You are given a set of 2n+1 integer points on a Cartesian plane. Points are numbered from 0 to 2n inclusive. Let P_i be the i-th point. The x-coordinate of the point P_i equals i. The y-coordinate of the point P_i equals zero (initially). Thus, initially P_i=(i,0). The given points are vertices of a plot of a piecewis...
3
import math if __name__ == '__main__': n, k = map(int, input().split()) print(-(-k // n))
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...
1
n = int(raw_input()) l = map(int,raw_input().split()) odd,even = 0,0 c,d = 1000,1000 for i in range(n): if l[i]%2==1: if not odd: c = i+1 odd+=1 else: if not even: d = i+1 even+=1 if odd==1:print c else:print d
You are given four integers n, c_0, c_1 and h and a binary string s of length n. A binary string is a string consisting of characters 0 and 1. You can change any character of the string s (the string should be still binary after the change). You should pay h coins for each change. After some changes (possibly zero) ...
3
for i in range(int(input())): n, c0, c1, h = map(int, input().split()) s = input() zero = s.count("0") one = s.count("1") res0 = n * c0 + one * h res1 = n * c1 + zero * h res2 = zero * c0 + one * c1 print(min(res0, res1, res2))
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109. In the evening after the conference, all n scientists decided to go to...
3
from collections import Counter n = int(input()) li = list(map(int,input().split())) lang=Counter() ans=[] for i in li: lang[i]+=1 m = int(input()) b = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(m): ans.append([lang[b[i]] , lang[c[i]] , i+1 ]) ans.sort() print(ans[-1][2])...
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each...
3
t,n=map(int,input().split());a=input() while n:a=a.replace("BG","GB");n=n-1 print(a)
You are given two strings s and t. Both strings have length n and consist of lowercase Latin letters. The characters in the strings are numbered from 1 to n. You can successively perform the following move any number of times (possibly, zero): * swap any two adjacent (neighboring) characters of s (i.e. for any i = ...
3
n=int(input()) s=list(input()) t=list(input()) r=[] b=0 for j in range(n): if s[j]!=t[j]: if j!=n-1: try: i=s.index(t[j],j+1,n) s.pop(i) s.insert(j,t[j]) for k in range(i,j,-1): r.append(k) except: ...
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
n,k=map(int,input().split()) l=[int(i) for i in input().split()] temp=l[:] l=l+l mini=10**9 def check(arr): sm=0 sm=sum([arr[i] for i in range(0,n,k)]) return sm for i in range(k,2*n): l[i]+=l[i-k] #print(l) for i in range(n-k,2*n): if l[i]<mini: #print(mini) # print(l[i]) ...
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which epi...
3
n = int(input()) l = list(map(int,input().split())) l.sort() flag = 0 for i in range(1,n): if i == l[i-1]: continue else: flag = 1 print(i) break if flag == 0: print(n)
You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either gras...
1
#!/usr/bin/env python2.6 # coding=utf-8 import sys import re def compute(n, m, gar): lastrow = -1 lef, rig = [ m-1 for i in range(n+1)],[ 0 for i in range(n+1)] for i in range(n): g = gar[i] l = g.find("W") r = g.rfind("W") if l != -1: lef[i] = l rig[...
Write a program which reads two integers x and y, and prints them in ascending order. Constraints * 0 ≤ x, y ≤ 10000 * the number of datasets ≤ 3000 Input The input consists of multiple datasets. Each dataset consists of two integers x and y separated by a single space. The input ends with two 0 (when both x and y...
3
a=[] while 1: n=input() if n=='0 0':break a.append(n) for s in a: x,y=map(int,s.split()) print(y,x) if x>y else print(s)
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood. Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights ...
3
def gen_prime(n): prime = [] prime.append(2) prime.append(3) prime.append(4) for i in range(5, n+1): div = False for j in prime: if not i%j: div = True break if not div: prime.append(i) return prime n = int(input()) prime = gen_prime(n) prime = prime[1:] prime.append(n) a = [int(i) for i i...
Ayrat has number n, represented as it's prime factorization pi of size m, i.e. n = p1·p2·...·pm. Ayrat got secret information that that the product of all divisors of n taken modulo 109 + 7 is the password to the secret data base. Now he wants to calculate this value. Input The first line of the input contains a sing...
1
MOD = pow(10, 9) + 7 MOD1 = MOD - 1 MOD2 = MOD * MOD n = input() primes = map(int, raw_input().strip().split()) f = {} for p in primes: try: f[p] += 1 except: f[p] = 1 isperf = 1 tau = 1 for p in f: e = f[p] if (e + 1) % 2 == 0 and isperf == 1: tau = tau * ((e + 1) // 2) isperf = 0 ...
Given is a lowercase English letter C that is not `z`. Print the letter that follows C in alphabetical order. Constraints * C is a lowercase English letter that is not `z`. Input Input is given from Standard Input in the following format: C Output Print the letter that follows C in alphabetical order. Example...
1
arg = raw_input() print chr(ord(arg) + 1)
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
1
a = raw_input() b = raw_input() result = "" for i in xrange(len(a)): result += "1" if (a[i] != b[i]) else "0" print result
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark. Now it'...
1
#!/usr/bin/python import sys data = iter(sys.stdin.read().split()) n = int(data.next()) a = int(data.next()) b = int(data.next()) lix = [] liy = [] ans = [1] * n for i in xrange(n): x = int(data.next()) lix.append((x, i)) liy.append((x, -i)) if a == b: for i in xrange(b): ans[i + a] = 2 elif a < b: liy.sor...
There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only p levels of the game. And Little Y can pass only q levels of the game. You are given the indices of levels Little X can pass ...
3
n= int(input()) k=[int(i) for i in input().split()] l=[int(i) for i in input().split()] g=[int(i) for i in range(1,n+1)] for i in g: if i in k[1:]: pass elif i in l[1:]: pass else: print("Oh, my keyboard!") break else: print("I become the guy.")
Let's start from some definitions. Strings A and B are called anagrams if it's possible to rearrange the letters of string A using all the original letters exactly once and achieve string B; in other words A and B are permutations of each other. For example, remote and meteor are anagrams, race and race are anagrams a...
1
import sys from collections import Counter num = int(sys.stdin.readline().rstrip()) text = sys.stdin.readline().rstrip() common_dict = Counter(text) while num != 1: text = sys.stdin.readline().rstrip() count = Counter(text) tmp = {} for key,val in common_dict.items(): if key in count: tmp[key] = min(val,coun...
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon...
1
pylons = int(raw_input().strip()) pylons_height = list(map(int, raw_input().strip().split())) result, energy, initial_height = 0, 0, 0 for p in pylons_height: energy += (initial_height - p) if energy < 0: result += (-energy) energy = 0 initial_height = p print result
Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is forbidden if it cuts off some ones. So, in fact, in one operation, you can m...
3
def process(now): count = 0 if now == 1: return 0 if now % 2 != 0: return -1 while now >= 1: if now == 1: return count if now % 8 == 0: count += 1 now //= 8 elif now % 4 == 0: count += 1 now //= 4 ...
Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols ...
3
import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) n=iinput() a=list(map(int,input().split())) m=iinput() for i in range(...
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
(n, m) = [int(x) for x in input().split()] f = [int(x) for x in input().split()] f.sort() mini = 1000 for i in range(m): if i + n - 1 == m: break if f[i + n - 1] - f[i] < mini: mini = f[i + n - 1] - f[i] print(mini)
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
s=list(input().split("+")) s=sorted(s) sn=("+").join(s) print(sn)
As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of ai cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highest a...
3
from sys import stdin, stdout outputs = [] n, m = (int(num) for num in stdin.readline().strip().split()) arr = [int(num) for num in stdin.readline().strip().split()] for i in range(n): arr[i] = [arr[i], i+1] arr = sorted(arr, key = lambda t: t[0]) res = [] diff = arr[-1][0] - arr[0][0] while True and m > 0: if ...
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
a=int(input()) for i in range(0,a): b=input() c=list(map(int,input().split())) c.sort() mini=c[1]-c[0] for j in range(2,len(c)): value=c[j]-c[j-1] if value<mini: mini=value print(mini)
Chandan is an extremely biased person, and he dislikes people who fail to solve all the problems in the interview he takes for hiring people. There are n people on a day who came to be interviewed by Chandan. Chandan rates every candidate from 0 to 10. He has to output the total ratings of all the people who came in ...
1
t=int(raw_input()) s= [] for i in range(t): n = int(input()) if n == 0: if len(s) == 0: pass else: s.pop() else: s.append(n) print sum(s)
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song wi...
3
n, d = map(int, input().split()) t = [int(x) for x in input().split()] tt = sum(t) if tt+((n-1)*10) > d: print(-1) exit() else: print((d-tt)//5)
Tomorrow is a difficult day for Polycarp: he has to attend a lectures and b practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them. While preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and d...
3
from math import ceil t=int(input()) for _ in range(t): a,b,c,d,k=map(int,input().split()) x=ceil(a/c) y=ceil(b/d) if x+y>k: print(-1) else: print(x,y)
Sherlock and Watson were good friends. They both were solving a mystery. But they got hungry and wanted to eat something. Hence they asked for some candies from Mom. Mom was also clever. She told them to solve a function for her. Function is defined as follows - F(x) = 2^x - 1 She gave number "a" to Shelock and "b"...
1
def gcd(a,b): if b==0: return a else: return gcd(b,a%b) import math y=math.sqrt t=input() while t: t-=1 a,b=map(int,raw_input().split()) a,b=(1<<a)-1,(1<<b)-1 a=gcd(a,b) b=int(y(a)) c=0 for i in range(2,b+1): if a%i==0: c+=1 while a%i==0: a/=i if a==1: break if a!=1: c+=1 print c
You are given two integers n and m. You have to construct the array a of length n consisting of non-negative integers (i.e. integers greater than or equal to zero) such that the sum of elements of this array is exactly m and the value ∑_{i=1}^{n-1} |a_i - a_{i+1}| is the maximum possible. Recall that |x| is the absolut...
3
t = int(input()) for tt in range(t): nm = input().split() n = int(nm[0]) m = int(nm[1]) if(n==1): print(0) elif(n==2): print(m) else: print(2*m)
Given a permutation p of length n, find its subsequence s_1, s_2, …, s_k of length at least 2 such that: * |s_1-s_2|+|s_2-s_3|+…+|s_{k-1}-s_k| is as big as possible over all subsequences of p with length at least 2. * Among all such subsequences, choose the one whose length, k, is as small as possible. If mul...
3
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) ans=[l[0]] for i in range(1,n-1): if (l[i]>l[i-1] and l[i]>l[i+1] ) or (l[i]<l[i-1] and l[i]<l[i+1]): ans.append(l[i]) ans.append(l[n-1]) print(len(ans)) print(*ans) ...
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. Let next(x) be the minimum lucky number which is larger than or equals x. Petya is interested what i...
3
l = [] s = set() for i in range(1025): t = ['7' if i == '0' else '4' for i in bin(i)[2:]] t = int(''.join(t)) if t not in s: l.append(t) s.add(t) t = ['4' if i == '0' else '7' for i in bin(i)[2:]] t = int(''.join(t)) if t not in s: l.append(t) s.add(t) l.sort() i, j = map(int, input().split()) ans = 0 f...
Petya is having a party soon, and he has decided to invite his n friends. He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one co...
3
a = [int(i) for i in input().split()] print(((2*a[0]-1)//a[1])+((5*a[0]-1)//a[1])+((8*a[0]-1)//a[1])+3)
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
x = [] y = int(input()) for i in range(y): x.append(input().split(" ")) count = 0 for i in x: sum = 0 bo = False for j in i: if int(j) == 1: sum+=1 if sum == 2 and not bo: count+=1 bo = True print(count)
You are given an array a consisting of n integer numbers. Let instability of the array be the following value: max_{i = 1}^{n} a_i - min_{i = 1}^{n} a_i. You have to remove exactly one element from this array to minimize instability of the resulting (n-1)-elements array. Your task is to calculate the minimum possible...
3
n = int(input()) a = list(map(int, input().split())) a.sort() x = a[-1] - a[1] y = a[-2] - a[0] print(min(x, y))
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write bi es...
1
raw= raw_input n, r, avg = map(int, raw().split()) s = n * avg ms = [map(int, raw().split()) for _ in xrange(n)] ms.sort(key=lambda x: x[1]) ref = 0 cm = sum([i[0] for i in ms]) if cm < s: for m, b in ms: if m < r and cm < s: nn = min(r - m, s - cm) cm += nn ref += nn * ...
Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from t...
3
n=int(input()) l=[*map(int,input().split())] k=max(l) x=n*k while x-sum(l) <= sum(l): x+=n k+=1 print(k)
DO YOU EXPECT ME TO FIND THIS OUT? WHAT BASE AND/XOR LANGUAGE INCLUDES string? DON'T BYTE OF MORE THAN YOU CAN CHEW YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT! I HAVE NO ARRAY AND I M...
3
n = int(input()) a1 = input().split() a = [int(a1[i]) for i in range(len(a1))] print(max(a) ^ a[-1])
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
def mi(): return map(int, input().split()) ''' 4 10 1 3 7 3 2 1 1000 1 1000000000000 42 88 ''' for _ in range(int(input())): n,a,b = mi() if 2*a<b: print (n*a) else: print ((n//2)*b+(n%2)*a)
All bandits are afraid of Sheriff. Sheriff constantly fights crime, but when bandits lay low, he gets bored and starts to entertain himself. This time Sheriff gathered all the bandits in his garden and ordered them to line up. After the whistle all bandits should change the order in which they stand. Sheriff gave all...
1
import fractions primes = [] def init_primes(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in xrange(2, n + 1): if is_prime[i]: for j in xrange(i * i, n + 1, i): is_prime[j] = False global primes primes = [i for i in xrang...
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
l,l2,l3=[],[],[] for i in range(int(input())): x,y=map(int,input().split()) l.append(x) l2.append(y) l3.append(1) for i in range(len(l)): for j in range(len(l2)): if l2[i]==l[j] and i!=j: l3[j]=0 print(sum(l3))
On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains. Mountains are described by a sequence of heights...
3
t=int(input()) for _ in range(t): n,k=map(int,input().split()) a=list(map(int,input().split())) peak=[0 for _ in range(n)] p=[0 for _ in range(n)] for i in range(1,n-1): if a[i]>a[i-1] and a[i]>a[i+1]: p[i]=p[i-1]+1 peak[i]=1 else: p[i]=p[i-1] ...
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
3
s1=0 s=0 c=0 n=int(input()) l = list(map(int,input().split())) l.sort(reverse=True) for i in range(0,n): s = s+ l[i] for j in range(0,n): s1 = s1 +l[j] c = c + 1 if s1>s-s1: break print(c)
The math faculty of Berland State University has suffered the sudden drop in the math skills of enrolling students. This year the highest grade on the entrance math test was 8. Out of 100! Thus, the decision was made to make the test easier. Future students will be asked just a single question. They are given a sequen...
3
#env python import sys def main(): n = int(sys.stdin.readline()) f = [ int(i) for i in sys.stdin.readline().split() ] f = f[:n] d = { (1, 2): 3, (1, 3): 4, (2, 1): 3, (2, 3): 'Infinite', (3, 1): 4, (3, 2): 'Infinite' } intersections = 0 for ...
Let LCM(x, y) be the minimum positive integer that is divisible by both x and y. For example, LCM(13, 37) = 481, LCM(9, 6) = 18. You are given two integers l and r. Find two integers x and y such that l ≤ x < y ≤ r and l ≤ LCM(x, y) ≤ r. Input The first line contains one integer t (1 ≤ t ≤ 10000) — the number of tes...
3
import sys, os.path if(os.path.exists('input.txt')): sys.stdin = open('input.txt',"r") sys.stdout = open('output.txt',"w") sys.setrecursionlimit(10 ** 5) def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().spli...
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
n=int(input()) if(n%4==0 or n%47==0 or n%744==0 or n%7==0 or n%477==0 or n%474==0): print("YES") else: print("NO")
n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could ha...
1
__author__ = 'Steshenko' def AP(dig): return (dig + 1) * dig / 2 n, m = map(int, raw_input().split(" ")) restMin = n % m kmin = AP(n / m - 1) * (m - restMin) + AP(n / m) * restMin restMsx = n - (m - 1) kmax = AP(restMsx - 1) print "{min} {max}\n".format(min=kmin, max=kmax)
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th...
3
total=0 t=0 n,m=map(int,input().split()) for i in range(1,n+1): t+=(5*i) if t+m<=240: total+=1 print(total)
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat! Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move: * exactly a steps left: from (u,v) to (u-1,v); * exactly b steps right: from (u,v) to (u+1,v); ...
3
for _ in range(int(input())): a, b, c, d = map(int,input().split()) x, y, x1, y1, x2, y2 = map(int,input().split()) print("YNEOS"[x - a + b > x2 or x - a + b < x1 or y - c + d > y2 or y - c + d < y1 or ((x2 - x1 == 0 and (a > 0 or b > 0)) or (y2 - y1 == 0 and (c > 0 or d > 0)))::2])
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
1
w = input() w = w-2 if w > 0 and w % 2 == 0: print("YES") else: print("NO")
You are given two arrays a and b, each consisting of n positive integers, and an integer x. Please determine if one can rearrange the elements of b so that a_i + b_i ≤ x holds for each i (1 ≤ i ≤ n). Input The first line of input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. t blocks follow, each d...
3
t = int(input()) answer = [] for i in range(t): f = input() n, x =map(int, f.split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.reverse() for j in a: if j + min(b) <= x: b.remove(min(b)) else: answer.append('No') ...
Allen wants to enter a fan zone that occupies a round square and has n entrances. There already is a queue of a_i people in front of the i-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute. Allen uses the following strategy to enter the fan zone: * Initially he stands...
3
N = int(input()) a = list(map(int,input().split())) c = 9999999999999999999999999 e = 0 for i in range(N): b = a[i]//N c = min(b,c) c = c*N for i in range(N): a[i] = a[i] - i - c if a[i] <= 0: e = 1 break if e == 1: print(i+1) else: for i in range(N): a[i] = a[i] - N if a[i] <= 0: ...
A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < t. You are given a sequence b0, b1, ..., bn - 1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasin...
1
#!/usr/bin/env python import string n, d = map(int, string.split(raw_input())) A = map(int, string.split(raw_input())) r = 0 for i in range(1, n): if A[i] <= A[i - 1]: k = ((A[i - 1] - A[i]) / d) + 1 A[i] += k * d r += k print r
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....
1
from sys import stdin n,m = map(int,stdin.readline().split()) b = [] for i in xrange(n): c = stdin.readline().strip() b.append(c) a = map(int,stdin.readline().split()) ans = 0 for i in xrange(m): cur = 0 di = {} for j in xrange(n): ch = b[j][i] di[ch] = di.get(ch,0) + 1 cur =...
This is the hard version of this problem. The only difference is the constraint on k — the number of gifts in the offer. In this version: 2 ≤ k ≤ n. Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "k of goods for the price of one" is held in...
3
import sys input = sys.stdin.readline t = int(input()) for tt in range(t): n, p, k = [int(x) for x in input().strip().split()] a = sorted([0] + [int(x) for x in input().strip().split()]) account_cumsum = [0 for _ in range(n+1)] count_cumsum = [0 for _ in range(n+1)] for i in range(1, k): if...
The next lecture in a high school requires two topics to be discussed. The i-th topic is interesting by a_i units for the teacher and by b_i units for the students. The pair of topics i and j (i < j) is called good if a_i + a_j > b_i + b_j (i.e. it is more interesting for the teacher). Your task is to find the number...
3
import bisect n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) for i in range(n): a[i]=a[i]-b[i] a.sort() ans=0 i=0 while i<n and a[i]<=0: ind=bisect.bisect_left(a,-a[i]+1) ans+=n-ind i+=1 left=n-i ans+=((left*(left-1))//2) print(ans)
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
3
n=int(input()) m=0 for i in range(n): x=input().split() a=int(x[0]) b=int(x[1]) c=int(x[2]) y=a+b+c if y>1: m=m+1 else: m=m print(m)
A penguin Rocher has n sticks. He has exactly one stick with length i for all 1 ≤ i ≤ n. He can connect some sticks. If he connects two sticks that have lengths a and b, he gets one stick with length a + b. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his se...
3
import math t = int(input()) while t!=0: n = int(input()) if n==3: print (2) elif n==1: print (1) else: print (math.ceil(n/2)) t-=1
You are given strings S and T consisting of lowercase English letters. You can perform the following operation on S any number of times: Operation: Choose two distinct lowercase English letters c_1 and c_2, then replace every occurrence of c_1 with c_2, and every occurrence of c_2 with c_1. Determine if S and T can ...
3
import collections s = input() t = input() S = sorted(list(collections.Counter(s).values())) T = sorted(list(collections.Counter(t).values())) if S == T: print('Yes') else: print('No')
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage...
1
D = [] for k in range(3): D.append(raw_input()) ''' flag = True for i in range(2): for j in range(3): if D[i][j] == D[2-i][2-j]: continue else: flag = False break ''' if D[0] == D[2][::-1]: if D[1] == D[1][::-1]: print "YES" else: ...
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
#Div -3 29th Sep Symmetric Matrix T=int(input()) while T!=0: n,m=[int(i) for i in input().split()] flag=0 for i in range(n): a=[[int(i) for i in input().split()],[int(i) for i in input().split()]] if a[0][1]==a[1][0]: flag=1 if m%2!=0: flag=0 if flag==0: p...
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...
1
import re n=int(raw_input()) s=raw_input() i=1 j=0 while i<n: if s[i]==s[i-1]: j+=1 i+=1 print(j)
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Pety...
1
a = raw_input() b = raw_input() c1, c2 = 0, 0 for i, j in zip(a, b): if i != j: if j == '4': c1 += 1 else: c2 += 1 print max(c1, c2)
Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it. ...
3
t=int(input()) for _ in range(t): n=int(input()) c=n//4 d=n%4 if d: c+=1 else: pass print('9'*(n-c)+'8'*c)
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1,...
1
n,m = map(int,raw_input().split()) for i in range(n): if i%2==0: print "#"*m elif i%4==1: print "."*(m-1)+"#" elif i%4==3: print "#"+"."*(m-1)
Takahashi made N problems for competitive programming. The problems are numbered 1 to N, and the difficulty of Problem i is represented as an integer d_i (the higher, the harder). He is dividing the problems into two categories by choosing an integer K, as follows: * A problem with difficulty K or higher will be for ...
3
N=int(input()) L=list(map(int,input().split())) L=sorted(L) print(L[N//2]-L[N//2-1])
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
# coding=utf-8 if __name__ == '__main__': n = int(input()) temp_list = [4, 7, 8, 12, 14, 16, 20, 21, 24, 28, 32, 35, 36, 40, 42, 44, 47, 48, 49, 52, 56, 60, 63, 64, 68, 70, 72, 74, 76, 77, 80, 84, 88, 91, 92, 94, 96, 98, 100, 104, 105, 108, 112, 116, 119, 120, 124, 126, 128, 1...
Petya has an array a consisting of n integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment is a non-empty sequence of elements standing one next to another in the array. Now he wonders what is the number of segments in his arra...
1
'''input 4 -1 -2 1 -2 3 ''' from collections import defaultdict as df from bisect import bisect_left as bl import sys n,t=[int(x) for x in raw_input().split()] A=[int(x) for x in raw_input().split()] S=[0]*(n+1) for i in range(n): S[i+1]=S[i]+A[i] SS=[-99999999999999999999999]+sorted(S)+[999999999999999999999...
n students are taking an exam. The highest possible score at this exam is m. Let a_{i} be the score of the i-th student. You have access to the school database which stores the results of all students. You can change each student's score as long as the following conditions are satisfied: * All scores are integers ...
3
for z in range(int(input())): n,m=map(int,input().split()) a=list(map(int,input().split())) print(min(sum(a),m))
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
s = int(input()) g = list(map(int,input().split())) # for i in range(s): # print(g.index(i+1)+1, end=' ') A = ['']*s for i, f in enumerate(g): A[f-1] = str(i+1) print(' '.join(A))
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings s and t to Vitaly. The strings have the same length, they consist of lowercase English l...
3
def f(s): return f(s[:-1])+'a' if s[-1] == 'z'else s[:-1]+chr(ord(s[-1])+1) s = f(input()) print(('No such string', s)[s < input()])
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri,...
1
[n, m] = map(int, raw_input().strip().split()) min = 100000000 for i in xrange(m): [l, r] = map(int, raw_input().strip().split()) if r - l < min: min = r - l i = 0 j = 0 print min + 1 while True: print str(i) + ' ', j += 1 i += 1 if j >= n: break if i == min + 1: i ...
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the n days of summer. On the i-th day, a_i millimeters of rain will fall. All values a_i are distinct. The mayor k...
1
n,x,y = [int(nxy) for nxy in raw_input().split(" ")] a = [int(ai) for ai in raw_input().split(" ")] i = 0 nf = True while nf and i < n: ai = a[i] cor = True j = i - 1 while cor and j > (i-x-1): if j >= 0: aj = a[j] if aj <= ai: cor = False j -= 1 j = i + 1 while cor and j < (i+y+1): if j <= (n-1)...
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow...
1
n=input() if n>0: print n else: s=(str)(n) delIndex=len(s)-1 if s[len(s)-1]<s[len(s)-2]: delIndex = len(s)-2 if(delIndex>=len(s)-1): print int(s[0:delIndex]) else: print int(s[0:delIndex]+s[delIndex+1:len(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
soma = input().split('+') soma.sort() print(soma[0],end="") tam = len(soma) for x in range(1,tam): print("+%s"%(soma[x]),end="") print()
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
y,b,r = map(int, input().split()) less = min(y,b,r) if less == y: if r-y >= 2: if b-y >= 1: print(3*y + 3) else: print(3*b) elif r-y == 1: if b-y >= 1: print(3*r-3) else: print(3*b) elif r == y: print(3*r-3) eli...
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auct...
3
n = int(input()) l = [int(x) for x in input().split()] g = sorted(l) a = l.index(g[-1])+1 print(a, g[-2])