problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
There is a string s of length 3 or greater. No two neighboring characters in s are equal. Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first: * Remove one of the characters in s, excluding both ends. However, a character cannot b...
3
s = input() F = "First" S = "Second" if s[0] == s[-1:]:#odd if len(s)&1: print(S) else: print(F) else: #even if len(s)&1: print(F) else: print(S)
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 class Square(): def __init__(self, inputs): self.shape = inputs[0:2] self.a = inputs[2] def run(self): outcome = 1 for i in range(len(self.shape)): outcome *= math.ceil(self.shape[i] / self.a) return outcome if __name__ == '__main__': inpu...
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
1
from __future__ import division from collections import Counter n = int(raw_input()) vals = map(int, raw_input().split()) cnt = Counter() for x in vals: cnt[x] += 1 def div_ceil(a, b): if a % b == 0: return a // b else: return a // b + 1 result = cnt[4] if cnt[1] == cnt[3]: result +=...
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 int_multiple(): return [int(c) for c in input().split()] def int_single(): return int(input()) def str_multiple(): return [c for c in input().split()] def str_single(): return input() # start s = str_single() t = str_single() ti = 0 start = [] for si in range(len(s)): if(s[si] == t[ti])...
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks. Determine whether the Cossack can reward all participants, giving each of them at leas...
3
n, m, k = map(int, input().split()) print("NYOE S"[min(m, k) >= n::2])
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
3
n=int(input()) if n < 3: print('NO') else: if n%2 ==0: print('YES') else: print('NO')
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() s = list(s) a = s.count('A') g = s.count('G') c = s.count('C') t = s.count('T') q = s.count('?') nucl = n/4 if n%4!=0: print '===' elif a>nucl or g>nucl or c>nucl or t>nucl: print '===' else: a_fill = nucl-a g_fill = nucl-g c_fill = nucl-c t_fill = nucl-t ...
You are given an array a of n integers. You want to make all elements of a equal to zero by doing the following operation exactly three times: * Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different). It can...
3
from sys import stdin """ n=int(stdin.readline().strip()) n,m=map(int,stdin.readline().strip().split()) s=list(map(int,stdin.readline().strip().split())) s=stdin.readline().strip() """ n=int(stdin.readline().strip()) s=list(map(int,stdin.readline().strip().split())) if n==1: print(1,1) print(0) print(1,1) ...
Codeforces user' handle color depends on his rating β€” it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
3
n=int(input()) t=0 for i in range(n): _,b,c=input().split() if int(c)>int(b) and int(b)>=2400: t=1 print(["NO","YES"][t==1])
Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the sock...
3
# check codeforces n = int(input()) n = 2*n pairs = [int(i) for i in input().split()] paired = [0 for i in range(n//2)] out = 0 maximum = 0 for i in range(n): if paired[pairs[i]-1] == 0: paired[pairs[i]-1] = 1 out += 1 elif paired[pairs[i]-1] == 1: paired[pairs[i]-1] == 2 out -= ...
Nick had received an awesome array of integers a=[a_1, a_2, ..., a_n] as a gift for his 5 birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product a_1 β‹… a_2 β‹… ... a_n of its elements seemed to him not large enough. He was ready t...
3
x=int(input()) s=list(map(int,input().split())) for n in range(x): if s[n]>=0: s[n]=-1-s[n] if x%2==1: o=min(s) for n in range(x): if s[n]==o: s[n]=-s[n]-1 break print(*s)
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. I...
3
n = int(input()) e =0 f=0 for i in range(n): a,b = map(int, input().split()) if a > b: e+=1 elif b>a : f+=1 if e > f : print('Mishka') elif e < f: print('Chris') else: print('Friendship is magic!^^')
Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". ...
3
x = [[0 for i in range(4)] for j in range(4)] y = [[0 for i in range(4)] for j in range(4)] vis = [[0 for i in range(4)] for j in range(4)] dic = {} k, a, b = list(map(lambda _: int(_), input().split())) for i in range(3): x[i+1][1], x[i+1][2], x[i+1][3] = list(map(lambda _: int(_), input().split())) for i in rang...
You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deletin...
3
def makeodd(listt): c=0 for r in range(len(listt)): if listt[r]%2==0: listt[r]="blah" c+=1 for e in range(c): listt.remove("blah") n=int(input()) inp=input() nums=inp.split(" ") for w in range(len(nums)): nums[w]=int(nums[w]) sum=0 tsum=0 neg=[] pos=[] an=False no...
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x- and y-coordinates before and after each movement must ...
3
sx,sy,tx,ty=map(int,input().split()) X=tx-sx Y=ty-sy print("U"*Y + "R"*X + "D"*Y + "L"*X + "L" + "U"*(Y+1) + "R"*(X+1) + "DR" +"D"*(Y+1) + "L"*(X+1) + "U")
You are given a permutation a consisting of n numbers 1, 2, ..., n (a permutation is an array in which each element from 1 to n occurs exactly once). You can perform the following operation: choose some subarray (contiguous subsegment) of a and rearrange the elements in it in any way you want. But this operation canno...
3
from sys import stdin, stdout intn = lambda : int(stdin.readline()) strs = lambda : stdin.readline()[:-1] lstr = lambda : list(stdin.readline()[:-1]) mint = lambda : map(int, stdin.readline().split()) lint = lambda : list(map(int, stdin.readline().split())) out = lambda x: stdout.write(str(x)+"\n") out_ = lambda x: st...
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them a...
3
import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) n, m = mints() e = [[] for i in range(n+1)] def isstar(): c = None for i in range(1, n+1): if len(e[i]) > 1: if c != None: return False c = i i...
Vasya owns a cornfield which can be defined with two integers n and d. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0, d), (d, 0), (n, n - d) and (n - d, n). <image> An example of a cornfield with n = 7 and d = 2. Vasya also knows that there are m grasshoppers near the fie...
3
n, d = [int(i) for i in input().split()] m = int(input()) for i in range(m): x, y = [int(i) for i in input().split()] if y >= x - d and y <= x + d and y >= -x + d and y <= -x + 2 *(n - d) + d: print('YES') else: print('NO')
There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number. Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1). When Mountain i (1 \leq i \l...
3
N=int(input()) A=list(map(int,input().split())) x=sum([A[i]*(-1)**i for i in range(N)]) res=[x] for i in range(N-1): x=A[i]*2-x res.append(x) print(*res)
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll...
3
vowels = "aeiou" answer = True def good(line, n): count = 0 for i in range(len(line)): if line[i] in vowels: count += 1 if count == n: return True else: return False for i in range(3): line = input() if i % 2 == 0: if good(line, 5) == True: ...
Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on t...
3
x=int(input()) s=[int(n) for n in input().split()] y=int(input()) z=[int(n) for n in input().split()] p=[] for n in z: for k in s: if n%k==0: p.append(n//k) print(p.count(max(p)))
Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once. You are given the sequence A and q questions where each question contains Mi. Notes You can solve this problem by a Burte Force appro...
3
N=int(input()) L=list(map(int,input().split())) B=1 for i in range(N): B=B|B<<L[i] BI=list(str(bin(B))) BI=BI[2:] SB=BI[::-1] #print(SB) Q=int(input()) A=list(map(int,input().split())) for i in range(Q): if A[i]>=len(SB): print("no") elif SB[A[i]]=="1": print("yes") else: print("...
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break th...
3
n = int(input()) arr = [int(i) for i in input().split()] dict = {} counter = 0 for i in range(n): if arr[i] in dict: counter +=1 del dict[arr[i]] else: dict[arr[i]] = 1 print(counter//2)
Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US. Calculate Pooja's account bal...
1
inp=raw_input().split() x=int(inp[0]) y=float(inp[1]) error_flag=0 if x%5!=0: error_flag=1 elif x+0.50>y: error_flag=1 else: print("%.2f" % round(y-x-0.50,2)) if error_flag==1: print("%.2f" % round(y,2))
n! = n Γ— (n βˆ’ 1) Γ— (n βˆ’ 2) Γ— ... Γ— 3 Γ— 2 Γ— 1 Is called the factorial of n. For example, the factorial of 12 12! = 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 479001600 And there are two consecutive 0s at the end. Write a program that inputs the integer n and outputs the number of consecutive 0s at the end of...
3
while True: n = int(input()) if n == 0: break a = 1 for i in range(1,n+1): a *= i count = 0 while(a % 10 == 0): count += 1 a //= 10 print(count)
"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
fline = input() numlst = fline.split() total = int(numlst[0]) tmp = int(numlst[1]) - 1 secline = input() lst = secline.split() newlst = list() for k in range(total) : num = int(lst[k]) newlst.append(num) count = 0 for i in range(total) : if (newlst[i] == 0) : continue if (newlst[i] >= newlst[tmp]) : ...
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
def solve(): a,b = map(int,input().split()) count = 0 a,b = max(a,b),min(a,b) if a%10 > b%10: count += 1 count += a//10 - b//10 print(count) t = int(input()) for x in range(t): solve()
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) β‹… maxDigit(a_{n}).$$$ Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes. Your task is calculate a_{K} for given a_{1} and K. Input The ...
3
t = int(input()) for i in range(t): a, k = map(int,input().split()) for j in range(k-1): s = str(a) int(a) din = 10 dax = -1 for z in range(len(s)): if(din>int(s[z])): din = int(s[z]) if(dax<int(s[z])): dax = int(s[z...
Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem. There are n positive integers a_1, a_2, …, a_n on Bob's homework paper, where n is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least 2 numbers. Suppose the n...
3
n = int(input()) a = sorted(map(int, input().split())) print(sum((a[i]+a[n-i-1])**2 for i in range(n//2)))
Suppose you are performing the following algorithm. There is an array v_1, v_2, ..., v_n filled with zeroes at start. The following operation is applied to the array several times β€” at i-th step (0-indexed) you can: * either choose position pos (1 ≀ pos ≀ n) and increase v_{pos} by k^i; * or not choose any posit...
3
t=int(input()) for i in range(t): n,k=map(int,input().split()) a=list(map(int,input().split())) b=[0 for i in range(58)] m=True for i in a: #ans=[] c=0 while i!=0: h=i//k ost=i-(h*k) if ost==0 or (b[c]==0 and ost==...
Array of integers is unimodal, if: * it is strictly increasing in the beginning; * after that it is constant; * after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following th...
3
def top(l2,i): if len(l2)==2: print("yes") exit(0) for j in range(i,len(l2)-1): if l2[j]>l2[j+1]: decrement(l2,j+1) if l2[j]<l2[j+1]: print("no") exit(0) print("yes") exit(0) def decrement(l3,i): if i==len(l3)-1: print("yes"...
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()) s=" " for i in range(1,n+1): if i==1 and n==1: s+="I hate it" elif i==1 and n!=1: s+="I hate"+" " elif i%2==1 and i!=1 and i!=n: s+="that I hate"+" " elif i%2==0 and i!=n: s+="that I love"+" " elif i%2==0 and i==n: s+=" that I love it"+" " e...
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." β€” an excerpt from contest rules. A total of n participants took part in the contest (n β‰₯ k), and you already know their scores. Calculate how many ...
3
n, k = input().split(' ') n = int(n) k = int(k) students = input().split(' ') students1 = [int(i) for i in students] students1.sort() score = students[ k - 1 ] score = int(score) count = 0 for i in students1: count += 1 if i == score and i != 0: number = n - count + 1 print (number) break elif i == scor...
Takahashi made N problems for competitive programming. The problems are numbered 1 to N, and the difficulty of Problem i is represented as an integer d_i (the higher, the harder). He is dividing the problems into two categories by choosing an integer K, as follows: * A problem with difficulty K or higher will be for ...
3
N=int(input()) d=list(map(int,input().split())) d.sort() print(max(0,d[N//2]-d[N//2-1]))
The round carousel consists of n figures of animals. Figures are numbered from 1 to n in order of the carousel moving. Thus, after the n-th figure the figure with the number 1 follows. Each figure has its own type β€” the type of the animal corresponding to this figure (the horse, the tiger and so on). The type of animal...
3
for _ in range(int(input())): n = int(input()) typea = list(map(int,input().split())) if len(set(typea))==1: print(1) print(*([1]*n)) continue val = 1 for i in range(n): val = typea[i%n] ^ typea[(i+1)%n] pos1=i pos2 = (i+1)%n if val==...
When a boy was cleaning up after his grand father passing, he found an old paper: <image> In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer". His grand mother says that Sanbonmatsu was standing ...
3
from math import pi,sin,cos _x=_y=a=0 while 1: x,y=map(int,input().split(',')) if x==y==0:break r=a*pi/180 _x+=x*sin(r) _y+=x*cos(r) a+=y print(*map(int,[_x,_y]),sep='\n')
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water...
3
k=int(input()) a=[int(i) for i in input().split(" ")] n=0 s=0 r=0 a=sorted(a) a=a[::-1] a=a+[0] for i in range(len(a)): if r>=k: print(n) break s=s+a[i] r=r+a[i] n=n+1 else: print(-1)
There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j). In Cell (i, j), a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and con...
3
h, w = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(h)] ans = [] for i in range(h): for j in range(w): if A[i][j]%2 == 1: if j != w-1: A[i][j+1] += 1 ans.append((i+1, j+1, i+1, j+2)) else: if i != h-1: ...
You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of mult...
3
t = int(input()) while t: M = int(input()) print(-1 if M == 1 else (10**(M-1) << 1) + ((10**(M-1)-1))//9*3) t-=1
The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess ...
3
vp = int(input()) vd = int(input()) t = int(input()) f = int(input()) c = int(input()) s = t * vp ans = 0 ch = c - vp * t while True: if vp >= vd: break dt = s / (vd - vp) ch -= dt * vp s = 0 if ch <= 0: break else: ans += 1 ch -= vp * ((c - ch) / vd + f) ...
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()) a = [];flag=0 for i in range(n): a.append(list(map(int, input().split()))) a.sort() for i in range(n): if s>a[i][0]: s+=a[i][1] else: flag=1 break if flag: print("NO") else: print("YES")
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
3
n = int(input()) i = 0 while i < n: word = input() l = len(word) if l > 10: print("%s%d%s" % (word[0], l - 2, word[-1])) else: print(word) i += 1
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates. You can perform each of the two following types of moves any (possibly, zero) number of times on any chip: * Move the chip i by 2 to the left or 2 to the right for free (i.e. replace...
3
n=int(input()) a=[int(x) for x in input().split()] cnt=0 for item in a: if item%2==0: cnt+=1 print(min(cnt,n-cnt))
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: * deletes all the vowels, * inserts a character "." before each consonant, * repl...
1
def task(letter): if letter.upper() in ("A", "O", "Y", "E", "U", "I"): return '' else: return "." + letter.lower() if __name__ == "__main__": print ''.join([task(s) for s in raw_input()])
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...
1
# Enter your code here. Read input from STDIN. Print output to STDOUT# =============================================================================================== # importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import Byt...
You are given k sequences of integers. The length of the i-th sequence equals to n_i. You have to choose exactly two sequences i and j (i β‰  j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the...
3
k = int(input()) d = {} ans = [] f = 0 for i in range(k): n = int(input()) a = list(map(int, input().split())) s = sum(a) for j in range(n): if s - a[j] in d: x, y = d[s - a[j]] if not x == i + 1: ans = [[x, y], [i + 1, j + 1]] f = 1 ...
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
def su(n, s): a = [] b = s[0][1]+s[1][1]-s[1][0] if n > 2: for i in range(2,n): a.append(b) b += s[i][1] - s[i][0] return max(max(a),s[0][1]) return s[0][1] n = int(input()) s = [] for j in range(n): a = [*map(int,input().split())] s.append(a) print(su...
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
3
line_s = input().strip() line_t = input().strip() if line_s == line_t[-1::-1]: print('YES') else: print('NO')
Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wants to test himself if he can implement it correctly, but he couldn't find any online judges that would do it (even though the...
3
t = int(input()) for _ in range(t): n, st = input().split() n = int(n) #ΠΈΡ‰Π΅ΠΌ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½ΡƒΡŽ num = n last = 0 answ = [0 for i in range(n)] for i in range(n): if i == n - 1 or st[i] == '>': for j in range(i, last-1, -1): answ[j] = num num -= ...
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 if __name__ == "__main__": nma = input() n, m, a = map(int, nma.split(' ')) print(math.ceil(n / a) * math.ceil(m / a))