problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
You are a coach of a group consisting of n students. The i-th student has programming skill a_i. All students have distinct programming skills. You want to divide them into teams in such a way that: * No two students i and j such that |a_i - a_j| = 1 belong to the same team (i.e. skills of each pair of students in t...
3
for i in range (int(input())): n = int(input()) arr = list(map(int, input().split())) arr.sort() arrf=[] for x in range (len(arr)-1): arrf.append(arr[x]-arr[x+1]) if((1 in arrf) or (-1 in arrf)): print(2) else: print(1)
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
3
n = int(input()) i = 0 sum = 0 while i<n: i = i + 1 petya, vasya, tonya = [int(petya) for petya in input().split()] add = petya + vasya + tonya if add >= 2: sum = sum + 1 print(sum)
There is an infinite 2-dimensional grid. The robot stands in cell (0, 0) and wants to reach cell (x, y). Here is a list of possible commands the robot can execute: * move north from cell (i, j) to (i, j + 1); * move east from cell (i, j) to (i + 1, j); * move south from cell (i, j) to (i, j - 1); * move wes...
3
x=int(input()) for x in range(x): c=0 a,b=map(int,input().split()) d=abs(a-b) if d>=2: c=abs(a)+abs(b)+d-1 else: c=abs(a)+abs(b) print(c)
The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts h hours and each hour lasts m minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colon) follows t...
3
a = [0, 1, 5, -1, -1, 2, -1, -1, 8, -1] test = int(input()) def check(x, y, h, m): if a[x // 10] == -1 or a[x % 10] == -1 or a[y // 10] == -1 or a[y % 10] == -1 : return 0 if a[x % 10] * 10 + a[x // 10] >= m or a[y % 10] * 10 + a[y // 10] >= h : return 0 return 1 def pnt(x, y): res='' ...
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse...
3
n, m = [int(x) for x in input().split(' ')] ns = [int(x) for x in input().split(' ')] fp = [int(x) for x in input().split(' ')] for i in range(len(ns)): if ns[i] in fp: print(ns[i], end=' ')
You play your favourite game yet another time. You chose the character you didn't play before. It has str points of strength and int points of intelligence. Also, at start, the character has exp free experience points you can invest either in strength or in intelligence (by investing one point you can either raise stre...
3
t = int(input()) for _ in range(t): s, i, e = map(int, input().split()) d = (i+e-s)//2+1 print(max(0,min(e-d+1,e+1)))
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can...
1
n, x = map(int, raw_input().split()) a = sorted(map(int, raw_input().split())) ans = 0 for i in a: ans += i * max(x, 1) x -= 1 print ans
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places. The robber girl was angry at first, but then she decided to arrange the animals herself. She ...
3
n = int(input()) arr = list(map(int, input().split())) temp = arr.copy() temp.sort() res = '' for i in range(n): k1 = arr.index(temp[n-i-1]) y = k1 + 1 while(y < n-i): res += str(y) + ' ' + str(y+1) + '\n' arr[y], arr[y-1] = arr[y-1], arr[y] y += 1 print(res)
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
w = input() w = w[0].capitalize() + w[1:] print(w)
Draw a rectangle which has a height of H cm and a width of W cm. Draw a 1-cm square by single '#'. Constraints * 1 ≀ H ≀ 300 * 1 ≀ W ≀ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero)...
1
#coding:utf-8 #????????Β’????????? def draw_square(h, w): for i in range(h): a = "" for j in range(w): a += "#" print a while 1: HW = raw_input().split() H = int(HW[0]) W = int(HW[1]) if H == 0 and W == 0: break draw_square(H, W) print ""
While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bit...
1
s = raw_input() nums = [] smap = {} ans = 1 for i in xrange(64): bstring = bin(i) bstring = bstring[2:] value = 3**(bstring.count('0')) * 3**(6-len(bstring)) nums.append(value) values = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_' for digit in values: smap[digit] = values.index(digit) f...
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2. Diame...
3
x, y = map(int, input().split()) a=list(map(int,input().split())) a.sort() cnt=0 mx=0 val=0 for i in range(x): for j in range(i,x): z=abs(a[i]-a[j]) if z<=y: #print("Biyog:") #print(abs(a[i]-a[j])) cnt=cnt+1 # print("cnt:") #print(cnt) ...
A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn. Nickolas adores permutations. He likes some permutations more than the o...
1
#Perfect Permutation #Language: Python #By Nicholas Joaquin number = input() if number % 2 == 1: print -1 exit() else: for x in xrange(1, number, 2): print x + 1, x,
Agent OO7 is engaged in a mission to stop the nuclear missile launch. He needs a surveillance team to monitor the progress of the mission. Several men with different type of capabilities assemble in a hall, help OO7 to find out total men with different capabilities. Capability is represented in form of numbers. Input -...
1
t=input() while t!=0: t-=1 input() print len(set(map(int,raw_input().split())))
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied: * For each i = 1,2,..., n-2, a_i = a_{i+2}. * Exactly two different numbers appear in the sequence. You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing s...
1
def solve(n, a): D = [{0: 0}, {0:0}] for i in range(n): if not a[i] in D[i%2]: D[i%2][a[i]] = 0 D[i%2][a[i]] += 1 e = sorted(D[0].items(), key=lambda _:-_[1]) o = sorted(D[1].items(), key=lambda _:-_[1]) k_e0, v_e0 = e[0] k_o0, v_o0 = o[0] if k_e0 != k_o0: ...
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
a,b = map(int, input().split()) i = 1 while i: a *= 3 b *= 2 if a > b: break i+=1 print(i)
You are given an array a of length n, which initially is a permutation of numbers from 1 to n. In one operation, you can choose an index i (1 ≀ i < n) such that a_i < a_{i + 1}, and remove either a_i or a_{i + 1} from the array (after the removal, the remaining parts are concatenated). For example, if you have the ar...
3
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) print(['Yes', 'No'][a[0] > a[-1]])
Pravin and Saddam are room-mates.They always solve aptitude questions together. Once, they came across a problem stated as: "Find the digit at the unit place that appears in sum of factorials of all numbers between A and B (both inclusive)." Though they are good at mathematics ,but this time they are scratching their...
1
memo={0:1,1:1,2:2,3:6,4:24,5:0,6:0,7:0,8:0,9:0} for _ in range(input()): a,b=map(int,raw_input().split()) sum=0 for i in range(a,b+1): if i>5:sum+=0 else:sum+=memo[i] print sum%10
Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divi...
3
import sys n = int(input()) if n % 2 == 0: print(n // 2) for i in range(n // 2): print('2', end=' ') else: print((n-1) // 2) for i in range((n-1)//2-1): print('2', end=' ') print('3', end=' ') print()
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second β€” number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 β€” AB, column 52 is marked by AZ. After ZZ there follow th...
3
import math for i in range(int(input())): s=input() if 'R' in s and 'C' in s and s.index('C')-s.index('R')>1 and s[s.index("R")+1:s.index("C")].isdigit(): r=s[s.index("R")+1:s.index("C")] c=int(s[s.index("C")+1:]) newstr="" while(c>0): if c%26==0: news...
N people are standing in a queue, numbered 1, 2, 3, ..., N from front to back. Each person wears a hat, which is red, blue, or green. The person numbered i says: * "In front of me, exactly A_i people are wearing hats with the same color as mine." Assuming that all these statements are correct, find the number of p...
3
mod = 10**9+7 n = int(input()) a = list(map(int, input().split())) remain = 3 s = [0,0,0] ans = 1 for i in a: k = s.count(i) ans *= s.count(i) ans %= mod if k == 0: break s[s.index(i)] += 1 print(ans)
Given are three integers A_1, A_2, and A_3. If A_1+A_2+A_3 is greater than or equal to 22, print `bust`; otherwise, print `win`. Constraints * 1 \leq A_i \leq 13 \ \ (i=1,2,3) * All values in input are integers. Input Input is given from Standard Input in the following format: A_1 A_2 A_3 Output If A_1+A_2+A_...
3
x = sum(map(int, input().split())) print('bust' if x > 21 else 'win')
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
3
a = str(input()) b = str(input()) c = str(input()) d = a+b if sorted(d) == sorted(c): print("YES") else: print("NO")
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
from sys import stdin def main(): m, n, a = map(int, stdin.readline().rstrip().split()) v = n // a + (1 if n % a > 0 else 0) h = m // a + (1 if m % a > 0 else 0) print(v * h) if __name__ == '__main__': main()
In the city of Saint Petersburg, a day lasts for 2^{100} minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4^k for each integer k β‰₯ 0. Team BowWow has arrived at the station at the time s and it is trying to co...
3
a = int(input()) b = 1 count = 0 while b < a: count = count + 1 b = b*100 print(count)
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
def pro(arr): cnt = 0 for i in range(len(arr)): if arr[i] == 0: arr[i] = 1 cnt += 1 return cnt def summ(arr): summ = 0 for i in arr: summ += i if summ == 0: return 1 return 0 def non_zero(arr, idx, step): if len(arr) == 0: return 0 step += pro(arr) step += summ(arr) return step t = int(input...
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t...
1
n,k=map(int,raw_input().split()) N=map(int,raw_input().split()) b=map(int,raw_input().split()) if k>1: print "Yes" else: for i in range(n): if N[i]==0: N[i]=b[0] if sorted(N)==N: print "No" else: print "Yes"
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: * if l=909, then adding one will result in 910 and 2 digits...
3
def calc(x): f = 1 ans = [] while f <= x: ans.append(x // f) f *= 10 return sum(ans) for case in range(int(input())): l, r = [int(x) for x in input().split()] print(calc(r) -calc(l))
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: * Tetrahedron. Tetrahedron has 4 triangular faces. * Cube. Cube has 6 square faces. * Octahedron. Octahedron has 8 triangular faces. * Dodecahedron. Dodecahedron has 12 pentagonal faces. *...
3
n = int(input()) count=0 for i in range(n): s = input() if(s[0]=='I'): count+=20 elif(s[0]=='T'): count+=4 elif(s[0]=='C'): count+=6 elif(s[0]=='O'): count+=8 else: count+=12 print(count)
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
import sys for l in sys.stdin: try: l = int(l) if l > 3: if l % 2 == 0: print('YES') else: print('NO') else: print('NO') except ValueError: continue
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n Γ— n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling in ran...
3
n = int(input()) N = [list(map(int, input().split())) for i in range(n)] INF = 10 ** 20 S1 = [0] * n S2 = [0] * n s3 = 0 s4 = 0 MagicI = INF MagicJ = INF MagicS = INF MagicN = 0 Magic = False if n == 1: print(1) else: for i in range(n): for j in range(n): S2[j] += N[i][j] if N...
You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels:...
3
n = int(input()) p = list(map(int, input().split(" "))) vowels = ['a', 'e', 'i', 'o', 'u', 'y'] def containsAny(str, arr): return 1 in [c in str for c in arr] good = True for i in range(n): line = str(input()) v = 0 words = line.split(" ") final = [] for word in words: if containsAny(word, vowels):...
Takahashi and Aoki will play a game on a tree. The tree has N vertices numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex b_i. At the beginning of the game, each vertex contains a coin. Starting from Takahashi, he and Aoki will alternately perform the following operation: * Choose a vertex ...
3
N = int(input()) Edge = [[] for _ in range(N+1)] for _ in range(N-1): a, b = map(int, input().split()) Edge[a].append(b) Edge[b].append(a) stack = [1] dist = [0]*(N+1) visited = set([1]) while stack: vs = stack.pop() for e in Edge[vs]: if e in visited: continue visited.ad...
Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: <image> <image> Ayrat is searching through the field. He started at point (...
3
def layer(n): a = (-3 + (9+12*n)**0.5)//6 a = int(a) a+=1 while 3*a*(a+1) >= n: a-=1 return a+1 n = int(input()) if n == 0: print(0, 0) quit() l = layer(n) base = 3*(l-1)*l+1 # base = (2*l-1, 2) a = [2*l, 0] b = [l, 2*l] bx = base + (l-1) c = [-l, 2*l] cx = bx + l d = [-2*l, 0] dx...
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 ≀ i ≀ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical. Monocarp wants to draw the segments in such a way that they enclose a rectangular...
3
for test in range(int(input())): li = list(map(int, input().split())) li.sort() print(li[0]*li[2])
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...
1
l,r,k=raw_input().split(); l=int(l) r=int(r) k=int(k) A=[] ret=1 for i in range(101): if (ret>=l and ret<=r): A.append(ret) ret=ret*k if ret>r: break if len(A)==0: print -1 else: for i in range(len(A)): print A[i], print
Takahashi has N cards. The i-th of these cards has an integer A_i written on it. Takahashi will choose an integer K, and then repeat the following operation some number of times: * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.) For...
3
import sys import collections as cl N=int(input()) A=list(map(int,sys.stdin.readline().split())) c=cl.Counter(A) NumberTupleList=c.most_common() NumberList=[x[1] for x in NumberTupleList[::-1]] LengthOfNumberList=len(NumberList) FormulaList=[0 for i in range(N)] flag=0 S=sum(NumberList) for x in range(1,N+1): wh...
For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that βˆ‘_{i=1}^{n}{βˆ‘_{j=i}^{n}{(a_j)/(j)}} equals m? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for exampl...
3
for _ in range(int(input())): a,b=map(int,input().split()) l = list(map(int,input().split())) print('YES' if sum(l)==b else 'NO')
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order. Constraints 0 ≀ height of mountain (integer) ≀ 10,000 Input Height of mountain 1 Height of mountain 2 Height of mountain 3 . . He...
3
mounts =[int(input()) for i in range(10)] mounts.sort(reverse = True) for i in range(3): print(mounts[i])
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living...
3
t=int(input()) c=0 for i in range(t): x=input().split() x=[int(x[l]) for l in range(2)] if (abs(x[0]-x[1])>=2): c+=1 else: continue print(c)
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy. Input The only line contains three integers n, a and ...
3
a,b,c = map(int,input().split()); print(min(a-b,c+1))
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...
1
n, h = map(int, raw_input().split()) a = map(int, raw_input().split()) count = 0 for i in xrange(n): if a[i] > h: count += 2 else: count += 1 print count
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
n=input() s='' for i in n: if(i=="A" or i=='a' or i=="O" or i=='o'or i=="Y" or i=='y' or i=="E" or i=='e'or i== "U" or i=='u' or i=="I" or i=='i'): continue else: s+='.' s+=i.lower() print(s)
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
n = int(input()) s = '' for i in range(n): x = input() if s.count('++')>0 or x.count('OO') == 0: s += x + '\n' else: x = x.replace('OO', '++', 1) s += x + '\n' if s.count('++')>0: print("YES") print(s) else: print('NO')
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Initially S...
3
stones = list(map(str,input())) colors = list(map(str,input())) #print(stones) #print(colors) move = 1 counter = 0 for i in range(len(colors)): if colors[i] == stones[counter]: move += 1 counter += 1 print(move)
Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y violet and z orange spheres. Can he get them (possible, in multiple...
3
from sys import stdin, exit inputs = map(int, next(stdin).split()) outputs = map(int, next(stdin).split()) extras = [x - y for x, y in zip(inputs, outputs)] for i in range(3): if extras[i] < 0: for x in range(3): while extras[i] < 0 and extras[x] > 1: extras[i] += 1 ...
Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill: * the graph contains exactly 2n + p edges; * the graph doesn't contain self-loops and multiple edges; * for any integer k (1 ≀ k ≀ n), any subgraph consisting of k vertices contains at most 2k + p edges. A sub...
3
#!/usr/bin/python3 import sys input = lambda: sys.stdin.readline().strip() def solve(n, p): total = 0 for d in range(1, n): for i in range(1, n + 1): print(i, (i + d - 1) % n + 1) total += 1 if total == 2 * n + p: return for _ in range(int(input())):...
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three int...
1
x, y, v = [], [], [] for i in range(8): x1, y1 = map(int, raw_input().split()) v.append((x1, y1)) x.append(x1) y.append(y1) v.sort() if not (v[0][0] == v[1][0] and v[2][0] == v[1][0]): print 'ugly' elif not (v[5][0] == v[6][0] and v[6][0] == v[7][0]): print 'ugly' elif not (v[3][0] == v[4][0])...
Fukushima Prefecture is also famous for producing fruits, and among them, peaches and apples boast one of the highest production volumes in Japan. By the way, when I made a print manuscript of an English pamphlet for sale, I mistakenly wrote the description about apples and the description about peaches in reverse. Yo...
3
Eng=input() print(Eng.replace('peach', 'X').replace('apple', 'peach').replace('X', 'apple'))
<image> It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in th...
3
n, k = map(int, input().split()) s = input() C = [0]*(n+1) for ch in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': if ch in s: C[s.find(ch)] += 1 C[s.rfind(ch)+1] -= 1 x = 0 for c in C: x += c if x > k: print('YES') break else: print('NO')
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
3
import sys input = lambda: sys.stdin.readline().strip("\r\n") s = list(input()) n = len(s) upper = 0 lower = 0 for i in s: if i.isupper(): upper += 1 else: lower += 1 if upper > lower: print("".join(s).upper()) else: print("".join(s).lower())
On a planet far, far away, M languages are spoken. They are conveniently numbered 1 through M. For CODE FESTIVAL 20XX held on this planet, N participants gathered from all over the planet. The i-th (1≦i≦N) participant can speak K_i languages numbered L_{i,1}, L_{i,2}, ..., L_{i,{}K_i}. Two participants A and B can c...
3
class UnionFind: def __init__(self, n): self.v = [-1 for _ in range(n)] def find(self, x): if self.v[x] < 0: return x else: self.v[x] = self.find(self.v[x]) return self.v[x] def unite(self, x, y): x = self.find(x) y = self.find(y)...
Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem: You are given an array a of n integers. You are also given an integer k. Lord Omkar wants you to do k ope...
3
for _ in range(int(input())): am, k = list(map(int,input().split())) arr = list(map(int,input().split())) mi = min(arr) ma = max(arr) if k&1: if mi == ma: print("0 "*am ) else: for i in range(am): arr[i] = ma-arr[i] print(*arr) ...
X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10. Constraints * 0 \leq X, A \leq 9 * All values in input are integers. Input Input is given from Standard Input in the following format: X A Output If X is less than A, print 0; if X is not less th...
3
x, a = map(int, input().split()) o = 0 if x<a else 10 print(o)
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For exampl...
3
n = int(input()) a = list(map(int, input().split())) d = [0] * 101 for i in a: d[i] += 1 p = 0 while True: allZeros = True k = 0 for i in range(101): if d[i] != 0: while i >= k and d[i] > 0: d[i] -= 1 k += 1 allZeros = False if allZeros...
Find out if it is possible to partition the first n positive integers into two non-empty disjoint sets S_1 and S_2 such that: gcd(sum(S_1), sum(S_2)) > 1 Here sum(S) denotes the sum of all elements present in set S and gcd means the[greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). Ev...
3
n = int(input()) if n <= 2: print('No') else: print('Yes') print(len(range(1, n + 1, 2)), end=' ') for i in range(1, n + 1, 2): print(i, end=' ') print('') print(len(range(2, n + 1, 2)), end=' ') for i in range(2, n + 1, 2): print(i, end=' ')
You have n gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The i-th gift consists of a_i candies and b_i oranges. During one move, you can choose some gift 1 ≀ i ≀ n and do one of the following operations: * eat exactly...
3
from sys import stdin input=lambda : stdin.readline().strip() from math import ceil,sqrt,factorial,gcd from collections import deque for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) count=0 x=min(a) y=min(b) for i in range(n): q=a[i]-x w=b[i]-y ...
While playing with geometric figures Alex has accidentally invented a concept of a n-th order rhombus in a cell grid. A 1-st order rhombus is just a square 1 Γ— 1 (i.e just a cell). A n-th order rhombus for all n β‰₯ 2 one obtains from a n-1-th order rhombus adding all cells which have a common side with it to it (look ...
3
print(sum(4 * i for i in range(1, int(input()))) + 1)
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ...
3
a=int(input()) ct=0 total=0 l=sorted(map(int,input().split())) for i in range(a-1): if l[i] == l[i+1]: ct+=1 if ct > total: total=ct else: ct=0 print(total+1,len(set(l)))
[3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo) Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"! The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The sho...
3
import sys n = int(sys.stdin.readline()) t = 0 for i in range(n): t += 1 / (i + 1) print(t)
There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor. The game is played on a square field consisting of n Γ— n cells. Initially all cells are empty. On each turn a pla...
3
cosa = input() wea = int(cosa[len(cosa)-1]) print(2-wea%2) # 1500429888830
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
# -*- coding: utf-8 -*- """ Created on Fri Aug 14 15:17:03 2020 @author: Lucky """ n = list(map(int, input().strip().split()))[:2] lst = list(map(int, input().strip().split()))[:n[0]] s = 0 for i in lst: if i > n[1]: s += 2 else: s += 1 print(s)
There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard ...
3
N = int(input()) A = list(map(int,input().split())) print('NO') if(sum(A) % 2) else print('YES')
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown be...
3
from collections import deque, Counter, OrderedDict from heapq import nsmallest, nlargest from math import ceil,floor,log,log2,sqrt,gcd,factorial,pow def binNumber(n,size=4): return bin(n)[2:].zfill(size) def iar(): return list(map(int,input().split())) def ini(): return int(input()) def isp(): retur...
n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could ha...
3
n, m = map(int, input().split()) x, mod = divmod(n, m) print(m * x * (x - 1) // 2 + x * mod, (n - m) * (n - m + 1) // 2)
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i...
1
n=int(raw_input()) mod=1000000007 c=[int(raw_input()) for i in xrange(n)] sum=[1 for i in xrange(1003)] dp=[[0 for i in xrange(1003)] for j in xrange(1003) ] for i in xrange(1,1003): for j in xrange(0,1003): dp[i][j]=sum[j] for j in xrange(1,1003): sum[j]=(sum[j-1]+dp[i][j])%mod l=c[0] ans=1 for i in xrange(1,n):...
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the re...
3
from collections import defaultdict import sys q = int(sys.stdin.readline()) old = defaultdict(str) new = defaultdict(str) for i in range(q): a, b = sys.stdin.readline().split() if a in new.values(): old[b] = old[a] new[old[a]] = b else: old[b] = a new[a] = b sys.stdout.writ...
There is a cave consisting of N rooms and M one-directional passages. The rooms are numbered 1 through N. Takahashi is now in Room 1, and Room N has the exit. The i-th passage connects Room s_i and Room t_i (s_i < t_i) and can only be traversed in the direction from Room s_i to Room t_i. It is known that, for each roo...
3
n,m = map(int,input().split()) ab = [list(map(int,input().split())) for i in range(m)] go = [[] for i in range(n+1)] come = [[] for i in range(n+1)] for a,b in ab: go[a].append(b) come[b].append(a) dpe = [0]*(n+1) for i in range(1,n+1)[::-1]: if i < n and go[i]: dpe[i] /= len(go[i]) for j in come[i]: dp...
A biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation. Find the total number of biscuits produced within T + 0.5 seconds after activation. Constraints * All values in input are integers. * 1 \leq A, B, T \le...
3
a,b,t=map(int, input().split()) time=t//a print(time*b)
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if...
3
string = input() start,con = 0,0 for i in ['h','e','l','l','o']: for j in range(start,len(string)): if string[j] == i: start = j+1 con += 1 break print('YES') if con == 5 else print('NO')
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...
1
m = 4 - len(set(map(int,raw_input().split()))) print m
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
blue, red = map(int, input().split()) a1 = min(blue, red) a2 = (blue - a1) // 2 + (red - a1) // 2 print('{} {}'.format(a1, a2))
An uppercase or lowercase English letter \alpha will be given as input. If \alpha is uppercase, print `A`; if it is lowercase, print `a`. Constraints * \alpha is an uppercase (`A` - `Z`) or lowercase (`a` - `z`) English letter. Input Input is given from Standard Input in the following format: Ξ± Output If \alph...
1
mod = int(1e9+7) def add(a, b): c = a + b if c >= mod: c -= mod return c def main(): #A, B = [int(x) for x in raw_input().split()] ch = raw_input() if ch.isupper(): print('A') else: print('a') main()
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...
1
start = 'a' sum = 0 for c in raw_input(): d = abs(ord(c) - ord(start)) start = c sum+=min(d, 26-d) print(sum)
Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A1440...
3
import sys n = sys.stdin.readline().rstrip() print(int(n, 16) % 2)
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number a, the second player wrote number b. How many ways ...
3
c, d = map(int,input().split()) if(c==d): print(0, 6, 0) else: a = min(c, d) b = max(c, d) first = a+(b-a-1)//2 second = 6-b+1 + (b-a-1)//2 draw = abs(6-(second+first)) if(c<d): print(first, draw, second) else: print(second, draw, first)
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
3
n=int(input()) num=1 curr=input() for i in range(n-1): prev=curr curr=input() if curr!=prev: num+=1 print(num)
You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbe...
3
n=int(input()) s=set() for i in range(n): a=input().strip() if a in s: s.remove(a) else: s.add(a) print(len(s))
You are a coach of a group consisting of n students. The i-th student has programming skill a_i. All students have distinct programming skills. You want to divide them into teams in such a way that: * No two students i and j such that |a_i - a_j| = 1 belong to the same team (i.e. skills of each pair of students in t...
3
for i in range(int(input())): f= True input() a=input().split() for j in range(len(a)): a[j]=int(a[j]) a=sorted(a) for j in range(len(a)-1): if abs(a[j]-a[j+1])==1: f = False break if f == False: print(2) else: print(1)
You are given a positive integer x. Find any such 2 positive integers a and b such that GCD(a,b)+LCM(a,b)=x. As a reminder, GCD(a,b) is the greatest integer that divides both a and b. Similarly, LCM(a,b) is the smallest integer such that both a and b divide it. It's guaranteed that the solution always exists. If ther...
3
t = int(input()) while t > 0: inp = int(input()) num1 = inp - 1 num2 = 1 print(num1, num2) t -= 1
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + 9 + 8 = 21. Then the digital root of number n equals to: 1. dr(n) = S(n), if S(n) < 10; 2. dr(n) = dr( S(n) ), i...
3
k,d=map(int,input().split()) if(d==0): if(k==1): print(0) else: print("No solution") else: print(d,end="") print("0"*(k-1))
Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face. One of the project's know-how is a camera rotating around its optical axis on shooting. People see an eye-catching gadget β€” a rotating camera β€” come up to it to see it be...
3
n = int(input().strip()) n %= 360 cnt = 0 opt = min(n, abs(360 - n)) for i in range(4): n = (n - 90) % 360 x = min(n, abs(360 - n)) if opt > x: opt = x cnt = i + 1 print(cnt)
As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with a...
3
while True: n, m = [int(i) for i in input().split()] if n == 0 and m == 0: break p = [int(i) for i in input().split()] p.sort() p.reverse() ans = 0 for i in range(len(p)): if (i+1) % m > 0: ans = ans + p[i] print(ans)
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 =1 ls = input().split() for i in range (n): ls[i] = int(ls[i]) dic={} for i in ls: dic[i] = a a = a+1 for i in range(1,n+1): print(dic[i], "" , end="")
There are N points in a D-dimensional space. The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}). The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}. How many pairs (i, j) (i < j) are there such ...
3
a,b=map(int,input().split()) c=[] for i in range(a): c+=[list(map(int,input().split()))] count=0 for i in range(a): for j in range(i+1,a): k=sum([(c[i][t]-c[j][t])**2 for t in range(b)]) if int(k**0.5)**2==k:count+=1 print(count)
A permutation of length n is a sequence of integers from 1 to n of length n containing each number exactly once. For example, [1], [4, 3, 5, 1, 2], [3, 2, 1] are permutations, and [1, 1], [0, 1], [2, 2, 1, 4] are not. There was a permutation p[1 ... n]. It was merged with itself. In other words, let's take two instanc...
3
for _ in range(int(input())): n=int(input()) li=list(map(int,input().split())) s=[] for i in li: if i not in s: s.append(i) print(*s)
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....
1
z=0 for _ in xrange(input()): a=raw_input() if a.count('+')>0: z+=1 else: z-=1 print z
Denis was very sad after Nastya rejected him. So he decided to walk through the gateways to have some fun. And luck smiled at him! When he entered the first courtyard, he met a strange man who was selling something. Denis bought a mysterious item and it was... Random permutation generator! Denis could not believed hi...
3
import sys input=sys.stdin.readline import collections as cc I=lambda:list(map(int,input().split())) for tc in range(int(input())): n,=I() l=I() f=cc.defaultdict(int) for i in range(n): f[l[i]]=i ans='Yes' for i in range(1,n): if f[i]>f[i+1] or f[i]+1==f[i+1]: ans='Ye...
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
3
n=input() count_4 = n.count('4') count_7 = n.count('7') if count_4 + count_7 == 4 or count_4 + count_7 == 7: print('YES') else: print('NO')
You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, ter...
3
n = int(input()) s = 0 minb = float("inf") f = False for _ in range(n): a, b = map(int, input().split()) if a > b: f = True minb = min(b, minb) s += a if f: print(s - minb) else: print(0)
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that 1. 1 ≀ i, j ≀ N 2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th. Input The single input line contains S, consisting of lowercase Latin letters and digits. It is ...
3
s=input() count=0 d={} for i in s: d[i]=d.get(i,0)+1 for v in d.values(): count+=v**2 print(count)
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they f...
1
n = input() m = map(int, raw_input().strip().split()) diss = [] diss.append(sum(m)) for i in range(2,n/2+1): if n%i == 0 and n/i >=3: for j in range(i): d = sum(m[j::i]) diss.append(d) print max(diss)
You are given a string S consisting of letters `b`, `d`, `p` and `q`. Determine whether S is a mirror string. Here, a mirror string is a string S such that the following sequence of operations on S results in the same string S: 1. Reverse the order of the characters in S. 2. Replace each occurrence of `b` by `d`, `d...
3
def main(): S = input() m = dict() m['d'] = 'b' m['b'] = 'd' m['p'] = 'q' m['q'] = 'p' T = "" for i in range(len(S)-1, -1, -1): T += m[S[i]] if T == S: return "Yes" return "No" if __name__ == '__main__': print(main())
There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer a_i. They will form N teams, each consisting of three participants. No participant may belong to multiple teams. The strength of a team is defined as the second largest strength among its members. For ...
3
N = int(input()) data = sorted(map(int, input().split()), reverse = True) print(sum(data[1:2*N:2]))
There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles. Find the length of the longest directed path in G. Here, the length of a directed path is the num...
1
N,M=[int(x) for x in raw_input().split()] A=[[] for i in range(N)] B=[[] for i in range(N)] C=[-1 for i in range(N)] D=[0 for i in range(N)] E=[0 for i in range(N)] for i in range(M): a,b=[int(x)-1 for x in raw_input().split()] A[a].append(b) #to B[b].append(a) #from F=[] s=0 for i in range(N): D[i]=le...
There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke ca...
3
def getN(): return int(input()) def getlist(): return [int(x) for x in input().split()] n, q = getlist() sin = " " + input() + " " oprs = [] lsafe = 1 rsafe = n lborder = sin[:2] rborder = sin[-2:] for i in range(q): oprs.append(input().split()) for opr in oprs[::-1]: #print(lsafe, lborder, rsafe, rb...
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
def base_10_to_n(x, n): if (int(x/n)): return base_10_to_n(int(x/n), n)+[x%n] return [x%n] t = int(input()) for _ in range(t): n, k = map(int, input().split()) A = map(int, input().split()) A = [base_10_to_n(a, k) for a in A] #print(A) d = {} for i in range(n): a = A[i] ...
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
s = input(); c =0 for i in range(len(s)): if s[i]=='4' or s[i]=='7': c+=1 if c==4 or c==7: print('YES') else:print('NO')
This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≀ 1000, n ≀ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems. After struggling and failing many ...
3
from collections import Counter k = int(input()) for _ in range(k): n = int(input()) A = list(input()) B = list(input()) C = Counter(A + B) ans = True for c in C: ans = ans and (not (C[c] % 2)) if not ans: print("No") continue swaps = [] for i in range(n): if A[i] == B[i]: continue for j...
You are given a sequence a_1, a_2, ..., a_n consisting of n integers. You can choose any non-negative integer D (i.e. D β‰₯ 0), and for each a_i you can: * add D (only once), i. e. perform a_i := a_i + D, or * subtract D (only once), i. e. perform a_i := a_i - D, or * leave the value of a_i unchanged. It is...
3
n = int(input()) a = [int(k) for k in input().split()] s = list(set(a)) s.sort() dl = len(s) if dl > 3: print(-1) elif dl == 1: print(0) elif dl == 2: if (s[1] - s[0]) % 2 == 0: print((s[1] - s[0]) // 2) else: print(s[1] - s[0]) else: if s[1] - s[0] == s[2] - s[1]: print(s[1]...