Once a walrus professor Plato asked his programming students to perform the following practical task. The students had to implement such a data structure that would support a convex hull on some set of points S. The input to the program had q queries of two types: 1. Add a point with coordinates (x, y) into the set S. Note that in this case the convex hull of S could have changed, and could have remained the same. 2. Say whether a point with coordinates (x, y) belongs to an area limited by the convex hull, including the border. All the students coped with the task. What about you?

The first line contains an integer q (4 ≤ q ≤ 105).  Then follow q lines in the following way: "t x y", where t is the query type (1 or 2), and (x, y) are the coordinates of the point ( - 106 ≤ x, y ≤ 106, x and y are integers).  There is at least one query of type 2. It is guaranteed that the three queries of the first type follow first and the points given in the queries form a non-degenerative triangle. Also all the points added in S are distinct.

For each query of the second type print one string containing "YES", if the point lies inside the convex hull or on its border. Otherwise, print "NO".

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

#define X	1000000
#define Q	100000

long long cross2(long long x1, long long y1, long long x2, long long y2) {
	return x1 * y2 - x2 * y1;
}

struct P {
	int x, y;
} *pl, *pr;

typedef struct P *T[(X + X + 1) * 4];

long long cross(struct P *o, struct P *p, struct P *q) {
	return cross2(p->x - o->x, p->y - o->y, q->x - o->x, q->y - o->y);
}

struct P *min(struct P *p, struct P *q) {
	return p != NULL && q != NULL ? (p->x < q->x ? p : q) : (p == NULL ? q : p);
}

struct P *max(struct P *p, struct P *q) {
	return p != NULL && q != NULL ? (p->x > q->x ? p : q) : (p == NULL ? q : p);
}

void update(T tl, T tr, int k, int l, int r, int x, struct P *p) {
	int m;

	if (r - l == 1) {
		tl[k] = tr[k] = p;
		return;
	}
	m = (l + r) / 2;
	if (x < m)
		update(tl, tr, k * 2 + 1, l, m, x, p);
	else
		update(tl, tr, k * 2 + 2, m, r, x, p);
	tr[k] = min(tr[k * 2 + 1], tr[k * 2 + 2]);
	tl[k] = max(tl[k * 2 + 1], tl[k * 2 + 2]);
}

void query(T tl, T tr, int k, int l, int r, int x) {
	int m;

	if (r - l == 1) {
		pl = max(pl, tl[k]);
		pr = min(pr, tr[k]);
		return;
	}
	m = (l + r) / 2;
	if (x < m) {
		pr = min(pr, tr[k * 2 + 2]);
		query(tl, tr, k * 2 + 1, l, m, x);
	} else {
		pl = max(pl, tl[k * 2 + 1]);
		query(tl, tr, k * 2 + 2, m, r, x);
	}
}

int query_(T tl_up, T tr_up, T tl_dn, T tr_dn, struct P *p, int insert) {
	struct P *q, *pl_, *pr_;
	int inside = 1;

	pl = pr = NULL;
	query(tl_up, tr_up, 0, 0, X + X + 1, p->x);
	pl_ = pl, pr_ = pr;
	if ((pl == pr
				&& (pl == NULL || pl->y < p->y))
			|| (pl != pr
				&& (pl == NULL || pr == NULL || cross(pl, p, pr) < 0))) {
		if (insert) {
			for (q = pl_; q && q->x > 0; q = pl) {
				pl = pr = NULL;
				query(tl_up, tr_up, 0, 0, X + X + 1, q->x - 1);
				if (!pl || cross(pl, q, p) < 0)
					break;
				update(tl_up, tr_up, 0, 0, X + X + 1, q->x, NULL);
			}
			for (q = pr_; q && q->x < X + X; q = pr) {
				pl = pr = NULL;
				query(tl_up, tr_up, 0, 0, X + X + 1, q->x + 1);
				if (!pr || cross(p, q, pr) < 0)
					break;
				update(tl_up, tr_up, 0, 0, X + X + 1, q->x, NULL);
			}
			update(tl_up, tr_up, 0, 0, X + X + 1, p->x, p);
		}
		inside = 0;
	}
	pl = pr = NULL;
	query(tl_dn, tr_dn, 0, 0, X + X + 1, p->x);
	pl_ = pl, pr_ = pr;
	if ((pl == pr
				&& (pl == NULL || pl->y > p->y))
			|| (pl != pr
				&& (pl == NULL || pr == NULL || cross(pl, p, pr) > 0))) {
		if (insert) {
			for (q = pl_; q && q->x > 0; q = pl) {
				pl = pr = NULL;
				query(tl_dn, tr_dn, 0, 0, X + X + 1, q->x - 1);
				if (!pl || cross(pl, q, p) > 0)
					break;
				update(tl_dn, tr_dn, 0, 0, X + X + 1, q->x, NULL);
			}
			for (q = pr_; q && q->x < X + X; q = pr) {
				pl = pr = NULL;
				query(tl_dn, tr_dn, 0, 0, X + X + 1, q->x + 1);
				if (!pr || cross(p, q, pr) > 0)
					break;
				update(tl_dn, tr_dn, 0, 0, X + X + 1, q->x, NULL);
			}
			update(tl_dn, tr_dn, 0, 0, X + X + 1, p->x, p);
		}
		inside = 0;
	}
	return inside;
}

int main() {
	static T tl_up, tr_up, tl_dn, tr_dn;
	int q;

	scanf("%d", &q);
	while (q-- > 0) {
		struct P *p = malloc(sizeof *p);
		int t;

		scanf("%d%d%d", &t, &p->x, &p->y);
		p->x += X;
		if (t == 1)
			query_(tl_up, tr_up, tl_dn, tr_dn, p, 1);
		else
			printf(query_(tl_up, tr_up, tl_dn, tr_dn, p, 0) ? "YES\n" : "NO\n");
	}
	return 0;
}


In Walrusland public transport tickets are characterized by two integers: by the number of the series and by the number of the ticket in the series. Let the series number be represented by a and the ticket number — by b, then a ticket is described by the ordered pair of numbers (a, b). The walruses believe that a ticket is lucky if a * b = rev(a) * rev(b). The function rev(x) reverses a number written in the decimal system, at that the leading zeroes disappear. For example, rev(12343) = 34321, rev(1200) = 21.The Public Transport Management Committee wants to release x series, each containing y tickets, so that at least w lucky tickets were released and the total number of released tickets (x * y) were minimum. The series are numbered from 1 to x inclusive. The tickets in each series are numbered from 1 to y inclusive. The Transport Committee cannot release more than maxx series and more than maxy tickets in one series.

The first line contains three integers maxx, maxy, w (1 ≤ maxx, maxy ≤ 105, 1 ≤ w ≤ 107).

Print on a single line two space-separated numbers, the x and the y. If there are several possible variants, print any of them. If such x and y do not exist, print a single number  - 1.

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define ll long long
#define N 100001

#define EPS 1e-10
void doubleIntSort(double d[],int m[],int s){int i,j,r;double k1,k2,t;if(s<=1)return;k1=(d[0]+d[s-1])/2.0;k2=k1+EPS;k1-=EPS;i=-1;j=s;for(;;){while(d[++i]<k1);while(d[--j]>k2);if(i>=j)break;t=d[i];d[i]=d[j];d[j]=t;r=m[i];m[i]=m[j];m[j]=r;}doubleIntSort(d,m,i);doubleIntSort(d+j+1,m+j+1,s-j-1);}

typedef struct struct_vector_int{ int size,mem; int *d; }intVector;
intVector intVectorNull(){ intVector v; v.size=v.mem=0; return v; }

void intVectorMemoryExpand(intVector *v){
  int i, *t, m;
  m=v->mem*2; if(m<5) m=5;
  t=(int*)malloc(m*sizeof(int));
  rep(i,v->size) t[i]=v->d[i];
  if(v->mem) free(v->d);
  v->d=t; v->mem=m;
}

void intVectorPushBack(intVector *v,int add){
  if(v->mem==v->size) intVectorMemoryExpand(v);
  v->d[(v->size)++] = add;
}

int rev(int n){
  int i, res=0;
  char buf[100];
  sprintf(buf,"%d",n);
  for(i=0;;i++) if(buf[i]<' ') break;
  while(i--) res=res*10+buf[i]-'0';
  return res;
}

int REV[N];
double rat[N]; int ind[N];
intVector edge[N];

int main(){
  int i,j,k,l,m,n;
  int useX[N];
  int x, y;
  int st, ed, add=0;
  ll resX, resY, nowX, nowY, now;

  rep(i,N) REV[i] = rev(i);
  REP(i,1,N) rat[i] = REV[i]/(double)i, ind[i]=i;

  doubleIntSort(rat+1,ind+1,N-1);
  rep(i,N) edge[i] = intVectorNull();

  ed=N-1;
  REP(st,1,N){
    while( ed>=1 && rat[st]*rat[ed] > 1+EPS) ed--;
    if(ed==0) break;
    for(i=ed;i>=1;i--){
      if(rat[st]*rat[i] < 1-EPS) break;
      intVectorPushBack(edge+ind[st],ind[i]); add++;
    }
  }

  while(scanf("%d%d%d",&x,&y,&n)==3){
    resX = 100000000; resY = 100000000;

    rep(i,x+1) useX[i]=0;

    nowX = x; now = 0;
    REP(nowY,1,y+1){
      rep(i,edge[nowY].size) if(1<=edge[nowY].d[i] && edge[nowY].d[i]<=nowX) now++, useX[edge[nowY].d[i]]++;

      while(now >= n){
        if(resX*resY > nowX*nowY) resX=nowX, resY=nowY;
        now -= useX[nowX]; nowX--;
      }
    }

    if(resX > x) puts("-1"); else printf("%d %d\n",(int)resX,(int)resY);
  }

  return 0;
}


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

The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood.

Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO".

#include <stdio.h>

int knights[100500], n;

char check(int k) {
    int start, j;
    if(n / k < 3)
        return 0;
    for(start = 0; start < k; start++) {
        char isHappy = 1;
        for(j = start; isHappy && j < n; j += k) {
            if(knights[j] == 0) {
                isHappy = 0;
            }
        }
        if(isHappy)
            return 1;
    }
    return 0;
}

int main() {
    int i, j;
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%d", knights + i);
    }
    for(i = 1; (long long)(i) * i <= n; i++) {
        if(n % i)
            continue;
        if(check(i) || check(n / i)) {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}


Vasya plays The Elder Trolls III: Morrowindows. He has a huge list of items in the inventory, however, there is no limits on the size of things. Vasya does not know the total amount of items but he is sure that are not more than x and not less than 2 items in his inventory. A new patch for the game appeared to view inventory in n different modes. Displaying in mode i is a partition of all inventory items on pages, each of which (except for maybe the last one) shows exactly ai items. In addition, each mode shows how many pages bi is in a complete list. Great! Perhaps this information will be enough for Vasya to find the required number. Moreover, it is very interesting, what is the fewest number of modes in which Vasya can see inventory to determine the number of items in it?Vasya cannot use the information that was received while looking on inventory in some mode for selection of next actions. I. e. Vasya chooses some set of modes first, and then sees all the results and determines the size.Knowing the number of ai, x and assuming that Vasya is very smart, check whether he can uniquely determine the number of items in his inventory, and how many modes he will need to do that if he knows numbers ai, x and he is able to know number bi after viewing items in mode i.

The first line contains two integers n and x (0 ≤ n ≤ 105, 2 ≤ x ≤ 109). The second line contains integers ai (1 ≤ ai ≤ 109). Some numbers among all ai may be equal.

Output the fewest amount of modes required to uniquely determine amount of items in the inventory. If there is no solution output  - 1.

NoteIn the second example Vasya is not able to determine items count uniquely because 3 items, as well as 4 items, can be displayed on two pages.

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define N 2000000

void intSort(int d[],int s){int i=-1,j=s,k,t;if(s<=1)return;k=(d[0]+d[s-1])/2;for(;;){while(d[++i]<k);while(d[--j]>k);if(i>=j)break;t=d[i];d[i]=d[j];d[j]=t;}intSort(d,i);intSort(d+j+1,s-j-1);}

void eratosthenes(int n,int p[]){
  int i,j;
  p[0]=p[1]=0; REP(i,2,n) p[i]=1;
  for(i=4;i<n;i+=2) p[i]=0;
  for(i=3;i*i<n;i+=2) if(p[i]) for(j=i;i*j<n;j+=2) p[i*j]=0;
}

int p[N];
int in[200000];

int main(){
  int i,j,k,l,m,n,x;
  int st, res;

  eratosthenes(N,p);

  while(scanf("%d%d",&n,&x)==2){
    rep(i,n) scanf("%d",in+i);
    intSort(in,n);

    if(x==2){ puts("0"); continue; }
    if(n && in[0]==1){ puts("1"); continue; }

    if(x >= N-10){ puts("-1"); continue; }

    res = 0;
    st = 0;
    REP(i,2,x) if(p[i]){
      while(st < n && in[st] < i) st++;
      if(st==n || in[st]>i){ res=-1; break; }

      res++;
    }

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

  return 0;
}


Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't.This problem is similar to a standard problem but it has a different format and constraints.In the standard problem you are given an array of integers, and you have to find one or more consecutive elements in this array where their sum is the maximum possible sum.But in this problem you are given n small arrays, and you will create one big array from the concatenation of one or more instances of the small arrays (each small array could occur more than once). The big array will be given as an array of indexes (1-based) of the small arrays, and the concatenation should be done in the same order as in this array. Then you should apply the standard problem mentioned above on the resulting big array.For example let's suppose that the small arrays are {1, 6, -2}, {3, 3} and {-5, 1}. And the indexes in the big array are {2, 3, 1, 3}. So the actual values in the big array after formatting it as concatenation of the small arrays will be {3, 3, -5, 1, 1, 6, -2, -5, 1}. In this example the maximum sum is 9.Can you help Mostafa solve this problem?

The first line contains two integers n and m, n is the number of the small arrays (1 ≤ n ≤ 50), and m is the number of indexes in the big array (1 ≤ m ≤ 250000). Then follow n lines, the i-th line starts with one integer l which is the size of the i-th array (1 ≤ l ≤ 5000), followed by l integers each one will be greater than or equal -1000 and less than or equal 1000. The last line contains m integers which are the indexes in the big array, and you should concatenate the small arrays in the same order, and each index will be greater than or equal to 1 and less than or equal to n. The small arrays are numbered from 1 to n in the same order as given in the input. Some of the given small arrays may not be used in big array. Note, that the array is very big. So if you try to build it straightforwardly, you will probably get time or/and memory limit exceeded.

Print one line containing the maximum sum in the big array after formatting it as described above. You must choose at least one element for the sum, i. e. it cannot be empty. Please, do not use %lld specificator to write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d).

#include <limits.h>
#include <stdio.h>

int main() {
	int i, k, n, m, a;
	long long l, s, r, t, max;
	static long long ll[50], ss[50], rr[50], tt[50], mm[50];

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		scanf("%d", &k);
		l = s = r = t = 0, max = INT_MIN;
		while (k-- > 0) {
			scanf("%d", &a);
			s += a;
			if (l < s)
				l = s;
			r = r + a < 0 ? 0 : r + a;
			if (t < r)
				t = r;
			if (max < a)
				max = a;
		}
		ll[i] = l;
		ss[i] = s;
		rr[i] = r;
		tt[i] = t;
		mm[i] = max;
	}
	max = INT_MIN;
	r = t = 0;
	while (m-- > 0) {
		scanf("%d", &i);
		i--;
		if (t < r + ll[i])
			t = r + ll[i];
		r = r + ss[i] > rr[i] ? r + ss[i] : rr[i];
		if (t < tt[i])
			t = tt[i];
		if (max < mm[i])
			max = mm[i];
	}
	printf("%lld\n", t == 0 ? max : t);
	return 0;
}


After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly.However, Ciel feels n strings b1, b2, ... , bn are really boring, and unfortunately she dislikes to remember a string that contains a boring substring. To make the thing worse, what she can remember is only the contiguous substring of s.Determine the longest contiguous substring of s that does not contain any boring string, so that she can remember the longest part of Taro's response.

In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≤ n ≤ 10).  Next n lines, there is a string bi (1 ≤ i ≤ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English alphabet (both lowercase and uppercase) or a underscore ('_') or a digit. Assume that these strings are case-sensitive.

Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several solutions, output any.

NoteIn the first sample, the solution is traight_alon.In the second sample, the solution is an empty string, so the output can be «0 0», «0 1», «0 2», and so on.In the third sample, the solution is either nagio or oisii.

Go_straight_along_this_street
5
str
long
tree
biginteger
ellipse

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXN 100055
#define MAXM 15

struct node
{
	char s[MAXM];
	int len;
};

int main ()
{
	static char s[MAXN];
	memset(s,0,sizeof(s));
	scanf("%s\n",s);
	int N = strlen(s);
	int M;
	scanf("%d\n",&M);
	static struct node data[MAXM];
	int i;
	for (i = 0; i < M; i++)
	{
		scanf("%s\n",data[i].s);
		data[i].len = strlen(data[i].s);
	}
	int res = 0;
	int resw = 0;
	int min = N;
	int j, k, temp;
	char flag;
	for (i = N-1; i >= 0; i--)
	{
		for (j = 0; j < M; j++)
		{
			flag = 1;
			for (k = 0; k < data[j].len; k++)
			{
				if (s[i+k] != data[j].s[k])
				{
					flag = 0;
					break;
				}
			}
			if (flag)
			{
				temp = i + data[j].len - 1;
				if (temp < min) min = temp;
			}
		}
		temp = min - i;
		if (temp > res)
		{
			res = temp;
			resw = i;
		}
	}
	printf("%d %d\n",res,resw);
	return 0;
}

[{'input': 'Go_straight_along_this_street\r\n5\r\nstr\r\nlong\r\ntree\r\nbiginteger\r\nellipse\r\n', 'output': ['12 4\r\n']}, {'input': 'IhaveNoIdea\r\n9\r\nI\r\nh\r\na\r\nv\r\ne\r\nN\r\no\r\nI\r\nd\r\n', 'output': ['0 0\r\n']}, {'input': 'unagioisii\r\n2\r\nioi\r\nunagi\r\n', 'output': ['5 5\r\n']}, {'input': 'abcabcabcabc\r\n3\r\nabcabca\r\nbcab\r\ncabc\r\n', 'output': ['4 6\r\n']}, {'input': 'ThankYouForParticipatingRound71\r\n6\r\nForP\r\noun\r\nnkYouForP\r\nTha\r\nouForP\r\nound7\r\n', 'output': ['18 9\r\n']}, {'input': 'WishYourSolutionPassesFinalTests\r\n10\r\nrSoluti\r\ninal\r\nolutionPas\r\nassesFin\r\nourSo\r\nonP\r\nWishYourSo\r\nsFinalTes\r\nhYourSolut\r\nonPas\r\n', 'output': ['9 15\r\n']}, {'input': '9\r\n1\r\n9\r\n', 'output': ['0 0\r\n']}, {'input': 'Z\r\n1\r\na\r\n', 'output': ['1 0\r\n']}, {'input': '12abcdefghijklmnop\r\n10\r\nabcd\r\nabc\r\nab\r\na\r\nklmn\r\nlmn\r\nmn\r\nn\r\nop\r\n12\r\n', 'output': ['12 3\r\n']}, {'input': '12abcdefghijklmnop\r\n10\r\na\r\nop\r\nab\r\nabc\r\nabcd\r\nn\r\nmn\r\n12\r\nlmn\r\nklmn\r\n', 'output': ['12 3\r\n']}, {'input': '12abcdefghijklmnop\r\n10\r\nlmn\r\nabc\r\na\r\nklmn\r\nn\r\nabcd\r\nop\r\nmn\r\nab\r\n12\r\n', 'output': ['12 3\r\n']}, {'input': 'x5x5\r\n10\r\nx5\r\nx5x\r\nx5x5\r\nx5\r\nx5\r\nQyBa0yZO_c\r\n_troGKxtGQ\r\nRItOLVC3ok\r\niD_57rFYR1\r\nvZhgXwTnE4\r\n', 'output': ['2 1\r\n']}, {'input': 'aaaay\r\n10\r\naa\r\naa\r\naaa\r\nay\r\naaay\r\ndltfBoU4nF\r\nYhImrXw62Y\r\nwswb4v7CRb\r\npjxxEE3S26\r\nwxDxW1MRaI\r\n', 'output': ['1 4\r\n']}, {'input': 'iiiiii\r\n10\r\nii\r\niiii\r\niiiii\r\niii\r\niiii\r\n5avjcwIsDh\r\nGgiVQ9ylRz\r\newWmNAJAL9\r\nk83baq5H2U\r\nXRX3fJ4dH8\r\n', 'output': ['1 5\r\n']}, {'input': 'ffBBfBB\r\n10\r\nBBfB\r\nffBBfB\r\nffBBf\r\nffBBf\r\nBfB\r\n1ehoxM6CU8\r\ntvB4q05iuU\r\nEYGkY6VxQO\r\nbKbE2ajjBW\r\nhqTKbQUZds\r\n', 'output': ['4 1\r\n']}, {'input': 'aaUUUUaa\r\n10\r\naUUU\r\naaU\r\naUU\r\nUUUU\r\nUU\r\neV1R6e2tCQ\r\nmwseAsylFZ\r\njkfXnCVagR\r\nRGPm9O09J8\r\nVBRpGUFrDB\r\n', 'output': ['3 5\r\n']}, {'input': '1111e1e1e\r\n10\r\n11\r\n1111e\r\n1111\r\ne1e1e\r\n1e1\r\npuCrQxcVPh\r\nfnbEroh3w4\r\nyie11ihNIi\r\n2_23hx3yX9\r\noPKXwByQLT\r\n', 'output': ['3 6\r\n']}, {'input': 'aMaMaMMaaM\r\n10\r\nMMaaM\r\nMMaaM\r\naa\r\naMaMMaa\r\nMaMa\r\nWoEVf7UuGQ\r\n2q8cm0_WfI\r\nZR63WSVBlC\r\ndtO9nmkXsc\r\ntHL2amBqOS\r\n', 'output': ['6 2\r\n']}, {'input': 'NNNIIIIIINN\r\n10\r\nNNIIIIIIN\r\nIIIINN\r\nIIIINN\r\nNNIIIII\r\nNNII\r\nlHJxS_HfkO\r\nPsss2tjeao\r\nY4Adt_8FXb\r\nkc9mq2vWmZ\r\nVJYusUjoTq\r\n', 'output': ['8 2\r\n']}, {'input': 'cCCcCCCcCccc\r\n10\r\ncC\r\nCCcCCCcCc\r\nCCcC\r\ncCc\r\ncCCC\r\npUKBhDtW8W\r\n0ap4vlgGej\r\nk059r28XMJ\r\nySQTZIOz3r\r\nFHn5rVpM8G\r\n', 'output': ['4 8\r\n']}, {'input': '7hh77hhhhhh7h\r\n10\r\nhhhh7\r\nhh77hhhhh\r\n7hhhhh\r\nhh7\r\nh77hhhhhh7\r\nC_t1uIxLWp\r\nHwH5EkVGCt\r\nyUgWASGwfR\r\nRfah5Fa12E\r\nS9CmGvTVKM\r\n', 'output': ['7 2\r\n']}, {'input': '3cc3\r\n10\r\ncc\r\nc3\r\n3c\r\ncc\r\ncc\r\n3cc3\r\n3cc3\r\n3cc\r\nc3\r\njLnOy3kI3M\r\n', 'output': ['1 3\r\n']}, {'input': '70aa70a\r\n10\r\n70\r\n0aa70\r\n0aa70\r\naa70\r\n70aa\r\n70aa\r\n70aa70a\r\naa7\r\n70aa7\r\nicHuodu1Ux\r\n', 'output': ['3 1\r\n']}, {'input': 'YUYEYEUUEU\r\n10\r\nYEYEUUEU\r\nEUUE\r\nUU\r\nYEYEUUE\r\nYEYE\r\nUU\r\nEY\r\nEYEUU\r\nYEYEUU\r\niBXoTbQ7X3\r\n', 'output': ['4 0\r\n']}, {'input': 'wwwwDwwwwD\r\n10\r\nwD\r\nDwww\r\nwD\r\nDwwww\r\nwwwwD\r\nDww\r\nwD\r\nwwDww\r\nwwww\r\nwwww\r\n', 'output': ['3 6\r\n']}, {'input': '4tg4ttgg47t44tg4ttgg47t4\r\n10\r\n47t44tg4tt\r\nttgg4\r\ng4ttgg47t4\r\ng47t44t\r\ntg4ttg\r\n44tg4ttg\r\nttgg47\r\nt44tg\r\ng47t44tg\r\n4ttgg47t4\r\n', 'output': ['8 5\r\n']}, {'input': 'g0sg00AAA0Asggss0sAg0sg00AAA0Asggss0sA\r\n10\r\nAg0sg00AAA\r\nAsggss\r\nsAg\r\nAsggss0s\r\nggss0sAg\r\nsAg0sg\r\nggss0sA\r\n0sg00AA\r\nAAA0A\r\nAA0\r\n', 'output': ['8 18\r\n']}, {'input': '000gooo0g0vgovvv0oggv0v0go000gooo0g0vgovvv0oggv0v0go\r\n10\r\ngv0v0go\r\n0gooo0g\r\ngooo0g0v\r\no000\r\ngooo0g0v\r\nv0go000go\r\ngo000gooo0\r\nv0v0go00\r\nvv\r\nggv0v0\r\n', 'output': ['10 30\r\n']}, {'input': 'B2KR\r\n10\r\nB2\r\n2KR\r\nB2KR\r\n2K\r\n2KR\r\nKR\r\n2KR\r\nB2KR\r\n2K\r\n2KR\r\n', 'output': ['1 3\r\n']}, {'input': 'dxY_8\r\n10\r\nxY_8\r\ndxY\r\ndx\r\nY_\r\nxY_\r\ndx\r\nxY\r\ndx\r\nxY_8\r\ndxY\r\n', 'output': ['2 3\r\n']}, {'input': 'umi4qX\r\n10\r\nqX\r\num\r\n4qX\r\nqX\r\numi4qX\r\numi4\r\numi4\r\numi4q\r\nmi4q\r\numi4q\r\n', 'output': ['3 2\r\n']}, {'input': '4stuNRe\r\n10\r\n4stu\r\nstuN\r\nstuNRe\r\n4stu\r\ntuNRe\r\nst\r\ntuNR\r\n4stuN\r\ntuN\r\n4stu\r\n', 'output': ['4 3\r\n']}, {'input': 'bTnstTqbTnstTq\r\n10\r\nbTnstTq\r\nnstTqbT\r\nTqbT\r\nbTns\r\nTqbT\r\nTns\r\nTnstT\r\nTnstTqb\r\nnstT\r\nstT\r\n', 'output': ['4 6\r\n']}, {'input': 'Oq02utSVOq02utSV\r\n10\r\n2utSVOq\r\n2utSVO\r\n02utS\r\nSVOq0\r\nut\r\nOq\r\nOq\r\nq02utSVO\r\nOq02utSV\r\nVOq0\r\n', 'output': ['4 9\r\n']}, {'input': 'DpGGt6_wGLPDpGGt6_wGLP\r\n10\r\n6_wGL\r\nGLPDpGG\r\nt6_wG\r\nPDpGGt6_\r\nwGLPDpGGt6\r\n6_\r\n_wGL\r\npGGt6_\r\n6_wGLPD\r\n6_wGLPDpG\r\n', 'output': ['8 9\r\n']}, {'input': '7QTfE4ALvzkzzD4j7QTfE4ALvzkzzD4j\r\n10\r\nvzkzzD4j7\r\nE4AL\r\nTfE4ALv\r\nzzD4j7QT\r\nzkzzD4j7\r\n4AL\r\nj7Q\r\nE4ALvzkzzD\r\nvzkzzD4j\r\n4ALvzk\r\n', 'output': ['9 22\r\n']}, {'input': '6CLznedj88834gqTIhMTPjm_3DbkQpuYkBvU3o55h79ntRqjHTOu3WWNNGLyQSZ_o45mK5mMtRJmWUq2twqWP10OlnDAB1EP2rG\r\n10\r\n834gqTI\r\n_o4\r\nvU3o55h79n\r\nvLwlk3PY7Z\r\nk8PnkBpRYB\r\nqdkB9b_SS2\r\nkY4mBeAdgK\r\nb577cjQiSx\r\nyOFiEkP1sD\r\noYOqd8uuTt\r\n', 'output': ['35 64\r\n']}, {'input': 'JroK3tfp941zeUovVIqCV7Sv2elf6TN8QRl8mhxQWgoQRXOLkcUjK29Ed2gBDR1TLdZeLUi9zJyBayrNlWgW0iPSG26DuJ9QK95\r\n10\r\nroK\r\novVI\r\nLUi9\r\nLUi\r\nTLd\r\nelf6\r\n9zJyBa\r\nDR1\r\ndZe\r\n8mhxQWgo\r\n', 'output': ['27 72\r\n']}, {'input': 'p7B41t9y83IghcJG8zgWzCSATkkvQQhvqm7j_4ffUPbriGW57mbGPzqiuMEmJevfIhX2FNLFBxAGm3vLXRPOdphoWkCquDjAsW9\r\n10\r\n1t9y83\r\nBxAGm3v\r\nG8z\r\nCSATk\r\ncJG\r\nIhX2FNLF\r\nzqiuME\r\np7B4\r\nkkvQ\r\nPbriGW57m\r\n', 'output': ['26 73\r\n']}, {'input': 'r5oW1NW2kr193KwV_eASuj9Jq0q0Kmt2EUD1R72p2nPuxNpIqi7o_KuxldYjLJmiXj93JUxRTniFzKkXxHwXDZCzC76klFnfjAQ\r\n10\r\np2nPuxN\r\n93J\r\nNpIqi7o_K\r\niXj93JUxRT\r\n1NW2kr19\r\n0Kmt2EUD1\r\nTniFzKkXxH\r\niXj93JU\r\nNW2kr19\r\n3KwV_\r\n', 'output': ['26 73\r\n']}, {'input': 'hb\r\n1\r\nAa\r\n', 'output': ['2 0\r\n']}, {'input': 'unagioisiiqqqqqqqqqqqq\r\n2\r\nioi\r\nunagi\r\n', 'output': ['17 5\r\n']}, {'input': 'abababab\r\n3\r\nab\r\nba\r\na\r\n', 'output': ['1 7\r\n']}, {'input': 'abcdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n2\r\nabcd\r\nabcd\r\n', 'output': ['50 1\r\n']}, {'input': 'abababababababababababababababababababababababababababababab\r\n1\r\na\r\n', 'output': ['1 59\r\n']}, {'input': 'abc\r\n2\r\na\r\nb\r\n', 'output': ['1 2\r\n']}, {'input': 'abcde\r\n1\r\nf\r\n', 'output': ['5 0\r\n']}, {'input': 'ahmed\r\n5\r\nahmed\r\nhmed\r\nmed\r\ned\r\nd\r\n', 'output': ['4 0\r\n']}, {'input': 'abc\r\n1\r\nb\r\n', 'output': ['1 2\r\n']}]


After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:   there are exactly a Safety Studies marks,  there are exactly b PE marks,  the total average score in both subjects is maximum. An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).

The first line contains an integer n (2 ≤ n ≤ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 ≤ a, b ≤ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 5), they are Polycarp's marks.

Print the sequence of integers f1, f2, ..., fn, where fi (1 ≤ fi ≤ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically. The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 ≤ j ≤ n) that pi = qi for all 1 ≤ i < j, аnd pj < qj.

NoteIn the first sample the average score in the first subject is equal to 4, and in the second one — to 4.5. The total average score is 8.5.

#include <stdio.h>

#define FOR(index, max_val) for(index = 0; index < max_val; index++)

int array[100010];
int indexes[100010];
int n;

int compare1(const void *a, const void *b) {
  return (array[*(int*)a] != array[*(int*)b])?(array[*(int*)a] - array[*(int*)b]):(*(int*)a - *(int*)b);
}

int compare2(const void *a, const void *b) {
  return (array[*(int*)a] != array[*(int*)b])?( - array[*(int*)a] + array[*(int*)b]):(*(int*)a - *(int*)b);
}

int main() {
  int i, j;
  int a, b;

  scanf("%d%d%d", &n, &a, &b);
  FOR(i, n) {
    scanf("%d", &array[i]);
    indexes[i] = i;
  }

  if(a > b) {
		qsort(indexes, n, sizeof(int), compare1);
  } else if(a < b) {
		qsort(indexes, n, sizeof(int), compare2);
	}
	//FOR(i, n) printf("%d ", indexes[i]);
	//printf("\n");
	for(i = 0; i < a; i++) array[indexes[i]] = 1;
	for(i = a; i < n; i++) array[indexes[i]] = 2;

  FOR(i, n-1) printf("%d ", array[i]);
  printf("%d\n", array[i]);

  return 0;
}


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

First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≤ k ≤ 26).

Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.

NoteIn the first test case string contains 6 different letters, so we don't need to change anything.In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}.In the third test case, it is impossible to make 7 different letters because the length of the string is 6.

using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.UI.WebControls;

namespace Codeforces
{
    class Program : IDisposable
    {
        private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
        private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

        private void Solve()
        {
            var s = Console.ReadLine();
            var k = int.Parse(Console.ReadLine());
            if (k > s.Length)
            {
                Console.WriteLine("impossible");
                return;
            }
            var dict = new Dictionary<char, int>();
            foreach (var ch in s)
            {
                if (dict.ContainsKey(ch))
                {
                    dict[ch]++;
                }
                else
                {
                    dict.Add(ch,1);
                }
            }

            var keysCnt = dict.Keys.Count;
            if (keysCnt >= k)
            {
                Console.WriteLine(0);
                return;
            }
            var diff = k-keysCnt;
            Console.WriteLine(diff);
        }

        int BinarySearch(int[] arr, int q)
        {
            var l = 0;
            var r = arr.Length - 1;
            //int med = -1;
            while (l <= r)
            {
                var med = l + (r - l) / 2;
                if (arr[med] == q)
                {
                    return med;
                }
                if (q < arr[med])
                {
                    r = med - 1;
                }
                else
                {
                    l = med + 1;
                }
            }
            return -1;
        }

        static void Main(string[] args)
        {
            var p = new Program();

            p.Solve();
            //Console.ReadLine();
            //p.Dispose();
            //////////////////////////////

        }

        #region Helpers

        private static int ReadInt()
        {
            return int.Parse(textReader.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(textReader.ReadLine());
        }

        private static int[] ReadIntArray()
        {
            return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        #endregion

        public void Dispose()
        {
            textReader.Close();
            textWriter.Close();
        }
    }
}

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


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.

using System;

namespace AnyTask
{
    class Second
    {
        static void Main(string[] args)
        {
            int newId;
            int n = int.Parse(Console.ReadLine());
            bool[] was = new bool[1234567]; // Was earlier in the library?

            int realtime = 0;
            int answer = 0;

            for (int i = 0; i < n; i++)
            {
                var isAlready = false;
                var s = Console.ReadLine().Split();
                newId = int.Parse(s[1]);
                if (char.Parse(s[0]) == '+')
                {
                    was[newId] = true;
                    realtime++;
                }
                else
                {
                    if (was[newId])
                    {
                        realtime--;
                        was[newId] = false;
                    }
                    else
                        isAlready = true;
                }
                answer = Math.Max(answer, realtime);
                if (isAlready)
                    answer++;
            }
            Console.WriteLine(answer);
        }
    }
}


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.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      int n = input.NextInt();
      int[] s = input.NextToken().Split(':').Select(int.Parse).ToArray();
      if (n == 24)
      {
        if(s[0] > 23)
          s[0] %= 10;
      }
      else
      {
        if (s[0] == 0)
          s[0] = 1;
        else if(s[0] > 12)
        {
          if (s[0] % 10 == 0)
            s[0] = 10;
          else
            s[0] %= 10;
        }
      }
      if (s[1] > 59)
      {
        s[1] %= 10;
      }
      Console.Write($"{s[0].ToString("00")}:{s[1].ToString("00")}");
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int NextInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long NextLong()
    {
      return long.Parse(this.NextToken());
    }

    public double NextDouble()
    {
      return double.Parse(this.NextToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = NextInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = NextLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = NextDouble();
      return a;
    }

    public string NextToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}


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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First < y.First || (x.First == y.First && x.Second > y.Second))
					return -1;
				return 1;
			}
		}

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;
			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		public static int BinarySearch(List<int> list, int value)
		{
			var l = -1;
			var r = list.Count;
			while (r - l > 1)
			{
				var m = (r + l) / 2;
				if (list[m] >= value)
					r = m;
				else
					l = m;
			}

			return r;
		}

		private static void Main()
		{
			var l = ReadListOfInts();
			var n = l[0];
			var a = l[1];
			var b = l[2];

			var ans = new int[a, b];
			for (var i = 0; i < a; ++i)
				for (var j = 0; j < b; ++j)
					ans[i, j] = 0;
			var ct = 1;
			var t = 0;
			for (var i = 0; i < a; ++i)
				for (var j = 0; j < b; ++j)
				{
					if (ct <= n && i % 2 == j % 2)
					{
						ans[i, j] = ct;
						ct += 2;
						t++;
					}
				}
			ct = 2;
			for (var i = 0; i < a; ++i)
				for (var j = 0; j < b; ++j)
				{
					if (ct <= n && i % 2 != j % 2)
					{
						ans[i, j] = ct;
						ct += 2;
						t++;
					}
				}
			if (t != n)
				Console.WriteLine(-1);
			else
			{
				for (var i = 0; i < a; ++i)
				{
					for (var j = 0; j < b; ++j)
					{
						Console.Write("{0} ", ans[i, j]);
					}
					Console.WriteLine();
				}
			}
			Console.ReadLine();
		}
	}
}


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

The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to    "L", if the i-th domino has been pushed to the left;  "R", if the i-th domino has been pushed to the right;  ".", if the i-th domino has not been pushed.  It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".

Output a single integer, the number of the dominoes that remain vertical at the end of the process.

NoteThe first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.In the second example case, all pieces fall down since the first piece topples all the other pieces.In the last example case, a single piece has not been pushed in either direction.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int sum = 0, count = 0;
            bool r = false;
            for (int i = 0; i < n; i++)
            {
                if (s[i] == '.')
                {
                    count++;
                }
                else
                {
                    if (s[i] == 'L')
                    {
                        if (r)
                        {
                            if (count % 2 > 0)
                            {
                                sum++;
                            }
                        }
                        r = false;
                    }
                    else
                    {
                        if (!r)
                        {
                            sum += count;
                        }
                        r = true;
                    }
                    count = 0;
                }
            }
            if (!r)
            {
                sum += count;
            }
            Console.Write(sum);
        }
    }
}


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

The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n).

Print the only number — the minimum number of changes needed to get the permutation.

NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] a = new int[n];
            Input(a);
            Array.Sort(a);
            int count = 0;
            Array.BinarySearch(a, 1);
            for (int i = 0; i < a.Length; i++)
            {
                if (Array.BinarySearch(a, i + 1) < 0)
                    count++;
            }
            Console.WriteLine(count);
        }
        static void Input(int[] l)
        {
            var input = Console.ReadLine().Split();
            for (int j = 0; j < input.Length; j++)
            {
                l[j] = Convert.ToInt32(input[j]);
            }
        }
    }
}


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.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Linq;

namespace Codeforces
{
    internal class Program
    {
        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static int[] ReadIntArray()
        {
            var input = ReadArray();
            var res = new int[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                res[i] = ReadNextInt(input, i);
            }
            return res;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        private static void Main()
        {
            var n = ReadInt();
            var a = new List<int>(ReadIntArray());
            var resF = new StringBuilder();
            var resS = new StringBuilder();
            var f = 0;
            var s = 0;
            var count = 0;
            foreach (var pair in a.Select((e, i)=>new{item =e,index =i + 1}).OrderBy(t=>t.item))
            {
                if(count%2==0)
                {
                    f++;
                    resF.Append(pair.index + " ");
                }
                else
                {
                    s++;
                    resS.Append(pair.index + " ");
                }
                count++;
            }

            Console.WriteLine(f);
            Console.WriteLine(resF.ToString().TrimEnd());
            Console.WriteLine(s);
            Console.WriteLine(resS.ToString().TrimEnd());
        }
    }
}


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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codeforces
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Trim().Split(' ');
            var n = Int32.Parse(input[0]);
            var m = Int32.Parse(input[1]);

            var index = new int[n][];
            var chars = new string[n];

            for (int i = 0; i < n; i++)
            {
                chars[i] = Console.ReadLine();
                index[i] = new int[m];
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (index[i][j] != 1)
                    {
                        for (int k = i + 1; k < n; k++)
                            if (chars[i][j] == chars[k][j])
                                index[i][j] = index[k][j] = 1;
                    }
                    if (index[i][j] != 2)
                    {
                        for (int k = j + 1; k < m; k++)
                            if (chars[i][j] == chars[i][k])
                                index[i][j] = index[i][k] = 2;
                    }
                }
            }
            var output = new List<char>();
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    if (index[i][j] == 0)
                        output.Add(chars[i][j]);
            Console.WriteLine(new string(output.ToArray()));

        }
    }
}

[{'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']}]


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

The first input file line contains integers n and m — the total number of clothing items in the shop and the total number of matching pairs of clothing items (). Next line contains n integers ai (1 ≤ ai ≤ 106) — the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different.

Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).

NoteIn the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.

using System;
using System.Linq;
using System.Collections.Generic;

class Solution
{
    static int Main(string[] args)
    {
        var q = Console.ReadLine().Split().Select(int.Parse).ToList();
        var n = q[0]; var m = q[1];

        int[] p = new int[9999];
        var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int i = 0; i < n; i++)
            p[i + 1] = d[i];

        bool[,] g = new bool[9999, 9999];
        for (int i = 0; i < m; i++)
        {
            string e = Console.ReadLine();
            int x = int.Parse(e.Split()[0]);
            int y = int.Parse(e.Split()[1]);
            g[x, y] = true;
            g[y, x] = true;
        }
        int a = int.MaxValue;
        for (int i = 1; i <= n; i++)
            for (int j = i + 1; j <= n; j++)
                for (int k = j + 1; k <= n; k++)
                    if (g[i, j] && g[j, k] && g[k, i])
                        a = Math.Min(a, p[i] + p[j] + p[k]);
        if (a == int.MaxValue)
            Console.WriteLine(-1);
        else
            Console.WriteLine(a);

        Console.Read();
        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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round80
{
    class B
    {
        static int[] ReadInts() { return Console.ReadLine().Split(' ').Select<string, int>(int.Parse).ToArray(); }

        static bool[] used;
        static List<int>[] e;
        static Stack<int> vis = new Stack<int>();
        static HashSet<int> roots = new HashSet<int>();
        static bool find;
        static int count = 0;

        static int edge(int u, int v) { return Math.Max(u, v) * 1000 + Math.Min(u, v); }

        static bool dfs(int idx)
        {
            int prev = vis.Any() ? vis.Peek() : -1;
            used[idx] = true;
            count++;
            vis.Push(idx);
            //Console.Write("edge: {0}:", idx + 1);
            //foreach (int i in e[idx])                Console.Write(" {0}", i + 1);
            //Console.WriteLine();
            foreach (int i in e[idx])
            {
                //Console.WriteLine("checked: {0} -> {1}", idx+1, i+1);
                if (!used[i])
                {
                    if (!dfs(i))
                        return false;
                }
                else if (prev != i)
                {
                    //Console.WriteLine("prev: {0} != {1}", prev+ 1, i + 1);
                    if (find)
                    {
                        //Console.WriteLine("infind: {0}", roots.Contains(edge(idx, i)));
                        if (!roots.Contains(edge(idx, i)))
                            return false;
                        continue;
                    }
                    find = true;
                    List<int> xs = new List<int>();
                    foreach (var v in vis)
                    {
                        xs.Add(v);
                        if (v == i)
                            break;
                    }
                    for (int j = 0; j < xs.Count; j++)
                    {
                        //Console.WriteLine("check: {0} {1}", xs[j], xs[j+1]);
                        roots.Add(edge(xs[j], xs[(j + 1) % xs.Count]));
                    }
                }
            }
            vis.Pop();
            return true;
        }

        static void Main()
        {
            var xs = ReadInts();
            int n = xs[0],
                m = xs[1];

            used = new bool[n];
            e = new List<int>[n];
            for (int i = 0; i < n; i++)
                e[i] = new List<int>();

            for (int i = 0; i < m; i++)
            {
                xs = ReadInts();
                for (int j = 0; j < 2; j++)
                    e[xs[j] - 1].Add(xs[j ^ 1] - 1);
            }

            Console.WriteLine(dfs(0) && find && count==n ? "FHTAGN!" : "NO");
        }
    }
}


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.

using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

public partial class codeforces85C
{
    public static void C()
    {
        int i;
        string[] given = Console.ReadLine().Split(' ');
        int n = int.Parse(given[0]);
        long x = long.Parse(given[1]);
        int y = int.Parse(given[2]);

        if(y<n) {Console.WriteLine(-1);return ;}
        long[] a = new long[n];
        for (i = 0; i < n; i++) a[i] = 1;
        int rem = y - n;
        a[0] += rem;
        long sum = 0;
        for (i = 0; i < n; i++) sum += a[i] * a[i];
        if (sum < x) {Console.WriteLine(-1); return;}
        for (i = 0; i < n; i++) Console.WriteLine(a[i]);
    }

    public static void Main()
    { C(); }
}


When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. — Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.

The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m () — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names — the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.

The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{
    #region MyIo

    class MyIo : IDisposable
    {
        TextReader inputStream;
        TextWriter outputStream = Console.Out;

        string[] tokens;
        int pointer;

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return int.Parse(NextString());
        }

        public long NextLong()
        {
            return long.Parse(NextString());
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();
        }
    }
    #endregion

    class Program
    {
        #region Program
        MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        static void Main(string[] args)
        {
#if  LOCAL_TEST
            using (MyIo io = new MyIo(new StreamReader("input.txt")))
#else
                using (MyIo io = new MyIo(System.Console.In))
#endif

            {
                new Program(io)
                    .Solve();

#if  LOCAL_TEST
                Console.ReadLine();
#endif
            }
        }

        #endregion

        public class LexComparer : IComparer<string>
        {
            private static readonly LexComparer lc = new LexComparer();

            public static LexComparer Instance
            {
                get
                {
                    return lc;
                }
            }

            public int Compare(string x, string y)
            {
                for (int i = 0; i < Math.Min(x.Length, y.Length); i++)
                {
                    if (x[i] == y[i])
                        continue;

                    return Comparer.Default.Compare(x[i], y[i]);
                }

                return Comparer.Default.Compare(x.Length, y.Length);
            }
        }

        void Solve()
        {
            int n = io.NextInt();
            int m = io.NextInt();

            List<string> names = new List<string>();

            for (int i = 0; i < n; i++)
                names.Add(io.NextString());

            names.Sort(LexComparer.Instance);

            int[] sts = new int[n];

            for (int i = 0; i < n; i++)
                sts[i] = (1 << (n + 1)) - 1;

            for (int i = 0; i < m; i++)
            {
                int x = names.BinarySearch(io.NextString(), LexComparer.Instance);
                int y = names.BinarySearch(io.NextString(), LexComparer.Instance);

                sts[x] &= ~(1 << y);
                sts[y] &= ~(1 << x);
            }

            int di = 0;
            int dz = 0;

            for (int i = 1 << n; i > 0; i--)
            {
                int xi = i;

                int z = 0;

                bool candidate = true;

                for (int j = 0; j < n; j++)
                {
                    if (xi % 2 > 0)
                    {
                        z++;

                        if ((i & sts[j]) != i)
                        {
                            candidate = false;
                            break;
                        }
                    }
                    xi >>= 1;
                }

                if (candidate && z >= dz)
                {
                    dz  = z;
                    di = i;
                }
            }

            if (dz > 0)
            {
                io.PrintLine(dz);

                for (int i = 0; i < n; i++)
			    {
                    if (((1 << i) & di) > 0)
                        io.PrintLine(names[i]);
                }
            }
        }

    }
}

[{'input': '3 1\r\nPetya\r\nVasya\r\nMasha\r\nPetya Vasya\r\n', 'output': ['2\r\nMasha\r\nPetya\r\n']}, {'input': '3 0\r\nPasha\r\nLesha\r\nVanya\r\n', 'output': ['3\r\nLesha\r\nPasha\r\nVanya\r\n']}, {'input': '7 12\r\nPasha\r\nLesha\r\nVanya\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nPasha Taras\r\nPasha Nikita\r\nPasha Andrey\r\nPasha Sergey\r\nLesha Taras\r\nLesha Nikita\r\nLesha Andrey\r\nLesha Sergey\r\nVanya Taras\r\nVanya Nikita\r\nVanya Andrey\r\nVanya Sergey\r\n', 'output': ['4\r\nAndrey\r\nNikita\r\nSergey\r\nTaras\r\n']}, {'input': '2 0\r\nAndrey\r\nTaras\r\n', 'output': ['2\r\nAndrey\r\nTaras\r\n']}, {'input': '16 0\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nRomka\r\nAlexey\r\nUra\r\nDenis\r\nEgor\r\nVadim\r\nAlena\r\nOlya\r\nVanya\r\nBrus\r\nJohn\r\nAlice\r\n', 'output': ['16\r\nAlena\r\nAlexey\r\nAlice\r\nAndrey\r\nBrus\r\nDenis\r\nEgor\r\nJohn\r\nNikita\r\nOlya\r\nRomka\r\nSergey\r\nTaras\r\nUra\r\nVadim\r\nVanya\r\n']}, {'input': '6 6\r\nAlena\r\nOlya\r\nVanya\r\nBrus\r\nJohn\r\nAlice\r\nAlena John\r\nAlena Alice\r\nOlya John\r\nOlya Alice\r\nVanya John\r\nVanya Alice\r\n', 'output': ['4\r\nAlena\r\nBrus\r\nOlya\r\nVanya\r\n']}, {'input': '7 6\r\nAlena\r\nOlya\r\nVanya\r\nBrus\r\nJohn\r\nAlice\r\nMariana\r\nAlena John\r\nAlena Alice\r\nOlya John\r\nOlya Alice\r\nVanya John\r\nVanya Alice\r\n', 'output': ['5\r\nAlena\r\nBrus\r\nMariana\r\nOlya\r\nVanya\r\n']}, {'input': '1 0\r\nPetr\r\n', 'output': ['1\r\nPetr\r\n']}, {'input': '2 0\r\nNgzlPJgFgz\r\nQfpagVpWz\r\n', 'output': ['2\r\nNgzlPJgFgz\r\nQfpagVpWz\r\n']}, {'input': '2 1\r\ncLWdg\r\nGoWegdDRp\r\nGoWegdDRp cLWdg\r\n', 'output': ['1\r\nGoWegdDRp\r\n']}, {'input': '3 0\r\nr\r\nyVwqs\r\nsdTDerOyhp\r\n', 'output': ['3\r\nr\r\nsdTDerOyhp\r\nyVwqs\r\n']}, {'input': '3 3\r\nvRVatwL\r\nWmkUGiYEn\r\nuvvsXKXcJ\r\nWmkUGiYEn vRVatwL\r\nuvvsXKXcJ vRVatwL\r\nuvvsXKXcJ WmkUGiYEn\r\n', 'output': ['1\r\nWmkUGiYEn\r\n']}, {'input': '16 11\r\njA\r\nkyRNTE\r\neY\r\nToLcqN\r\nbnenhMxiK\r\nzlkOe\r\nXCKZ\r\neaQrds\r\nqUdInpi\r\nKgPQA\r\nmQIl\r\ninOCWEZHxy\r\nyA\r\nPIZRMOu\r\nXtueKFM\r\nfRNwNn\r\ninOCWEZHxy qUdInpi\r\nKgPQA zlkOe\r\ninOCWEZHxy KgPQA\r\nfRNwNn XCKZ\r\ninOCWEZHxy eY\r\nyA mQIl\r\ninOCWEZHxy ToLcqN\r\nyA KgPQA\r\nqUdInpi ToLcqN\r\nqUdInpi eaQrds\r\nPIZRMOu eY\r\n', 'output': ['10\r\nKgPQA\r\nPIZRMOu\r\nToLcqN\r\nXCKZ\r\nXtueKFM\r\nbnenhMxiK\r\neaQrds\r\njA\r\nkyRNTE\r\nmQIl\r\n']}, {'input': '12 12\r\njWuGgOjV\r\nWs\r\njTZQMyH\r\nULp\r\nUfsnPRt\r\nk\r\nbPKrnP\r\nW\r\nJOaQdgglDG\r\nAodc\r\ncpRjAUyYIW\r\nMrjB\r\nbPKrnP ULp\r\nk Ws\r\ncpRjAUyYIW k\r\nULp jTZQMyH\r\nbPKrnP jWuGgOjV\r\ncpRjAUyYIW jTZQMyH\r\nW ULp\r\nk jTZQMyH\r\nk ULp\r\nMrjB ULp\r\ncpRjAUyYIW Aodc\r\nW k\r\n', 'output': ['8\r\nAodc\r\nJOaQdgglDG\r\nMrjB\r\nUfsnPRt\r\nW\r\nWs\r\nbPKrnP\r\njTZQMyH\r\n']}, {'input': '11 17\r\njFTNgFBO\r\ntZDgmdF\r\nIjeDjoj\r\nBEMAaYkNb\r\nRZRQl\r\ntK\r\nlNHWt\r\nIdG\r\nLAbVLYiY\r\notOBsWqJuo\r\nUoTy\r\ntK BEMAaYkNb\r\nBEMAaYkNb jFTNgFBO\r\nIjeDjoj tZDgmdF\r\nRZRQl jFTNgFBO\r\nlNHWt tZDgmdF\r\nRZRQl tZDgmdF\r\nUoTy LAbVLYiY\r\nBEMAaYkNb IjeDjoj\r\nIdG BEMAaYkNb\r\nLAbVLYiY tK\r\nLAbVLYiY jFTNgFBO\r\nUoTy IjeDjoj\r\nlNHWt jFTNgFBO\r\nlNHWt BEMAaYkNb\r\ntK IjeDjoj\r\nUoTy RZRQl\r\nBEMAaYkNb tZDgmdF\r\n', 'output': ['6\r\nIdG\r\nIjeDjoj\r\nLAbVLYiY\r\nRZRQl\r\nlNHWt\r\notOBsWqJuo\r\n']}, {'input': '11 13\r\ncZAMfd\r\nSWQnweM\r\nKlQW\r\nWRsnNZT\r\nix\r\nUC\r\nLWqsVHcWec\r\nfeb\r\ncBy\r\ntvk\r\nRXDlX\r\nfeb SWQnweM\r\ncBy WRsnNZT\r\nLWqsVHcWec KlQW\r\nRXDlX feb\r\nLWqsVHcWec cZAMfd\r\ncBy UC\r\nWRsnNZT SWQnweM\r\nRXDlX cBy\r\ntvk UC\r\ncBy SWQnweM\r\nUC KlQW\r\nRXDlX KlQW\r\nUC WRsnNZT\r\n', 'output': ['6\r\nKlQW\r\nWRsnNZT\r\ncZAMfd\r\nfeb\r\nix\r\ntvk\r\n']}, {'input': '4 2\r\nadQx\r\nrJGeodBycK\r\ntgPYZk\r\ncz\r\ncz tgPYZk\r\nrJGeodBycK adQx\r\n', 'output': ['2\r\nadQx\r\ncz\r\n']}, {'input': '4 2\r\noVemoZhjW\r\nHspFEry\r\nhFO\r\njxt\r\nhFO HspFEry\r\njxt oVemoZhjW\r\n', 'output': ['2\r\nHspFEry\r\njxt\r\n']}, {'input': '5 2\r\niBrgNFlNXd\r\nlnGPIV\r\nnb\r\nB\r\nVgqRcEOG\r\nlnGPIV iBrgNFlNXd\r\nB iBrgNFlNXd\r\n', 'output': ['4\r\nB\r\nVgqRcEOG\r\nlnGPIV\r\nnb\r\n']}, {'input': '5 1\r\nWEYUdpYmZp\r\nfhNmMpjr\r\nydARivBg\r\ncilTtE\r\nyeXxkhPzB\r\nyeXxkhPzB cilTtE\r\n', 'output': ['4\r\nWEYUdpYmZp\r\ncilTtE\r\nfhNmMpjr\r\nydARivBg\r\n']}, {'input': '6 9\r\noySkmhCD\r\nUIKWj\r\nmHolKkBx\r\nQBikssqz\r\nZ\r\nzoFUJYa\r\nZ UIKWj\r\nQBikssqz oySkmhCD\r\nQBikssqz UIKWj\r\nZ oySkmhCD\r\nzoFUJYa UIKWj\r\nzoFUJYa Z\r\nzoFUJYa mHolKkBx\r\nzoFUJYa QBikssqz\r\nQBikssqz mHolKkBx\r\n', 'output': ['3\r\nUIKWj\r\nmHolKkBx\r\noySkmhCD\r\n']}, {'input': '6 1\r\nuPVIuLBuYM\r\nVejWyKCtbN\r\nqqjgF\r\nulBD\r\nDRNzxJU\r\nCOzbXWOt\r\nulBD qqjgF\r\n', 'output': ['5\r\nCOzbXWOt\r\nDRNzxJU\r\nVejWyKCtbN\r\nqqjgF\r\nuPVIuLBuYM\r\n']}, {'input': '7 14\r\nFXCT\r\nn\r\no\r\nS\r\nMdFuonu\r\nmszv\r\nbqScOCw\r\nS o\r\nbqScOCw FXCT\r\nMdFuonu o\r\no n\r\nbqScOCw n\r\nmszv S\r\nbqScOCw MdFuonu\r\nmszv n\r\nS FXCT\r\nbqScOCw o\r\no FXCT\r\nmszv MdFuonu\r\nmszv FXCT\r\nbqScOCw mszv\r\n', 'output': ['3\r\nFXCT\r\nMdFuonu\r\nn\r\n']}, {'input': '7 6\r\nj\r\nZ\r\nPZNeTyY\r\nm\r\na\r\nUj\r\nsuaaSiKcK\r\nUj PZNeTyY\r\na j\r\nPZNeTyY Z\r\nPZNeTyY j\r\nm PZNeTyY\r\nm j\r\n', 'output': ['5\r\nUj\r\nZ\r\na\r\nm\r\nsuaaSiKcK\r\n']}, {'input': '8 6\r\nU\r\nC\r\nPEElYwaxf\r\nVubTXNI\r\nJ\r\nIxZUHV\r\nhLNFnzmqFE\r\nDPPvwuWvmA\r\nhLNFnzmqFE IxZUHV\r\nIxZUHV C\r\nJ PEElYwaxf\r\nIxZUHV PEElYwaxf\r\nPEElYwaxf C\r\nJ VubTXNI\r\n', 'output': ['5\r\nC\r\nDPPvwuWvmA\r\nJ\r\nU\r\nhLNFnzmqFE\r\n']}, {'input': '8 12\r\nBkgxqAF\r\nKhq\r\nNpIfk\r\nkheqUyDVG\r\niRBkHlRpp\r\nZDaQY\r\nNG\r\nqN\r\nqN BkgxqAF\r\nNpIfk BkgxqAF\r\niRBkHlRpp BkgxqAF\r\niRBkHlRpp NpIfk\r\nNG Khq\r\niRBkHlRpp Khq\r\nNG ZDaQY\r\nNG iRBkHlRpp\r\nNG NpIfk\r\nqN Khq\r\nZDaQY kheqUyDVG\r\nNpIfk Khq\r\n', 'output': ['3\r\nBkgxqAF\r\nKhq\r\nZDaQY\r\n']}, {'input': '9 5\r\nRFiow\r\naxgvtiBGbx\r\ngGBVZtI\r\nVWAxrqx\r\nmnASVEQI\r\ntZHzWGAvXc\r\nBeaCYhIRLy\r\nhTdUL\r\nFJd\r\nhTdUL RFiow\r\nhTdUL gGBVZtI\r\nFJd axgvtiBGbx\r\nFJd BeaCYhIRLy\r\nhTdUL axgvtiBGbx\r\n', 'output': ['7\r\nBeaCYhIRLy\r\nRFiow\r\nVWAxrqx\r\naxgvtiBGbx\r\ngGBVZtI\r\nmnASVEQI\r\ntZHzWGAvXc\r\n']}, {'input': '9 13\r\nYiUXqlBUx\r\nQNgYuX\r\ndPtyZ\r\nITtwRJCv\r\nLJ\r\nrAG\r\nOgxNq\r\nsitechE\r\nvVAAz\r\nOgxNq QNgYuX\r\nOgxNq dPtyZ\r\nsitechE rAG\r\nLJ QNgYuX\r\nQNgYuX YiUXqlBUx\r\nOgxNq LJ\r\nvVAAz OgxNq\r\nrAG dPtyZ\r\nvVAAz LJ\r\nvVAAz ITtwRJCv\r\nsitechE LJ\r\nrAG YiUXqlBUx\r\nsitechE QNgYuX\r\n', 'output': ['4\r\nITtwRJCv\r\nLJ\r\nYiUXqlBUx\r\ndPtyZ\r\n']}, {'input': '9 6\r\nfLfek\r\nEQPcotnrp\r\nCaAlbwoIL\r\nVG\r\nNAZKIBiKT\r\noFy\r\njFluh\r\nKqHXRNya\r\nQSwgobA\r\noFy EQPcotnrp\r\nKqHXRNya jFluh\r\noFy NAZKIBiKT\r\njFluh oFy\r\njFluh fLfek\r\noFy fLfek\r\n', 'output': ['7\r\nCaAlbwoIL\r\nEQPcotnrp\r\nKqHXRNya\r\nNAZKIBiKT\r\nQSwgobA\r\nVG\r\nfLfek\r\n']}, {'input': '9 14\r\nmoRNeufngu\r\nBSKI\r\nzXl\r\ngwmIDluW\r\nYFn\r\nHvasEgl\r\nXcAC\r\neVP\r\nAiOm\r\neVP BSKI\r\neVP YFn\r\nHvasEgl YFn\r\neVP XcAC\r\nAiOm HvasEgl\r\nXcAC YFn\r\nzXl moRNeufngu\r\neVP zXl\r\nHvasEgl BSKI\r\nXcAC gwmIDluW\r\nXcAC HvasEgl\r\nYFn moRNeufngu\r\nzXl BSKI\r\nHvasEgl gwmIDluW\r\n', 'output': ['4\r\nAiOm\r\nBSKI\r\nYFn\r\ngwmIDluW\r\n']}, {'input': '15 8\r\ncXeOANpvBF\r\nbkeDfi\r\nnsEUAKNxQI\r\noSIb\r\naU\r\nXYXYVo\r\nduZQ\r\naPkr\r\nPVrHpL\r\nmVgmv\r\nhHhukllwbf\r\nGkNPGYVxjY\r\nbgBjA\r\nslNKCLIlOv\r\nmPILXy\r\nbgBjA cXeOANpvBF\r\nGkNPGYVxjY cXeOANpvBF\r\nslNKCLIlOv GkNPGYVxjY\r\nGkNPGYVxjY mVgmv\r\nXYXYVo cXeOANpvBF\r\nslNKCLIlOv bkeDfi\r\nmVgmv aPkr\r\nslNKCLIlOv nsEUAKNxQI\r\n', 'output': ['12\r\nGkNPGYVxjY\r\nPVrHpL\r\nXYXYVo\r\naPkr\r\naU\r\nbgBjA\r\nbkeDfi\r\nduZQ\r\nhHhukllwbf\r\nmPILXy\r\nnsEUAKNxQI\r\noSIb\r\n']}, {'input': '15 3\r\na\r\nYclKFJoaIA\r\nhalYcB\r\nbLOlPzAeQ\r\ntckjt\r\noDFijpx\r\nb\r\npz\r\nVDLb\r\nlCEHPibt\r\noF\r\npzJD\r\nMC\r\nqklsX\r\nTAU\r\npzJD tckjt\r\nqklsX oF\r\nMC pzJD\r\n', 'output': ['13\r\nMC\r\nTAU\r\nVDLb\r\nYclKFJoaIA\r\na\r\nb\r\nbLOlPzAeQ\r\nhalYcB\r\nlCEHPibt\r\noDFijpx\r\noF\r\npz\r\ntckjt\r\n']}, {'input': '16 8\r\nJIo\r\nINanHVnP\r\nKaxyCBWt\r\nkVfnsz\r\nRAwFYCrSvI\r\nF\r\nvIEWWIvh\r\nTGF\r\nFeuhJJwJ\r\nTngcmS\r\nSqI\r\nRmcaVngp\r\neGwhme\r\nlwaFfXzM\r\noabGmpvVH\r\nTMT\r\nFeuhJJwJ F\r\neGwhme FeuhJJwJ\r\nRmcaVngp SqI\r\nINanHVnP JIo\r\nSqI FeuhJJwJ\r\nF kVfnsz\r\nTGF F\r\nTMT TGF\r\n', 'output': ['11\r\nF\r\nINanHVnP\r\nKaxyCBWt\r\nRAwFYCrSvI\r\nRmcaVngp\r\nTMT\r\nTngcmS\r\neGwhme\r\nlwaFfXzM\r\noabGmpvVH\r\nvIEWWIvh\r\n']}, {'input': '16 25\r\nbBZ\r\nEr\r\nZ\r\nrYJmfZLgmx\r\nPaJNrF\r\naHtRqSxOO\r\nD\r\nhsagsG\r\nMDuBOXrmWH\r\nSgjMQZ\r\nYXgWq\r\nxDwpppG\r\nSDY\r\nJwZWx\r\ncOzrgrBaE\r\nFJYX\r\nYXgWq SgjMQZ\r\nSDY PaJNrF\r\nFJYX rYJmfZLgmx\r\nhsagsG Er\r\nxDwpppG rYJmfZLgmx\r\naHtRqSxOO rYJmfZLgmx\r\nhsagsG bBZ\r\nJwZWx hsagsG\r\nFJYX cOzrgrBaE\r\nSDY YXgWq\r\nFJYX Z\r\nJwZWx rYJmfZLgmx\r\nD rYJmfZLgmx\r\nYXgWq Z\r\nrYJmfZLgmx Z\r\naHtRqSxOO bBZ\r\nSDY rYJmfZLgmx\r\ncOzrgrBaE D\r\nYXgWq hsagsG\r\nSDY aHtRqSxOO\r\ncOzrgrBaE xDwpppG\r\nSDY bBZ\r\nSDY Er\r\nJwZWx xDwpppG\r\nFJYX JwZWx\r\n', 'output': ['8\r\nD\r\nEr\r\nJwZWx\r\nMDuBOXrmWH\r\nPaJNrF\r\nSgjMQZ\r\nZ\r\naHtRqSxOO\r\n']}, {'input': '16 37\r\ntIWi\r\nq\r\nIEAYCq\r\nXozwkum\r\nCC\r\niPwfd\r\nS\r\nXEf\r\nWqEiwkH\r\nWX\r\ne\r\nltmruh\r\nKGx\r\nauTUYZRC\r\nmeJa\r\nM\r\nmeJa q\r\nKGx e\r\nXEf Xozwkum\r\ne q\r\nauTUYZRC KGx\r\ne CC\r\nM CC\r\nM meJa\r\nWX CC\r\nWqEiwkH IEAYCq\r\nauTUYZRC WqEiwkH\r\nKGx WX\r\nmeJa KGx\r\nXEf q\r\nauTUYZRC XEf\r\nauTUYZRC IEAYCq\r\nWX XEf\r\nM XEf\r\nWqEiwkH q\r\nM KGx\r\nKGx CC\r\nM e\r\nWqEiwkH Xozwkum\r\nCC q\r\nS Xozwkum\r\nKGx tIWi\r\nWX q\r\nXEf S\r\nauTUYZRC S\r\nCC IEAYCq\r\nKGx IEAYCq\r\ne WqEiwkH\r\nM S\r\nauTUYZRC q\r\nS tIWi\r\nM ltmruh\r\nM iPwfd\r\n', 'output': ['8\r\nIEAYCq\r\nWX\r\nXozwkum\r\ne\r\niPwfd\r\nltmruh\r\nmeJa\r\ntIWi\r\n']}, {'input': '16 11\r\ntulhZxeKgo\r\nbrAXY\r\nyQUkaihDAg\r\nmwjlDVaktK\r\nweVtBIP\r\nzRwb\r\nds\r\nhXPfJrL\r\nAdIfP\r\nazQeXn\r\nB\r\nJlmscIUOxO\r\nZuxr\r\nV\r\nOfyLIUO\r\nuaMl\r\nhXPfJrL yQUkaihDAg\r\nweVtBIP yQUkaihDAg\r\nazQeXn hXPfJrL\r\nV tulhZxeKgo\r\nzRwb yQUkaihDAg\r\nds mwjlDVaktK\r\nzRwb brAXY\r\nyQUkaihDAg brAXY\r\nB yQUkaihDAg\r\nAdIfP mwjlDVaktK\r\nbrAXY tulhZxeKgo\r\n', 'output': ['11\r\nAdIfP\r\nB\r\nJlmscIUOxO\r\nOfyLIUO\r\nV\r\nZuxr\r\nazQeXn\r\nbrAXY\r\nds\r\nuaMl\r\nweVtBIP\r\n']}, {'input': '5 10\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nRomka\r\nTaras Romka\r\nTaras Nikita\r\nTaras Sergey\r\nTaras Andrey\r\nRomka Nikita\r\nRomka Sergey\r\nRomka Andrey\r\nNikita Sergey\r\nNikita Andrey\r\nSergey Andrey\r\n', 'output': ['1\r\nAndrey\r\n']}]


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

The first line contains two integers n and m — the initial number of students and laces (). The students are numbered from 1 to n, and the laces are numbered from 1 to m. Next m lines each contain two integers a and b — the numbers of students tied by the i-th lace (1 ≤ a, b ≤ n, a ≠ b). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.

Print the single number — the number of groups of students that will be kicked out from the club.

NoteIn the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.

using System; using System.Linq; using System.Collections.Generic;

class p {
  static void Main() {
    var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var n = s[0]; var m = s[1];
    var links = Enumerable.Range(0, n+1).Select(i => new List<int>()).ToArray();
    var absent = new bool[n+1];
    while (m --> 0) {
      s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      links[s[0]].Add(s[1]);
      links[s[1]].Add(s[0]);
    }
    var g = 0;
    while (true) {
      var toBeRemoved = Enumerable.Range(1,n)
                 .Where(i => links[i].Count(q => !absent[q]) == 1 && !absent[i]).ToArray();
      if (!toBeRemoved.Any()) break;

      foreach (var x in toBeRemoved) absent[x] = true;
      g++;
    }
    Console.Write(g);
  }
}