problem
stringlengths
29
9.39k
language
int64
1
3
solution
stringlengths
7
465k
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
score = 0 for i in range(int(input())): a, b = list(map(int, input().split())) if a > b: score += 1 elif b > a: score -= 1 print("Mishka" if score > 0 else "Chris" if score < 0 else "Friendship is magic!^^")
Pavel loves grid mazes. A grid maze is an n Γ— m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
3
""" pppppppppppppppppppp ppppp ppppppppppppppppppp ppppppp ppppppppppppppppppppp pppppppp pppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppp...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number x in an array. For an array a indexed from zero, and an integer x the pseudocode o...
3
n, x, pos = map(int, input().split()) permutations = [0] * n modulo = 10**9 + 7 def binary_search(copy_of_the_x): left_numbers = x - 1 right_numbers = n - x left = 0 right = n while left < right: middle = (left + right) // 2 if middle < pos: permutations[middle] = left...
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ...
1
r,x,y,a,b=map(int,raw_input().split()) import math if(x==a and y==b): print "0" else: c=abs(x-a) d=abs(y-b) di=math.sqrt(c*c+d*d) print int(math.ceil(di/(2*r)))
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them! A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≀ a ≀ b ≀ n). For e...
3
n, k = map(int, input().split()) s = input() x = set(list(input().split())) prev = None count = 0 for i in range(len(s)): if s[i] not in x: if prev == None: continue else: # print(i - 1, prev) dist = i - 1 - prev + 1 count += (dist) * (dist + 1) // 2 ...
Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases. A staircase is a squared figure that consists of square cells. Each staircase consists of an arbitrary number of stairs. If a staircase ha...
3
for _ in range(int(input())): x = int(input()) a = 1 n = 0 b = 0 while True: b = (a+1)*(a//2) + a//2 + 1 x -= b n += 1 if x < 0: n -= 1 break elif x == 0: break a = a * 2 + 1 print(n)
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slots when group will have classes are known. Your task is to determine the mi...
3
n=int(input()) l=[] for i in range(n): l.append(list(input())) d=list(zip(*l)) m=0 for i in range(7): m=max(m,d[i].count('1')) print(m)
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with ve...
3
import math n=int(input()) s1=int(math.sqrt(n)) s2=n//s1 ans=s1+s2 if s1*s2<n: diff=n-(s1*s2) m=max(s1,s2) ans+=math.ceil(diff/m) print(ans)
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
i=int(input()) if i==2 or i%2==1 : print("NO") else : print("YES")
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
line1 = list(input()) line2 = list(input()) output = [] for i in range(len(line1)): if line1[i] == line2[i]: output.append("0") else: output.append("1") print("".join(output))
Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For ex...
3
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): S = input() print(S[:-8]) if __name__ == "__main__": main()
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 ...
3
# -*- coding: utf-8 -*- def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j][1] <= x[1]: i += 1 A[i], A[j] = A[j], A[i] A[i+1], A[r] = A[r], A[i+1] return i+1 def quickSort(A, p, r): if p < r: q = partition(A, p, r) quick...
There is a right triangle ABC with ∠ABC=90°. Given the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC. It is guaranteed that the area of the triangle ABC is an integer. Constraints * 1 \leq |AB|,|BC|,|CA| \leq 100 * All values in input are integers. * The area of the triangl...
3
A, B, C = map(int, input().split(" ")) print(A*B//2)
Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second...
3
a,b,c,d=map(int,input().split()) e=max(a,c) f=min(b,d) if e<f: print(f-e) else: print(0)
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he...
1
n = input() a = map(int, raw_input().split()) ans = 0 while(True): mx = a[0] - 1 ind = 0 for i in xrange (1,n,1): if a[i] > mx: mx = a[i] ind = i if mx < a[0]: break a[0] += 1 a[ind] -= 1 ans += 1 print ans
Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types β€” shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick. Each tool can be sold for exactly one emerald. How many...
3
for i in range(int(input())): l,r = map(int,input().split()) print(min(l,r,(l+r)//3))
This is the easy version of the problem. The difference between the versions is that in the easy version all prices a_i are different. You can make hacks if and only if you solved both versions of the problem. Today is Sage's birthday, and she will go shopping to buy ice spheres. All n ice spheres are placed in a row ...
3
n = int(input()) l = list(map(int,input().split())) l.sort() print((n-1)//2) if n<3: print(*l) else: arr = [0]*n j = 0 for i in range(1,n,2): arr[i] = l[j] j+=1 for i in range(0,n,2): arr[i] = l[j] j+=1 print(*arr)
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
c = 0 cmax = 0 for i in range(int(input())): a, b = map(int, input().split()) c = c + b - a cmax = c if c > cmax else cmax print(cmax)
One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of ...
1
n = int(raw_input()) for i in xrange(n): s = raw_input() if s.endswith('lala.') and not s.startswith('miao.'): print 'Freda\'s' elif s.startswith('miao.') and not s.endswith('lala.'): print 'Rainbow\'s' else: print 'OMG>.< I don\'t know!'
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≀ t ≀ 100). The first line of...
3
t = int(input()) for _ in range(t): n = int(input()) b = list(map(int, input().split())) c = set(b) l = [] valid = True for i in b: temp = i + 1 while temp in c: temp += 1 if temp > 2*n: print(-1) valid = False break ...
Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms: * Everyone must gift as many coins as others. * All coins given to Ivan must be different. * Not l...
3
n,m,k,l = map(int, input().split()) x = -(-(k+l)//m) if x <= n/m: print(x) else: print(-1)
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
3
import string S = input() up = 0 lo = 0 for s in S: if s in string.ascii_lowercase: lo += 1 else: up += 1 if lo < up: print(S.upper()) else: print(S.lower())
You're given a row with n chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 2. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones (0 means...
3
_, sa = input(), input() print( "No" if ("11" in sa or "000" in sa or sa.startswith("00") or sa.endswith("00")) or sa == "0" else "Yes")
Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al...
3
x1, y1, x2, y2 = map(int, input().split()) dx, dy = abs(x1-x2), abs(y2-y1) if y1 == y2: print(f"{x1} {y1+dx} {x2} {y2+dx}") elif x1 == x2: print(f"{x1+dy} {y1} {x2+dy} {y2}") elif dx == dy: print(f"{x1} {y2} {x2} {y1}") else: print(-1)
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
3
n = int(input()) for i in range(n): s = input() l = len(s) if l > 10: s1 = s[0] + str(l-2) + s[l-1] print(s1) else: print(s)
Ayush and Ashish play a game on an unrooted tree consisting of n nodes numbered 1 to n. Players make the following move in turns: * Select any leaf node in the tree and remove it together with any edge which has this node as one of its endpoints. A leaf node is a node with degree less than or equal to 1. A tree...
3
for t in range(int(input())): n, x = map(int, input().split()) s=0 for i in range(n-1): if x in list(map(int, input().split())): s+=1 if n < 3 or s==1 or (n-3)%2!=0: print('Ayush') else: print('Ashish')
A permutation of length n is an array p=[p_1,p_2,...,p_n], which contains every integer from 1 to n (inclusive) and, moreover, each number appears exactly once. For example, p=[3,1,4,2,5] is a permutation of length 5. For a given number n (n β‰₯ 2), find a permutation p in which absolute difference (that is, the absolut...
3
t=int(input()) for i in range(t): n=int(input()) arr=[] if (n==2 or n==3): print(-1) else: if (n % 2==0): k=n while (k>0): if (k==4): k=k-2 else: arr=arr+[k] k=k-2 ...
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon...
1
n=int(raw_input()) h=map(int,raw_input().split()) s=[] for i in range(0,n): s.append(-h[i]) print abs(min(s))
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter. Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition: * Every ro...
3
from collections import Counter H, W = map(int, input().split()) count = Counter() for _ in range(H): s = input() for j in range(W): count[s[j]] += 1 four = int(H/2) * int(W/2) two = (H%2)*int(W/2) + (W%2)*int(H/2) one = (H%2) * (W%2) # print(count) # print(four, two, one) for i in range(26): alpha ...
Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked n of them how much effort they needed to reach red. "Oh, I just spent x_i hours solving problems", said the i-th of them. Bob wants to train his math skills...
3
# 1266A.py def evenExists(num): evenCount = 0 i = 0 while(evenCount<2 and i<len(num)): if num[i]%2 == 0: evenCount+=1 i+=1 if(evenCount>=2): return True return False t = int(input()) while t: num = [int(x) for x in input()] s = sum(num) if s % 3 == 0 and evenExists(num) and 0 in num: print('red') ...
In this problem, a n Γ— m rectangular matrix a is called increasing if, for each row of i, when go from left to right, the values strictly increase (that is, a_{i,1}<a_{i,2}<...<a_{i,m}) and for each column j, when go from top to bottom, the values strictly increase (that is, a_{1,j}<a_{2,j}<...<a_{n,j}). In a given ma...
3
n, m = map(int, input().split()) k = 0 a = [0] * n for i in range(n): a[i] = list(map(int, input().split())) b = [0] * n c = [0] * n for i in range(n): b[i] = [0] * m c[i] = [0] * m for j in range(m): b[i][j] = [0, 0] c[i][j] = [0, 0] for i in range(n): for j in range(m - 1): ...
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats. Constraints * 2 ≀ N ...
3
N = int(input()) a = list(map(int,input().split())) ma = max(a) mi = min(a) if ma-mi >= 2: print('No') elif ma == mi: if a[0] <= N//2 or a[0] == N-1: print('Yes') else: print('No') else: maxnum = a.count(ma) minnum = a.count(mi) #if max(a) == minnum: # print('No') if ...
Write a program which replace all the lower-case letters of a given text with the corresponding captital letters. Input A text including lower-case letters, periods, and space is given in a line. The number of characters in the text is less than or equal to 200. Output Print the converted text. Example Input t...
3
l = str(input()) print(str.upper(l))
You are given a rectangular cake, represented as an r Γ— c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 Γ— 4 cake may look as follows: <image> The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contain...
1
m, n = map(int, raw_input().split()) # 3 4 l = [] for i in xrange(m): l.append( map( int, list( raw_input().replace('S','2').replace('.','1') ) ) ) s = 0 for i in xrange(m): if 2 in l[i]: continue for j in xrange(n): ...
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from t...
3
N,A,B=map(int,input().split()) S=input() for i in range(N): if S[i]=="a": if (A+B)>0: print("Yes") A-=1 else: print("No") if S[i]=="b": if (A+B)>0 and B>0: print("Yes") B-=1 else: print("No") if S[i]=="c": print("No")
Three friends are going to meet each other. Initially, the first friend stays at the position x = a, the second friend stays at the position x = b and the third friend stays at the position x = c on the coordinate axis Ox. In one minute each friend independently from other friends can change the position x by 1 to the...
3
t = int(input()) for i in range(t): s = list(map(int,input().split())) a = s[0] b = s[1] c = s[2] p = abs(a-b)+abs(a-c)+abs(b-c) if a==b and b==c : p = 0 elif a==b or b==c or a==c : if p==2: p-=2 else: p-=4 else: p-=4 print(p)
A map of some object is a rectangular field consisting of n rows and n columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly k islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each ...
3
def logic(a, b): sea = ['S' for _ in range(a*a)] if a % 2 != 0: if b <= (a * a) // 2 + 1: for i in range((a)**2): if b == 0: break else: if i % 2 == 0: sea[i] = 'L' b -= 1 ...
You are given the array a consisting of n positive (greater than zero) integers. In one move, you can choose two indices i and j (i β‰  j) such that the absolute difference between a_i and a_j is no more than one (|a_i - a_j| ≀ 1) and remove the smallest of these two elements. If two elements are equal, you can remove a...
3
import sys tc = int(sys.stdin.readline()) for _ in range(tc): n = int(sys.stdin.readline()) arr = list(map(int, sys.stdin.readline().split())) check = sorted(arr) can = True for i in range(1, n): if check[i] - check[i - 1] > 1: can = False break if can: pr...
A binary string is a string where each character is either 0 or 1. Two binary strings a and b of equal length are similar, if they have the same character in some position (there exists an integer i such that a_i = b_i). For example: * 10010 and 01111 are similar (they have the same character in position 4); * 10...
3
t = int(input()) for _ in range(t): n = int(input()) s = input() ans='' for i in range(0, (2*n -1), 2): ans+=s[i] print(ans)
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...
1
s, t = map(lambda x: x.lower(), [raw_input() for i in range(2)]) print -1 if s < t else 0 if s == t else 1
Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t. Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decim...
3
n=str(input()) op='' if n[0]=='9': op+=''.join('9') k=1 else: k=0 for i in range(k,len(n)): if int(n[i])>4: j=9-int(n[i]) op+=''.join(str(j)) else: op+=''.join(n[i]) print(op)
There is a robot on a coordinate plane. Initially, the robot is located at the point (0, 0). Its path is described as a string s of length n consisting of characters 'L', 'R', 'U', 'D'. Each of these characters corresponds to some move: * 'L' (left): means that the robot moves from the point (x, y) to the point (x...
3
import math for _ in range(int(input())): d = dict() x, y = 0, 0 move = 0 d[(x,y)] = move n = int(input()) bestmove = math.inf bl, br = -1, -1 for c in input(): move += 1 if c == 'L': x -= 1 elif c == 'R': x += 1 elif c == 'U': y += 1 elif c == 'D': y -= 1 if (x, y) in d and move - d[(...
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
n,m=[int(i) for i in input().split()] k=min(n,m) if k==1 or k%2==1 : print('Akshat') else: print('Malvika')
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder). Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that. You have to answer t independent test cases. Input The fi...
3
t=int(input()) for _ in range(t): a=int(input()) count2=0 count3=0 while(a%2==0): a=a//2 count2+=1 while(a%3==0): a=a//3 count3+=1 if(a==1 and count2<=count3): print((2*count3)-count2) else: print("-1")
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimu...
3
""" https://codeforces.com/problemset/problem/579/A """ x = int(input()) print("{0:b}".format(x).count("1"))
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of ea...
3
n=int(input()) l=list(map(int,input().split())) a=0 for i in l: a+=i/n print(a)
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of ...
3
str = input() removePos = len(str) - 1 for i in range(len(str)): if str[i] == '0': removePos = i break for i in range(len(str)): if (i != removePos): print(str[i], end="") print()
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 = input() for i in range(0, int(n)): word = input() if(len(word) > 10): print (word[0] + str(len(word)-2) + word[-1]) else: print (word)
Ayoub had an array a of integers of size n and this array had two interesting properties: * All the integers in the array were between l and r (inclusive). * The sum of all the elements was divisible by 3. Unfortunately, Ayoub has lost his array, but he remembers the size of the array n and the numbers l and...
3
n, l, r = map(int, input().split()) mod = 1000000007 dp = [[0, 0, 0] for i in range(n + 1)] zero=(r)//3-(l-1)//3 one=(r-1)//3-(l-2)//3 two=(r-2)//3-(l-3)//3 zero %= mod one %= mod two %= mod dp[1][0] = zero dp[1][1] = one dp[1][2] = two for i in range(2, n + 1): dp[i][0] = (dp[i - 1][0] * zero) % mod + (dp[i - 1][1...
For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integ...
3
from sys import stdin from math import gcd n = int(stdin.readline()) arr = list(map(int,stdin.readline().split())) gc = [arr[-1]] for i in range(n-2,0,-1): gc.append(gcd(gc[-1],arr[i])) ans = (arr[0]*gc[-1])//gcd(arr[0],gc[-1]) for i in range(1,n-1): ans = gcd(ans,(arr[i]*gc[-1-i])//gcd(arr[i],gc[-1-i])) print(...
Mike is trying rock climbing but he is awful at it. There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai < ai + 1 for all i from 1 to n - 1; we will call such sequence a track. Mike thinks that the track a1, ..., an has difficulty <image>. In othe...
1
n = input() a = map(int, raw_input().split()) print max(min([a[i + 1] - a[i - 1] for i in range(1, n - 1)]), max([a[i + 1] - a[i] for i in range(n - 1)]))
A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi...
1
n,m = map(int,raw_input().split()) # if n<=int(m/2): # print n # elif m<=int(n/2): # print m # else: tot = 0 tm = [[1,2],[2,1]] while n>0 and m>0: if n>m: n-=tm[1][0] m-=tm[1][1] if n<0 or m<0: break tot+=1 else: n-=tm[0][0] m-=tm[0][1] if n<0 or m<0: break tot+=1 print tot
A flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouqu...
3
import sys num = int(sys.stdin.readline()) fl = map(int, sys.stdin.readline().split()) odd = 0 even = 0 for f in fl: if (f % 2): odd += 1 else: even += 1 res = min(even, odd) odd -= even if (odd > 0): res += odd // 3 print(res)
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, the...
3
a=eval(input()) b=input().split() b=[int(x) for x in b] sum = 0 for i in b: sum+=abs(i) print(sum)
You are playing another computer game, and now you have to slay n monsters. These monsters are standing in a circle, numbered clockwise from 1 to n. Initially, the i-th monster has a_i health. You may shoot the monsters to kill them. Each shot requires exactly one bullet and decreases the health of the targeted monste...
3
import io,os input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import sys def main(): t=int(input()) for _ in range(t): n=int(input()) AB=[list(map(int,input().split())) for _ in range(n)] for i,(a,b) in enumerate(AB): a_prev=AB[(i+1)%n][0] AB[i][1]=min(b...
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed tha...
3
s1 = input() s2 = input() h1 = int(s1[0:2]) m1 = int(s1[3:]) h2 = int(s2[0:2]) m2 = int(s2[3:]) t1 = 60 * h1 + m1 t2 = 60 * h2 + m2 res = (t1 + t2) // 2 hour = res // 60 minutes = res % 60 if hour >= 10: print(hour, end="") else: print('0', hour, sep="", end="") print(":", end="") if minutes >= 10: ...
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X ...
3
N=int(input()) D,X=map(int,input().split()) ans=0 for _ in[0]*N: A=int(input()) ans+=(D+A-1)//A print(ans+X)
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
3
n = int(input()) i = 0 s = [] while i < n: tmp = input() s.append(tmp) i = i + 1 i = 0 while i < n: if s[i] in s[:i]: print("YES") else: print("NO") i = i + 1
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other wi...
3
# import sys # sys.stdin=open("input.in","r") # sys.stdout=open("output.out","w") d,l,v1,v2=map(int,input().split()) x=l-d print(x/(v1+v2))
You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board. A knight is a chess piece that can attack a piece in cell (x_2, y_2) from the cell (x_1, y_1) if one of the following conditions is met: * |x_...
3
n=int(input()) ans=[] x1=[] x2=[] for i in range(0,n): if(i%2==0): x1.append("W") else: x1.append("B") for i in range(0,n): if(i%2==0): x2.append("B") else: x2.append("W") for i in range(0,n): if(i%2==0): ans.append(x1) else: ans.append(x2) for i i...
You are given a string S. Each character of S is uppercase or lowercase English letter. Determine if S satisfies all of the following conditions: * The initial character of S is an uppercase `A`. * There is exactly one occurrence of `C` between the third character from the beginning and the second to last character (i...
1
import string import sys s = str(raw_input()) if (s[0] == 'A') & (s[2:-1].count('C') == 1): if (s.count('A') == 1) & (s.count('C') == 1): strans = s.translate(string.maketrans("AC", "ac")) slower = s.lower() if strans == slower: print 'AC' sys.exit() print 'WA'
Let's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the k-th digit of this sequence. Input The first and only lin...
3
L = [(i+1)*9*10**i for i in range(12)] number = int(input()) exponent=0 while number >= 0: number-=L[exponent] exponent+=1 exponent-=1 number%=L[exponent] start = 10**exponent numDigits = exponent+1 final = start+(number//numDigits-1) remainder = number%numDigits if remainder == 0: final = str(final) p...
Snuke lives on an infinite two-dimensional plane. He is going on an N-day trip. At the beginning of Day 1, he is at home. His plan is described in a string S of length N. On Day i(1 ≦ i ≦ N), he will travel a positive distance in the following direction: * North if the i-th letter of S is `N` * West if the i-th letter...
1
S=raw_input() print "No" if ("S" in S)+("N" in S)==1 or ("W" in S)+("E" in S)==1 else "Yes"
E869120 is initially standing at the origin (0, 0) in a two-dimensional plane. He has N engines, which can be used as follows: * When E869120 uses the i-th engine, his X- and Y-coordinate change by x_i and y_i, respectively. In other words, if E869120 uses the i-th engine from coordinates (X, Y), he will move to the ...
3
from math import * n = int(input()) engine = [list(map(int, input().split())) for i in range(n)] args = [] for i in range(n): x, y = engine[i] if x == 0: if y < 0: args.append((-pi/2, x, y)) elif y > 0: args.append((pi/2, x, y)) elif y == 0: if x > 0: ...
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory...
3
from itertools import permutations def solve(g): perm = list(permutations(range(0, 5))) sol = 0 for p in perm: happ = g[p[0]][p[1]] + g[p[1]][p[0]] + g[p[2]][p[3]] + g[p[3]][p[2]] + g[p[1]][p[2]] + g[p[2]][p[1]] + g[p[3]][p[4]] + g[p[4]][p[3]] + g[p[2]][p[3]] + g[p[3]][p[2]] + g[p[3]][p[4]] + g[p[4...
Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence. Constraints * 1 \leq N,A,B \leq 3\times 10^5 * ...
3
# で぀oO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys def main(N, A, B): if A + B - 1 > N or A * B < N: print(-1) return P = [] r = A * B - N for b in range(B): for a in range(A): if b >= 1 and a >= 1 and r > 0: if r >= A - 1: r...
Kolya got an integer array a_1, a_2, ..., a_n. The array can contain both positive and negative integers, but Kolya doesn't like 0, so the array doesn't contain any zeros. Kolya doesn't like that the sum of some subsegments of his array can be 0. The subsegment is some consecutive segment of elements of the array. Y...
3
from __future__ import division, print_function from io import BytesIO, IOBase import os,sys,math,heapq,copy from collections import defaultdict,deque,Counter from bisect import bisect_left,bisect_right from functools import cmp_to_key from itertools import permutations,combinations,combinations_with_replacement # <fas...
There are n points on the plane, (x_1,y_1), (x_2,y_2), …, (x_n,y_n). You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle. I...
3
n=int(input()) list=[] for i in range(n): p,q=map(int,input().split()) list.append(p+q) print(max(list))
On her way to programming school tiger Dasha faced her first test β€” a huge staircase! <image> The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values β€” th...
3
z=list(map(int,input().split())) if abs(z[0]-z[1])>1 : print("NO") else: if z[0]==0 and z[1]==0: print("NO") else: 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()) a="" for i in range(n): a = a.replace("it", "that") if(i%2!=0): a+=("I love it " ) else: a+=("I hate it " ) print(a[:len(a)-1])
Sasha is a very happy guy, that's why he is always on the move. There are n cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered from 1 to n in increasing order. The distance between any two adjacent cities is equal to 1 kilometer. Since all roads in...
3
n,v=map(int,input().split()) if v>=n-1: print(n-1) else: print (int(v-1+((n-v)*(n-v+1)/2)))
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans. New parliament assembly hall is a rectangle consisting of a Γ— b chairs β€” a rows of b chairs each. Two ch...
3
import sys n, a, b = map(int, input().split()) if n > a*b: print(-1) sys.exit(0) par = [] for i in range(1, n+1, b): s = ['0']*b for j in range(b): if i+j <= n: s[j] = str(i+j) par.append(s) while len(par) < a: par.append(['0']*b) for i in range(a): if i%2 == 0: p...
There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a_1, a_2, ..., a_n, where a_i = 1 if in the i-th flat the light is on and a_i = 0 otherwise. Vova thinks that people in the i-th flats are distur...
3
n=int(input());a=list(map(int,input().split()));p=0 for i in range(n-2): if a[i]==a[i+2]==1!=a[i+1]: a[i+2]=0 p+=1 print(p)
Little penguin Polo has an n Γ— m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of row i and column j as aij. In one move the penguin can add or subtract number...
1
I = lambda:map(int , raw_input().split()) n , m , d = I() a = [] for i in range(n): a.extend(I()) a = sorted(a) q = a[0] % d for i in range(len(a)): if a[i] % d != q: print -1 exit(0) else: a[i] = (a[i] - q) // d S = sum(a) cur_s = 0 answer = 10**9 for i in range(len(a)): answer...
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
def abbrov(word): n=len(word) if(n<=10):return(word) else: return word[0]+str(n-2)+word[n-1] n=int(input()) list=[] for i in range(n): word=input() abb=abbrov(word) list.append(abb) for i in range(n): print(list[i])
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maxi...
3
n = int(input()) a = [int(i) for i in input().split()] g = [] s = 0 a.sort(reverse = True) i = 0 while i<len(a)-1: if a[i] == a[i+1] or a[i] == a[i+1]+1: g.append(a[i+1]) del a[i] del a[i] else: del a[i] g.sort() if len(g)<2: print(0) elif len(g)%2!=0: del g[0] j = 0...
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...
1
s1 = raw_input() s1 = list(set(s1)) new_str = "" for item in s1: new_str += item if len(new_str) % 2 == 0: print("CHAT WITH HER!") else: print("IGNORE HIM!")
You are given n integers a_1, a_2, ..., a_n, where n is odd. You are allowed to flip the sign of some (possibly all or none) of them. You wish to perform these flips in such a way that the following conditions hold: 1. At least (n - 1)/(2) of the adjacent differences a_{i + 1} - a_i for i = 1, 2, ..., n - 1 are grea...
3
# -*- coding: utf-8 -*- """ Created on Sat Jul 4 20:08:40 2020 @author: rishi """ t=int(input()) ans=[] for i in range(t): n=int(input()) a=list(map(int,input().split())) for j in range(n): if(j%2==0): a[j]=abs(a[j]) else: a[j]=-1*(abs(a[j])) ans....
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objecti...
3
a,b,c=map(int,input().split()) for i in range(a,b*a+1,a): if i%b==c: print('YES');break else: print('NO')
Ashishgup and FastestFinger play a game. They start with a number n and play in turns. In each turn, a player can make any one of the following moves: * Divide n by any of its odd divisors greater than 1. * Subtract 1 from n if n is greater than 1. Divisors of a number include the number itself. The player...
3
import sys from os import path if(path.exists('C:/Users/prana/Desktop/sublime/input.txt')): sys.stdin = open("C:/Users/prana/Desktop/sublime/input.txt","r") sys.stdout = open("C:/Users/prana/Desktop/sublime/output.txt","w") # ---------------------------------------------------------------------- import math ...
An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code 091), a colon (ASCII code 058), some (possibly zero) vertical line characters (ASCII code 124), another colon, and a ...
1
s=raw_input() bstart = -1 bend = -1 for i in range(0,len(s)): if s[i]=='[': bstart=i break for i in range(0,len(s)): if s[i]==']': bend=i if bstart<0 or bend<0: print '-1' else: s=s[bstart+1:bend] cstart = -1 for i in range(0,len(s)): if s[i]==':': cst...
You are given integers A and B, each between 1 and 3 (inclusive). Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number. Constraints * All values in input are integers. * 1 \leq A, B \leq 3 Input Input is given from Standard Input in the following format: A...
3
A,B=map(int,input().split()) print("NYoe s"[A%2and B%2::2])
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
x = int(input()) c = '' for i in range(1,x+1): if i%2==1: c += 'I hate that ' else: c+='I love that ' d = c[0:-5] + 'it' print(d)
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()) x=0 for i in range(n): a,b,c=input().split() if int(a)+int(b)+int(c)>=2: x+=1 print(x)
Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for n last days: a_1, a_2, ..., a_n, where a_i is the price of berPhone on the day i. Polycarp considers the price on the day i to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For example, if ...
3
tcase = int(input()) while tcase > 0: tcase -= 1 n = int(input()) l = list(map(int, input().split())) min = l[n-1] ans = 0 for i in range(n-2, -1, -1): if l[i] > min: ans += 1 if l[i] < min: min = l[i] print(ans)
Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer n, he encrypts it in the following way: he picks three integers a, b and c such that l ≀ a,b,c ≀ r, and then he computes the encrypted value m = n β‹… a + b - c. Unfortunately, an adversa...
3
t = int(input()) for T in range(t): l , r , m = input().split() l = int(l) r = int(r) m = int(m) a , b , c = 0 , 0 , 0 for i in range(l , r + 1): if m % i >= 0 and m % i <= r - l : a = i b , c = r , r - m % i if m - (m % i) > 0 : ...
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting o...
3
n = int(input()) a = [int(i) for i in input().split()] a.sort() start = 0 end = len(a) - 1 vertical = 0 horizontal = 0 flag = 0 while start <= end: if flag == 0: horizontal += a[end] end -= 1 flag = 1 else: vertical += a[start] start += 1 flag = 0 print(horizo...
There are N students and M checkpoints on the xy-plane. The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j). When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance. T...
3
N,M=map(int,input().split()) s=[list(map(int,input().split())) for _ in range(N)] c=[list(map(int,input().split())) for _ in range(M)] for i in range(N): d=10**9 n=0 for j in range(M): x=abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]) if x<d: d=x n=j+1 print(n)
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The ...
3
n , k = [int(i) for i in input().split()] ans = 0 team = 0 student = 0 for i in input().split(): student = int(i) if student + k <= 5: team +=1 if team == 3: team = 0 ans +=1 print(ans)
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
from typing import List def solve(*, _input: List[List[int]]) -> int: return sum([1 if sum(inner_lst) >= 2 else 0 for inner_lst in _input]) if __name__ == '__main__': problems_number = int(input()) input_lst = [] for _ in range(problems_number): input_lst.append(list(map(int, input().split()...
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
import decimal D=decimal.Decimal def answer(): # n k # int(n/k) moves # if odd, then sasha wins a = input().split() n = D(int(a[0])) k = D(int(a[1])) if D(D(D(int(n/k))%2)): print("YES") else: print("NO") answer()
The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis. Aki is fond of numbers, especially those with trailing zeros. For example, the number 9200 has two trailing zeros. Aki thinks the more trailing zero digits a n...
3
from math import sqrt def fact(a): global g global h for i in range(2, int(sqrt(a)) + 1): k = 0 if a % i == 0: g.append(i) while a % i == 0: a = a // i k += 1 if k != 0: h.append(k) if a > 1: g.append(a) h.ap...
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. Constraints * 1 ≀ a,b ≀ 10000 * a and b are integers. Input Input is given from Standard Input in the following format: a b Output If the product is odd, print `Odd`; if it is even, print `Even`. E...
3
a,b=map(int,input().split()) print("Even" if (a*b)%2==0 else "Odd")
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: * Operation ++ increases the value of variable x by 1. * Operation -- decreases the value of variable x by 1....
3
n = int(input()) cnt = 0 for i in range(n): line = input() if line.count('+') > 0: cnt += 1 else: cnt -= 1 print(cnt)
You are the gym teacher in the school. There are n students in the row. And there are two rivalling students among them. The first one is in position a, the second in position b. Positions are numbered from 1 to n from left to right. Since they are rivals, you want to maximize the distance between them. If students a...
3
import sys from array import array # noqa: F401 import typing as Tp # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') def main(): t = int(input()) for _ in range(t): n, x, a, b = map(int, input().split()) if a > b: a, b = b, a left_mv = m...
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black? Constraints * 1 \leq N \leq 100 * 0 \leq A \leq N^2 Inputs Input is given from Standard Input in the following format: N A Outputs Print...
3
A = int(input()) N = int(input()) print(A**2 - N)
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha...
3
r1,r2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1,d2 = map(int,input().split()) digits = [i for i in range(1,10)] n = 9 def good_combo(dig1,dig2,dig3,dig4): row1 = (r1 == dig1 + dig2) row2 = (r2 == dig3 + dig4) col1 = (c1 == dig1 + dig3) col2 = (c2 == dig2 + dig4) diag1 = (d1 == ...
You are given two strings s and t both of length 2 and both consisting only of characters 'a', 'b' and 'c'. Possible examples of strings s and t: "ab", "ca", "bb". You have to find a string res consisting of 3n characters, n characters should be 'a', n characters should be 'b' and n characters should be 'c' and s and...
1
n = int(raw_input()) s = raw_input() t = raw_input() cs = ['a','b','c'] for a in cs: for b in cs: for c in cs: if a != b and b != c and c != a: if a+b not in [s,t] and b+c not in [s, t] and (n < 2 or c + a not in [s, t]): x = a+b+c print 'YES' print x*n exit...
Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no e...
1
# 1 - ordena cada par de valores pra ver o primeiro ser o maior # 2 - orderna lista dos pares pra que o maior retangulo venha primeiro na matriz # - Nesse caso o tamnho do meu retangulo eh o tamanho do primeiro do meu par mais a esquerda # 3 - Fazer as combinacoes de colocar na matriz, se nenhuma der, retorna -1. S...
Input The input contains a single integer a (0 ≀ a ≀ 35). Output Output a single integer. Examples Input 3 Output 8 Input 10 Output 1024
3
'''n=int(input()) x=0 for i in range(n): s=input() if s=='++X': x+=1 else: x-=1 print(x) ''' ''' n=int(input()) l=list(map(int,input().split())) c=0 for i in range(1,n,1): if l[i-1]<=l[i]: c+=1 print(c) ''' n=int(input()) if n%2==0: print(0) else: print(1)