problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
The new PIN is hard to remember. I was told that I shouldn't take notes, but I don't think I can remember them. Therefore, I decided to embed a numerical value in the text and make a note of the PIN. Here, the sum of all the numbers is the PIN. Create a program that reads the memorandum and outputs the PIN code. In...
3
import re try: ls = [] while True: ls.append(input()) except: result = 0 for i in ls: for s in re.findall(r'\d+', i): result += int(s) print(result)
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
3
n = int(input()) a = "hate " b = "love " start = "I " for i in range(1, n+1): print(start, end="") if i % 2 == 1: print(a, end="") else: print(b, end="") if i < n: print("that ",end="") print("it")
We have two bottles for holding water. Bottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water. Bottle 2 contains C milliliters of water. We will transfer water from Bottle 2 to Bottle 1 as much as possible. How much amount of water will remain in Bottle 2? Constraints * All val...
3
a,b,c=map(int,input().split()) print(max(0,b+c-a))
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
class Polygon(object): def is_nice(self): self.n = int(input()) for i in range(self.n): self.m = int(input()) if (self.m)%4==0: print('YES') else: print('NO') cc = Polygon() cc.is_nice()
You are given two binary strings x and y, which are binary representations of some two integers (let's denote these integers as f(x) and f(y)). You can choose any integer k β‰₯ 0, calculate the expression s_k = f(x) + f(y) β‹… 2^k and write the binary representation of s_k in reverse order (let's denote it as rev_k). For e...
3
# -*- coding: utf-8 -*- #!/usr/bin/python false = False true = True null = None # import math TEST = false try: import sys for arg in sys.argv: if(arg == 'test'): print('test mode') TEST = True pass except: pass def AddImports(libraryNames): for libname in libraryN...
There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only p levels of the game. And Little Y can pass only q levels of the game. You are given the indices of levels Little X can pass ...
3
n = int(input()) x = list(map(int, input().split()))[1:] y = list(map(int, input().split()))[1:] z = x+y k = True for i in range(1,n+1): if i not in z: k =False if k == False: print('Oh, my keyboard!') else: print('I become the guy.')
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies. Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. ...
3
a,b=list(map(int,input().split())) l=list(map(int,input().split())) for i in range(a): if l[i]<=b: l[i]=1 elif l[i]%b==0: l[i]=l[i]//b else: l[i]=l[i]//b+1 print(a-(l[::-1].index(max(l))))
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
import sys input = sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) n=inp() s=insr() def sameneigh(str): S=0 j=len(str) for i in range(1,...
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
import math k = input() k = k.split() m = math.ceil(int(k[0])/int(k[2])) n = math.ceil(int(k[1])/int(k[2])) print(m*n)
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≀ w2 ≀ ... ≀ wk holds. Polar bears Alice and Bob each have caught some fish, and they are g...
3
n,m,k=map(int,input().split()) Alice=list(map(int,input().split())) Bob=list(map(int,input().split())) SA={} SB={} for item in Alice: if(item in SA): SA[item]+=1 continue SA[item]=1 SB[item]=0 for item in Bob: if(item in SB): SB[item]+=1 continue SB[item]=1 SA...
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight...
3
def solve(): a, b = [int(x) for x in input().strip().split(' ')] y = 0 while a <= b: a, b, y = a * 3, b * 2, y + 1 print(y) solve()
There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster a...
3
import functools import fractions N=int(input()) A=list(map(int,input().split())) print(functools.reduce(fractions.gcd,A))
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive. Input Input contains one integer number n (1 ≀ n ≀ 3000). Output Output the amount ...
3
import math a=[] for i in range(3001): a.append(0) for i in range(3,3001,2): a[i]=1 for i in range(3,3001,2): if a[i]==1: for j in range(i*i,3001,i): a[j]=0 a[2]=1 a1=[] for i in range(3001): if a[i]==1: a1.append(i) def fun(n): #if n==1: # return True if n>=...
You are given three strings s, t and p consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. During each operation you choose any character from p, erase it from p and insert it into string s (you may insert this character anywhere you want: in the beginning of...
3
def get(a, b, c): pb = len(b) - 1 for i in range(len(a) - 1, -1, -1): while pb >= 0 and b[pb] != a[i]: pb -= 1 if pb < 0: return "NO" else: b = b[:pb] + b[pb+1:] pb -= 1 for elm in b: pc = c.find(elm) if pc < 0: ...
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
3
n,h = map(int,input().split()) a=list(map(int,input().split())) ans=len(a)*1 for x in a: if x>h: ans+=1 print(ans)
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
3
def char_range(c1, c2): for c in range(ord(c1), ord(c2) + 1): yield chr(c) def string_in_dict(s, d): for ii in range(0, len(s)): d[s[ii]] = [s, ii] n = int(input()) latin_list = list(char_range('a', 'z')) latin_dict = dict.fromkeys(latin_list) for i in range(0, n): new_string = input() ...
The circle line of the Roflanpolis subway has n stations. There are two parallel routes in the subway. The first one visits stations in order 1 β†’ 2 β†’ … β†’ n β†’ 1 β†’ 2 β†’ … (so the next stop after station x is equal to (x+1) if x < n and 1 otherwise). The second route visits stations in order n β†’ (n-1) β†’ … β†’ 1 β†’ n β†’ (n-1) ...
3
n,s1,e1,s2,e2=map(int,input().split()) m=n flag=0 for i in range(m): if(s1%n==s2%n): flag=1 if(s1%n==e1%n or s2%n==e2%n): break s1+=1 s2-=1 if(flag==1): print("Yes") else: print("No")
Naruto has sneaked into the Orochimaru's lair and is now looking for Sasuke. There are T rooms there. Every room has a door into it, each door can be described by the number n of seals on it and their integer energies a_1, a_2, ..., a_n. All energies a_i are nonzero and do not exceed 100 by absolute value. Also, n is e...
3
def GCD(x, y): if y == 0: return x return GCD(y, x % y) T = int(input()); ans = [] for i in range(T): ans += [[]] for i in range(T): n = int(input()) a = list(map(int, input().split())) for j in range(0, n, 2): nok = a[j] * a[j + 1] // GCD(a[j], a[j + 1]) ans[i] += [nok // a[j]]; an...
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≀ c, just the new word is appended to other words on the screen. If b - a > c, then ever...
3
n,c=list(map(int,input().split())) inp=list(map(int,input().split())) cntr=0 for i in range(n-1): if inp[i+1]-inp[i]>c: cntr=0 else: cntr+=1 print(cntr+1)
Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time wh...
3
n=int(input()) l=list(map(int,input().split())) summ=0 count=0 l.sort() for i in l: if(summ<=i): count+=1 summ+=i print(count)
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()) list1 = list(map(int, input().split(" "))) list1.sort() list1.reverse() sum1 = 0 num = 0 count = 0 for i in list1: sum1 = sum1 + i for i in list1: count = count + i num = num + 1 sum1 = sum1 - i if(count>sum1): break print(num)
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? Input The firs...
3
def read_data(): n = int(input().strip()) a = [] for i in range(n): line = tuple(map(int, input().strip().split())) a.append(line) return n, a def is_on_line(a,b,c): return 1 if (a[0]*(b[1]-c[1])+b[0]*(c[1]-a[1])+c[0]*(a[1]-b[1])) == 0 else 0 def solve(): if n <= 4: ret...
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq...
3
def bin_s(l, r, need, curr): m = (r + l) // 2 if need < m: return bin_s(l, m - 1, need, curr - 1) elif need > m: return bin_s(m + 1, r, need, curr - 1) else: return curr n, k = map(int, input().split()) sz = 1 for i in range(n - 1): sz = sz * 2 + 1 print(bin_s(1, sz, k, n))
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ...
3
n = int(input()) a = [int(j) for j in input().split()] x = a.count(200) y = a.count(100) if(x%2==0 and y%2==0): print("YES") elif(x%2==1 and y%2==0 and y>=2): print("YES") else: print("NO")
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()) c=0 for j in range(n): for k in range(n): if(j+k==n): if(j%2==0 and k%2==0): c=c+1 if(c>=1): print("YES") else: print("NO")
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan consider...
3
from collections import * n=int(input()) xd=Counter() yd=Counter() pd=Counter() ans=0 for i in range(n): x,y=map(int,input().split()) ans+=xd[x]+yd[y]-pd[(x,y)] xd[x]+=1 yd[y]+=1 pd[(x,y)]+=1 print(ans)
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
# -*- coding:utf-8 -*- import sys def is_min(): ''' ''' def some_func(): """ """ n,m = map(int, sys.stdin.readline().split()) m_list = map(int, sys.stdin.readline().split()) m_list.sort() mix_n = 1000 for i in range(0,m-n+1): mix_n = min([mix_n, m_list[i+n-1]-m_list[i] ])...
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player. Your task is to write a program that...
1
s=sum(map(int,raw_input().split())) if s%5==0 and s/5!=0: print s/5 else: print -1
There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he...
3
import queue N, M = map(int, input().split()) e = [[] for _ in range(N)] for i in range(M): A, B = map(int, input().split()) A -= 1 B -= 1 e[A].append(B) e[B].append(A) # print(e) seen = [-1] * N k = -1 for i in range(N): if seen[i] == -1: k += 1 seen[i] = k que = queue...
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
3
s = list(map(str,input().split("WUB"))) x = "" for i in s: if len(i) != 0: x += i + " " print(x)
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). Constraints * 1 \leq N \leq 10^4 * 1 \leq A \leq B \leq 36 * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output Print the s...
1
N, A, B = map(int, raw_input().split()) ans = 0 for i in range(1, N+1): x = sum(map(int, list(str(i)))) if x >= A and x <= B: ans += i print ans
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player. Your task is to write a program that...
3
sum_in = sum(map(int, input().strip().split(' '))) print(int(sum_in/5) if sum_in % 5 == 0 and sum_in > 0 else -1)
Petya is having a party soon, and he has decided to invite his n friends. He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one co...
3
#-------------Program------------- #----KuzlyaevNikita-Codeforces---- # n,k=map(int,input().split()) answer=0 answer+=2*n//k+int(2*n%k!=0) answer+=5*n//k+int(5*n%k!=0) answer+=8*n//k+int(8*n%k!=0) print(answer)
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is di...
3
n = int(input()) a = [int(x) for x in input().split()] even = 0 odd = 0 s = 0 for i in range(n): if a[i]/2 == int(a[i]/2): even = even + 1 else: odd = odd + 1 if even == 1: for i in range(n): if a[i]/2 == int(a[i]/2): s = i + 1 else: for i in range(n): if a[i]...
You are given three integers x, y and n. Your task is to find the maximum integer k such that 0 ≀ k ≀ n that k mod x = y, where mod is modulo operation. Many programming languages use percent operator % to implement it. In other words, with given x, y and n you need to find the maximum possible integer from 0 to n tha...
3
for _ in range(int(input())): x,y,n=map(int,input().split()) mul=n//x ans=x*mul if(ans+y>n): ans-=(x-y) else: ans+=y print(ans)
Valera had two bags of potatoes, the first of these bags contains x (x β‰₯ 1) potatoes, and the second β€” y (y β‰₯ 1) potatoes. Valera β€” very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater ...
3
ar = [] for i in input().split(' '): ar.append(int(i)) res = [] temp = ar[0]//ar[1] + 1 temp = temp * ar[1] if temp > ar[2]: print(-1) else: while temp <= ar[2]: res.append(temp-ar[0]) temp = temp + ar[1] print(*res)
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million...
3
from sys import stdin,stdout n=int(stdin.readline()) m=int(stdin.readline()) test=n ans=0 while m>test: test*=n ans+=1 if m==test: stdout.write('YES'+'\n') stdout.write(str(ans)+'\n') else: stdout.write('NO'+'\n')
The Fair Nut found a string s. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences p_1, p_2, …, p_k, such that: 1. For each i (1 ≀ i ≀ k), s_{p_i} = 'a'. 2. For each i (1 ≀ i < k), there is such j that p_i < j < p_{i + 1} and s...
1
s = raw_input() def get_s(s): res = '' for let in s: if let in ['a', 'b']: res += let return res s = get_s(s) res = 0 sumi = 0 next_sumi = 0 mod = 1000000007 for i in range(len(s)): if s[i] == 'b': sumi += next_sumi next_sumi = 0 continue res += sumi + 1 ...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that i β‰  j |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of such pairs for the given array and the integer K. Input The first lin...
1
for asd in range(int(raw_input())): n,k=map(int,raw_input().split()) a=map(int,raw_input().split()) mini=10000000000 count=0 for i in range (n): for j in range(i+1,n): temp=abs(a[j]+a[i]-k) if(temp==mini): count+=1 elif (temp<mini): ...
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
import math k = int(input()) t = 0 i = 0 while i < k: s = input() if s == 'X++': t += 1 elif s == '++X': t += 1 elif s == '--X': t -= 1 elif s == 'X--': t -= 1 i += 1 print(t)
Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix M of size n Γ— n contains only 'X' and '.' (without quotes). The element in the i-th row and the j-th column (i, j) is defined as M(i, j), where 1 ≀ i, j ≀ n. We define a cross appearing in the i-th row and the j-th column (1 < i...
3
n = int(input()) a = [] for i in range(n): d = input() a.append(d) #print(a) count = 0 for i in range(n): for j in range(n): count1 = 0 if a[i][j] == 'X': if (i-1>=0 and j+1<n) and a[i-1][j+1] == 'X': count1+=1 if (i-1>=0 and j-1>=0) and a[i-1][j-1] ==...
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
(n,m,a)=map(int,input().split()) b=n//a p=m//a if n%a!=0: b=b+1 if m%a!=0: p=p+1 print(b*p)
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage...
3
a="" for i in range(3): a+=input() if a==a[::-1]: print("YES") else: print("NO")
Berland annual chess tournament is coming! Organizers have gathered 2Β·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers sh...
3
n = int(input()) line = input() nums = [int(s) for s in line.split()] nums.sort() if nums[n] > nums[n-1]: print("YES") else: print("NO")
Ibis is fighting with a monster. The health of the monster is H. Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins wh...
3
h,n,*t=map(int,open(0).read().split()) dp=[10**18]*(h+1) dp[0]=0 for a,b in zip(*[iter(t)]*2): for j in range(h+1): dp[j]=min(dp[j],dp[max(0,j-a)]+b) print(dp[h])
There are N bags of biscuits. The i-th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags. He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such wa...
3
n,p=map(int,input().split()) a=list(map(int,input().split())) j=True for t in a: if t%2!=0: j=False break if j: print(2**n if p==0 else 0) else: print(2**(n-1))
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Pe...
3
n, t = map(int, input().split()) a = sorted([list(map(int, input().split())) for _ in range(n)]) ans = 2 for i in range(n - 1): if a[i + 1][0] * 2 - a[i + 1][1] - a[i][0] * 2 - a[i][1] > t * 2: ans += 2 elif a[i + 1][0] * 2 - a[i + 1][1] - a[i][0] * 2 - a[i][1] == t * 2: ans += 1 print(ans)
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied. ZS and Chris are...
3
a = int(input()) h = [] count = 0 count1 = 0 for i in range(a): count1 += 1 b = input() c = b[:2] s = b[3:] if c[0] == "O" and c[1] == "O": f = b.replace("O", "+", 2) h.append(f) count+=1 break elif s[0] == "O" and s[1] == "O": r = s.replace("O", "+") ...
You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar! An array a of length n is called complete if all elements are positive and don't exceed 1000, and for all indices x,y,z (1 ≀ x,y,z ≀ n), a_{x}+a_{y} β‰  a_{z} (not necessarily distinct). You are given one integer ...
3
p=int(input()) for i in range(0,p): q=int(input()) k=1 l=[] for j in range(0,q): l.append(1) l=[str(u) for u in l] print(' '.join(l))
The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crim...
3
n, limit, janela = input().split() n = int(n) limit = int(limit) janela = int(janela) presos = [*map(int, input().split())] count = 0 i = 0 acc = 0 while(i < n): if(presos[i] <= limit): acc += 1 i += 1 if(acc >= janela): count += 1 else: acc = 0 i += 1 print(count)
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti...
1
import sys sys.setrecursionlimit(1 + 10**5) n = int(raw_input()) a = sorted([map(int, raw_input().split()) for _ in range(n)]) M = max(a) z = dict(a) d = [-1 for _ in range(0, 1 + M[0])] def f(x): if x < 0: return 0 if d[x] == -1: if x in z: idx = x - z[x] - 1 d[x] = (...
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
m=input().lower() n=input().lower() l=0 for i in range(len(m)): if ord(m[i])>ord(n[i]): l+=1 break elif ord(m[i])<ord(n[i]): l-=1 break else: l=0 print(l)
You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k in different moves. Your task is to find the minimum number of mo...
3
t = int(input()) for _ in range(t): a,b = map(int,input().split()) if(a>b): a,b = b,a ans = (b-a)//10 if((b-a)%10!=0): ans+=1 print(ans)
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
3
def is_prime(n): if n == 1: return False i = 2 while i*i <= n: if n % i == 0: return False i += 1 return True n = int(input()) half = int(n/2) i=4; while i<=half: if not is_prime(i) and not is_prime(n-i): print(i,n-i) break; else: i+=1
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
t = int(input()) for _ in range(t): ## n, k = map(int, input().split()) ## l = list(map(int, input().split())) n = int(input()) if n > 30: if n - 30 == 6: print("YES") print(5, 6, 10, 15) elif n - 30 == 14: print("YES") print(6...
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of o...
3
a = input() b = input() if a != b: if len(a) >= len(b): print(len(a)) else: print(len(b)) else: '''l1=[a[0]] l2=[b[0]] for i in range(0,len(a)): s="" for j in range(i+1, len(a)): s+=a[j] l1.append(s) for i in range(0,len(b)): s="" ...
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
from math import * t=int(input()) while t!=0: n, m=map(int,input().split()) print(ceil(n*m/2)) t-=1
Orac is studying number theory, and he is interested in the properties of divisors. For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, such that aβ‹… c=b. For n β‰₯ 2, we will denote as f(n) the smallest positive divisor of n, except 1. For example, f(7)=7,f(10)=2,f(35)=5. ...
3
for _ in range(int(input())): n,k = map(int,input().split()) if n%2==0: print(n + 2*k) else: i=2 f = 0 while i*i<=n: if n%i==0: f = 1 break i+=1 if f==0: print(n+n + 2*(k-1)) else: ...
You've got a 5 Γ— 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1....
3
def solve(matrix): i = r = c = 0 isFound = False while i<5 and not isFound: j = 0 while j<5 and not isFound: if matrix[i][j] == '1': r = i c = j isFound = True j+=1 i+=1 return abs(r-2) + abs(c-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
line1 = str(input()) line2 = str(input()) k = int(line1.split(" ")[1]) arr = [int(x) for x in line2.split(" ")] sc = arr[k - 1] ans = 0 for i in arr: if i > 0 and i >= sc: ans += 1 print(ans)
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given n numbers finds one that is di...
3
n = int(input()) nss = [int(i) for i in input().split()] even = 0 odd = 0 for i in nss: if i%2 == 0: even += 1 else: odd += 1 if odd == 1: for i in range(0,len(nss)): if nss[i]%2 != 0: print(i+1) break else: for i in range(0,len(nss)): if nss[i]%2...
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiadβ€”'1' for a correctly identified cow and '0' otherwise. However, all is not...
3
from collections import Counter _ = input() s = input().strip() sequences = Counter() cur_seq_len = 1 for p, n in zip(s, s[1:] + '*'): if p == n: cur_seq_len += 1 else: if cur_seq_len > 3: cur_seq_len = 3 sequences[cur_seq_len] += 1 cur_seq_len = 1 basic = sum(seq...
Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You h...
3
numbers = list(map(int,input().split(' '))) max = max(numbers) numbers.remove(max) for number in numbers: print(max-number)
We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\cdots, N and 1, 2, \cdots, N-1. Edge i connects Vertex u_i and v_i. For integers L, R (1 \leq L \leq R \leq N), let us define a function f(L, R) as follows: * Let S be the set of the vertices numbered L through R. f(L, R) represents the number ...
3
def solve(): n = int(input()) res = 0 for i in range(n - 1): u, v = map(int, input().split()) if u > v: u, v = v, u res += u * (n-v+1) return n * (n+1) * (n+2) // 6 - res print(solve())
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like...
3
a,b=map(int,input().split()) count=0 while a>0: a=a-1 count=count+1 if count%b==0: a=a+1 print(count)
AtCoder Inc. holds a contest every Saturday. There are two types of contests called ABC and ARC, and just one of them is held at a time. The company holds these two types of contests alternately: an ARC follows an ABC and vice versa. Given a string S representing the type of the contest held last week, print the str...
3
print('ARC' if input()[1]=='B' else 'ABC')
There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to...
3
dis = [int(i) for i in input().split()] d1 = abs(dis[1] - dis[0]) d2 = abs(dis[2] - dis[1]) d3 = abs(dis[2] - dis[0]) L1 = d1 + d2 L2 = d1 + d3 L1 = min(L1, L2) L1 = min(L1, d2 + d3) print(L1)
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another. Note that in this problem you do not have to minimize the number of sw...
1
def srt(lst): print len(lst)-1 for i in range(0,len(lst)-1): mn = min(range(i,len(lst)), key=lst.__getitem__) lst[i],lst[mn] = lst[mn],lst[i] print i, mn return lst n = int(raw_input()) l = map(int, raw_input().split()) ans = srt(l)
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input The first line contains integ...
1
lenghtOfString = int(input()) inputString = raw_input() count = 0 if len(inputString) == lenghtOfString: for i in range(1,lenghtOfString): if inputString[i] == inputString[i-1]: count +=1 print count
Shubham has a binary string s. A binary string is a string containing only characters "0" and "1". He can perform the following operation on the string any amount of times: * Select an index of the string, and flip the character at that index. This means, if the character was "0", it becomes "1", and vice versa. ...
3
import sys from functools import reduce read=sys.stdin.buffer.readline mi=lambda :map(int,read().split()) cin=lambda :int(read()) for _ in range(cin()): s=input() no,nz=0,0 for el in s: if el=='0': nz+=1 else: no+=1 ans=min(no,nz) tnz,tno=0,0 for el in ...
Tomorrow is a difficult day for Polycarp: he has to attend a lectures and b practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them. While preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and d...
3
''' CODED WITH LOVE BY SATYAM KUMAR ''' from sys import stdin, stdout import heapq import cProfile, math from collections import Counter, defaultdict, deque from bisect import bisect_left, bisect, bisect_right import itertools from copy import deepcopy from fractions import Fraction import sys, threading import operat...
β€” Hey folks, how do you like this problem? β€” That'll do it. BThero is a powerful magician. He has got n piles of candies, the i-th pile initially contains a_i candies. BThero can cast a copy-paste spell as follows: 1. He chooses two piles (i, j) such that 1 ≀ i, j ≀ n and i β‰  j. 2. All candies from pile i are...
3
from sys import stdin inp = lambda : stdin.readline().strip() t = int(inp()) for _ in range(t): n, k = [int(x) for x in inp().split()] a = [int(x) for x in inp().split()] a.sort() ans = 0 minimum = float('inf') for i in range(1,n): x = ((k-a[i])//a[0]) ans += x mi...
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the displ...
1
#!/usr/bin/env python from array import array # entrada n = int(raw_input()) cod = int(raw_input()) numero = [] for i in range(n): numero.append(cod % 10) cod = cod/10; numero.reverse() # encontra clusters i = 0 clusters = [] nclusters = 0 tam_max = 1 while i < n: tam_atual = 1 inicio = i di...
In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to n. The teacher came to student a and put a hole in his badge. The student, ...
3
def main(): n = int(input()) arr = list(map(int,input().split())) adj = [[] for i in range(n)] for i in range(n): adj[i].append(arr[i]-1) def dfs_iter(s): nb_holes =[0]*n path = list() stack = list() stack.append(s) while(stack): s = sta...
You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≀ i ≀ m - k. You need to find the smallest beautiful integer y,...
3
n, k = map(int, input().split()) s = input() num = s[:k]*(n//k) + s[:n%k] print(n) if s <= num: print(num) else: v = str(int(s[:k]) + 1) num = v * (n//k)+ v[:n%k] print(num)
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
luckyCount = 0 num = input() for i in range(len(num)): if num[i] == "4" or num[i] == "7": luckyCount += 1 newNum = str(luckyCount) isLucky = True for i in range(len(newNum)): if newNum[i] != "4" and newNum[i] != "7": isLucky = False if(isLucky): print("YES") else: print("NO")
Find the minimum area of a square land on which you can place two identical rectangular a Γ— b houses. The sides of the houses should be parallel to the sides of the desired square land. Formally, * You are given two identical rectangles with side lengths a and b (1 ≀ a, b ≀ 100) β€” positive integers (you are given ...
3
from sys import stdin, stdout ##import math T = int(stdin.readline()) for i in range(T): a,b= map(int, stdin.readline().split()) stdout.write(str((max(2*min(a,b), max(a,b) ))**2)+ '\n')
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
3
x=(input().lower()).split('wub') print((" ".join(x)).upper())
Given an integer x, find 2 integers a and b such that: * 1 ≀ a,b ≀ x * b divides a (a is divisible by b). * a β‹… b>x. * a/b<x. Input The only line contains the integer x (1 ≀ x ≀ 100). Output You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of in...
3
x=int(input()) if x%2==0: a=x b=a if a*b>x and a//b<x: print(str(a)+" "+str(b)) else: print(-1) else : a=x-1 b=a if a*b>x and a//b<x: print(str(a)+" "+str(b)) else: print(-1)
There are N squares aligned in a row. The i-th square from the left contains an integer a_i. Initially, all the squares are white. Snuke will perform the following operation some number of times: * Select K consecutive squares. Then, paint all of them white, or paint all of them black. Here, the colors of the squares...
3
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x)-1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip(...
Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play! More specifically, he wants to get from (0,0) to (x,0) by making multiple hops. He is only willing to hop from one point to another point on the 2D plane if the Euclidean distance betw...
3
import math for _ in range(int(input())): n,d=map(int,input().split()) arr=list(map(int,input().split())) if(d in arr): print(1) else: print(max(2,math.ceil(d/max(arr))))
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
3
t=int(input()) for _ in range(t): n=int(input()) arr=[int(x) for x in input().split()] if(n<=2): print(0) continue greatLeft=[-1 for i in range(n)] greatRight=[-1 for i in range(n)] stack=[] for i in range(n): length=len(stack) while(length>0 and arr[stack[length-1]]<arr[i]): greatRi...
You are given two binary strings a and b of the same length. You can perform the following two operations on the string a: * Swap any two bits at indices i and j respectively (1 ≀ i, j ≀ n), the cost of this operation is |i - j|, that is, the absolute difference between i and j. * Select any arbitrary index i (1 ...
3
n = int(input()) a = list(input()) b = list(input()) dp = [] sm1 = 0 sm2 = 0 for i in range(n - 1): if a[i] != b[i] : if a[i] != a[i + 1 ] and a[i + 1 ] != b[i + 1 ]: sm1 += abs(i - i + 1 ) a[i] , a[i + 1 ] = a[i + 1 ] , a[i] else: continue else: cont...
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly n pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Som...
1
#!/usr/bin pages = input() days = map( int, raw_input().split() ) read = sum(days) if ( read < pages ): pages = pages % read if pages == 0: pages = read for i, r in enumerate( days ): pages = pages - r if pages <= 0: print -~i break
Takahashi's house has only one socket. Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets. One power strip with A sockets can extend one empty socket into A empty sockets. Find the minimum number of power strips required. Constraints * All values in inp...
3
A, B = map(int, input().split()) A -= 1 B -= 1 print((B + A - 1) // A)
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
sum = 0 n = int(input()) x = list(map(int, input().split())) for i in range(n): sum += x[i] z = sum / len(x) print(z)
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
3
t=int(input()) for i in range(t): s=input() if len(s)>10: s=s[0]+str(len(s)-2)+s[-1] print(s)
Diamond Miner is a game that is similar to Gold Miner, but there are n miners instead of 1 in this game. The mining area can be described as a plane. The n miners can be regarded as n points on the y-axis. There are n diamond mines in the mining area. We can regard them as n points on the x-axis. For some reason, no m...
1
from __future__ import division,print_function import sys le = sys.__stdin__.read().split("\n")[::-1] af=[] for zorg in range(int(le.pop())): n=int(le.pop()) x=[] y=[] for k in range(2*n): a,b=list(map(int,le.pop().split())) if a==0: y.append(abs(b)) else: ...
Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size n Γ— m. Each cell in this grid was either empty, containing one little pig, or containing one wolf. A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid of ...
3
n,m=map(int,input().split()) l=[] s="" a=[[-1 for i in range (m+2)]for j in range(n+2)] count=0 for i in range(1,n+1): s=input() for j in range(1,m+1): if s[j-1]=='P': a[i][j]=0 elif s[j-1]=='W': a[i][j]=1 for i in range(1,n+1): for j in range(1,m+1): if a[i][...
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length ...
3
d1,d2,d3=map(int,input().split()) x1=d1+d3+d2 x2=d1+d3+d3+d1 x3=d2+d2+d1+d1 x4=d2+d3+d3+d2 print(min(x1,x2,x3,x4))
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
3
import sys n, v = list(map(int, sys.stdin.readline().rstrip().split())) kc_ls = [] kayaks = [] catamaran = [] total_space = 0 total_capacity = 0 for i in range(1, n + 1): kc_ls.append( tuple(map(int, sys.stdin.readline().rstrip().split() + [i])) ) # Numbering the items kc_ls.sort(key=lambda x: x[1] if...
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
import math n,m,a = list(map(int, input().split(' '))) s=math.ceil(n/a) f=math.ceil(m/a) print(s*f)
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
def check(b): if b%4==0: return("YES") else: return("NO") a = int(input()) c=[] for i in range(0,a): b= int(input()) c.append(check(b)) for i in range(0,len(c)): print(c[i])
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls f...
3
a, b, c, d = map(int, input().split()) if b >= a: print("Second") else: print("First")
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
from math import ceil data = raw_input() m,n,a = map(float, data.split()) print int(ceil(m/a)*ceil(n/a))
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...
1
def fun(str, hello): if len(hello) == 0: return True if len(str) == 0: return False for i, s in enumerate(str): if s == hello[0]: return fun(str[i+1:], hello[1:]) return False print ["NO", "YES"][fun(raw_input(), "hello")]
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
n = int(input()) result = [] for i in range(n): l, r = map(int, input().split()) x = l y = x*2 if y > r: result.append([-1, -1]) else: result.append([x, y]) for ele in result: for j in ele: print(j, end = ' ') print()
Today at the lesson of mathematics, Petya learns about the digital root. The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-d...
3
def func(k, x): return x+(k-1)*9 n = int(input()) for i in range(n): s = input().split() print(func(int(s[0]), int(s[1])))
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, p...
3
H, W = map(int, input().split()) for i in range(H): S = input() print(S+'\n'+S)
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
lis = [int(x) for x in range(5,0,-1)] n = int(input()) count = 0 for i in lis: if(i<=n): count+=n//i n=n%i print(count)