Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them are numbered with integers from 0 to n in the order in which they follow from Gerald's home. The bus stop by Gerald's home has number 0 and the bus stop by the school has number n.There are m buses running between the house and the school: the i-th bus goes from stop si to ti (si < ti), visiting all the intermediate stops in the order in which they follow on the segment. Besides, Gerald's no idiot and he wouldn't get off the bus until it is still possible to ride on it closer to the school (obviously, getting off would be completely pointless). In other words, Gerald can get on the i-th bus on any stop numbered from si to ti - 1 inclusive, but he can get off the i-th bus only on the bus stop ti.Gerald can't walk between the bus stops and he also can't move in the direction from the school to the house.Gerald wants to know how many ways he has to get from home to school. Tell him this number. Two ways are considered different if Gerald crosses some segment between the stops on different buses. As the number of ways can be too much, find the remainder of a division of this number by 1000000007 (109 + 7).

The first line contains two space-separated integers: n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 105). Then follow m lines each containing two integers si, ti. They are the numbers of starting stops and end stops of the buses (0 ≤ si < ti ≤ n).

Print the only number — the number of ways to get to the school modulo 1000000007 (109 + 7).

NoteThe first test has the only variant to get to school: first on bus number one to the bus stop number one; then on bus number two to the bus stop number two.In the second test no bus goes to the third bus stop, where the school is positioned. Thus, the correct answer is 0.In the third test Gerald can either get or not on any of the first four buses to get closer to the school. Thus, the correct answer is 24 = 16.


Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.

The first line of input contains two integers n and m (1 ≤ n ≤ 19, 0 ≤ m) – respectively the number of vertices and edges of the graph. Each of the subsequent m lines contains two integers a and b, (1 ≤ a, b ≤ n, a ≠ b) indicating that vertices a and b are connected by an undirected edge. There is no more than one edge connecting any pair of vertices.

Output the number of cycles in the given graph.

NoteThe example graph is a clique and contains four cycles of length 3 and three cycles of length 4.

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

typedef long long ll;

ll dp[19][262144]; /* at, mask */
int g[32][32];
int v,e;
int bc[262144];

void printmask(int mask) {
  int i;
  for(i=0;i<v;i++) printf("%c",(mask&(1<<i))?'1':'0');
}

/* count cycles going through first, with no nodes >first */
ll solve(int first,int at,int mask) {
  ll res=0;
  int i;
  if(dp[at][mask]>-1) return dp[at][mask];
  /* can go back? only if cycle is of length >=3 */
  if(g[first][at] && bc[mask]>=2) res++;
  for(i=0;i<first;i++) if(g[at][i] && !(mask&(1<<i))) {
    res+=solve(first,i,mask|(1<<i));
  }
/*  printf("cycle at %d %d, mask ",first,at);
  printmask(mask);
  printf(": %I64d\n",res);*/
  return dp[at][mask]=res;
}

int main() {
  int i,j,a,b;
  ll ans=0,res;
  bc[0]=0;
  for(i=1;i<262144;i++) bc[i]=bc[i>>1]+(i&1);
  scanf("%d %d",&v,&e);
  memset(g,0,sizeof(g));
  for(i=0;i<e;i++) {
    scanf("%d %d",&a,&b);
    g[a-1][b-1]=g[b-1][a-1]=1;
  }
  for(i=2;i<v;i++) {
    for(j=0;j<=i;j++) memset(dp[j],-1,sizeof(ll)*(1<<i));
    res=solve(i,i,0);
    ans+=res;
/*    printf("end at %d %I64d\n",i,res);*/
  }
  ans/=2;
#ifdef _WIN32
  printf("%I64d\n",ans);
#else
  printf("%lld\n",ans);
#endif
  return 0;
}


#include <stdio.h>
#include <string.h>
#define QLEN 100007
int n,m;
int e[200010][2],v[200010],p[100010];
int bgn[100010],len[100010],ban[100010],go[100010];
int q[100010],dis[100010];
short vis[100010];
void adde(int sn,int fn,int val,int id)
{
	e[id][0] = fn; e[id][1] = p[sn]; p[sn] = id; v[id] = val;
}
int calc(int sn,int tim)
{
	int head = bgn[sn],tail = bgn[sn]+len[sn]-1,mid;
	if(!len[sn]) return tim;
	while(head<tail)
	{
		mid = (head+tail)>>1;
		if(ban[mid]>=tim) tail = mid;
		else head = mid+1;
	}
	if(ban[head] != tim) return tim;
	else return go[head];
}
void spfa()
{
	int i,sn,fn,val;
	int head = 1,tail = 2;
	memset(dis,60,sizeof(dis));
	q[1] = 1; dis[1] = 0; vis[1] = 1;
	while(head != tail)
	{
		sn = q[head++];
		for(i=p[sn];i;i=e[i][1])
		{
			fn = e[i][0];
			val = calc(sn,dis[sn])+v[i];
			if(dis[fn]<=val) continue;
			dis[fn] = val;
			if(vis[fn]) continue;
			vis[fn] = 1; q[tail++] = fn;
			if(tail>QLEN) tail = 1;
		}
		if(head>QLEN) head = 1;
	}
}
int main()
{
	int i,j,sn,fn,val;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
	{
		scanf("%d%d%d",&sn,&fn,&val);
		adde(sn,fn,val,i<<1);
		adde(fn,sn,val,i<<1|1);
	}
	bgn[0] = 1;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&len[i]);
		bgn[i] = bgn[i-1]+len[i-1];
		for(j=bgn[i];j<bgn[i]+len[i];j++) scanf("%d",&ban[j]);
		go[j-1] = ban[j-1]+1;
		for(j-=2;j>=bgn[i];j--)
		{
			if(ban[j] == ban[j+1]-1) go[j] = go[j+1];
			else go[j] = ban[j]+1;
		}
	}
	spfa();
	printf("%d",dis[n]<dis[0]?dis[n]:-1);
	return 0;
}

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

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

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

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

#include <stdio.h>
#include <string.h>
#define QLEN 100007
int n,m;
int e[200010][2],v[200010],p[100010];
int bgn[100010],len[100010],ban[100010],go[100010];
int q[100010],dis[100010];
short vis[100010];
void adde(int sn,int fn,int val,int id)
{
	e[id][0] = fn; e[id][1] = p[sn]; p[sn] = id; v[id] = val;
}
int calc(int sn,int tim)
{
	int head = bgn[sn],tail = bgn[sn]+len[sn]-1,mid;
	if(!len[sn]) return tim;
	while(head<tail)
	{
		mid = (head+tail)>>1;
		if(ban[mid]>=tim) tail = mid;
		else head = mid+1;
	}
	if(ban[head] != tim) return tim;
	else return go[head];
}
void spfa()
{
	int i,sn,fn,val;
	int head = 1,tail = 2;
	memset(dis,60,sizeof(dis));
	q[1] = 1; dis[1] = 0; vis[1] = 1;
	while(head != tail)
	{
		sn = q[head++];
		for(i=p[sn];i;i=e[i][1])
		{
			fn = e[i][0];
			val = calc(sn,dis[sn])+v[i];
			if(dis[fn]<=val) continue;
			dis[fn] = val;
			if(vis[fn]) continue;
			vis[fn] = 1; q[tail++] = fn;
			if(tail>QLEN) tail = 1;
		}
		vis[sn] = 0;
		if(head>QLEN) head = 1;
	}
}
int main()
{
	int i,j,sn,fn,val;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
	{
		scanf("%d%d%d",&sn,&fn,&val);
		adde(sn,fn,val,i<<1);
		adde(fn,sn,val,i<<1|1);
	}
	bgn[0] = 1;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&len[i]);
		bgn[i] = bgn[i-1]+len[i-1];
		for(j=bgn[i];j<bgn[i]+len[i];j++) scanf("%d",&ban[j]);
		go[j-1] = ban[j-1]+1;
		for(j-=2;j>=bgn[i];j--)
		{
			if(ban[j] == ban[j+1]-1) go[j] = go[j+1];
			else go[j] = ban[j]+1;
		}
	}
	spfa();
	printf("%d",dis[n]<dis[0]?dis[n]:-1);
	return 0;
}


#include <stdio.h>

#define M 1000000

typedef int bool;
#define true 1
#define false 0

int n,k;
char str[M];
int v[M];

bool check(int d);
int bs(int l,int r);

int main(){
    scanf("%d %d", &n, &k);
    char ch;
    for(int i=0;i<n;++i){
        scanf(" %c",&ch);
        str[i] = ch;
    }

    for(int i = 0;i < n; ++i){
        if(str[i] == '0'){
            v[i] = i;
        } else {
            v[i] = v[i-1];
        }
    }

    int ans = bs(0,n-2);

    printf("%d",ans);
}

bool check(int d){
    int s = 0;
    int kk = 0;
    while(true){
        if(s + d + 1 >= n - 1){
            break;
        }
        if(kk == k - 2){
            return false;
        }
        if(v[s + d + 1] <= s){
            return false;
        } else{
            s = v[s + d + 1];
        }
        kk++;
    }
    true;
}

int bs(int l,int r){
    while(l + 1 < r){
        int m = (l + r) / 2;
        if(check(m)){
            r = m;
        } else{
            l = m;
        }
    }
    if(check(l)){
        return l;
    } else{
        return r;
    }
}

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

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

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

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

#include <stdio.h>
#define N 200005

int n, k;
char a[N];

int check(int x)
{
	int last = 1, i, ok, cnt = k;
	while (last + x < n)
	{
		ok = 0;
		for (i = last + x; i > last; --i)
			if (a[i] == '0')
			{
				last = i;
				ok = 1;
				if (--cnt < 0) ok = 0;
				break;
			}
		if (!ok) return 0;
	}
	return 1;
}

int solve()
{
	int l = 1, r = n - 1, mid;
	if (check(1)) return 1;
	while (l + 1 < r)
	{
		mid = (l + r) >> 1;
		if (check(mid)) r = mid;
		else l = mid;
	}
	return r;
}

int main()
{
	scanf("%d%d%s", &n, &k, a + 1);
	k -= 2;
	printf("%d\n", solve() - 1);
	return 0;
}


#include <stdio.h>
#include <string.h>
int n,m,an = 0,am = 0,bn = 0,bm = 0;
int sga[25][25][25][25],sgb[25][25][25][25];
char map[25][25];
short ga[25][25],gb[25][25];
int max(int a,int b)
{
    return a>b?a:b;
}
int worka(int i,int j,int ii,int jj)
{
    int fi,fj;
    short v[700] = {0};

    if(i>ii||j>jj||i<=0||j<=0||ii<=0||jj<=0||i>an||j>am||ii>an||jj>am) return 0;
    if(sga[i][j][ii][jj]>=0) return sga[i][j][ii][jj];

    for(fi=i;fi<=ii;fi++) for(fj=j;fj<=jj;fj++)
    {
        if(ga[fi][fj] == 1)
            v[worka(i,j,ii,fj-1)^worka(i,fj+1,ii,jj)] = 1;
        else if(ga[fi][fj] == 2)
            v[worka(i,j,fi-1,jj)^worka(fi+1,j,ii,jj)] = 1;
        else if(ga[fi][fj] == 3)
            v[worka(i,j,fi-1,fj-1)^worka(i,fj+1,fi-1,jj)^worka(fi+1,j,ii,fj-1)^worka(fi+1,fj+1,ii,jj)] = 1;
    }
    for(fi=0;v[fi];fi++);
    return sga[i][j][ii][jj] = fi;
}
int workb(int i,int j,int ii,int jj)
{
    int fi,fj;
    short v[700] = {0};

    if(i>ii||j>jj||i<=0||j<=0||ii<=0||jj<=0||i>bn||j>bm||ii>bn||jj>bm) return 0;
    if(sgb[i][j][ii][jj]>=0) return sgb[i][j][ii][jj];

    for(fi=i;fi<=ii;fi++) for(fj=j;fj<=jj;fj++)
    {
        if(gb[fi][fj] == 1)
            v[workb(i,j,ii,fj-1)^workb(i,fj+1,ii,jj)] = 1;
        else if(gb[fi][fj] == 2)
            v[workb(i,j,fi-1,jj)^workb(fi+1,j,ii,jj)] = 1;
        else if(gb[fi][fj] == 3)
            v[workb(i,j,fi-1,fj-1)^workb(i,fj+1,fi-1,jj)^workb(fi+1,j,ii,fj-1)^workb(fi+1,fj+1,ii,jj)] = 1;
    }
    for(fi=0;v[fi];fi++);
    return sgb[i][j][ii][jj] = fi;
}
int main()
{
    int i,j,k,l,ii,jj,fi,fj,t1,t2;
    memset(sga,-1,sizeof(sga)); memset(sgb,-1,sizeof(sgb));
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++) scanf("%s",map[i]+1);

    for(i=n;i;i--) for(j=1;j<=m;j++)
    {
        ii = (i+j-2)/2+1;
        jj = ((j-i)-(1-n))/2+1;
        if(((i+j)&1) == ((n+1)&1))
        {
            if(map[i][j] == 'L') ga[ii][jj] = 1;
            else if(map[i][j] == 'R') ga[ii][jj] = 2;
            else ga[ii][jj] = 3;
            an = max(an,ii); am = max(am,jj);
        }
        else
        {
            if(map[i][j] == 'L') gb[ii][jj] = 1;
            else if(map[i][j] == 'R') gb[ii][jj] = 2;
            else gb[ii][jj] = 3;
            bn = max(bn,ii); bm = max(bm,jj);
        }
    }
    if(worka(1,1,an,am)^workb(1,1,bn,bm)) printf("WIN");
    else printf("LOSE");

    return 0;
}

Recently Roma has become the happy owner of a new game World of Darkraft. This game combines elements of virtually all known genres, and on one of the later stages of the game Roma faced difficulties solving a puzzle.In this part Roma fights with a cunning enemy magician. The battle takes place on a rectangular field plaid n × m. Each cell contains one magical character: L, R or X. Initially all the squares of the field are "active".The players, Roma and enemy magician, take turns. Roma makes the first move. During a move a player selects one of the active cells. Then depending on the image in the character in the cell one of the following actions takes place:   L — magical waves radiate from the cell to the left downwards and to the right upwards along diagonal paths. All cells on the path of the waves (including the selected cell too) become inactive. The waves continue until the next inactive cell or to the edge of the field if there are no inactive cells on the way.  R — the magical waves radiate to the left upwards and to the right downwards.  X — the magical waves radiate in all four diagonal directions. If the next player cannot make a move (i.e., all cells are inactive), he loses.Roma has been trying to defeat the computer opponent for three days but he just keeps losing. He asks you to help him and determine whether it is guaranteed that he can beat the opponent, or he will have to hack the game.

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 20). Next n lines contain m characters describing the playing field: the j-th character of the i-th line equals to the magical character of the corresponding field square.

On the first line print "WIN" if Roma can win or "LOSE" if it is impossible to win considering that the opponent pays optimally.

NoteIn the first test each move makes one diagonal line of the square inactive, thus it is guaranteed that Roma loses after two moves.There are three variants of making a move in the second test: to "finish off" the main diagonal line or any of the squares that are left. That means that after three moves the game stops and Roma wins.

[{'input': '2 2\r\nRL\r\nLR\r\n', 'output': ['LOSE\r\n']}, {'input': '2 2\r\nRR\r\nRR\r\n', 'output': ['WIN\r\n']}, {'input': '1 4\r\nLXXL\r\n', 'output': ['LOSE\r\n']}, {'input': '2 2\r\nLL\r\nXX\r\n', 'output': ['WIN\r\n']}, {'input': '2 2\r\nXL\r\nXX\r\n', 'output': ['LOSE\r\n']}, {'input': '2 4\r\nRRXR\r\nRRRX\r\n', 'output': ['WIN\r\n']}, {'input': '3 3\r\nXLX\r\nRRL\r\nLRL\r\n', 'output': ['LOSE\r\n']}, {'input': '4 3\r\nRLR\r\nRLR\r\nXLL\r\nLXX\r\n', 'output': ['WIN\r\n']}, {'input': '4 4\r\nXLRL\r\nXLLX\r\nXXLX\r\nLRXL\r\n', 'output': ['LOSE\r\n']}, {'input': '2 6\r\nXRLLXL\r\nRXXRLR\r\n', 'output': ['WIN\r\n']}, {'input': '3 6\r\nLXLRLL\r\nLLLXRL\r\nXRLXRX\r\n', 'output': ['LOSE\r\n']}, {'input': '7 5\r\nLXXLL\r\nXXXRX\r\nXRLLL\r\nLRLRL\r\nLXRLR\r\nXLXXR\r\nXXXXX\r\n', 'output': ['WIN\r\n']}, {'input': '7 7\r\nLLLLXXL\r\nLXRRXXL\r\nXLXLRRL\r\nXRXRLXL\r\nXRXLXRL\r\nLXXXXRL\r\nRLLXLXR\r\n', 'output': ['WIN\r\n']}, {'input': '8 1\r\nX\r\nL\r\nR\r\nX\r\nL\r\nL\r\nR\r\nR\r\n', 'output': ['LOSE\r\n']}, {'input': '2 9\r\nRXRLXXLRR\r\nXLRXLLLXX\r\n', 'output': ['LOSE\r\n']}, {'input': '10 3\r\nXLX\r\nXRX\r\nXRX\r\nRLL\r\nRRL\r\nRLL\r\nXRR\r\nLRL\r\nRRR\r\nXRL\r\n', 'output': ['WIN\r\n']}, {'input': '9 9\r\nLLXLXRRRX\r\nLLRXXRXLR\r\nXLRXXXLXL\r\nRXXRLLRRR\r\nLRLLRXXRX\r\nLLLLRLRLX\r\nXXXLLXXLX\r\nRLXLLRXLL\r\nRLRRRRLXX\r\n', 'output': ['LOSE\r\n']}, {'input': '10 11\r\nXRLXRXLXLRR\r\nLXLRRLRXRXR\r\nLRXXLRXXXLX\r\nXXXXRRLLLLR\r\nXRXRRRXXRXX\r\nLRLRRRXLXLR\r\nRLRXXXLXXRL\r\nLRXXRRXXLXR\r\nLXXRLLLRLRR\r\nRLRXLLXRLXR\r\n', 'output': ['WIN\r\n']}, {'input': '12 7\r\nLRLRLXR\r\nRRRXXRR\r\nRXRXXRX\r\nLXLLLRR\r\nLXRXLLL\r\nRRRLLXR\r\nRRLXRXR\r\nRXRLLLL\r\nXXRXRXX\r\nLXLRLRX\r\nLXLXRLR\r\nXXXXRRR\r\n', 'output': ['LOSE\r\n']}, {'input': '13 13\r\nXLLXRXLXRRLLL\r\nXRLLXXRRXLLLX\r\nXXLRXRLLRRRRL\r\nXLRRLRLLRRLLL\r\nXLLLXXXXRRXRR\r\nRLXXLRRLXRRXL\r\nRLRXRRXLLRLLR\r\nRRRXLRRRLRLXR\r\nXRLLXLXRRXLRR\r\nLLLLRLXRRLRXL\r\nRLRRXLRLLXXXX\r\nLRXRXLRLRXRLX\r\nLLLRLRLXXXLXR\r\n', 'output': ['WIN\r\n']}, {'input': '18 1\r\nX\r\nL\r\nR\r\nX\r\nL\r\nX\r\nX\r\nR\r\nX\r\nR\r\nR\r\nX\r\nX\r\nR\r\nL\r\nL\r\nR\r\nX\r\n', 'output': ['LOSE\r\n']}, {'input': '2 20\r\nLLLRRLRLRLLXLXLRRLXL\r\nXRXLLLXRRXRXRXXLRLLX\r\n', 'output': ['WIN\r\n']}, {'input': '17 3\r\nXRR\r\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\nX\r\nR\r\nL\r\nL\r\nL\r\nL\r\nR\r\nL\r\nR\r\n', 'output': ['LOSE\r\n']}, {'input': '1 20\r\nRLXLXRXLXXXLXXXLXXRR\r\n', 'output': ['LOSE\r\n']}, {'input': '2 20\r\nLLLRRLRLRLLXLXLRRLXL\r\nXRXLLLXRRXRXRXXLRLLX\r\n', 'output': ['WIN\r\n']}, {'input': '20 2\r\nRR\r\nXL\r\nRR\r\nRX\r\nXR\r\nXL\r\nXR\r\nXL\r\nXR\r\nRL\r\nXR\r\nLR\r\nRX\r\nLX\r\nRR\r\nLX\r\nRL\r\nRL\r\nXR\r\nXR\r\n', 'output': ['LOSE\r\n']}, {'input': '3 19\r\nXXXLLRLRRLLLRRRRRLX\r\nLRRXLRXRXLLRRXLXLXR\r\nXRXRXXXRRXXLRRLXLRR\r\n', 'output': ['WIN\r\n']}, {'input': '3 19\r\nXXLXRXXXLRRXXLXXRLR\r\nLXXLXRXXRRRRLXRLXLX\r\nLXRXLRLRLXXRLXXLXXR\r\n', 'output': ['LOSE\r\n']}, {'input': '1 1\r\nX\r\n', 'output': ['WIN\r\n']}, {'input': '1 1\r\nR\r\n', 'output': ['WIN\r\n']}, {'input': '20 20\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXXXXX\r\nXXXXXXXXXXXXXXXXX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\nRRRRRRRRRRRRRRRRRRRR\r\nRRRRRRRRRRRRRRRRRRRR\r\nRRRRRRRRRRRRRRRRRRRR\r\n', 'output': ['WIN\r\n']}, {'input': '18 20\r\nRLLLLLRRRRLXLLRLXLLL\r\nRRXRXXXLXXRLXLRXLRXR\r\nLRLXLLXRRRLXXLRXLXRL\r\nXXXRRXLRLRLXLLLLRXLL\r\nRRXXXXXRRRLRXLLXXXXR\r\nXLRLLXXLLXRLRRXRRRRR\r\nRRRXRXLRRRLXLRRXXXRR\r\nLLRXRLRRRLRRRLRXRRRL\r\nLLXRXLLXRLXRRRRLLXLX\r\nRRRRRLXXLRXRRLLRRRRL\r\nXLRLRXXXRXRLRXXRLXXX\r\nXLXXXRXXLXRLLLLLLXXR\r\nRRRLRXLRRLXLXXLLLRRR\r\nLRXLRRRXXRLRLLXLLRLR\r\nRXRLLRRRRLXLRXXLRRLL\r\nRRRLLLRLXRRRXXXRLXLL\r\nXRXRXLXXRRRXXRXLRLLL\r\nRLXLLRXRRLLXRXXXXRXL\r\n', 'output': ['LOSE\r\n']}]


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-7
#define MOD 1000000007
#define ll long long int
#define N 450000
int que[N];
int graph[1000][1000];
int new_graph[1000][1000];
int dist[N];
int visited[N];
int rear=-1;
int front=-1;
void insert_que(int x){
   que[++rear]=x;
   if(rear==0)
   front=0;
}
int pop_que(){
   return que[front++];
}
int is_empty(){
   return front>rear?1:0;
}
int solve(int x,int n){
   insert_que(x);
   visited[x]=1;
   while(!is_empty()){
      int get=pop_que();
      for(int i=1;i<=n;i++){
         if(!visited[i] && new_graph[get][i]){
            visited[i]=1;
            insert_que(i);
         }
         if(!visited[i] && new_graph[get][i]){
            dist[i]=dist[get]+1;
         }
      }
   }
   return dist[n]==0?-1:dist[n];
}
int solve1(int x,int n){
   insert_que(x);
   visited[x]=1;
   while(!is_empty()){
      int get=pop_que();
      for(int i=1;i<=n;i++){
         if(!visited[i] && graph[get][i]){
            visited[i]=1;
            insert_que(i);
         }
         if(!visited[i] && graph[get][i]){
            dist[i]=dist[get]+1;
         }
      }
   }
   return dist[n]==0?-1:dist[n];
}
int main(){
   int a,b,c,d;
   scanf("%d%d",&a,&b);
   int flag=2;
   for(int i=0;i<b;i++){
      int foo[2];
      scanf("%d%d",foo,foo+1);
      graph[foo[0]][foo[1]]=1;
      graph[foo[1]][foo[0]]=1;
   }
   for(int i=1;i<=a;i++){
      for(int w=1;w<=a;w++){
         if(i!=w){
            if(!graph[i][w]){
               new_graph[i][w]=1;
            }
         }
      }
   }
   int x=solve(1,a);
   memset(visited,0,sizeof(visited));
   memset(que,0,sizeof(que));
   front=rear=-1;
   memset(dist,0,sizeof(dist));
   int x1=solve1(1,a);
   if(x==-1 || x1==1){
      printf("-1");
      return 0;
   }
   x>x1?printf("%d",x):printf("%d",x1);
}

In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so.

The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns.

Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output  - 1.

NoteIn the first sample, the train can take the route  and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.


As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si — how many students who play basketball belong to this department.Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.

The first line contains three integers n, m and h (1 ≤ n ≤ 100, 1 ≤ m ≤ 1000, 1 ≤ h ≤ m) — the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.  The second line contains a single-space-separated list of m integers si (1 ≤ si ≤ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.

Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.

NoteIn the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.In the second example, there are not enough players.In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.

#include<stdio.h>
int main()
{
	int j,i,n,m,h,temp,a,b,ans1,ans2;
	double ans;
	scanf("%d%d%d",&n,&m,&h);
	b=0;
	for(i=1;i<=m;i++)
	{
		scanf("%d",&temp);
		if(i==h)
			a=temp-1;
		else
			b+=temp;
	}
	ans=1;
	n--;
	/*for(i=1,j=a;i<=a;i++,j--)
	{
		if(i<n+1)
			ans*=(long double)(b-n+i);
		if(j>a-n)
			ans/=(long double)(b+j);
	}*/
	for(i=0;i<n;i++)
	{
		ans1=(b-i);
		ans2=(b+a-i);
		ans*=(double)ans1/(double)ans2;
	}
	if(a+b<n)
		ans=2;
	ans=1.0-ans;
	printf("%lf\n",ans);
	return 0;
}


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

namespace _132
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            var A = ReadInts();
             A = ReadInts();
             var B = ReadInts();
             B = ReadInts();
             Dictionary<int, int> r = new Dictionary<int, int>();
            foreach (var it in A)
            {
                foreach (var t in B)
                {
                    if (t != it)
                    {
                        if (t % it == 0)
                        {
                            var d = t / it;
                            if (!r.ContainsKey(d)) r[d] = 0;
                            r[d]++;
                        }
                    }
                }
            }
            Console.WriteLine(r[r.Max(x=>x.Key)]);
        }

        static IEnumerable<int> ReadInts(Func<int, int> f = null)
        {
            var t = Console.ReadLine();
            var ret = new List<int>();
            foreach (var it in t.Split(' '))
                ret.Add( f == null ? int.Parse(it): f(int.Parse(it)));
            return ret;
        }
    }
}

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

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

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

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

using System;
using System.Linq;
namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n= int.Parse(Console.ReadLine());
            int[] a= Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int m = int.Parse(Console.ReadLine());
            int[] b= Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int count = 0;
            int max = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (b[j]%a[i]==0)
                    {
                        int rez = b[j] / a[i];
                        if (rez>max)
                        {
                            max = rez;
                            count=1;
                        }
                        else if (rez==max)
                        {
                            count++;
                        }
                    }
                }
            }
            Console.WriteLine(count) ;
        }
    }
}


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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            long n, x, y;
            string s = Console.ReadLine();
            char[] par = { ' ' };
            string[] ss = s.Split(par);
            n = Convert.ToInt64(ss[0]);
            x = Convert.ToInt64(ss[1]);
            y = Convert.ToInt64(ss[2]);

            if (n > y)
            {
                Console.WriteLine(-1);
            }
            else
            {
                if ((y - n + 1) * (y - n + 1) >= x)
                {
                    for (int i = 0; i < n - 1; i++)
                        Console.WriteLine("1");
                    Console.WriteLine(y - n + 1);
                }
                else Console.WriteLine(-1);
            }
        }
    }
}

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(); }
}


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

namespace ProgrammingContest.Codeforces.Round9
{
    class C
    {
        public static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            double vb = double.Parse(s[1]);
            double vs = double.Parse(s[2]);

            s = Console.ReadLine().Split(' ');
            double[] busStopX = new double[n];
            for (int i = 0; i < n; i++)
            {
                busStopX[i] = double.Parse(s[i]);
            }

            s = Console.ReadLine().Split(' ');
            double xu, yu;
            xu = double.Parse(s[0]);
            yu = double.Parse(s[1]);

            int optIndex = -1;
            double timeMin = double.MaxValue;
            double distMin = double.MaxValue;
            for (int i = 0; i < n; i++)
            {
                double dx = xu - busStopX[i];
                double dy = yu;
                double dist = Math.Sqrt(dx * dx + dy * dy);
                double time = busStopX[i] / vb + dist / vs;
                if (timeMin > time || timeMin == time && distMin > dist)
                {
                    timeMin = time;
                    distMin = dist;
                    optIndex = i;
                }
            }
            Console.WriteLine(optIndex+1);
        }
    }
}

And again a misfortune fell on Poor Student. He is being late for an exam.Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.Poor Student knows the following:   during one run the minibus makes n stops, the i-th stop is in point (xi, 0)  coordinates of all the stops are different  the minibus drives at a constant speed, equal to vb  it can be assumed the passengers get on and off the minibus at a bus stop momentarily  Student can get off the minibus only at a bus stop  Student will have to get off the minibus at a terminal stop, if he does not get off earlier  the University, where the exam will be held, is in point (xu, yu)  Student can run from a bus stop to the University at a constant speed vs as long as needed  a distance between two points can be calculated according to the following formula:   Student is already on the minibus, so, he cannot get off at the first bus stop Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.

The first line contains three integer numbers: 2 ≤ n ≤ 100, 1 ≤ vb, vs ≤ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn ≤ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.

In the only line output the answer to the problem — index of the optimum bus stop.

NoteAs you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.

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

namespace ProgrammingContest.Codeforces.Round9
{
    class C
    {
        public static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            double vb = double.Parse(s[1]);
            double vs = double.Parse(s[2]);

            s = Console.ReadLine().Split(' ');
            double[] busStopX = new double[n];
            for (int i = 0; i < n; i++)
            {
                busStopX[i] = double.Parse(s[i]);
            }

            s = Console.ReadLine().Split(' ');
            double xu, yu;
            xu = double.Parse(s[0]);
            yu = double.Parse(s[1]);

            int optIndex = -1;
            double timeMin = double.MaxValue;
            double distMin = double.MaxValue;
            for (int i = 1; i < n; i++)
            {
                double dx = xu - busStopX[i];
                double dy = yu;
                double dist = Math.Sqrt(dx * dx + dy * dy);
                double time = busStopX[i] / vb + dist / vs;
                //Console.WriteLine("{0}, {1}", dist, time);
                if (timeMin > time || timeMin == time && distMin > dist)
                {
                    timeMin = time;
                    distMin = dist;
                    optIndex = i;
                }
            }
            Console.WriteLine(optIndex+1);
        }
    }
}


using System; using System.Linq;

class P {
  static void Main() {
    Console.ReadLine();
    var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var left = 0;
    var props = new int[p.Length];
    foreach (var ai in a) {
      left += ai;
      for (var j = p.Length - 1; j >= 0 ; j--) if (p[j] <= left) {
        props[j]++;
        left -= p[j];
        j++;
      }
    }
    Console.WriteLine(string.Join(" ", props));
    Console.Write(left);
  }
}

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

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

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

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

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

namespace ConsoleApplication10
{
    class Program
    {
       /*static long ch (long x)
        {
            if (x > 0)
                return ;
            else
                return ;
        }*/
        static void Main(string[] args)
        {
            long n = Convert.ToInt64(Console.ReadLine());
            string s = Console.ReadLine();
            string[] p = s.Split(' ');
            s = Console.ReadLine();
            string[] pr = s.Split(' ');
            long bal = 0;
            long a = Convert.ToInt64(pr[0]);
            long b = Convert.ToInt64(pr[1]);
            long c = Convert.ToInt64(pr[2]);
            long d = Convert.ToInt64(pr[3]);
            long e = Convert.ToInt64(pr[4]);
            long a1 = 0;
            long b1 = 0;
            long c1 = 0;
            long d1 = 0;
            long e1 = 0;
            for (int i = 1; i <= n; i++)
            {
                bal = bal + Convert.ToInt64(p[i - 1]);
                e1 = e1 + bal / e;
                bal = bal % e;
                d1 = d1 + bal / d;
                bal = bal % d;
                c1 = c1 + bal / c;
                bal = bal % c;
                b1 = b1 + bal / b;
                bal = bal % b;
                a1 = a1 + bal / a;
                bal = bal % a;

            }
            Console.WriteLine(a1+" "+b1+" "+c1+" "+d1+" "+e1);
            Console.WriteLine(bal);

        }
    }
}


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

namespace cf
{
    class Program
    {

        static void Main(string[] args)
        {
            try
            {
                int[] nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int[] ar = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int c = 0;
                while (ar[0] != nk[1])
                {
                    bool x = false;
                    for (int i = 0; i < ar.Length - 1; i++)
                    {
                        if (ar[i] != ar[i + 1])
                        {
                            if (ar[i] != nk[1])
                            {
                                ar[i]++;
                                x = true;
                            }
                        }
                        else if (i == ar.Length - 2)
                        {
                            if (ar[i] == ar[i + 1])
                            {
                                if (ar[i] != nk[1])
                                {
                                    ar[i+1]++;
                                    x = true;
                                }
                                else
                                {
                                    if (ar[i] != nk[1])
                                    {
                                        ar[i]++;
                                        x = true;
                                    }
                                    if (ar[i + 1] != nk[1])
                                    {
                                        ar[i + 1]++;
                                        x = true;
                                    }
                                }
                            }
                        }
                    }
                    if (x)
                        c++;
                    //for (int j = 0; j < ar.Length; j++)
                    //{
                    //    Console.Write(ar[j] + " ");
                    //}
                    //Console.WriteLine();
                }
                Console.WriteLine(c-1);
                Console.ReadKey();

            }
            catch { }
            }

    }
}

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

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

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

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

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

namespace ProgrammingContest.Codeforces.Round59
{
    class B
    {
        public static void Main()
        {
            int[] nk = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));
            int n = nk[0], k = nk[1];
            int[] sol = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));
            int res = 0;
            for (; ; res++)
            {
                bool updated = false;
                for (int i = 0; i < sol.Length && sol[i] < k; i++)
                {
                    if (i == sol.Length - 1 || sol[i] != sol[i + 1])
                    {
                        sol[i]++;
                        updated = true;
                    }
                }
                if (!updated)
                    break;
            }
            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static List<int> roots = new List<int>();
        static bool[,] graph;
        static bool[,] graph2;
        static bool[] used;
        static int n;
        static int count;
        static int cycleCount = 0;

        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            n = int.Parse(str[0]);
            int m = int.Parse(str[1]);
            used = new bool[n];
            graph = new bool[n, n];
            graph2 = new bool[n, n];
            int a;
            int b;

            for (int i = 0; i < m; i++)
            {
                str = Console.ReadLine().Split(' ');
                a = int.Parse(str[0]) - 1;
                b = int.Parse(str[1]) - 1;
                graph[a, b] = true;
                graph[b, a] = true;
            }

            Solve();

            if (cycleCount == 1 && count == 1)
            {
                Console.WriteLine("FNTAGN!");
            } else
            {
                Console.WriteLine("NO");
            }
        }

        static void Solve()
        {
            used = new bool [n];
            count = 0;

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    count++;
                    DFS(i);
                }
            }
        }

        static void DFS(int v)
        {
            used[v] = true;
            for (int j = 0; j < n; j++)
            {
                if (j != v && used[j] && graph[v, j] && !graph2[v,j])
                {
                    cycleCount++;
                }
                graph2[v, j] = true;
                graph2[j, v] = true;
                if (!used[j] && graph[v,j])
                {
                    DFS(j);
                }
            }
        }
    }
}

...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");
        }
    }
}


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)
        {
            string s = Console.ReadLine();
            s = Console.ReadLine();
            int l = -1, r = -1, k = 0;
            for (int i = 0; i < s.Length; i++)
            {

                if (s[i] == 'L')
                {
                    l = i;
                    if(r!=-1 && (i - r )% 2 == 0 ){k++; }
                }
                else if (s[i] == 'R')
                {
                    if (r == -1 && l==-1) { k += i; }
                    r = i;
                    if (l!=-1 &&(i - l )% 2 == 0){k++; }
                }

            }
            if (l>r) k += s.Length-l-1;
            if (l == -1 && r == -1) k = s.Length;

            Console.WriteLine(k);

        }
    }
}

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);
        }
    }
}


using System;
using static System.Console;

namespace _66B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = default(int);
            int covered = default(int), maxCovered = default(int);
            n = Int32.Parse(ReadLine());
            int[] fields = new int[n];
            string input = ReadLine();
            for(int i= 0; i < n; i++)
            {
                fields[i] = Int32.Parse(input.Split(' ')[i]);
            }

            for(int CurrentField = 0; CurrentField < fields.Length; CurrentField++)
            {
                covered = 1;
                for(int left = CurrentField -1; (left >= 0)&&(fields[left] < fields[left +1]); left--)
                {
                    covered++;
                }
                for(int right = CurrentField +1; (right < fields.Length)&&(fields[right] < fields[right-1]); right++)
                {
                    covered++;
                }
                if(covered > maxCovered)
                {
                    maxCovered = covered;
                }
            }
            Write(maxCovered);
        }
    }
}

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

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

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

using System;
public class Program
    {
        public static void Main(string[] args)
        {
            int[] data;
            {
                string[] input = Console.In.ReadToEnd().Split(new char[] { ' ', '\r', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                data = new int[input.Length];
                for (int i = 1; i < input.Length; ++i)
                    data[i] = int.Parse(input[i]);
            }
            int maximum = 1;
            for (int i = 2, cntr = 1, mntn=1; i < data.Length; cntr = mntn)
            {
                while(i<data.Length && data[i]>=data[i-1])
                {
                    cntr++; i++;
                }
                while(i<data.Length && data[i]<=data[i-1])
                {
                    if (data[i] == data[i - 1]) mntn++;
                    else mntn = 1;
                    i++; cntr++;
                }
                if (cntr > maximum) maximum = cntr;
            }
            Console.WriteLine(maximum);
        }
    }


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

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //int n = int.Parse(Console.ReadLine());
            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var n = int.Parse(Console.ReadLine());
            var input = new int[n][];

            var front = new Dictionary<int, int>();
            var back = new Dictionary<int, int>();
            var memo = new Dictionary<Tuple<int, int>, int>();
            for(int i =0; i< n; i++)
            {
                input[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int l = input[i][0];
                int r = input[i][1];

                if (!front.Keys.Contains(l)) front[l] = 1;
                else front[l]++;

                if (!back.Keys.Contains(r)) back[r] = 1;
                else back[r]++;

                if (!memo.Keys.Contains(Tuple.Create(l,r))) memo[Tuple.Create(l,r)]=1;
                else memo[Tuple.Create(l, r)]++;

            }

            int num = n / 2 + n % 2;
            int turn = int.MaxValue;

            foreach(var item in front)
            {
                if (item.Value >= num)
                {
                    turn = 0;
                    break;
                }
                else if(back.Keys.Contains(item.Key))
                {
                    int tmp = 0;
                    if(memo.Keys.Contains(Tuple.Create(item.Key, item.Key)))
                    {
                        tmp = memo[Tuple.Create(item.Key, item.Key)];
                    }

                    if(item.Value + back[item.Key]-tmp >= num)
                    {
                        turn = Math.Min(turn , num - item.Value);
                    }

                }
            }

            foreach (var item in back)
            {
                if (item.Value >= num)
                {
                    turn = Math.Min(turn, item.Value);

                }

                if (front.Keys.Contains(item.Key))
                {
                    int tmp = 0;
                    if (memo.Keys.Contains(Tuple.Create(item.Key, item.Key)))
                    {
                        tmp = memo[Tuple.Create(item.Key, item.Key)];
                    }

                    if (item.Value + front[item.Key] - tmp >= num)
                    {
                        turn = Math.Min(turn, item.Value-tmp);
                    }

                }
            }

            if (turn == int.MaxValue) turn = -1;

            Console.WriteLine(turn);

        }

    }

}

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

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

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

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

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;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      int n = input.ReadInt();
      var a = new Dictionary<int, int>();
      var b = new Dictionary<int, int>();
      for (int i = 0; i < n; i++)
      {
        int c1 = input.ReadInt();
        int c2 = input.ReadInt();
        AddCount(a, c1);
        if (c1 != c2)
          AddCount(b, c2);
      }
      int m = (n + 1) / 2;
      int ans = n;
      foreach (var c in a.Keys.Concat(b.Keys).Distinct())
      {
        int x = GetCount(a, c);
        int y = GetCount(b, c);
        if (x + y < m)
          continue;
        ans = Min(ans, Max(0, m - x));
      }
      Console.Write(ans == n ? -1 : ans);
    }

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

    #region Service functions

    private static void AddCount<T>(Dictionary<T, int> counter, T item)
    {
      int count;
      if (counter.TryGetValue(item, out count))
        counter[item] = count + 1;
      else
        counter.Add(item, 1);
    }

    private static int GetCount<T>(Dictionary<T, int> counter, T item)
    {
      int count;
      return counter.TryGetValue(item, out count) ? count : 0;
    }

    private static int GCD(int a, int b)
    {
      while (b != 0)
      {
        a %= b;
        int t = b;
        b = a;
        a = t;
      }
      return a;
    }

    #endregion
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int ReadInt()
    {
      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 ReadLong()
    {
      return long.Parse(this.ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(this.ReadToken(), CultureInfo.InvariantCulture);
    }

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

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

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

    public string ReadToken()
    {
      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
}


using System;
using System.Globalization;
namespace eolimp
{
   class Program
   {
       public static void Main (string[] args)
       {
			System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
			string []s = Console.ReadLine().Split(' ');

			int n = int.Parse(s[0]), b = int.Parse(s[1]),m=0;
			s = Console.ReadLine().Split(' ');
			int [] a = new int [n];
			double [] c = new double [n];
			for(int i=0;i<n;++i)
			{
				a[i] = int.Parse(s[i]);
				m = Math.Max(a[i],m);
			}

			for(int i=0;i<n;++i)
			{
				int x = m-a[i];
				if (b<x) {Console.WriteLine(-1); return ;}
				c[i] = x;
				b-=x;
			}
			for(int i=0;i<n;++i)
			{
						Console.WriteLine((c[i]+1.0*b/n).ToString());
			}
       }
   }
}

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

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

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

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

namespace _2016_08_11_problem_about_equation
{
    class Program
    {
        static void Main(string[] args)
        {
            string nb, a;
            string [] nbArr;
            string[] aArr;
            int summeBottle;
            decimal toDivide;
            bool possible = true;

            nb = Console.ReadLine();
            nbArr = nb.Split(new char [] {' '});
            a = Console.ReadLine();
            aArr = a.Split(new char[] { ' ' });
            summeBottle = int.Parse(nbArr[1]);

            for (int i = 0; i < aArr.Length; i++)
            {
                summeBottle = summeBottle + int.Parse(aArr[i]);
            }

            toDivide = summeBottle / decimal.Parse(nbArr[0]);

            int j = 0;
            while (possible == true && j < aArr.Length)
            {
                if (decimal.Parse(aArr[j]) > toDivide)
                    possible = false;
                j++;
            }

            CultureInfo en = new CultureInfo("en-US", false);

            if (possible == false)
                Console.WriteLine("-1");
            else
                for (int i = 0; i < aArr.Length; i++ )
                {
                    aArr[i] = Convert.ToString(toDivide - decimal.Parse(aArr[i]));
                    Console.WriteLine((String.Format("{0:0.000000}", decimal.Parse(aArr[i]), 6)).Replace(",", "."));

                }

        }
    }
}


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

namespace _38A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            string[] d = Console.ReadLine().Split();
            string[] str = Console.ReadLine().Split();

            int a = Convert.ToInt32(str[0]);
            int b = Convert.ToInt32(str[1]);

            int total = 0;

            for (int i = a; i <= b; ++i)
            {
                total += Convert.ToInt32(d[i - 1]);
            }

            Console.WriteLine(total);
        }
    }
}

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

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

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

using System;
 class Program
    {
        public static void Main(string[] args)
        {
            string[] input = Console.In.ReadToEnd().Split(new char[] { ' ', '\r', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            int sum = 0;
            for (int a = int.Parse(input[input.Length - 2]), b = int.Parse(input[input.Length - 1]); a < b; ++a)
                sum += int.Parse(input[a]);
            Console.WriteLine(sum);
        }
    }


using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.In.ReadLine());
            int a = Int32.Parse(Console.In.ReadLine());
            int b = Int32.Parse(Console.In.ReadLine());

            if ((a * b < n) ||
                ((a < 1) && (a > 100)) ||
                ((b < 1) && (b > 100)) ||
                ((n < 1) && (n > 10000)))
            {
                Console.Out.WriteLine("-1");
                Environment.Exit(0);
            }

            int man = 1;
            for (int row = 0; row < a; row++)
            {
                if ((b % 2 == 0) && (row % 2 == 1))
                {
                    man += (b - 1);
                    for (int col = b - 1; col >= 0; col--)
                    {
                        if (man <= n)
                            Console.Out.Write(man.ToString() + " ");
                        else
                            Console.Out.Write("0 ");
                        man--;
                    }
                    man += (b + 1);
                }
                else
                {
                    for (int col = 0; col < b; col++)
                    {
                        if (man <= n)
                            Console.Out.Write(man.ToString() + " ");
                        else
                            Console.Out.Write("0 ");
                        man++;
                    }
                }
                Console.Out.WriteLine("");
            }
        }
    }
}

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();
		}
	}
}


using System;
class Program
    {
        static void Main(string[] args)
        {
            string input = Console.In.ReadToEnd().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)[1];
            char[] result;
            int i,j;
            switch(input.Length%3)
            {
                case 1:
                    result = new char[input.Length + input.Length / 3 + 1];
                    result[2] = '-';
                    result[0] = input[0];
                    result[1] = input[1];
                    result[5] = '-';
                    result[3] = input[2];
                    result[4] = input[3];
                    i = 6;
                    j = 4;
                    break;
                case 2:
                    result = new char[input.Length / 3 + input.Length + 1];
                    result[2] = '-';
                    result[0] = input[0];
                    result[1] = input[1];
                    i = 3;
                    j = 2;
                    break;
                default:
                    result = new char[input.Length / 3 + input.Length];
                    j = i = 0;
                    break;
            }
            for(;i<input.Length;)
            {
                result[i++] = input[j++];
                result[i++] = input[j++];
                result[i++] = input[j++];
                result[i++] = '-';
            }
            result[result.Length - 1] = '\n';
            Console.Write(new string(result));
        }
    }

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

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

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

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

namespace CodeForce
{
    class _25b
    {
        public static void Main()
        {
            var line = Console.ReadLine();
            line = Console.ReadLine();
            var result = string.Empty;
            if (line.Length == 2)
            {
                Console.WriteLine(line);
                return;
            }
            var idx = 0;
            if (line.Length % 2 == 1)
            {
                result = line.Substring(0, 3);
                idx = 3;
            }
            else
            {
                result = line.Substring(0, 2);
                idx = 2;
            }
            for (var i = idx; i < line.Length; i += 2)
            {
                result += "-" + line.Substring(i, 2);
            }
            Console.WriteLine(result);
        }
    }
}