import sys
def main ():
    n = int(sys.stdin.readline().strip())
    lis = sys.stdin.readline().split()
    rango = sys.stdin.readline().split()
    c = 0
    for i in range (int(rango[0])-1,int(rango[1])-1):
        c += int(lis[i])
    sys.stdout.write(str(c))
main()

n=int(input())
x=list(map(int,input().split()))
a,b=list(map(int,input().split()))

c=0
for i in range(n+1):
	if a!=b:
		c+=x[a-1]
		a+=1
	else:
		print(c)
		break

The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank i+1. Reaching a certain rank i having not reached all the previous i-1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream.


MOD = 1000000007

# Python3 program to do modular division
import math

# Function to find modulo inverse of b. It returns
# -1 when inverse doesn't
# modInverse works for prime m
def mod_inverse(b,m):
    g = math.gcd(b, m)
    if (g != 1):
        # print("Inverse doesn't exist")
        return -1
    else:
        # If b and m are relatively prime,
        # then modulo inverse is b^(m-2) mode m
        return pow(b, m - 2, m)

# Function to compute a/b under modulo m
def div_mod(a,b,m):
    a = a % m
    inv = mod_inverse(b,m)
    if(inv == -1):
        return None
    else:
        return (inv*a) % m

def sum_mod(a, b):
    return (a + b) % MOD

def fast_power(base, power):
    """
    Returns the result of a^b i.e. a**b
    We assume that a >= 1 and b >= 0

    Remember two things!
     - Divide power by 2 and multiply base to itself (if the power is even)
     - Decrement power by 1 to make it even and then follow the first step
    """

    result = 1
    while power > 0:
        # If power is odd
        if power % 2 == 1:
            result = (result * base) % MOD

        # Divide the power by 2
        power = power // 2
        # Multiply base to itself
        base = (base * base) % MOD

    return result

years = int(input())

fst = fast_power(4, years)
snd = fast_power(2, years)
sum_num = sum_mod(fst, snd)

out = div_mod(sum_num, 2, MOD)

# for _ in range(years):
#     up_partial = up
#     down_partial = down
#     up = up_partial * 3 - up_partial
#     down = down_partial * 3 - down_partial
#     down += up_partial
#     up += down_partial

#     print(up, down)

print(out)

import sys
import math

TESTING = False

def solve():
    n, = read()
    if n == 0: return 1
    MOD = 1000000007
    return (pow(2, n-1, MOD) + pow(2, 2*n-1, MOD)) % MOD

def read(mode=2):
    inputs = input().strip()
    if mode == 0: return inputs  # String
    if mode == 1: return inputs.split()  # List of strings
    if mode == 2: return list(map(int, inputs.split()))  # List of integers

def write(s="\n"):
    if s is None: s = ""
    if isinstance(s, list): s = " ".join(map(str, s))
    s = str(s)
    print(s, end="")

def run():
    if TESTING: sys.stdin = open("test.txt")
    res = solve()
    write(res)

run()

Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process. Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.


n, m = [int(i) for i in input().split()]
g = [[] for i in range(n)]
mark = [False] * n
if n is not m:
    print("NO")
else:
    def dfs(node):
        mark[node] = True
        for u in g[node]:
            if mark[u] is False:
                dfs(u)
    for i in range(m):
        v, u = [int(x)-1 for x in input().split()]
        g[v].append(u)
        g[u].append(v)
    dfs(0)
    ans = True
    for i in range(1, n):
        if mark[i] is False:
            ans = False
    if ans is True:
        print("FHTAGN!")
    else:
        print("NO")

from collections import defaultdict
from typing import List, Tuple

def solve(n: int, m: int, adj: List[Tuple[int, int]]) -> str:
    visited = [0] * n
    graph = defaultdict(list)  # type: Dict[int, List[int]]
    for u, v in adj:
        graph[u - 1].append(v - 1)
        graph[v - 1].append(u - 1)
    stack = [0]
    while stack:
        curr_node = stack.pop()
        visited[curr_node] = 1
        for adj_node in graph[curr_node]:
            if not visited[adj_node]:
                stack.append(adj_node)
    if sum(visited) != n:
        return 'NO'
    elif n == m:
        return 'FHTAGN!'
    else:
        return 'NO'

n, m = list(map(int, input().split()))
adj = [list(map(int, input().split())) for _ in range(m)]

print(solve(n, m, adj))

...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with n vertices and m edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.It is guaranteed that the graph contains no multiple edges and self-loops.


__author__ = 'Alexander'
import sys
format = int(sys.stdin.readline().strip())
timeH, timeM = map(int,sys.stdin.readline().split(':'))
# print(format)
# print(timeH)
# print(timeM)
if format == 12:
    if timeH > 12 or timeH == 0:
        if timeH == 0: timeH = 1
        elif timeH%10 == 0: timeH = 10
        else: timeH %= 10
    if timeM > 59:
        timeM %= 10
else:
    if timeH > 23:
        timeH %= 10
    if timeM > 59:
        timeM %= 10
sys.stdout.write("%02d:%02d" % (timeH, timeM))

You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.


n,m = map(int, input().split())

grid = [[0 for j in range(n)] for i in range(n)]

for i in range(m):
	a,b = map(int, input().split())
	grid[a-1][b-1] = 1
	grid[b-1][a-1] = 1

groups = 0
fire = True
while(fire):
	found = False
	to_fire = []
	for i in range(n):
		if sum(grid[i]) == 1:
			found = True
			j = grid[i].index(1)
			to_fire.extend([(i,j),(j,i)])
	for e in to_fire:
		grid[e[0]][e[1]] = 0
	if found:
		groups+=1
	else:
		fire = False
print(groups)

n,m=map(int,input().split())
friends_list = [[] for _ in range(n)]
for i in range(m):
	a,b = map(int, input().split())
	friends_list[a-1].append(b)
	friends_list[b-1].append(a)

# so idea: we keep track of the number of the number of laces each student is tied to - that way, if we remove a student, we can update the list in constant time

def reprimand(friends_list):
	bad_list = []
	for index in range(n):
		neighbours = friends_list[index]
		if len(neighbours) == 1:
			bad_list.append(index)
	for index in bad_list:
		neighbours = friends_list[index]
		friends_list[index] = []
		try:
			friends_list[neighbours[0]-1].remove(index+1)
		except IndexError: # already deleted
			pass

ans = 0
copy = [len(stuff) for stuff in friends_list]
another = []
while copy != another:
	another = copy
	reprimand(friends_list)
	copy = [len(stuff) for stuff in friends_list]
	ans += 1

print(ans-1)

Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.Determine how many groups of students will be kicked out of the club.


from collections import Counter

def coincalc(nsoldiers, nranks, ranking):
    '''This is my reference implementation, which aims to be clear rather than fast'''
    # group ranks
    rank_count = Counter(ranking)
    rank_groups = tuple(rank_count[r] for r in range(1, nranks + 1))

    steps = []  #store all steps for ease of debugging
    current_state = rank_groups
    while current_state[-1] < nsoldiers:
        new_state = list(current_state)
        for rank in range(nranks-1):
            if current_state[rank] > 0:
                new_state[rank] = new_state[rank] - 1
                new_state[rank+1] += 1
        steps.append(new_state)
        current_state = new_state
    return steps

def main():
    nsoldiers, nranks = (int(x) for x in input().split())
    ranking = (int(x) for x in input().split())
    print(len(coincalc(nsoldiers, nranks, ranking)))

if __name__ == '__main__':
    main()

n,k=list(map(int,input().split()))
l=list(map(int,input().split()))
c=0
while set(l)!={k}:
    t=100000000000
    for i in range(n-1,-1,-1):
        if l[i]<k and t!=l[i]:
            t=l[i]
            l[i]=l[i]+1
    c=c+1
print(c)

In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank — some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k.


s = input()
k = int(input())

now = len(set(s))

if(len(s) < k):
    print('impossible')
else:
    if(now >= k):
        print(0)
    else:
        print(abs(k - now))

s = input()
k = int(input())
if len(s) < k or k > 26:
    print("impossible")
else:
    l = set()
    for ch in s:
        l.add(ch)
    a = k - len(l)
    if a < 0:
        a = 0
    print(a)

Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.

[{'input': 'yandex\n6\n', 'output': ['0\n']}, {'input': 'yahoo\n5\n', 'output': ['1\n']}, {'input': 'google\n7\n', 'output': ['impossible\n']}, {'input': 'a\n1\n', 'output': ['0\n']}, {'input': 'z\n2\n', 'output': ['impossible\n']}, {'input': 'fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26\n', 'output': ['14\n']}, {'input': 'nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26\n', 'output': ['12\n']}, {'input': 'a\n3\n', 'output': ['impossible\n']}, {'input': 'smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1\n', 'output': ['0\n']}, {'input': 'cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4\n', 'output': ['1\n']}, {'input': 'fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20\n', 'output': ['18\n']}, {'input': 'swmkwaruyv\n5\n', 'output': ['0\n']}, {'input': 'tnbqpsuhkczmejirvyfdolxwga\n22\n', 'output': ['0\n']}, {'input': 'abcde\n3\n', 'output': ['0\n']}, {'input': 'abb\n1\n', 'output': ['0\n']}, {'input': 'aaaa\n1\n', 'output': ['0\n']}, {'input': 'abcde\n2\n', 'output': ['0\n']}, {'input': 'yandex\n4\n', 'output': ['0\n']}, {'input': 'aaabbbccc\n1\n', 'output': ['0\n']}, {'input': 'abcd\n2\n', 'output': ['0\n']}, {'input': 'asdfgh\n2\n', 'output': ['0\n']}, {'input': 'aab\n1\n', 'output': ['0\n']}, {'input': 'mynameissako\n5\n', 'output': ['0\n']}, {'input': 'abcde\n1\n', 'output': ['0\n']}, {'input': 'abcd\n3\n', 'output': ['0\n']}, {'input': 'abcdef\n2\n', 'output': ['0\n']}, {'input': 'abcdefg\n4\n', 'output': ['0\n']}, {'input': 'abc\n1\n', 'output': ['0\n']}, {'input': 'asdafjsgljdllgjdgkl\n5\n', 'output': ['0\n']}, {'input': 'yaay\n3\n', 'output': ['1\n']}, {'input': 'yaay\n4\n', 'output': ['2\n']}, {'input': 'zzzzzz\n2\n', 'output': ['1\n']}]


def train_and_peter():
    flags = input()
    a = input()
    b = input()

    i = flags.find(a)
    if i == -1:
        forward = False
    else:
        forward = flags.find(b, i + len(a)) != -1

    reversed_flags = flags[::-1]
    j = reversed_flags.find(a)
    if j == -1:
        backward = False
    else:
        backward = reversed_flags.find(b, j + len(a)) != -1

    if forward and backward:
        print('both')
    elif forward:
        print('forward')
    elif backward:
        print('backward')
    else:
        print('fantasy')

train_and_peter()

a, b, c = input(), input(), input()

def check(a):
    i = a.find(b)
    return i != -1 and a.find(c, i + len(b)) != -1

f = check(a)
b = check(a[::-1])

if f and b:
    print("both")
elif f:
    print("forward")
elif b:
    print("backward")
else:
    print("fantasy")

Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.

[{'input': 'atob\na\nb\n', 'output': ['forward\n']}, {'input': 'aaacaaa\naca\naa\n', 'output': ['both\n']}, {'input': 'aaa\naa\naa\n', 'output': ['fantasy\n']}, {'input': 'astalavista\nastla\nlavista\n', 'output': ['fantasy\n']}, {'input': 'abacabadabacaba\nabacaba\nabacaba\n', 'output': ['both\n']}, {'input': 'a\na\na\n', 'output': ['fantasy\n']}, {'input': 'ab\nb\na\n', 'output': ['backward\n']}, {'input': 'aaa\naaaa\naaaa\n', 'output': ['fantasy\n']}, {'input': 'bbabbbbababbaabaabaa\nabb\nbaab\n', 'output': ['forward\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb\n', 'output': ['both\n']}, {'input': 'babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa\n', 'output': ['forward\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb\n', 'output': ['both\n']}, {'input': 'aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa\n', 'output': ['backward\n']}, {'input': 'aaaa\naaa\naa\n', 'output': ['fantasy\n']}, {'input': 'zzzz\nzz\nzzz\n', 'output': ['fantasy\n']}, {'input': 'zzzz\nzzzz\nzzzz\n', 'output': ['fantasy\n']}, {'input': 'zzzz\nzz\nzz\n', 'output': ['both\n']}, {'input': 'aabaa\naab\nbaa\n', 'output': ['fantasy\n']}, {'input': 'aabaab\naba\nab\n', 'output': ['forward\n']}, {'input': 'aab\nb\naa\n', 'output': ['backward\n']}, {'input': 'abacaba\naca\nba\n', 'output': ['both\n']}]


from heapq import heappush, heappop

s = list(input())
n = len(s)
ans = 0
k = 0
heap = []

for i in range(n):
    if s[i] == '(':
        k+=1
    elif s[i] == ')':
        k-=1
    else:
        a,b = map(int, input().split())
        ans += b
        heappush(heap, (a-b, i))
        s[i] = ')'
        k-=1

    if k<0:
        if len(heap)==0:
            break
        v,p = heappop(heap)
        ans += v
        s[p] = '('
        k+=2

if k!=0:
    print(-1)
else:
    print(ans)
    print(''.join(s))

# Made By Mostafa_Khaled

import heapq

s = list(input())

new_s, cost, opens, opens_i = str(), 0, 0, list()

for i in range(len(s)):
    opens += int(s[i] == '(') - int(s[i] != '(')

    if s[i] == '?':
        a, b = [int(i) for i in input().split()]

        s[i] = ')'
        heapq.heappush(opens_i, [-b + a, i])
        cost += b

    if opens < 0:
        if opens_i:
            closed = heapq.heappop(opens_i)
            s[closed[1]] = '('

            cost += closed[0]
            opens += 2
        else:
            break

if opens == 0:
    print(cost)
    print(''.join(s))
else:
    print(-1)

This is yet another problem on regular bracket sequences.A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequence that consists of characters "(", ")" and "?". You have to replace each character "?" with a bracket so, that you get a regular bracket sequence.For each character "?" the cost of its replacement with "(" and ")" is given. Among all the possible variants your should choose the cheapest.


n = int(input())
s = list(map(int,input().split()))

dp = [-1]*n
dp[n-1] = s[n-1]
i = n-2
while(i>-1):
    dp[i] = s[i]
    if(i+2<n):
        dp[i] = min(dp[i],max(dp[i+1],dp[i+2]))
    else:
        dp[i] = min(dp[i],dp[i+1])
    i -= 1

print(dp[0])

n = int(input())
s = list(map(int,input().split()))
a = [0]*n
for i in range(n):
    if i == 0:
        a[i]=s[i]
    elif i == 1:
        a[i]=min(s[i],a[i-1])
    else:
        a[i]=max(min(s[i],a[i-1]),min(s[i],a[i-2]))
print(a[-1])

In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i<n-1), you can reach the tiles number i+1 or the tile number i+2 from it (if you stand on the tile number n-1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai+1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.


I=lambda:map(int,input().split())

n,m=I()

N=list(I())

p=set()

for i in range(m):

	x,y=I();x-=1;y-=1

	p.add((x,y)if x<y else(y,x))

r=1e9

for i in range(n):

	for j in range(i):

		for k in range(j):

			if(j,i)in p and(k,i)in p and(k,j)in p:

				r = min(r,N[i]+N[j]+N[k])

print(-1 if r>1e8 else r)

import itertools
import math

import time
def timer(f):
    def tmp(*args, **kwargs):
        t = time.time()
        res = f(*args, **kwargs)
        print("Время выполнения функции: %f" % (time.time()-t))
        return res

    return tmp

#n = int(input())

n, m = map(int, input().split(' '))
array = list(map(int, input().split(' ')))
matrix = [[0 for j in range(n)] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split(' '))
    a-=1
    b-=1
    matrix[a][b] = 1
    matrix[b][a] = 1

price = 100000000000000
u = 0;
uu = 0;
uuu = 0;
for i in range(n):
    for j in range(n):
        for k in range(n):
            if i!=j and j!=k and i!=k:
                if matrix[i][j]==1 and matrix[i][k]==1 and matrix[j][k]==1:
                    cp = array[i]+array[j]+array[k]
                    if cp<price:
                        price = cp
                        u = i
                        uu = j
                        uuu = k
                else:
                    #print(i, j, k)
                    pass

if price == 100000000000000:
    print(-1)
else:
    print(price)

A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.


n = int(input())
s = set()
ans = 0
crtVisNb = 0
for _ in range(n):
  a, b = input().split()
  if a == '-':
    if b in s:
      s.remove(b)
      ans = max(ans,crtVisNb)
      crtVisNb -= 1
    else:
      ans += 1
  else:
    s.add(b)
    crtVisNb += 1
    ans = max(ans,crtVisNb)
print(ans)

a = int(input())
b = [0 for i in range(1000001)]
q = 0
cnt = 0
mx = 0
for i in range(a):
    z, x = input().split()
    x = int(x)
    if z == '+':
        b[x] = 1
        cnt += 1
    if z == '-':
        if b[x] == 0:
            mx = mx + 1
            cnt += 1
        b[x] = 0
        cnt -= 1
    mx = max(mx, cnt)
print(mx)

Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 10^6. Thus, the system logs events of two forms:  "+ ri" — the reader with registration number ri entered the room;  "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.


commands, bytes = map(int, input().split())
s = [0] * bytes
c = 0

for i in range(commands):
	op = input().split()
	if op[0] == 'alloc':
        # n = the value written next to the "alloc" statement
		n = int(op[1])
        # search for a block
		p = min([i for i in range(bytes - n + 1) if all(not x for x in s[i : i + n])] + [bytes])
        # if fitted
		if p < bytes:
			c += 1
			print(c)
			for i in range(p, p + n):
				s[i] = c
        # if didn't fit
		else:
			print('NULL')

	elif op[0] == 'erase':
		x = int(op[1])
        # if command exists
		if x > 0 and s.count(x):
            # set all the cells occupied by that specific block back to 0
			for i in [i for i, v in enumerate(s) if v == x]:
				s[i] = 0
		else:
			print ('ILLEGAL_ERASE_ARGUMENT')
	else:
        # defragment
		s = ([v for v in s if v] + [0] * bytes)[ : bytes]

t, m = [int(i) for i in input().split()]
a = []
k = 0
for i in range(t):
    # print(a)
    f = True
    op = input()
    if op[:5] == "alloc":
        j, b = op.split()
        b = int(b)
        s = 0
        for j in range(len(a)):
            if a[j][1] - s >= b:
                k += 1
                a.insert(j, (k, s, b))
                print(k)
                f = False
                break
            else:
                s = a[j][1] + a[j][2]
        if f:
            if m - s >= b:
                k += 1
                a.append((k, s, b))
                print(k)
                continue
            else:
                print("NULL")
    elif op[:5] == "erase":
        j, b = op.split()
        b = int(b)
        for j in a:
            if j[0] == b:
                a.remove(j)
                f = False
                break
        if f:
            print("ILLEGAL_ERASE_ARGUMENT")
    else:
        s = 0
        for j in range(len(a)):
            a[j] = (a[j][0], s, a[j][2])
            s += a[j][2]

There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:   alloc n — to allocate n bytes of the memory and return the allocated block's identifier x;  erase x — to erase the block with the identifier x;  defragment — to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order; The memory model in this case is very simple. It is a sequence of m bytes, numbered for convenience from the first to the m-th.The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of n successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL.The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT.The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order.In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration.You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands.

[{'input': '6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n', 'output': ['1\n2\nNULL\n3\n']}, {'input': '6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1\n', 'output': ['NULL\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n']}, {'input': '14 100\nalloc 99\nalloc 1\nalloc 1\nerase 2\nalloc 1\nerase 4\nerase 1\nalloc 100\nalloc 1\nalloc 99\ndefragment\nerase 4\nalloc 100\nalloc 99\n', 'output': ['1\n2\nNULL\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\n4\nNULL\nNULL\nNULL\n']}, {'input': '26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2121605039\nerase 3\nalloc 51\nalloc 65\ndefragment\nerase 2\nerase 4\nalloc 52\nerase 3\ndefragment\nerase -1842529282\nerase 3\n', 'output': ['ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n1\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n']}, {'input': '22 9\nerase 1\nalloc 6\nalloc 65\nerase 1\nalloc 87\nerase -1638927047\nalloc 5\nerase 2\nalloc 70\ndefragment\nalloc 20\nalloc 48\nerase -69401977\nalloc 20\ndefragment\nerase 7\ndefragment\nerase 9\nerase 7\nerase 4\ndefragment\nalloc 66\n', 'output': ['ILLEGAL_ERASE_ARGUMENT\n1\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\n']}, {'input': '12 40\nerase 1\nalloc 21\nalloc 5\nalloc 7\ndefragment\ndefragment\nerase 2\nalloc 83\nerase 4\ndefragment\nalloc 59\ndefragment\n', 'output': ['ILLEGAL_ERASE_ARGUMENT\n1\n2\n3\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\n']}, {'input': '38 18\nalloc 72\nerase 2\nalloc 50\ndefragment\nerase 3\ndefragment\nalloc 43\nalloc 41\ndefragment\ndefragment\nalloc 26\nalloc 46\nalloc 16\nalloc 15\ndefragment\ndefragment\nalloc 95\nerase 7\nerase 7\nerase 5\nerase 2\nerase 9\nerase 7\nalloc 43\ndefragment\nerase 7\ndefragment\nalloc 48\nalloc 77\nerase 10\nerase 11\nalloc 16\nalloc 84\nerase 1\ndefragment\nalloc 86\ndefragment\nerase 13\n', 'output': ['NULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nNULL\n1\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n']}, {'input': '37 74\nalloc 11\ndefragment\nerase 1\ndefragment\nerase 2\ndefragment\nalloc 90\nerase 3\nerase 2\nerase 3\nerase 1\nerase 1\nalloc 38\nalloc 19\nerase 1\nerase 3\ndefragment\nalloc 93\nerase 5\nerase 4\nalloc 66\nalloc 71\nerase 5\ndefragment\ndefragment\ndefragment\ndefragment\nerase 7\nalloc 47\nerase -95616683\nerase 2\nalloc 28\nalloc 32\nerase 11\nalloc 50\ndefragment\ndefragment\n', 'output': ['1\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n4\n5\nILLEGAL_ERASE_ARGUMENT\nNULL\n']}, {'input': '16 49\nerase -751005193\ndefragment\nalloc 37\nalloc 82\nerase 3\nerase 1\nalloc 80\nalloc 51\ndefragment\nalloc 74\nerase 1\nalloc 91\ndefragment\ndefragment\nalloc 98\ndefragment\n', 'output': ['ILLEGAL_ERASE_ARGUMENT\n1\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n']}, {'input': '42 98\ndefragment\ndefragment\ndefragment\ndefragment\ndefragment\nalloc 5\nalloc 66\ndefragment\nerase 3\nalloc 53\ndefragment\nerase 4\nerase 2\nalloc 70\nerase 3\ndefragment\ndefragment\nerase 2\nerase 3\nerase -1327931832\nalloc 93\nalloc 64\nerase 7\nerase 6\nerase 3\nalloc 61\nalloc 12\nalloc 65\nerase 2\nalloc 46\nerase 11\nerase 9\nerase 9\nerase 6\nalloc 2\nalloc 78\ndefragment\nerase 13\nerase 6\nerase 10\nalloc 53\nalloc 46\n', 'output': ['1\n2\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n4\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n']}, {'input': '19 46\nalloc 21\nerase 2\nerase 1\ndefragment\nalloc 4\ndefragment\ndefragment\nalloc 40\nerase 1\ndefragment\ndefragment\nalloc 68\nerase -388966015\nalloc 85\nalloc 53\nerase 4\ndefragment\nalloc 49\nalloc 88\n', 'output': ['1\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n']}, {'input': '44 46\nalloc 28\nalloc 36\ndefragment\nerase -937404236\nalloc 71\ndefragment\nalloc 81\nalloc 51\nerase 3\ndefragment\nalloc 48\nerase 1\ndefragment\nalloc 36\ndefragment\ndefragment\nerase 1\ndefragment\ndefragment\nerase -1173350787\nalloc 94\nerase 5\ndefragment\nerase 9\nalloc 98\nerase 7\ndefragment\nerase 5\nerase 1\ndefragment\nerase 2\ndefragment\nerase 4\ndefragment\nerase 9\nalloc 8\ndefragment\nerase 9\ndefragment\ndefragment\ndefragment\nerase 1\nalloc 70\nerase 9\n', 'output': ['1\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\n2\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n']}, {'input': '26 25\nalloc 25\nerase 1\nalloc 24\nerase 2\nalloc 23\nerase 3\nalloc 24\nerase 4\nalloc 24\nerase 5\nalloc 21\nerase 6\nalloc 24\nerase 7\nalloc 25\nerase 8\nalloc 25\nerase 9\nalloc 24\nerase 10\nalloc 25\nerase 11\nalloc 25\nerase 12\nalloc 25\nerase 13\n', 'output': ['1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n']}, {'input': '22 9\nalloc 9\nerase 1\nalloc 9\nerase 2\nalloc 9\nerase 3\nalloc 9\nerase 4\nalloc 9\nerase 5\nalloc 9\nerase 6\nalloc 9\nerase 7\nalloc 9\nerase 8\nalloc 9\nerase 9\nalloc 9\nerase 10\nalloc 9\nerase 11\n', 'output': ['1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n']}, {'input': '7 6\nalloc 1\nalloc 2\nalloc 3\nerase 1\ndefragment\nerase 3\nalloc 4\n', 'output': ['1\n2\n3\n4\n']}, {'input': '3 1\nerase -1\nerase 0\nerase -2147483648\n', 'output': ['ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n']}, {'input': '7 100\nalloc 100\nerase 2147483647\nerase 1\nalloc 50\nalloc 50\nerase 3\nerase -2147483648\n', 'output': ['1\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\n']}, {'input': '12 10\nalloc 6\nalloc 2\nerase 1\nalloc 4\nalloc 2\nerase 3\nalloc 2\nalloc 3\nalloc 1\nalloc 1\nalloc 1\nalloc 1\n', 'output': ['1\n2\n3\n4\n5\nNULL\n6\n7\n8\n9\n']}, {'input': '8 50\nalloc 51\ndefragment\nalloc 100\ndefragment\nerase 1\nalloc 50\ndefragment\nalloc 50\n', 'output': ['NULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n1\nNULL\n']}, {'input': '10 10\nalloc 10\nerase -1\nerase 1\nalloc 5\nerase -1\nalloc 5\nerase 0\nalloc 5\nerase 0\nalloc 5\n', 'output': ['1\nILLEGAL_ERASE_ARGUMENT\n2\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\n']}, {'input': '16 10\nalloc 10\ndefragment\ndefragment\ndefragment\nalloc 10\nerase 1\nerase 2\nalloc 6\ndefragment\ndefragment\nalloc 4\ndefragment\ndefragment\nerase 3\ndefragment\nalloc 6\n', 'output': ['1\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\n3\nNULL\n']}, {'input': '16 10\nalloc 10\ndefragment\ndefragment\ndefragment\nalloc 10\nerase 1\nerase 2\nalloc 6\ndefragment\ndefragment\nalloc 4\ndefragment\ndefragment\nerase 2\ndefragment\nalloc 6\n', 'output': ['1\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\n3\n4\n']}]


def makeSet(n):
  global parent, ranks
  parent = [i for i in range (1000 ** 2 + 1)]
  ranks = [0 for i in range(1000 ** 2 + 1)]

def findSet(u):
  if u != parent[u]:
    parent[u] = findSet(parent[u])
  return parent[u]

def unionSet(u, v):
  up = findSet(u)
  vp = findSet(v)
  if up == vp:
    return
  if ranks[up] > ranks[vp]:
    parent[vp] = up
  elif ranks[up] < ranks[vp]:
    parent[up] = vp
  else:
    parent[up] = vp
    ranks[vp] += 1

def getID(x, y):
  return x * n + y

n = int(input())
makeSet(n)
x = []
y = []

for i in range(n):
  sx, sy = map(int, input().split())
  x.append(sx)
  y.append(sy)
  for j in range(i):
    if x[j] == sx or y[j] == sy:
      a = getID(sx, sy)
      b = getID(x[j], y[j])
      unionSet(a, b)

count = 0
for i in range(1000 ** 2):
  if i != parent[i]:
    count += 1

print(n - count - 1)

Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.We assume that Bajtek can only heap up snow drifts at integer coordinates.


n = int(input())
s = input().split('L')
ans = 0
if 'R' not in s[0]:
	if len(s) != 1:
		s = s[1:]
if 'R' in s[-1]:
	s[-1] = s[-1][:s[-1].index('R')]
for sub in s:
	if 'R' not in sub:
		ans += len(sub)
	else:
		idx = sub.index('R')
		ans += idx
		ans += (len(sub) - idx - 1) % 2
print(ans)

def num_standing(s):
    ret = 0
    l = [i for i, x in enumerate(s) if x=="L"]
    r = [i for i, x in enumerate(s) if x=="R"]
    for i in range(len(l)):
        if l[i]%2 == r[i]%2: ret += 1
    for i in range(1,len(r)):
        ret += r[i]-l[i-1]-1
    return ret

n = int(input())
s = input()

L_i = [i for i, x in enumerate(s) if x=="L"]
R_i = [i for i, x in enumerate(s) if x=="R"]

if len(L_i)==0 and len(R_i)==0:
    print(n)
elif len(L_i)==0:
    print(R_i[0])
elif len(R_i)==0:
    print(n-L_i[0]-1)
else:
    standing = 0
    #there are both L and R
    if R_i[0]<L_i[0]:
        # R comes first
        standing += R_i[0]
        if R_i[-1]>L_i[-1]: standing += R_i[-1]-L_i[-1]-1
        else: standing += n-L_i[-1]-1
        standing += num_standing(s[R_i[0]:L_i[-1]+1])

    else:
        # L comes first
        standing += R_i[0]-L_i[0]-1
        if R_i[-1]>L_i[-1]: standing += R_i[-1]-L_i[-1]-1
        else: standing += n-L_i[-1]-1
        standing += num_standing(s[R_i[0]:L_i[-1]+1])
        if len(L_i)==1 and len(R_i)==1: standing//=2
    print(standing)

Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!


n,L=map(int,input().split())
a=sorted(list(map(int,input().split())))
ans=0
for clen in range(L,101):
    csum=sum(y//clen for y in a)
    ans=max(ans,csum*clen)
print(ans)

n, l = map(int, input().split())
s, t = 0, list(map(int, input().split()))
for i in range(l, 101):
    r = sum(j // i for j in t) * i
    if r > s: s = r
print(s)

The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they may not have the same length (it is even possible for them to have different lengths)Every stripe can be cut into two or more parts. The cuttings are made perpendicularly to the side along which the length is measured. Thus the cuttings do not change the width of a stripe but each of the resulting pieces has a lesser length (the sum of which is equal to the length of the initial stripe)After all the cuttings the blinds are constructed through consecutive joining of several parts, similar in length, along sides, along which length is measured. Also, apart from the resulting pieces an initial stripe can be used as a blind if it hasn't been cut. It is forbidden to construct blinds in any other way.Thus, if the blinds consist of k pieces each d in length, then they are of form of a rectangle of k×d bourlemeters. Your task is to find for what window possessing the largest possible area the blinds can be made from the given stripes if on technical grounds it is forbidden to use pieces shorter than l bourlemeter. The window is of form of a rectangle with side lengths as positive integers.


n = int (input())
a = list(map(int,input().split()))
d = {}
for i in range(n):
	x = i
	j = i
	count = 1
	while True:
		if j>0 and a[j] >= a[j-1]:
			count+=1
		else:
			break
		j-=1
	while True:
		if x<len(a)-1 and a[x] >= a[x+1]:
			count+=1
		else:
			break
		x+=1
	d[i] = count
print(max(d.values()))

def q66b():
	n = int(input())
	sections_list = [int(num) for num in input().split()]
	max_no = -1
	for i in range(len(sections_list)):
		num_sections = find_num_sections(sections_list, i)
		if(num_sections > max_no):
			max_no = num_sections
	print(max_no)

def find_num_sections(arr, index):
	count = 0
	ceiling = arr[index]
	for i in range(index, -1, -1):
		if(arr[i] <= ceiling):
			ceiling = arr[i]
			count += 1
		else:
			break
	ceiling = arr[index]
	for i in range(index+1, len(arr)):
		if(arr[i] <= ceiling):
			ceiling = arr[i]
			count += 1
		else:
			break
	return count

q66b()

Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1×n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1×5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.


import bisect
n=int(input())
l=list(map(int,input().split()))
c=list(map(int,input().split()))
count=0
f=[0]*5
for i in range(n):
  count=count+l[i]
  while count>=c[0]:
    j=bisect.bisect(c,count)-1
    p=count//c[j]
    f[j]=f[j]+p
    count=count-(count//c[j])*c[j]

for i in range(5):
  print(f[i],end=" ")
print()
print(count)

'''
def main():
	from sys import stdin,stdout
if __name__=='__main__':
	main()
'''
#Journey to moon
'''
def main():
	from sys import stdin,stdout
	import collections
	N,I =map(int,stdin.readline().split())
	visited=list(0 for x in range(N))
	G=collections.defaultdict(list)
	groups=[0]
	for _ in range(I):
		a,b=map(int,stdin.readline().split())
		G[a].append(b)
		G[b].append(a)
	q=collections.deque()
	flag=0
	for i in range(N):
		if not visited[i]:
			q.append(i)
			visited[i]=flag+1
			groups[flag]+=1
			while len(q):
				top=q.popleft()
				for j in G[top]:
					if visited[j]!=visited[top]:
						visited[j]=flag+1
						groups[flag]+=1
						q.append(j)
			flag+=1
			groups.append(0)
	counter=0
	for i in range(len(groups)-1):
		for j in range(i+1,len(groups)):
			counter+=groups[i]*groups[j]
	stdout.write(str(counter))
if __name__=='__main__':
	main()
'''
#Djikstra's
'''
import collections
class Graph:
	def __init__(self):
		self.nodes=set()
		self.edges=collections.defaultdict(list)
		self.distances = {}

	def add_node(self, value):
		self.nodes.add(value)

	def add_edge(self, from_node, to_node, distance):
		self.edges[from_node].append(to_node)
		self.edges[to_node].append(from_node)
		self.distances[(from_node, to_node)] = distance
		self.distances[(to_node, from_node)] = distance

def dijsktra(graph, initial):
	visited = {initial: 0}
	path = {}

	nodes = set(graph.nodes)

	while nodes:
		min_node = None
		for node in nodes:
			if node in visited:
				if min_node is None:
					min_node = node
				elif visited[node] < visited[min_node]:
					min_node = node

		if min_node is None:
			break

		nodes.remove(min_node)
		current_weight = visited[min_node]

		for edge in graph.edges[min_node]:
			weight = current_weight + graph.distances[(min_node, edge)]
			if edge not in visited or weight < visited[edge]:
				visited[edge] = weight
				path[edge] = min_node

	return visited, path

def main():
	from sys import stdin,stdout
	for _ in range(int(stdin.readline())):
		n,m=map(int,stdin.readline().split())
		G=Graph()
		for i in range(n):
			G.add_node(i+1)
		for i in range(m):
			a,b,c=map(int,stdin.readline().split())
			G.add_edge(a,b,c)
		initial=int(stdin.readline())
		v,p=dijsktra(G, initial)
		#print(v)
		#print(p)
		for i in range(1,n+1):
			if i!=initial:
				k=v.get(i,-1)
				stdout.write(str(k)+' ')
		stdout.write('\n')
if __name__=='__main__':
	main()
'''
#Larget pallindrome in String
'''
def main():
	from sys import stdin,stdout
	string=stdin.readline().strip()
	l=len(string)
	#Triangle logic

	arrlen=(l*(l-1))//2
	arr=list(0 for x in range(arrlen))
	f=0
	c=l-1
	for i in range(l-1):
		for j in range(i+1,l):
			if string[i]==string[j]:
				arr[f+j-i-1]=1
		f+=c
		c-=1
	#print(arr)
	if any(arr):

	else:
		if l & 1:
			stdout.write('First')
		else:
			stdout.write('Second')
	#2-d Array Logic
	arr=list(list(0 for i in range(l)) for j in range(l))
	for i in range(l):
		for j in range(l):
			if string[i]==string[j]:
				arr[i][j]=1
	maxim=0
	for i in range(0,l*(l-1)-2,l+1):
		a,b=i+1,i+2
		#print(a,b)
		acount=0
		x=a//5
		y=a%5
		acount=arr[x][y]
		x-=1
		y-=1
		while x>=0 and y>=0:
			acount+=arr[x][y]
			x-=1
			y-=1
		x=b//5
		y=b%5
		bcount=arr[x][y]
		x-=1
		y-=1
		while x>=0 and y>=0:
			bcount+=arr[x][y]
			x-=1
			y-=1
		maxim=max((acount,bcount,maxim))
	maxim=max(maxim,arr[l-2][l-1])
	maxim=(maxim<<1)^1
	delta=l-maxim
	if delta & 1:
		stdout.write('Second')
	else:
		stdout.write('First')
if __name__=='__main__':
	main()
'''
#276B
'''
def main():
	from sys import stdin,stdout
	import collections
	s=stdin.readline().strip()
	count=collections.Counter(s)
	l=list(filter(lambda x: count[x] & 1,list(x for x in count)))
	removed=sum(list(count[x] for x in l))-max(list(count[x] for x in l)+[0])
	if removed & 1:
		stdout.write('Second')
	else:
		stdout.write('First')
if __name__=='__main__':
	main()
'''
#362B
'''
def main():
	from sys import stdin,stdout
	n,m=map(int,stdin.readline().split())
	if m:
		dirty=sorted(map(int,stdin.readline().split()))
		if dirty[0]==1 or dirty[-1]==n:
			stdout.write('NO')
		else:
			flag=True
			for i in range(m-2):
				if dirty[i+1]==dirty[i]+1 and dirty[i+2]==dirty[i]+2:
					flag=False
					break
			if flag:
				stdout.write('YES')
			else:
				stdout.write('NO')
	else:
		stdout.write('YES')
if __name__=='__main__':
	main()
'''
#279B SUM OF SUB-ARRAY
'''
def main():
	from sys import stdin,stdout
	n,t=map(int,stdin.readline().split())
	arr=list(map(int,stdin.readline().split()))
	maxim=0
	curr_sum=arr[0]
	i=0
	j=1
	if curr_sum <=t:
		count=1
	else:
		curr_sum=0
		count=0
		i=1
		j=2
	while j<n:
		if curr_sum+arr[j]<=t:
			count+=1
			curr_sum+=arr[j]
			j+=1
		else:
			maxim=max(count,maxim)
			if curr_sum:
				curr_sum-=arr[i]
				count-=1
			else:
				j+=1
			i+=1
	maxim=max(count,maxim)
	stdout.write(str(maxim))
if __name__=='__main__':
	main()
'''
#469B
'''
def main():
	from sys import stdin,stdout
	p,q,l,r=map(int,stdin.readline().split())
	a=[]
	b=[]
	visited=list(0 for x in range(r-l+1))
	#print(visited)
	for i in range(p):
		x,y=map(int,stdin.readline().split())
		a.append(x)
		b.append(y)
	for i in range(q):
		x,y=map(int,stdin.readline().split())
		x+=l
		y+=l
		for j in range(p):
			#print('x=',x,'y=',y)
			lower=max(0,a[j]-y)
			upper=min(b[j]-x,r)+1
			if upper > lower:
				delta=upper-lower
				#print('upper=',upper,'lower=',lower)
				visited[lower:upper]=list(1 for x in range(delta))
				#print('visited:\n',visited)
	#	print(visited)
	stdout.write(str(visited[:r-l+1].count(1)))
if __name__=='__main__':
	main()
'''
'''
def main():
	from sys import stdin,stdout
	#import numpy as np
	n,k=map(int,stdin.readline().split())
	a=tuple(map(int,stdin.readline().split()))
	minim=min(a)
	maxim=max(a)
	arr=list(a)
	for i in range(n):
		arr[i]-=minim
	if max(arr) > k:
		stdout.write('NO')
	else:
		stdout.write('YES\n')
		for i in a:
			stdout.write('1 '*minim)
			for j in range(i-minim):
				stdout.write(str(j%k+1)+' ')
			stdout.write('\n')
if __name__=='__main__':
	main()
'''
'''
def main():
	from sys import stdin,stdout
	n,p=[],[]
	for _ in range(int(stdin.readline())):
		last=int(stdin.readline())
		if last<0:
			n.append(-1*last)
		else:
			p.append(last)
	if sum(p)>sum(n):
		stdout.write('first')
	elif sum(n)>sum(p):
		stdout.write('second')
	else:
		maxim=max(n,p)
		#print(maxim)
		if maxim==p:
			if maxim==n:
				if last<0:
					stdout.write('second')
				else:
					stdout.write('first')
			else:
				stdout.write('first')
		else:
			stdout.write('second')

if __name__=='__main__':
	main()
'''
#286C
'''
def main():
	from sys import stdin,stdout
	m,n=map(int,stdin.readline().split())
	minim=min(m,n)
	stdout.write(str(minim+1)+'\n')
	if n==minim:
		for i in range(minim+1):
			stdout.write(str(m)+' '+str(i)+'\n')
			m-=1
	else:
		for i in range(minim+1):
			stdout.write(str(i)+' '+str(n)+'\n')
			n-=1
if __name__=='__main__':
	main()
'''
#387B
'''
def main():
	from sys import stdin,stdout
	n,m=map(int,stdin.readline().split())
	a=tuple(map(int,stdin.readline().split()))
	b=tuple(map(int,stdin.readline().split()))
	i=0
	j=0
	while True:
		#print(i,j)
		if i>=n or j>=m:
			break
		if b[j]>=a[i]:
			i+=1
			j+=1
		else:
			j+=1
	stdout.write(str(n-i))
if __name__=='__main__':
	main()
'''
#365B
'''
def main():
	from sys import stdin,stdout
	n=int(stdin.readline())
	a=tuple(map(int,stdin.readline().split()))
	maxim=2
	count=2
	i=2
	while True:
		if i>=n:
			break
		if a[i]==a[i-1]+a[i-2]:
			count+=1
			maxim=max(count,maxim)
		else:
			count=2
		i+=1
	stdout.write(str(min(maxim,n)))
if __name__=='__main__':
	main()
'''	#474D
'''
def main():
	from sys import stdin,stdout
	MOD=int(1e9)+7
	T,k=map(int,stdin.readline().split())
	fib=[x for x in range(1,k+1)]
	for i in range(k,100001):
		fib.append((fib[i-1]+fib[i-k]+1)%MOD)
	for _ in range(T):
		a,b=map(int,stdin.readline().split())
		stdout.write(str((fib[b]-fib[a-1])%MOD)+'\n')
if __name__=='__main__':
	main()
'''
#330B
#not working
'''
def main():
	from sys import stdin,stdout
	import collections
	road_not=collections.defaultdict(set)
	n,m=map(int,stdin.readline().split())
	for _ in range(m):
		a,b=map(int,stdin.readline().split())
		road_not[a].add(b)
		road_not[b].add(a)
	counter=0
	road=collections.defaultdict(set)
	visited=[0 for x in range(n)]
	visited[0]=True
	for index in range(1,n+1):
		for i in range(1,n+1):
			if not visited[i-1]:
				if i not in road_not[index] and i!=index:
					counter+=1
					road[index].add(i)
					visited[i-1]=True
	stdout.write(str(counter)+'\n')
	for i in road:
		for j in road[i]:
			stdout.write(str(i)+' '+str(j)+'\n')
if __name__=='__main__':
	main()
'''
#208D
def main():
	from sys import stdin,stdout
	import bisect
	n=int(stdin.readline())
	p=tuple(map(int,stdin.readline().split()))
	P=tuple(map(int,stdin.readline().split()))
	record=[0 for x in range(5)]
	points=0
	for i in p:
		points+=i
		while points>=P[0]:
			index=bisect.bisect_right(P,points)
			if index:
				index-=1
				number=points//P[index]
				record[index]+=number
				points-=P[index]*number
	for i in record:
		stdout.write(str(i)+' ')
	stdout.write('\n'+str(points))
if __name__=='__main__':
	main()

Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After a participant earns a certain number of points, he can come to the prize distribution center and exchange the points for prizes. When somebody takes a prize, the prize's cost is simply subtracted from the number of his points.Vasya didn't only bought the bars, he also kept a record of how many points each wrapping cost. Also, he remembers that he always stucks to the greedy strategy — as soon as he could take at least one prize, he went to the prize distribution centre and exchanged the points for prizes. Moreover, if he could choose between multiple prizes, he chose the most expensive one. If after an exchange Vasya had enough points left to get at least one more prize, then he continued to exchange points.The sweepstake has the following prizes (the prizes are sorted by increasing of their cost):   a mug (costs a points),  a towel (costs b points),  a bag (costs c points),  a bicycle (costs d points),  a car (costs e points). Now Vasya wants to recollect what prizes he has received. You know sequence p1,p2,...,pn, where pi is the number of points Vasya got for the i-th bar. The sequence of points is given in the chronological order. You also know numbers a, b, c, d, e. Your task is to find, how many prizes Vasya received, what prizes they are and how many points he's got left after all operations are completed.


n, x, y = [int(i) for i in input().split()]

minSum = n

if minSum > y:
    print(-1)

else:
    extra = y-(n-1)
    if minSum-1+extra*extra < x:
        print(-1)

    else:
        print(extra)
        for i in range(n-1):
            print(1)

ch=input()
l=ch.split( )
y=int(l[2])
n=int(l[0])
x=int(l[1])
diff=y-n+1
if diff <=0 :
    print(-1)
else:

 l=[]
 l.append(diff)
 for i in range(n-1):
    l.append(1)
 def check(t):
    sd=0
    ss=0
    for e in t:
        ss+=e
        sd+=e**2
    if sd>=x:
        if ss<=y:
            return True
    else :
        return False

 test=check(l)
 if test :
    for s in range(n):
        print(l[s])
 else :
    print(-1)

Little Petya loves inequations. Help him find n positive integers a1,a2,...,an, such that the following two conditions are satisfied: a1^2+a2^2+...+an^2≥x a1+a2+...+an≤y


class Home:
	def __init__(self,x,a):
		self.x=x
		self.a=a
		self.l=x-a/2
		self.r=x+a/2

n,t=map(int,input().split(' '))
v=[]
for c in range(n):
	x,a=map(int,input().split(' '))
	v.append(Home(x,a))
d=2
v.sort(key= lambda x:x.x)
for c in range(n-1):
	if(v[c+1].l-v[c].r==t):
		d+=1
	if(v[c+1].l-v[c].r>t):
		d+=2
print(d)

n,t = map(int,input().split())
s = []
for i in range(n):
    x,a = map(int,input().split())
    x1 = x - a/2
    x2 = x + a/2
    s.append([x1,x2])
s.sort()

c = 0
for i in range(n-1):
    if t < s[i+1][0] - s[i][1]:
        c += 2
    if t == s[i+1][0] - s[i][1]:
        c += 1
c += 2
print(c)

A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village.Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?


a=int(input(''))
b=list(map(int,input().split()))
f=0
for i in range(3,a+1):
    if(a%i==0):
        n=a//i
        for j in range(n):
            flag=True
            for il in range(j,a,n):
                if(b[il]==0):
                    flag=False
                    break
            if flag:
                f=1
                break
if f:
    print('YES')
else:
    print('NO')

import sys, os, math

def er(k):
    a = [True for i in range(k + 1)]
    a[0] = a[1] = False
    global p
    p = [2]
    m = 2
    while m < k:
        for i in range(k // m):
            a[(i + 1) * m] = False
        a[m] = True
        i = m + 1
        while (not a[i]) & (i < k): i = i + 1
        if i < k:
            m = i
            p.append(m)
        else:
            m = k + 1

def lucky(string):
    global p
    n = len(string)
    for num in p:
        if (num > n):
            return 0
        elif (n % num == 0):
            for i in range(n // num):
                if sum(list(map(int,string[i::n//num])))==num:
                    return 1

p = [2]
er(100000)
p.insert(2,4)
p.remove(2)
n = map(int, input())
st = input().replace(" ", "")
if lucky(st):
    print("YES")
else:
    print("NO")

There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not.


Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.Each digit is allowed to occur in the number the same number of times it occurs in the set.


n = int(input())
x = 1
for i in range(1, n):
	x = x+i
	if x>n:
		x = x%n

	print(x, end=' ')

n = int(input())
t = 1
res = []
for i in range(1,n):
    t = (t + i) % n
    if t ==0:
        t = n
    res.append(t)
print(*res)

A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to n clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if n=5, then after the third throw the child number 2 has the ball again. Overall, n-1 throws are made, and the game ends.The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.


import time,math,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x))
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
#####################################################################################
mx=10**9+7
def solve():
    n,m=IP()
    li=[set() for i in range(m)]
    for i in range(n):
        s=input()
        for i in range(m):
            li[i].add(s[i])
    prod=1
    for ele in li:
        prod=(prod*len(ele))%mx
    print(prod)

solve()

    #######
   #
  #
 #######   #     #  # ####   # #     #
       #  # #   #  # #   #  # # #   #
      #  ####  #  # ####   ####  # #
######  #   # #### #    # #   #   #

import logging
import copy
import sys

logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

def solve(names):
    m = len(names[0])

    postfix = {}
    for name in names:
        postfix[name[-1:]] = True

    if m == 1:
        return len(postfix)
    newList = list((map(lambda x: x[:-1], names)))

    return len(postfix) * solve(newList)

def main():
    firstLine = input().split()
    firstLine = list(map(int, firstLine))
    inputLines = []
    for i in range(firstLine[0]):
        line = input()
        inputLines.append(line)

    #solve(firstLine)
    print (solve(inputLines) % 1000000007)

def log(*message):
    logging.debug(message)

if __name__ == "__main__":
    main()

One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1≤i<j≤n, 1≤k≤m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (10^9+7).

[{'input': '2 3\nAAB\nBAA\n', 'output': ['4\n']}, {'input': '4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n', 'output': ['216\n']}, {'input': '1 1\nE\n', 'output': ['1\n']}, {'input': '2 2\nNS\nPD\n', 'output': ['4\n']}, {'input': '3 4\nPJKD\nNFJX\nFGFK\n', 'output': ['81\n']}, {'input': '4 5\nSXFMY\nATHLM\nKDDQW\nZWGDS\n', 'output': ['1024\n']}, {'input': '20 14\nJNFKBBBJYZHWQE\nLBOKZCPFNKDBJY\nXKNWGHQHIOXUPF\nDDNRUKVUGHWMXW\nMTIZFNAAFEAPHX\nIXBQOOHEULZYHU\nMRCSREUEOOMUUN\nHJTSQWKUFYZDQU\nGMCMUZCOPRVEIQ\nXBKKGGJECOBLTH\nXXHTLXCNJZJUAF\nVLJRKXXXWMTPKZ\nPTYMNPTBBCWKAD\nQYJGOBUBHMEDYE\nGTKUUVVNKAHTUI\nZNKXYZPCYLBZFP\nQCBLJTRMBDWNNE\nTDOKJOBKEOVNLZ\nFKZUITYAFJOQIM\nUWQNSGLXEEIRWF\n', 'output': ['515139391\n']}, {'input': '5 14\nAQRXUQQNSKZPGC\nDTTKSPFGGVCLPT\nVLZQWWESCHDTAZ\nCOKOWDWDRUOMHP\nXDTRBIZTTCIDGS\n', 'output': ['124999979\n']}, {'input': '9 23\nOILBYKHRGMPENVFNHLSIUOW\nLPJFHTUQUINAALRDGLSQUXR\nLYYJJEBNZATAFQWTDZSPUNZ\nHSJPIQKKWWERJZIEMLCZUKI\nOJYIEYDGPFWRHCMISJCCUEM\nLMGKZVFYIVDRTIHBWPCNUTG\nUBGGNCITVHAIPKXCLTSAULQ\nOWSAWUOXQDBSXXBHTLSXUVD\nUGQTIZQPBGMASRQPVPSFUWK\n', 'output': ['454717784\n']}, {'input': '25 4\nLVKG\nMICU\nZHKW\nLFGG\nOWQO\nLCQG\nLVXU\nOUKB\nLNQX\nZJTO\nOOQX\nLVQP\nMFQB\nMRQV\nOIQH\nOPXX\nXFKU\nFCQB\nZPKH\nLVCH\nNFCU\nOVQW\nOZKU\nLFHX\nLPXO\n', 'output': ['5733\n']}, {'input': '30 10\nUTNTGOKZYJ\nQHOUHNYZVW\nLTVGHJRZVW\nMZHYHOLZYJ\nERYEUEPZYE\nUZDBFTURYJ\nRVSMQTIZGW\nWDJQHMIRYY\nKCORHQPZYE\nRRPLFOZZVY\nJTXMFNNNYJ\nMVTGGOZZVV\nEHAFFNUZVF\nLBRNWJZNYE\nJVMOHTPZYJ\nWTARFJLZVV\nLVJCWOURVW\nLCLQFJYRVV\nQVBVGNJRYF\nNTZGHOLRYE\nMGQKHOUPYJ\nRRSSBXPZYJ\nRYCRGTLZYJ\nJRDEGNKRVW\nRZKFGHYRVG\nMDJBFNIZYG\nMPLWHXIZYE\nSRZMHMURVE\nMTEBBMRZYJ\nJPJIFOLZYM\n', 'output': ['919913906\n']}, {'input': '40 7\nPNTVVER\nPAHTQDR\nRXMJVAS\nVIQNLYC\nILPUSVX\nYJOXQDJ\nSEFODTO\nOTJMREL\nLIQRZGD\nLBJJPOR\nRUTYHQO\nRIWEPBD\nKQUMFIB\nISTRRYH\nXBTOTGK\nRFQODEY\nHDSTZTP\nYCXFAGL\nAREGRFU\nLELZUYU\nGVABDKH\nFJAMMME\nACVULXE\nJHVPJAS\nAAQNMBX\nJJGUCXG\nOQATILQ\nNEOSHJM\nHFLWOFM\nICYEQHY\nFACGLYP\nPLLXJEQ\nDCHXYPB\nAGDDZJJ\nLSQRXTN\nHDQZXIY\nNAHDDWW\nQCMXRQN\nFDUDSZO\nHKBEVTW\n', 'output': ['206575993\n']}, {'input': '2 2\nAA\nBB\n', 'output': ['4\n']}, {'input': '1 10\nAAAAAAAAAA\n', 'output': ['1\n']}, {'input': '2 8\nAAAAAAAA\nBBBBBBBB\n', 'output': ['256\n']}, {'input': '10 10\nAAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\nAAAAAAAAAA\nBBBBBBBBBB\nCCCCCCCCCC\nDDDDDDDDDD\nAAAAAAAAAA\nBBBBBBBBBB\n', 'output': ['1048576\n']}, {'input': '1 20\nAAAAAAAAAAAAAAAAAAAA\n', 'output': ['1\n']}, {'input': '20 1\nA\nB\nC\nD\nE\nF\nG\nA\nB\nC\nD\nE\nF\nG\nA\nB\nC\nD\nE\nF\n', 'output': ['7\n']}, {'input': '5 60\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\nEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n', 'output': ['449874206\n']}, {'input': '50 4\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\nAAAA\nBBBB\nCCCC\nDDDD\nEEEE\nFFFF\nGGGG\nHHHH\nIIII\nJJJJ\n', 'output': ['10000\n']}, {'input': '1 100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n', 'output': ['1\n']}, {'input': '100 1\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\nA\n', 'output': ['1\n']}, {'input': '100 1\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\nA\nB\n', 'output': ['2\n']}, {'input': '100 1\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\n', 'output': ['14\n']}, {'input': '100 1\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\nW\nX\nY\nZ\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nO\nP\nQ\nR\nS\nT\nU\nV\n', 'output': ['26\n']}]


import sys
n,b=input().split()
n=int(n)
b=int(b)
a = list(map(int,input().strip().split()))[:n]
total=0
for i in a:
    total=total+i

final=(b+total)/n
for i in a:
    if final-i<0:
        print(-1)
        sys.exit()
for i in a:
    print("{:.6f}".format(final-i));

a, b = map(int,input().split())
c = list(map(float, input().split()))
d = b
for x in c:d += x
d = d / a
if any(x > d for x in c):print(-1)
else:
	for x in c:print("%.6f" %(d - x))

A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:   there were b milliliters poured in total. That is, the bottle need to be emptied;  after the process is over, the volumes of the drink in the mugs should be equal.


import sys

EPS = sys.float_info.epsilon

LENGTH = 10
matrix = [[] for i in range(LENGTH)]
arr = [0] * 1001

n, a, b = map(int, input().split())
arr = [[0] * b for i in range(a)]
c1 = 3
c2 = 2
arr[0][0] = 1
for j in range(1, b):
    if j % 2 == 0 and c1 <= n:
        arr[0][j] = c1
        c1 += 2
    elif j % 2 == 1 and c2 <= n:
        arr[0][j] = c2
        c2 += 2
for i in range(1, a):
    for j in range(b):
        val = arr[i - 1][j]
        if val % 2 == 0 and c1 <= n:
            arr[i][j] = c1
            c1 += 2
        elif val % 2 == 1 and c2 <= n:
            arr[i][j] = c2
            c2 += 2

if c1 > n and c2 > n:
    for i in range(a):
        for j in range(b):
            print(arr[i][j], end=' ')
        print()
else:
    arr = [[0] * b for i in range(a)]
    c1 = 1
    c2 = 4
    arr[0][0] = 2
    for j in range(1, b):
        if j % 2 == 1 and c1 <= n:
            arr[0][j] = c1
            c1 += 2
        elif j % 2 == 0 and c2 <= n:
            arr[0][j] = c2
            c2 += 2
    for i in range(1, a):
        for j in range(b):
            val = arr[i - 1][j]
            if val % 2 == 0 and c1 <= n:
                arr[i][j] = c1
                c1 += 2
            elif val % 2 == 1 and c2 <= n:
                arr[i][j] = c2
                c2 += 2
    if c1 > n and c2 > n:
        for i in range(a):
            for j in range(b):
                print(arr[i][j], end=' ')
            print()
    else:
        print(-1)

n, a, b = map(int,input().split())
a1 = 1
a2 = 2
if a * b < n:
    print(-1)
else:
    for i in range(a):
        for j in range(b):
            if (i+j)%2:
                if a2 <= n:
                    print (a2,end=' ')
                    a2 += 2
                else:
                    print (0,end= ' ' )
            else:
                if a1 <= n:
                    print (a1,end=' ')
                    a1 += 2
                else:
                    print (0,end= ' ' )
        print()

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 chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hallWe know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.


n, m = map(int, input().split())
matrix_row = []
for i in range(n):
    matrix_row.append(list(input()))

matrix_col = list(zip(*matrix_row))
d_row = []
d_col = []
result = []

#print(matrix_row)
#print(matrix_col)

for i in range(n): #Row i_th
    d = {} #dictionary for this row
    for j in range(m): #column j_th
        letter = matrix_row[i][j]
        if letter in d:
            d[letter] += 1
        else:
            d[letter] = 1
    d_row.append(d)

#print(d_row)

for j in range(m): #Col j_th
    d = {} #dictionary for this row
    for i in range(n): #Row i_th
        letter = matrix_col[j][i]
        if letter in d:
            d[letter] += 1
        else:
            d[letter] = 1
    d_col.append(d)

#print(d_col)

for i in range(n):
    for j in range(m):
        letter = matrix_row[i][j]
        if d_row[i][letter] == 1 and d_col[j][letter] == 1:
            result.append(letter)

print(''.join(result))

def checkRow(i, c):
    cnt = 0
    for j in range(m):
        cnt += (a[i][j] == c)
    return cnt >= 2
def checkCol(j, c):
    cnt = 0
    for i in range(n):
        cnt += (a[i][j] == c)
    return cnt >= 2

n, m = map(int, input().split())
a = []
for i in range(n):
    s = input()
    a.append(s)

Free = [[0] * m for _ in range(n)]
for i in range(n):
    for j in range(m):
        if checkRow(i, a[i][j]) or checkCol(j, a[i][j]):
            Free[i][j] = 1

for i in range(n):
    for j in range(m):
        if Free[i][j] == 0:
            print(a[i][j], end = '')

An African crossword is a rectangular table n×m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.You are suggested to solve an African crossword and print the word encrypted there.

[{'input': '3 3\ncba\nbcd\ncbc\n', 'output': ['abcd']}, {'input': '5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n', 'output': ['codeforces']}, {'input': '4 4\nusah\nusha\nhasu\nsuha\n', 'output': ['ahhasusu']}, {'input': '7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz\n', 'output': ['bcdeghjlmnprsuvwz']}, {'input': '10 10\naaaaaaaaaa\nbccceeeeee\ncdfffffffe\ncdfiiiiile\ncdfjjjjile\ndddddddile\nedfkkkkile\nedddddddde\ngggggggggg\nhhhhhhhhhe\n', 'output': ['b']}, {'input': '15 3\njhg\njkn\njui\nfth\noij\nyuf\nyfb\nugd\nhgd\noih\nhvc\nugg\nyvv\ntdg\nhgf\n', 'output': ['hkniftjfbctd']}, {'input': '17 19\nbmzbmweyydiadtlcoue\ngmdbyfwurpwbpuvhifn\nuapwyndmhtqvkgkbhty\ntszotwflegsjzzszfwt\nzfpnscguemwrczqxyci\nvdqnkypnxnnpmuduhzn\noaquudhavrncwfwujpc\nmiggjmcmkkbnjfeodxk\ngjgwxtrxingiqquhuwq\nhdswxxrxuzzfhkplwun\nfagppcoildagktgdarv\neusjuqfistulgbglwmf\ngzrnyxryetwzhlnfewc\nzmnoozlqatugmdjwgzc\nfabbkoxyjxkatjmpprs\nwkdkobdagwdwxsufees\nrvncbszcepigpbzuzoo\n', 'output': ['lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs']}, {'input': '1 1\na\n', 'output': ['a']}, {'input': '2 2\nzx\nxz\n', 'output': ['zxxz']}, {'input': '1 2\nfg\n', 'output': ['fg']}, {'input': '2 1\nh\nj\n', 'output': ['hj']}, {'input': '1 3\niji\n', 'output': ['j']}, {'input': '3 1\nk\np\nk\n', 'output': ['p']}, {'input': '2 3\nmhw\nbfq\n', 'output': ['mhwbfq']}, {'input': '3 2\nxe\ner\nwb\n', 'output': ['xeerwb']}, {'input': '3 7\nnutuvjg\ntgqutfn\nyfjeiot\n', 'output': ['ntvjggqfnyfjeiot']}, {'input': '5 4\nuzvs\namfz\nwypl\nxizp\nfhmf\n', 'output': ['uzvsamfzwyplxizphm']}, {'input': '8 9\ntjqrtgrem\nrwjcfuoey\nywrjgpzca\nwabzggojv\najqmmcclh\nozilebskd\nqmgnbmtcq\nwakptzkjr\n', 'output': ['mrjcfuyyrjpzabzvalhozilebskdgnbtpzr']}, {'input': '9 3\njel\njws\ntab\nvyo\nkgm\npls\nabq\nbjx\nljt\n', 'output': ['elwtabvyokgmplabqbxlt']}, {'input': '7 6\neklgxi\nxmpzgf\nxvwcmr\nrqssed\nouiqpt\ndueiok\nbbuorv\n', 'output': ['eklgximpzgfvwcmrrqedoiqptdeiokuorv']}, {'input': '14 27\npzoshpvvjdpmwfoeojapmkxjrnk\nitoojpcorxjdxrwyewtmmlhjxhx\ndoyopbwusgsmephixzcilxpskxh\nygpvepeuxjbnezdrnjfwdhjwjka\nrfjlbypoalbtjwrpjxzenmeipfg\nkhjhrtktcnajrnbefhpavxxfnlx\nvwlwumqpfegjgvoezevqsolaqhh\npdrvrtzqsoujqfeitkqgtxwckrl\nxtepjflcxcrfomhqimhimnzfxzg\nwhkfkfvvjwkmwhfgeovwowshyhw\nolchgmhiehumivswgtfyhqfagbp\ntdudrkttpkryvaiepsijuejqvmq\nmuratfqqdbfpefmhjzercortroh\nwxkebkzchupxumfizftgqvuwgau\n', 'output': ['zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva']}, {'input': '1 100\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu\n', 'output': ['g']}, {'input': '2 100\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg\n', 'output': ['rbe']}, {'input': '3 100\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo\n', 'output': ['blkck']}, {'input': '100 1\na\nm\nn\nh\na\nx\nt\na\no\np\nj\nz\nr\nk\nq\nl\nb\nr\no\ni\ny\ni\np\ni\nt\nn\nd\nc\nz\np\nu\nn\nw\ny\ng\ns\nt\nm\nz\ne\nv\ng\ny\nj\nd\nz\ny\na\nn\nx\nk\nd\nq\nn\nv\ng\nk\ni\nk\nf\na\nb\nw\no\nu\nw\nk\nk\nb\nz\nu\ni\nu\nv\ng\nv\nx\ng\np\ni\nz\ns\nv\nq\ns\nb\nw\ne\np\nk\nt\np\nd\nr\ng\nd\nk\nm\nf\nd\n', 'output': ['hlc']}, {'input': '100 2\nhd\ngx\nmz\nbq\nof\nst\nzc\ndg\nth\nba\new\nbw\noc\now\nvh\nqp\nin\neh\npj\nat\nnn\nbr\nij\nco\nlv\nsa\ntb\nbl\nsr\nxa\nbz\nrp\nsz\noi\nec\npw\nhf\njm\nwu\nhq\nra\npv\ntc\ngv\nik\nux\ntz\nbf\nty\ndk\nwo\nor\nza\nkv\nqt\nfa\njy\nbk\nuv\ngk\ncz\nds\nie\noq\nmf\nxn\nql\nxs\nfb\niv\ncj\nkn\nns\nlg\nji\nha\naj\ndg\nfj\nut\nsg\nju\noc\nov\nhe\nnw\nbl\nlp\nbx\nnm\nyq\ncw\nov\nxk\npg\noh\npl\nuo\ngf\nul\n', 'output': ['dvy']}, {'input': '100 3\nruy\nmye\njgp\nscn\nktq\nalx\nmvk\nlpm\nkry\norb\nmpu\nzcv\nlge\nkft\ndzp\ntfb\nhqz\nuur\nhry\nzjx\ncuo\nqqc\ntih\nenj\nvnp\nbwi\nzzh\nhkc\nwdr\nldh\nvel\nizj\nfhb\nqrn\nqpp\nvzs\nlhg\nkee\nlbq\nzhy\nwcl\nyaa\nton\nfly\nkyw\nept\ngwq\ncoe\nopd\neez\nnmx\nnjg\nwhy\nvel\nafq\nnbq\nulx\noxs\nbbo\nyhx\nfmz\nnrg\nnfm\njek\nbeu\ntya\nxgs\nsgg\nnkq\nbbv\nwkd\ntns\nfdt\neox\nobc\neab\nkkj\noub\ngji\nrht\nozv\nysk\nsbt\nflf\npbu\nlxb\npzs\nrzh\ncea\nkmi\nuea\nncc\nzng\nvkn\njhn\njqw\nlqc\nmbt\nlov\ngam\n', 'output': ['tvdiixs']}]


n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n+1):
    if a.count(i)<1:
        ans+=1
print(ans)

import sys
import math

"""k = []
for i in range(5):
    k.append([int(x) for x in (sys.stdin.readline()).split()])

vmax = 0
tt = []
for i in range(5):
    for j in range(i, 5):
        if(i != j):
            k[i][j] = k[j][i] = k[i][j] + k[j][i]

for i in range(5):
    print(k[i])"""

n = int(sys.stdin.readline())
an = [int(x) for x in (sys.stdin.readline()).split()]
k = [0] * (n + 1)

res = 0
for i in an:
    if(i <= n):
        k[i] += 1
    else:
        res += 1

for i in k:
    if(i > 1):
        res += i - 1

print(res)

"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1,a2,...,an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).


#ROUNIAAUDI
num1=int(input())
list1=list(map(int,input().split()))
num2=int(input())
list2=list(map(int,input().split()))
f=[0 for i in range((50*50)+4)]

for i in range(num2):
    for j in range(num1):
        if list2[i]%list1[j]==0:
            #print(list2[i],list1[j],end=" ")
            f.append(int(list2[i]//list1[j]))
print(f.count(max(f)))

import math
m = int(input())
l1 = list(map(int,input().split()))
n = int(input())
l2 = list(map(int,input().split()))
x = []

for i in range(n):
    for j in range(m):
        z = l2[i]/l1[j]
        if(z==math.ceil(z)):
            x.append(z)

t = max(x)

count = 0
for i in x:
    if(i == t):
        count+=1
print(count)

Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.We know that the i-th star on the pedal axle has ai (0<a1<a2<...<an) teeth, and the j-th star on the rear wheel axle has bj (0<b1<b2<...<bm) teeth. Any pair (i,j) (1≤i≤n; 1≤j≤m) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (i,j) has a gear ratio, equal to the value .Since Vasya likes integers, he wants to find such gears (i,j), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (i,j) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.In the problem, fraction  denotes division in real numbers, that is, no rounding is performed.


encabezado = input()
carta = input()

retorno = True
letras = {}
for k in encabezado:
    if k == ' ':
        continue
    elif k in letras:
        letras[k] = letras[k] + 1
    elif k not in letras:
        letras.update({k:1})

for k in carta:
    if k == ' ':
        continue
    elif k in letras:
        letras[k] = letras[k] - 1
        if letras[k] == -1:
            retorno = False
            break
    elif k not in letras:
        retorno = False
        break
if retorno:
    b = 'YES'
else:
    b = 'NO'
print(b)

def main():
    s1 = sorted(list(input()))
    s2 = sorted(list(input()))
    st1 = ''
    st2 = ''
    for j in s1:
        if j != ' ':
            st1 += j
        else:
            continue
    for i in s2:
        if i != ' ':
            st2 += i
        else:
            continue
    flag1 = True
    if len(st2) > len(st1):
        flag1 = False
    else:
        di1 = {}
        for char in st1:
            di1[char] = st1.count(char)
        di2 = {}
        for char in st2:
            di2[char] = st2.count(char)
        count = 0
        flag2 = True
        flag3 = True
        for k in di2:
            if k in di1:
                if di1[k] >= di2[k]:
                    count += 1
                else:
                    break
            else:
                flag2 = False
                break
        if count == len(di2):
            flag3 = True
        else:
            flag3 = False

    if flag1 == True and flag2 == True and flag3 == True:
        print("YES")
    else:
        print("NO")

main()

Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.

[{'input': 'Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n', 'output': ['NO\n']}, {'input': 'Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n', 'output': ['YES\n']}, {'input': 'Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n', 'output': ['NO\n']}, {'input': 'abcdefg hijk\nk j i h g f e d c b a\n', 'output': ['YES\n']}, {'input': 'HpOKgo\neAtAVB\n', 'output': ['NO\n']}, {'input': 'GRZGc\nLPzD\n', 'output': ['NO\n']}, {'input': 'GtPXu\nd\n', 'output': ['NO\n']}, {'input': 'FVF\nr \n', 'output': ['NO\n']}, {'input': 'HpOKgo\nogK\n', 'output': ['YES\n']}, {'input': 'GRZGc\nZG\n', 'output': ['YES\n']}, {'input': 'HpOKgoueAtAVBdGffvQheJDejNDHhhwyKJisugiRAH OseK yUwqPPNuThUxTfthqIUeb wS jChGOdFDarNrKRT  MlwKecxWNoKEeD BbiHAruE XMlvKYVsJGPP\nAHN  XvoaNwV  AVBKwKjr u      U K wKE D K   Jy KiHsR h d W  Js IHyMPK Br iSqe  E fDA   g H\n', 'output': ['YES\n']}, {'input': 'GRZGcsLPzDrCSXhhNTaibJqVphhjbcPoZhCDUlzAbDnRWjHvxLKtpGiFWiGbfeDxBwCrdJmJGCGv GebAOinUsFrlqKTILOmxrFjSpEoVGoTdSSstJWVgMLKMPettxHASaQZNdOIObcTxtF qTHWBdNIKwj\nWqrxze Ji x q aT GllLrRV jMpGiMDTwwS JDsPGpAZKACmsFCOS CD Sj  bCDgKF  jJxa RddtLFAi VGLHH SecObzG q  hPF \n', 'output': ['YES\n']}, {'input': 'GtPXuwdAxNhODQbjRslDDKciOALJrCifTjDQurQEBeFUUSZWwCZQPdYwZkYbrduMijFjgodAOrKIuUKwSXageZuOWMIhAMexyLRzFuzuXqBDTEaWMzVdbzhxDGSJC SsIYuYILwpiwwcObEHWpFvHeBkWYNitqYrxqgHReHcKnHbtjcWZuaxPBVPb\nTQIKyqFaewOkY lZUOOuxEw EwuKcArxRQGFYkvVWIAe SuanPeHuDjquurJu aSxwgOSw jYMwjxItNUUArQjO BIujAhSwttLWp\n', 'output': ['YES\n']}, {'input': 'FVFSr unvtXbpKWF vPaAgNaoTqklzVqiGYcUcBIcattzBrRuNSnKUtmdGKbjcE\nUzrU K  an GFGR        Wc zt iBa     P c    T K v p     V In   b           B   c\n', 'output': ['YES\n']}, {'input': 'lSwjnYLYtDNIZjxHiTawdh ntSzggZogcIZTuiTMWVgwyloMtEhqkrOxgIcFvwvsboXUPILPIymFAEXnhApewJXJNtFyZ\nAoxe  jWZ u  yImg  o AZ FNI w lpj  tNhT g y  ZYcb rc J    w Dlv\n', 'output': ['YES\n']}, {'input': 'kvlekcdJqODUKdsJlXkRaileTmdGwUHWWgvgUokQxRzzbpFnswvNKiDnjfOFGvFcnaaiRnBGQmqoPxDHepgYasLhzjDgmvaFfVNEcSPVQCJKAbSyTGpXsAjIHr\nGjzUllNaGGKXUdYmDFpqFAKIwvTpjmqnyswWRTnxlBnavAGvavxJemrjvRJc\n', 'output': ['YES\n']}, {'input': 'kWbvhgvvoYOhwXmgTwOSCDXrtFHhqwvMlCvsuuAUXMmWaYXiqHplFZZemhgkTuvsUtIaUxtyYauBIpjdbyYxjZ ZkaBPzwqPfqF kCqGRmXvWuabnQognnkvdNDtRUsSUvSzgBuxCMBWJifbxWegsknp\nBsH   bWHJD n Ca T xq  PRCv  tatn Wjy sm  I q s WCjFqdWe  t W XUs  Do  eb Pfh ii  hTbF  O Fll\n', 'output': ['YES\n']}, {'input': 'OTmLdkMhmDEOMQMiW ZpzEIjyElHFrNCfFQDp SZyoZaEIUIpyCHfwOUqiSkKtFHggrTBGkqfOxkChPztmPrsHoxVwAdrxbZLKxPXHlMnrkgMgiaHFopiFFiUEtKwCjpJtwdwkbJCgA bxeDIscFdmHQJLAMNhWlrZisQrHQpvbALWTwpf jnx\nDbZwrQbydCdkJMCrftiwtPFfpMiwwrfIrKidEChKECxQUBVUEfFirbGWiLkFQkdJiFtkrtkbIAEXCEDkwLpK\n', 'output': ['YES\n']}, {'input': 'NwcGaIeSkOva\naIa\n', 'output': ['YES\n']}, {'input': 'gSrAcVYgAdbdayzbKGhIzLDjyznLRIJH KyvilAaEddmgkBPCNzpmPNeGEbmmpAyHvUSoPvnaORrPUuafpReEGoDOQsAYnUHYfBqhdcopQfxJuGXgKnbdVMQNhJYkyjiJDKlShqBTtnnDQQzEijOMcYRGMgPGVhfIReYennKBLwDTVvcHMIHMgVpJkvzTrezxqS\nHJerIVvRyfrPgAQMTI AqGNO mQDfDwQHKgeeYmuRmozKHILvehMPOJNMRtPTAfvKvsoGKi xHEeKqDAYmQJPUXRJbIbHrgVOMGMTdvYiLui\n', 'output': ['YES\n']}, {'input': 'ReB hksbHqQXxUgpvoNK bFqmNVCEiOyKdKcAJQRkpeohpfuqZabvrLfmpZOMcfyFBJGZwVMxiUPP pbZZtJjxhEwvrAba\nJTCpQnIViIGIdQtLnmkVzmcbBZR CoxAdTtWSYpbOglDFifqIVQ vfGKGtLpxpJHiHSWCMeRcrVOXBGBhoEnVhNTPWGTOErNtSvokcGdgZXbgTEtISUyTwaXUEIlJMmutsdCbiyrPZPJyRdOjnSuAGttLy\n', 'output': ['NO\n']}, {'input': 'hrLzRegCuDGxTrhDgVvM KowwyYuXGzIpcXdSMgeQVfVOtJZdkhNYSegwFWWoPqcZoeapbQnyCtojgkcyezUNHGGIZrhzsKrvvcrtokIdcnqXXkCNKjrOjrnEAKBNxyDdiMVeyLvXxUYMZQRFdlcdlcxzKTeYzBlmpNiwWbNAAhWkMoGpRxkCuyqkzXdKWwGH\nJESKDOfnFdxPvUOCkrgSBEPQHJtJHzuNGstRbTCcchRWJvCcveSEAtwtOmZZiW\n', 'output': ['NO\n']}, {'input': 'yDBxCtUygQwWqONxQCcuAvVCkMGlqgC zvkfEkwqbhMCQxnkwQIUhucCbVUyOBUcXvTNEGriTBwMDMfdsPZgWRgIUDqM\neptVnORTTyixxmWIBpSTEwOXqGZllBgSxPenYCDlFwckJlWsoVwWLAIbPOmFqcKcTcoQqahetl KLfVSyaLVebzsGwPSVbtQAeUdZAaJtfxlCEvvaRhLlVvRJhKat IaB awdqcDlrrhTbRxjEbzGwcdmdavkhcjHjzmwbxAgw\n', 'output': ['NO\n']}, {'input': 'jlMwnnotSdlQMluKWkJwAeCetcqbIEnKeNyLWoKCGONDRBQOjbkGpUvDlmSFUJ bWhohqmmIUWTlDsvelUArAcZJBipMDwUvRfBsYzMdQnPDPAuBaeJmAxVKwUMJrwMDxNtlrtAowVWqWiwFGtmquZAcrpFsLHCrvMSMMlvQUqypAihQWrFMNoaqfs IBg\nNzeWQ bafrmDsYlpNHSGTBBgPl WIcuNhyNaNOEFvL\n', 'output': ['NO\n']}, {'input': 'zyWvXBcUZqGqjHwZHQryBtFliLYnweXAoMKNpLaunaOlzaauWmLtywsEvWPiwxJapocAFRMjrqWJXYqfKEbBKnzLO\npsbi bsXpSeJaCkIuPWfSRADXdIClxcDCowwJzGCDTyAl\n', 'output': ['NO\n']}, {'input': 'kKhuIwRPLCwPFfcnsyCfBdnsraGeOCcLTfXuGjqFSGPSAeDZJSS bXKFanNqWjpFnvRpWxHJspvisDlADJBioxXNbVoXeUedoPcNEpUyEeYxdJXhGzFAmpAiHotSVwbZQsuWjIVhVaEGgqbZHIoDpiEmjTtFylCwCkWWzUOoUfOHxEZvDwNpXhBWamHn\nK VpJjGhNbwCRhcfmNGVjewBFpEmPlIKeTuWiukDtEWpjgqciqglkyNfWrBLbGAKvlNWxaUelJmSlSoakSpRzePvJsshOsTYrMPXdxKpaShjyVIXGhRIAdtiGpNwtiRmGTBZhkJqIMdxMHX RMxCMYcWjcjhtCHyFnCvjjezGbkRDRiVxkbh\n', 'output': ['NO\n']}, {'input': 'AXssNpFKyQmJcBdBdfkhhMUzfqJVgcLBddkwtnFSzSRUCjiDcdtmkzIGkCKSxWUEGhmHmciktJyGMkgCductyHx\nI nYhmJfPnvoKUiXYUBIPIcxNYTtvwPUoXERZvY ahlDpQFNMmVZqEBiYqYlHNqcpSCmhFczBlOAhsYFeqMGfqL EJsDNOgwoJfBzqijKOFcYQ\n', 'output': ['NO\n']}, {'input': 'lkhrzDZmkdbjzYKPNMRkiwCFoZsMzBQMnxxdKKVJezSBjnLjPpUYtabcPTIaDJeDEobbWHdKOdVfMQwDXzDDcSrwVenDEYpMqfiOQ xSsqApWnAMoyhQXCKFzHvvzvUvkWwmwZrvZz\nsUzGspYpRFsHRbRgTQuCBgnFgPkisTUfFNwyEEWWRiweWWgjRkVQxgTwxOzdsOwfrGIH O gCXpzvHzfItuEHaihmugEyymSJIogYwX qAwcwIItidfnzZDhZgQHi eRjMAeVkJHceDZuJkmxGowOsmcGYYvk Ajtgi TxwihvjLViNZjvscTWvsaQUelTSivLShhEl\n', 'output': ['NO\n']}, {'input': 'BRsVjyNhrqRHVwrJzuzRigEhdpbDmaACSPfed\nlWqKTjlrqOCUbgBBZdZDGCeQJDXawPnnDkQdZDgwrEQk\n', 'output': ['NO\n']}, {'input': 'KRmINuyBYPwiTsdlyiNVuylToysJKmOpcLovAtwGPqrgFJQNAYvuAiyQRkeFMECVZvkDEmTauXlyjAaYRnTJXORMZRnTakBaUzSelMilejySDIZjQjzcOIrwXdvDvpeRIkoBgreyFXIyyIZutjiEBtwrmzQtPVUhvvdEtDMbXjBpoPVjGdM EXTAK JbCnw\nXZZqlJvzKKtvdNlzFPDTYxidqlsgufVzyEmO FZuLQ vVQsJESNviUCovCK NwwlbxsmPtOJNmAonCqrOZ bZ LVKAsQGmoLnYjeekvEIECFk\n', 'output': ['NO\n']}]


#include<stdio.h>
#include<stdlib.h>
int cmp(const void*x,const void*y){
    return *(int*)x - *(int*)y ;
}
int main(){
    int n,t,i,a,c=0,d,e,f,b;
    int s[100];
    scanf("%d",&n);

    for(i=0;i<n-1;i++){
        scanf("%d",&s[i]);
    }
   // qsort(s,n-1,sizeof(int),cmp);

    scanf("%d %d",&a,&b);
    f=b-a;
    for(i=0;i<f;i++){
        c=c+s[a-1];
        a=a+1;
    }

    printf("%d\n",c);

    return 0;
    }

#include<stdio.h>
#include<math.h>
int main()
{
	int a[9999],i,j,k,n,sum=0;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	scanf("%d%d",&j,&k);
	for(i=j;i<(k);i++)
	{
		sum+=a[i];
	}
	printf("%d",sum);

		return 0;
}

The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank i+1. Reaching a certain rank i having not reached all the previous i-1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream.


The Little Elephant loves to play with color cards.He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny.


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>

#define PI 3.141592653589793
#define max(a,b) (a < b) ? (b) : (a)
#define min(a,b) (a > b) ? (b) : (a)
#define FOR(i,a,b) for(i = a ; i <= b ; i++)
#define ROF(i,a,b) for(i = a ; i >= b ; i--)
#define RAD(x) ((x)*PI)/180
#define y1 y_1
#define endl printf("\n")
#define MAX 1005

int n, m, i, j, k, x, y, sum, parca, mat[MAX][MAX], h1[MAX], h2[MAX], h[MAX];

int dfs (int);

int main () {
	scanf("%d %d", &n, &m);
	FOR(i, 1, m){
		scanf("%d %d", &x, &y);
		mat[x][y] = mat[y][x] = 1;
	}
	FOR(i, 1, n)
		if(!h[i]){
			dfs(i);
			parca++;
		}
	FOR(i, 1, n){
		FOR(j, 1, n){
			if(mat[i][j])
				h1[i]++;
			if(mat[j][i])
				h2[j]++;
		}
	}
	FOR(k, 1, 10005)
		FOR(j, 1, n)
		if(h1[j] == 1 && h2[j] == 1)
			FOR(i, 1, n)
				if(mat[i][j]){
					h1[j] = 0;
					h2[j] = 0;
					h1[i]--;
					h2[i]--;
					mat[i][j] = 0;
					mat[j][i] = 0;
				}
	FOR(i, 1, n){
		if(h1[i] > 2 || h2[i] > 2){
			printf("NO");
			return 0;
		}
	}
	FOR(i, 1, n)
		sum += h1[i] + h2[i];
	if(sum && parca == 1)
		printf("FHTAGN!");
	else
		printf("NO");
	return 0;
}

int dfs (int x){
	int i;
	if(h[x])
		return;
	h[x] = 1;
	FOR(i, 1, n)
		if(mat[i][x])
			dfs(i);
}

#include <stdio.h>
#include <string.h>
int main(){
	/*
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	*/
	int i, j, n, m, a, b;
	scanf("%d%d", &n, &m);
	int M[n][n];
	for( i=0;i<n;i++ )
		for( j=0;j<n;j++ )
			M[i][j]=0;
	for( i=0;i<m;i++ ){
		scanf("%d%d", &a, &b);
		M[a-1][b-1]=M[b-1][a-1]=1;
	}

	int Pila[n*n], tope=0, marca[n], aux, conexo=1;
	Pila[0]=0;memset(marca, 0, sizeof marca);
	while( tope>=0 ){
		aux=Pila[tope--];
		if( marca[aux]==0 ){
			marca[aux]=1;
			for( i=0;i<n;i++ ){
				if( i!=aux && M[i][aux] )
					Pila[++tope]=i;
			}
		}
	}
	for(i=0;i<n;i++) if( !marca[i] ) conexo=0;
	if( n==m && conexo ) printf("FHTAGN!\n");
	else printf("NO\n");
	return 0;
}

...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with n vertices and m edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.It is guaranteed that the graph contains no multiple edges and self-loops.