problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: * the length of the password must be equal to n, * the password should con...
3
s='abcdefghijklmnopqrstuvwxyz' n,k=map(int,input().split()) s=s[:k] print(s*(n//k)+s[:n%k])
One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point (x1, y1...
1
from sys import stdin rints = lambda: [int(x) for x in stdin.readline().split()] x1, y1, z1 = rints() x, y, z = rints() a = rints() print(sum([a[0] * (y1 < 0), a[1] * (y1 > y), a[2] * (z1 < 0), a[3] * (z1 > z), a[4] * (x1 < 0), a[5] * (x1 > x)]))
You are given two arrays of integers a_1,…,a_n and b_1,…,b_m. Your task is to find a non-empty array c_1,…,c_k that is a subsequence of a_1,…,a_n, and also a subsequence of b_1,…,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, f...
3
for _ in range(int(input())): n,m=map(int,input().split()) lis1=list(map(int,input().split())) lis2=list(map(int,input().split())) flag=0 for i in range(n): for j in range(m): if lis1[i]==lis2[j]: print("YES") print('1',lis1[i],sep=' ') ...
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s. You have to answer t independent test cases. Input The first line of the input co...
3
for _ in range(int(input())): a,b=map(int,input().split()) x=a%b if a==b or x==0: print(0) elif a>b and b==1: print(0) elif a>b: print(str(b-x)) else: print(str(abs(b-a)))
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 _ in range(int(input())): n,k=map(int,input().split()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] b.sort(reverse=True) s=a+b[:k] #print(s) s.sort(reverse=True) print(sum(s[:n]))
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. Constrain...
3
import re s = input() if re.search('^(dreamer|eraser|dream|erase)*$', s): print('YES') else: print('NO')
For the given integer n (n > 2) let's write down all the strings of length n which contain n-2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order. Recall that the string s of length n is lexicographically less than string t of length n, if there exists such i (1 ≤ i ≤ n), that s_i < t_i, and for a...
3
t = int(input()) for q in range(t): n, k = map(int, input().split()) pi = 0 x = 0 while pi < k : x += 1 pi += x list = [] for i in range(0,n): list.append("a") for j in range(0,n): if j == x: list[n-j-1] = "b" for j in range(0, n): if j == x -(pi-k): list[n-j] = "b" str= ""...
Shichikuji is the new resident deity of the South Black Snail Temple. Her first job is as follows: There are n new cities located in Prefecture X. Cities are numbered from 1 to n. City i is located x_i km North of the shrine and y_i km East of the shrine. It is possible that (x_i, y_i) = (x_j, y_j) even when i ≠ j. S...
1
import sys range = xrange input = raw_input def mergesort(A1, A2): B1 = A1[:] B2 = A2[:] n = len(A1) for i in range(0, n - 1, 2): if A1[i] > A1[i ^ 1]: A1[i], A1[i ^ 1] = A1[i ^ 1], A1[i] A2[i], A2[i ^ 1] = A2[i ^ 1], A2[i] width = 2 while width < n: fo...
There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins. Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different col...
3
import heapq X,Y,Z = map(int,input().split()) N = X+Y+Z src = [tuple(map(int,input().split())) for i in range(N)] src.sort(key=lambda x:x[0]-x[1]) l_opt = [0]*(N+1) r_opt = [0]*(N+1) silver = bronze = 0 q_sb = [] heapq.heapify(q_sb) for i,(g,s,b) in enumerate(src): heapq.heappush(q_sb, (s-b, s, b)) silver += ...
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo...
1
def fact(i): if(i==1): return 1 return i*fact(i-1) a,b=map(int,raw_input().split()) t=min(a,b) print fact(t)
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1. Constraints * 1\leq N,K\leq 100 * N and K are integers. Input Input is given from Standard Input in the following format: N K Output If we can choose K integers as above, print `YES`; otherwise, prin...
1
# -*- coding: utf-8 -*- import array import bisect import collections import fractions import heapq import itertools import math import re import string class joshu: # stdio @staticmethod def getInt(): return int(raw_input().strip()) @staticmethod def getInts(): return [int(i) for i in raw_input()...
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. <image> The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has t...
3
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin....
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()) arr = map(int, input().split()) vols = sum(arr) cans = sorted(list(map(int, input().split()))) max_can = cans[-1] + cans[-2] if (vols <= max_can): print("YES") else: print("NO")
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
cal = list(map(int, input().split())) str1 = input() sum = 0 for i in str1: sum += cal[int(i) - 1] print(sum)
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr...
3
# -*- coding: utf-8 -*- """ Created on Tue Oct 20 15:29:15 2020 @author: Cui Shiao """ m=input().lower() n=input().lower() k=0 for x in range(len(m)): if ord(m[x]) > ord(n[x]): k+=1 break elif ord(m[x]) < ord(n[x]): k-=1 break print(k)
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates. You can perform each of the two following types of moves any (possibly, zero) number of times on any chip: * Move the chip i by 2 to the left or 2 to the right for free (i.e. replace...
3
import os import sys from io import BytesIO, IOBase def solution(n, arr): odds = sum(1 for x in arr if x & 1 == 1) eves = n - odds write(min(odds, eves)) def main(): n = r_int() arr = r_array() solution(n, arr) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self,...
A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true: * Employee A is the immediate manag...
1
n = int(raw_input()) a = [0,] b = [0 for i in range(n+1)] for i in range(n): a.append(int(raw_input())) maxCur = 0 for i in range(1,n+1): t = i cur = 1 while a[t] != -1: b[t] = 1 t = a[t] cur += 1 if cur > maxCur: maxCur = cur print maxCur
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
x=int(input()) ans=1-x print(int(ans))
You are given an array a of length n. You are also given a set of distinct positions p_1, p_2, ..., p_m, where 1 ≤ p_i < n. The position p_i means that you can swap elements a[p_i] and a[p_i + 1]. You can apply this operation any number of times for each of the given positions. Your task is to determine if it is poss...
3
for _ in range(int(input())): m,n = map(int,input().split()) a = list(map(int,input().split())) p = list(map(int,input().split())) b = a.copy() b.sort() if a == b: print('YES') else: for i in range(n): for j in p: if (a[j] < a[j-1]): ...
Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order...
3
s=input() ans=s.split('@') f=[] for i in ans: f.append(len(i)) flag=0 for p in range(1,len(f)-1): if f[p]<=1: flag=1 break if f[0]<=0: flag=1 if f[-1]<1: flag=1 if s.count('@')==0: flag=1 if flag==1: print('No solution') else: res=list(s) y=[] ...
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a. What is the least number of flagstones needed to pave the Square? It'...
3
x = [] n,m,a = map(int,input().split()) if a == 1: x.append(n) elif n % a == 0: x.append(n / a) elif a >= (n / 2) and a < n: x.append(2) elif a <= (n / 2) and a < n: x.append((n // a) + 1) elif a >= n: x.append(1) if a == 1: x.append(m) elif m % a == 0: x.append(m / a) elif a >= (m / 2) a...
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...
3
str_0=input() list_0=list(str_0) def allup(list_0): for i in list_0: if ord(i)>90: return False return True def firstup(list_0): if ord(list_0[0])>90: for i in list_0[1:]: if ord(i)>90: return False return True else: return False...
The only difference between easy and hard versions is the size of the input. You are given a string s consisting of n characters, each character is 'R', 'G' or 'B'. You are also given an integer k. Your task is to change the minimum number of characters in the initial string s so that after the changes there will be ...
3
""" Satwik_Tiwari ;) . 12th july , 2020 - Sunday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, I...
There are N towns in the State of Atcoder, connected by M bidirectional roads. The i-th road connects Town A_i and B_i and has a length of C_i. Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order). She will fly to the first town she visits, and fly back from the last town she visi...
1
import sys import itertools N,M,R=map(int, raw_input().split()) d=[ [ float("inf") for j in range(N+1) ] for i in range(N+1) ] for i in range(N+1): d[i][i]=0 r=map(int, sys.stdin.readline().split()) for _ in range(M): a,b,c=map(int, sys.stdin.readline().split()) d[a][b]=c d[b][a]=c for i in range(1,N+1): f...
Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aa...
3
import sys input = sys.stdin.readline S = list(input())[: -1] K = int(input()) a = ord("a") N = len(S) for i in range(N): x = ord(S[i]) if K >= (a - x) % 26: K -= (a - x) % 26 S[i] = "a" S[-1] = chr((ord(S[i]) - a + K % 26) % 26 + a) print("".join(S))
On a strip of land of length n there are k air conditioners: the i-th air conditioner is placed in cell a_i (1 ≤ a_i ≤ n). Two or more air conditioners cannot be placed in the same cell (i.e. all a_i are distinct). Each air conditioner is characterized by one parameter: temperature. The i-th air conditioner is set to ...
3
t = int(input()) INF = 9 * 10**9 for _ in range(t): input() n, k = [int(x) for x in input().split()] a = [int(x)-1 for x in input().split()] t = [int(x) for x in input().split()] cond = [(a[i], t[i]) for i in range(k)] cond.sort() res = [INF for _ in range(n)] for mult, idx, ai in [(1, 0...
You are given n strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String a is a substring of string b if it is possible to choose several consecutive letters in b in such a way...
3
import sys n=int(input()) L=[] for _ in range(n): L.append(input()) for i in range(n-1): for j in range(i+1,n): if len(L[i])>len(L[j]): temp=L[i] L[i]=L[j] L[j]=temp for i in range(n-1): if L[i+1].find(L[i])==-1: print("NO") sys.exit(0) p...
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
# -*- coding: utf-8 -*- """ Created on Sat Oct 17 10:47:53 2020 @author: alber """ def checar(numero1, numero2): lista = range(numero1,numero2+1) for i in lista: if len(str(i)) == len(set(str(i))): return i return -1 numero1, numero2 = lis...
Omkar is building a waterslide in his water park, and he needs your help to ensure that he does it as efficiently as possible. Omkar currently has n supports arranged in a line, the i-th of which has height a_i. Omkar wants to build his waterslide from the right to the left, so his supports must be nondecreasing in he...
3
#asd def sol(l): ans = 0 for i in range(1,len(l)): ans+=max(l[i-1]-l[i],0) print(ans) k = int(input()) for i in range(k): input() lis =list(map(int,input().split(' '))) sol(lis)
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
inpt = list(map(int,input().split())) M = inpt[0] N = inpt[1] print((M*N)//2)
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many ...
3
n,k=input().split() n,k=[int(n), int(k)] count=0 scores=input().split() for i in range(len(scores)): scores[i]=int(scores[i]) for i in range(len(scores)): if scores[i]>=scores[k-1] and scores[i]>0: count=count+1 print(count)
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t...
3
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) b.sort() b = b[::-1] count = 0 for i in range(n): if a [i] == 0: a[i] = b[count] count += 1 x = a + [] a.sort() if x == a: print('No') else: print('Yes')
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting e...
3
a = int(input()) b = int(input()) c = int(input()) m = max(a + b + c, a + b * c, a * b + c, a * b * c, (a + b) * c, a * (b + c)) print(m)
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
1
print "YES" if (sum(1 for ch in raw_input() if ch == '4' or ch == '7') in [4,7]) else "NO"
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon p...
3
n, k = map(int, input().split()) arr = [[], [], [], []] for i in range(4): for j in range(n): arr[i] += ["."] if k % 2 == 0: as_far = k // 2 for i in range(1, 3): for j in range(1, as_far + 1): arr[i][j] = "#" else: if k > n - 2: as_far_down = 3 else: as_f...
Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters. In this problem you should implement the similar functionality. You are given a string which only consists of: * uppercase and lowercase English...
3
import math import time from collections import defaultdict,deque from sys import stdin,stdout from bisect import bisect_left,bisect_right n=int(input()) s=input() bracket=False bracword=0 maxword=0 temp=0 for i in s: if(i=="_"): if(not bracket): maxword=max(temp,maxword) temp=0 ...
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and pl...
3
a,b,c,d=map(int,input().split()) print('Left' if((a+b)>(c+d)) else 'Right' if((a+b)<(c+d)) else 'Balanced' )
You are given strings s and t. Find one longest string that is a subsequence of both s and t. Constraints * s and t are strings consisting of lowercase English letters. * 1 \leq |s|, |t| \leq 3000 Input Input is given from Standard Input in the following format: s t Output Print one longest string that is a su...
3
s1=input() s2=input() l1=len(s1) l2=len(s2) dp=[[0 for i in range(l2+1)] for j in range(l1+1)] for i in range(1,l1+1): for j in range(1,l2+1): if s1[i-1]==s2[j-1]: dp[i][j]=1+dp[i-1][j-1] else: dp[i][j]=max(dp[i-1][j],dp[i][j-1]) i=l1;j=l2 ans="" while(i>0 and j>0): if s1...
Write a program which reads an integer and prints sum of its digits. Input The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000. The input ends with a line including single zero. Your program should not process for this terminal ...
3
while(True): n = input() if n == "0": break print(sum(map(int, n)))
Lee is going to fashionably decorate his house for a party, using some regular convex polygons... Lee thinks a regular n-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the OX-axis and at least one of its edges is parallel to the OY-axis a...
3
t=int(input()) for k in range(t): n=int(input()) print('NO' if n%4 else 'YES')
Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level. All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases...
3
for _ in range(int(input())): n = int(input()) first = input().split() plays, clears = int(first[0]), int(first[1]) possible = True if clears > plays: possible = False for i in range(n - 1): value = input().split() current_plays, current_clears = int(value[0]), int(value[...
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins. He wants to distribute all these n coins between his sisters in such a way that ...
3
for _ in range(int(input())): a=list(map(int,input().split())) x=a[3] a.remove(a[3]) m=max(a) s=0 for i in range(3): s+=(m-a[i]) p=x-s if(p<0): print("NO") elif(p%3==0): print("YES") else: print("NO")
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
l, r = [int(_) for _ in input().split()] for i in range(l, r + 1): if len(str(i)) == len(list(set(list(str(i))))): print(i) break else: print(-1)
We will define the median of a sequence b of length M, as follows: * Let b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down. For example, the median of (10, 30, 20) is 20; the median of ...
3
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() class BIT(object): def __init__(self,A,dot=lambda x,y:x+y,e=0,inv=None): ...
You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists. You have to answer t independent test cases. Recall that the substring s[l ...
3
for t in range(int(input())): n,a,b = map(int,input().split()) s='' x='a' for i in range(b): s+=chr(ord(x)+i) res='' for i in range(n): res+=s[i%len(s)] print(res)
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement ...
1
l = int(raw_input()) print "", for i in range(l+1): if i//3 != 0: if i%3 ==0: print i, elif "3" in str(i): print i,
Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: * Extract the first character of s and append t with this character. * Extract the last character of t and append u with this ...
1
from collections import Counter s=raw_input() t=[] u=[] s=list(s) cc=dict(Counter(s)) f=sorted(list(set(s))) ch=f[0] k=0 for i in range(len(s)): t.append(s[i]) cc[s[i]]-=1 while cc[ch]==0: k+=1 try: ch=f[k] except: break while t[-1]<=ch: gg=t.pop()...
Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions: 1. The coordinates of each point in the set are integers. 2. For any two points from the set, the distance between them is a non-integer. Consider all poi...
3
import re, sys, string, operator, functools, fractions, collections sys.setrecursionlimit(10**7) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] RI=lambda x=' ': list(map(int,input().split(x))) RS=lambda x=' ': input().rstrip().split(x) mod=int(1e9+7) eps=1e-6 ###############################################...
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel. Ari draws a regular convex polygon on the floor and numbers it's vertices 1, 2, ..., n in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex...
3
n = int(input()) col = 1 + 3 * (n - 3) + (n - 4) * (n - 3) print(col)
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...
3
s=input() b=s.split(' ') h=float(b[0]) l=float(b[1]) print((l**2-h**2)/(2*h))
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of dama...
3
import sys def ans(s): print(s) sys.exit() a, b, c = map(int, input().split()) if c % a == 0: ans('Yes') while c > 0: if c % b == 0: ans('Yes') c -= a ans('No')
There are n points on the plane, (x_1,y_1), (x_2,y_2), …, (x_n,y_n). You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle. I...
3
A = [] T = int(input()) for i in range (T): A.append(sum([int(x) for x in input().split()])) print(max(A))
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now? Constrai...
3
sum=0 for _ in range(int(input())): a,b=map(int,input().split()) sum+=b-a+1 print(sum)
"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
a = list(map(int, input().strip().split())) n = list(map(int, input().strip().split()))[:a[0]] i = 0 while i < len(n): if n[i] == 0: break if n[i] < n[a[1]-1]: break i += 1 print(i)
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
def hulk(n, flag): if n == 1: if flag: return "I hate it" else: return "I love it" if flag: flag = False return "I hate that " + hulk(n - 1, flag) else: flag = True return "I love that " + hulk(n - 1, flag) print(hulk(int(input()), Tru...
You have a bag of size n. Also you have m boxes. The size of i-th box is a_i, where each a_i is an integer non-negative power of two. You can divide boxes into two parts of equal size. Your goal is to fill the bag completely. For example, if n = 10 and a = [1, 1, 32] then you have to divide the box of size 32 into tw...
3
import sys from collections import defaultdict def get(dic,tar,b): #print(dic,'dic') #print(tar,'tar') #print(b,'b') s=bin(tar) n=len(s) num=1<<(n-2) ans=0 temp=defaultdict(int) for i in range(n-1,1,-1): if s[i]=='1': num=1<<(n-i-1) #print(num,'num',an...
An n × n table a is defined as follows: * The first row and the first column contain ones, that is: ai, 1 = a1, i = 1 for all i = 1, 2, ..., n. * Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defin...
3
def get_value(x, y): if x==0 or y==0: return 1 else: return get_value(x-1, y) + get_value(x, y-1) n = int(input()) print(get_value(n-1, n-1))
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said: —Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes....
1
def test(n, m): if n == 0: return m == 0 nl = list(n) nl.sort() for i in range(0, len(nl)): if nl[i] != '0': if i != 0: nl[0], nl[i] = nl[i], nl[0] break return nl == list(m) n = raw_input() m = raw_input() # can be 000123123...
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
3
n=int(input()) if (2**n%24)>8: print("YES") else: print("NO")
You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D ≥ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i. e. perform a_i := a_i - D, or * leave the value of a_i unchanged. It is...
3
n = int(input()) arr = set(map(int, input().split())) if len(arr)>3: print("-1") elif len(arr) == 3: a = max(arr) arr.remove(a) b = min(arr) arr.remove(b) if (a+b)//2 == max(arr) and (a+b)%2 == 0: print(max(arr)-b) else: print("-1") elif len(arr) == 2: if (min(arr) + max(...
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...
1
input() d={} d['A']=0 d['D']=0 for i in raw_input().strip(): d[i]+=1 if d['A']>d['D']: print "Anton" elif d['A']==d['D']: print "Friendship" else: print "Danik"
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
3
import math a=int(input()) b=input().split() one=0 two=0 three=0 four=0 for i in range(0,a): if int(b[i])==1: one+=1 if int(b[i])==2: two+=1 if int(b[i])==3: three+=1 if int(b[i])==4: four+=1 if one > 2*(two%2) + three: k=four+three+math.ceil(two/2)+math.ceil((one-2*(...
There are N cubes stacked vertically on a desk. You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is `0`, and blue if that character is `1`. You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent...
1
#abc120c s=raw_input() print min(s.count('0'),s.count('1'))*2
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
s = int(input()) j = [] if 8977 <= s <= 9000: print(9012) quit() for e in range(1000, 9000): e = str(e) if e[0] != e[1] and e[0] != e[2] and e[0] != e[3] and e[1] != e[2] and e[1] != e[3] and e[2] != e[3]: j.append(int(e)) if s not in j: j.append(s) j.sort() i = j.index(s) print(j[i+1])
Alice and Bob play a game. They have a binary string s (a string such that each character in it is either 0 or 1). Alice moves first, then Bob, then Alice again, and so on. During their move, the player can choose any number (not less than one) of consecutive equal characters in s and delete them. For example, if the...
3
for _ in range(int(input())): l = input() s = [] c = 0 for i in l: if i == '0': s.append(c) c = 0 else: c += 1 if l[-1] == '1': s.append(c) s.sort(reverse=True) print(sum(s[0::2]))
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 index in range(0,n): str=input() if(str=="++X" or str=="X++"): x+=1 if(str=="--X" or str=="X--"): x-=1 print(x)
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
3
n = int(input()) lst = [int(x) for x in str(n)] count = 0 for i in lst: if i == 4 or i == 7: count+=1 if count==7 or count==4: print("YES") else: print("NO")
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose s...
3
# import sys import math # input=sys.stdin.buffer.readline t=int(input()) def ret(l): if l == "2": return "1" else: return l for _ in range(t): sudoku=[] for i in range(9): row=[ret(c) for c in input()] print("".join(row))
You are given three positive (i.e. strictly greater than zero) integers x, y and z. Your task is to find positive integers a, b and c such that x = max(a, b), y = max(a, c) and z = max(b, c), or determine that it is impossible to find such a, b and c. You have to answer t independent test cases. Print required a, b a...
3
t=int(input()) for i in range(t): temp=input() temp=temp.split() x=int(temp[0]) y=int(temp[1]) z=int(temp[2]) if x==y and z<=y: print('YES') print(x, z, z) elif y==z and x<=y: print("YES") print(y, x, x) elif x==z and y<=z: print("YES") print(x, y, y) else: print('NO...
Phoenix has n blocks of height h_1, h_2, ..., h_n, and all h_i don't exceed some value x. He plans to stack all n blocks into m separate towers. The height of a tower is simply the sum of the heights of its blocks. For the towers to look beautiful, no two towers may have a height difference of strictly more than x. P...
3
g = int(input()) import heapq while g>0: g -= 1 print('YES') n,m,x = map(int, input().split()) a = list(map(int, input().split())) pq = [] for i in range(m): heapq.heappush(pq, (0,i)) for i in a: mi = heapq.heappop(pq) print(mi[1]+1) heapq.heappush(pq, (mi[0]+...
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if...
3
if __name__ == "__main__": s = input() h = "hello" i = 0 for c in s: if c == h[i]: i += 1 if i == 5: print("YES") break else: print("NO")
Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to trans...
3
a,b=map(int,input().split()) c=b/a ans=0 k=0 while c!=1: if c%6==0: ans+=2 c/=6 elif c%2==0: ans+=1 c/=2 elif c%3==0: ans+=1 c/=3 else: print(-1) k=1 break if k==0: print(ans)
You are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation. * Choose 2 ≤ k ≤ n and split the deck in k nonempty contiguous parts D_1, D_2,..., D_k (D_1 contains the first |D_1| cards of the deck, D_2 contains the f...
3
from sys import stdin n = int(stdin.readline()) cards = list(int(x) for x in stdin.readline().split()) def to_right(minimum, cards): idx = cards.index(minimum) output = [1] * (n-minimum) if idx-n+minimum+1 != 0: output.append(idx-n+minimum+1) if n-idx-1 != 0: output.append(n-idx-1) ...
One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task. Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following...
3
n,k=map(int,input().split()) f=sorted(list(map(int,input().split()))) ans=0 for i in range(n-1,-1,-k): ans+=2*(f[i]-1) print(ans)
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
3
a = int(input()) if a % 2 == 0 and a != 0 and a != 2: print('YES') else: print('NO')
You are given a string s consisting of |s| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number of ...
1
input_arr = raw_input() items = "abcdefghijklmnopqrstuvwxyz0" ans = [] for i in input_arr: if items != "0" and items[0] >= i: ans.append(items[0]) items = items[1:] else: ans.append(i) if items == "0": print ''.join(ans) else: print -1
Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate. The path consists of n consecutive tiles, numbered from 1 to n. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles wit...
3
n=int(input()) a=0 for i in range(2,int(n**0.5)+1): if n%i==0: a=1 break if a==0: print(n) else: import math l=[] # Function to calculate all the prime # factors and count of every prime factor count = 0; # count the number of # times 2 divides while (...
You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D ≥ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i. e. perform a_i := a_i - D, or * leave the value of a_i unchanged. It is...
3
n = int(input()) m = list(map(int,input().split())) s = 0 d = {} for i in range(n): if(m[i] not in d.keys()): d[m[i]] = 1 t = len(d.keys()) if(t > 3): print(-1) elif(t == 1): print(0) elif(t == 2): l = list(d.keys()) l.sort() a = l[0] b = l[1] x = a+b if(x%2 == 0): d ...
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
coord = int(input()) steps = coord // 5 steps += 1 if coord % 5 != 0 else 0 print(steps)
You are given two sequences a_1, a_2, ..., a_n and b_1, b_2, ..., b_n. Each element of both sequences is either 0, 1 or 2. The number of elements 0, 1, 2 in the sequence a is x_1, y_1, z_1 respectively, and the number of elements 0, 1, 2 in the sequence b is x_2, y_2, z_2 respectively. You can rearrange the elements i...
3
for i in range(int(input())): a,b,c=map(int,input().split()) d,e,f=map(int,input().split()) g=min(c,e) r=g*2 c=c-g e=e-g if(a+c>=f): print(r) else: f=f-(a+c) r=r-(2*f) print(r)
Seen from above, there is a grid-like square shaped like Figure 1. The presence or absence of "walls" on each side of this grid is represented by a sequence of 0s and 1s. Create a program that stands at point A, puts your right hand on the wall, keeps walking in the direction of the arrow, and outputs the route to retu...
3
g=[[0]*5 for _ in[0]*5] for i in range(9): e=input() for j in range(4+i%2): if int(e[j]): if i%2:g[i//2][j]+=4;g[i//2+1][j]+=1 else:r=g[i//2];r[j]+=2;r[j+1]+=8 y,x=0,1 k=1 a=[1] while 1: k+=2 for _ in[0]*4: k+=1 if g[y][x]&int(2**(k%4)):a+=[k%4];break if k%2:x+=1-2*((k%4)>1) else:y+=2*((k%4)>0)-1 if ...
Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She w...
3
n, r =map(int, input().split()) l = list(map(int, input().split())) ans = [r] * n for i in range(n): for j in range(i): if 4 * r ** 2 - (max(l[i], l[j]) - min(l[i], l[j])) ** 2 >= 0: y = 4 * r ** 2 - (max(l[i], l[j]) - min(l[i], l[j])) ** 2 ans[i] = max(ans[i], ans[j] + y ** 0.5) pri...
On her way to programming school tiger Dasha faced her first test — a huge staircase! <image> The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — th...
1
a, b = map(int, raw_input().split()) print "NO" if abs(a-b) > 1 or (a, b) == (0, 0) else "YES"
Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element among all k-element subsets. But only function does not interest him. He wan...
1
from sys import stdin from itertools import repeat def main(): m = int(stdin.readline()) a = map(int, stdin.readline().split(), repeat(10, m)) b = map(int, stdin.readline().split(), repeat(10, m)) b = [(x, i) for i, x in enumerate(b)] c = [0] * m a.sort(reverse=True) b.sort() for i, x in...
Berland crossword is a puzzle that is solved on a square grid with n rows and n columns. Initially all the cells are white. To solve the puzzle one has to color some cells on the border of the grid black in such a way that: * exactly U cells in the top row are black; * exactly R cells in the rightmost column ar...
3
for _ in range(int(input())): n, u, r, d, l = tuple(map(int, input().split())) if u <= n and d <= n and r <= n and l <= n: s = 0 if r == n and l == n and (u > 1 and d > 1): s += 1 elif (r == n and l == (n - 1) or r == (n - 1) and l == n) and (u > 1 and d > 0 or u > 0 and d > ...
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th...
3
t=int(input()) while(t): a=input() flag=0 if('R' in a and 'C' in a): m=a.index('R') n=a.index('C') for i in range(m+1,n): if(a[i].isdigit()): continue else: flag=1 if((65<=ord(a[0])<=90)and(65<=ord(a[1])<=90)): ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
1
n = input() number = list(str(n)) def checkIfLucky(lstnum): for i in lstnum: if (i != '4' and i != '7'): return False return True def almostLucky(lstnum, num): if not checkIfLucky(lstnum): for i in range(int(num/2) + 1): if (checkIfLucky(list(str(i))) and num%i == ...
Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid algorithm. Formally, find the biggest integer d, such that all int...
1
a,b=raw_input().split() a=int(a) b=int(b) if a!=b: print "1" else: print a
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and...
3
import collections n = input() l = map(int, input().split()) d = dict() for i in l: if i not in d: d[i] = 0 d[i] += i od = collections.OrderedDict(sorted(d.items())) sum_new = 0 sum_old = 0 first = True for k, v in od.items(): if first: sum_new = v first = False continu...
Today professor Ka has given a string task to Oz and RK. He has given a string STR consisting only of characters '(' and ')' and asked them to convert the string STR into a closed one by adding parenthesis to start and/or end of string STR. This means that they could add characters either only to the start of string ...
1
class Stack: def __init__(self): self.data = list() def push(self, value): self.data.append(value) def empty(self): if len(self.data): return False else: return True def pop(self): if not self.empty(): self.data.pop() de...
Kuroni has n daughters. As gifts for them, he bought n necklaces and n bracelets: * the i-th necklace has a brightness a_i, where all the a_i are pairwise distinct (i.e. all a_i are different), * the i-th bracelet has a brightness b_i, where all the b_i are pairwise distinct (i.e. all b_i are different). Kuro...
3
for t in range(int(input())): n = int(input()) print(*sorted([int(i) for i in input().split()])) print(*sorted([int(i) for i in input().split()]))
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise. Constraints * C_{i,j}(1 \leq i \leq 2, 1 \leq...
3
print("YES" if "".join(reversed(input())) == input() else "NO")
Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them. Your task is: given the n and t print an integer strictly larger than zero consisting of n digits that is divisible by t. If such number doesn't exist, print - 1. Input T...
1
n,t = raw_input().split() if (n == '1' and t == '10'): print -1 elif(len(t) == 1): print t*int(n) else: print "1" + "0"*(int(n)-1)
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has a coins, Barbara has b coins and Cerene has c coins. Recently Polycarp has returned from the trip around the world and brought n coins. He wants to distribute all these n coins between his sisters in such a way that ...
3
t = int(input()) for i in range(t): a, b, c, n = map(int, input().split()) x = (a + b + c + n) / 3 if int(x) != x or x < max(a, b, c): print('NO') else: print('YES')
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
3
x = int(input().strip()) subtractor = 1 found = False while(not found and subtractor < x): if((x - subtractor) % 2 == 0 and (subtractor % 2 == 0)): print("YES") found = True subtractor += 1 if(not found): print("NO")
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
def main(): s = [int(x) for x in input().split('+')] s.sort() print("+".join([str(x) for x in s])) return 0 if __name__ == "__main__": main()
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than n digits. Input The on...
1
n = int(raw_input().strip()) ans = 2**(n+1)-2 print ans
Compute A \times B. Constraints * 1 \leq A \leq 100 * 1 \leq B \leq 100 * All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the value A \times B as an integer. Examples Input 2 5 Output 10 Input 100 100 Output 10000
3
a,b = map(int, input().split()); print(a*b);
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()) ris = 0 for cont in range(0,n): a,b,c = map(int, input().split()) if a+b+c > 1: ris += 1 print(ris)
You have three piles of candies: red, green and blue candies: * the first pile contains only red candies and there are r candies in it, * the second pile contains only green candies and there are g candies in it, * the third pile contains only blue candies and there are b candies in it. Each day Tanya eats...
3
for i in range(int(input())): a, b, c = (int(x) for x in input().split()) mx = max(a, b, c) mn = min(a, b, c) md = a + b + c - mn - mx if mx >= md + mn: print(mn + md) else: print(mx + (mn + md - mx) // 2)