f = lambda: list(map(int, input().split()))
n, p, d = f()[0], f(), f()
c = list(range(n))
def g(x):
    if c[x] != x: c[x] = g(c[x])
    return c[x]
for x, k in zip(c, d):
    if x >= k: c[g(x)] = g(x - k)
    if x < n - k: c[g(x)] = g(x + k)
print('YES' if all(g(x) == g(y - 1) for x, y in zip(c, p)) else 'NO')

One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited.The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state.

The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells.

If the given state is reachable in the described game, output YES, otherwise NO.

n = int(input())
data = list(map(int, input().split()))
spans = list(map(int, input().split()))

connect = [[False for c in range(n)] for r in range(n)]
for p, span in enumerate(spans):
  for r in [p-span, p+span]:
    if r >= 0 and r < n:
      connect[p][r] = connect[r][p] = True

def visit(data, connect, seen, group, i):
  if not seen[i]:
    seen[i] = True
    group.append((i, data[i]))
    for j in range(n):
      if connect[i][j]:
        visit(data, connect, seen, group, j)

seen = [False for i in range(n)]
for i in range(n):
  group = []
  visit(data, connect, seen, group, i)
  group.sort()
  #print()
  #print(group)
  values = sorted([value for (index, value) in group])
  #print(values)
  for i, value in enumerate(values):
    data[group[i][0]] = value
  #print(data)

if data == list(range(1, n+1)):
  print('YES')
else:
  print('NO')


from heapq import *
INF = 1e16
viajantes = []

N,M = map(int,input().split())

galaxia = [[] for i in range(100002)]
tempo = [INF] * (N+1)

for i in range(M):
    a,b,c = map(int,input().split())
    galaxia[a] += [(c,b)]
    galaxia[b] += [(c,a)]

for j in range(N):
    vi = list(map(int,input().split()))
    viajantes.append(vi[1::])

def visitante_chegando(w,a):
    for x in viajantes[a-1]:
        if x == w:
            w += 1
    return w

def dijsktra(u,v,galaxia):
    tempo[u] = 0
    q = [(0,u)]

    while q:
        z,a = heappop(q)
        #a[0] = distância
        #a[1] = vertice
        #tempo[a[1]] melhor tempo que cheguei em a[1]
        #if a[0] == tempo[a[1]]:
        if z <= tempo[a]:
            w2 = tempo[a]
            w2 = visitante_chegando(w2,a)
            for adj in galaxia[a]:
                w,b = w2 + adj[0],adj[1]
                print(w)
                if w < tempo[b]:
                    tempo[b] = w
                    heappush(q,(tempo[b],b))
    return tempo

d = dijsktra(1,N,galaxia)
if d[-1] == INF:
    print(-1)
else:
    print(d[N])

Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet.Overall the galaxy has n planets, indexed with numbers from 1 to n. Jack is on the planet with index 1, and Apophis will land on the planet with index n. Jack can move between some pairs of planets through stargates (he can move in both directions); the transfer takes a positive, and, perhaps, for different pairs of planets unequal number of seconds. Jack begins his journey at time 0.It can be that other travellers are arriving to the planet where Jack is currently located. In this case, Jack has to wait for exactly 1 second before he can use the stargate. That is, if at time t another traveller arrives to the planet, Jack can only pass through the stargate at time t + 1, unless there are more travellers arriving at time t + 1 to the same planet.Knowing the information about travel times between the planets, and the times when Jack would not be able to use the stargate on particular planets, determine the minimum time in which he can get to the planet with index n.

The first line contains two space-separated integers: n (2 ≤ n ≤ 105), the number of planets in the galaxy, and m (0 ≤ m ≤ 105) — the number of pairs of planets between which Jack can travel using stargates. Then m lines follow, containing three integers each: the i-th line contains numbers of planets ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which are connected through stargates, and the integer transfer time (in seconds) ci (1 ≤ ci ≤ 104) between these planets. It is guaranteed that between any pair of planets there is at most one stargate connection. Then n lines follow: the i-th line contains an integer ki (0 ≤ ki ≤ 105) that denotes the number of moments of time when other travellers arrive to the planet with index i. Then ki distinct space-separated integers tij (0 ≤ tij < 109) follow, sorted in ascending order. An integer tij means that at time tij (in seconds) another traveller arrives to the planet i. It is guaranteed that the sum of all ki does not exceed 105.

Print a single number — the least amount of time Jack needs to get from planet 1 to planet n. If Jack can't get to planet n in any amount of time, print number -1.

NoteIn the first sample Jack has three ways to go from planet 1. If he moves to planet 4 at once, he spends 8 seconds. If he transfers to planet 3, he spends 3 seconds, but as other travellers arrive to planet 3 at time 3 and 4, he can travel to planet 4 only at time 5, thus spending 8 seconds in total. But if Jack moves to planet 2, and then — to planet 4, then he spends a total of only 2 + 5 = 7 seconds.In the second sample one can't get from planet 1 to planet 3 by moving through stargates.

from heapq import *
INF = 1e16
viajantes = []

N,M = map(int,input().split())

galaxia = [[] for i in range(100002)]
tempo = [INF] * (N+1)

for i in range(M):
    a,b,c = map(int,input().split())
    galaxia[a] += [(c,b)]
    galaxia[b] += [(c,a)]

for j in range(N):
    vi = list(map(int,input().split()))
    viajantes.append(vi[1::])

def visitante_chegando(w,a):
    for x in viajantes[a-1]:
        if x == w:
            w += 1
    return w

def dijsktra(u,v,galaxia):
    tempo[u] = 0
    q = [(0,u)]

    while q:
        z,a = heappop(q)
        #a[0] = distância
        #a[1] = vertice
        #tempo[a[1]] melhor tempo que cheguei em a[1]
        #if a[0] == tempo[a[1]]:
        if z <= tempo[a]:
            w2 = tempo[a]
            w2 = visitante_chegando(w2,a)
            for adj in galaxia[a]:
                w,b = w2 + adj[0],adj[1]
                #print(w)
                if w < tempo[b]:
                    tempo[b] = w
                    heappush(q,(tempo[b],b))
    return tempo

d = dijsktra(1,N,galaxia)
if d[-1] == INF:
    print(-1)
else:
    print(d[N])


"""
6
-2 1
0 3
3 3
4 1
3 -2
2 -2
4
0 1
2 2
3 1
1 0
"""

import sys
import bisect
import heapq
import math

INF = 10**9+7
sys.setrecursionlimit(INF)

def fi():
    return int(sys.stdin.readline())

def fi2():
    return map(int, sys.stdin.readline().split())

def fi3():
    return sys.stdin.readline().rstrip()

def fo(*args):
    for s in args:
        sys.stdout.write(str(s)+' ')
    sys.stdout.write('\n')
##    sys.stdout.flush()

##

def convex_hull_graham(points):

    TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0)

    def cmp(a, b):
        return (a > b) - (a < b)

    def turn(p, q, r):
        return cmp((q[0] - p[0])*(r[1] - p[1]) - (r[0] - p[0])*(q[1] - p[1]), 0)

    def _keep_left(hull, r):
        while len(hull) > 1 and turn(hull[-2], hull[-1], r) != TURN_LEFT:
            hull.pop()
        if not len(hull) or hull[-1] != r:
            hull.append(r)
        return hull

    points = sorted(points)
    l = reduce(_keep_left, points, [])
    u = reduce(_keep_left, reversed(points), [])
    return l.extend(u[i] for i in range(1, len(u) - 1)) or l

##
#main

n1 = fi()

Q = []
HULL = set()

for i in range(n1):
    x, y = fi2()

    Q.append((x, y))
    HULL.add((x, y))

n2 = fi()

for i in range(n2):
    x, y = fi2()
    if (x, y) in HULL:
        fo('NO')
        exit(0)
    Q.append((x, y))

S = convex_hull_graham(Q)

for p in S:
    if p not in HULL:
        fo('NO')
        exit(0)

fo('YES')

You've got another geometrical task. You are given two non-degenerate polygons A and B as vertex coordinates. Polygon A is strictly convex. Polygon B is an arbitrary polygon without any self-intersections and self-touches. The vertices of both polygons are given in the clockwise order. For each polygon no three consecutively following vertices are located on the same straight line.Your task is to check whether polygon B is positioned strictly inside polygon A. It means that any point of polygon B should be strictly inside polygon A. "Strictly" means that the vertex of polygon B cannot lie on the side of the polygon A.

The first line contains the only integer n (3 ≤ n ≤ 105) — the number of vertices of polygon A. Then n lines contain pairs of integers xi, yi (|xi|, |yi| ≤ 109) — coordinates of the i-th vertex of polygon A. The vertices are given in the clockwise order. The next line contains a single integer m (3 ≤ m ≤ 2·104) — the number of vertices of polygon B. Then following m lines contain pairs of integers xj, yj (|xj|, |yj| ≤ 109) — the coordinates of the j-th vertex of polygon B. The vertices are given in the clockwise order. The coordinates of the polygon's vertices are separated by a single space. It is guaranteed that polygons A and B are non-degenerate, that polygon A is strictly convex, that polygon B has no self-intersections and self-touches and also for each polygon no three consecutively following vertices are located on the same straight line.

Print on the only line the answer to the problem — if polygon B is strictly inside polygon A, print "YES", otherwise print "NO" (without the quotes).

def cw(a, b, c):
    return a[0] * (b[1] - c[1]) + b[0] * (c[1] - a[1]) + c[0] * (a[1] - b[1]) <= 0

def ccw(a, b, c):
    return a[0] * (b[1] - c[1]) + b[0] * (c[1] - a[1]) + c[0] * (a[1] - b[1]) >= 0

def convex_hull(points):
    points = sorted(points, key = lambda x: (x[0], x[1]))
    up = [points[0]]
    down = [points[0]]
    for i in range(1, len(points)):
        if (i == len(points)-1 or cw(points[0], points[i], points[-1])):
            while (len(up) >= 2 and not cw(up[-2], up[-1], points[i])):
                up.pop(-1)
            up.append(points[i])
        if (i == len(points)-1 or ccw(points[0], points[i], points[-1])):
            while (len(down) >= 2 and not ccw(down[-2], down[-1], points[i])):
                down.pop(-1)
            down.append(points[i])
    points = up[:] + down[1:-1][::-1]
    return points

points = []

n = int(input())
for i in range(n):
    x, y = map(int, input().split())
    points.append([x, y, 0])

m = int(input())
for i in range(m):
    x, y = map(int, input().split())
    points.append([x, y, 1])

points = convex_hull(points)

for p in points:
    if p[-1] == 1:
        print('NO')
        break
else:
    print('YES')


from sys import exit
n=0
k=0
s=""
for i in input().split():
    if n==0:
        n=int(i)
    else:
        k=int(i)

s=str(input())
node=[]
for i in range(len(s)):
    if s[int(i)]=='0':
        node.append(i+1)

node.append(1000000000)
def check(dis):
    current=0
    num=k-2
    for i in range(len(node)-1):
        if num<1:
            break
        if node[i]-node[current]<=dis and node[i+1]-node[current]>dis:
            current=i
            num-=1
    if n-node[current]>dis:
        return -1

    return 1

left=1
right=n
while left+1<right:
    mid=int((left+right)/2)
    t=check(mid)
    if t==1:
        right=mid
    else:
        left=mid
    for i in range(left,right+1):
        if check(i)==1:
            print(i-1)
            exit(0)
print(0)

Polycarp's workday lasts exactly $$$n$$$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $$$k$$$ bars at the beginning of the workday.In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that $$$k$$$ is strictly greater than $$$1$$$.Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible.Consider that Polycarp eats a bar in the minute $$$x$$$ and the next bar in the minute $$$y$$$ ($$$x < y$$$). Then the break time is equal to $$$y - x - 1$$$ minutes. It is not necessary for Polycarp to eat all bars he has.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 200\,000$$$, $$$2 \le k \le n$$$) — the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday. The second line contains the string with length $$$n$$$ consisting of zeros and ones. If the $$$i$$$-th symbol in the string equals to zero, Polycarp has no important things to do in the minute $$$i$$$ and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute $$$i$$$ and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes.

Print the minimum possible break in minutes between eating chocolate bars.

NoteIn the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.In the second example Polycarp will eat bars in the minutes $$$1$$$ and $$$8$$$ anyway, also he needs to eat the chocolate bar in the minute $$$5$$$, so that the time of the maximum break will be equal to $$$3$$$ minutes.

def check(mn, n, k, s):
	cur = 0
	k -= 1
	while cur + 1 < n:
		prv = cur
		cur = min(n - 1, cur + mn)
		while s[cur] == '1':
			cur -= 1
		if prv == cur:
			return False
		k -= 1
	return k >= 0

n, k = map(int, input().split())
s = input()
L = 1
R = n - 1
while L < R:
	mid = (L + R) // 2
	if not check(mid, n, k, s):
		L = mid + 1
	else:
		R = mid
print(L - 1)


class Scroll:
	def __init__(self, id, power, damage):
		self.id = id
		self.power = power
		self.damage = damage
		self.active = False

num_scrolls, boss_max, regenerate = map(int, input().split())
scrolls = [Scroll(i+1, *map(int, input().split())) for i in range(num_scrolls)]
scrolls.sort(key = lambda scroll: scroll.damage)
boss_curr = boss_max
scroll_damage = 0
active_scrolls = []
tick = 0
while True:
	boss_prev = boss_curr
	boss_curr -= scroll_damage
	boss_curr = min(boss_max, boss_curr + regenerate)
	if boss_curr <= 0:
		print('YES')
		print(tick, len(active_scrolls))
		for scroll in active_scrolls:
			print(scroll.start, scroll.id)
		break
	found = False
	for scroll in scrolls:
		if not scroll.active and 100*boss_curr <= scroll.power*boss_max:
			scroll.start = tick
			scroll.active = True
			active_scrolls.append(scroll)
			scroll_damage += scroll.damage
			found = True
			break
	if not found and boss_curr >= boss_prev:
		print('NO')
		break
	tick += 1

Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place.While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level:1) The boss has two parameters: max — the initial amount of health and reg — regeneration rate per second.2) Every scroll also has two parameters: powi — spell power measured in percents — the maximal amount of health counted off the initial one, which allows to use the scroll (i.e. if the boss has more than powi percent of health the scroll cannot be used); and dmgi the damage per second inflicted upon the boss if the scroll is used. As soon as a scroll is used it disappears and another spell is cast upon the boss that inflicts dmgi of damage per second upon him until the end of the game.During the battle the actions per second are performed in the following order: first the boss gets the damage from all the spells cast upon him, then he regenerates reg of health (at the same time he can’t have more than max of health), then the player may use another scroll (no more than one per second).The boss is considered to be defeated if at the end of a second he has nonpositive ( ≤ 0) amount of health.Help Petya to determine whether he can win with the set of scrolls available to him and if he can, determine the minimal number of seconds he needs to do it.

The first line contains three integers N, max and reg (1 ≤ N, max, reg ≤ 1000) –– the amount of scrolls and the parameters of the boss. The next N lines contain two integers powi and dmgi each — the parameters of the i-th scroll (0 ≤ powi ≤ 100, 1 ≤ dmgi ≤ 2000).

In case Petya can’t complete this level, output in the single line NO. Otherwise, output on the first line YES. On the second line output the minimal time after which the boss can be defeated and the number of used scrolls. In the next lines for each used scroll output space-separated number of seconds passed from the start of the battle to the moment the scroll was used and the number of the scroll. Scrolls are numbered starting from 1 in the input order. The first scroll is considered to be available to be used after 0 seconds. Output scrolls in the order they were used. It is not allowed to use scrolls after the boss is defeated.

class Scroll:
	def __init__(self, id, power, damage):
		self.id = id
		self.power = power
		self.damage = damage
		self.active = False

num_scrolls, boss_max, regenerate = map(int, input().split())
scrolls = [Scroll(i+1, *map(int, input().split())) for i in range(num_scrolls)]
scrolls.sort(key = lambda scroll: -scroll.damage)
boss_curr = boss_max
scroll_damage = 0
active_scrolls = []
tick = 0
while True:
	boss_prev = boss_curr
	boss_curr -= scroll_damage
	boss_curr = min(boss_max, boss_curr + regenerate)
	if boss_curr <= 0:
		print('YES')
		print(tick, len(active_scrolls))
		for scroll in active_scrolls:
			print(scroll.start, scroll.id)
		break
	found = False
	for scroll in scrolls:
		if not scroll.active and 100*boss_curr <= scroll.power*boss_max:
			scroll.start = tick
			scroll.active = True
			active_scrolls.append(scroll)
			scroll_damage += scroll.damage
			found = True
			break
	if not found and boss_curr >= boss_prev:
		print('NO')
		break
	tick += 1


#include<stdio.h>
long int index[100010];
void quicksort(long int x[],long int first,long int last){
    long int pivot,j,temp,i,temp1;

     if(first<last){
         pivot=first;
         i=first;
         j=last;

         while(i<j){
             while(x[i]<=x[pivot]&&i<last)
                 i++;
             while(x[j]>x[pivot])
                 j--;
             if(i<j){
                 temp=x[i];
                 temp1=index[i];
                 index[i]=index[j];
                  x[i]=x[j];
                  x[j]=temp;
                  index[j]=temp1;
             }
         }

         temp=x[pivot];
         temp1=index[pivot];
         x[pivot]=x[j];
         index[pivot]=index[j];
         x[j]=temp;
         index[j]=temp1;
         quicksort(x,first,j-1);
         quicksort(x,j+1,last);

    }
}

int main()
{
    long int n,arr[100010],i,c1,c2;
    scanf("%ld",&n);
    for(i=0;i<n;i++)
    {
        scanf("%ld",&arr[i]);
        index[i]=i+1;
    }
    quicksort(arr,0,n-1);
    if(n%2==0)
    {
        c1=n/2;
        c2=n/2;
    }
    else
    {
        c1=n/2+1;
        c2=n/2;
    }
    printf("%ld\n",c1);
    for(i=n-1;i>=0;i-=2)
        printf("%ld\n",index[i]);
    printf("%ld\n",c2);
    for(i=n-2;i>=0;i-=2)
        printf("%ld\n",index[i]);
    return 0;
}

Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:  Each boy plays for exactly one team (x + y = n).  The sizes of teams differ in no more than one (|x - y| ≤ 1).  The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.

The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills.

On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.

NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled.

#include <stdio.h>
struct play{
    int skill;
    int position;
};
typedef struct play player;

typedef int (*compfn)(const void*, const void*);

int compare(struct play *, struct play *);

int main(){
    int n, x=0, y=0;
    int i, j;

    scanf("%d", &n);

    player players[n];

    for(i=0; i<n; i++){
        scanf("%d", &players[i].skill);
        players[i].position=i+1;
    }

/*    for(i=0; i<n; i++){
        printf("\nSkill: %d\tPosition: %d\n", players[i].skill, players[i].position);
    }
*/
    //printf("\n");
/*        int aux1, aux2;
        for(i=0; i<n; i++){
         for(j = i+1 ; j<n; j++){
             if(players[j].skill < players[i].skill){
                aux1 = players[j].position;
                aux2 = players[j].skill;
                players[j].position = players[i].position;
                players[j].skill = players[i].skill;
                players[i].position = aux1;
                players[i].skill = aux2;
             }
         }
      }
*/

   qsort((void *)&players, n, sizeof(struct play),(compfn)compare);

/*    for(i=0; i<n; i++){
        printf("\nSkill: %d\tPosition: %d\n", players[i].skill, players[i].position);
    }
*/
    if(n%2==0){
        x = n/2;
        y = n/2;
    }else{
        x= (n/2)+1;
        y= n/2;
    }

    printf("%d\n", x);
    for(i=0; i<n; i+=2){
        printf("%d ", players[i].position);
    }

    printf("\n%d\n", y);
    for(i=1; i<n; i+=2){
        printf("%d ", players[i].position);
    }

    return 0;
}

/*void sortStruct(int ){
      for(i=0; i<n; i++){
         for(j = i+1 ; j<n; j++){
             if(players[j].skill < players[i].skill){
                aux1 = players[j].position;
                aux2 = players[j].skill;
                players[j].position = players[i].position;
                players[j].skill = players[i].skill;
                players[i].position = aux1;
                players[i].skill = aux2;
             }
         }
      }
}
*/

int compare(struct play *elem1, struct play *elem2)
{
   if ( elem1->skill < elem2->skill)
      return -1;

   else if (elem1->skill > elem2->skill)
      return 1;

   else
      return 0;
}


//Spelling Check - Codeforces
#include <stdio.h>
#include <string.h>
#include <string>
char s1[1000001], s2[1000001];
int n, counta, cantidad, resp2[1000001];
int main(){
    scanf("%s %s",s1+1,s2+1);
    n=strlen(s1+1);
    for(int i=n;i>=1;--i)
        if (i==1||s1[i]!=s2[i - 1]){
            counta = n - i;
            break;
        }
    for(int i=1;i<=n;++i){
        if(counta>=n-i){
            resp2[++cantidad] = i;
        }
        if(i==n||s1[i]!=s2[i]){
            break;
        }
    }
    printf("%d\n", cantidad);
    if(cantidad!=0){
        for (int i=1;i<=cantidad;++i){
            printf("%d ", resp2[i]);
        }
    }
    return 0;
}

Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete?

The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one.

In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0.

[{'input': 'abdrakadabra\r\nabrakadabra\r\n', 'output': ['1\r\n3 ']}, {'input': 'aa\r\na\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'competition\r\ncodeforces\r\n', 'output': ['0\r\n']}, {'input': 'ab\r\na\r\n', 'output': ['1\r\n2 ']}, {'input': 'bb\r\nb\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'aab\r\nab\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'aabb\r\nabb\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'babaacaacaa\r\nbbaacaacaa\r\n', 'output': ['1\r\n2 ']}, {'input': 'bccaabbcccc\r\nbccaabcccc\r\n', 'output': ['2\r\n6 7 ']}, {'input': 'ababcaabaaa\r\nabacaabaaa\r\n', 'output': ['1\r\n4 ']}, {'input': 'cccacaccacb\r\ncccacaccac\r\n', 'output': ['1\r\n11 ']}, {'input': 'aaaaaaaaaaa\r\naaaaaaaaaa\r\n', 'output': ['11\r\n1 2 3 4 5 6 7 8 9 10 11 ']}, {'input': 'lcaaxcbcjca\r\nccaaacccca\r\n', 'output': ['0\r\n']}, {'input': 'babbbtaamba\r\nbabbbaabba\r\n', 'output': ['0\r\n']}, {'input': 'xdfxmcnzpch\r\nazvotghvtk\r\n', 'output': ['0\r\n']}, {'input': 'ki\r\nb\r\n', 'output': ['0\r\n']}, {'input': 'vct\r\nie\r\n', 'output': ['0\r\n']}, {'input': 'feee\r\nsnl\r\n', 'output': ['0\r\n']}, {'input': 'cbxxxxzvks\r\ncbxxxzvks\r\n', 'output': ['4\r\n3 4 5 6 ']}, {'input': 'qybldcgfhdhhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur\r\nqybldcgfhdhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur\r\n', 'output': ['10\r\n11 12 13 14 15 16 17 18 19 20 ']}]


#include <stdio.h>

int main(void)
{
		int n;
		scanf("%d ", &n);

		int n_arr[n];
		for (int i = 0; i < n; i++)
				scanf("%d ", &n_arr[i]);

		int m;
		scanf("%d ", &m);

		int m_arr[n];
		for (int i = 0; i < m; i++)
				scanf("%d ", &m_arr[i]);

		int max = 0, num_max = 0;
		for (int i = 0; i < n; i++)
				for (int j = m - 1; j >= 0; j--)
						if (m_arr[j]%n_arr[i] == 0){
								if (m_arr[j]/n_arr[i] == max){
										num_max++;
								}

								if (m_arr[j]/n_arr[i] > max){
										num_max = 1;
										max = m_arr[j]/n_arr[i];
										break;
								}
						}

		printf("%d\n", num_max);
}

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

The first input line contains integer n (1 ≤ n ≤ 50) — the number of stars on the bicycle's pedal axle. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 104) in the order of strict increasing. The third input line contains integer m (1 ≤ m ≤ 50) — the number of stars on the rear wheel axle. The fourth line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 104) in the order of strict increasing. It is guaranteed that there exists at least one gear (i, j), that its gear ratio is an integer. The numbers on the lines are separated by spaces.

Print the number of "integer" gears with the maximum ratio among all "integer" gears.

NoteIn the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them a1 = 4, b1 = 12, and for the other a2 = 5, b3 = 15.


#include <stdio.h>

int main()
{
     int n, i;
     long long x, y, a;

     scanf("%d %I64d %I64d", &n, &x, &y);

     a = y - n + 1;

     if (a >= 0 && a * a + n - 1 >= x) {
	  for (i = 0; i < n - 1; i++) puts("1");
	  printf("%I64d\n", a);
     } else {
	  puts("-1");
     }

     return 0;
}

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

The first line contains three space-separated integers n, x and y (1 ≤ n ≤ 105, 1 ≤ x ≤ 1012, 1 ≤ y ≤ 106). Please do not use the %lld specificator to read or write 64-bit integers in С++. It is recommended to use cin, cout streams or the %I64d specificator.

Print n positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them.

#include<stdio.h>

typedef unsigned long long int u_long;

int main(void) {
	u_long x, y, n;
	u_long i, j, k;
	u_long sum = 0;
	scanf("%llu %llu %llu", &n, &x, &y);
	if(y < n) {
		puts("-1");
		return 0;
	}
	sum = (y - n + 1) * (y - n + 1);
	sum += (n - 1);
	if(sum < x) {
		puts("-1");
	} else {
		printf("%llu\n", (y - n + 1));
		for(i = 1; i < n; i++) puts("1");
	}
	return 0;
}


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

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of chocolate bar wrappings that brought points to Vasya. The second line contains space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ 109). The third line contains 5 integers a, b, c, d, e (1 ≤ a < b < c < d < e ≤ 109) — the prizes' costs.

Print on the first line 5 integers, separated by a space — the number of mugs, towels, bags, bicycles and cars that Vasya has got, respectively. On the second line print a single integer — the number of points Vasya will have left after all operations of exchange are completed. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample Vasya gets 3 points after eating the first chocolate bar. Then he exchanges 2 points and gets a mug. Vasya wins a bag after eating the second chocolate bar. Then he wins a towel after eating the third chocolate bar. After all chocolate bars 3 - 2 + 10 - 10 + 4 - 4 = 1 points remains.


#include<stdio.h>

int main(void)
{
  int flag=1,count=0,hold,n,k,i,rank[100];
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++)
    scanf("%d",rank+i);
  while(flag)
  {
    hold=-1;  flag=0;
    for(i=0;i<n;i++)
      if(rank[i]<k && rank[i]!=hold)
      {
        hold=rank[i];
        rank[i]+=1;
        flag=1;
      }
    if(flag)  count++;
  }
  printf("%d\n",count);
  return 0;
}

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

The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ ai ≤ k).

Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.

NoteIn the first example the ranks will be raised in the following manner:1 2 2 3  →  2 2 3 4  →  2 3 4 4  →  3 4 4 4  →  4 4 4 4Thus totals to 4 training sessions that require 4 golden coins.

#include <stdio.h>

int Cnt[101];

int main()
{
    int n, k, a, ans = 0;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a);
        ++Cnt[a];
    }
    while(1) {
        char update = 0;
        for(int i = k - 1; i >= 1; --i) {
            if(Cnt[i]) {
                --Cnt[i];
                ++Cnt[i + 1];
                update = 1;
            }
        }
        if(!update) {
            break;
        }
        ans += update;
    }
    printf("%d\n", ans);
    return 0;
}


#include <stdio.h>

int i, x, y, n, m, succs[101][100], nsuccs[101], seen[101], cedge[101], ncycles ;

int dfs(int root, int from)
{
	int k ;

	seen[root] = 1 ;

	for (k = 0 ; k < nsuccs[root] ; k++)
	{
		if (!seen[succs[root][k]])
		{
			if (dfs(succs[root][k], root))
			{
				return 1 ;
			}
		}
		else if (succs[root][k] != from && cedge[root] != succs[root][k])
		{
			cedge[succs[root][k]] = root ;

			if (++ncycles == 2)
			{
				return 1 ;
			}
		}
	}

	return 0 ;
}

int main(void)
{
	scanf("%d %d", &n, &m) ;

	for (i = 0 ; i < m ; i++)
	{
		scanf("%d %d", &x, &y) ;

		succs[x][nsuccs[x]++] = y ;
		succs[y][nsuccs[y]++] = x ;
	}

	if (n != m)
	{
		printf("NO") ;
	}
	else
	{
		dfs(1, 0) ;

		printf((ncycles == 1 ? "FHTAGN!" : "NO")) ;
	}

	return 0 ;
}

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

The first line contains two integers — the number of vertices n and the number of edges m of the graph (1 ≤ n ≤ 100, 0 ≤ m ≤ ). Each of the following m lines contains a pair of integers x and y, that show that an edge exists between vertices x and y (1 ≤ x, y ≤ n, x ≠ y). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.

Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.

NoteLet us denote as a simple cycle a set of v vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., v - 1 and v, v and 1.A tree is a connected undirected graph consisting of n vertices and n - 1 edges (n > 0).A rooted tree is a tree where one vertex is selected to be the root.

#include <stdio.h>

#include <stdlib.h>

typedef struct link1
{
    int d;
    struct link1 *next;
}node;

node *a[100005];
int n,s,d;
int top=-1;
//int front,rear;
int visited[100005];
//int q[100000][2];

void print()
{
    int i;
    for(i=1;i<=n;i++)
    {
        node *v=a[i];
        while(v!=NULL)
        {
            printf("%d ",v->d);
            v=v->next;
        }
        printf("\n");
    }
}

int parent[100005];

int find(int i)
{
    while(parent[i]!=-1)
    {
        i=parent[i];
    }
     return i;
}

void Union(int x,int y)
{
    parent[find(x)]=find(y);
}

void dfs(node *v,int depth)
{
  //  flag1=0;
    visited[v->d]=1;
  //  printf("%d  ",v->d);
    if(v->next==NULL)
        return;
    else
    {
        v=v->next;
        while(v!=NULL)
        {
            int r=v->d;
            if(visited[r]==0)
            {
                visited[r]=1;
                dfs(a[r],depth+1);
            }
            v=v->next;
            // dfs(v->next->next,depth+1);
        }
    }
}

int main()
{
    int m,i,x,y;
    scanf("%d %d",&n,&m);
    //    a=(node *)malloc(n*sizeof(node));
    for(i=1;i<=n;i++)
    {
        a[i]=(node *)malloc(sizeof(node));
        a[i]->d=i;
        a[i]->next=NULL;
        visited[i]=0;
        parent[i]=-1;
    }
    int flag=0;
    for(i=0;i<m;i++)
    {
        scanf("%d %d",&x,&y);
        if(find(x)==find(y))
        {
            flag=1;
            //printf("cycle");
        }
        else
            Union(x,y);
        node *p=(node *)malloc(sizeof(node));
        node *q=(node *)malloc(sizeof(node));
        q->d=x;
        q->next=a[y]->next;
        p->d=y;
        p->next=a[x]->next;
        a[x]->next=p;
        a[y]->next=q;
      //  print();
    }
    if(n!=m)
    {
        printf("NO\n");
        return 0;
    }
    dfs(a[1],0);
  /*  for(i=0;i<=n;i++)
    {
        parent[i]=-1;
    }*/
    for(i=1;i<=n;i++)
    {
        if(visited[i]!=1)
        {
            printf("NO\n");
            return 0;
        }
    //    printf("parent[%d]=%d\n",i,find(i));
    }
    if(flag==1)
        printf("FHTAGN!\n");
    else
        printf("NO\n");
    return 0;
}


#include<stdio.h>

int main()
{
    int i,j,n;
    int max=0,a=0,k;
    scanf("%d",&n);

    int arr[n],arr1[n];
    for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
    if(n==1)
        printf("%d",n);
    else
    {
    for(i=0;i<n;i++)
    {
        if(max<a)
            max=a;
        a=0;
        for(k=i;k>=0;k--)  //before
        {
            if(arr[k]>=arr[k-1])
            {
                ++a;
            }
            else
                break;
        }
        for(j=i;j<n;j++)  //after
        {
            if(arr[j]>=arr[j+1])
                ++a;
                else
                    break;
        }
    }
    printf("%d",max+1);
    }

return 0;
}

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

The first line contains a positive integer n (1 ≤ n ≤ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.

Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, m = 0, S = 0, j, x, large = 0;
    scanf("%d", &n);
    int array[n], arr[n];
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &array[i]);
    }
    if(n == 1)
    {
        printf("1");
        return 0;
    }
    else if(n == 2)
    {
        printf("2");
        return 0;
    }
    else
    {
        if(array[0] > array[1])
        {
            arr[m] = 0;
            m++;
            //printf("%d\n", m);
            S = 1;
        }
        if(array[n - 1] > array[n - 2])
        {
            arr[m] = n - 1;
            m++;
            //printf("%d\n", m);
            S = 1;
        }
        for(int i = 1; i < n - 1; i++)
        {
            if(array[i - 1] < array[i])
            {
                //printf("%d\n", i);
                //printf("%d\n", array[i]);
                //printf("%d\n", array[i + 1]);
                while(array[i] == array[i + 1])
                {
                    if(i == n - 1)
                    {
                        arr[m] = n - 1;
                        //printf("%d\n", m);
                        m++;
                    }
                    i++;
                }
                //printf("%d\n", i);
                if(array[i] > array[i + 1])
                {
                    arr[m] = i;
                    m++;
                    //printf("%d\n", m);
                    S = 1;
                }
            }
        }
        if(S == 0 || m == 1)
        {
            printf("%d", n);
            return 0;
        }
        else
        {
            for(int i = 0; i < m; i++)
            {
                if(arr[i] == 0)
                {
                    j = 0; x = 1;
                    while(!(array[j] < array[j + 1]))
                    {
                        x++;
                        if(j == n - 2)
                        {
                            break;
                        }
                        j++;
                    }
                    if(x > large)
                    {
                        large = x;
                    }
                }
                else if(arr[i] == n - 1)
                {
                    j = n - 1; x = 1;
                    while(!(array[j] < array[j - 1]))
                    {
                        x++;
                        if(j == 1)
                        {
                            break;
                        }
                        j--;
                    }
                    if(x > large)
                    {
                        large = x;
                    }
                }
                else
                {
                    j = arr[i]; x = 1;
                    while(!(array[j] < array[j + 1]))
                    {
                        x++;
                        if(j == n - 2)
                        {
                            break;
                        }
                        j++;
                    }
                    j = arr[i];
                    while(!(array[j] < array[j - 1]))
                    {
                        x++;
                        if(j == 1)
                        {
                            break;
                        }
                        j--;
                    }
                    if(x > large)
                    {
                        large = x;
                    }
                }
            }
        }
    }
    printf("%d", large);
    //for(int i = 0; i < m; i++)
    //{
      //  printf("%d ", arr[i]);
    //}
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M  100000
struct card{
       int f;
       int b;
       int g;
       }card[M];
struct color{
       int c;
       int num;
       int same;
       }front[M];
struct color1{
       int c;
       int num;
       }back[M];
int cmp1(const void *a,const void *b){
    struct card *c=(struct card *)a;
    struct card *d=(struct card *)b;
    return c->f-d->f;
}
int cmp2(const void *a,const void *b){
    struct card *c=(struct card *)a;
    struct card *d=(struct card *)b;
    return c->b-d->b;
}
int cmp3(const void *a,const void *b){
    struct color *c=(struct color *)a;
    struct color *d=(struct color *)b;
    return d->num-c->num;
}
int main(){
    int N,i,j,t,k,fnum,bnum,move,min,same,count;
    while(scanf("%d",&N),N){
        memset(card,0,sizeof(card));
        memset(front,0,sizeof(front));
        memset(back,0,sizeof(back));
        for(i=0;i<N;i++){
            scanf("%d %d",&card[i].f,&card[i].b);
            if(card[i].f==card[i].b)card[i].g=1;
            else card[i].g=0;
        }
        qsort(card,N,sizeof(card[0]),cmp1);
        t=1;j=0;
        for(i=1;i<N;i++)
            if(card[i].f==card[i-1].f) t++;
            else {
                front[j].c=card[i-1].f;
                front[j].num=t;
                same=0;
                for(k=i-t;k<i;k++){if(card[k].g==1)same++;}
                front[j++].same=same;
                t=1;
            }
        front[j].c=card[i-1].f;front[j].num=t;
        fnum=j+1;
        qsort(card,N,sizeof(card[0]),cmp2);
        t=1;j=0;
        for(i=1;i<N;i++)
            if(card[i].b==card[i-1].b)   t++;
            else {
                back[j].c=card[i-1].b;
                back[j++].num=t;
                t=1;
            }
        back[j].c=card[i].b;back[j].num=t;
        bnum=j+1;
        qsort(front,fnum,sizeof(front[0]),cmp3);
        min=N;move=N;
        for(i=0;i<fnum;i++){
            if(front[i].num>=(N+1)/2){ move=0;break;}
            else{
                for(j=0;j<bnum;j++)
                    if(back[j].c==front[i].c){
                        count=back[j].num+front[i].num-front[i].same;
                        if(count>=(N+1)/2)move=back[j].num-front[i].same;
                        if(move<min)min=move;
                        break;
                    }
            }
        }
        if(move==0)printf("%d\n",move);
        else if(move==N)printf("-1\n");
        else printf("%d\n",min);
    }
    return 0;
}

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

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces.

On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.

NoteIn the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.

#include<stdio.h>
#include<stdlib.h>
#define LEN 2000200
#define LENC 200010
#define MAX 10000000
typedef struct{
	int c;
	int n;
     }Node;
typedef struct {
	int c;
	int f;//front or down 1 or 0
    }Color;
Color C[LENC];
int lenc,lena,lenb;
Node A[LEN],B[LEN];
int cmpc(const void *a, const void *b){
	Color *a0 = (Color*)a;
	Color *b0 = (Color*)b;
	return a0 -> c - b0 -> c;}
int Min(int a, int b){
	if(a < b)return a;
	return b;}
int main(){
	int i, j,n;
	while(scanf("%d", &n) != EOF){
		int c1, c2;
		lenc = 0;
		for(i = 0; i < n; i++){
			scanf("%d%d", &c1, &c2);
			C[lenc].c = c1;
			C[lenc++].f = 1;
			if(c2 != c1){
				C[lenc].c = c2;
				C[lenc++].f = 0;
			}
		}
		qsort(C, lenc, sizeof(Color), cmpc);
		lenb = 0;
		for(i = 0; i < lenc; i++)
			if(C[i].f == 1){
				B[0].c = C[i].c;
				B[0].n = 1;
				lenb = 1;
				i++;
				break;
			}
		for(; i < lenc; i++){
			if(C[i].f == 1){
				if(C[i].c == B[lenb - 1].c)	B[lenb - 1].n++;
				else{
					B[lenb].c = C[i].c;
					B[lenb++].n = 1;
				}
			}
		}
		lena = 0;A[0].c = C[0].c;A[0].n = 1;lena = 1;
		for(i = 1; i < lenc; i++){
			if(C[i].c == A[lena - 1].c)	A[lena - 1].n++;
			else{
					A[lena].c = C[i].c;
					A[lena++].n = 1;
				}
         }
		int psb = 0;int mint = MAX;
		for(i = 0; i < lena; i++){
			int t = (n + 1) / 2;
			if(A[i].n >= t){
				int ii = 0;int jj = lenb - 1;int find = 0;int mid;
				while(ii <= jj){
					mid = (ii + jj) / 2;
					if(B[mid].c == A[i].c){
						find = 1;
						break;
					}
					else if(A[i].c < B[mid].c)	jj = mid - 1;
					else	ii = mid + 1;
				}
				if(find == 1){
					int k = t - B[mid].n;
					mint = Min(mint, k);
				}
				else	mint = Min(mint, t);
				psb = 1;
			}
		}
		if(psb == 1){
			if(mint >= 0)	printf("%d\n", mint);
			else 	printf("0\n");
		}
		else printf("-1\n");
	}
return 0;
}


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

The first line contains a pair of integers n, b (2 ≤ n ≤ 100, 1 ≤ b ≤ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the current volume of drink in the i-th mug.

Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique. Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.

#include<stdio.h>
int main(){
	int i,n,sum=0,t,arr[105];
	double s;
	scanf("%d%d",&n,&t);
	s=t;
	for(i=1;i<=n;i++){
		scanf("%d",&arr[i]);
		s+=arr[i];
	}
	s/=n;
	for(i=1;i<=n;i++)
		if((s-arr[i])<0){
			printf("-1");
			return 0;
		}
	for(i=1;i<=n;i++)
		printf("%f\n",s-arr[i]);
	return 0;
}


#include<stdio.h>
int main()
{
int n,i,a,b,sum=0;
scanf("%d",&n);
int ar[n-1];
for(i=0;i<n-1;i++)
{
    scanf("%d",&ar[i]);
}
scanf("%d%d",&a,&b);
if(b-a==1){

    printf("%d",ar[a-1]);
    return 0;
}
else{
for(i=a-1;i<b-a;i++)
    sum+=ar[i];
    printf("%d",sum);
    return 0;
}
}

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

The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated.

Print the single number which is the number of years that Vasya needs to rise from rank a to rank b.

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


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

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.

Print a single integer — the minimum possible capacity of the reading room.

NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.

 #include<stdio.h>
int main(){
    int n,d, max= 0, prev=0, a[1000001]={0};
    char c;
    scanf("%d",&n);
    while( n-- ){
        getchar();
        scanf("%c%d",&c,&d);
        if( c == '+' )
        {
            a[d] = 1;
            prev++;
        }
        else if( a[d] == 1 ){
            a[d] = 0;
            prev--;
        }
        else{
            max++;
        }
        if( prev > max )
            max = prev;
    }
    printf("%d\n",max);
    return 0;
}


#include<stdio.h>
int main() {
	int a, b, n,i, j, c;

	freopen("input.txt", "r", stdin);
	scanf("%d %d %d",&n, &a, &b);
	if (a * b < n) {
		printf("-1"); return 0;
	}
	for (i = 0; i < a; i++) {
		for (j = 0; j < b; j++) {
			if (i & 1) c = (i + 1)*b - j;
			else c = i * b + j + 1;
			if (c > n) printf("0 ");
			else printf("%d ", c);
		}
		putchar('\n');
	}
	return 0;
}

There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.New parliament assembly hall is a rectangle consisting of a × b chairs — a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hallWe know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.

The first line of the input contains three integers n, a and b (1 ≤ n ≤ 10 000, 1 ≤ a, b ≤ 100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.

If there is no way to assigns seats to parliamentarians in a proper way print -1. Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.

NoteIn the first sample there are many other possible solutions. For example, 3 20 1and 2 13 0The following assignment 3 21 0is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void main()
{
    int i,n,N;
    char chaine[101];
    int len =0;
    scanf("%d",&n);
    while(len!=n)
    {
        scanf("%d",&N);
        sprintf(chaine,"%d",N);
        len =strlen(chaine);
    }
    if ((len%2)!=0)
    {
        for(i=0;i<(len-3);i=i+2)
        {
           printf("%c%c-",chaine[i],chaine[i+1]);
        }
        printf("%c%c%c",chaine[len-3],chaine[len-2],chaine[len-1]);
    }
    else
    {
        for(i=0;i<(len-2);i=i+2)
        {
            printf("%c%c-",chaine[i],chaine[i+1]);
        }
        printf("%c%c",chaine[len-2],chaine[len-1]);
    }
}

Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.

The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups.

Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.


#include<stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int t=1, k=1;
    while(k<n)
    {
        t = (t+k)%n;
        printf("%d ", t);
        k++;
    }
    return 0;
}

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

The first line contains integer n (2 ≤ n ≤ 100) which indicates the number of kids in the circle.

In the single line print n - 1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.

#include <stdio.h>

int main() {
    int n ,x=1;
    scanf("%d",&n);
    for (int i=1; i<n; i++)
    {
        x=x+i;
        if(x>n)
        {
            x=x-n;
        }

        printf("%d ",x);

    }
    return 0;
}


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

The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).

NoteThe first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.

//Created by Pratik Paras Mandlecha
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
long long int p=1000000007;
long long int power(long long int x,long long int y)
{
	long long int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%p;
		y=y>>1;
		x = (x*x) % p;
	}
	return res;
}
int main()
{
	long long int n;
	scanf("%lld",&n);
	if(n==0) printf("1");
	else printf("%lld",(((power(2,n-1)%1000000007)+(2*power(4,n-1)%1000000007))%1000000007));

	return 0;
}


#include<stdio.h>
int main()
{

	int type,hr,min,i;

	scanf("%d",&type);
	scanf("%02d:%02d",&hr,&min);
	if(hr==0)
		hr=1;

	 if(min==60)
		 min=0;
		 else if(min>60)
		min=min%10;
	if(type==12)
	{
		if(hr>12)
			hr=hr%10;
		if(hr==0)
			hr=10;
	}
		else
		{
			if(hr>23)
				hr=hr%10;
			}

	printf("%02d:%02d",hr,min);
				return 0;
}

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

The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.

The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.

/* Problem: 722A - Broken Clock */
/* Solver: Gusztav Szmolik */

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main ()
    {
    unsigned short tf;
    unsigned char tm[7];
    unsigned short h;
    unsigned short m;

    if (scanf("%hu",&tf) != 1)
        return -1;
    if (tf != 12 && tf != 24)
        return -1;
    if (scanf("%6s",tm) != 1)
        return -1;
    if (strlen(tm) != 5)
        return -1;
    if (!isdigit(tm[0]) || !isdigit(tm[1]) || !isdigit(tm[3]) || !isdigit(tm[4]))
        return -1;
    if (tm[2] != ':')
        return -1;
    h = 10*(tm[0]-'0')+tm[1]-'0';
    m = 10*(tm[3]-'0')+tm[4]-'0';
    if (tf == 12 && !h)
        printf ("01:");
    else if (tf == 12 && h > 12)
        {
        if (tm[1] == '0')
            printf ("10:");
        else
            printf ("0%c:",tm[1]);
        }
    else if (tf == 24 && h > 23)
        printf ("0%c:",tm[1]);
    else
        printf ("%c%c:",tm[0],tm[1]);
    if (m > 59)
        printf ("0%c\n",tm[4]);
    else
        printf ("%c%c\n",tm[3],tm[4]);
    return 0;
    }


#include<stdio.h>
#include<math.h>
int main()
{
    long long int a,b,n,i,t=0,c,d;
    scanf("%I64d %I64d %I64d",&a,&b,&n);
    for(i=1;i<=10;i++){
        c=a*pow(i,n);
        d=a*pow(-i,n);
        if(c==b){
            t=i;
            break;
        }
        else if(d==b){
            t=-i;
            break;
        }
    }
    if(t==0){
        printf("No solution\n");
    }
    else{
        printf("%I64d\n",t);
    }
    return 0;
}

A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient X — the coefficient of income growth during one year. This coefficient should satisfy the equation:A·Xn = B.Surely, the king is not going to do this job by himself, and demands you to find such number X.It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient X must be integers. The number X may be zero or negative.

The input contains three integers A, B, n (|A|, |B| ≤ 1000, 1 ≤ n ≤ 10).

Output the required integer coefficient X, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.

#include <stdio.h>
 int power(int x, int n) {
 int index, temp = x;
 for(index = 1 ; index < n ; index++)
  temp = x*temp;
 return temp;
}
int main() {
int a,b,n,result,negorpos=1,x;
scanf("%d %d %d",&a,&b,&n);
if(b==0 && a==0){
 printf("5");
 return 0;
}
if(a==0&&b!=0) {
  printf("No solution");
  return 0;
}

if(((a<0)&&(b>0)&&(n%2==1))||((a>0)&&(b<0)&&(n%2==1)))
   negorpos=-1;
if(a*b<0 && n%2==0) {
   printf("No solution");
   return 0;
}

if(a<0) a=-a;
if(b<0) b=-b;

 for(x =0 ; x <= 1000 ; x++){
    if(power(x,n)*a ==b) {
         printf("%d",x*negorpos);
         return 0;
    }
    if(power(x,n)*a > b){
           printf("No solution");
           return 0;
    }
 }
 return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SORT(a,n) qsort(a,n,sizeof(int),intcmp)
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define fiI64(a,v)                   memset(a, v, sizeof a)
int intcmp(const void *f,const void *s)
{
   return (*(int *)f-*(int *)s);
}
int gcd(int a,int b){ return ((b==0)?a:gcd(b,a%b));}

#define MAX 100
#define MODBY 1000000007

typedef long long int I64d;
typedef long double Lf;
I64d table[20][10];
int checkspl(I64d a)
{
   int last=a%10,first=a%10;
   while(a){
      first=a%10;
      a/=10;
   }
   return (first==last);
}
void preprocess()
{
   int i,j;
   for(i=1;i<10;++i){ table[0][i]=0;
      table[1][i]=table[2][i]=1;
   }
   int s=10;
   for(i=3;i<20;++i,s*=10)
      for(j=1;j<10;++j)
         table[i][j]=s;
}
I64d myatoi(char *s,int from,int tiI64)
{
   I64d ans=0;
   int i;
   for(i=from;i<=tiI64;++i)
      ans=ans*10+(s[i]-'0');
   return ans;
}
I64d count(char *s)
{
   int len=strlen(s),i,j;
   I64d ans=0;
   if(len==1) return *s-'0';

   ans=1+myatoi(s,1,len-2);

   for(j=1;j<len;++j)
      for(i=1;i<10;++i)
         ans+=table[j][i];
   for(i=1;i<s[0]-'0';++i)
      ans+=table[len][i];
   return ans;
}
int main()
{
   char a[MAX],b[MAX];
   I64d aint,bint;
   preprocess();
   sl(aint);aint--;
   while(!checkspl(aint)) aint--;
   sl(bint);
   while(!checkspl(bint)) bint--;
   sprintf(a,"%I64d",aint);
   sprintf(b,"%I64d",bint);
   printf("%I64d\n",count(b)-count(a));
   return 0;
}

The Little Elephant very much loves sums on intervals.This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.Help him and count the number of described numbers x for a given pair l and r.

The single line contains a pair of integers l and r (1 ≤ l ≤ r ≤ 1018) — the boundaries of the interval. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

On a single line print a single integer — the answer to the problem.

NoteIn the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.

#include<stdio.h>
long long d[20];
void compute()
{
    d[0]=9;
    d[1]=18;
    long long s=10,i;
    for(i=2;i<20;++i)
    {
        d[i]=9*s+d[i-1];
        s*=10;
    }
}
long long find(long long x)
{
    if(x<10)
        return x;
    long long ans=0;
    ans=x/10+9;
    return ans;
}
int main()
{
    long long l,r,x,ans=0,rem;
    scanf("%lld%lld",&l,&r);
    x=r;
    rem=x%10;
    while(x>=10)
        x/=10;
    if(x>rem)
        ans-=1;
    x=l-1;
    rem=(l-1)%10;
    while(x>=10)
        x/=10;
    if(x>rem)
        ans+=1;
    compute();
    ans-=find(l-1);
    ans+=find(r);
    printf("%lld",ans);
    return 0;
}


[12:43 p. m., 8/10/2019] Adri: #include<stdio.h>

int main() {
	int n,m,l;
	int a[100],am=0,suma;

		scanf("%d%d",&n,&l);

			for(int i=0;i<n;i++)
				scanf("%d",&a[i]);

			for(int i=l;i<=100;i++) {
				suma = 0;

				for(int j=0;j<n;j++)
					suma += (a[j]/i)*i;
				if(suma>am)
					am = suma;
			}

	printf("%d\n",am);
	return 0;
}

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

The first output line contains two space-separated integers n and l (1 ≤ n, l ≤ 100). They are the number of stripes in the warehouse and the minimal acceptable length of a blind stripe in bourlemeters. The second line contains space-separated n integers ai. They are the lengths of initial stripes in bourlemeters (1 ≤ ai ≤ 100).

Print the single number — the maximal area of the window in square bourlemeters that can be completely covered. If no window with a positive area that can be covered completely without breaking any of the given rules exist, then print the single number 0.

NoteIn the first sample test the required window is 2 × 4 in size and the blinds for it consist of 4 parts, each 2 bourlemeters long. One of the parts is the initial stripe with the length of 2, the other one is a part of a cut stripe with the length of 3 and the two remaining stripes are parts of a stripe with the length of 4 cut in halves.

#include<stdio.h>

int a[101][2];
main()
{int i,j,k,sum,save,n,len,store,max;
max=0;
sum=0;
save=0;
scanf("%d%d",&n,&len);
for(i=1;i<=n;i++)
{
scanf("%d",&store);
if(store>max)
    max=store;
a[store][0]++;
}

for(i=len;i<=max;i++)
{
  sum=0;
  for(j=i;j<=max;j++)
     sum=sum+(j/i)*(a[j][0]);

//printf("%d\n",i*sum);
   if(i*sum>save){
    // printf("%d  %d\n",i,sum);

     save=i*sum;
   }

}

printf("%d",save);

}


#include<stdio.h>
#include<string.h>

int main(void){
  char str[524288];
  int i,j,k,l;
  int length,check,flg=0;
  fgets(str,sizeof(str)/sizeof(char),stdin);

  l=strlen(str);
  str[l-1]='\0';
  l=strlen(str);
  check=0;
  if(str[0]=='.'){
    puts("NO");
    return 0;
  }

  for(i=0;i<l;i++){
    ++check;
    if(str[i]=='.'){
      if(check<=-2){
	puts("NO");
	return 0;
      }
      check=-3;
    }
    if(check>8){
      puts("NO");
      return 0;
    }
  }
  if(check>0){
    puts("NO");
    return 0;
  }
  puts("YES");

  for(i=0;i<l;i+=j+flg+1){
    for(j=0;str[i+j]!='.';j++) putchar(str[i+j]);
    putchar('.');
    for(k=j+1;str[i+k]!='.';k++){
      if(str[i+k]=='\0'){
	for(check=i+j+1;check<l;check++) putchar(str[check]);
	putchar('\n');
	return 0;
      }
    }
    length=k;
    if(length==2) flg=1;
    else if(length==3) flg=2;
    else flg=3;
    for(k=0;k<flg;k++) putchar(str[i+j+k+1]);
    putchar('\n');
  }
  return 0;
}

Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:   name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;  ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters. For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.

The input data consists of a single string s, its length is from 1 to 4·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').

In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them. If the solution does not exist, then print in a single line "NO" (without the quotes).

#include<stdio.h>
#include<string.h>
int main()
{
	char s[400001];
	int i;
	int a[400000];
	char c;
	int m=0,count=0;
	int f1=0,f2=0;
	int t=0;
	while(1)
	{
		scanf("%c",&c);
		if(c=='\n')
			break;
		else
			s[i]=c;
//		printf("%d\n",count);
		if(s[i]=='.')
		{
//			printf("%d %d\n",count,f1);
			a[m]=count;
			m++;
			if(f1==0&&(count>8||count<=0))
			{t=1;f1=1;break;}
			else if(f1==1&&count<2||count>11)
			{t=1;break;}
			else count=0;
			if(f1==0)
				f1=1;
		}
		else
			count++;
		i++;
	}
//	printf("%d\n",count);
	if(count<1||count>3)
	t=1;
	int k=0;
	if(t==1||m==0)
		printf("NO\n");
	else
	{
	printf("YES\n");
	a[m]=count;
	m++;
//	for(i=0;i<m;i++)
//		printf("%d\n",a[i]);
	for(i=0;i<m-1;i++)
	{
		if(i==0)
		{
		for(k=0;k<a[i]+1;k++)
			printf("%c",s[k]);
		}
		else
		{
			if(a[i]>=2&&a[i]<=9)
			{printf("%c\n",s[k]);
				k++;
			int till=k+a[i];
			while(k<till)
			{printf("%c",s[k]);
				k++;
			}
			}
			else
			{
				int y=a[i]-8;
				int u;
				for(u=0;u<y;u++)
				{
					printf("%c",s[k]);
					k++;
				}
				printf("\n");
				int till=k+a[i]-y+1;
				while(k<till)
				{printf("%c",s[k]);
				k++;
				}
			}
		}
//		printf("%d\n",k);
	}
	int e=k+a[i];
	while(k<e)
	{	printf("%c",s[k]
		      );
		k++;
	}
	printf("\n");
	}
	return 0;
}

[{'input': 'read.meexample.txtb.cpp\r\n', 'output': ['YES\r\nread.m\r\neexample.t\r\nxtb.cpp\r\n']}, {'input': 'version.infontldrcontestdata.zip\r\n', 'output': ['NO\r\n']}, {'input': 'thisis.text.txt\r\n', 'output': ['YES\r\nthisis.t\r\next.txt\r\n']}, {'input': 'oops.t\r\n', 'output': ['YES\r\noops.t\r\n']}, {'input': 'thisislongfilename\r\n', 'output': ['NO\r\n']}, {'input': 'double..dot\r\n', 'output': ['NO\r\n']}, {'input': 'one.one.one.one.one.one.one.one.one.one\r\n', 'output': ['YES\r\none.o\r\nne.o\r\nne.o\r\nne.o\r\nne.o\r\nne.o\r\nne.o\r\nne.o\r\nne.one\r\n']}, {'input': '.\r\n', 'output': ['NO\r\n']}, {'input': 'z\r\n', 'output': ['NO\r\n']}, {'input': 'a.\r\n', 'output': ['NO\r\n']}, {'input': '.a\r\n', 'output': ['NO\r\n']}, {'input': 'za\r\n', 'output': ['NO\r\n']}, {'input': '..\r\n', 'output': ['NO\r\n']}, {'input': 'xlq\r\n', 'output': ['NO\r\n']}, {'input': '.r.\r\n', 'output': ['NO\r\n']}, {'input': 'ulmc\r\n', 'output': ['NO\r\n']}, {'input': 'nja.\r\n', 'output': ['NO\r\n']}, {'input': 't..kz\r\n', 'output': ['NO\r\n']}, {'input': 'twaha\r\n', 'output': ['NO\r\n']}, {'input': 'm..dw.\r\n', 'output': ['NO\r\n']}, {'input': 'utsvfg.\r\n', 'output': ['NO\r\n']}, {'input': '.we.voae\r\n', 'output': ['NO\r\n']}, {'input': 'kw.gkcxk.\r\n', 'output': ['NO\r\n']}, {'input': '.c.v.hpehh\r\n', 'output': ['NO\r\n']}, {'input': 'akymwh\r\n', 'output': ['NO\r\n']}, {'input': 'jx.lqv.\r\n', 'output': ['NO\r\n']}, {'input': 'qkwtq.zw\r\n', 'output': ['YES\r\nqkwtq.zw\r\n']}, {'input': 'yxwvlk..b\r\n', 'output': ['NO\r\n']}, {'input': 'ph..qlr.pt\r\n', 'output': ['NO\r\n']}, {'input': 'cab.ab.bac\r\n', 'output': ['YES\r\ncab.a\r\nb.bac\r\n']}, {'input': 'badaba.ae\r\n', 'output': ['YES\r\nbadaba.ae\r\n']}, {'input': 'badabaca.mor\r\n', 'output': ['YES\r\nbadabaca.mor\r\n']}, {'input': 'bae.a\r\n', 'output': ['YES\r\nbae.a\r\n']}, {'input': 'b.baba.ebpbac.iabaeabac.abab.adabacaba.ahcggibij.adaacab.ebaba.aa.abacaba.dacabada.daqjcpc.jadab.dab\r\n', 'output': ['YES\r\nb.b\r\naba.e\r\nbpbac.i\r\nabaeabac.a\r\nbab.a\r\ndabacaba.a\r\nhcggibij.a\r\ndaacab.e\r\nbaba.a\r\na.a\r\nbacaba.d\r\nacabada.d\r\naqjcpc.j\r\nadab.dab\r\n']}, {'input': '.ab\r\n', 'output': ['NO\r\n']}, {'input': 'aa.aa.aaaabbbbccc.ddd.ee\r\n', 'output': ['YES\r\naa.a\r\na.aaa\r\nabbbbccc.d\r\ndd.ee\r\n']}, {'input': 'a.aaaa\r\n', 'output': ['NO\r\n']}, {'input': 'aaaaread.meexample.txtb.cpp\r\n', 'output': ['YES\r\naaaaread.m\r\neexample.t\r\nxtb.cpp\r\n']}, {'input': 'abcdabcd.a\r\n', 'output': ['YES\r\nabcdabcd.a\r\n']}, {'input': 'qwertyuio.qwe\r\n', 'output': ['NO\r\n']}, {'input': 'asd.\r\n', 'output': ['NO\r\n']}, {'input': 'aaaaaaaa.\r\n', 'output': ['NO\r\n']}, {'input': 'a.txtaaaaaaaaa.txt\r\n', 'output': ['NO\r\n']}, {'input': '.abcde.cpp\r\n', 'output': ['NO\r\n']}, {'input': '.abc.cpp\r\n', 'output': ['NO\r\n']}, {'input': 'abcdefgh.aaaabcdefgh.bbb\r\n', 'output': ['YES\r\nabcdefgh.aaa\r\nabcdefgh.bbb\r\n']}, {'input': 'filename.exe\r\n', 'output': ['YES\r\nfilename.exe\r\n']}, {'input': '.abcd.cpp\r\n', 'output': ['NO\r\n']}, {'input': 'abc.bcdabcdabcd.abc\r\n', 'output': ['YES\r\nabc.bcd\r\nabcdabcd.abc\r\n']}, {'input': 'abc.abcde\r\n', 'output': ['NO\r\n']}, {'input': 'a.cp\r\n', 'output': ['YES\r\na.cp\r\n']}, {'input': 'a.b.c\r\n', 'output': ['NO\r\n']}, {'input': '.ha\r\n', 'output': ['NO\r\n']}, {'input': 'a.a.a.a\r\n', 'output': ['NO\r\n']}, {'input': 'a.a.a\r\n', 'output': ['NO\r\n']}, {'input': 'qwertyui.cp\r\n', 'output': ['YES\r\nqwertyui.cp\r\n']}, {'input': 'ss.aaaaaaaaaaaa.aa\r\n', 'output': ['NO\r\n']}, {'input': 'name.extnamename.ext\r\n', 'output': ['YES\r\nname.ext\r\nnamename.ext\r\n']}, {'input': '.aaaa.aaa\r\n', 'output': ['NO\r\n']}, {'input': 'aaaaaaaaaaaaaaaaaaaa.a\r\n', 'output': ['NO\r\n']}, {'input': '.filena.exe\r\n', 'output': ['NO\r\n']}, {'input': 'a.aaaaaaaaaaa.a\r\n', 'output': ['YES\r\na.aaa\r\naaaaaaaa.a\r\n']}, {'input': '.aa.w\r\n', 'output': ['NO\r\n']}]


#include <stdio.h>
#include <stdlib.h>

int main()
{

    int n,m;
    scanf("%d %d",&n,&m);
    char words[n][m];
    int bools[n][m];
    int i=0,j=0;
    for(i=0;i<n;i++)
    {
        bools[i][j]=0;
        getchar();
        for(j=0;j<m;j++)
        {
            scanf("%c",&words[i][j]);

        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            int flag=0;
            if(bools[i][j]==1)
                continue;
            char z=words[i][j];
            int c=0;
            for(c=0;c<n||c<m;c++)
            {
                if(c<n&&words[c][j]==z&&c!=i)
                {
                    bools[c][j]=1;
                    flag=1;
                }
                if(c<m&&words[i][c]==z&&c!=j)
                {
                    bools[i][c]=1;
                    flag=1;
                }
            }
            if(!flag)
                printf("%c",z);
        }
    }
    return 0;
}

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

The first line contains two integers n and m (1 ≤ n, m ≤ 100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.

Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.

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