I found an interesting problem on https://codeforces.com/problemset/problem/1057/B:
We get more and more news about DDoS-attacks of popular websites.

Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds $100 \cdot t$, where $t$ — the number of seconds in this time segment.

Arseny knows statistics on the number of requests per second since the server is booted. He knows the sequence $r_1, r_2, \dots, r_n$, where $r_i$ — the number of requests in the $i$-th second after boot.

Determine the length of the longest continuous period of time, which Arseny considers to be a DDoS-attack. A seeking time period should not go beyond the boundaries of the segment $[1, n]$.

-----Input-----

The first line contains $n$ ($1 \le n \le 5000$) — number of seconds since server has been booted. The second line contains sequence of integers $r_1, r_2, \dots, r_n$ ($0 \le r_i \le 5000$), $r_i$ — number of requests in the $i$-th second.

-----Output-----

Print the only integer number — the length of the longest time period which is considered to be a DDoS-attack by Arseny. If it doesn't exist print 0.

-----Examples-----
Input
5
100 200 1 1 1

Output
3

Input
5
1 2 3 4 5

Output
0

Input
2
101 99

Output
1

I tried it in Python, but could not do it. Can you solve it?

n = int(input())
a=[int(x) for x in input().split()]
pref = [0]*n
pref[0] = a[0]
for i in range(1, n):
    pref[i] = a[i]+pref[i-1]
ans = 0
for t in range(n, 0, -1):
    for i in range(n-t+1):
        s = pref[i+t-1]
        if i > 0:
            s-=pref[i-1]
        if s > 100*t:
            ans = max(ans,t)
print(ans)


I found an interesting problem on https://codeforces.com/problemset/problem/1057/C:
There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is equal to $c_i$).

Initially, Tanya is next to the box number $s$. Tanya can move to the neighbor box (that is, with a number that differs by one) or eat candies in the current box. Tanya eats candies instantly, but the movement takes one second.

If Tanya eats candies from the box, then the box itself remains in place, but there is no more candies in it. In other words, Tanya always eats all the candies from the box and candies in the boxes are not refilled.

It is known that Tanya cannot eat candies of the same color one after another (that is, the colors of candies in two consecutive boxes from which she eats candies are always different). In addition, Tanya's appetite is constantly growing, so in each next box from which she eats candies, there should be strictly more candies than in the previous one.

Note that for the first box from which Tanya will eat candies, there are no restrictions on the color and number of candies.

Tanya wants to eat at least $k$ candies. What is the minimum number of seconds she will need? Remember that she eats candies instantly, and time is spent only on movements.

-----Input-----

The first line contains three integers $n$, $s$ and $k$ ($1 \le n \le 50$, $1 \le s \le n$, $1 \le k \le 2000$) — number of the boxes, initial position of Tanya and lower bound on number of candies to eat. The following line contains $n$ integers $r_i$ ($1 \le r_i \le 50$) — numbers of candies in the boxes. The third line contains sequence of $n$ letters 'R', 'G' and 'B', meaning the colors of candies in the correspondent boxes ('R' for red, 'G' for green, 'B' for blue). Recall that each box contains candies of only one color. The third line contains no...

I tried it in Python, but could not do it. Can you solve it?

INF = 10e9
n,s,k = list(map(int, input().split()))
r = list(map(int, input().split()))
r.append(0)
col = input()
mat = []
for i in range(n+1):
    adj = {}
    for j in range(n):
        if i == n:
            adj[j] = abs((s-1)-j)
        else:
            if col[i] != col[j] and r[i] < r[j]:
                adj[j] = abs(i-j)
    mat.append(adj)
# print(*mat, sep='\n')

mem = [{} for i in range(n+1)]
# print(mem)

def get(s, k):
    # print(s,k)
    # print(mem)
    if mem[s].get(k):
        return mem[s].get(k)
    if r[s] >= k:
        mem[s][k] = 0
    else:
        mi = None
        for nei in mat[s]:
            ncost = get(nei, k-r[s])
            if ncost is None:
                continue
            curr = ncost + mat[s][nei]
            if mi is None or curr < mi:
                mi = curr
        if mi is not None:
            mem[s][k] = mi
        else:
            mem[s][k] = INF
    return mem[s].get(k)

# print(mem)

ans = get(n,k)
if ans is None or ans >= INF:
    print(-1)
else:
    print(ans)


I found an interesting problem on https://codeforces.com/problemset/problem/1059/A:
Vasya has recently got a job as a cashier at a local store. His day at work is $L$ minutes long. Vasya has already memorized $n$ regular customers, the $i$-th of which comes after $t_{i}$ minutes after the beginning of the day, and his service consumes $l_{i}$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer.

Vasya is a bit lazy, so he likes taking smoke breaks for $a$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?

-----Input-----

The first line contains three integers $n$, $L$ and $a$ ($0 \le n \le 10^{5}$, $1 \le L \le 10^{9}$, $1 \le a \le L$).

The $i$-th of the next $n$ lines contains two integers $t_{i}$ and $l_{i}$ ($0 \le t_{i} \le L - 1$, $1 \le l_{i} \le L$). It is guaranteed that $t_{i} + l_{i} \le t_{i + 1}$ and $t_{n} + l_{n} \le L$.

-----Output-----

Output one integer  — the maximum number of breaks.

-----Examples-----
Input
2 11 3
0 1
1 1

Output
3
Input
0 5 2

Output
2
Input
1 3 2
1 2

Output
0

-----Note-----

In the first sample Vasya can take $3$ breaks starting after $2$, $5$ and $8$ minutes after the beginning of the day.

In the second sample Vasya can take $2$ breaks starting after $0$ and $2$ minutes after the beginning of the day.

In the third sample Vasya can't take any breaks.

I tried it in Python, but could not do it. Can you solve it?

n, l ,a = map(int, input().split())
T = 0
k = 0
for i in range(n):
    t, li = map(int, input().split())
    k += (t - T) // a
    T = t + li
k += (l - T) // a
print(k)


I found an interesting problem on https://codeforces.com/problemset/problem/1059/B:
Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?

For simplicity, the signature is represented as an $n\times m$ grid, where every cell is either filled with ink or empty. Andrey's pen can fill a $3\times3$ square without its central cell if it is completely contained inside the grid, as shown below.

xxx

x.x

xxx

Determine whether is it possible to forge the signature on an empty $n\times m$ grid.

-----Input-----

The first line of input contains two integers $n$ and $m$ ($3 \le n, m \le 1000$).

Then $n$ lines follow, each contains $m$ characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.

-----Output-----

If Andrey can forge the signature, output "YES". Otherwise output "NO".

You can print each letter in any case (upper or lower).

-----Examples-----
Input
3 3
###
#.#
###

Output
YES
Input
3 3
###
###
###

Output
NO
Input
4 3
###
###
###
###

Output
YES
Input
5 7
.......
.#####.
.#.#.#.
.#####.
.......

Output
YES

-----Note-----

In the first sample Andrey can paint the border of the square with the center in $(2, 2)$.

In the second sample the signature is impossible to forge.

In the third sample Andrey can paint the borders of the squares with the centers in $(2, 2)$ and $(3, 2)$:   we have a clear paper:

...

...

...

...

  use the pen with center at $(2, 2)$.

###

#.#

###

...

  use the pen with center at $(3, 2)$.

###

###

###

###

In the fourth sample Andrey can paint the borders of the squares with the centers in $(3, 3)$ and $(3, 5)$.

I tried it in Python, but could not do it. Can you solve it?

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

def is_squad(x, y):
  if cl[x][y]=='#' and cl[x+1][y]=='#' and cl[x+2][y]=='#' and cl[x+2][y+1]=='#' and cl[x+2][y+2]=='#' and cl[x+1][y+2]=='#' and cl[x][y+2]=='#' and cl[x][y+1]=='#':
    return True
  else:
    return False

def cv(x, y):
  counter = 0
  if x-2>=0 and y+2<=m-1 and is_squad(x-2, y):
    return True

  elif x-1>=0 and x+1<=n-1 and y+2<=m-1 and is_squad(x-1, y):
    return True

  elif x+2<=n-1 and y+2<=m-1 and is_squad(x, y):
    return True

  elif x+2<=n-1 and y+1<=m-1 and y-1>=0 and is_squad(x, y-1):
    return True

  elif x+2<=n-1 and y-2>=0 and is_squad(x, y-2):
    return True

  elif x+1<=n-1 and x-1>=0 and y-2>=0 and is_squad(x-1, y-2):
    return True

  elif x-2>=0 and y-2>=0 and is_squad(x-2, y-2):
    return True

  elif x-2>=0 and y-1>=0 and y+1<=m-1 and is_squad(x-2, y-1):
    return True
  else:
    return False

for i in range(n):
  for j in range(m):
    if cl[i][j]=='#':
      if not cv(i, j):
        print('NO')
        return

print('YES')


I found an interesting problem on https://codeforces.com/problemset/problem/1059/C:
Let's call the following process a transformation of a sequence of length $n$.

If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a sequence of $n$ integers: the greatest common divisors of all the elements in the sequence before each deletion.

You are given an integer sequence $1, 2, \dots, n$. Find the lexicographically maximum result of its transformation.

A sequence $a_1, a_2, \ldots, a_n$ is lexicographically larger than a sequence $b_1, b_2, \ldots, b_n$, if there is an index $i$ such that $a_j = b_j$ for all $j < i$, and $a_i > b_i$.

-----Input-----

The first and only line of input contains one integer $n$ ($1\le n\le 10^6$).

-----Output-----

Output $n$ integers  — the lexicographically maximum result of the transformation.

-----Examples-----
Input
3

Output
1 1 3
Input
2

Output
1 2
Input
1

Output
1

-----Note-----

In the first sample the answer may be achieved this way:  Append GCD$(1, 2, 3) = 1$, remove $2$.  Append GCD$(1, 3) = 1$, remove $1$.  Append GCD$(3) = 3$, remove $3$.

We get the sequence $[1, 1, 3]$ as the result.

I tried it in Python, but could not do it. Can you solve it?

"""n,L,a=map(int,input().split())
#s=[int(x) for x in input().split()]
ed=0
ct=0
for j in range(0,n):
    t,l=map(int,input().split())
    ct=ct+((t-ed)//a)
    ed=t+l
t=L
ct=ct+((t-ed)//a)
print(ct)"""

"""n,m=map(int,input().split())
dp=[[-1 for i in range(m)] for j in range(n)]
dp2=[[-1 for i in range(m)] for j in range(n)]
#dp=[]
#dp2=[]
for i in range(0,n):
    s=input()
    for j in range(0,m):
        if(s[j]=='.'):
            dp[i][j]=-1
        else:
            dp[i][j]=s[j]
for i in range(0,n-2):
    for j in range(0,m-2):
        #print(i,j)
        p=0
        c=0
        for k in range(i,i+3):
            for h in range(j,j+3):
                p=p+1
                if(p!=5):
                    if(dp[k][h]=='#'):
                        c=c+1

        if(c==8):
            p=0
            for k in range(i,i+3):
                for h in range(j,j+3):7
                    p=p+1
                    if(p!=5):
                        dp2[k][h]='#'

#print(dp)
#print(dp2)
if(dp==dp2):
    print('YES')
else:
    print('NO')"""

import math
n=int(input())
if(n==3):
    print('1 1 3')

else:
    t=1
    while(t<=n):
        ct=math.ceil((n//t)/2)
        for i in range(0,ct):
            print(t,end=" ")
        #t=t*2
        if(ct==2 and (n//t)%2!=0):
            t=t*3
        else:
            t=t*2
    print(" ")


I found an interesting problem on https://codeforces.com/problemset/problem/1059/D:
There is a forest that we model as a plane and live $n$ rare animals. Animal number $i$ has its lair in the point $(x_{i}, y_{i})$. In order to protect them, a decision to build a nature reserve has been made.

The reserve must have a form of a circle containing all lairs. There is also a straight river flowing through the forest. All animals drink from this river, therefore it must have at least one common point with the reserve. On the other hand, ships constantly sail along the river, so the reserve must not have more than one common point with the river.

For convenience, scientists have made a transformation of coordinates so that the river is defined by $y = 0$. Check whether it is possible to build a reserve, and if possible, find the minimum possible radius of such a reserve.

-----Input-----

The first line contains one integer $n$ ($1 \le n \le 10^5$) — the number of animals.

Each of the next $n$ lines contains two integers $x_{i}$, $y_{i}$ ($-10^7 \le x_{i}, y_{i} \le 10^7$) — the coordinates of the $i$-th animal's lair. It is guaranteed that $y_{i} \neq 0$. No two lairs coincide.

-----Output-----

If the reserve cannot be built, print $-1$. Otherwise print the minimum radius. Your answer will be accepted if absolute or relative error does not exceed $10^{-6}$.

Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is considered correct if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$.

-----Examples-----
Input
1
0 1

Output
0.5
Input
3
0 1
0 2
0 -3

Output
-1

Input
2
0 1
1 1

Output
0.625

-----Note-----

In the first sample it is optimal to build the reserve with the radius equal to $0.5$ and the center in $(0,\ 0.5)$.

In the second sample it is impossible to build a reserve.

In the third sample it is optimal to build the reserve with the radius equal to $\frac{5}{8}$ and the center in $(\frac{1}{2},\ \frac{5}{8})$.

I tried it in Python, but could not do it. Can you solve it?

import sys
input = sys.stdin.readline

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

def get(x0, a, n):
    r = 0
    for i in range(n):
        p = (x0 - a[i].x)*(x0 - a[i].x) + 1.0*a[i].y*a[i].y
        p = p/2.0/a[i].y
        if p < 0:
            p = -p
        r = max(r, p)
    return r

def main():
    n = int(input())
    pos, neg = False, False
    a = []
    for i in range(n):
        x, y = map(int, input().split())
        t = Point(x, y)
        if t.y > 0:
            pos = True
        else:
            neg = True
        a.append(t)
    if pos and neg:
        return -1
    if neg:
        for i in range(n):
            a[i].y = -a[i].y
    L, R = -1e8, 1e8
    for i in range(120):
        x1 = L + (R-L)/3
        x2 = R - (R-L)/3
        if get(x1, a, n) < get(x2, a, n):
            R = x2
        else:
            L = x1
    return get(L, a, n)

def __starting_point():
    print(main())
__starting_point()


I found an interesting problem on https://codeforces.com/problemset/problem/1059/E:
You are given a rooted tree on $n$ vertices, its root is the vertex number $1$. The $i$-th vertex contains a number $w_i$. Split it into the minimum possible number of vertical paths in such a way that each path contains no more than $L$ vertices and the sum of integers $w_i$ on each path does not exceed $S$. Each vertex should belong to exactly one path.

A vertical path is a sequence of vertices $v_1, v_2, \ldots, v_k$ where $v_i$ ($i \ge 2$) is the parent of $v_{i - 1}$.

-----Input-----

The first line contains three integers $n$, $L$, $S$ ($1 \le n \le 10^5$, $1 \le L \le 10^5$, $1 \le S \le 10^{18}$) — the number of vertices, the maximum number of vertices in one path and the maximum sum in one path.

The second line contains $n$ integers $w_1, w_2, \ldots, w_n$ ($1 \le w_i \le 10^9$) — the numbers in the vertices of the tree.

The third line contains $n - 1$ integers $p_2, \ldots, p_n$ ($1 \le p_i < i$), where $p_i$ is the parent of the $i$-th vertex in the tree.

-----Output-----

Output one number  — the minimum number of vertical paths. If it is impossible to split the tree, output $-1$.

-----Examples-----
Input
3 1 3
1 2 3
1 1

Output
3
Input
3 3 6
1 2 3
1 1

Output
2
Input
1 1 10000
10001

Output
-1

-----Note-----

In the first sample the tree is split into $\{1\},\ \{2\},\ \{3\}$.

In the second sample the tree is split into $\{1,\ 2\},\ \{3\}$ or $\{1,\ 3\},\ \{2\}$.

In the third sample it is impossible to split the tree.

I tried it in Python, but could not do it. Can you solve it?

def solve(n, l, s, www, children):
    ans = 0
    dp = [{} for _ in range(n)]
    for v in range(n - 1, -1, -1):
        cv = children[v]
        if not cv:
            dp[v][1] = www[v]
            continue
        ans += len(cv) - 1
        wv = www[v]
        if wv > s:
            return -1
        dv = dp[v]
        for c in cv:
            for lc, wc in dp[c].items():
                if lc == l:
                    continue
                wt = wc + wv
                if wt > s:
                    continue
                if lc + 1 not in dv:
                    dv[lc + 1] = wt
                else:
                    dv[lc + 1] = min(dv[lc + 1], wt)
        if not dv:
            ans += 1
            dv[1] = wv

    return ans + 1

n, l, s = list(map(int, input().split()))
www = list(map(int, input().split()))
if n == 1:
    print(-1 if www[0] > s else 1)
    return
children = [set() for _ in range(n)]
for i, p in enumerate(map(int, input().split())):
    children[p - 1].add(i + 1)
print(solve(n, l, s, www, children))


I found an interesting problem on https://codeforces.com/problemset/problem/1060/A:
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.

For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.

You have $n$ cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.

-----Input-----

The first line contains an integer $n$ — the number of cards with digits that you have ($1 \leq n \leq 100$).

The second line contains a string of $n$ digits (characters "0", "1", ..., "9") $s_1, s_2, \ldots, s_n$. The string will not contain any other characters, such as leading or trailing spaces.

-----Output-----

If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.

-----Examples-----
Input
11
00000000008

Output
1

Input
22
0011223344556677889988

Output
2

Input
11
31415926535

Output
0

-----Note-----

In the first example, one phone number, "8000000000", can be made from these cards.

In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".

In the third example you can't make any phone number from the given cards.

I tried it in Python, but could not do it. Can you solve it?

n=int(input())
r=input()
c=0
for i in r:
	if i=='8':
		c=c+1
print (min(n//11,c))


I found an interesting problem on https://codeforces.com/problemset/problem/1060/B:
You are given a positive integer $n$.

Let $S(x)$ be sum of digits in base 10 representation of $x$, for example, $S(123) = 1 + 2 + 3 = 6$, $S(0) = 0$.

Your task is to find two integers $a, b$, such that $0 \leq a, b \leq n$, $a + b = n$ and $S(a) + S(b)$ is the largest possible among all such pairs.

-----Input-----

The only line of input contains an integer $n$ $(1 \leq n \leq 10^{12})$.

-----Output-----

Print largest $S(a) + S(b)$ among all pairs of integers $a, b$, such that $0 \leq a, b \leq n$ and $a + b = n$.

-----Examples-----
Input
35

Output
17

Input
10000000000

Output
91

-----Note-----

In the first example, you can choose, for example, $a = 17$ and $b = 18$, so that $S(17) + S(18) = 1 + 7 + 1 + 8 = 17$. It can be shown that it is impossible to get a larger answer.

In the second test example, you can choose, for example, $a = 5000000001$ and $b = 4999999999$, with $S(5000000001) + S(4999999999) = 91$. It can be shown that it is impossible to get a larger answer.

I tried it in Python, but could not do it. Can you solve it?


I found an interesting problem on https://codeforces.com/problemset/problem/1060/C:
You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively.

Let $c$ be an $n \times m$ matrix, where $c_{i,j} = a_i \cdot b_j$.

You need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total number of elements) is the largest possible.

Formally, you need to find the largest number $s$ such that it is possible to choose integers $x_1, x_2, y_1, y_2$ subject to $1 \leq x_1 \leq x_2 \leq n$, $1 \leq y_1 \leq y_2 \leq m$, $(x_2 - x_1 + 1) \times (y_2 - y_1 + 1) = s$, and $$\sum_{i=x_1}^{x_2}{\sum_{j=y_1}^{y_2}{c_{i,j}}} \leq x.$$

-----Input-----

The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 2000$).

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 2000$).

The third line contains $m$ integers $b_1, b_2, \ldots, b_m$ ($1 \leq b_i \leq 2000$).

The fourth line contains a single integer $x$ ($1 \leq x \leq 2 \cdot 10^{9}$).

-----Output-----

If it is possible to choose four integers $x_1, x_2, y_1, y_2$ such that $1 \leq x_1 \leq x_2 \leq n$, $1 \leq y_1 \leq y_2 \leq m$, and $\sum_{i=x_1}^{x_2}{\sum_{j=y_1}^{y_2}{c_{i,j}}} \leq x$, output the largest value of $(x_2 - x_1 + 1) \times (y_2 - y_1 + 1)$ among all such quadruplets, otherwise output $0$.

-----Examples-----
Input
3 3
1 2 3
1 2 3
9

Output
4

Input
5 1
5 4 2 4 5
2
5

Output
1

-----Note-----

Matrix from the first sample and the chosen subrectangle (of blue color):

 [Image]

Matrix from the second sample and the chosen subrectangle (of blue color):

 $\left. \begin{array}{l l l l l}{10} & {8} & {4} & {8} & {10} \end{array} \right.$

I tried it in Python, but could not do it. Can you solve it?

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=int(input())
gooda=[10000000]*n
goodb=[10000000]*m
for i in range(n):
    tots=0
    lent=0
    for j in range(i,n):
        tots+=a[j]
        lent+=1
        gooda[lent-1]=min(gooda[lent-1],tots)
for i in range(m):
    tots=0
    lent=0
    for j in range(i,m):
        tots+=b[j]
        lent+=1
        goodb[lent-1]=min(goodb[lent-1],tots)
best=0
aind=0
bind=m-1
while aind<n and bind>=0:
    if gooda[aind]*goodb[bind]<=x:
        best=max(best,(aind+1)*(bind+1))
        aind+=1
    else:
        bind-=1
print(best)


I found an interesting problem on https://codeforces.com/problemset/problem/1060/D:
You invited $n$ guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles.

Your guests happen to be a little bit shy, so the $i$-th guest wants to have a least $l_i$ free chairs to the left of his chair, and at least $r_i$ free chairs to the right. The "left" and "right" directions are chosen assuming all guests are going to be seated towards the center of the circle. Note that when a guest is the only one in his circle, the $l_i$ chairs to his left and $r_i$ chairs to his right may overlap.

What is smallest total number of chairs you have to use?

-----Input-----

First line contains one integer $n$  — number of guests, ($1 \leqslant n \leqslant 10^5$).

Next $n$ lines contain $n$ pairs of space-separated integers $l_i$ and $r_i$ ($0 \leqslant l_i, r_i \leqslant 10^9$).

-----Output-----

Output a single integer — the smallest number of chairs you have to use.

-----Examples-----
Input
3
1 1
1 1
1 1

Output
6

Input
4
1 2
2 1
3 5
5 3

Output
15

Input
1
5 6

Output
7

-----Note-----

In the second sample the only optimal answer is to use two circles: a circle with $5$ chairs accomodating guests $1$ and $2$, and another one with $10$ chairs accomodationg guests $3$ and $4$.

In the third sample, you have only one circle with one person. The guest should have at least five free chairs to his left, and at least six free chairs to his right to the next person, which is in this case the guest herself. So, overall number of chairs should be at least 6+1=7.

I tried it in Python, but could not do it. Can you solve it?

def mainA():
    n = int(input())
    s = input()
    cnt = 0
    for i in s:
        if i == '8':
            cnt += 1
    print(min(cnt, n // 11))

def mainB():
    def get(n):
        ret = 0
        while n > 0:
            ret += n % 10
            n //= 10
        return ret

    n = int(input())
    if n <= 9:
        print(n)
        return
    t = 9
    while n > t:
        t = t * 10 + 9
    t //= 10
    print(get(t) + get(n - t))

def mainD():
    n, A, B, ans = int(input()), [], [], 0
    for i in range(n):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    for i in range(n):
        ans += max(A[i], B[i])
    print(ans + n)

mainD()


I found an interesting problem on https://codeforces.com/problemset/problem/1061/A:
You have unlimited number of coins with values $1, 2, \ldots, n$. You want to select some set of coins having the total value of $S$.

It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum $S$?

-----Input-----

The only line of the input contains two integers $n$ and $S$ ($1 \le n \le 100\,000$, $1 \le S \le 10^9$)

-----Output-----

Print exactly one integer — the minimum number of coins required to obtain sum $S$.

-----Examples-----
Input
5 11

Output
3
Input
6 16

Output
3

-----Note-----

In the first example, some of the possible ways to get sum $11$ with $3$ coins are:

  $(3, 4, 4)$

 $(2, 4, 5)$

 $(1, 5, 5)$

 $(3, 3, 5)$

It is impossible to get sum $11$ with less than $3$ coins.

In the second example, some of the possible ways to get sum $16$ with $3$ coins are:

  $(5, 5, 6)$

 $(4, 6, 6)$

It is impossible to get sum $16$ with less than $3$ coins.

I tried it in Python, but could not do it. Can you solve it?

n,s=map(int,input().split())
x=s//n
if x*n<s:
    x+=1
print(x)


I found an interesting problem on https://codeforces.com/problemset/problem/1061/B:
You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface.

The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$.

There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$

Find the maximum number of blocks you can remove such that the views for both the cameras would not change.

Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either.

-----Input-----

The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right.

-----Output-----

Print exactly one integer — the maximum number of blocks that can be removed.

-----Examples-----
Input
5 6
3 3 3 3 3

Output
10
Input
3 5
1 2 4

Output
3
Input
5 5
2 3 1 4 4

Output
9
Input
1 1000
548

Output
0
Input
3 3
3 1 1

Output
1

-----Note-----

The following pictures illustrate the first example and its possible solution.

Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]

I tried it in Python, but could not do it. Can you solve it?

import sys

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

if n==1:
    print(0)
    return

A.sort(reverse=True)

NOW=A[0]
ANS=1
i=1
while i<n:
    if A[i]==A[i-1]:
        NOW=max(1,NOW-1)
        ANS+=1
    else:
        if A[i]>=NOW-1:
            ANS+=1
            NOW=max(NOW-1,1)
        else:
            ANS+=max(1,NOW-A[i])
            NOW=A[i]
    i+=1
    #print(i,ANS,NOW)

ANS+=(NOW-1)
print(sum(A)-ANS)


I found an interesting problem on https://codeforces.com/problemset/problem/1061/C:
You are given an integer array $a_1, a_2, \ldots, a_n$.

The array $b$ is called to be a subsequence of $a$ if it is possible to remove some elements from $a$ to get $b$.

Array $b_1, b_2, \ldots, b_k$ is called to be good if it is not empty and for every $i$ ($1 \le i \le k$) $b_i$ is divisible by $i$.

Find the number of good subsequences in $a$ modulo $10^9 + 7$.

Two subsequences are considered different if index sets of numbers included in them are different. That is, the values of the elements do not matter in the comparison of subsequences. In particular, the array $a$ has exactly $2^n - 1$ different subsequences (excluding an empty subsequence).

-----Input-----

The first line contains an integer $n$ ($1 \le n \le 100\,000$) — the length of the array $a$.

The next line contains integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).

-----Output-----

Print exactly one integer — the number of good subsequences taken modulo $10^9 + 7$.

-----Examples-----
Input
2
1 2

Output
3
Input
5
2 2 1 22 14

Output
13

-----Note-----

In the first example, all three non-empty possible subsequences are good: $\{1\}$, $\{1, 2\}$, $\{2\}$

In the second example, the possible good subsequences are: $\{2\}$, $\{2, 2\}$, $\{2, 22\}$, $\{2, 14\}$, $\{2\}$, $\{2, 22\}$, $\{2, 14\}$, $\{1\}$, $\{1, 22\}$, $\{1, 14\}$, $\{22\}$, $\{22, 14\}$, $\{14\}$.

Note, that some subsequences are listed more than once, since they occur in the original array multiple times.

I tried it in Python, but could not do it. Can you solve it?

def getFacts(n):
    facts = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            facts.append(i)
            if i != n//i:
                facts.append(n//i)

    return facts

def main():
    n = int(input())
    arr = list(map(int,input().split()))

    dp = [0]*(n+1)
    mod = 10**9+7

    for i in arr:
        facts = getFacts(i)
        vals = {}
        for j in facts:
            if j <= n:
                vals[j] = dp[j-1]

        for j in facts:
            if j <= n:
                dp[j] += vals[j]
                dp[j] %= mod

        dp[1] += 1

    #print(dp)
    total = sum(dp)%mod

    print(total)

main()


I found an interesting problem on https://codeforces.com/problemset/problem/1062/A:
JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $a_1$, $a_2$, ..., $a_n$ of integers, such that $1 \le a_1 < a_2 < \ldots < a_n \le 10^3$, and then went to the bathroom.

JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range $[1, 10^3]$.

JATC wonders what is the greatest number of elements he can erase?

-----Input-----

The first line of the input contains a single integer $n$ ($1 \le n \le 100$) — the number of elements in the array.

The second line of the input contains $n$ integers $a_i$ ($1 \le a_1<a_2<\dots<a_n \le 10^3$) — the array written by Giraffe.

-----Output-----

Print a single integer — the maximum number of consecutive elements in the array that JATC can erase.

If it is impossible to erase even a single element, print $0$.

-----Examples-----
Input
6
1 3 4 5 6 9

Output
2
Input
3
998 999 1000

Output
2
Input
5
1 2 3 4 5

Output
4

-----Note-----

In the first example, JATC can erase the third and fourth elements, leaving the array $[1, 3, \_, \_, 6, 9]$. As you can see, there is only one way to fill in the blanks.

In the second example, JATC can erase the second and the third elements. The array will become $[998, \_, \_]$. Because all the elements are less than or equal to $1000$, the array is still can be restored. Note, that he can't erase the first $2$ elements.

In the third example, JATC can erase the first $4$ elements. Since all the elements are greater than or equal to $1$, Giraffe can still restore the array. Note, that he can't erase the last $4$ elements.

I tried it in Python, but could not do it. Can you solve it?

def user99():
    n = int(input())
    a = list(map(int, input().split()))
    b = [[] for i in range(n)]

    ptr = 0
    for i in range(n):
        if i >= 1 and a[i - 1] + 1 != a[i]:
            ptr += 1
        b[ptr].append(a[i])

    ans = 0
    for i in b:
        if len(i) == 0:
            continue;
        x = len(i) - 2
        if i[0] == 1: x += 1
        if i[-1] == 10**3: x += 1
        ans = max(ans, x)

    print(ans)

user99()


I found an interesting problem on https://codeforces.com/problemset/problem/1062/B:
JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer $n$, you can perform the following operations zero or more times:  mul $x$: multiplies $n$ by $x$ (where $x$ is an arbitrary positive integer).  sqrt: replaces $n$ with $\sqrt{n}$ (to apply this operation, $\sqrt{n}$ must be an integer).

You can perform these operations as many times as you like. What is the minimum value of $n$, that can be achieved and what is the minimum number of operations, to achieve that minimum value?

Apparently, no one in the class knows the answer to this problem, maybe you can help them?

-----Input-----

The only line of the input contains a single integer $n$ ($1 \le n \le 10^6$) — the initial number.

-----Output-----

Print two integers: the minimum integer $n$ that can be achieved using the described operations and the minimum number of operations required.

-----Examples-----
Input
20

Output
10 2
Input
5184

Output
6 4

-----Note-----

In the first example, you can apply the operation mul $5$ to get $100$ and then sqrt to get $10$.

In the second example, you can first apply sqrt to get $72$, then mul $18$ to get $1296$ and finally two more sqrt and you get $6$.

Note, that even if the initial value of $n$ is less or equal $10^6$, it can still become greater than $10^6$ after applying one or more operations.

I tried it in Python, but could not do it. Can you solve it?

def natlog(mx):
    maxpower = 0
    while mx > 1:
        mx = (mx+1) // 2
        maxpower += 1
    return maxpower

from collections import Counter
n = int(input())

if n == 1:
    print(1, 0)
    return

j = 2
setres  = Counter()

while n>1:
    if n % j == 0:
        n = n//j
        setres[j] += 1
    else:
        j+= 1

res = 1
for j in setres:
    res *= j
# print(res, setres, setres.most_common(1))
maxpower = natlog(setres.most_common(1)[0][1])
maxnum = 2**maxpower

cnt_actions = maxpower

for j, p in list(setres.items()):
    if p < maxnum:
        cnt_actions += 1
        break

print(res, cnt_actions)


I found an interesting problem on https://codeforces.com/problemset/problem/1062/C:
JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way.

First, he splits the Banh-mi into $n$ parts, places them on a row and numbers them from $1$ through $n$. For each part $i$, he defines the deliciousness of the part as $x_i \in \{0, 1\}$. JATC's going to eat those parts one by one. At each step, he chooses arbitrary remaining part and eats it. Suppose that part is the $i$-th part then his enjoyment of the Banh-mi will increase by $x_i$ and the deliciousness of all the remaining parts will also increase by $x_i$. The initial enjoyment of JATC is equal to $0$.

For example, suppose the deliciousness of $3$ parts are $[0, 1, 0]$. If JATC eats the second part then his enjoyment will become $1$ and the deliciousness of remaining parts will become $[1, \_, 1]$. Next, if he eats the first part then his enjoyment will become $2$ and the remaining parts will become $[\_, \_, 2]$. After eating the last part, JATC's enjoyment will become $4$.

However, JATC doesn't want to eat all the parts but to save some for later. He gives you $q$ queries, each of them consisting of two integers $l_i$ and $r_i$. For each query, you have to let him know what is the maximum enjoyment he can get if he eats all the parts with indices in the range $[l_i, r_i]$ in some order.

All the queries are independent of each other. Since the answer to the query could be very large, print it modulo $10^9+7$.

-----Input-----

The first line contains two integers $n$ and $q$ ($1 \le n, q \le 100\,000$).

The second line contains a string of $n$ characters, each character is either '0' or '1'. The $i$-th character defines the deliciousness of the $i$-th part.

Each of the following $q$ lines contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the segment of the corresponding query.

-----Output-----

Print $q$ lines, where $i$-th of them contains a single integer — the answer to the...

I tried it in Python, but could not do it. Can you solve it?

def beki(a,b):
    waru=10**9+7
    ans=1
    while(b>0):
        if(1 & b):
            ans= ans * a %waru
        b >>= 1
        a=a * a % waru
    return ans

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

ans=[]
waru=10**9+7
ruiseki=[0]*(n+1)
bekij=[1]*(n+1)
for i in range(n):
    ruiseki[i+1]=ruiseki[i]+int(s[i])
    bekij[i+1]=(bekij[i]*2)%waru
for i in range(m):
    l,r=map(int,input().split())
    ko=ruiseki[r]-ruiseki[l-1]
    ans.append(str((((bekij[ko] -1)) * ((bekij[r+1-l - ko]))) %waru))

print("\n".join(ans))


I found an interesting problem on https://codeforces.com/problemset/problem/1062/D:
You are given a positive integer $n$ greater or equal to $2$. For every pair of integers $a$ and $b$ ($2 \le |a|, |b| \le n$), you can transform $a$ into $b$ if and only if there exists an integer $x$ such that $1 < |x|$ and ($a \cdot x = b$ or $b \cdot x = a$), where $|x|$ denotes the absolute value of $x$.

After such a transformation, your score increases by $|x|$ points and you are not allowed to transform $a$ into $b$ nor $b$ into $a$ anymore.

Initially, you have a score of $0$. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?

-----Input-----

A single line contains a single integer $n$ ($2 \le n \le 100\,000$) — the given integer described above.

-----Output-----

Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print $0$.

-----Examples-----
Input
4

Output
8
Input
6

Output
28
Input
2

Output
0

-----Note-----

In the first example, the transformations are $2 \rightarrow 4 \rightarrow (-2) \rightarrow (-4) \rightarrow 2$.

In the third example, it is impossible to perform even a single transformation.

I tried it in Python, but could not do it. Can you solve it?

n=int(input())
print(4*sum(i*(n//i-1) for i in range(2,n)))


I found an interesting problem on https://codeforces.com/problemset/problem/1063/B:
You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step you can move one square up, left, down or right, if the target cell is not occupied by an obstacle. You can't move beyond the boundaries of the labyrinth.

Unfortunately, your keyboard is about to break, so you can move left no more than x times and move right no more than y times. There are no restrictions on the number of moves up and down since the keys used to move up and down are in perfect condition.

Now you would like to determine for each cell whether there exists a sequence of moves that will put you from the starting cell to this particular one. How many cells of the board have this property?

-----Input-----

The first line contains two integers n, m (1 ≤ n, m ≤ 2000) — the number of rows and the number columns in the labyrinth respectively.

The second line contains two integers r, c (1 ≤ r ≤ n, 1 ≤ c ≤ m) — index of the row and index of the column that define the starting cell.

The third line contains two integers x, y (0 ≤ x, y ≤ 10^9) — the maximum allowed number of movements to the left and to the right respectively.

The next n lines describe the labyrinth. Each of them has length of m and consists only of symbols '.' and '*'. The j-th character of the i-th line corresponds to the cell of labyrinth at row i and column j. Symbol '.' denotes the free cell, while symbol '*' denotes the cell with an obstacle.

It is guaranteed, that the starting cell contains no obstacles.

-----Output-----

Print exactly one integer — the number of cells in the labyrinth, which are reachable from starting cell, including the starting cell itself.

-----Examples-----
Input
4 5
3 2
1 2
.....
.***.
...**
*....

Output
10

Input
4 4
2 2
0 1
....
..*.
....
....

Output
7

-----Note-----

Cells, reachable in the corresponding example, are marked with '+'.

First example: ...

I tried it in Python, but could not do it. Can you solve it?

from collections import deque
n,m = [int(x) for x in input().split()]
x,y = [int(x) for x in input().split()]
left,right = [int(x) for x in input().split()]
s=[]
d=[None]*2007
ans=0
for i in range(0,2007):
    d[i]=[]
    for j in range(0,2007):
        d[i].append(0)

for i in range(0,n):
    s.append(input())

q = deque()

q.append([x-1,y-1,left,right])

while(len(q)):
    v = q[0]
    q.popleft()

    if(v[0]<0 or v[0]>=n or v[1]<0 or v[1]>=m or d[v[0]][v[1]]==1 or v[2]<0 or v[3]<0 or s[v[0]][v[1]]=='*'): continue

    d[v[0]][v[1]]=1

    q.appendleft([v[0]+1,v[1],v[2],v[3]])
    q.appendleft([v[0]-1,v[1],v[2],v[3]])
    q.append([v[0],v[1]+1,v[2],v[3]-1])
    q.append([v[0],v[1]-1,v[2]-1,v[3]])

for i in range(0,n):
    for j in range(0,m):
        ans+=d[i][j]

print(ans)


I found an interesting problem on https://codeforces.com/problemset/problem/1064/A:
Masha has three sticks of length $a$, $b$ and $c$ centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.

What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a triangle of positive area. Sticks should be used as triangle's sides (one stick for one side) and their endpoints should be located at triangle's vertices.

-----Input-----

The only line contains tree integers $a$, $b$ and $c$ ($1 \leq a, b, c \leq 100$) — the lengths of sticks Masha possesses.

-----Output-----

Print a single integer — the minimum number of minutes that Masha needs to spend in order to be able to make the triangle of positive area from her sticks.

-----Examples-----
Input
3 4 5

Output
0

Input
2 5 3

Output
1

Input
100 10 10

Output
81

-----Note-----

In the first example, Masha can make a triangle from the sticks without increasing the length of any of them.

In the second example, Masha can't make a triangle of positive area from the sticks she has at the beginning, but she can spend one minute to increase the length $2$ centimeter stick by one and after that form a triangle with sides $3$, $3$ and $5$ centimeters.

In the third example, Masha can take $33$ minutes to increase one of the $10$ centimeters sticks by $33$ centimeters, and after that take $48$ minutes to increase another $10$ centimeters stick by $48$ centimeters. This way she can form a triangle with lengths $43$, $58$ and $100$ centimeters in $81$ minutes. One can show that it is impossible to get a valid triangle faster.

I tried it in Python, but could not do it. Can you solve it?

a,b,c = [int(s) for s in input().split()]
su = a+b+c
ma = max(a,b,c)
print(max(0, 2*ma-su+1))


I found an interesting problem on https://codeforces.com/problemset/problem/1064/B:
Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for.Arkadi and Boris Strugatsky. Monday starts on Saturday

Reading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: $a - (a \oplus x) - x = 0$ for some given $a$, where $\oplus$ stands for a bitwise exclusive or (XOR) of two integers (this operation is denoted as ^ or xor in many modern programming languages). Oira-Oira quickly found some $x$, which is the solution of the equation, but Cristobal Junta decided that Oira-Oira's result is not interesting enough, so he asked his colleague how many non-negative solutions of this equation exist. This task turned out to be too difficult for Oira-Oira, so he asks you to help.

-----Input-----

Each test contains several possible values of $a$ and your task is to find the number of equation's solution for each of them. The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of these values.

The following $t$ lines contain the values of parameter $a$, each value is an integer from $0$ to $2^{30} - 1$ inclusive.

-----Output-----

For each value of $a$ print exactly one integer — the number of non-negative solutions of the equation for the given value of the parameter. Print answers in the same order as values of $a$ appear in the input.

One can show that the number of solutions is always finite.

-----Example-----
Input
3
0
2
1073741823

Output
1
2
1073741824

-----Note-----

Let's define the bitwise exclusive OR (XOR) operation. Given two integers $x$ and $y$, consider their binary representations (possibly with leading zeroes): $x_k \dots x_2 x_1 x_0$ and $y_k \dots y_2 y_1 y_0$. Here, $x_i$ is the $i$-th bit of the number $x$ and $y_i$ is the $i$-th bit of the number $y$. Let $r = x \oplus y$ be the result of the XOR operation of $x$ and $y$. Then $r$ is defined as $r_k \dots r_2 r_1 r_0$ where:

$$ r_i = \left\{ \begin{aligned} 1, ~ \text{if} ~ x_i \ne y_i \\ 0, ~ \text{if} ~ x_i = y_i...

I tried it in Python, but could not do it. Can you solve it?

def solve(n):
    res = 0
    for x in range(n + 1):
        if n^x == n - x:
            res += 1
    return res

def solve_1(n):
    cnt = 0
    while n:
        if n %2 == 1:
            cnt += 1
        n = n//2
    return 2**cnt

t = int(input())
while t:
    n = int(input())
    print(solve_1(n))
    t -= 1


I found an interesting problem on https://codeforces.com/problemset/problem/1065/A:
There is a special offer in Vasya's favourite supermarket: if the customer buys $a$ chocolate bars, he or she may take $b$ additional bars for free. This special offer can be used any number of times.

Vasya currently has $s$ roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs $c$ roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!

-----Input-----

The first line contains one integer $t$ ($1 \le t \le 100$) — the number of testcases.

Each of the next $t$ lines contains four integers $s, a, b, c~(1 \le s, a, b, c \le 10^9)$ — the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.

-----Output-----

Print $t$ lines. $i$-th line should contain the maximum possible number of chocolate bars Vasya can get in $i$-th test.

-----Example-----
Input
2
10 3 1 1
1000000000 1 1000000000 1

Output
13
1000000001000000000

-----Note-----

In the first test of the example Vasya can buy $9$ bars, get $3$ for free, buy another bar, and so he will get $13$ bars.

In the second test Vasya buys $1000000000$ bars and gets $1000000000000000000$ for free. So he has $1000000001000000000$ bars.

I tried it in Python, but could not do it. Can you solve it?

n = int(input())
for i in range(n):
	s,a,b,c = list(map(int,input().split()))
	kol = s // c
	print(kol + kol // a * b)


I found an interesting problem on https://codeforces.com/problemset/problem/1065/B:
Vasya has got an undirected graph consisting of $n$ vertices and $m$ edges. This graph doesn't contain any self-loops or multiple edges. Self-loop is an edge connecting a vertex to itself. Multiple edges are a pair of edges such that they connect the same pair of vertices. Since the graph is undirected, the pair of edges $(1, 2)$ and $(2, 1)$ is considered to be multiple edges. Isolated vertex of the graph is a vertex such that there is no edge connecting this vertex to any other vertex.

Vasya wants to know the minimum and maximum possible number of isolated vertices in an undirected graph consisting of $n$ vertices and $m$ edges.

-----Input-----

The only line contains two integers $n$ and $m~(1 \le n \le 10^5, 0 \le m \le \frac{n (n - 1)}{2})$.

It is guaranteed that there exists a graph without any self-loops or multiple edges with such number of vertices and edges.

-----Output-----

In the only line print two numbers $min$ and $max$ — the minimum and maximum number of isolated vertices, respectively.

-----Examples-----
Input
4 2

Output
0 1

Input
3 1

Output
1 1

-----Note-----

In the first example it is possible to construct a graph with $0$ isolated vertices: for example, it should contain edges $(1, 2)$ and $(3, 4)$. To get one isolated vertex, we may construct a graph with edges $(1, 2)$ and $(1, 3)$.

In the second example the graph will always contain exactly one isolated vertex.

I tried it in Python, but could not do it. Can you solve it?

USE_STDIO = False

if not USE_STDIO:
    try: import mypc
    except: pass

def main():
    n, m = list(map(int, input().split(' ')))
    if m == 0:
        print(n, n)
        return

    minc = max(0, n - m * 2)

    x = int((m*2)**0.5)
    if x * (x + 1) < m * 2:
        x += 1
    maxc = n - (x + 1)

    print(minc, maxc)

def __starting_point():
    main()

__starting_point()


I found an interesting problem on https://codeforces.com/problemset/problem/1065/C:
There is a toy building consisting of $n$ towers. Each tower consists of several cubes standing on each other. The $i$-th tower consists of $h_i$ cubes, so it has height $h_i$.

Let's define operation slice on some height $H$ as following: for each tower $i$, if its height is greater than $H$, then remove some top cubes to make tower's height equal to $H$. Cost of one "slice" equals to the total number of removed cubes from all towers.

Let's name slice as good one if its cost is lower or equal to $k$ ($k \ge n$).

 [Image]

Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so.

-----Input-----

The first line contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $n \le k \le 10^9$) — the number of towers and the restriction on slices, respectively.

The second line contains $n$ space separated integers $h_1, h_2, \dots, h_n$ ($1 \le h_i \le 2 \cdot 10^5$) — the initial heights of towers.

-----Output-----

Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth.

-----Examples-----
Input
5 5
3 1 2 2 4

Output
2

Input
4 5
2 3 4 5

Output
2

-----Note-----

In the first example it's optimal to make $2$ slices. The first slice is on height $2$ (its cost is $3$), and the second one is on height $1$ (its cost is $4$).

I tried it in Python, but could not do it. Can you solve it?

def ii():
    return int(input())
def mi():
    return list(map(int, input().split()))
def li():
    return list(mi())

n, k = mi()
h = li()
m = max(h)
f = [0] * (m + 1)
for hi in h:
    f[hi] += 1
for i in range(m - 1, 0, -1):
    f[i] += f[i + 1]

ans = 0
i = m
while i > 0:
    if f[i] == n:
        break
    j = i
    cur = 0
    while j > 0:
        if cur + f[j] > k:
            break
        cur += f[j]
        j -= 1
    ans += 1
    i = j
print(ans)


I found an interesting problem on https://codeforces.com/problemset/problem/1065/D:
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $8 \times 8$, but it still is $N \times N$. Each square has some number written on it, all the numbers are from $1$ to $N^2$ and all the numbers are pairwise distinct. The $j$-th square in the $i$-th row has a number $A_{ij}$ written on it.

In your chess set you have only three pieces: a knight, a bishop and a rook. At first, you put one of them on the square with the number $1$ (you can choose which one). Then you want to reach square $2$ (possibly passing through some other squares in process), then square $3$ and so on until you reach square $N^2$. In one step you are allowed to either make a valid move with the current piece or replace it with some other piece. Each square can be visited arbitrary number of times.

A knight can move to a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. A bishop moves diagonally. A rook moves horizontally or vertically. The move should be performed to a different square from the one a piece is currently standing on.

You want to minimize the number of steps of the whole traversal. Among all the paths to have the same number of steps you want to choose the one with the lowest number of piece replacements.

What is the path you should take to satisfy all conditions?

-----Input-----

The first line contains a single integer $N$ ($3 \le N \le 10$) — the size of the chessboard.

Each of the next $N$ lines contains $N$ integers $A_{i1}, A_{i2}, \dots, A_{iN}$ ($1 \le A_{ij} \le N^2$) — the numbers written on the squares of the $i$-th row of the board.

It is guaranteed that all $A_{ij}$ are pairwise distinct.

-----Output-----

The only line should contain two integers — the number of steps in the best answer and the number of replacement moves in it.

-----Example-----
Input
3
1 9 3
8 6 7
4 2 5

Output
12 1

-----Note-----

Here are the steps for the first example (the starting piece is a knight): ...

I tried it in Python, but could not do it. Can you solve it?

import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

n = int(minp())
m = [None]*n
k = [None]*3
dp = [None]*3
dp[0] = [None]*(n*n)
dp[1] = [None]*(n*n)
dp[2] = [None]*(n*n)
path = [None]*(n*n)
for i in range(n):
	m[i] = list(map(int, minp().split()))
	for j in range(n):
		path[m[i][j]-1] = (i,j)
for z in range(3):
	k_ = [None]*n
	for i in range(n):
		kk = [None]*n
		for j in range(n):
			kkk_ = [None]*3
			for zz in range(3):
				kkk = [None]*n
				for w in range(n):
					kkk[w] = [(1000000,0)]*n
				kkk_[zz] = kkk
			kk[j] = kkk_
		k_[i] = kk
	k[z] = k_

q = [0]*(10*n*n)
qr = 0
km = [(1,2),(1,-2),(-1,2),(-1,-2),(2,1),(2,-1),(-2,1),(-2,-1)]
sm = [(1,1),(1,-1),(-1,1),(-1,-1)]
lm = [(0,1),(0,-1),(-1,0),(1,0)]
mm = [km,sm,lm]
for z in range(3):
	for i in range(n):
		for j in range(n):
			#print('========')
			ql = 0
			qr = 1
			q[0] = (z, i, j, (0,0))
			kc = k[z][i][j]
			kc[z][i][j] = (0, 0)
			while ql < qr:
				t, x, y, dd = q[ql]
				#print(t,x,y,dd)
				d = kc[t][x][y]
				ql += 1
				if d != dd:
					continue
				dd = (d[0]+1, d[1]+1)
				for tt in range(3):
					if t != tt and kc[tt][x][y] > dd:
						kc[tt][x][y] = dd
						q[qr] = (tt,x,y,dd)
						qr += 1
				dd = (d[0]+1,d[1])
				if t == 0:
					for w in mm[t]:
						xx,yy = w[0]+x,w[1]+y
						if xx >= 0 and xx < n and yy >= 0 and yy < n:
							if kc[t][xx][yy] > dd:
								kc[t][xx][yy] = dd
								q[qr] = (t,xx,yy,dd)
								qr += 1
				else:
					for w in mm[t]:
						for hm in range(n*2):
							xx,yy = w[0]*hm+x,w[1]*hm+y
							if xx >= 0 and xx < n and yy >= 0 and yy < n:
								if kc[t][xx][yy] > dd:
									kc[t][xx][yy] = dd
									q[qr] = (t,xx,yy,dd)
									qr += 1
							else:
								break
dp[0][0] = (0,0)
dp[1][0] = (0,0)
dp[2][0] = (0,0)
for i in range(0,n*n-1):
	x,y = path[i]
	xx,yy = path[i+1]
	for z in range(3):
		for j in range(3):
			dist = k[j][x][y][z][xx][yy]
			if dp[j][i] != None:
				nd = (dp[j][i][0]+dist[0],dp[j][i][1]+dist[1])
				if dp[z][i+1] == None:
					dp[z][i+1] =...


I found an interesting problem on https://codeforces.com/problemset/problem/1065/E:
Consider some set of distinct characters $A$ and some string $S$, consisting of exactly $n$ characters, where each character is present in $A$.

You are given an array of $m$ integers $b$ ($b_1 < b_2 < \dots < b_m$).

You are allowed to perform the following move on the string $S$:

  Choose some valid $i$ and set $k = b_i$;  Take the first $k$ characters of $S = Pr_k$;  Take the last $k$ characters of $S = Su_k$;  Substitute the first $k$ characters of $S$ with the reversed $Su_k$;  Substitute the last $k$ characters of $S$ with the reversed $Pr_k$.

For example, let's take a look at $S =$ "abcdefghi" and $k = 2$. $Pr_2 =$ "ab", $Su_2 =$ "hi". Reversed $Pr_2 =$ "ba", $Su_2 =$ "ih". Thus, the resulting $S$ is "ihcdefgba".

The move can be performed arbitrary number of times (possibly zero). Any $i$ can be selected multiple times over these moves.

Let's call some strings $S$ and $T$ equal if and only if there exists such a sequence of moves to transmute string $S$ to string $T$. For the above example strings "abcdefghi" and "ihcdefgba" are equal. Also note that this implies $S = S$.

The task is simple. Count the number of distinct strings.

The answer can be huge enough, so calculate it modulo $998244353$.

-----Input-----

The first line contains three integers $n$, $m$ and $|A|$ ($2 \le n \le 10^9$, $1 \le m \le min(\frac n 2, 2 \cdot 10^5)$, $1 \le |A| \le 10^9$) — the length of the strings, the size of the array $b$ and the size of the set $A$, respectively.

The second line contains $m$ integers $b_1, b_2, \dots, b_m$ ($1 \le b_i \le \frac n 2$, $b_1 < b_2 < \dots < b_m$).

-----Output-----

Print a single integer — the number of distinct strings of length $n$ with characters from set $A$ modulo $998244353$.

-----Examples-----
Input
3 1 2
1

Output
6

Input
9 2 26
2 3

Output
150352234

Input
12 3 1
2 5 6

Output
1

-----Note-----

Here are all the distinct strings for the first example. The chosen letters 'a' and 'b' are there just to show that the characters in $A$ are different.

  "aaa" ...

I tried it in Python, but could not do it. Can you solve it?

n,m,a=map(int,input().split())
b=list(map(int,input().split()))
for i in range(m):
    if i==0:
        diffs=[b[0]]
    else:
        diffs.append(b[i]-b[i-1])
powers=[a%998244353]
for i in range(30):
    powers.append(powers[-1]**2%998244353)
def power(x,y,binpowers):
    prod=1
    bits=bin(y)[2:]
    bits=bits[::-1]
    for i in range(len(bits)):
        if bits[i]=="1":
            prod*=binpowers[i]
            prod%=998244353
    return prod
maxi=b[-1]
prod1=power(a,n-2*maxi,powers)
for guy in diffs:
    newprod=power(a,guy,powers)
    newprod=(newprod*(newprod+1))//2
    newprod%=998244353
    prod1*=newprod
    prod1%=998244353
print(prod1)


I found an interesting problem on https://codeforces.com/problemset/problem/1066/A:
Vova plans to go to the conference by train. Initially, the train is at the point $1$ and the destination point of the path is the point $L$. The speed of the train is $1$ length unit per minute (i.e. at the first minute the train is at the point $1$, at the second minute — at the point $2$ and so on).

There are lanterns on the path. They are placed at the points with coordinates divisible by $v$ (i.e. the first lantern is at the point $v$, the second is at the point $2v$ and so on).

There is also exactly one standing train which occupies all the points from $l$ to $r$ inclusive.

Vova can see the lantern at the point $p$ if $p$ is divisible by $v$ and there is no standing train at this position ($p \not\in [l; r]$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.

Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $t$ different conferences, so you should answer $t$ independent queries.

-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of queries.

Then $t$ lines follow. The $i$-th line contains four integers $L_i, v_i, l_i, r_i$ ($1 \le L, v \le 10^9$, $1 \le l \le r \le L$) — destination point of the $i$-th path, the period of the lantern appearance and the segment occupied by the standing train.

-----Output-----

Print $t$ lines. The $i$-th line should contain one integer — the answer for the $i$-th query.

-----Example-----
Input
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000

Output
3
0
1134
0

-----Note-----

For the first example query, the answer is $3$. There are lanterns at positions $2$, $4$, $6$, $8$ and $10$, but Vova didn't see the lanterns at positions $4$ and $6$ because of the standing train.

For the second example query, the answer is $0$ because the only lantern is at the point $51$ and there is also a standing train at this point.

For the third example query, the answer is $1134$ because there...

I tried it in Python, but could not do it. Can you solve it?

t=int(input())

for i in range(t):
    L, u, l, r = map(int,input().split())
    d=0
    print(L//u - (r//u-(l-1)//u))


I found an interesting problem on https://codeforces.com/problemset/problem/1066/B:
Vova's house is an array consisting of $n$ elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The $i$-th element of the array is $1$ if there is a heater in the position $i$, otherwise the $i$-th element of the array is $0$.

Each heater has a value $r$ ($r$ is the same for all heaters). This value means that the heater at the position $pos$ can warm up all the elements in range $[pos - r + 1; pos + r - 1]$.

Vova likes to walk through his house while he thinks, and he hates cold positions of his house. Vova wants to switch some of his heaters on in such a way that each element of his house will be warmed up by at least one heater.

Vova's target is to warm up the whole house (all the elements of the array), i.e. if $n = 6$, $r = 2$ and heaters are at positions $2$ and $5$, then Vova can warm up the whole house if he switches all the heaters in the house on (then the first $3$ elements will be warmed up by the first heater and the last $3$ elements will be warmed up by the second heater).

Initially, all the heaters are off.

But from the other hand, Vova didn't like to pay much for the electricity. So he wants to switch the minimum number of heaters on in such a way that each element of his house is warmed up by at least one heater.

Your task is to find this number of heaters or say that it is impossible to warm up the whole house.

-----Input-----

The first line of the input contains two integers $n$ and $r$ ($1 \le n, r \le 1000$) — the number of elements in the array and the value of heaters.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 1$) — the Vova's house description.

-----Output-----

Print one integer — the minimum number of heaters needed to warm up the whole house or -1 if it is impossible to do it.

-----Examples-----
Input
6 2
0 1 1 0 0 1

Output
3

Input
5 3
1 0 0 0 1

Output
2

Input
5 10
0 0 0 0 0

Output
-1

Input
10 3
0 0 1 1 0 1 0 0 0...

I tried it in Python, but could not do it. Can you solve it?

def mini(arr, n, k):
	lo = [0 for i in range(n + 1)]
	o = -1

	for i in range(n):
		if (arr[i] == 1):
			o = i
		lo[i] = o
	a= 0; i = 0
	while(i < n):
		pos = lo[min(i + k - 1, n - 1)]
		if (pos == -1 or pos + k <= i):
			return -1
		i = pos + k
		a+= 1
	return a
n,k=list(map(int,input().split()))
arr=[int(i) for i in input().split()]
print(mini(arr, n, k))


I found an interesting problem on https://codeforces.com/problemset/problem/1066/C:
You have got a shelf and want to put some books on it.

You are given $q$ queries of three types:  L $id$ — put a book having index $id$ on the shelf to the left from the leftmost existing book;  R $id$ — put a book having index $id$ on the shelf to the right from the rightmost existing book;  ? $id$ — calculate the minimum number of books you need to pop from the left or from the right in such a way that the book with index $id$ will be leftmost or rightmost.

You can assume that the first book you will put can have any position (it does not matter) and queries of type $3$ are always valid (it is guaranteed that the book in each such query is already placed). You can also assume that you don't put the same book on the shelf twice, so $id$s don't repeat in queries of first two types.

Your problem is to answer all the queries of type $3$ in order they appear in the input.

Note that after answering the query of type $3$ all the books remain on the shelf and the relative order of books does not change.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.

-----Input-----

The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries.

Then $q$ lines follow. The $i$-th line contains the $i$-th query in format as in the problem statement. It is guaranteed that queries are always valid (for query type $3$, it is guaranteed that the book in each such query is already placed, and for other types, it is guaranteed that the book was not placed before).

It is guaranteed that there is at least one query of type $3$ in the input.

In each query the constraint $1 \le id \le 2 \cdot 10^5$ is met.

-----Output-----

Print answers to queries of the type $3$ in order they appear in the input.

-----Examples-----
Input
8
L 1
R 2
R 3
? 2
L 4
? 1
L 5
? 1

Output
1
1
2

Input
10
L 100
R 100000
R 123
L 101
? 123
L 10
R 115
? 100
R 110
? 115

Output
0
2
1

-----Note-----

Let's take a look at the first example and let's consider queries: ...

I tried it in Python, but could not do it. Can you solve it?

import sys
f=sys.stdin
out=sys.stdout

q=int(f.readline().rstrip('\r\n'))
pos,id=f.readline().rstrip('\r\n').split()
mid=int(id)

left=[]
right=[]
dleft={}
dright={}

for i in range(q-1):
	pos,id=f.readline().rstrip('\r\n').split()
	id=int(id)
	if pos=="L":
		left.append(id)
		dleft[id]=len(dleft)+1
	elif pos=="R":
		right.append(id)
		dright[id]=len(dright)+1
	else:
		if id==mid:
			out.write(str(min(len(dleft),len(dright)))+"\n")
		elif id in dleft:
			z=len(dleft)-dleft[id]+1
			out.write(str(min(z-1,1+len(dright)+dleft[id]-1))+"\n")
		else:
			z=dright[id]
			#print(z)
			out.write(str(min(len(dleft)+z,len(dright)-z))+"\n")


I found an interesting problem on https://codeforces.com/problemset/problem/1066/D:
Maksim has $n$ objects and $m$ boxes, each box has size exactly $k$. Objects are numbered from $1$ to $n$ in order from left to right, the size of the $i$-th object is $a_i$.

Maksim wants to pack his objects into the boxes and he will pack objects by the following algorithm: he takes one of the empty boxes he has, goes from left to right through the objects, and if the $i$-th object fits in the current box (the remaining size of the box is greater than or equal to $a_i$), he puts it in the box, and the remaining size of the box decreases by $a_i$. Otherwise he takes the new empty box and continues the process above. If he has no empty boxes and there is at least one object not in some box then Maksim cannot pack the chosen set of objects.

Maksim wants to know the maximum number of objects he can pack by the algorithm above. To reach this target, he will throw out the leftmost object from the set until the remaining set of objects can be packed in boxes he has. Your task is to say the maximum number of objects Maksim can pack in boxes he has.

Each time when Maksim tries to pack the objects into the boxes, he will make empty all the boxes he has before do it (and the relative order of the remaining set of objects will not change).

-----Input-----

The first line of the input contains three integers $n$, $m$, $k$ ($1 \le n, m \le 2 \cdot 10^5$, $1 \le k \le 10^9$) — the number of objects, the number of boxes and the size of each box.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the size of the $i$-th object.

-----Output-----

Print the maximum number of objects Maksim can pack using the algorithm described in the problem statement.

-----Examples-----
Input
5 2 6
5 2 1 4 2

Output
4

Input
5 1 4
4 2 3 4 1

Output
1

Input
5 3 3
1 2 3 1 1

Output
5

-----Note-----

In the first example Maksim can pack only $4$ objects. Firstly, he tries to pack all the $5$ objects. Distribution of objects will be $[5], [2, 1]$. Maxim cannot pack the next...

I tried it in Python, but could not do it. Can you solve it?

import math
import sys
n,m,k = map(int, sys.stdin.readline().split())
a =[int(x) for x in sys.stdin.readline().split()]
a.reverse()
ans = 0
bag = m - 1
size = k
for x in a:
    if size < x:
        if bag > 0:
            bag -= 1
            size = k - x
        else: break
    else: size -= x
    ans += 1
sys.stdout.write(str(ans))


I found an interesting problem on https://codeforces.com/problemset/problem/1066/E:
You are given two huge binary integer numbers $a$ and $b$ of lengths $n$ and $m$ respectively. You will repeat the following process: if $b > 0$, then add to the answer the value $a~ \&~ b$ and divide $b$ by $2$ rounding down (i.e. remove the last digit of $b$), and repeat the process again, otherwise stop the process.

The value $a~ \&~ b$ means bitwise AND of $a$ and $b$. Your task is to calculate the answer modulo $998244353$.

Note that you should add the value $a~ \&~ b$ to the answer in decimal notation, not in binary. So your task is to calculate the answer in decimal notation. For example, if $a = 1010_2~ (10_{10})$ and $b = 1000_2~ (8_{10})$, then the value $a~ \&~ b$ will be equal to $8$, not to $1000$.

-----Input-----

The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) — the length of $a$ and the length of $b$ correspondingly.

The second line of the input contains one huge integer $a$. It is guaranteed that this number consists of exactly $n$ zeroes and ones and the first digit is always $1$.

The third line of the input contains one huge integer $b$. It is guaranteed that this number consists of exactly $m$ zeroes and ones and the first digit is always $1$.

-----Output-----

Print the answer to this problem in decimal notation modulo $998244353$.

-----Examples-----
Input
4 4
1010
1101

Output
12

Input
4 5
1001
10101

Output
11

-----Note-----

The algorithm for the first example:   add to the answer $1010_2~ \&~ 1101_2 = 1000_2 = 8_{10}$ and set $b := 110$;  add to the answer $1010_2~ \&~ 110_2 = 10_2 = 2_{10}$ and set $b := 11$;  add to the answer $1010_2~ \&~ 11_2 = 10_2 = 2_{10}$ and set $b := 1$;  add to the answer $1010_2~ \&~ 1_2 = 0_2 = 0_{10}$ and set $b := 0$.

So the answer is $8 + 2 + 2 + 0 = 12$.

The algorithm for the second example:   add to the answer $1001_2~ \&~ 10101_2 = 1_2 = 1_{10}$ and set $b := 1010$;  add to the answer $1001_2~ \&~ 1010_2 = 1000_2 = 8_{10}$ and set $b := 101$;  add to the answer $1001_2~ \&~ 101_2 = 1_2 =...

I tried it in Python, but could not do it. Can you solve it?

n,m=map(int,input().split())
ta=input()
tb=input()
count=0
ans=0
r=n-m
for i in range(m):
    if tb[i]=='1':
        count+=1
    if i+r>=0:
        if ta[i+r]=='1':
            ans=(ans+pow(2,m-i-1,998244353)*count)%998244353
print(ans)


I found an interesting problem on https://codeforces.com/problemset/problem/1066/F:
Maksim walks on a Cartesian plane. Initially, he stands at the point $(0, 0)$ and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point $(0, 0)$, he can go to any of the following points in one move:   $(1, 0)$;  $(0, 1)$;  $(-1, 0)$;  $(0, -1)$.

There are also $n$ distinct key points at this plane. The $i$-th point is $p_i = (x_i, y_i)$. It is guaranteed that $0 \le x_i$ and $0 \le y_i$ and there is no key point $(0, 0)$.

Let the first level points be such points that $max(x_i, y_i) = 1$, the second level points be such points that $max(x_i, y_i) = 2$ and so on. Maksim wants to visit all the key points. But he shouldn't visit points of level $i + 1$ if he does not visit all the points of level $i$. He starts visiting the points from the minimum level of point from the given set.

The distance between two points $(x_1, y_1)$ and $(x_2, y_2)$ is $|x_1 - x_2| + |y_1 - y_2|$ where $|v|$ is the absolute value of $v$.

Maksim wants to visit all the key points in such a way that the total distance he walks will be minimum possible. Your task is to find this distance.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.

-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of key points.

Each of the next $n$ lines contains two integers $x_i$, $y_i$ ($0 \le x_i, y_i \le 10^9$) — $x$-coordinate of the key point $p_i$ and $y$-coordinate of the key point $p_i$. It is guaranteed that all the points are distinct and the point $(0, 0)$ is not in this set.

-----Output-----

Print one integer — the minimum possible total distance Maksim has to travel if he needs to visit all key points in a way described above.

-----Examples-----
Input
8
2 2
1 4
2 3
3 1
3 4
1 1
4 3
1 2

Output
15

Input
5
2 1
1 0
2 0
3 2
0 3

Output
9

-----Note-----

The picture corresponding to the first example: [Image]

There is one of the possible answers of length...

I tried it in Python, but could not do it. Can you solve it?

n = int(input())
f = [0] * (n + 1)
p = [(0, 0, 0)] * (n + 1)
for i in range(1, n + 1):
	x, y = map(int, input().split())
	p[i] = (x, y, max(x, y))

p.sort(key=lambda x : (x[2], x[0] - x[1]))

def dis(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])

lasi = lasj = 0
i = 1
while i <= n:
	j = i
	while j < n and p[j + 1][2] == p[i][2]:
		j += 1
	for k in {i, j}:
		f[i ^ j ^ k] = dis(p[i], p[j]) + min(f[l] + dis(p[l], p[k]) for l in {lasi, lasj})
	lasi, lasj = i, j
	i = j + 1

print(min(f[lasi], f[lasj]))


I found an interesting problem on https://codeforces.com/problemset/problem/1067/B:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least $3$ (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make himself $k$-multihedgehog.

Let us define $k$-multihedgehog as follows: $1$-multihedgehog is hedgehog: it has one vertex of degree at least $3$ and some vertices of degree 1. For all $k \ge 2$, $k$-multihedgehog is $(k-1)$-multihedgehog in which the following changes has been made for each vertex $v$ with degree 1: let $u$ be its only neighbor; remove vertex $v$, create a new hedgehog with center at vertex $w$ and connect vertices $u$ and $w$ with an edge. New hedgehogs can differ from each other and the initial gift.

Thereby $k$-multihedgehog is a tree. Ivan made $k$-multihedgehog but he is not sure that he did not make any mistakes. That is why he asked you to check if his tree is indeed $k$-multihedgehog.

-----Input-----

First line of input contains $2$ integers $n$, $k$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{9}$) — number of vertices and hedgehog parameter.

Next $n-1$ lines contains two integers $u$ $v$ ($1 \le u, \,\, v \le n; \,\, u \ne v$) — indices of vertices connected by edge.

It is guaranteed that given graph is a tree.

-----Output-----

Print "Yes" (without quotes), if given graph is $k$-multihedgehog, and "No" (without quotes) otherwise.

-----Examples-----
Input
14 2
1 4
2 4
3 4
4 13
10 5
11 5
12 5
14 5
5 13
6 7
8 6
13 6
9 6

Output
Yes

Input
3 1
1 3
2 3

Output
No

-----Note-----

2-multihedgehog from the first example looks like this:

[Image]

Its center is vertex $13$. Hedgehogs created on last step are: [4 (center), 1, 2, 3], [6 (center), 7, 8, 9], [5 (center), 10, 11, 12, 13].

Tree from second example is not a hedgehog because degree of center should be at least $3$.

I tried it in Python, but could not do it. Can you solve it?

from collections import deque

m, k = list(map(int, input().split()))

G = [set() for _ in range(m + 1)]

q, nq = deque(), deque()

for _ in range(m - 1):
    u, v = list(map(int, input().split()))
    G[u].add(v)
    G[v].add(u)

for u in range(1, m + 1):
    if len(G[u]) == 1:
        q.append(u)

step = 0
removed = 0
ok = True

while removed < m - 1:
    each = {}
    for u in q:
        nxt = G[u].pop()
        G[nxt].remove(u)
        each[nxt] = each.get(nxt, 0) + 1
        removed += 1
        if len(G[nxt]) == 0:
            break
        if len(G[nxt]) == 1:
            nq.append(nxt)
    if any(v < 3 for k,v in list(each.items())):
        ok = False
        break
    q, nq = nq, deque()
    step += 1

if ok and step == k and removed == m - 1:
    print('Yes')
else:
    print('No')


I found an interesting problem on https://codeforces.com/problemset/problem/1067/C:
Ivan places knights on infinite chessboard. Initially there are $n$ knights. If there is free cell which is under attack of at least $4$ knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can prove that this process is finite. One can also prove that position in the end does not depend on the order in which new knights are placed.

Ivan asked you to find initial placement of exactly $n$ knights such that in the end there will be at least $\lfloor \frac{n^{2}}{10} \rfloor$ knights.

-----Input-----

The only line of input contains one integer $n$ ($1 \le n \le 10^{3}$) — number of knights in the initial placement.

-----Output-----

Print $n$ lines. Each line should contain $2$ numbers $x_{i}$ and $y_{i}$ ($-10^{9} \le x_{i}, \,\, y_{i} \le 10^{9}$) — coordinates of $i$-th knight. For all $i \ne j$, $(x_{i}, \,\, y_{i}) \ne (x_{j}, \,\, y_{j})$ should hold. In other words, all knights should be in different cells.

It is guaranteed that the solution exists.

-----Examples-----
Input
4

Output
1 1
3 1
1 5
4 4

Input
7

Output
2 1
1 2
4 1
5 2
2 6
5 7
6 6

-----Note-----

Let's look at second example:

$\left. \begin{array}{|l|l|l|l|l|l|l|l|l|} \hline 7 & {} & {} & {} & {} & {0} & {} & {} \\ \hline 6 & {} & {0} & {} & {} & {} & {0} & {} \\ \hline 5 & {} & {} & {} & {2} & {} & {} & {} \\ \hline 4 & {} & {} & {} & {} & {} & {} & {} \\ \hline 3 & {} & {} & {1} & {} & {} & {} & {} \\ \hline 2 & {0} & {} & {} & {} & {0} & {} & {} \\ \hline 1 & {} & {0} & {} & {0} & {} & {} & {} \\ \hline & {1} & {2} & {3} & {4} & {5} & {6} & {7} \\ \hline \end{array} \right.$

Green zeroes are initial knights. Cell $(3, \,\, 3)$ is under attack of $4$ knights in cells $(1, \,\, 2)$, $(2, \,\, 1)$, $(4, \,\, 1)$ and $(5, \,\, 2)$, therefore Ivan will place a knight in this cell. Cell $(4, \,\, 5)$ is initially attacked by only $3$ knights in cells $(2, \,\, 6)$, $(5, \,\, 7)$ and $(6, \,\, 6)$. But new knight in cell $(3, \,\, 3)$ also attacks cell $(4, \,\, 5)$, now it is...

I tried it in Python, but could not do it. Can you solve it?

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input())
above = n // 3
below = n - above
for i in range(above):
    print(2 * i + 1, 3)
for i in range(below):
    print(i, 0)


I found an interesting problem on https://codeforces.com/problemset/problem/1068/A:
Ivan is collecting coins. There are only $N$ different collectible coins, Ivan has $K$ of them. He will be celebrating his birthday soon, so all his $M$ freinds decided to gift him coins. They all agreed to three terms:  Everyone must gift as many coins as others. All coins given to Ivan must be different. Not less than $L$ coins from gifts altogether, must be new in Ivan's collection.

But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.

-----Input-----

The only line of input contains 4 integers $N$, $M$, $K$, $L$ ($1 \le K \le N \le 10^{18}$; $1 \le M, \,\, L \le 10^{18}$) — quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.

-----Output-----

Print one number — minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).

-----Examples-----
Input
20 15 2 3

Output
1
Input
10 11 2 4

Output
-1

-----Note-----

In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.

In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.

I tried it in Python, but could not do it. Can you solve it?

n,m,k,l=list(map(int,input().split()))
if k+l>n:
    print('-1')
else:
    x=(k+l)//m
    if (k+l)%m>0:
        x+=1
    if x*m>n:
        print('-1')
    else:
        print(x)


I found an interesting problem on https://codeforces.com/problemset/problem/1068/B:
Ivan has number $b$. He is sorting through the numbers $a$ from $1$ to $10^{18}$, and for every $a$ writes $\frac{[a, \,\, b]}{a}$ on blackboard. Here $[a, \,\, b]$ stands for least common multiple of $a$ and $b$. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the board if he would finish the task. Help him to find the quantity of different numbers he would write on the board.

-----Input-----

The only line contains one integer — $b$ $(1 \le b \le 10^{10})$.

-----Output-----

Print one number — answer for the problem.

-----Examples-----
Input
1

Output
1
Input
2

Output
2

-----Note-----

In the first example $[a, \,\, 1] = a$, therefore $\frac{[a, \,\, b]}{a}$ is always equal to $1$.

In the second example $[a, \,\, 2]$ can be equal to $a$ or $2 \cdot a$ depending on parity of $a$. $\frac{[a, \,\, b]}{a}$ can be equal to $1$ and $2$.

I tried it in Python, but could not do it. Can you solve it?

b = int(input())
n = 0
from math import sqrt
r = int(sqrt(b))
for i in range(1, r+1):
    if b%i==0:
        n+=1
n*=2
if r*r==b:
    n-=1
print(n)


I found an interesting problem on https://codeforces.com/problemset/problem/1068/C:
Ivan is a novice painter. He has $n$ dyes of different colors. He also knows exactly $m$ pairs of colors which harmonize with each other.

Ivan also enjoy playing chess. He has $5000$ rooks. He wants to take $k$ rooks, paint each of them in one of $n$ colors and then place this $k$ rooks on a chessboard of size $10^{9} \times 10^{9}$.

Let's call the set of rooks on the board connected if from any rook we can get to any other rook in this set moving only through cells with rooks from this set. Assume that rooks can jump over other rooks, in other words a rook can go to any cell which shares vertical and to any cell which shares horizontal.

Ivan wants his arrangement of rooks to have following properties: For any color there is a rook of this color on a board; For any color the set of rooks of this color is connected; For any two different colors $a$ $b$ union of set of rooks of color $a$ and set of rooks of color $b$ is connected if and only if this two colors harmonize with each other.

Please help Ivan find such an arrangement.

-----Input-----

The first line of input contains $2$ integers $n$, $m$ ($1 \le n \le 100$, $0 \le m \le min(1000, \,\, \frac{n(n-1)}{2})$) — number of colors and number of pairs of colors which harmonize with each other.

In next $m$ lines pairs of colors which harmonize with each other are listed. Colors are numbered from $1$ to $n$. It is guaranteed that no pair occurs twice in this list.

-----Output-----

Print $n$ blocks, $i$-th of them describes rooks of $i$-th color.

In the first line of block print one number $a_{i}$ ($1 \le a_{i} \le 5000$) — number of rooks of color $i$. In each of next $a_{i}$ lines print two integers $x$ and $y$ ($1 \le x, \,\, y \le 10^{9}$) — coordinates of the next rook.

All rooks must be on different cells.

Total number of rooks must not exceed $5000$.

It is guaranteed that the solution exists.

-----Examples-----
Input
3 2
1 2
2 3

Output
2
3 4
1 4
4
1 2
2 2
2 4
5 4
1
5 1

Input
3 3
1 2
2 3
3 1

Output
1
1 1
1
1 2
1
1 3

Input
3 1
1...

I tried it in Python, but could not do it. Can you solve it?

n,m=[int(el) for el in input().split()]

pair=[]
kol={i:1 for i in range(1,n+1)}

for i in range(m):
    q,w=[int(el) for el in input().split()]
    if q<w:
        pair.append((q,w))
    else:
        q,w=w,q
        pair.append((q,w))
    kol[q]+=1
    kol[w]+=1

pair.sort()

mazy=[]
for i in range(1,n+1):
    mazy.append((i,i,i))

for i in pair:
    mazy.append((i[0],10000*i[1]+i[0],i[0]))
    mazy.append((i[1],10000*i[1]+i[0],i[1]))

mazy.sort()

cur=1
print(kol[1])

while mazy!=[]:
    q=mazy.pop(0)
    if q[0]==cur:
        print(q[1],q[0])
    else:
        print(kol[q[0]])
        print(q[1],q[0])
        cur=q[0]


I found an interesting problem on https://codeforces.com/problemset/problem/1068/D:
Ivan unexpectedly saw a present from one of his previous birthdays. It is array of $n$ numbers from $1$ to $200$. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:

$a_{1} \le a_{2}$,

$a_{n} \le a_{n-1}$ and

$a_{i} \le max(a_{i-1}, \,\, a_{i+1})$ for all $i$ from $2$ to $n-1$.

Ivan does not remember the array and asks to find the number of ways to restore it. Restored elements also should be integers from $1$ to $200$. Since the number of ways can be big, print it modulo $998244353$.

-----Input-----

First line of input contains one integer $n$ ($2 \le n \le 10^{5}$) — size of the array.

Second line of input contains $n$ integers $a_{i}$ — elements of array. Either $a_{i} = -1$ or $1 \le a_{i} \le 200$. $a_{i} = -1$ means that $i$-th element can't be read.

-----Output-----

Print number of ways to restore the array modulo $998244353$.

-----Examples-----
Input
3
1 -1 2

Output
1

Input
2
-1 -1

Output
200

-----Note-----

In the first example, only possible value of $a_{2}$ is $2$.

In the second example, $a_{1} = a_{2}$ so there are $200$ different values because all restored elements should be integers between $1$ and $200$.

I tried it in Python, but could not do it. Can you solve it?


I found an interesting problem on https://codeforces.com/problemset/problem/1070/B:
Berkomnadzor — Federal Service for Supervision of Communications, Information Technology and Mass Media — is a Berland federal executive body that protects ordinary residents of Berland from the threats of modern internet.

Berkomnadzor maintains a list of prohibited IPv4 subnets (blacklist) and a list of allowed IPv4 subnets (whitelist). All Internet Service Providers (ISPs) in Berland must configure the network equipment to block access to all IPv4 addresses matching the blacklist. Also ISPs must provide access (that is, do not block) to all IPv4 addresses matching the whitelist. If an IPv4 address does not match either of those lists, it's up to the ISP to decide whether to block it or not. An IPv4 address matches the blacklist (whitelist) if and only if it matches some subnet from the blacklist (whitelist). An IPv4 address can belong to a whitelist and to a blacklist at the same time, this situation leads to a contradiction (see no solution case in the output description).

An IPv4 address is a 32-bit unsigned integer written in the form $a.b.c.d$, where each of the values $a,b,c,d$ is called an octet and is an integer from $0$ to $255$ written in decimal notation. For example, IPv4 address $192.168.0.1$ can be converted to a 32-bit number using the following expression $192 \cdot 2^{24} + 168 \cdot 2^{16} + 0 \cdot 2^8 + 1 \cdot 2^0$. First octet $a$ encodes the most significant (leftmost) $8$ bits, the octets $b$ and $c$ — the following blocks of $8$ bits (in this order), and the octet $d$ encodes the least significant (rightmost) $8$ bits.

The IPv4 network in Berland is slightly different from the rest of the world. There are no reserved or internal addresses in Berland and use all $2^{32}$ possible values.

An IPv4 subnet is represented either as $a.b.c.d$ or as $a.b.c.d/x$ (where $0 \le x \le 32$). A subnet $a.b.c.d$ contains a single address $a.b.c.d$. A subnet $a.b.c.d/x$ contains all IPv4 addresses with $x$ leftmost (most significant) bits equal to $x$ leftmost bits of the address $a.b.c.d$. It...

I tried it in Python, but could not do it. Can you solve it?

#!/usr/bin/env python3
# Copied solution

import collections
import sys
import traceback

class Input(object):
    def __init__(self):
        self.fh = sys.stdin

    def next_line(self):
        while True:
            line = sys.stdin.readline()
            if line == '\n':
                continue
            return line

    def next_line_ints(self):
        line = self.next_line()
        return [int(x) for x in line.split()]

    def next_line_strs(self):
        line = self.next_line()
        return line.split()

class Node(object):
    def __init__(self, color, subtree_color):
        self.left = self.right = None
        self.color = color
        self.subtree_color = subtree_color

def list_to_number(list):
    """Return (color, bits, number)."""
    color = 1 if list[0] == '-' else 2
    values = list[1:].split('/')
    bits = 32
    if len(values) == 2:
        bits = int(values[1])
    nums = values[0].split('.')
    number = 0
    for num in nums:
        number = number * 256 + int(num)
    return (color, bits, number)

def add_list_to_tree(tree, list):
    color, bits, number = list_to_number(list)
    shift = 31
    for _ in range(bits):
        tree.subtree_color |= color
        value = (number >> shift) & 1
        if value == 0:
            if not tree.left:
                tree.left = Node(0, 0)
            tree = tree.left
        else:
            if not tree.right:
                tree.right = Node(0, 0)
            tree = tree.right
        shift -= 1
    tree.subtree_color |= color
    tree.color |= color

def check_tree(tree):
    if not tree:
        return True
    if tree.color == 3 or (tree.color and (tree.subtree_color & ~tree.color)):
        return False
    return check_tree(tree.left) and check_tree(tree.right)

def number_to_list(number, bits):
    number <<= (32 - bits)
    values = []
    for _ in range(4):
        #print('number = {}'.format(number))
        values.append(str(number % 256))
        number //= 256
    values = values[::-1]
    return '.'.join(values)...


I found an interesting problem on https://codeforces.com/problemset/problem/1070/D:
Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it.

For each of next $n$ days Vasya knows $a_i$ — number of units of garbage he will produce on the $i$-th day. Each unit of garbage must be disposed of either on the day it was produced or on the next day. Vasya disposes of garbage by putting it inside a bag and dropping the bag into a garbage container. Each bag can contain up to $k$ units of garbage. It is allowed to compose and drop multiple bags into a garbage container in a single day.

Being economical, Vasya wants to use as few bags as possible. You are to compute the minimum number of bags Vasya needs to dispose of all of his garbage for the given $n$ days. No garbage should be left after the $n$-th day.

-----Input-----

The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 2\cdot10^5, 1 \le k \le 10^9$) — number of days to consider and bag's capacity. The second line contains $n$ space separated integers $a_i$ ($0 \le a_i \le 10^9$) — the number of units of garbage produced on the $i$-th day.

-----Output-----

Output a single integer — the minimum number of bags Vasya needs to dispose of all garbage. Each unit of garbage should be disposed on the day it was produced or on the next day. No garbage can be left after the $n$-th day. In a day it is allowed to compose and drop multiple bags.

-----Examples-----
Input
3 2
3 2 1

Output
3

Input
5 1
1000000000 1000000000 1000000000 1000000000 1000000000

Output
5000000000

Input
3 2
1 0 1

Output
2

Input
4 4
2 8 4 1

Output
4

I tried it in Python, but could not do it. Can you solve it?

n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
ans=0
pre=0
for i in range(n):
    if pre!=0:
        ans+=1
        a[i]-=(k-pre)
        if a[i]<0:a[i]=0
    ans+=a[i]//k
    pre=a[i]-a[i]//k*k
if pre!=0 : ans+=1
print(ans)


I found an interesting problem on https://codeforces.com/problemset/problem/1070/F:
Elections in Berland are coming. There are only two candidates — Alice and Bob.

The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views:  supporting none of candidates (this kind is denoted as "00"),  supporting Alice but not Bob (this kind is denoted as "10"),  supporting Bob but not Alice (this kind is denoted as "01"),  supporting both candidates (this kind is denoted as "11").

The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions:  at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators),  at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators),  the total influence of spectators is maximal possible.

Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.

-----Input-----

The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) — the number of people who want to take part in the debate as a spectator.

These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values — "00", "10", "01", "11") and $a_i$ — the influence of the $i$-th person.

-----Output-----

Print a single integer — maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.

-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9

Output
22

Input
5
11 1
01 1
00 100
10 1
01 1

Output
103

Input
6
11 19
10 22
00 18
00...

I tried it in Python, but could not do it. Can you solve it?

n=int(input())
a=[[] for i in range(4)]

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

for i in range(4):
    a[i].sort(reverse=True)
def check():
    x=len(a[1])
    y=len(a[2])
    xy=len(a[3])
    z=len(a[0])

    if(xy+y==0 or xy+x==0 ):
        print(0)
        return

    w=min(x,y)
    sum0=0
    sum0+=sum(a[1][:w])+sum(a[2][:w])+sum(a[3])
    choose = 2
    if x >= y:
        choose = 1
    num=0
    i=w
    j=0
    while(i<max(x,y) and j<z and num<xy):
        if(a[choose][i]>=a[0][j]):
            sum0+=a[choose][i]
            i+=1
        else:
            sum0 += a[0][j]
            j += 1
        num+=1

    while(i<max(x,y) and num<xy):
        sum0 += a[choose][i]
        i += 1
        num+=1

    while (j < z and num < xy):
        sum0 += a[0][j]
        j += 1
        num += 1
    print(sum0)

check()


I found an interesting problem on https://codeforces.com/problemset/problem/1073/A:
You are given a string $s$, consisting of $n$ lowercase Latin letters.

A substring of string $s$ is a continuous segment of letters from $s$. For example, "defor" is a substring of "codeforces" and "fors" is not.

The length of the substring is the number of letters in it.

Let's call some string of length $n$ diverse if and only if there is no letter to appear strictly more than $\frac n 2$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.

Your task is to find any diverse substring of string $s$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring.

-----Input-----

The first line contains a single integer $n$ ($1 \le n \le 1000$) — the length of string $s$.

The second line is the string $s$, consisting of exactly $n$ lowercase Latin letters.

-----Output-----

Print "NO" if there is no diverse substring in the string $s$.

Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $s$.

-----Examples-----
Input
10
codeforces

Output
YES
code

Input
5
aaaaa

Output
NO

-----Note-----

The first example has lots of correct answers.

Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer.

I tried it in Python, but could not do it. Can you solve it?

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

flag = False

for i in range(len(s) - 1):
    if flag:
        break
    if s[i] != s[i + 1]:
        print("YES")
        print(s[i:i+2])
        flag = True
if not flag:
    print("NO")