problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow...
3
n=int(input()) last=str(n) last = last[-1] if n>=0: print(n) else: a = str(n) a = a[:-1] a = int(a) b = str(n) b= b[:-2] b = b + last b = int(b) if a>b: print(a) else: print(b)
It is winter now, and Max decided it's about time he watered the garden. The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned ...
3
def build_lands(a): lands = [] for one in range(a): lands.append(0) return lands if __name__ == "__main__": num = int(input()) for num_ in range(num): time = 0 args = input().split(" ") land, water = int(args[0]), int(args[1]) water_p = [] for w_p in...
Arkady and his friends love playing checkers on an n × n field. The rows and the columns of the field are enumerated from 1 to n. The friends have recently won a championship, so Arkady wants to please them with some candies. Remembering an old parable (but not its moral), Arkady wants to give to his friends one set o...
3
n, m = list(map(int, input().split(' '))) ans = 0 for i in range(1, m+1): for j in range(1, m+1): if (i*i + j*j) % m == 0: ans += ((n - i) // m + 1) * ((n - j) // m + 1) print(ans)
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
3
a=[int(x) for x in input().split()] a=set(a) b=4-len(a) print(b)
HQ9+ is a joke programming language which has only four one-character instructions: * "H" prints "Hello, World!", * "Q" prints the source code of the program itself, * "9" prints the lyrics of "99 Bottles of Beer" song, * "+" increments the value stored in the internal accumulator. Instructions "H" and "Q"...
1
def check(s): for c in s: if (c == 'H' or c == 'Q' or c == '9'): print "YES" return ; print "NO" s = raw_input(); check(s);
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ Output Print the previ...
3
import sys; import itertools; n = int(sys.stdin.readline()) a = tuple(map(int, sys.stdin.readline().split())) prev=() for l in itertools.permutations(sorted(a), n): if a==l: if len(prev)>0: print(' '.join(map(str,prev))) print(' '.join(map(str,a))) if prev==a: print(' '.joi...
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two adjacent elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this. Constraint...
3
n=int(input()) a=list(map(int,input().split())) ans=0 for i in range(n): if i+1==a[i]: ans+=1 if i!=n-1: a[i+1]=a[i] print(ans)
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard. If at least one of these n people has answered that th...
3
bloat = input() feedback = input().split() if '1' in feedback: print("HARD") else: print("EASY")
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. Input The first line cont...
3
from sys import stdin n = int(stdin.readline()) arr = [int(x) for x in stdin.readline().split()] le = 1 prev = -1 ptr = 0 while ptr<n-1: if arr[ptr] >= arr[ptr+1]: le = max ( le , ptr-prev ) prev = ptr ptr += 1 if prev != n-2: le = max ( le , n-1-prev ) print(le)
Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny. He has a special interest to create difficult problems for others to solve. This time, with many 1 × 1 × 1 toy bricks, he builds up a 3-dimensional object. We can describe ...
1
#! /usr/bin/python n, m, h = [int(inp) for inp in raw_input().split()] a = [int(inp) for inp in raw_input().split()] b = [int(inp) for inp in raw_input().split()] t = [[int(inp) for inp in raw_input().split()] for _ in xrange(n)] for curH in xrange(h, -1, -1): for x in xrange(n): for y in xrange(m): if a[y] >...
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k. <image> The description of the first test case. Since sometimes it's impossible to find such point ...
3
for i in range(int(input())): n,k=map(int,input().split()) if n==k: print(0) else: if k==0: if n%2==0: print(0) else: print(1) elif n>k: if n%2==0 and k%2==0: print(0) elif n%2!=0 and k%2!...
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input The first line contains integ...
3
n = int(input()) s = input() num_s= 0 for num in range(n): if num == n - 1: break if s[num] == s[num +1]: num_s += 1 print(num_s)
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
n=int(input()) data=input().split() for i in range(n): data[i]=int(data[i]) max_index=0 min_index=0 for i in range(n): if data[i]==max(data): max_index=i break for i in range(n): if data[i]==min(data): min_index=i moves=0 #print(min_index) #print(max_index) status=False if min_index<...
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
import sys inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 ttt = inp[ii]; ii += 1 for _ in range(ttt): x, y, n = inp[ii: ii + 3]; ii += 3 rem = y % x print((n - rem) // x * x + rem)
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() c=0 d=0 for i in range(len(s)): if(s[i]=='1' and i!=0): if(s[i-1]!='1'): c=0 if(s[i]=='0' and i!=0): if(s[i-1]!='0'): d=0 if(s[i]=='1' and i!=0): if(s[i-1]=='1'): c+=1 if(s[i]=='0' and i!=0): if(s[i-1]=='0'): d+=1 ...
The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of n haybale piles on the farm. The i-th pile contains a_i haybales. However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an a...
3
x = input() for i in range(int(x)): des = input() val = input() n = int(des.split(" ")[0]) d = int(des.split(" ")[1]) counter = 1 list = val.split(" ") lemon = int(list[0]) for i in list[1:]: if(int(i)*counter<=d): #we can move all d = d - int(i)*counter ...
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
3
str1=input() str2=input() list=[] for x in range(len(str1)): if str1[x]!=str2[x]: list.append(1) else: list.append(0) for x in range(len(str1)): print(list[x],end="")
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 × n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed h...
1
n = input() h = map(int, raw_input().split()) p = 1 for i in range(n): l, r = i, i + 1 while l > 0 and h[l - 1] <= h[l]: l -= 1 while r < n and h[r - 1] >= h[r]: r += 1 p = max(p, r - l) print p
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ld...
3
n,k = [int(i) for i in input().split()] h = [int(i) for i in input().split()] inf = 10**10 dp = [inf]*n dp[0] = 0 for i in range(1,n): dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]) for j in range(min(i,k)+1)) print(dp[n-1])
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N. When Takahashi eats Dish i, he earns A_i points of happiness; when Aoki eats Dish i, she earns B_i points of happiness. Starting from Takahashi, they alternately choose one dish and ...
3
n=int(input()) a=[] b=[] l=[] ans=0 for i in range(n): x,y=map(int,input().split()) a+=[x] b+=[y] l+=[(x,y,i)] l.sort(key=lambda x:x[0]+x[1]) for x in l[-1::-2]: ans+=a[x[2]]+b[x[2]] print(ans-sum(b))
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it. Constraints * The length of S is 2 or 3. * S consists of lowercase English letters. Input Input is given from Standard Input i...
3
s = input() print([s,s[-1::-1]][len(s) == 3])
In Japan, people make offerings called hina arare, colorful crackers, on March 3. We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have ...
3
_ = input() s = set(input().split()) print("TFhoruere"[len(s)==4::2])
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) po...
3
w, h, n = map(int, input().split()) d = l = 0 u = h r = w for _ in range(n): x, y, a = map(int, input().split()) if a == 1: l = max(l, x) elif a == 2: r = min(r, x) elif a == 3: d = max(d, y) else: u = min(u, y) print(max(0, u - d) * max(0, r - l))
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,...
3
n,v=map(int,input().split()) a=[] for x in range(n): p=list(map(int,input().split())) a.append((p[0],p[1])) a.sort() arr=[0]*(4000) for x in range(n): arr[a[x][0]]+=a[x][1] tmp=max(0,arr[a[x][0]]-v) arr[a[x][0]]-=tmp arr[a[x][0]+1]+=tmp arr[a[x][0]+1]=min(arr[a[x][0]+1],v) print(sum(arr))
You are given an integer number n. The following algorithm is applied to it: 1. if n = 0, then end algorithm; 2. find the smallest prime divisor d of n; 3. subtract d from n and go to step 1. Determine the number of subtrations the algorithm will make. Input The only line contains a single integer n (2 ≤...
3
n = int( input() ) d = n i = 2 while i * i <= n: div = n // i if i * div == n: d = i break i += 1 print( 1 + ( n - d ) // 2 )
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...
3
z=[int(X) for X in input().split()] n=z[0] m=z[1] a=z[2] b=z[3] if(b/m >= a): print(a*n) else: cost=0 e=n//m cost+=e*b rem=(n%m)*a if(rem<=b): cost+=rem print(cost) else: cost+=b print(cost)
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
max=0 current=0 for _ in range(int(input())): out,inp=map(int,input().split()) current-=out current+=inp if(current>max): max=current print(str(max))
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that a yuan for b kilos (You don't need to care about what "yuan" is), the same as a/b yuan for a kilo. Now imagine you'd like ...
3
fin=list(map(int,input().split())) need=[] for x in range(fin[0]): inp=list(map(int,input().split())) need.append(inp[0]/inp[1]) print(round(min(need)*fin[1],8))
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...
3
import math n,m=map(int,input().split()) l=sorted(list(map(int,input().split()))) min1=5000 for i in range(len(l)): if(i+n-1>len(l)-1): break min1=min(min1,l[i+n-1]-l[i]) print(str(min1))
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many ...
3
t = list(map(int, input().split())) a = list(map(int, input().split())) c = 0 for n in a: if n >= a[t[1]-1] and n > 0: c += 1 print(c)
Ashish and Vivek play a game on a matrix consisting of n rows and m columns, where they take turns claiming cells. Unclaimed cells are represented by 0, while claimed cells are represented by 1. The initial state of the matrix is given. There can be some claimed cells in the initial state. In each turn, a player must ...
3
t=int(input()) for _ in range(t): n,m=list(map(int,input().split())) r=0 c=[] for i in range(n): t=list(map(int,input().split())) if(t.count(1)==0): r+=1 for i in range(m): if(t[i]==1): if(i not in c): c+=[i] c=m-len...
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
3
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) first = [] second = [] zeroes = a.count(0) ones = a.count(1) if zeroes%2: if (ones-1) >= n//2: print(ones-1) print(*[1 for i in range(ones-1)]) els...
A card pyramid of height 1 is constructed by resting two cards against each other. For h>1, a card pyramid of height h is constructed by placing a card pyramid of height h-1 onto a base. A base consists of h pyramids of height 1, and h-1 cards on top. For example, card pyramids of heights 1, 2, and 3 look as follows: ...
3
import bisect list=[] for i in range(1,10**5): list.append((3*i**2+i)//2) for _ in range(int(input())): n=int(input()) count=0 while n>=2: r=bisect.bisect_right(list,n) n-=list[r-1] count+=1 print(count)
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before. It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl...
3
x , y = map(int,input().split()) if x == y : print('=') exit() if x == 1 : print('<') exit() if y == 1 : print('>') exit() if x == 2 and y == 4 or x == 4 and y == 2 : print('=') exit() if x == 3 and y == 2 : print('>') exit() if x == 2 and y == 3 : print('<') exit() ...
Three swimmers decided to organize a party in the swimming pool! At noon, they started to swim from the left side of the pool. It takes the first swimmer exactly a minutes to swim across the entire pool and come back, exactly b minutes for the second swimmer and c minutes for the third. Hence, the first swimmer will b...
3
from typing import List def closest(start: int, values: List[int]) -> int: timings = [(item - (start % item)) % item for item in values] return min(timings) def read_input(filename: str = None) -> None: from sys import stdin stdin = open(filename) if filename else stdin cases = int(stdin.readlin...
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the...
3
no=int(input()) main=[] for i in range(no): x=list(map(int,input().split())) x=sum(x) main.append(x//2) for i in main: print(i)
The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n - 1 in the order from the beginning of the street to the end (in the picture: from ...
3
n, a = map(int, input().split()) if a % 2 == 0: a = n - a + 1 print(a // 2 + 1)
There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other. Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro: * Choose an element x in A, and remove e...
3
N, K = map(int, input().split()) a = list(map(int, input().split())) dp = [False]*(K+1) for i in range(K+1): for ai in a: if i-ai>=0: dp[i] |= not dp[i-ai] if dp[K]: print('First') else: print('Second')
After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the fi...
3
#Bhargey Mehta (Sophomore) #DA-IICT, Gandhinagar import sys, math, queue sys.setrecursionlimit(1000000) #sys.stdin = open("input.txt", "r") n = int(input()) l = [-1 for i in range(n)] r = [-1 for i in range(n)] for i in range(n): l[i], r[i] = map(int, input().split()) k = int(input()) for i in range(n): if k >= l[i...
You have array a1, a2, ..., an. Segment [l, r] (1 ≤ l ≤ r ≤ n) is good if ai = ai - 1 + ai - 2, for all i (l + 2 ≤ i ≤ r). Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l1, r1], is longer than segment [l2, r2], if len([l1, r1]) > len([l2, r2]). Your task is to find a ...
3
def read_args(): n = int(input()) a = list(map(int, input().split())) return a, n def get_good_segment_of_max_length(a, n): if n <= 2: return n count = 0 current_count = 0 for i in range(n - 2): if a[i] + a[i + 1] == a[i + 2]: current_count += 1 if c...
You are given an array of n integers a_1,a_2,...,a_n. You have to create an array of n integers b_1,b_2,...,b_n such that: * The array b is a rearrangement of the array a, that is, it contains the same values and each value appears the same number of times in the two arrays. In other words, the multisets \\{a_1,a_...
3
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) pos=[] neg=[] cs=0 flag=0 for i in l: if(i>0): pos.append(i) fp=1 elif i<0: neg.append(i) else: pos.append(i) cs+=i if(cs==0): ...
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 = tuple(map(int, input().split())) print((m * n) // 2)
A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true: * Employee A is the immediate manag...
3
n = int(input()) parent = [-1] * n lvl = [-1] * n for i in range(n): x = int(input()) if x > 0: parent[i] = x - 1 else: lvl[i] = 1 for i in range(n): flag = False for j in range(n): if lvl[j] != -1: continue if lvl[parent[j]] != -1: lvl[j] = lvl[parent[j]] + 1 flag = True if not flag: break pri...
After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem. Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For exa...
3
def check(s): if s.count('0') != s.count('1'): return True return False def solve(a,res): if check(a): res.append(a) return res for i in range(len(a)): if check(a[:i+1]): res.append(a[:i+1]) return solve(a[i+1:], res) n = int(input()) s = ...
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 = str(input().lower()) n = str(input().lower()) if m == n: print ('0') elif m> n : print ('1') else: print ('-1')
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant...
3
s=input() s1="aeiou" s2="aeioun" f=0 if(s[len(s)-1] not in s2 ): f=1 for i in range(len(s)-1): if(s[i] not in s1 and s[i]!="n"): if(s[i+1] not in s1): #print(s[i+1]) f=1 break if(f==1): print("NO") else: print("YES")
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not. Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each c...
3
def check(s): for i in range(len(s) - 1): if s[i] == s[i+1] and s[i] != '?': return True return False for _ in range(int(input())): l = input() ch = check(l) if ch: print(-1) else: l = list(l) for i in range(len(l)): if l[i] ==...
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
3
s = input() d = {} for c in s: d[c] = 1 if len(d) % 2 == 1: print("IGNORE HIM!") else: print("CHAT WITH HER!")
There are N cubes stacked vertically on a desk. You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is `0`, and blue if that character is `1`. You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent...
3
S = input() print(len(S) - abs(S.count('1') - S.count('0')))
There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y. Co...
3
N = input() V = map(int, input().split()) C = map(int, input().split()) xy = 0 for v, c in zip(V, C): if c < v: xy += v - c print(xy)
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
string1 = input() string2 = input() string1 = string1.lower() string2 = string2.lower() if string1 > string2: print(1) elif string1 == string2: print(0) else: print(-1)
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If t...
3
n = int (input ()) a = list (map (int, input ().split ())) otv = [0,0] * n for i in range (n): j = a[i] otv[j] = i + 1 while 0 in otv: otv.remove (0) print (*otv)
The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2). You are given a sequence a consisting of n integers. All these integers are distinct, each value from 1 to n appears in the sequence exactly once. You are making a sequen...
3
def f(r1): global r, lastNum, lPos, rPos r.append(r1) if r1 == 'L': lastNum = a[lPos] lPos += 1 else: lastNum = a[rPos] rPos -= 1 def onlyLeft(begin): global a pos = begin while a[pos] < a[pos+1]: pos += 1 return pos - begin + 1 def onlyRight(beg...
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and ...
3
a, b = map(int, input().split()) greater = max(a, b) lesser = min(a, b) print(lesser, (greater - lesser) // 2)
<image> You have one chip and one chance to play roulette. Are you feeling lucky? Output Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares).
1
print "even"
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: * deletes all the vowels, * inserts a character "." before each consonant, * repl...
3
import sys for line in sys.stdin: print('.' + '.'.join(line.translate(str.maketrans('','','AEIOUYaeiouy')).lower())[:-2])
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
3
Positions={'r': 17, 'f': 5, 'q': 16, 'x': 23, 'h': 7, 'w': 22, 't': 19, 'm': 12, 'p': 15, 'z': 25, 'k': 10, 'u': 20, 'a': 0, 'y': 24, 'b': 1, 'c': 2, 'i': 8, 'g': 6, 's': 18, 'd': 3, 'l': 11, 'v': 21, 'o': 14, 'e': 4, 'n': 13, 'j': 9} nom=input() pointeur=0 S=0 for i in nom: mouvements=(Positions[i]-pointeur)%26 ...
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
h,l = [int(x) for x in input().split()] x=((l*l-h*h)/(2*h)) print(x)
Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by...
3
import math R,x1,y1,x2,y2=map(int,input().split()) x2-=x1 y2-=y1 v=math.sqrt(x2*x2+y2*y2) if v>=R : print(x1,y1,R) quit() if v==0 : print(x1+R/2,y1,R/2) quit() d=v+R ans3=d/2 x3=x2+(-x2)*((v+R)/v) y3=y2+(-y2)*((v+R)/v) ans1=x2+(x3-x2)*0.5 ans2=y2+(y3-y2)*0.5 print(ans1+x1,ans2+y1,ans3)
You are given a string s=s_1s_2... s_n of length n, which only contains digits 1, 2, ..., 9. A substring s[l ... r] of s is a string s_l s_{l + 1} s_{l + 2} … s_r. A substring s[l ... r] of s is called even if the number represented by it is even. Find the number of even substrings of s. Note, that even if some subs...
3
import sys def main(): _, s = sys.stdin.read().strip().split() return sum(i+1 for i,j in enumerate(map(int, s)) if not j%2) print(main())
Guy-Manuel and Thomas have an array a of n integers [a_1, a_2, ..., a_n]. In one step they can add 1 to any element of the array. Formally, in one step they can choose any integer index i (1 ≤ i ≤ n) and do a_i := a_i + 1. If either the sum or the product of all elements in the array is equal to zero, Guy-Manuel and T...
3
t=int(input()) for ygn in range(t): n=int(input()) a=list(map(int, input().split())) z=0 s=0 p=1 for i in range(n): s+=a[i] p*=a[i] if a[i]==0: z+=1 a[i]=1 if s!=0 and p!=0: print(0) continue if z==0: print(1) ...
A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily 7 days! In detail, she can choose any integer k which satisfies 1 ≤ k ≤ r, and set k days as the number of days in a week. Alice is going to paint some n...
3
# import sys # sys.setrecursionlimit(100000) # f = open('input.txt') # a = list(map(int, f.readline().split())) # f.close() # f = open('output.txt', 'w+') # f.close() inp = lambda: int(input()) inpm = lambda: map(int, input().split()) inpl = lambda: list(inpm()) l2mn = lambda _n, _m: [[0 for __ in range(_m)] for _ in...
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest comm...
1
n=input() a=[raw_input() for _ in range(n)] x=0 while x<len(a[0]): ok=True for i in range(n): if a[i][x]!=a[0][x]: ok=False break if not ok: break else: x+=1 print x
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n. Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes). Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} ...
3
for _ in range(int(input())): n = int(input()) s = [i for i in map(int, input().split(' '))] s = [0] + s dp = [1 for i in range(n + 1)] for i in range(1, n + 1): for j in range(i, n + 1, i): if s[j] > s[i]: dp[j] = max(dp[j], dp[i] + 1) print(max(dp))
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column ...
3
a=input().split() a1=int(a[0]) a2=int(a[1]) ost1=[0,0,0,0,0] ost2=[0,0,0,0,0] for i in range(1,a1%5+1): ost1[i]+=1 for i in range(1,a2%5+1): ost2[i]+=1 a1=a1//5 a2=a2//5 c=a1*a2 for i in range(1,5): c=c+(a1+ost1[i])*(a2+ost2[5-i]) print(c)
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly a_i names.". You got scared (of course yo...
3
import sys data = sys.stdin.readlines() # n = data[0].split()[0] m = int(data[0].split()[1]) a = list(map(int, data[1].split())) page = m for i in a: count = 0 if i < page: page -= i elif i == page: count += 1 page = m else: # i = 90 / m = 9 / page = 6 i -= page page = m count += ...
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100)...
3
import math t=int(input()) for i in range(t): n=int(input()) flag=0 for j in range(2,int(pow(n,0.5)+1)): if n%j==0: n1=n//j for k in range(j+1,int(pow(n1,0.5)+1)): n2=n1//k if n1%k==0 and n2!=k: flag=1 n2=n1//k print("YES") print(j,end=" ") print(k,end=" ") print(n2,end=...
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself,...
3
for _ in range(int(input())): n = int(input()) a = list( map(int,input().split())) isVisited = False d = {} if n == 1: print('YES') continue for k in range(n): m = (k + a[k])%n if m not in d: d[m] = True else: isVisited = True ...
Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations: * multiply the current number by 2 (that is, replace the number x by 2·x); * append the digit 1 to the right of current number (that is, replace the number x by 10·x + 1). You need to help Vasil...
3
a, b = map(int, input().split()) mass = [b] while a != b: if str(b)[-1] != '1' and b % 2 != 0 and a > b or b == 0: print('NO') exit() else: if str(b)[-1] == '1' and len(str(b)) != 1: b = int(str(b)[:-1]) elif b % 2 == 0: b = b // 2 else: print('NO') exit() mass.append(b) print('YES') print(le...
The only difference between easy and hard versions is the length of the string. You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without chang...
3
def c(s1,s2): x=0 for i in range(len(s1)): if(s1[i]==s2[x]): x+=1 if(x==len(s2)): break if(len(s2)==x): return True else: return False s1=input() s2=input() ans=0 for i in range(len(s1)): for j in range(1,len(s1)+1): if(c(s1[0:i]+s1[j:],s2)): ans=max(ans,j-i) print(ans)
Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = (V, E). Constraints * 1 ≤ |V| ≤ 10,000 * 0 ≤ |E| ≤ 100,000 * 0 ≤ wi ≤ 10,000 * The graph is connected * There are no parallel edges * There are no self-loops Input |V| |E| s0 t0 w0 s1 t1 w1 : s|E|-1 t|E|-1 w|E|-...
3
import heapq v, e = map(int, input().split()) edges = [] for i in range(e): s, t, w = map(int, input().split()) heapq.heappush(edges, (w, (s, t))) class Node(): def __init__(self, id): self.id = id self.p = self self.rank = 0 class DisjointSet(): def __init__(self, n): ...
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...
3
n, m, a, b = list(map(int, input().split())) #n, m, a, b = [10,3,5,1] onem = m/b onen = 1/a if onem<=onen: print(n*a) else: sum = (n//m)*b if (n-(n//m)*m)*a>=((n//m)+1)*b-sum: print(((n//m)+1)*b) else: print(sum+(n-(n//m)*m)*a)
New Year is coming! Vasya has prepared a New Year's verse and wants to recite it in front of Santa Claus. Vasya's verse contains n parts. It takes a_i seconds to recite the i-th part. Vasya can't change the order of parts in the verse: firstly he recites the part which takes a_1 seconds, secondly — the part which take...
3
t = int(input()) for _ in range(t): n,s = map(int,input().split()) a = list(map(int,input().split())) if sum(a)<=s: print(0) continue else: sum_=0 big = 0 for i in range(n): if sum_>s: break sum_+=a[i] if a[i] > ...
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there. If t...
3
n = int(input()) l = list(map(int, input().split())) r = [0]*n for i in range(0,n): x = l[i] r[x-1] = i+1 print(*r)
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, …, a_n] of n distinct integers. An array b = [b_1, b_2, …, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears ...
3
import sys def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_array(): return list(get_ints()) def input(): return sys.stdin.readline().strip() T = int(input()) while T > 0: n = int(input()) Arr = get_array() Arr.sort() if(Arr[0] < 0): print("NO") else: ...
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure. Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed...
3
l,r,k = map(int,input().split()) print(*([k**i for i in range(64) if l<=k**i<=r] or [-1]))
You are given a set of n segments on the axis Ox, each segment has integer endpoints between 1 and m inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ m) — coordinates of the left and of the right endpoints. Consider...
3
[n, m] = list(map(int, input().split(" "))) t = [0]*(m+2) for i in range(n): [a, b] = list(map(int, input().split(" "))) t[a] += 1 t[b+1] -= 1 for i in range(1, m+1): t[i] += t[i-1] t.pop() t.pop(0) result = t.count(0) print(result) if result > 0: arr = [] for i in range(m): if t[i] == ...
Petya and Vasya are competing with each other in a new interesting game as they always do. At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in his array should be equal to S. Then Petya has to select an integer K such that 0 ≤ K ≤ S. In order to win, Vasya ha...
3
''' Author : Shubhanshu Jain; ''' import math import random; from collections import * mod =1000000007 r1 = lambda : int(input()); rm = lambda : map(int,input().split()); rms = lambda : map(str,input().split()); rls = lambda : list(rm()) def def_value(): return "nan" def solve(): n,s = rm(); ls = ...
You have two integers l and r. Find an integer x which satisfies the conditions below: * l ≤ x ≤ r. * All digits of x are different. If there are multiple answers, print any of them. Input The first line contains two integers l and r (1 ≤ l ≤ r ≤ 10^{5}). Output If an answer exists, print any of them. Oth...
3
x,y=map(int,input().split()) for i in range(x,y+1): if len(str(i))==len(set(str(i))): print(i) exit() print(-1)
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis. Input The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-t...
3
n=int(input()) l1=0 l2=0 for i in range(n): x,y=map(int,input().split()) if x<0: l1+=1 else: l2+=1 if l1==1 or l2==1 or l1==0 or l2==0: print('Yes') else: print('No')
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws n sticks in a row. After that the players tak...
3
n, k = map(int, input().split()) x = n // k if x % 2 == 0: print('NO') else: print('YES')
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning. To check which buttons need replacement, Polycarp pressed som...
3
q=int(input()) for i in range(q): w=input() k=0 s=[] while k<=(len(w)-1): e=w[k] l=1 while (k+1)<=(len(w)-1) and e==w[k+1]: l+=1 k+=1 if l%2==1: s.append(w[k]) k+=1 print(''.join(sorted(list(set(s)))))
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 main(): a, b = (int(x) for x in input().split()) it = 0 while a <= b: a = 3 * a b = 2 * b it = it + 1 print(it) if __name__ == "__main__": main()
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
input() stones = raw_input().strip() ans, lch = 0, "" for ch in stones: if ch == lch: ans += 1 else: lch = ch print ans
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. Input The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — ...
3
from bisect import bisect_right n,m=map(int,input().split()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] a.sort() for i in b: m=bisect_right(a,i) print(m,end=" ")
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is...
1
n = int(raw_input()) s = raw_input() a = s.count('A') c = s.count('C') g = s.count('G') t = s.count('T') if n % 4 == 0: m = n / 4 if max(a, c, g, t) > m: print '===' else: print s.replace('?', 'A', m-a).replace('?', 'C', m-c).replace('?', 'G', m-g).replace('?', 'T', m-t) else: print '===...
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as...
1
#!/usr/bin/python # coding: utf-8 n=int(raw_input()) arr=map(long,raw_input().split(' ')) arr1=[] for i in xrange(n-1): tmp=abs(arr[i+1]-arr[i]) tmp=tmp*((-1)**i) arr1.append(tmp) arr2=[] for i in xrange(n-1): arr2.append(arr1[i]*(-1)) max=current=0 for i in xrange(n-1): current+=arr1[i] if(c...
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,n=map(int,input().split()) xi=[] yi=[] i=0 while i<n: a=input().split() i=i+1 xi.append(int(a[0])) yi.append(int(a[1])) while 1>0: t=0 for i in range(0,len(xi)): if xi[i]<s: s=s+yi[i] xi.pop(i) yi.pop(i) t=1 break if len(xi)==0: print('YES') break elif t==0: print('NO') break
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
3
a=[[4,7]] for j in range(2): l=[] for i in a[-1]: l.append(10*i+4) l.append(10*i+7) a.append(l) del l a=sum(a,[]) n=int(input().strip()) for i in a: if n%i==0: print("YES") exit(0) print("NO")
There are n houses along the road where Anya lives, each one is painted in one of k possible colors. Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have the same color. She wants to select a long segment of the road such that no two adjacent houses have the same color. H...
3
n,k=map(int,input().split()) a=list(map(int,input().split())) m=0 count=1 val=a[0] if len(a)==1: print(1) else: for i in range(1,len(a)): if val==a[i]: m=max(m,count) count=1 else: count+=1 val = a[i] print(max(m,count))
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
x = list(map(int, input().split())) y = str(input()) k = x[1] alpha ="ABCDEFGHIJKLMNOPQRSTUVWXYZ" list=[0]*27 i =0 c = 0 flag = True while i<k: while c<len(y) : if y[c]==alpha[i]: list[i]=list[i]+1 c+=1 i+=1 c=0 i = 0 min = 100000 while i<k : if list[i]==0: flag = False break else: i...
You are given an integer N. Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w. If there are multiple solutions, any of them will be accepted. Constraints * It is guaranteed that, for the given integer N, there exists a solution such that h,n,w \leq 3500. Inputs Input is given from Stan...
3
N=int(input()) for h in range(1,3501): for n in range(1,3501): if (4*h*n-N*n-N*h) and (4*h*n-N*n-N*h) > 0 and (N*h*n) % (4*h*n-N*n-N*h)==0: print(h,n,(N*h*n) // (4*h*n-N*n-N*h)) exit()
Alice has a string s. She really likes the letter "a". She calls a string good if strictly more than half of the characters in that string are "a"s. For example "aaabb", "axaa" are good strings, and "baca", "awwwa", "" (empty string) are not. Alice can erase some characters from her string s. She would like to know wh...
3
def amount(s): j = 0 k = 0 while True: a = s.find('a', j, len(s)+1) if (a != -1): k += 1 j=a+1 else: return (k) break s = input() m = amount(s) k = len(s)-m if (k > m-1): k = m-1 print(k+m)
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
n=input() #n=int(n) if n==2: print ("NO") elif n%2==0: print ("YES") else: print ("NO")
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and...
3
#!/usr/bin/env python3 """ Codeforces 455 A. Boredom @author yamaton @date 2015-08-22 2015-09-10 2015-09-22 """ import collections def solve(xs): cnt = collections.Counter(xs) xmax = max(xs) f = collections.defaultdict(int) for i in range(1, xmax+1): f[i] = max(f[i-1], cnt[i] * 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()) ipt = [int(x) for x in input().split()] ipt.sort(reverse=True) for i in range(1, n+1): slice1 = ipt[:i] slice2 = ipt[i:] if sum(slice1) > sum(slice2): print(len(slice1)) break
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input A single line contains a non-empty word. This word consists of lowercase and uppercase English letters....
3
s=input() f=s[0] on=s[1:] uc=f.upper() a=f"{uc}{on}" print(a)
Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk. Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a...
1
n, k = map(int, raw_input().split()) walks = map(int, raw_input().split()) original = [] for i in range(len(walks)): original.append(walks[i]) walks.append(k) for i in range(0, len(walks) - 1): today, next_day = walks[i], walks[i+1] if today + next_day < k: walks[i+1] = walks[i+1] + (k - (today + next_d...
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana). He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas? Input The first lin...
3
k, n, w = map(int,input().split()) t = 0 for i in range(w+1): t += i m = t*k if m > n: print(m-n) else: print(0)
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of ...
1
def find_name(ip,l): namen="" for i in range(len(l)): if ip==l[i][1]: namen=l[i][0] break return namen all_inp=[int(inp) for inp in raw_input().split()] n,m,servs,names=all_inp[0],all_inp[1],[],[] for i in range(n): ln=raw_input() name_ip=ln.split(' ') names.appen...