problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weigh...
3
t = int(input()) for i in range(t): n=int(input()) print(int(2*(2**(n/2))-2))
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 millis...
3
s, v1, v2, t1, t2 = map(int, input().split()) s1 = 2*t1 + s*v1 s2 = 2*t2 + s*v2 if s1 > s2: print("Second") elif s1 == s2: print("Friendship") else: print("First")
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
3
ch=input() ch1=input() if(ch==ch1[::-1]): print("YES") else: print("NO")
Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be good if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one sq...
3
import sys input = sys.stdin.readline H, W = map(int, input().split()) s = [input() for _ in range(H)] dp = [[float('inf')] * W for _ in range(H)] dp[0][0] = 1 if s[0][0] == '#' else 0 for i in range(H): for j in range(W): if i > 0: if s[i-1][j] == '.' and s[i][j] == '#': dp[i][...
Asya loves animals very much. Recently, she purchased n kittens, enumerated them from 1 and n and then put them into the cage. The cage consists of one row of n cells, enumerated with integers from 1 to n from left to right. Adjacent cells had a partially transparent partition wall between them, hence there were n - 1 ...
3
n = int(input()) p = [[i, i, i] for i in range(n + 1)] def asd(i): if i == p[i][0]: return i p[i][0] = asd(p[i][0]) return p[i][0] def qwe(i, j): i = asd(i) j = asd(j) ## print(i, j) p[i][0] = p[j][0] p[p[i][2]][2] = p[p[j][1]][1] p[j][1] = p[i][1] return i s = 0 while n >...
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()) for T in range(t): n = int(input()) a = [int(x) for x in input().split()] a.sort() even = 0 for i in range(n): if a[i] % 2 == 0: even += 1 if even % 2 == 0: print("YES") continue flag = 0 for i in range(n - 1): if a[i + 1] - ...
Ivan has n songs on his phone. The size of the i-th song is a_i bytes. Ivan also has a flash drive which can hold at most m bytes in total. Initially, his flash drive is empty. Ivan wants to copy all n songs to the flash drive. He can compress the songs. If he compresses the i-th song, the size of the i-th song reduce...
3
import sys n, m = list(map(int, input().split())) a = [] b=[] diff=[] for x in range(n): a1, b1 =list(map(int, input().split())) a.append(a1) b.append(b1) diff.append(a1-b1) sum_song=sum(a) diff=sorted(diff, reverse=True) # sum_song_compress=sum(b) if sum_song>m: for x in range(len(diff)): ...
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
from sys import stdin m=int(stdin.readline()) a = list(map(int,stdin.readline().split())) a.insert(0,0) a.append(0) n = int(stdin.readline()) for i in range(n): x , y = map(int,stdin.readline().split()) a[x-1] += y-1 a[x+1] += a[x]-y a[x]=0 for j in range(1,m+1): print(a[j])
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input The first line contains integ...
3
input() s=list(input()) i=0 j=0 while(i<(len(s)-1)): if (s[i]==s[i+1]): del s[i] j+=1 else:i+=1 print(j)
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
a=int(input()) for i in range(a): s=input() if len(s)>10: print(s[0]+str(len(s)-2)+s[-1]) else: print(s)
You are given n integers a_1, a_2, ..., a_n, where n is odd. You are allowed to flip the sign of some (possibly all or none) of them. You wish to perform these flips in such a way that the following conditions hold: 1. At least (n - 1)/(2) of the adjacent differences a_{i + 1} - a_i for i = 1, 2, ..., n - 1 are grea...
3
t = int(input()) while t: t += -1 n = int(input()) l = list(map(int, input().split())) for i in range(n): if i % 2: print(abs(l[i]), end = " ") else: print(-abs(l[i]), end = " ") print()
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting o...
3
n = int(input()) a = list(map(int, input().split())) a.sort() b = n // 2 c = sum(a) d = 0 for i in range(b): d += a[i] print(d * d + (c - d) * (c - d))
You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2). You want to construct the array a of length n such that: * The first n/2 elements of a are even (divisible by 2); * the second n/2 elements of a are odd (not divisible by 2); * all elements of a are distinct and positi...
3
t = int(input()) for i in range(0,t): n = int(input()) k = n//2 if k%2 == 1: print("NO") continue else: print("YES") for i in range(1,k+1): print(i*2, end =' ') for i in range(1,k): print(i*2-1, end = ' ') print(3*k-1)
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: * if the last digit of the number is non-zero, she decreases the number by one; * if the last digit of the number is ze...
3
a=input() a=a.split() a1=int(a[0]) a2=int(a[1]) if (a1%10>=a2): print (a1-a2) else: while a2>0: if (a1%10==0 ): a1=a1//10 a2=a2-1 else: if (a1%10>=a2): a1=a1-a2 a2=0 else: ...
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
3
a=input() b=input() print("YES" if a==b[::-1] else "NO")
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimu...
3
n = int(input()) x=0 while n>=1: if n%2==1: x+=1 n-=1 else: n//=2; print(x)
There was once young lass called Mary, Whose jokes were occasionally scary. On this April's Fool Fixed limerick rules Allowed her to trip the unwary. Can she fill all the lines To work at all times? On juggling the words Right around two-thirds Sh...
3
#! ./bin/python3 import math x = int(input()) s = int(x/2 + 1) l = [] count = 0 i = 2 while i < s: while x % i == 0: l.append(i) x = int(x/i) count += 1 i += 1 if count == 2: break print("%d%d" %(l[0], l[1]))
This is the easy version of this problem. The only difference between easy and hard versions is the constraints on k and m (in this version k=2 and m=3). Also, in this version of the problem, you DON'T NEED to output the answer by modulo. You are given a sequence a of length n consisting of integers from 1 to n. The s...
3
for _ in " " * int(input()): n = int(input()) a = sorted(map(int, input().split())) ans = 0 cnt = 0 if n < 3: print(0) else: for i in range(2,n): while a[i] - a[cnt]>2: cnt+=1 val = i-cnt ans+=((val-1)*val)//2 print(ans)
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
1
for x in range(input()): r = raw_input("") s = len(r) if s <= 10: print r else: print r[0] + str(s-2) + r[s-1]
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. ...
3
a,b,c=map(int,input().split()) print("Yes"if a<=c<=b else "No")
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show. The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions: * Is it true that y is stric...
3
n = int(input()) upper = 2*(10**9) lower = (-2)*(10**9) for i in range(n): r = input() r = r.split() if r[0] == '>': if r[-1] == 'Y': lower = max(lower, int(r[1]) + 1) else: upper = min(upper, int(r[1])) if r[0] == '<': if r[-1] == 'Y': uppe...
You have a coins of value n and b coins of value 1. You always pay in exact change, so you want to know if there exist such x and y that if you take x (0 ≤ x ≤ a) coins of value n and y (0 ≤ y ≤ b) coins of value 1, then the total value of taken coins will be S. You have to answer q independent test cases. Input The...
3
for _ in range(int(input())): a, b, n, s = map(int, input().split()) if a*n + b >= s and b >= s % n: print('YES') else: print('NO')
The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the posi...
1
from sys import stdin from heapq import heapify inFile = stdin tokens = [] tokens_next = 0 def next_str(): global tokens, tokens_next while tokens_next >= len(tokens): tokens = inFile.readline().split() tokens_next = 0 tokens_next += 1 return tokens[tokens_next - 1] def nextInt(): ...
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver...
1
input() c={} i,j,k=0,0,0 a=map(int,raw_input().split()) G=lambda x:c.get(x,0) for x in a: j+=1 while G(x-2) or G(x+2) or (G(x-1) and G(x+1)): c[a[i]]-=1 i+=1 c[x]=G(x)+1 k=max(k,j-i) print k
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 i in range(0,t) : a = list(map(int, input().split())) if(a[0]==1): print(0) if (a[0] == 2): print(a[1]) if (a[0] >2): print(2*a[1])
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number y?". The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no ...
3
n = int(input()) ans = [] isprime = [True] * 1001 isprime[0], isprime[1] = False, False for i in range(2, n + 1): if isprime[i]: for j in range(i * i, n + 1, i): isprime[j] = False for i in range(2, n + 1): if isprime[i]: ans += [int(pow(i, x)) for x in range(1, 10) if int(pow(i, x)) <= n] print(len(ans)) ...
Sorry folks,, admin has no time to create a story for this problem... You have two integers n and m and you have to print value of factorial(n)%m. OUTPUT a single integer containing answer of problem. Input 23 14567 NOTE You do not need to create a program for this problem you have to write your answers of given in...
1
def main(): n,m=raw_input().split() n,m=int(n),int(m) # FIND N! i=1 s=1 while(i<=n): s=s*i i=i+1 print s%m if __name__ == '__main__': main()
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every...
3
import itertools def go(): n, k = map(int, input().split()) s = [input() for _ in range(n)] dic = {'S': 1, 'E': 2, 'T': 3} s2 = [[dic[let] for let in ss] for ss in s] ts = {s[i]: i for i in range(n)} dif = {} alp = 'SET' for aa, bb, cc in itertools.permutations(alp): dif[dic[a...
"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
t,k=map(int,input().split()) l=list(map(int,input().split())) c=0 for i in l: if i>=l[k-1] and i>0: c+=1 print(c)
Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}. Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold. Constraints * 3 \...
3
n = int(input()) counter = 0 ans = "No" for i in range(n): d1,d2 = map(int,input().split()) if d1 == d2: counter += 1 else: counter = 0 if counter == 3: ans = "Yes" print(ans)
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...
1
#!/usr/bin/python import os import sys import itertools def solve(f): n = f.read_int() ans = 0 for _ in xrange(n): i, j = f.read_int_list() if i > j: ans += 1 elif i < j: ans -= 1 if ans == 0: return "Friendship is magic!^^" elif ans > 0: ...
You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2). You want to construct the array a of length n such that: * The first n/2 elements of a are even (divisible by 2); * the second n/2 elements of a are odd (not divisible by 2); * all elements of a are distinct and positi...
3
t=int(input()) for _ in range(t): n=int(input()) a= n//2 if(a%2==1): print('NO') else: print('YES') b=[] c=2 while(c<=n): b.append(c) c+=2 s=sum(b) d=[] i=1 while(i<=n-3): d.append(i) ...
There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if...
3
h, w = map(int, input().split()) a = [tuple(input()) for _ in range(h)] b = [b for b in a if "#" in b] c = zip(*[c for c in zip(*b) if "#" in c]) for d in c: print(*d, sep="")
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If t...
3
n=int(input()) l=[int(x) for x in input().split(" ")] for i in range(1,n+1): print(l.index(i)+1,end=' ')
Today, Yasser and Adel are at the shop buying cupcakes. There are n cupcake types, arranged from 1 to n on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type i is an integer a_i. There are both tasty and nasty cupcakes, so the tastiness can be positive, zero or negative. Yasser, ...
3
import sys # sys.setrecursionlimit(10**6) from sys import stdin, stdout import bisect #c++ upperbound import math import heapq def modinv(n,p): return pow(n,p-2,p) def cin(): return map(int,sin().split()) def ain(): #takes array as input return list(map(int,sin().split...
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is it...
3
# -*- coding: utf-8 -*- """ Created on Fri Oct 23 17:06:43 2020 @author: an """ n = int(input()) list = [int(x) for x in input().split()] k = 1 list2 = [] for i in range(n): if i+1 < n and list[i] <= list[i+1]: k += 1 elif i+1 < n and list[i] > list[i+1]: list2.append(k) k = 1 list2.ap...
In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc. The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0). Aoki, an explorer, conducted a survey to identify the center ...
3
N = int(input()) list = [list(map(int,input().split())) for i in range(N)] for i in range(N): if list[i][2]: x0,y0,h0 = list[i] for Cx in range(0,101): for Cy in range(0,101): for i in range(N): H = max(h0+abs(x0-Cx)+abs(y0-Cy),0) if max(H-abs(list[i][0]-Cx)-abs(list[i]...
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits. SAMPLE INPUT 1 2 88 42 99 SAMPL...
1
x=-1 while(x!=42): x=int(raw_input()) if (x!=42): print x
There was once young lass called Mary, Whose jokes were occasionally scary. On this April's Fool Fixed limerick rules Allowed her to trip the unwary. Can she fill all the lines To work at all times? On juggling the words Right around two-thirds Sh...
3
n = int(input()) for i in range(2,999): if(n%i==0): print(str(i)+str(n//i)) exit(0)
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on n wooden ...
3
n = int(input()) l=[] for x in range(0,n): a,b=[int(x) for x in input().split()] l.append(a) l.append(b) i = int(0) j= int(0) left = l[0:len(l):2] right = l[1:len(l):2] i = right.count(1) j = left.count(1) print((min(left.count(1),left.count(0)))+min(right.count(1),right.count(0)))
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For exampl...
3
from math import ceil n = int(input()) xs = list(map(int, input().split())) ret = 1 xs.sort() for i in range(n): ret = max(ret, int(ceil((i+1)/(xs[i]+1)))) print(ret)
There are n candies in a row, they are numbered from left to right from 1 to n. The size of the i-th candy is a_i. Alice and Bob play an interesting and tasty game: they eat candy. Alice will eat candy from left to right, and Bob — from right to left. The game ends if all the candies are eaten. The process consists o...
3
def task(n, a): aa = 0 bb = 0 moves = 0 Alice = True last = 0 candies = 0 while True: if Alice: candy = a.pop(0) candies += candy aa += candy else: candy = a.pop() candies += candy bb += candy i...
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
a,b = [int(x) for x in input().split()] answer = a*b // 2 print(answer)
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise ai times. Greg now only does three types of exercises: "chest" exercises,...
3
times = int(input()) inputArr = input().split(" ") count = 1 totalBiceps = 0 totalChest = 0 totalBack = 0 for i in inputArr: i = int(i) if count == 1: totalChest += i count += 1 elif count == 2: totalBiceps += i count += 1 elif count == 3: totalBack += i ...
You are given a permutation a consisting of n numbers 1, 2, ..., n (a permutation is an array in which each element from 1 to n occurs exactly once). You can perform the following operation: choose some subarray (contiguous subsegment) of a and rearrange the elements in it in any way you want. But this operation canno...
3
import io import os from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from heapq import heappush, heappop, heapify from math import gcd, inf def solve(N, A): sA = sorted(A) if sA == A: return 0 if sA[0] == A[0] or sA[-1] == A[-1]: return 1 ...
Find the number of ways of distributing N objects into R groups such that each group gets 1 or more objects. Input: The one and only line of input contains two numbers separated by a single space, which are N and R respectively. Output: The corresponding answer modulo 10000007 in a single line and if no answer exist...
1
import math def nCr(n,r): f = math.factorial return f(n) / f(r) / f(n-r) input = raw_input() input = input.split(' ') n = int(input[0]) r = int(input[1]) result = 0 if n<r: print "-1" else: result = nCr(n-1, r-1) print result%10000007
Bob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point T, which coordinates to be found out. Bob travelled around the world and collected clues of the treasure location at n obelisks. These clues were in an ancient language, and he has only decrypted them at hom...
3
n=int(input()) s1,s2=0,0 for i in range(2*n): x,y=map(int,input().split()) s1+=x s2+=y print(int(s1/n),int(s2/n))
Let's define a split of n as a nonincreasing sequence of positive integers, the sum of which is n. For example, the following sequences are splits of 8: [4, 4], [3, 3, 2], [2, 2, 1, 1, 1, 1], [5, 2, 1]. The following sequences aren't splits of 8: [1, 7], [5, 4], [11, -3], [1, 1, 4, 1, 1]. The weight of a split is t...
3
print(int(int(input())/2)+1)
You are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and integer ki. It means that you should cyclically shift the substring s[li... ri] ki times. The queries should be processed one after another in the order they are given. One operation of a cyclic shift (rota...
3
def ans(s,l,r,k): if(r==len(s)): subR="" # print("bbbbbbb") else: subR=s[r:len(s)] # print("ccccccccc") sub=s[l-1:r] subL=s[0:l-1] L=len(sub) sub=sub+sub sub.replace(" ","") reminder=k%L # print("reminder",reminder) # print("subL",subL) # print("sub",sub) ...
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: * deletes all the vowels, * inserts a character "." before each consonant, * repl...
3
s=input(" ") vowels=('aeiouy') s=s.lower() for i in s: if i in vowels: s=s.replace(i,"") print( '.'+'.'.join(s[:]))
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break. The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch...
1
n, k = map(int, raw_input().split()) print max(map(lambda x:[x[0], x[0]-x[1]+k][x[1]>k], [map(int, raw_input().split()) for _ in xrange(n)]))
You are given two integers n and m (m < n). Consider a convex regular polygon of n vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length). <image> Examples of convex regular polygons Your task is to say if it is poss...
3
for _ in range(int(input())): n,m = map(int,input().split()) print('NO' if n%m else 'YES')
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
3
n = int(input()) magnets = [] for i in range(n): magnet = int(input()) magnets.append(magnet) changes = 1 for i in range(n -1): if magnets[i] != magnets[i + 1]: changes += 1 print(changes)
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
3
a = input() b = input() all = a + b c = list(input()) count = 0 while count < len(all): i = all[count] if i in c: c.remove(i) else: print("NO") exit() count += 1 if len(c) == 0: print("YES") else: print("NO")
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 ...
1
n,l=map(int,raw_input().split()) x=map(int,raw_input().split()) x.sort() a=x[0]-0 b=l-x[-1] m=0 for i in xrange(1,n): c=x[i]-x[i-1] m=max(m,c) m=m*1.0 a=a*1.0 b=b*1.0 a=max(a,b) m/=2 print max(m,a)
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can ...
3
def get_array(): return [int(el) for el in input().split()] def gcd(a, b, c=None): return ((a if b == 0 else gcd(b, a % b)) if c is None else gcd(gcd(a, b), gcd(a, c))) def get_line_odds(point1, point2): A = point1[1] - point2[1] B = point2[0] - point1[0] C = point1[0]*point2[1] - po...
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 difDigs(st): s = set() for ch in st: if ch in s: return False else: s.add(ch) return True # print("Input l and r") l, r = [int(x) for x in input().split()] done = False for test in range(l, r+1): if difDigs(str(test)): print(test) don...
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game. The rules are following. On each turn a fi...
1
n = input() s1 = map(int,raw_input().split()) s2 = map(int,raw_input().split()) del s1[0] del s2[0] foo = [] x = [] for i in s1: x.append(i) y = [] for i in s2: y.append(i) z = (x,y) foo.append(z) cnt = 0 f = 0 d = 10 while True: if s1[0] == s2[0]: f = -1 break elif s1[0] > s2[0]: ...
Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem: You are given an array a of n integers. You are also given an integer k. Lord Omkar wants you to do k ope...
3
t=int(input()) for _ in range(t): n,k=map(int,input().split()) arr=list(map(int,input().split())) d=max(arr) a=[] if n==1: print(0) else: for i in range(n): a.append(d-arr[i]) # print(a,"odd",k) if k%2==0: d=max(a) # print(d) ...
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and ...
3
a,b=[int(i) for i in input().split()] c=max(a,b) d=min(a,b) print(d,int((c-d)/2))
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x ...
3
mod = 10 ** 9 + 7 ii = lambda : int(input()) si = lambda : input() dgl = lambda : list(map(int, input())) f = lambda : map(int, input().split()) il = lambda : list(map(int, input().split())) ls = lambda : list(input()) n=ii() l=sorted(list(set(il()))) l1=len(l) if l1 in [1,2]: print('YES') elif l1>3: print('NO'...
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ...
3
input() ls=input().split() print(max(ls.count(i) for i in ls))
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference i...
3
n=int(input()) l=sorted(map(int,input().split())) ans=l[-1]-l[0] if ans == 0:print(ans,(n-1)*n//2) else: id = 1 i = n-2 while 1: if l[i] == l[-1]: id += 1 else: break i-=1 id2 = 1 i = 1 while 1: if l[i] == l[0]: id2 += 1 else: break i+=1 print(ans,id*id2)
Chef is the head of commercial logging industry that recently bought a farm containing N trees. You are given initial height of the i-th tree by Hi and the rate of growth of height as Ri meters per month. For simplicity, you can assume that all the trees are perfect cylinders of equal radius. This allows us to consider...
1
def can_cut(time): total_cut = 0 for i in xrange(N): temp = H[i]+time*R[i] if temp>=L: total_cut+=temp return total_cut>=W N,W,L=map(int,raw_input().split(" ")) H=[0]*N R=[0]*N for i in xrange(N): H[i],R[i]=map(int,raw_input().split(" ")) t_low=-1 t_high=10**18 while t_high-t...
We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead. Constraints * All values in input are integers. * 0 \leq A,\ B \leq 10^9 * A and B are distinct. Input Input is given from Standard Input in the following format: ...
3
a,b=map(int,input().split()) n=int((a+b)/2) print(n) if (a+b)%2==0 else print('IMPOSSIBLE')
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
ii=input().split() iii=[] i=0 u=0 t=int (ii[0]) while i< t : r=input() iii.append(r) i=i+1 while u < t: if len(iii[u])<11: print (iii[u]) else: a=iii[u][0] b=str (len(iii[u])-2) c=iii[u][len(iii[u])-1] p=a+b+c print(p) u=u+1
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure. Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed...
3
l, r, k = map(int, input().split()) print(*[k**i for i in range(65) if l <= k**i <= r] or [-1])
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
3
# --------------------------------# #-----------<HajLorenzo>----------- #Most Important Thing About Life #Is Loving What You Do... # --------------------------------# CHECK=False for i in range(int(input())): _=list(input().split()) if(int(_[1])>=2400 and int(_[2])>int(_[1])): CHECK=True print("YES" if...
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
3
# 97-122 - lowercase # 65-90 - uppercase t = input() lower = 0 upper = 0 for i in t: if ord(i) >= 97 and ord(i) <= 122: lower += 1 elif ord(i) >= 65 and ord(i) <= 90: upper += 1 if upper <= lower: print(t.lower()) else: print(t.upper())
Agent OO7 is engaged in a mission to stop the nuclear missile launch. He needs a surveillance team to monitor the progress of the mission. Several men with different type of capabilities assemble in a hall, help OO7 to find out total men with different capabilities. Capability is represented in form of numbers. Input -...
1
from sys import stdin t = int(stdin.readline()) for i in xrange(t): a = stdin.readline() a = set(stdin.readline().strip().split()) print len(a)
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up in a row. The happiness of Camel i will be L_i if it is among the K_i frontmost camels, and R_i otherwise. Snuke wants to maximize the total happiness of the camels. Find the maximum possible total happiness of the camel. Solve this probl...
3
def resolve(): #n=int(input()) #a,b=map(int,input().split()) #x=list(map(int,input().split())) #a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)] import heapq t=int(input()) for i in range(t): n=int(input()) L=[[] for _ in range(n)] R=[[] for _ in r...
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to s and elevator initially starts on floor s...
1
n, s = map(int, raw_input().split()) floorTimes = [0]*(s+1) for i in range(n): f, t = map(int, raw_input().split()) floorTimes[f] = max(floorTimes[f], t) curTime = 0 for n in floorTimes[:0:-1]: curTime += max(0, n - curTime) curTime += 1 print curTime
On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides). That's why Mister B decided to use this polygon. Now Mister B must find ...
3
n,a = map(int,input().split()) angle = (180-(180-(360/n)))/2 jump = (360)/n c = n aa = 1 bb = 2 mini = 10e9 if(n==3): cc = 3 else: for i in range(n,2,-1): #print(i,(angle*(n-i+1))) boo = abs(a-(angle*(n-i+1))) #print(boo) mini = min(boo,mini) if(mini == boo ): ...
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on...
3
n=int(input()) f=0 while not f: n+=1 if len(set(str(n)))==4: f=1 print(n)
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order ...
3
dis=int(input()) if dis<=5: print(1) else: result=dis//5 if dis%5>0: result+=1 print(result)
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: * deletes all the vowels, * inserts a character "." before each consonant, * repl...
3
import sys import math word = sys.stdin.readline().rstrip() word = word.lower() newWord = "" for letter in word: if letter == "a" or letter == "o" or letter == "y" or letter == "e" or letter == "u" or letter == "i": pass else: newWord += "." + letter print(newWord)
You are given an array a_1, a_2, ..., a_n where all a_i are integers and greater than 0. In one operation, you can choose two different indices i and j (1 ≤ i, j ≤ n). If gcd(a_i, a_j) is equal to the minimum element of the whole array a, you can swap a_i and a_j. gcd(x, y) denotes the [greatest common divisor (GCD)](...
3
for _ in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] m = min(a) l = sorted([x for x in a if not x%m]) b = a for i in range(n): if not a[i]%m: b[i] = 0 for i, x in zip(range(n), b): if not x: b[i] = l[0] l.pop(0) if s...
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: * Operation ++ increases the value of variable x by 1. * Operation -- decreases the value of variable x by 1....
3
n = int(input()) x = 0 for i in range(n): s = input() #a,b,c = map(int,input().split()) if "++" in s: x += 1 else: x -= 1 print(x)
Vasya has his favourite number n. He wants to split it to some non-zero digits. It means, that he wants to choose some digits d_1, d_2, …, d_k, such that 1 ≤ d_i ≤ 9 for all i and d_1 + d_2 + … + d_k = n. Vasya likes beauty in everything, so he wants to find any solution with the minimal possible number of different d...
3
number = int(input()) for i in range(9, 0, -1) : if number % i == 0 : no_of_digits = number // i print(no_of_digits) print((str(i) + ' ') * no_of_digits) break
Ringo is giving a present to Snuke. Ringo has found out that Snuke loves yakiniku (a Japanese term meaning grilled meat. yaki: grilled, niku: meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things. You are given a string S representing the Japanese name of ...
1
S=raw_input() print "Yes" if S[:4]=="YAKI" else "No"
Recently Vasya found a golden ticket — a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. No...
3
n=int(input()) s=input() l=[] total=0 p=0 for i in range(0,450): sum1=0 flag=1 r=0 for k in range(n): sum1=sum1+int(s[k]) if(sum1>i): flag=0 if(sum1==i): sum1=0 r=r+1 if(r>=2 and sum1==0 and flag==1): print("YES") p=1 ...
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
3
t = int(input()) for _ in range(t): word = input() if len(word)>10: result = word[0]+str(len(word)-2)+word[len(word)-1] print(result) else: print(word)
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k. <image> The description of the first test case. Since sometimes it's impossible to find such point ...
3
for t in range(int(input())): n,k=[int(x) for x in input().split(' ')] if(k<n): if(k%2==0): if(n%2==0): print(0) else: print(1) else: if(n%2==0): print(1) else: print(0) elif(k==n): print(0) else: print(k-n)
Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as in the dictionary), but he is not allowed to swap any of them. The only ope...
1
n = int(raw_input()) data = map(int, raw_input().split()) s = [] for i in range(n): s.append(raw_input()) dp = [[2**100 for i in xrange(2)] for x in xrange(100011)] dp[0][0] = 0 dp[0][1] = data[0] for i in range(1, n): if s[i] >= s[i - 1]: dp[i][0] = min(dp[i][0], dp[i - 1][0]) if s[i] >= s[i - 1][::-1]: dp[i][0...
You are given two arrays a and b both consisting of n positive (greater than zero) integers. You are also given an integer k. In one move, you can choose two indices i and j (1 ≤ i, j ≤ n) and swap a_i and b_j (i.e. a_i becomes b_j and vice versa). Note that i and j can be equal or different (in particular, swap a_2 w...
3
t = int(input()) for i in range(t): n , k = map(int , input().split()) a = list(map(int , input().split())) b = list(map(int , input().split())) a = sorted(a) b = sorted(b) sum = 0 for i in range(0,len(a)): sum = sum + a[i] j = 1 for i in range(0 , len(a)): if a[i]...
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple tre...
3
n = int(input()) ts = [[0, 0]] l, r = 0, 0 for i in range(n): x, a = map(int, input().split()) if x < 0: l += 1 elif x > 0: r += 1 ts.append([x, a]) ts.sort() m = l d = min(l, r) s = sum([t[1] for t in ts[m-d:m+d+1]]) if l < r: s += ts[m+d+1][1] elif l > r: s += ts[m-d-1][1] p...
You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: * A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of string s is string sisi + 1...sj. * The prefix of string s of length l (1 ≤ l ≤ |s|) is string s[1..l]. * The suffix of string s o...
3
#!/usr/bin/env python3 """Compute z function.""" def compute_z(data): z = [0 for _ in range(len(data))] z[0] = len(data) l = 0 r = 0 for i in range(1, len(data)): if i <= r: # nu am explorat z[i] = min(z[i-l], r-i+1) while i + z[i] < len(data) and data[z[i]] == data[i+z...
Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each apartment has exactly one window. In other words, a three-room apar...
3
# cook your dish here from sys import stdin,stdout #lst = [int(x) for x in stdin.readline().split()] t=int(input()) while t>0 : t=t-1 n=int(input()) if n<3 or n==4 : print(-1) continue rem=n%3 if rem==0 : print(n//3,end=" ") print(0,end=" ") ...
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on...
3
n=int(input()) while True: n=int(n)+1 k=n n=str(n) l=len(n) n=set(n) if len(n)==l: print(k) break n=k
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ...
3
a = int(input()) count = [0 for j in range(a)] b = list(map(int, input().split())) for i in range(a): for j in range(a): if b[i] == b[j]: count[i] += 1 count.sort() x = len(count) - 1 print(count[x])
The number 105 is quite special - it is odd but still it has eight divisors. Now, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)? Constraints * N is an integer between 1 and 200 (inclusive). Input Input is given from Standard Input in the following...
3
l = [3*5*7, 3*5*11, 3*5*13, 3**3*5, 3**3*7] n = int(input()) ans = 0 for i in l: if i <= n: ans += 1 print(ans)
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
3
n=int(input()) s2=' hate ' s1=' love ' s3='I' s4='it' s5='' for i in range(n): if(i==n-1): if i%2==0: s5=s5+s2 elif i%2 !=0: s5=s5+s1 else: if i%2==0: s5=s5+s2 elif i%2 !=0: s5=s5+s1 s5=s5+'that I' print(s3+s5+s4)
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such t...
1
# def recur(ind, loc, s, p, memo): # if loc == len(s) and ind < len(memo): # return -1 # elif loc == len(s): # return 0 # elif ind == len(memo): # return 0 # for i in memo: # print(i) # print(" " * ind, ind, loc) # if memo[ind][loc] != -1: # return memo[...
Recently Vasya found a golden ticket — a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. No...
3
n=int(input()) l=input() l=list(map(int,l)) s=0 D=0 for i in range(n): s+=l[i] ss=0 found=0 pos=i+1 while(pos<n and ss<=s): ss+=l[pos] if(ss==s): found+=1 ss=0 pos+=1 if ((found>0 and ss==0) and D==0): D=1 print("YES") break...
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo...
1
#6A #import math def Ttest(p, q, r): if (p < q+r) and (q < p+r) and (r < p+q): return True else: return False def Triangle(w,x,y,z): if Ttest(w,x,y)==True: return True elif Ttest(w,y,z)==True: return True elif Ttest(w,x,z)==True: return True elif Ttest(x,y,z)==True: retur...
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()) a = input().count("A") print("Anton" if 2*a > n else "Friendship" if 2*a == n else "Danik")
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)! There are five means of transport in this empire: * Train: travels from City 1 to 2 in one minute. A train can occupy at most A people. * Bus: travels from City 2 to 3 in one minute. A bus can occupy a...
1
def get_input(): N = int(raw_input()) A = int(raw_input()) B = int(raw_input()) C = int(raw_input()) D = int(raw_input()) E = int(raw_input()) return N, A, B, C, D, E def solve2(): N, A, B, C, D, E = get_input() X = min(A, B, C, D, E) NdivX = (N + X - 1) / X ret = 5 + NdivX...
We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them. If we place the K pieces on squares (x_1, y_1), (x_2, y_2), ..., and (x_K, y_K), the cost of this arrangement is...
3
from functools import reduce def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) # mを法とするaの乗法的逆元 def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: ...
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows. <image> The event coordinator has a list of k participants who should be picked up at the airport....
3
class CodeforcesTask475ASolution: def __init__(self): self.result = '' self.passengers = 0 def read_input(self): self.passengers = int(input()) def process_task(self): seats = ["#" for x in range(34)] for x in range(self.passengers): seats[x] = "O" ...
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ...
1
n = input() arr = map(int,raw_input().split()) x = max(arr)-25 if x<=0: print 0 else: print x