problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Create a program that reads the sales unit price and sales quantity and outputs the total sales amount and the average sales quantity. Input The input is given in the following format: Sales unit price, sales quantity Sales unit price, sales quantity :: :: A comma-separated pair of unit price and quantity is gi...
3
A = [] while True: try: a = list(map(int, input().split(','))) except: break A.append(a) Sum = 0 N = 0 for i in range(len(A)): Sum += A[i][0] * A[i][1] N += A[i][1] N_average = N / len(A) N_average_int = N // len(A) if 0 <= N_average - N_average_int <0.5: N_average = int(N_aver...
See Russian Translation Adam and Bob are playing a game. The game is parameterized by the three integers a,b,c. They start out with the integer 1, with Adam going first. Suppose the current integer is S. On a player's turn, he may change the current integer to any integer between aΓ—S and bΓ—S, inclusive. The first play...
1
for t in range(int(raw_input())): (a,b,c) = [int(s) for s in raw_input().strip().split(" ")] m = a*b s = 1 while s<c: s*=m if s/a>=c or s/b>=c: print "Adam" else: print "Bob"
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>. The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is t...
3
n = int(input()) [first_value, *sn] = list(map(int, input().strip().split())) ans = 0 stack = [None]*n top = 0 stack[top] = first_value for s in sn: if s > stack[top]: while top > -1 and s > stack[top]: ans = max(ans, s ^ stack[top]) top -= 1 if top > -1: ans ...
You are given an integer n (n β‰₯ 0) represented with k digits in base (radix) b. So, $$$n = a_1 β‹… b^{k-1} + a_2 β‹… b^{k-2} + … a_{k-1} β‹… b + a_k.$$$ For example, if b=17, k=3 and a=[11, 15, 7] then n=11β‹…17^2+15β‹…17+7=3179+255+7=3441. Determine whether n is even or odd. Input The first line contains two integers b and...
3
b, k = map(int, input().split()) a = list(map(int, input().split())) ans = 0; for i in range(k): if i == k - 1: ans ^= a[i] % 2; else: ans ^= (a[i] % 2) * (b % 2) print('even' if ans == 0 else 'odd')
Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information: If a=`H`, AtCoDe...
3
a,b=input().split() # print(a,b) if a==b:print('H') else:print('D')
Polycarp and his friends want to visit a new restaurant. The restaurant has n tables arranged along a straight line. People are already sitting at some tables. The tables are numbered from 1 to n in the order from left to right. The state of the restaurant is described by a string of length n which contains characters ...
3
N = int(input()) for i in range(N): n, k = tuple(map(int, input().split())) s = input() if len(s) == 1: if s == '0': print(1) else: print(0) continue l = 0 ret = 0 first = True for x in s: if x == '0': l += 1 else: if first is True: ret += l // (k+1) first = False else: ret +...
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia...
3
def NaytiChisla(stroka): kek = "" chislo = [] koef = 1 for i in range(len(stroka)): if stroka[i] == '-': koef = -1 if stroka[i] == '0' or stroka[i] == '1' or stroka[i] == '2' or stroka[i] == '3' or stroka[i] == '4' or stroka[i] == '5' or stroka[i] == '6' or stroka[i] == '7' o...
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t1, t2, ..., tn. Yo...
1
n=int(raw_input()) #n,k=map(int,raw_input().split()) l=map(int,raw_input().split()) ans=chk=15 l=l[::-1] while len(l): tmp=l.pop() if tmp>ans: break ans=tmp+15 print min(90,ans)
In this problem you will have to help Berland army with organizing their command delivery system. There are n officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer a is the direct superior of officer...
3
n, q = map(int,input().split()) officers = map(int,input().split()) s = [[] for _ in range(n)] c = [1] * n b = [0] * n for i,v in enumerate(officers): s[v-1].append(i+1) traversal = [] def dfs(): stack = [0] while stack: n = stack.pop() traversal.append(n) for child in reversed(s[n]): stack.append(child)...
While playing with geometric figures Alex has accidentally invented a concept of a n-th order rhombus in a cell grid. A 1-st order rhombus is just a square 1 Γ— 1 (i.e just a cell). A n-th order rhombus for all n β‰₯ 2 one obtains from a n-1-th order rhombus adding all cells which have a common side with it to it (look ...
3
n=int(input()) o=2*n-1 o1=o-2 while(o1>0): o+=2*o1 o1-=2 print(o)
Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile. You are given n operations which Vasya has made. Find the minimal possible number of stones that can b...
3
n=int(input()) s=input() ans=0 for letter in s: if letter=='+': ans+=1 else: ans-=1 if ans<0: ans=0 print(ans)
This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt. To make a toast, each friend needs nl ...
1
import string; ii = []; ss = string.split(raw_input()); for s in ss: ii.append(int(s)); print min((ii[1] * ii[2]) / ii[6], ii[3] * ii[4], ii[5] / ii[7]) / ii[0];
Alica and Bob are playing a game. Initially they have a binary string s consisting of only characters 0 and 1. Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent char...
3
for _ in range(int(input())): s=input() s1=0 s2=0 for i in s: if i=="1": s1+=1 else: s2+=1 c=min(s1,s2) if c%2==0: print("NET") else: print("DA")
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4 Γ— 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the p...
3
a = [] for i in range(4): a.append(input()) for i in range(3): for j in range(3): k = 0 if a[i][j] == '#': k += 1 if a[i][j+1] == '#': k += 1 if a[i+1][j] == '#': k += 1 if a[i+1][j+1] == '#': k += 1 if k>=3: ...
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
a=input() if len(a)==1: print(a) else: q="" q=q.join(sorted(a,reverse=False)) q=q.strip('+') final='' for i in q: final+=i+'+' print(final[:-1])
Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ). Consider a sequence A satisfying the following conditions: * A is a sequence of N positive integers. * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M. Let us define a score of this sequence as follows: * The score is the ...
3
n,m,q = map(int,input().split()) ans = 0 x = [list(map(int,input().split())) for i in range(q)] import itertools arrs = list(itertools.combinations_with_replacement(range(m),n)) for arr in arrs: buf = 0 for i in x: a,b,c,d = i if arr[b-1]-arr[a-1]==c: buf+=d ans = max(ans,buf) pr...
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 l in range(t): n=int(input()) ans=0 for i in range(1,10): val=0 for j in range(10): val=val*10+i if(val<=n): ans+=1 else: break print(ans)
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...
1
t = int(raw_input()) while t > 0: t -= 1 n, m = map(int, raw_input().split()) d1 = map(int, raw_input().split()) d2 = map(int, raw_input().split()) s = set(d1) & set(d2) if len(s) == 0: print 'NO' else: print 'YES' print '1 %s' % list(s)[0]
You are given a string s of length n, which consists only of the first k letters of the Latin alphabet. All letters in string s are uppercase. A subsequence of string s is a string that can be derived from s by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD...
3
n,k = map(int,input().split(" ")) s = input() l = [] a=0 for i in range(k): # a=i+ord("A") 65.66,67..... l.append(s.count(chr(i+ord("A")))) print(min(l)*k)
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
3
s = input('') n = len(s) i = 0 count_z = 0 count_o = 0 flag = 0 while(i<n): if(s[i]=='0'): count_o = 0 count_z+=1 if(count_z>=7): flag =1 break elif(s[i]=='1'): count_z = 0 count_o+=1 if(count_o>=7): flag = 1 break ...
Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n. He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arb...
3
#!/usr/bin/env python3 ''' https://github.com/dhruvildave http://codeforces.com/contest/1216/problem/A Mon 30 Sep 2019 10:25:36 PM IST ''' def soln() -> None: '''Driver code''' def logic() -> None: '''Logic''' n = int(input()) arr = list(input()) cnt = 0 for i in range(...
Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst...
1
class DoublyLinkedList: def __init__(self): self.nil = self.make_node(None) self.nil['next'] = self.nil self.nil['prev'] = self.nil def make_node(self,v): return {'key':v, 'next':None, 'prev':None} def dump(self): n = self.nil['next'] while True: ...
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequenc...
3
n=int(input()) x=0 for i in range(n): x+=(n-i)*i print (x+n)
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length n, such that it is simultaneously...
3
n=int(input()) if n==1 or n==2: print(-1) elif n==3: print(210) else: a=(10**(n-1)) if a%210==0: print(a) else: print(((a//210)+1)*210)
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance. The park is a rectangular table with n rows and m columns, where the cells of the...
3
t=int(input()) for i in range(t): n,m=map(int,input().split()) p=n*m r= (p//2) + (p%2) print(r)
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: * he chooses two elements of the array ai, aj (i β‰  j); ...
3
n=int(input()) a=[int(v) for v in input().split()] if sum(a)%n==0: print(n) else: print(n-1)
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
3
n = int(input()) aux1 = 0 while (aux1 < n): word = (input()) if (len(word)<=10): res = word else: res = word[0]+str(len(word)-2)+word[len(word)-1] print(res) aux1+=1
You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 Γ— 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures. Yo...
3
qq = int(input()) for _ in range(qq): n = int(input()) dat = list(map(int, input().split())) if n == 1: print("YES") continue c = dat[0] % 2 f = True for i in range(n): if c != dat[i] % 2: f = False print("YES" if f else "NO")
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their h...
3
import sys n=int(input()) arr=list(map(int,input().split(' '))) mi=sys.maxsize;ma=-1*sys.maxsize;mii=0;mai=0; for i in range(n): if arr[i]>ma: ma=arr[i];mai=i; if arr[n-(i+1)]<mi: mi=arr[n-(i+1)];mii=n-(i+1); mi=mii;ma=mai if ma<mi: print(ma+(n-mi-1)) else: print(ma+(n-mi-1)-1)
We are very near to our goal now. The enemy is being weakened continuously. But alas, sensing his fall, the hacker has spread a worm into our network. It is consuming all our files at a tremendous rate and must be stopped at all costs. The only way to stop it is to enter a specific code number in to the worm. It is up ...
1
def SumDigits(num): r=0 l = len(str(num)) while l > 0 : r = (r)+(num%10) num = num / 10 l-=1 return r cases = int(raw_input()) op = [] while (cases > 0): a = int(raw_input()) #print(a%SumDigits(a)) op.append(a%SumDigits(a)) cases-=1 for x in op: print x
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
n = int(input()) a, b = input(), input() count = 0 for i in range(n): q = abs(int(a[i])-int(b[i])) count += q*(q<=5) + (10-q)*(q>5) print(count)
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002. You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2. Let's define the ternary XOR operation βŠ™ of two ternary n...
3
for i in range(int(input())): input() a = str(input()) x = "" y = "" bool = 0 for j in a: if j == "0": x += "0" y += "0" elif j == "1" and bool == 0: x += "1" y += "0" bool = 1 elif j == "1" and bool == 1: ...
Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task. You are given two matrices A and B of size n Γ— m, each of which consists of 0 and 1 only. You can apply the following operation to the matrix A arbitrary number of times: take any subma...
3
n, m = map(int, input().split()) A = [] B = [] for _ in range(n): row = list(map(int, input().split())) A.append(row) for _ in range(n): row = list(map(int, input().split())) B.append(row) flag = 0 for i in range(n): re = 0 for j in range(m): if A[i][j]!=B[i][j]: re += 1 ...
Polycarp has an array a consisting of n integers. He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its...
3
t = int(input()) l = list(map(int,input().split())) l.sort() l1=[] l2=[] for i in l: if i%2==0: l1.append(i) else: l2.append(i) x = abs(len(l1)-len(l2))-1 if x==0: print(x) elif x >0 and len(l1)>len(l2): print(sum(l1[:x])) elif x >0 and len(l1)<len(l2): print(sum(l2[:x])) elif x <0 and len(l1)==len(l2...
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
1
w = int(input()) if w%2==0 and w!=2: print 'YES' else: print 'NO'
You found a useless array a of 2n positive integers. You have realized that you actually don't need this array, so you decided to throw out all elements of a. It could have been an easy task, but it turned out that you should follow some rules: 1. In the beginning, you select any positive integer x. 2. Then you ...
3
from collections import defaultdict,deque,Counter import sys import bisect import math input=sys.stdin.readline mod=1000000007 t=int(input()) for ii in range(t): n=int(input()) b=[int(i) for i in input().split() if i!='\n'] b.sort() for i in range(2*n-2,-1,-1): ans=[[b[-1]]] req,m...
n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance u...
3
n=int(input()) a=list(map(int,input().split())) a=a+[a[0]] #print(a) min=99999999 index=0 index1=0 for i in range(n): if(abs(a[i]-a[i+1])<min): min=abs(a[i]-a[i+1]) #print(min,i,i%n) index=((i)%n)+1 index1=((i+1)%n)+1 print(index,index1)
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ...
3
n = int(input()) flag = 0 temp = 0 l = [] for i in range(n): a, b = map(int,input().split()) if i is 0 and a is 0: flag += 1 temp = temp - a temp = temp + b l.append(temp) print(max(l))
Aizu Gakuen High School holds a school festival every year. The most popular of these is the haunted house. The most popular reason is that 9 classes do haunted houses instead of 1 or 2 classes. Each one has its own unique haunted house. Therefore, many visitors come from the neighborhood these days. Therefore, the sc...
3
i = 1 while i <= 9: name_i,a_i,b_i = map(str,input().split()) a_i = int(a_i) b_i = int(b_i) x = a_i + b_i y = a_i * 200 + b_i * 300 print(name_i,x,y) i += 1
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '<image>' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Coder start at the level 1. When ZS the Coder is at level k, he can : 1. Pr...
1
n = int(raw_input()) num = 2 target = 1 while(n >= target): xxx = (target*target+target) temp = xxx*xxx temp -= num temp /= target print int(temp) num = int(pow(num + temp*target, 0.5)) target += 1 #print num, " fuck ", target
There are n warriors in a row. The power of the i-th warrior is a_i. All powers are pairwise distinct. You have two types of spells which you may cast: 1. Fireball: you spend x mana and destroy exactly k consecutive warriors; 2. Berserk: you spend y mana, choose two consecutive warriors, and the warrior with gr...
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...
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situat...
3
n, y = map(int, input().split()) for i in range(n+1): for j in range(n+1-i): if i*10000 + j*5000 + (n-i-j)*1000 == y: print(i, j, n-i-j) exit() print("-1 -1 -1")
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
# -*- coding: utf-8 -*- """ Created on Tue Nov 5 16:43:03 2019 @author: 86138 """ #59A Word s = input() lower = 0 upper = 0 for x in s: if ord('a') <= ord(x) <= ord('z'): lower += 1 else: upper += 1 if upper > lower: print(s.upper()) else: print(s.lower())
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddl...
1
n,m = map(int, raw_input().split()) al = list(map(int, raw_input().split())) al = sorted(al) raz = [] for i in range(m-n+1): raz.append(al[i+n-1]-al[i]) print(min(raz))
After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls and m baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to m, correspondingly. The ...
3
import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(int, tinput()) def rlinput(): return list(rinput()) import math n,m = rinput() def get_list(lower,upper): if lower == upp...
There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests. A result of the elimination stage is the tota...
3
t = int(input()) for _ in range(t): points = [int(number) for number in input().split(" ")] print(max(points[0] + points[1], points[2] + points[3]))
A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1. For example, 1234, 1, and 334 are lunlun numbers, while ...
3
L=[] def search(x): if x>3234566667: return L.append(x) search(10*x+x%10) if x%10!=0: search(10*x+x%10-1) if x%10!=9: search(10*x+x%10+1) for i in range(1,10): search(i) L.sort() k=int(input()) print(L[k-1])
There is a building consisting of 10~000 apartments numbered from 1 to 10~000, inclusive. Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are 11, 2, 777, 9999 and so on. Our character is a troublemaker, and he calls the intercoms of all boring apartments, till someone...
3
t=int(input()) for i in range(t): n=input() p=len(n) n=int(n) k=n%10 if(k==1): if(p==1): print(1) elif(p==2): print(3) elif(p==3): print(6) elif(p==4): print(10) elif(k==2): if(p==1): print(11) ...
You are given a rectangular board of M Γ— N squares. Also you are given an unlimited number of standard domino pieces of 2 Γ— 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squa...
3
m,n = map(int, input().split()) S = m*n maxdom = S//2 print('{0:.0f}'.format(maxdom))
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'...
1
#!/usr/bin/env python import math def pave(n, m, a): n = int(n) m = int(m) a = float(a) return int(math.ceil(n / a) * math.ceil(m / a)) input_parameters = raw_input() print pave(*input_parameters.split(' '))
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
n = int(input()) a = input() b = input() m = 0 for i in range(n): c = int(a[i]) d = int(b[i]) m += min(abs(min(c, d) - max(c, d)),abs(min(c, d) - max(c, d) + 10)) print(m)
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
t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) res=0 for i in range(1,n): res+=max(l[i-1]-l[i],0) print(res)
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
num = input() luck = num.count('4') + num.count('7') luck = str(luck) if luck.count('4')+luck.count('7') == len(luck): print('YES') else: print('NO')
Let LCM(x, y) be the minimum positive integer that is divisible by both x and y. For example, LCM(13, 37) = 481, LCM(9, 6) = 18. You are given two integers l and r. Find two integers x and y such that l ≀ x < y ≀ r and l ≀ LCM(x, y) ≀ r. Input The first line contains one integer t (1 ≀ t ≀ 10000) β€” the number of tes...
3
T = int(input()) def solve(): if r < 2*l: ans = "-1 -1" else: ans = str(l) + " " + str(2*l) return ans for test in range(T): l,r = map(int,input().split()) print(solve())
You have n sticks of the given lengths. Your task is to choose exactly four of them in such a way that they can form a rectangle. No sticks can be cut to pieces, each side of the rectangle must be formed by a single stick. No stick can be chosen multiple times. It is guaranteed that it is always possible to choose suc...
1
#import resource #import sys #resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY]) #import threading #threading.stack_size(2**26) #sys.setrecursionlimit(0x1000000) from sys import stdin, stdout mod=(10**9)+7 mod1=mod-1 def modinv(n,p): return pow(n,p-2,p) def ncr(n,r,p): t=((fact[n])...
Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had. Constraints * 1 \leq N \leq 10^5 * 0 \leq K \leq N-1 * All input values are integers. ...
3
N, K = map(int, input().split()) ans = 0 for b in range(1, N+1): if K>=b: continue if K==0: ans += N else: ans += N//b*(b-K)+max(N%b-K+1, 0) print(ans)
Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`. From a road square, you can move to a horizontally or vertically adjacent ro...
3
# D - Maze Master from collections import deque def bfs(start: int): queue = deque([start]) dist = {start: 0} while queue: x = queue.popleft() for nx in (x + 1, x - 1, x + W, x - W): if maze[nx] == "." and nx not in dist: dist[nx] = dist[x] + 1 q...
You are given a long decimal number a consisting of n digits from 1 to 9. You also have a function f that maps every digit from 1 to 9 to some (possibly the same) digit from 1 to 9. You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in a, and replace each digi...
3
n = int(input()) a = input();a = list(a) F = list(map(int,input().split())) b = -1 for i in range(n): if(F[int(a[i])-1]>int(a[i])): an = a[i] b = i break if(b!=-1): for i in range(b,n): if(F[int(a[i])-1]<int(a[i])): break a[i] = F[int(a[i])-1] for i in a: ...
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
import math h,l=map(int,input().split()) x=(math.pow(l,2)-math.pow(h,2))/(2*h) print(x)
The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the...
3
def f(): n = int(input()) t = input().split() a, b = 0, 0 for i in t: if i == '25': a += 1 elif i > '3': b += 1 a -= 1 else: if b > 0: b -= 1 a -= 1 else: a -= 3 if a < 0: return 1 return ...
You are given an array a of length n, and an integer x. You can perform the following operation as many times as you would like (possibly zero): replace two adjacent elements of the array by their sum. For example, if the initial array was [3, 6, 9], in a single operation one can replace the last two elements by their ...
3
import math, sys from collections import defaultdict, Counter, deque from heapq import heapify, heappush, heappop from bisect import bisect_left, bisect_right INF = float('inf') MOD = int(1e9) + 7 MAX = int(2e6) def solve(): n, x = vars() arr = array() mini = math.ceil(sum(arr) / x) maxi = 0 for i in range(n):...
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
t = int(input()) n = 0 for x in range(t): array = input().split(' ') sum = int(array[0]) + int(array[1]) + int(array[2]) if sum >= 2: n += 1 print(str(n))
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. Input The first line of input contains ...
3
# codeforces 320-A. Magic Numbers n=input() num4=0 res = True for idx,val in enumerate(n): if val =='4': if num4<2 and idx>0: num4+=1 else: res=False break elif val =='1': num4=0 else: res=False break print('YES') if res else print(...
Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) β‰₯ n, * s(b) β‰₯ n, * s(a + b) ≀ m. Input The only line of input contain two integers n and m (1 ≀ n, m ≀ 1129). Output Print two lines, one for decimal...
3
n, m = map(int, input().split()) nc = n//8 + bool(n%8) a = '8' * nc + '9' b = '9' * len(a) + '1' * len(a) print(a, b, sep = '\n')
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
3
# -*- coding: utf-8 -*- """ Created on Fri Sep 25 15:16:02 2020 @author: 86188 """ for x in range(int(input())): a=input() b=len(a) print(a if b < 11 else a[0]+str(b-2)+a[-1])
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n. <image> Mehrdad has become quite confused and wants you to help him. Please hel...
3
""" n, h = map(int, input().split()) a = [int(x) for x in input().split()] 3) arr2d = [[j for j in input().split()] for i in range(int(b)] for row in arr2d: print(*row, sep=', ') """ print(pow(1378, int(input()), 10))
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xi coins. Vasiliy plans to buy his favorite drink fo...
3
n=int(input()) li=sorted(list(map(int,input().split()))) m=int(input()) for i in range(m): c=int(input()) l=-1 r=n while(r>l+1): mid=(l+r)//2 if li[mid]<=c : l=mid else : r=mid print(l+1)
Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market! In the morning, there are n opportunities to buy shares. The i-th of them allows to buy as many shares as you want, each at the price o...
3
from math import floor def get_input(): return list(map(int, input().split())) r = int(input().split()[2]) s_min = min(get_input()) b_max = max(get_input()) if (b_max > s_min): s_shares_bought = floor(r/s_min) print((r%s_min) + (s_shares_bought*b_max)) else: print(r)
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()) pole = [int(i) for i in input().split()] pole = sum(pole)/100 print((pole/n)*100)
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a mask of a positive integer n the number that is obtained after successive writing of...
1
def masked(x): t,p=0,1 while x>0: d,x=x%10,x/10 if 4==d or 7==d: t+=d*p p*=10 return t a,b=map(int,raw_input().split()) while True: a+=1 t=masked(a) if t==b: print a break
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...
3
n, t = map(int, input().split()) if t < 10: print(str(t)*n) elif t == 10: if n == 1: print('-1') else: print('1' + '0'*(n-1))
Cirno gave AquaMoon a chessboard of size 1 Γ— n. Its cells are numbered with integers from 1 to n from left to right. In the beginning, some of the cells are occupied with at most one pawn, and other cells are unoccupied. In each operation, AquaMoon can choose a cell i with a pawn, and do either of the following (if po...
3
MOD = 998244353 def mod_pow(a, b): if b==0: return 1 root = mod_pow(a, b//2) if b%2 == 0: return (root*root)%MOD else: return (root*root*a)%MOD def inv_mod(a): return mod_pow(a, MOD-2) def ncr(a, b): ans = 1 for i in range(1,a+1): ans *= i ans %= ...
A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who ...
3
n = int(input()) A = [int(input()) for _ in range(n)] m = 30 C = [False]*m x = 0 for a in A: x ^= a for i in range(m): if a>>i & 1: C[i] = True break total = 0 ans = 0 for i in range(m-1, -1, -1): if (x>>i & 1) ^ total: if C[i]: ans += 1 total ^= 1 else: print(-1) b...
You have n coins, each of the same value of 1. Distribute them into packets such that any amount x (1 ≀ x ≀ n) can be formed using some (possibly one or all) number of these packets. Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single x, howeve...
3
from math import log n = int(input()) p = int(log(n+1,2)) if pow(2,p)-1 == n: print(p) else: print(p+1)
n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could ha...
1
''' Created on May 11, 2015 @author: sshadmin ''' n,m=map(int,raw_input().strip().split()) mx=((n-m)*(n-m+1))/2 div=n/m mod= n % m lo=m-mod hi=mod print lo*(div*(div-1))/2 + hi*((div)*(div+1))/2 , mx
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess...
1
#!/usr/bin/env/ python n=int(input()) x=int(input()) def sort(n): print (x+n)%3 if n%2 : #odd if x==0: x=1 elif x==1: x=0 sort((n-1)/2) else: sort(n/2)
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - ...
3
from collections import deque from math import log,sqrt,ceil def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().strip().split(" ")) def li(): return list(mi()) n=ii() if(n<=3): a=0 print(n,a,a) else: f0=1 f1=1 f2=2 f3=3 f4=f2+f3 while(f4<n): f...
The length of the longest common prefix of two strings s = s_1 s_2 … s_n and t = t_1 t_2 … t_m is defined as the maximum integer k (0 ≀ k ≀ min(n,m)) such that s_1 s_2 … s_k equals t_1 t_2 … t_k. Koa the Koala initially has n+1 strings s_1, s_2, ..., s_{n+1}. For each i (1 ≀ i ≀ n) she calculated a_i β€” the length of ...
3
def diff(s): if s == 'z': return 'a' return 'z' for test in range(int(input())): n = int(input()) l = list(map(int, input().split())) curr = 'a'*55 print(curr) for i in l: new = curr[:i] + diff(curr[i]) + 'a'*(54-i) print(new) curr = new
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
s1 = input() s1 = s1.lower() s2 = input() s2 = s2.lower() flag = 0 for i in range(len(s1)): if(s1[i]>s2[i]): print(1) flag = 1 break elif(s1[i]<s2[i]): print(-1) flag = -1 break if(flag==0): print(0)
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
3
n=int(input()) l=[] for i in range(n): s=input() l.append(s) for i in l: if(len(i)<=10): print(i) else: a=i[0] b=i[1:-1] c=i[-1] print(a+str(len(b))+c)
This is the easy version of the problem. The difference between the versions is the constraint on n and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings a and b of length n (a binary string is a string consisting of symbols 0 and 1). In ...
3
import math value = int(input()) for T in range(value): n = int(input()) sa = input() sb = input() count, ans = 0, [] for i in range(0, n): j = -i-1 k = n-1-2*i if k == 0 and sb[0] != sa[i]: count += 1 ans.append(1) if k <= 0: ...
Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls? Constraints * 1 \leq K \leq N \leq 100 * All values in input are intege...
3
a,b=map(int,input().split()) print(a-b) if b-1 else print(0)
Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns β€” from left to right starting from one. We'll represent the cell on the x-th row and the y-th column as a pair of numbers (x, y). The table corners are cells: (1, 1...
1
def solve(n, m, grid): for i in range(n): if grid[i][0] == 1 or grid[i][m-1] == 1: return 2 for j in range(m): if grid[0][j] == 1 or grid[n-1][j] == 1: return 2 return 4 n, m = map(int, raw_input().split()) grid = [map(int, raw_input().split()) for i in range(n)] print solve(n, m, grid)
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve Flint's task. Recently, out of blue Captain Flint has been interested in ma...
3
for _ in range(int(input())): N = int(input()) if N > 30: print("YES") Ans1 = [6, 10, 14, N - 30] if len(set(Ans1)) == 4:print(*Ans1) else:print(6, 10, 15, N - 31) else:print("NO") # New Start
You are given an array a of n integers. You want to make all elements of a equal to zero by doing the following operation exactly three times: * Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different). It can...
3
n = int(input()) a = list(map(int, input().split())) if n==1: print('1 1') print('0') print('1 1') print('0') print('1 1') print(-a[0]) else: print('1', n - 1) b = [] for i in range(n - 1): x = a[i] % n y = x * (n - 1) b.append(y) a[i] = -(y + a[i]) ...
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
3
n=int(input()) l=list(map(int,input().split())) s=0 cnt=0 i=0 l.sort(reverse=True) while(len(l)>0): s=s+l[i] del l[i] k=sum(l) cnt=cnt+1 if(s>k): break print(cnt)
You are given a string s. Each character is either 0 or 1. You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met. You may eras...
3
for i in range(int(input())): a = input().strip('0').count('0') print (a)
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder). Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that. You have to answer t independent test cases. Input The fi...
3
t = int(input()) ar = [] for i in range(t) : n = int(input()) c = 0 if n == 1 : c = 0 elif n == 6 : c = 1 elif n%3 != 0 : c = -1 else : while n != 1 and n%3 ==0: if n%6 == 0 : n = n//6 c += 1 else : n *= 2 c += 1 if n != 1 : c = -1...
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
3
s=input().split() n=int(s[0]) l=[] for i in range(int(s[1])): a=input().split() l.append([int(a[0]),int(a[1])]) l.sort() for i in l: if n>i[0]: n+=i[1] else: print('NO') break if n>l[len(l)-1][0]: print('YES')
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ...
3
n = int(input()) inputs = input().split(" ") for i in range(len(inputs)): inputs[i] = int(inputs[i]) l = [0] * 100 for i in range(n): l[inputs[i]-1]+=1 max = 0 for i in range(100): if(l[i] > max): max = l[i] print(max)
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
number=int(input()) str=input() cnt=0 for i in range(number-1): if str[i]==str[i+1]: cnt+=1 print(cnt)
You are given positive integers X and Y. If there exists a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, choose one such integer and print it. If it does not exist, print -1. Constraints * 1 ≀ X,Y ≀ 10^9 * X and Y are integers. Input Input is given from Standard Input in...
3
# -*- coding:utf-8 -*- x, y = map(int, input().split()) if x%y: print(x) else: print(-1)
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of...
1
import sys import math s = sys.stdin.readline().split() n = float(s[0]) m = float(s[1]) a = float(s[2]) b = float(s[3]) c = math.floor(n/m); d = math.ceil(n/m); print int(min(n*a,c*b+(n-c*m)*a,d*b))
Let's call the following process a transformation of a sequence of length n. If the sequence is empty, the process ends. Otherwise, append the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) (GCD) of all the elements of the sequence to the result and remove one arbitrary element from t...
1
import sys def solve(n): if n == 1: return [1] elif n == 0: return [] elif n == 3: return [1, 1, 3] res = [1 for _ in range(0, (n + 1) / 2)] res2 = solve(n - (n + 1) / 2) return res + map(lambda a: a * 2, res2) def gcd(a, b): if a > b: return gcd(b, a) ...
Heidi and Doctor Who hopped out of the TARDIS and found themselves at EPFL in 2018. They were surrounded by stormtroopers and Darth Vader was approaching. Miraculously, they managed to escape to a nearby rebel base but the Doctor was very confused. Heidi reminded him that last year's HC2 theme was Star Wars. Now he und...
3
import bisect n,m=map(int,input().split()) l=list(map(int,input().split())) s=[] for i in range(m): a,b=map(int,input().split()) s.append([a,b]) k=sorted(s) dp=[] s=[] c=0 for i in range(len(k)): s.append(k[i][0]) c+=k[i][1] dp.append(c) for i in range(n): p=bisect.bisect(s,l[i]) if p==0: ...
You play your favourite game yet another time. You chose the character you didn't play before. It has str points of strength and int points of intelligence. Also, at start, the character has exp free experience points you can invest either in strength or in intelligence (by investing one point you can either raise stre...
3
t = int(input()) for _ in range(t): a,b,c = list(map(int,input().split())) k = (b+c-a)/2 if k<0: print(c+1) else: t = int(k)+1 if t>c: print(0) else: print(c+1-t)
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
def main(): n,k = list(map(int,input().split())) a = list(map(int,input().split())) b = list(map(int,input().split())) a.sort() b.sort(reverse=True) sum = 0 for i in range(n): if(i<k and b[i]>a[i]): sum+=b[i] else: sum+=a[i] print(sum) ...
You are given a board of size n Γ— n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure. In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move...
3
for _ in range(int(input())): n = int(input()) if n == 1: print(0) else: res = 0 j = 3 k = 1 t = 1 for i in range(1,n-1, 2): res += ((j*j)-(k*k))*t j += 2 k += 2 t += 1 print(res)
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()) s=0 while n!=0: r=n%10 if r==7 or r==4: s=s+1 n=n//10 if s==7 or s==4: print("YES") else: print("NO")
Koto Municipal Subway Koto Municipal Subway Koto City is a famous city whose roads are in a grid pattern, as shown in the figure below. The roads extending from north to south and the roads extending from east to west are lined up at intervals of 1 km each. Let Koto station at the southwestern intersection of Koto ci...
3
while True: d, e = map(int, input().split()) if d == 0: break ans = abs(d - e) for x in range(1, d): y = d - x ans = min(ans, abs((x ** 2 + y ** 2) ** 0.5 - e)) print("{:.4f}".format(ans))