problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≀ bi). Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! Input The first line of the input contains one integer n (2 ≀ n ≀ 100 000) β€” number of cola...
3
n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) m1 = -1 m2 = -1 for i in B: if i > m1: m2 = m1 m1 = i elif i > m2: m2 = i if sum(A) <= m1 + m2: print("YES") else: print("NO")
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
3
def initial(s): p = s.find('WUB') if p < 0: return s elif p == 0: return initial(s[3:]) else: return s[0: p] + ' ' + initial(s[p + 3:]) print(initial(input()))
Sasha likes investigating different math objects, for example, magic squares. But Sasha understands that magic squares have already been studied by hundreds of people, so he sees no sense of studying them further. Instead, he invented his own type of square β€” a prime square. A square of size n Γ— n is called prime if ...
1
MAX = 100; mat = [[0 for x in range(MAX)] for y in range(MAX)]; def fillRemaining(i, j, n): x = 2; for k in range(i + 1,n): mat[k][j] = x; x+=1; for k in range(i): mat[k][j] = x; x+=1; def constructMatrix(n): right = n - 1; left = 0; for i in range(n)...
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
word=input() lowercase=0 uppercase=0 letters=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] for i in word: if i in letters: lowercase+=1 else: uppercase+=1 if lowercase>uppercase: word=word.lower...
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
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Apr 15 08:30:47 2017 @author: lawrenceylong """ a = int(input()) count = 0 past = 00 for i in ' '*a: g = int(input()) if g != past: count += 1 past = g print(count)
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
alfa = input() beta = input() a = list(alfa) b = list(beta) if len(alfa) == len(beta): for i in range(len(alfa)): if a[i] == b[(len(beta)-i-1)]: i = i else: print('NO') break if a[i] == b[(len(beta)-i-1)]: print('YES') else: print('NO')
You are given an array a of length n, which initially is a permutation of numbers from 1 to n. In one operation, you can choose an index i (1 ≀ i < n) such that a_i < a_{i + 1}, and remove either a_i or a_{i + 1} from the array (after the removal, the remaining parts are concatenated). For example, if you have the ar...
3
import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) t,=I() for _ in range(t): n,=I() l=I() f=0;cr=n if l[0]==n or l[-1]==1: f=1 ar=[l[0]] for i in range(1,n): if ar[-1]>l[i]: ar.append(l[i]) else: while len(ar)>1 and ar[-1]<l[i]: ar.pop() ar.append(l[i]) po=1 fo...
Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers x and y value of f(x, y) is also nonnegative. She would like to r...
3
n = int(input()) a = list(map(int, input().split())) bitsum = [0]*32 for i in a: for j in range(32): bitsum[j] += i>>j&1 onebit = None for i in range(31, -1, -1): if bitsum[i]==1: onebit = i break if onebit is None: print(*a) exit(0) for i in range(n): if a[i]>>onebit&1: ...
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown be...
3
n,m = map(int, input().split()) inter = n*m palito = n+m aux = 1 while inter > 0: n-=1 m-=1 inter = n*m aux+=1 if aux%2 == 1: print("Malvika") else: print("Akshat")
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor. The game is played on a square field consisting of n Γ— n cells. Initially all cells are empty. On each turn a pla...
1
n = int(raw_input()) print 2 - n % 2
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly n pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Som...
3
pages = int(input()) days = input().split(' ') count=0 while(pages > 0): for day in days: pages = pages - int(day) count+=1; if (pages <= 0): print(count) break if (count == len(days)): count=0
There is BMI (Body Mass Index) as an index showing the degree of obesity. The BMI value is calculated using the following formula. BMI = weight (kg) / (height (m)) 2 The closer the BMI value is to the standard value, the more "ideal body shape" is considered. Therefore, if the standard value of BMI is 22, create a pr...
1
def bmi(a): return a[0], abs(22-a[2]/((a[1]/100.0)**2)) while 1: n=input() if n==0:break d=[bmi(map(int,raw_input().split())) for i in range(n)] print sorted(sorted(d),key=lambda x:x[1])[0][0]
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + 9 + 8 = 21. Then the digital root of number n equals to: 1. dr(n) = S(n), if S(n) < 10; 2. dr(n) = dr( S(n) ), i...
3
k,d = map(str,input().split()) d = int(d) l = int(k) if(l==1): print(d) exit() if(l>1 and d==0): print('No solution') exit() s = str(1) for i in range(int(k)-2): s+=str(0) s+=str(8) s = int(s)+d print(s)
HQ9+ is a joke programming language which has only four one-character instructions: * "H" prints "Hello, World!", * "Q" prints the source code of the program itself, * "9" prints the lyrics of "99 Bottles of Beer" song, * "+" increments the value stored in the internal accumulator. Instructions "H" and "Q"...
3
valid = ['H', 'Q', '9'] def test(): commands = list(input()) works = False for i in commands: for j in valid: if i == j: works = True break if works: break if works: print('YES') else: print('NO') if __name__ =...
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
1
word=raw_input() t=word[0] d=word[1:] if word.isupper(): print(word.lower()) elif t.islower() and d.isupper(): print(word.capitalize()) elif len(word)==1 and t.islower(): print(word.upper()) else: print word #print s
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of ...
1
import sys line = raw_input() for i in range(0,len(line)): if line[i] == '0': print line[:i] + line[i+1:] sys.exit() print line[:len(line)-1]
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
a = int(input()) for i in range(a): b = int(input()) c = input() arr = c.split(" ") even = False odd = False for j in arr: j = int(j) if (j%2 == 0): even = True else: odd = True if (even == True and odd == True): print("YES") ...
The only difference between easy and hard versions is constraints. There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p_i-th kid (in case of i = p_i the kid will give his book to himself). It is guaranteed that all values of p_i are distinct integers ...
3
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int,input().split())) d={} for i in range(n): d[i+1] = l[i] s = "" for i in range(n): a = 1 b = i+1 while d[b] != i+1: b = d[b] a+=1 s+=str(a)+" " print(s)
Takahashi is standing on a multiplication table with infinitely many rows and columns. The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1). In one move, he can move from (i,j) to either (i+1,j) or (i,j+1). Given an integer N, find the minimum number of moves needed to reach a ...
3
N = int(input()) print(min(i-1+N//i-1 for i in range(1,int(N**0.5)+1) if N%i==0))
We have N clocks. The hand of the i-th clock (1≀i≀N) rotates through 360Β° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again? Constraints * 1≀...
3
import fractions n = int(input()) p = 1 for i in range(n) : t = int(input()) p = p*t//fractions.gcd(p,t) print(p)
Orac is studying number theory, and he is interested in the properties of divisors. For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, such that aβ‹… c=b. For n β‰₯ 2, we will denote as f(n) the smallest positive divisor of n, except 1. For example, f(7)=7,f(10)=2,f(35)=5. ...
3
tc = int(input()) while tc: n, k = map(int,input().split()) if n%2==0: print(n+2*k) else: f = 0 for i in range(3,n+1,2): if n%i==0: f = i break n+=f k-=1 print(n+2*k) tc-=1
HQ9+ is a joke programming language which has only four one-character instructions: * "H" prints "Hello, World!", * "Q" prints the source code of the program itself, * "9" prints the lyrics of "99 Bottles of Beer" song, * "+" increments the value stored in the internal accumulator. Instructions "H" and "Q"...
3
#!/usr/bin/env python3 import sys line = sys.stdin.readline().strip() commands = set('HQ9') for symbol in line: if symbol in commands: print('YES') exit() print('NO')
Vova plans to go to the conference by train. Initially, the train is at the point 1 and the destination point of the path is the point L. The speed of the train is 1 length unit per minute (i.e. at the first minute the train is at the point 1, at the second minute β€” at the point 2 and so on). There are lanterns on the...
3
import math def io_main(): for _ in range(int(input())): L, v, l, r = map(int, input().split()) num_seen = L // v block_start = int(math.ceil(l / v)) block_end = int(math.floor(r / v)) num_seen -= block_end - block_start + 1 print(num_seen) if __name__ == '__main_...
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
3
#timus ID 297513FP import math x = y = z = 0 for i in range(int(input())): a, b, c = map(int, input().split()) x += a y += b z += c print(["NO", "YES"][x == y == z == 0])
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if: * Its elements are in increasing o...
3
def hungry(n): a = 10 ** 7 b = list() for i in range(n): b.append(a - n + i + 1) return b print(*hungry(int(input())))
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()) p=0 for i in range(n): a,b,c=map(int,input().split()) f=[a,b,c] if(f.count(1)>=2): p+=1 print(p)
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle t...
3
def l(a, b): return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 def d(t): a return (t[1][0] - t[0][0], ) def f(t): if t[0] == t[1] or t[1] == t[2] or t[0] == t[2]: return 1 p = [l(t[1], t[2]), l(t[0], t[2]), l(t[0], t[1])] return sum(p) - 2 * max(p) t = list(map(int, input().split())) a, b, c = (t[0], ...
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...
1
string=list(raw_input()) vowels=['a','e','i','o','u','y','A','E','I','O','U','Y'] ans="" for k,v in enumerate(string): if v not in vowels: if string[k].isupper(): string[k]=string[k].lower() ans+="."+string[k] print ans
You have a given integer n. Find the number of ways to fill all 3 Γ— n tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap. <image> This picture describes when n = 4. The left one is the shape and the right one is 3 Γ— n tiles. Input The only line cont...
3
n=int(input()) if(n%2==0): print(int(2**(n/2))) else: print(0)
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minut...
1
n,a,b,c,d,e=map(int,raw_input().split());c-=b;b-=a;e+=d;t,x=1e4,0 for i in range(n):l,r=map(int,raw_input().split());x,t,l=x+a*(r-l),r,l-t;x+=a*max(l,0)+b*max(l-d,0)+c*max(l-e,0) print x
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
for i in range(int(input())): n,k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort(reverse=True) for i in range(k): if(a[i]<=b[i]): a[i] = b[i] else: break print(sum(a))
The Squareland national forest is divided into equal 1 Γ— 1 square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates (x, y) of its south-west corner. Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land A, B, C i...
3
xa,ya = map(int,input().split()) xb,yb = map(int,input().split()) xc,yc = map(int,input().split()) ans = [] xl = xb - xa xs = yb - ya a = abs(xl) b = abs(xs) x,y = xa,ya dis = [[xa,ya],abs(xa-xc) + abs(ya-yc)] for i in range(abs(xl) + abs(xs)): if a > 0 and b > 0: x1,y1 = x + xl//abs(xl),y d1 = abs(...
Problem statement JOI decided to start a new social game from tomorrow. In this social game, you can log in up to once a day, and you will get A coins each time you log in. Also, if you log in for 7 consecutive days from Monday to Sunday, you will get an additional B coins each time. No other coins will be given. ...
3
import math a,b,c = map(int,input().split()) d=1 r=0 w=0 w = c//(7*a+b) r = c%(7*a+b) d = (math.ceil(r/a)) if d>7: d = 7 d += 7*w print(d)
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input The first line contains integ...
3
n = int (input()) word = input() count = 0 for i in range(n - 1): if word[i] == word[i+1]: count += 1 print(count)
After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself. This means the process of eating candies is the following: in the beginning Vasya choos...
1
# always avoid floats (even in Python :( ) n = input() lo, hi = 1, n while lo < hi: mid = lo + (hi - lo) / 2 amt = n cnt = 0 k = mid while amt > 0: vas = min(amt, k) amt -= vas cnt += vas pet = amt // 10 amt -= pet if 2 * cnt >= n: hi ...
Screen resolution of Polycarp's monitor is a Γ— b pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates (x, y) (0 ≀ x < a, 0 ≀ y < b). You can consider columns of pixels to be numbered from 0 to a-1, and rows β€” from 0 to b-1. Polycarp wants to open a rectangular window of maximal size, which ...
3
for t in range(int(input())): a, b, x, y = map(int, input().split(" ")) print(max(x*b, b*(a-1-x), a*y, a*(b-1-y)))
You're given an array a of n integers, such that a_1 + a_2 + β‹…β‹…β‹… + a_n = 0. In one operation, you can choose two different indices i and j (1 ≀ i, j ≀ n), decrement a_i by one and increment a_j by one. If i < j this operation is free, otherwise it costs one coin. How many coins do you have to spend in order to make a...
3
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) s=0 for i in range(n): if a[i]>0:s+=a[i] else: mn=min(s,-a[i]) a[i]+=mn s-=mn print(sum(-min(i,0) for i in a))
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
import sys l = sys.stdin.readline() a = l[0] b = int(l[1]) moves = 0 if a == "a" or a == "h": if b == 8 or b == 1: moves = 3 else : moves = 5 else : if b == 8 or b == 1: moves = 5 else : moves = 8 print moves
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi. To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem...
3
L=lambda:list(map(int,input().split())) M=lambda:map(int,input().split()) I=lambda:int(input()) n,m=M() a=L() b=L() i,j=0,0 while(i<n and j<m): if b[j]>=a[i]: i+=1 j+=1 else: j+=1 print(n-i)
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 rep in range(t): n,m = list(map(int,input().split())) if n >= 3: print(2*m) elif n== 2: print(m) else: print(0)
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...
3
n = int(input()) print(max(n, int(str(n)[:-1]), int(str(n)[:-2] + str(n)[-1])))
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in. During his ride, Arkady woke up several time...
3
n = int(input()) x = list(input().split()[1:]) x = set(x) for i in range(n-1): y = list(input().split()[1:]) y = set(y) x = x&y for j in x: print(j, end=' ')
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
# f n = int(input()) answers = 0 for i in range(1,n+1): answer = input() num_of_1 = 0 for i in answer: if i == '1': num_of_1 += 1 if num_of_1 >= 2: answers += 1 print(answers)
Hooray! Polycarp turned n years old! The Technocup Team sincerely congratulates Polycarp! Polycarp celebrated all of his n birthdays: from the 1-th to the n-th. At the moment, he is wondering: how many times he turned beautiful number of years? According to Polycarp, a positive integer is beautiful if it consists of ...
3
t=int(input()) for i in range(t): a=input() b=len(a) n=int(a) if b==1: print(n) else: sum=(b-1)*9 c=int("1"*b) i=1 while c*i<=n: sum+=1 i+=1 print(sum)
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o...
3
a = [int(x) for x in input().split()] s = input() res = 0 for i in s: res += a[int(i) - 1] print(res)
Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow) * Procedure 1. If a certain integer n greater than or equal to 0 is ...
3
import sys # -*- coding: utf-8 -*- def multiple(target,count): length = len(target) result = [] if length == 1: return count for i in range(1,length): prefix = int(target[:i]) suffix = int(target[i:]) result.append(prefix*suffix) return multiple(str(max(result)), cou...
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of ea...
1
t= input() array = map(int,raw_input().split(" ")) total = len(array) part = 0 for k,v in enumerate(array): part += (v/100.0)/total print part*100
Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. Constraints * 0 \leq x \leq 1 * x is an integer Input Input is given from Standard Input in the following format: x Output Print 1 if x is equal to 0, or 0 if x is equal ...
3
N = int(input()) print((N-1)*-1)
This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the st...
3
import sys def input(): return sys.stdin.readline().strip() def dinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(str, tinput()) def rt(a, s): t = "" z = 0 x = len(a) y = len(s) while z < x and z < y: t = t + a[z] + s[z] ...
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...
1
a = list(raw_input()) b = list(raw_input()) c = sorted(list(raw_input())) ab = a + b if sorted(ab) == c: print "YES" else: print "NO"
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list. For ex...
3
a= int(input()) b = list(map(int,input().split())) b.sort(reverse = True) t = b[0] g = [] i=0 while(i!=len(b)): if (t%b[i]!=0)and b.count(b[i])==1: g.append(b[i]) elif b.count(b[i])==2: g.append(b[i]) b.remove(b[i]) i+=1 if(len(g)==0): print(b[0],b[1]) else: g.sort(re...
In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so ...
1
data = [] def is_connect(int1, int2): if (int1[0]<int2[1] and int1[0]>int2[0]) or (int1[1]<int2[1] and int1[1]>int2[0]): return True else: return False def is_link(start, end): def dfs(now, end): if now == end: return True mark.append(now) for i, v in e...
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
n = list(input()) x = list(input()) if n == x[::-1]: print("YES") else: print("NO")
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`. Constraints * |S|=3 * S consists of `a`, `b` and `c`. Input Input is given from Standard Input in the following format: S Output If S can be obtained by permuting `abc`, print `Yes`; otherwis...
1
s=raw_input() sa=0 sb=0 sc=0 for i in range(len(s)): if s[i]=="a": sa+=1 if s[i]=="b": sb+=1 if s[i]=="c": sc+=1 if sa==1 and sb==1 and sc==1: print "Yes" else: print "No"
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat. <image> There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ....
3
#fin=open("input.txt","r") n = int(input()) #n=int(fin.readline()) s = 0 mi= 1e9 a=0 p=0 #print("n:",n) for i in range(n): # print(" i:",i,"a:",a,"p:",p,"mi:",mi,"sss:",s) #a , p = map(int,fin.readline().split()) a,p=map(int,input().split()) mi=min(mi,p) s+=a*mi print(s) #fin.close()
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6. Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task! Each digit c...
3
import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read non spaced string and elements are integers to list of int get_intList_from_str = lambda: list(map(int,list(sys.stdin.read...
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
1
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import sys input = sys.stdin output = sys.stdout def solve(A): P = set() aa = [0]*8 for a in A: aa[:4] = a aa[4:] = a found = False for i in range(4): aaa = aa[i:i+4] if tuple(aaa) in P: f...
Mishka got an integer array a of length n as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: * Replace each occurre...
3
a=int(input()) b=map(int,input().split()) for i in b: print(i-1+i%2,end=" ")
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of ea...
3
n = int(input()) p = list(map(int, input().split())) print(sum(p)/(n*100)*100)
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
3
n=int(input()) a=list(map(int,input().strip().split())) count=0 for i in range(1,n-1): if (a[i]>a[i-1] and a[i]>a[i+1]) or (a[i]<a[i-1] and a[i]<a[i+1]): count=count+1 print(count)
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn. Nickolas adores permutations. He likes some permutations more than the o...
3
n=int(input()) if n % 2 != 0: print(-1) else: A = [] for i in range(n): if i % 2 == 0: A.append(i+2) else: A.append(i) print(*A)
Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought n integers, now it's time to distribute them between his friends rationally... Lee has n integers a_1, a_2, …, a_n in his backpack and he has k friends. Lee would like to distribute all integers in his backpack betwe...
3
import sys import math import itertools import functools import collections import operator import fileinput import copy ORDA = 97 # a def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return [int(i) for i in input().split()] def lcm(a, b): return abs(a * b) // math.gcd(a, b) def revn...
There are two sisters Alice and Betty. You have n candies. You want to distribute these n candies between two sisters in such a way that: * Alice will get a (a > 0) candies; * Betty will get b (b > 0) candies; * each sister will get some integer number of candies; * Alice will get a greater amount of candie...
3
T=int(input()) for i in range(T): n=int(input()) l=n//2+1 rem=0 if(l>1 and l<n): rem=n-l print(rem) else: print(0)
You've got a 5 Γ— 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
3
mat = [] for i in range(5): aux = input().split() mat.append(aux) for i in range(5): for j in range(5): if(mat[i][j] == '1'): print(abs(i - 2)+abs(j - 2)) i = 5 break
You are given a string s consisting of lowercase Latin letters and q queries for this string. Recall that the substring s[l; r] of the string s is the string s_l s_{l + 1} ... s_r. For example, the substrings of "codeforces" are "code", "force", "f", "for", but not "coder" and "top". There are two types of queries: ...
3
import sys input = sys.stdin.readline def make_tree(n): tree = [[0] * (n + 1) for _ in range(26)] return tree def get_sum(i, j): s = 0 while i > 0: s += tree[j][i] i -= i & -i return s def add(i, j, x): while i <= n: tree[j][i] += x i += i & -i s = ["?"] + lis...
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam. Some of them celebrated in the BugDonalds restaurant, some of them...
3
a,b,c,n = map(int, input().split()) f = n-(a+b-c) print(f if (a>=c and b>=c and f>0) else -1)
Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a table. Cans are numbered from left to right from 1 to n. Vasya has to knock down each can exactly once to finish the exercise. He is allowed to choose the order in which he wi...
3
##import sys ##sys.stdin=open('inputs.txt') T=int(input()) L=list(map(int, input().split())) rt=0 order= '' l=0 while l< len(L): c=-1 x=0 while x<len(L): if (c==-1 or L[x] > L[c]): c=x x+=1 order+= (str(c+1)) + ' ' rt+= l*L[c]+1 L[c]=0 l+=1 ...
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
3
print(input().replace('WUB',' '))
You are given a string s[1 ... n] consisting of lowercase Latin letters. It is guaranteed that n = 2^k for some integer k β‰₯ 0. The string s[1 ... n] is called c-good if at least one of the following three conditions is satisfied: * The length of s is 1, and it consists of the character c (i.e. s_1=c); * The lengt...
3
alp =['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] def gt(s,x): if len(s)==1: if alp[x]==s: return 0 else: return 1 else: l = len(s) req = alp[x]*(l//2) c1 = len([i for i in range(l//2) if...
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surfac...
1
""" // Author : snape_here - Susanta Mukherjee // Date : 27/07/2019 """ from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip else: _st...
Little C loves number Β«3Β» very much. He loves all things about it. Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution. Input A single line containing one integer n (3 ≀ n ≀ 10^9) β€” the integ...
3
from sys import stdin A = int(stdin.readline()) if A%3==2: print(1,2,A-3) else: print(1, 1, A - 2)
Sereja has got an array, consisting of n integers, a1, a2, ..., an. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: 1. Make vi-th array element equal to xi. In other words, perform the assignment avi = xi. 2. Increase each array element by yi....
1
import sys n, m = [int(el) for el in sys.stdin.readline().split()] a = [int(el) for el in sys.stdin.readline().split()] change = {} y = [] sumy = 0 lasty = 0 for i in xrange(m): ins = [int(el) for el in sys.stdin.readline().split()] add = ins[1] if ins[0] == 2 else 0 y.append(add + lasty) if ins[0] ...
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
print(min(c - i for i, c in enumerate(map(int, input().split()), -1)) * 3)
Given is a sequence of integers A_1, A_2, ..., A_N. If its elements are pairwise distinct, print `YES`; otherwise, print `NO`. Constraints * 2 ≀ N ≀ 200000 * 1 ≀ A_i ≀ 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output If the elements...
3
n = int(input()) s = set(map(int, input().split())) print("YES" if len(s) == n else "NO")
Ilya plays a card game by the following rules. A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number ai, and the bottom co...
1
from operator import itemgetter n=input() A=[ map(int,raw_input().split()) for i in range(n) ] A.sort(key=itemgetter(1,0)) c=1 p=0 for x in A[::-1]: if c==0: break p+=x[0] c-=1 c+=x[1] print p
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies. Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. ...
1
a,b = map(int,raw_input().split()) t = map(int,raw_input().split()) t = map(lambda x: x/b if x%b==0 else x/b+1,t) M=0 for i in t: M=max(M,i) for i in range(len(t)): if(t[i]==M) : ans=i print ans+1
You are given two integers a and m. Calculate the number of integers x such that 0 ≀ x < m and \gcd(a, m) = \gcd(a + x, m). Note: \gcd(a, b) is the greatest common divisor of a and b. Input The first line contains the single integer T (1 ≀ T ≀ 50) β€” the number of test cases. Next T lines contain test cases β€” one pe...
3
def gcd(a,b): while a != 0: a,b = b % a,a return b def phi(a): tmp,ans = a,a d = 2 while d*d <= tmp: cnt = 0 while tmp % d == 0: tmp /= d cnt += 1 if cnt > 0: ans -= ans/d d += 1 if tmp > 1: ans -= ans/tmp ...
You are given a rectangular board of M Γ— N squares. Also you are given an unlimited number of standard domino pieces of 2 Γ— 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squa...
1
M, N = [int(x) for x in raw_input().split()] print (N/2) * (M/2) * 2 + [0, N/2][M%2] + [0, M/2][N%2]
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n. Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes). Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} ...
3
'''test=int(input()) for i in range(test): a,b,c,d=[int(i) for i in input().split(" ")] x,y,x1,y1,x2,y2=[int(i) for i in input().split(" ")] ans1=0 ans2=0 if abs(x-x1)>=a and abs(x2-x)>=b: ans1=1 elif abs(x-x1)>=a: if abs(x2-(x-a))>=b: ans1=1 elif abs(x2-x)>=b: ...
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: 1. Subtract 1 from x. This operation costs you A coins. 2. Divide x by k. Can be performed...
3
n = int(input()) k = int(input()) a = int(input()) b = int(input()) x = n ans = 0 while x > 1: if x % k == 0 and k != 1: case1 = b case2 = (x - x // k) * a # if case1 < case2: ans += min(case1, case2) x = x // k elif x >= k and k != 1: ans += (x % k) * a ...
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
3
name = set(input()) if len(name)%2 == 0: res = 'CHAT WITH HER!' else: res = 'IGNORE HIM!' print(res)
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like...
3
a, b = map(int, input().split()) c = a while a // b: c += a // b a = a//b + a % b print(c)
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth fl...
1
build = range(1, 5) floor = range(1, 4) dic = {b: {f: [0]*10 for f in floor} for b in build} n = input() for i in range(n): info = map(int, raw_input().split()) dic[info[0]][info[1]][info[2]-1] += info[3] if dic[info[0]][info[1]][info[2]-1] > 9: print 'error' for b in build: for f in floor: ...
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the root of the tree. Alice starts at vertex 1 and Bob starts at vertex x (x β‰  1). The moves are made in turns, Bob goes first...
3
import sys input = sys.stdin.buffer.readline from collections import deque def prog(): n,x = map(int,input().split()) adj = [[] for i in range(n + 1)] for i in range(n-1): u,v = map(int,input().split()) adj[u].append(v) adj[v].append(u) dist = [0]*(n+1) parent = [0]*(n+1...
Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In...
1
# Authored by dolphinigle def main(): n = int(raw_input()) maxsize = 0 que = [] posq = 0 curtime = 0 lasttime = 0 itus = [] for _ in range(n): itus.append(map(int, raw_input().split())) itus.append((1020000000000000, 0)) for t, c in itus: while posq < len(que) and curtime < t: if not...
problem JOI decided to play a game with his friends. N players participate in this game. The rules for a single game are as follows: Each player writes a favorite integer from 1 to 100 on the card and submits it. Each player gets the same score as he wrote if no one else wrote the same number. If there is another per...
3
n=int(input()) l=[[int(s) for s in input().split(" ")]for i in range(n)] pts=[0 for i in range(n)] for i in range(3): dct={} nums=[sl[i] for sl in l] for num in nums: if num in dct:dct[num]+=1 else:dct[num]=1 for p in range(n): if dct[nums[p]]==1:pts[p]+=nums[p] for point in pts:...
Smaug, the dragon, rules under The Mountain, Erabor which was originally the ruling place of Dwarf King. King Thorin, who is the rightful heir to the throne is on his way to take back his kingdom from Smaug. With the help of a map, King Thorin is able to find a secret entry into the mountain. But now when he has reache...
1
lis=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] a=raw_input().strip() leng=len(a) count=0 if(leng%2==1): count+=1 flag=1 for i in lis: k=a.count(i) if(k%2==1): if(count>0): count-=1 else: flag=0 break if(flag==1): print "YES" else: print "N...
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number. Constraints * 1?N?10^8 * N is an integer. Input Input is given from Standard Input in the following format: N Output...
3
n=input() s=sum([int(s) for s in n]) print("Yes"if int(n)%s==0 else "No")
You are both a shop keeper and a shop assistant at a small nearby shop. You have n goods, the i-th good costs a_i coins. You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More precisely you decided to set the same price for all n goods you have. ...
3
t=int(input()) for i in range(0,t): n=int(input()) sum=0 a=list(map(int,input().split())) for j in range(0,n): sum=sum+a[j] if(sum%n==0): ans=sum//n else: ans=sum//n+1 print(ans)
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly x. the MEX of ...
3
n,x=map(int,input().split()) ans=0 a=list(map(int,input().split())) for i in range(x): if not i in a: ans+=1 print(ans+(1 if x in a else 0))
Square Route Square root English text is not available in this practice contest. Millionaire Shinada, who has decided to build a new mansion, is wondering in which city to build the new mansion. To tell the truth, Mr. Shinada is a strange person who likes squares very much, so he wants to live in a city with as many...
3
import collections def accumulate(a): sum = 0 result = [0] for x in a: sum += x result.append(sum) return result def aggregate(a): result = [] for j in range(len(a)): for i in range(j): result.append(a[j] - a[i]) return result while True: H, W = map(int, input().split()) if H == 0: break h = [int...
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The ...
3
#http://codeforces.com/problemset/problem/381/A def game_score(ls): s_score,d_score = 0, 0 l = 0 r = len(ls) - 1 #Sereja turn: 0 #Dima turn: 1 turn = 0 card = 0 while (l <= r): if ls[l] > ls[r]: card = ls[l] l += 1 else: card ...
You are given an integer n. You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times: 1. Replace n with n/2 if n is divisible by 2; 2. Replace n with 2n/3 if n is divisible by 3; 3. Replace n with 4n/5 if n is divisible by 5. For example, you can repl...
1
for _ in range(input()) : num = input() count = 0 while num % 3 == 0 : num = num / 3 count += 2 while num % 5 == 0 : num = num / 5 count += 3 while num % 2 == 0 : num = num / 2 count += 1 if num == 1 : print count else : ...
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 = str(input('')).split('+') nums = {1:0,2:0,3:0} for n in s: nums[int(n)] += 1 res = '1+'*nums[1] + '2+'*nums[2] + '3+'*nums[3] if len(res) > 0: res = res[0:-1] print(res)
AquaMoon had n strings of length m each. n is an odd number. When AquaMoon was gone, Cirno tried to pair these n strings together. After making (n-1)/(2) pairs, she found out that there was exactly one string without the pair! In her rage, she disrupted each pair of strings. For each pair, she selected some positions...
3
import os import sys from collections import Counter for t in range(int(input())): n,m = map(int, input().split()) s,a = [],[] for i in range(2 * n - 1): if i < n: s.append(input()) else: a.append(input()) aa = [dict(Counter([i[j] for i in a])) for j in range(m)]...
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." <image> The problem is:...
3
luck=input() extra=['7'] luck = list(luck) luck= extra + luck n=len(luck) i=0 pos=0 while i<n: if luck[n-i-1]=='7': pos=pos+2**i i=i+1 pos=pos-1 print(pos) i=0
Your favorite shop sells n Kinder Surprise chocolate eggs. You know that exactly s stickers and exactly t toys are placed in n eggs in total. Each Kinder Surprise can be one of three types: * it can contain a single sticker and no toy; * it can contain a single toy and no sticker; * it can contain both a sing...
3
a = input() a = int(a) content = [] for i in range(a): x = input() content.append(x) for i in range(a): content[i] = content[i].split() #print (content) for i in content: worst=min(int(i[1]), int(i[2])) print (int(i[0])-worst+1)
A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array). For a positive integer n, we call a...
3
from sys import stdin from collections import defaultdict import math input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) print(*range(1, n + 1))
You are given a rectangular board of M Γ— N squares. Also you are given an unlimited number of standard domino pieces of 2 Γ— 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squa...
3
m, n = [int(i) for i in input().split()] t = m * n s = int(t/2) print(s)
Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs n actions. The first action performed is to put a single candy into the box. For each of the remainin...
3
import sys import math input=sys.stdin.readline n,k=map(int,input().split()) ans=-1 for i in range(int(math.sqrt(2*(n+k)))): if((i*(i+3))//2==(n+k)): ans=n-i print(ans)