Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!

The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.

Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.

welcome to the
Codeforces
Beta
Round 5

and
good luck

program format;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  a: array [1..10000] of string;
  mx, r, n, k, f, j, i: integer;
  b: boolean;

begin
  b := true;
  mx := 0;
  r := 0;
  while not eof do
  begin
    inc(r);
    readln(a[r]);
    if (length(a[r]) > mx) then mx := length(a[r]);
  end;
  for i := 1 to mx + 2 do write('*');
  writeln;
  for i := 1 to r do
  begin
    f := mx - length(a[i]);
    n := f div 2;
    k := f div 2;
    write('*');
    if (f mod 2 = 1) then
    begin
      if b then inc(k)
      else inc(n);
      b := not b;
    end;
    for j := 1 to n do write(' ');
    write(a[i]);
    for j := 1 to k do write(' ');
    writeln('*');
  end;
  for i := 1 to mx + 2 do write('*');
  writeln;
end.


In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known: li — the number of the starting section,  ri — the number of the finishing section (li≤ri), ti — the time a biathlete needs to complete an section of the path, ci — the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman. The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri-li+1)·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives k·ci roubles.In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.We should also add that Nikita can bet on each section and on any contestant running in this section.Help the friends find the maximum possible profit.

The first line contains two integers n and m (1≤n,m≤100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1≤li≤ri≤n, 1≤ti,ci≤1000).

Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.

In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.
In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var n,m,i,j,k,s:integer;
    a,b,c,t,r,l,ans:array[1..10000] of integer;
begin
//assign(input,'in.txt'); reset(input);
//assign(output,'out.txt'); rewrite(output);
readln(n,m);
for i:=1 to n do
a[i]:=100500000;
for i:=1 to m do
begin
readln(l[i],r[i],t[i],c[i]);
for j:=l[i] to r[i] do
if t[i]<a[j] then begin a[j]:=t[i]; b[j]:=c[i]; end;
end;
s:=0;
for i:=1 to n do
s:=s+b[i];
writeln(s);
//close(input); close(output);
end.


Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements.

The first line of the input data contains an integer n (1≤n≤10^5). The second line contains an array of original integers a1,a2,...,an (-10^9≤ai≤10^9).

Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).

Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3].

{$R+ Q+ I+}
{$APPTYPE CONSOLE}
uses
  SysUtils;
var
   n,k,i,j : integer;
   s,ans : int64;
   a : array[1..100001] of integer;
begin
     read(n);
     k := 1;
     ans := 0;
     for i := 1 to n do read(a[i]);
     for i := 1 to n - 1 do
         if a[i] = a[i+1] then inc(k)
         else begin
              s := 0;
              for j := 1 to k do s := s + j;
              ans := ans + s;
              k := 1;
         end;
     s := 0;
     for i := 1 to k do s := s + i;
     ans := ans + s;

     write(ans);
end.


The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.There are n stations in the subway. It was built according to the Bertown Transport Law:  For each station i there exists exactly one train that goes from this station. Its destination station is pi, possibly pi=i;  For each station i there exists exactly one station j such that pj=i. The President will consider the convenience of subway after visiting it. The convenience is the number of ordered pairs (x,y) such that person can start at station x and, after taking some subway trains (possibly zero), arrive at station y (1≤x,y≤n).The mayor of Bertown thinks that if the subway is not convenient enough, then the President might consider installing a new mayor (and, of course, the current mayor doesn't want it to happen). Before President visits the city mayor has enough time to rebuild some paths of subway, thus changing the values of pi for not more than two subway stations. Of course, breaking the Bertown Transport Law is really bad, so the subway must be built according to the Law even after changes.The mayor wants to do these changes in such a way that the convenience of the subway is maximized. Help him to calculate the maximum possible convenience he can get!

The first line contains one integer number n (1≤n≤100000) — the number of stations.
The second line contains n integer numbers p1, p2, ..., pn (1≤pi≤n) — the current structure of the subway. All these numbers are distinct.

Print one number — the maximum possible value of convenience.

In the first example the mayor can change p2 to 3 and p3 to 1, so there will be 9 pairs: (1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,1), (3,2), (3,3).
In the second example the mayor can change p2 to 4 and p3 to 5.

                  const eps=0.0000000001;  besk=20000000000008;  nn=200000;
   label 1,2,3,4,5,6;
    type
    mas=array [0..nn] of int64;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..nn] of int64;mass1=^mass;
    var start,kk,ans,pp,qq,aaa,bbb,ccc,tt,aa,bb,jj,ii,ott,time,ppp,istart,jstart,iii,newdl, t1,t2,cc,ll,rr,oldpos,t,jjj,kol,pos,dloch,told,p,q,pmin,ppold,ot,pmax,imax,p1,p2,p3,p4,l,nm,n,s2,m,smin,cen:int64;
   mask,k, step, i,j:longint;
    s0,s1,aanew,bbnew:extended;
    y,xx,yy,och,s,d11,a,b,prev,next,z,x,newc,d,c,nap:array[-10..1000001] of int64;
    sd:array[-1000..1000000] of char;
    yyy:array[-10..1000000,0..11] of longint;
    dot,dd:array[-10..1010,-10..1010] of int64;
    ddminus, ppole:array[-1..2000,-100..1502] of int64;
   sss,text1,text2:array[-10..2000000] of string;
     stest,ss3,ss1,ss2:string;
     ch1,ch2:char;
     ddd1:array[-1..400000,-1..10] of int64;
     marked:array[-100..1500,-100..1500] of boolean;
    {sss:string;ch:char;
   } pole :array [-10..1500,-10..1500] of char;
    st:array[0..nn] of string;
    stest1,ss:string;
     v0,v1,t0:real;
     zv:point;
     newx,newy:array[-1..200000] of int64;

     koef,yot:extended;
      globflag, flag2,flag,flag1:boolean;
    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p/pi*180;
 end;
  function min(x,y:int64):int64;begin min:=x;if y<x then min:=y; end;
  function max(x,y:int64):int64;begin max:=x;if y>x then max:=y; end;

  function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

procedure udal(ii:longint);
begin  next[prev[ii]]:=next[ii]; prev[next[ii]]:=prev[ii];  end;

begin
   { assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
    }

     read(n);
     for i:=1 to n do begin read(a[i]);  end;

     for i:=0 to n+1 do begin next[i]:=i+1;prev[i]:=i-1; end;
while next[0]<=n do
  begin
     inc(p); q:=0;
     start:=next[0];
     pos:=start;
     repeat udal(pos); inc(q); pos:=a[pos];  until pos=start;
     x[p]:=q;

  end;

  if p<=2 then begin  writeln(n*n); goto 1; end;
  {writeln('p= ',p);
  for i:=1 to p do write(x[i],' '); writeln;
   }
  t1:=0;
  for i:=1 to p do if x[i]>t1 then begin imax:=i; t1:=x[i]; end;

  t2:=0;
  for i:=1 to p do if (x[i]>t2)and(i<>imax) then begin  t2:=x[i]; ii:=i; end;

 { writeln(t1,' ',t2);
  }
  for i:=1 to n do if (i<>imax)and(i<>ii) then ans:=ans+x[i]*x[i];

 { writeln('ans= ',ans);
  }
  writeln(ans+(t1+t2)*(t1+t2));

   1:    close(output);
end.


«Next please», — the princess called and cast an estimating glance at the next groom.The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing.The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1,t2,...,tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1.

The only line of input data contains three integer numbers n,a and b (1≤n≤100,0≤a,b≤15,n>a+b), separated with single spaces.

Output any sequence of integers t1,t2,...,tn, where ti (1≤ti≤50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1.

Let's have a closer look at the answer for the first sample test.
  The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.  The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.

Var t2,v,v1,t,t1,r:real;max1,xv,d,x2,y2,g,c,l,z,k,j,rez,x,y,x1,y1,i,n,uk,a,kol:integer;b,kolv:int64;
begin
 //  assign(input,'input.txt');
 //  assign(output,'output.txt');
   readln(n,a,b);
   if (a<>0) and (a=n-1) and (b=0)
   then Begin
           writeln(-1);
           halt(0);
        end
   else if (a<>0) and (b=0)
        then Begin
               write(1,' ',1,' ');
               c:=1;
               for i:=1 to a do
                Begin
                   inc(c);
                   write(c,' ');
                end;
               for i:=1 to n-a-2 do
                  write(c,' ');
               halt(0);
             end;
   write(1,' ');
   c:=1;
   for i:=1 to b do
      Begin
         c:=c*2;
         write(c,' ');
      end;
   for i:=1 to a do
      Begin
         inc(c);
         write(c,' ');
      end;
   for i:=1 to n-a-b-1 do
      write(c,' ');
end.


You have been offered a job in a company developing a large social network. Your first task is connected with searching profiles that most probably belong to the same user.The social network contains n registered profiles, numbered from 1 to n. Some pairs there are friends (the "friendship" relationship is mutual, that is, if i is friends with j, then j is also friends with i). Let's say that profiles i and j (i≠j) are doubles, if for any profile k (k≠i, k≠j) one of the two statements is true: either k is friends with i and j, or k isn't friends with either of them. Also, i and j can be friends or not be friends.Your task is to count the number of different unordered pairs (i,j), such that the profiles i and j are doubles. Note that the pairs are unordered, that is, pairs (a,b) and (b,a) are considered identical.

The first line contains two space-separated integers n and m (1≤n≤10^6, 0≤m≤10^6), — the number of profiles and the number of pairs of friends, correspondingly.
Next m lines contains descriptions of pairs of friends in the format "v u", where v and u (1≤v,u≤n,v≠u) are numbers of profiles that are friends with each other. It is guaranteed that each unordered pair of friends occurs no more than once and no profile is friends with itself.

Print the single integer — the number of unordered pairs of profiles that are doubles.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the %I64d specificator.

In the first and second sample any two profiles are doubles.
In the third sample the doubles are pairs of profiles (1,3) and (2,4).

{$apptype console}
{$R-,S+,I+,Q-}
const
     inf = 'input.txt';
     outf = 'output.txt';
     p = 1303;
var
 n,m,i,j:longint;
 x,tmp,ans,k:int64;
 a,b:array[0..1000010] of longint;
 pow,h:array[0..1000010] of int64;

 procedure sort(l,r:longint);
 var i,j:longint;
  begin
   i:=l;
   j:=r;
   x:=h[l+random(r-l+1)];
   repeat
    while h[i] < x do inc(i);
    while h[j] > x do dec(j);
    if i <= j then
     begin
      tmp:=h[i];
      h[i]:=h[j];
      h[j]:=tmp;
      inc(i);
      dec(j);
     end;
   until i > j;
   if i < r then sort(i,r);
   if j > l then sort(l,j);
  end;

begin
 //reset(input,inf);
 //rewrite(output,outf);
 randomize;
 read(n,m);
 for i:=1 to m do read(a[i],b[i]);
 pow[0]:=1;
 for i:=1 to n do pow[i]:=pow[i-1]*p;
 fillchar(h,sizeof(h),0);
 for i:=1 to m do
  begin
   inc(h[a[i]],pow[b[i]]);
   inc(h[b[i]],pow[a[i]]);
  end;
 ans:=0;
 for i:=1 to m do if h[a[i]]+pow[a[i]] = h[b[i]]+pow[b[i]] then inc(ans);
 sort(1,n);
 i:=1;
 while i <= n do
  begin
   j:=i;
   while (j < n) and (h[j+1] = h[i]) do inc(j);
   k:=j-i+1;
   inc(ans,k*(k-1) div 2);
   i:=j+1;
  end;
 writeln(ans);
end.


"The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter the Chamber of Secrets. These aren't good news for Lord Voldemort. The problem is, he doesn't want anybody to be able to enter the chamber. The Dark Lord is going to be busy sucking life out of Ginny.The Chamber of Secrets is an n×m rectangular grid in which some of the cells are columns. A light ray (and a basilisk's gaze) passes through the columns without changing its direction. But with some spell we can make a column magic to reflect the light ray (or the gaze) in all four directions when it receives the ray. This is shown in the figure below.   The left light ray passes through a regular column, and the right ray — through the magic column. The basilisk is located at the right side of the lower right cell of the grid and is looking to the left (in the direction of the lower left cell). According to the legend, anyone who meets a basilisk's gaze directly dies immediately. But if someone meets a basilisk's gaze through a column, this person will get petrified. We know that the door to the Chamber is located on the left side of the upper left corner of the grid and anyone who wants to enter will look in the direction of its movement (in the direction of the upper right cell) from that position.   This figure illustrates the first sample test. Given the dimensions of the chamber and the location of regular columns, Lord Voldemort has asked you to find the minimum number of columns that we need to make magic so that anyone who wants to enter the chamber would be petrified or just declare that it's impossible to secure the chamber.

The first line of the input contains two integer numbers n and m (2≤n,m≤1000). Each of the next n lines contains m characters. Each character is either "." or "#" and represents one cell of the Chamber grid. It's "." if the corresponding cell is empty and "#" if it's a regular column.

Print the minimum number of columns to make magic or -1 if it's impossible to do.

The figure above shows the first sample test. In the first sample we should make both columns magic. The dragon figure represents the basilisk and the binoculars represent the person who will enter the Chamber of secrets. The black star shows the place where the person will be petrified. Yellow lines represent basilisk gaze moving through columns.

var i, j, n, m, l, r: Longint;
    xq, yq, dq: array [1..10000000] of Longint;
    a: array [1..2000, 1..2000] of Char;
    dist: array [1..2000, 1..2000, 1..4] of Longint;
    mark: array [1..2000, 1..2000, 1..4] of Boolean;

function able(x, y, d: Longint): Boolean;
Begin
    if (x >= 1) and (x <= n) and (y >= 1) and (y <= m) and (mark[x, y, d] = false) then
        able := true
    else
        able := false;
End;

function gox(x: Longint): Longint;
Begin
    if x = 2 then
        gox := -1
    else
    if x = 4 then
        gox := 1
    else
        gox := 0;
End;

function goy(x: Longint): Longint;
Begin
    if x = 1 then
        goy := -1
    else
    if x = 3 then
        goy := 1
    else
        goy := 0;
End;

Begin
    readln(n, m);
    for i := 1 to n do begin
        for j := 1 to m do
            read(a[i, j]);
        readln;
    end;
    inc(m);
    l := 1;
    r := 1;
    xq[1] := 1;
    yq[1] := 1;
    dq[1] := 3;
    dist[1, 1, 3] := 0;
    mark[xq[1], yq[1], dq[1]] := true;
    while l <= r do begin
        if a[xq[l], yq[l]] = '#' then
        for i := 1 to 4 do
            if (i <> dq[l]) and (able(xq[l] + gox(i), yq[l] + goy(i), i)) then begin
                inc(r);
                xq[r] := xq[l] + gox(i);
                yq[r] := yq[l] + goy(i);
                dq[r] := i;
                dist[xq[r], yq[r], dq[r]] := dist[xq[l], yq[l], dq[l]] + 1;
                mark[xq[r], yq[r], dq[r]] := true;
            end;

        if able(xq[l] + gox(dq[l]), yq[l] + goy(dq[l]), dq[l]) then begin
            dist[xq[l] + gox(dq[l]), yq[l] + goy(dq[l]), dq[l]] := dist[xq[l], yq[l], dq[l]];
            xq[l] := xq[l] + gox(dq[l]);
            yq[l] := yq[l] + goy(dq[l]);
            mark[xq[l], yq[l], dq[l]] := true;
        end else
            inc(l);
    end;
    if mark[n, m, 3] = false then
        write(-1)
    else
        write(dist[n, m, 3]);
End.


Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l,r]. In other words, this function does the following: function rangeIncrement(l, r)    for i := l .. r do        a[i] = a[i] + 1Polycarpus knows the state of the array a after a series of function calls. He wants to determine the minimum number of function calls that lead to such state. In addition, he wants to find what function calls are needed in this case. It is guaranteed that the required number of calls does not exceed 10^5.Before calls of function rangeIncrement(l, r) all array elements equal zero.

The first input line contains a single integer n (1≤n≤10^5) — the length of the array a[1... n].
The second line contains its integer space-separated elements, a[1],a[2],...,a[n] (0≤a[i]≤10^5) after some series of function calls rangeIncrement(l, r).
It is guaranteed that at least one element of the array is positive. It is guaranteed that the answer contains no more than 10^5 calls of function rangeIncrement(l, r).

Print on the first line t — the minimum number of calls of function rangeIncrement(l, r), that lead to the array from the input data. It is guaranteed that this number will turn out not more than 10^5.
Then print t lines — the descriptions of function calls, one per line. Each line should contain two integers li,ri (1≤li≤ri≤n) — the arguments of the i-th call rangeIncrement(l, r). Calls can be applied in any order.
If there are multiple solutions, you are allowed to print any of them.

The first sample requires a call for the entire array, and four additional calls:
  one for the segment [2,2] (i.e. the second element of the array),  three for the segment [5,5] (i.e. the fifth element of the array).

uses math;
type mass=array[0..100000] of integer;
     maxx=array[1..100000,1..2] of integer;
var d,kol,q,q1,i1,z1,q2,k,uk,p,n,kolv,res,r,l,j,b,c,e,e1,max1:int64;s:string;i,z:integer;
    m,m1:mass;ch:char;u:boolean;qq,w,o,g,a:int64;min1,a1,b1,c1:extended;
    m2:maxx;
begin
  // assign(input,'input.txt');
  // assign(output,'output.txt');
   readln(n);
   for i:=1 to n do
     read(m[i]);
   a:=0;
   b:=0;
   for i:=1 to n do
      Begin
         while (a>0) and (m[i]<m[m1[a]]) do
            Begin
               for z:=max(m[i],m[m1[a-1]]) to m[m1[a]]-1 do
                  Begin
                     inc(b);
                     m2[b,1]:=m1[a];
                     m2[b,2]:=i-1;
                  end;
               if m[i]>m[m1[a-1]]
               then m[m1[a]]:=m[i]
               else dec(a);
            end;
         if m[i]>m[m1[a]]
         then Begin
                 inc(a);
                 m1[a]:=i;
              end;
      end;
   for i:=a downto 1 do
      Begin
         for z:=m[m1[i-1]] to m[m1[i]]-1 do
            Begin
               inc(b);
               m2[b,1]:=m1[i];
               m2[b,2]:=n;
            end;
      end;
   writeln(b);
   for i:=1 to b do
      writeln(m2[i,1],' ',m2[i,2]);
end.


Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w=xy. A split operation is transforming word w=xy into word u=yx. For example, a split operation can transform word "wordcut" into word "cutword".You are given two words start and end. Count in how many ways we can transform word start into word end, if we apply exactly k split operations consecutively to word start. Two ways are considered different if the sequences of applied operations differ. Two operation sequences are different if exists such number i (1≤i≤k), that in the i-th operation of the first sequence the word splits into parts x and y, in the i-th operation of the second sequence the word splits into parts a and b, and additionally x≠a holds.

The first line contains a non-empty word start, the second line contains a non-empty word end. The words consist of lowercase Latin letters. The number of letters in word start equals the number of letters in word end and is at least 2 and doesn't exceed 1000 letters.
The third line contains integer k (0≤k≤10^5) — the required number of operations.

Print a single number — the answer to the problem. As this number can be rather large, print it modulo 1000000007 (10^9+7).

The sought way in the first sample is:
ab → a|b → ba → b|a → ab
In the second sample the two sought ways are:
 ababab → abab|ab → ababab  ababab → ab|abab → ababab

program Task1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
const md = round(1e9)+7;
var t,s1,s2: string;
    n,i,col,k,j,l: integer;
    cnt0,cnt1,buf0,buf1: integer;
    r: array[0..1000]of integer;
begin
  readln(s1);
  readln(s2);
  readln(k);
  col:=0;
  if (s1=s2)then begin
    inc(col);
    r[col]:=0;
  end;
  n:=length(s1)-1;
  for i:=1 to n do begin
    t:=copy(s1,i+1,n+1-i)+copy(s1,1,i);
    if (t=s2)Then begin
      inc(col);
      r[col]:=i;
    end;
  end;
  if (col=0)then begin
    write(0);
    halt;
  end;

  cnt0:=1;
  cnt1:=0;

  for i:=1 to k do begin
    buf0:=cnt0;
    buf1:=cnt1;
    cnt0:=0;
    for j:=1 to n do
      cnt0:=(cnt0+buf1)mod md;
    cnt1:=buf0;
    for j:=1 to n-1 do
      cnt1:=(cnt1+buf1)mod md;
  end;

  j:=0;
  for i:=1 to col do
    if (r[i]=0)then
      j:=(j+cnt0)mod md
    else
      j:=(j+cnt1)mod md;
  write(j);
end.

[{'input': ['ab\r\nab\r\n2\r\n'], 'output': ['1\r\n']}, {'input': ['ababab\r\nababab\r\n1\r\n'], 'output': ['2\r\n']}, {'input': ['ab\r\nba\r\n2\r\n'], 'output': ['0\r\n']}, {'input': ['aaa\r\naaa\r\n0\r\n'], 'output': ['1\r\n']}, {'input': ['hi\r\nhi\r\n1\r\n'], 'output': ['0\r\n']}, {'input': ['abcd\r\ncbad\r\n5\r\n'], 'output': ['0\r\n']}, {'input': ['ab\r\nba\r\n10\r\n'], 'output': ['0\r\n']}, {'input': ['voodoo\r\ndoovoo\r\n100000\r\n'], 'output': ['792428974\r\n']}, {'input': ['ababab\r\nbababa\r\n100000\r\n'], 'output': ['377286908\r\n']}, {'input': ['abcdefgh\r\ncdefghab\r\n666\r\n'], 'output': ['83913683\r\n']}, {'input': ['aaaabaaaaaaaaaaabaaaaaaa\r\naaaaaaaaaabaaaaaaaaabaaa\r\n7477\r\n'], 'output': ['0\r\n']}, {'input': ['ssgqcodnqgfbhqsgineioafkkhcmmmihbiefialidgkffrhaiekebpieqgpplmsgmghphjsfgpscrbcgrssbccqroffnfgkfohljdarbpqmkolldcjcfhpodeqmgbdddlgoolesecdqsochdfgjsmorbnmiinjlpda\r\nljdarbpqmkolldcjcfhpodeqmgbdddlgoolesecdqsochdfgjsmorbnmiinjlpdassgqcodnqgfbhqsgineioafkkhcmmmihbiefialidgkffrhaiekebpieqgpplmsgmghphjsfgpscrbcgrssbccqroffnfgkfoh\r\n50897\r\n'], 'output': ['222669762\r\n']}, {'input': ['jfemedqrsqaopiekdosgjnhbshanggdqqpkhepjfrkgkshepbmkdnidmpgfojjjbeddkelccoqapnpkqbimlbgagllioqbdgnsejqcbicjbbijjlrjmkkarjdoganmfsmfohlspbsoldfspdacasgsrcndlhg\r\nhepbmkdnidmpgfojjjbeddkelccoqapnpkqbimlbgagllioqbdgnsejqcbicjbbijjlrjmkkarjdoganmfsmfohlspbsoldfspdacasgsrcndlhgjfemedqrsqaopiekdosgjnhbshanggdqqpkhepjfrkgks\r\n6178\r\n'], 'output': ['568786732\r\n']}, {'input': ['aaeddddadbcacbdccaeeeddecadbecbbcebdcdbcddcadcadccecccecdbabd\r\nadbecbbcebdcdbcddcadcadccecccecdbabdaaeddddadbcacbdccaeeeddec\r\n55400\r\n'], 'output': ['471327413\r\n']}, {'input': ['chajciihijjbjcgaedebdcjaaeaiffiggfdfbdjhikhbiijhbjciebgkadbbekijadafhjhgiidfjkjbgcdfdgjjfficbagghkdgdhdedihifcfkedcefcdfjaagiehccjbjhihcbdakbjfjdgakkfagddhekccbdjhejhakfccgghkdc\r\ndafhjhgiidfjkjbgcdfdgjjfficbagghkdgdhdedihifcfkedcefcdfjaagiehccjbjhihcbdakbjfjdgakkfagddhekccbdjhejhakfccgghkdcchajciihijjbjcgaedebdcjaaeaiffiggfdfbdjhikhbiijhbjciebgkadbbekija\r\n67572\r\n'], 'output': ['18146811\r\n']}, {'input': ['dkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjijdkjij\r\ndddkikjjidkkidijjjjkkjjikjdikiidijjikikjijjiijdikkjjjiddjjijkkkjkiijijkijdjjikikdjjjijdddjkjjdijjjjjjjddkjjkjjjdjjdkijjkijkkjkkkiiijdjijkkdjdjjjkkjkdddjidjjijdddkijididjdddidijjjjjdkidijjkkjiijkjjjjjjdjkkdddkjj\r\n31328\r\n'], 'output': ['0\r\n']}, {'input': ['lnxjsxjjfbrhijshlptgogxstvaybbueilocmaqwhlauulubpwtjtsdktgrowgbkhdotemhstqtxnpspmxjxrqymonnpcvrendrfxbwqxeedyamwvyyytxtmorkovoeklkabyexrfseimlaqlibaoaaeae\r\nalxckgrkneuqrqstpxormswxsyhaaoebqhfspyqjbxgytrpdoybxmmenllxxrrjtxtvhaoidjmaekiflxykmpnwageytemoewalwihbunbnvomqbututijjvdsbelrxestajokwysctfptalvegdahlboo\r\n44031\r\n'], 'output': ['0\r\n']}, {'input': ['cfacacbfaeadfdbedfdccdccdddaaa\r\ncbfaeadfdbedfdccdccdddaaacfaca\r\n15215\r\n'], 'output': ['668863397\r\n']}, {'input': ['xxx\r\nyyy\r\n0\r\n'], 'output': ['0\r\n']}, {'input': ['abc\r\ncba\r\n0\r\n'], 'output': ['0\r\n']}, {'input': ['ab\r\nba\r\n0\r\n'], 'output': ['0\r\n']}, {'input': ['abc\r\nabc\r\n1\r\n'], 'output': ['0\r\n']}, {'input': ['ab\r\nba\r\n9\r\n'], 'output': ['1\r\n']}, {'input': ['ab\r\nba\r\n10\r\n'], 'output': ['0\r\n']}, {'input': ['aa\r\naa\r\n1\r\n'], 'output': ['1\r\n']}, {'input': ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n100000\r\n'], 'output': ['486606280\r\n']}, {'input': ['aaaba\r\naaaad\r\n0\r\n'], 'output': ['0\r\n']}]


A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled "Special Olympics". He justly thought that, if the regular Olympic games have five rings, then the Special ones will do with exactly two rings just fine.Let us remind you that a ring is a region located between two concentric circles with radii r and R (r<R). These radii are called internal and external, respectively. Concentric circles are circles with centers located at the same point.Soon a white canvas, which can be considered as an infinite Cartesian plane, had two perfect rings, painted with solid black paint. As Sasha is very impulsive, the rings could have different radii and sizes, they intersect and overlap with each other in any way. We know only one thing for sure: the centers of the pair of rings are not the same.When Sasha got tired and fell into a deep sleep, a girl called Ilona came into the room and wanted to cut a circle for the sake of good memories. To make the circle beautiful, she decided to cut along the contour.We'll consider a contour to be a continuous closed line through which there is transition from one color to another (see notes for clarification). If the contour takes the form of a circle, then the result will be cutting out a circle, which Iona wants.But the girl's inquisitive mathematical mind does not rest: how many ways are there to cut a circle out of the canvas?

The input contains two lines.
Each line has four space-separated integers xi, yi, ri, Ri, that describe the i-th ring; xi and yi are coordinates of the ring's center, ri and Ri are the internal and external radii of the ring correspondingly (-100≤xi,yi≤100; 1≤ri<Ri≤100).
It is guaranteed that the centers of the rings do not coinside.

A single integer — the number of ways to cut out a circle from the canvas.

Figures for test samples are given below. The possible cuts are marked with red dotted line.

{$R-,S-,Q-,I-,O+}
{$M 64000000}

{$APPTYPE CONSOLE}

uses Math;
const
maxn = 2222;
type
circle=record
       x,y,r : integer;
       end;
var
x,y,r,rr,ans : integer;
c : array [1..4] of circle;

function cross (a,b : integer) : boolean;
begin
 if sqr(c [a].x-c [b].x)+sqr(c [a].y-c [b].y)>=sqr(c [a].r+c [b].r) then
 begin
  cross:=false;
  exit;
 end;
 if sqr(max (c [a].r,c [b].r)-min (c [a].r,c [b].r))>=sqr(c [a].x-c [b].x)+sqr(c [a].y-c [b].y) then
 begin
  cross:=false;
  exit;
 end;
 cross:=true;
end;

function into (a,b : integer) : boolean;
begin
 if c [b].r-c [a].r<=0 then
 begin
  into:=false;
  exit;
 end;
 if sqr(c [b].r-c [a].r)>=sqr(c [a].x-c [b].x)+sqr(c [a].y-c [b].y) then
 begin
  into:=true;
  exit;
 end;
 into:=false;
end;

function fill (a,b,d : integer) : boolean;
begin
 if (sqr(c [a].x-c [b].x)+sqr(c [a].y-c [b].y)>=sqr(c [a].r+c [b].r)) and into (a,d) then fill:=true
                                                                                else fill:=false;
end;

begin
 //reset (input,'input.txt');
 //rewrite (output,'output.txt');
 readln (x,y,r,rr);
 c [1].x:=x; c [2].x:=x;
 c [1].y:=y; c [2].y:=y;
 c [1].r:=r; c [2].r:=rr;
 readln (x,y,r,rr);
 c [3].x:=x; c [4].x:=x;
 c [3].y:=y; c [4].y:=y;
 c [3].r:=r; c [4].r:=rr;

 ans:=0;
 if not cross (1,3) and not cross (1,4) and not (into (1,4) and into (3,1)) and not fill (1,3,4) then inc (ans);
 if not cross (2,3) and not cross (2,4) and not (into (2,4) and into (3,2)) and not fill (2,3,4) then inc (ans);
 if not cross (3,1) and not cross (3,2) and not (into (3,2) and into (1,3)) and not fill (3,1,2) then inc (ans);
 if not cross (4,1) and not cross (4,2) and not (into (4,2) and into (1,4)) and not fill (4,1,2) then inc (ans);
 writeln (ans);
end.


The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.A path called normalized if it contains the smallest possible number of characters '/'.Your task is to transform a given path to the normalized form.

The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.

program t_path;

{$APPTYPE CONSOLE}

uses
  SysUtils;
type arr=array[1..100] of string;
var sz, x, y, i, n:integer;
    s, s2:string;
    a:arr;
    f:boolean;
begin
{  assign(input, 'input.txt');
  reset(input);
  assign(output, 'output.txt');
  rewrite(output);}
  readln(s);
  s:=s+'/';
  n:=length(s);
  sz:=0;
  x:=0;
  y:=0;
  for i:=1 to n do
    begin
        if (s[i]<>'/') and (x=0)
        then x:=i
        else if  (s[i]='/') and (y=0)and (x<>0)
             then begin
                     inc(sz);
                     y:=i;
                     a[sz]:=copy(s, x, (y-1)-x+1);
                     x:=0;
                     y:=0;
                  end;
    end;
  s2:='/'+a[1];
  for i:=2 to sz do
     s2:=s2+'/'+a[i];
  write(s2);
{  close(input);
  close(output); }
end.

[{'input': ['//usr///local//nginx/sbin\r\n'], 'output': ['/usr/local/nginx/sbin\r\n']}, {'input': ['////a//b/////g\r\n'], 'output': ['/a/b/g\r\n']}, {'input': ['/a/b/c\r\n'], 'output': ['/a/b/c\r\n']}, {'input': ['/\r\n'], 'output': ['/\r\n']}, {'input': ['////\r\n'], 'output': ['/\r\n']}, {'input': ['/a//aa/a//\r\n'], 'output': ['/a/aa/a\r\n']}, {'input': ['/aa//b/aa\r\n'], 'output': ['/aa/b/aa\r\n']}, {'input': ['////////////////////////////////////////////////////////////////////////////////////////////////////\r\n'], 'output': ['/\r\n']}, {'input': ['/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/\r\n'], 'output': ['/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb\r\n']}, {'input': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game\r\n']}, {'input': ['/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game\r\n']}, {'input': ['/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test\r\n']}, {'input': ['/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt\r\n']}, {'input': ['///a//a////a/a//a//a//a/////\r\n'], 'output': ['/a/a/a/a/a/a/a\r\n']}, {'input': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n'], 'output': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n']}, {'input': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/\r\n'], 'output': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n']}, {'input': ['/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a\r\n'], 'output': ['/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a\r\n']}, {'input': ['///////////////////////////////////////////////////////////////////////////////////////////////////z\r\n'], 'output': ['/z\r\n']}, {'input': ['/z//////////////////////////////////////////////////////////////////////////////////////////////////\r\n'], 'output': ['/z\r\n']}]


You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:  First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1≤i≤n) of array s equals . The operation x mod y means that we take the remainder of the division of number x by number y.  Then we write the contents of the array s to the array a. Element number i (1≤i≤n) of the array s becomes the i-th element of the array a (ai=si). You task is to find array a after exactly k described operations are applied.

The first line contains two space-separated integers n and k (1≤n≤2000, 0≤k≤10^9). The next line contains n space-separated integers a1,a2,...,an — elements of the array a (0≤ai≤10^9).

Print n integers  — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces.

{$apptype console}
{$maxstacksize 1000000}
{$b-}
const md=1000000007;
var
 cur,q,j,n,k,i:integer;
 d,ans,c,a:array[0..2001] of integer;

 Function gcd(a,b:integer):integer;
 begin
    if b=0 then gcd:=a else gcd:=gcd(b,a mod b);
 end;

begin
 {reset(input,'input.txt');
 rewrite(output,'output.txt'); }
 readln(n,k);
 for i := 1 to n do read(a[i]);
 if k=0 then
 begin
   for i := 1 to n do write(a[i],' ');
     writeln;
 end
 else
 begin
 dec(k);
 Fillchar(c,sizeof(c),0);
 c[0]:=1;
 for i := 1 to n do
 begin
    d[i]:=k+i; cur:=i;
    for j := 1 to i do
      begin
        q:=gcd(d[j],cur);
        d[j]:=d[j] div q;
        cur:=cur div q;
        if cur=1 then break;
      end;
     c[i]:=1;
     for j := 1 to i do c[i]:=(int64(c[i])*d[j]) mod md;
 end;
 Fillchar(ans,sizeof(ans),0);
 for i := 1 to n do
  for j := i to n do  ans[j]:=(ans[j]+int64(c[j-i])*a[i]) mod md;

  for i := 1 to n do write(ans[i],' ');
 end;
end.


Consider the following equation:  where sign [a] represents the integer part of number a.Let's find all integer z (z>0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means that there are no such positive integers x and y (x,y>0), for which the given above equation holds.Let's write out all such z in the increasing order: z1,z2,z3, and so on (zi<zi+1). Your task is: given the number n, find the number zn.

The first line contains a single integer n (1≤n≤40).

Print a single integer — the number zn modulo 1000000007 (10^9+7). It is guaranteed that the answer exists.


There are n piles of stones of sizes a1,a2,...,an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of the added pile.Your task is to determine the minimum cost at which you can gather all stones in one pile. To add some challenge, the stone piles built up conspiracy and decided that each pile will let you add to it not more than k times (after that it can only be added to another pile). Moreover, the piles decided to puzzle you completely and told you q variants (not necessarily distinct) of what k might equal. Your task is to find the minimum cost for each of q variants.

The first line contains integer n (1≤n≤10^5) — the number of stone piles. The second line contains n space-separated integers: a1,a2,...,an (1≤ai≤10^9) — the initial sizes of the stone piles.
The third line contains integer q (1≤q≤10^5) — the number of queries. The last line contains q space-separated integers k1,k2,...,kq (1≤ki≤10^5) — the values of number k for distinct queries. Note that numbers ki can repeat.

Print q whitespace-separated integers — the answers to the queries in the order, in which the queries are given in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

In the first sample one way to get the optimal answer goes like this: we add in turns the 4-th and the 5-th piles to the 2-nd one; then we add the 1-st pile to the 3-rd one; we add the 2-nd pile to the 3-rd one. The first two operations cost 1 each; the third one costs 2, the fourth one costs 5 (the size of the 2-nd pile after the first two operations is not 3, it already is 5).
In the second sample you can add the 2-nd pile to the 3-rd one (the operations costs 3); then the 1-st one to the 3-th one (the cost is 2); then the 5-th one to the 4-th one (the costs is 1); and at last, the 4-th one to the 3-rd one (the cost is 2).

const n=1024*128{1024};eps=1e-19; label 1,2;
type mas=array[-200000..2*n+1] of int64;
var step1,lll,rrr,pp,ot,i,j,k,l,m,n1,k1,w,mesto,jj,tt,num,pl1,pl2,pl3:longint;
gr1,gr2,step,ii,tt1,nnn,kol,d,raz1,raz2,v,s,st,q,t,p,gr:int64; flag1:boolean;
 perev:array[0..1000000] of boolean;
 ott:array[0..1000000] of int64;
sum,ppp,ccc, x,y, c,a,b,a1,b1:mas; flag:boolean;  pl:longint;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if (a[i]<a[j]) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if (a[i]>=a[j]) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);

end;
 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;

function usp(t:int64):boolean; var i,j:longint; k:int64;
  begin  k:=0;
      for i:=n1 downto 1 do
      if v=1 then k:=k+a[i] else if a[i]>t then
      k:=k+(a[i]-t-1) div (v-1) +1;
     if k<=t then usp:=true else usp:=false;
  end;

begin
{assign(input,'input.txt');reset(input);
assign(output,'output.txt');rewrite(output);
}

read(n1);
for i:=1 to n1 do begin  read(a[i]);    end;
    for i:=n1+1 to n do a[i]:=1000000000000;
   sort(a);
  { for i:=1 to n1 do write(a[i],' ');
  } for i:=1 to n do b[i]:=a[n1+1-i];
   sum[0]:=0; for i:=1 to n1 do sum[i]:=sum[i-1]+b[i];
  { for i:=1 to n1 do write(sum[i],' '); writeln;
  } for step1:=1 to 3  do
     begin
        kol:=(n1-1) div step1;   ott[step1]:=0;
        ii:=0;
        for i:=1 to kol do
      begin
        ii:=i;

        ott[step1]:=ott[step1]+(sum[1+ii*step1]-sum[1+(ii-1)*step1])*ii;
      end;
       { writeln(step,' ',ott[step],' ',1+ii*step);
       } ott[step1]:=ott[step1]+(sum[n1]-sum[1+ii*step1])*(ii+1);
     end;

    read(k); for j:=1 to k do
      begin
         read(step); st:=0;
         if step<=1 then  write(ott[step],' ');
         if step>1 then
           begin

        ii:=1; t:=1; gr1:=1;gr2:=gr1+ii*step;
       while gr2<=n1 do
      begin
     {    writeln('gr= ',gr2,' ',gr1,'   t=',t,' ');
     }   st:=st+(sum[gr2]-sum[gr1])*t;
       ii:=ii*step;   inc(t);
        gr1:=gr2;   gr2:=gr1+ii*step;
      end;
       { writeln(step,' ',ott[step],' ',1+ii*step);
       } st:=st+(sum[n1]-sum[gr1])*t;

          write(st,' ');
           end;
      end;

 1: close (output);
end.


A piece of paper contains an array of n integers a1,a2,...,an. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you are allowed to perform not more than k following operations — choose an arbitrary element from the array and add 1 to it. In other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times).Your task is to find the maximum number of occurrences of some number in the array after performing no more than k allowed operations. If there are several such numbers, your task is to find the minimum one.

The first line contains two integers n and k (1≤n≤10^5; 0≤k≤10^9) — the number of elements in the array and the number of operations you are allowed to perform, correspondingly.
The third line contains a sequence of n integers a1,a2,...,an (|ai|≤10^9) — the initial array. The numbers in the lines are separated by single spaces.

In a single line print two numbers — the maximum number of occurrences of some number in the array after at most k allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces.

In the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6,4,4,0,4, where number 4 occurs 3 times.
In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array 5,5,5, if we increase each by one, we get 6,6,6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.
In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3,2,2,2,2, where number 2 occurs 4 times.

uses math;
type mass=array[1..100000] of integer;
var r,l,k:int64;s,s1:string;u:boolean;d,max1,min1,n,res,de:int64;i:integer;z,x,code,j,a,b,c,y:int64;
    m:mass;
procedure qsort(var A:mass);
    procedure sort(l,r: integer);
      var i,j,x,y: integer;
    begin
      i := l;
      j := r;
      x := A[l+random(r-l)];
      repeat
        while A[i] < x do inc(i);
        while x < A[j] do dec(j);
        if not (i>j) then
          begin
            y    := A[i];
            A[i] := A[j];
            A[j] := y;
            inc(i);
            dec(j);
          end;
      until i>j;
      if l < j then sort(l,j);
      if i < r then sort(i,r);
    end;
begin
  sort(1,n);
end;
begin
//  reset(input,'input.txt');
//  assign(output,'output.txt');
  readln(n,k);
  for i:=1 to n do
     read(m[i]);
  qsort(m);
  r:=0;
  max1:=0;
  j:=0;
  b:=0;
  a:=0;
  for i:=1 to n do
     Begin
        r:=max(r,i);
        a:=max(a,1);
        while r<n do
           Begin
              if b+(m[r+1]-m[r])*a>k
              then break;
              inc(r);
              inc(b,(m[r]-m[r-1])*a);
              inc(a);
           end;
        if a>max1
        then Begin
                max1:=a;
                j:=m[r];
             end;
        dec(b,m[r]-m[i]);
        dec(a);
     end;
  writeln(max1,' ',j);
end.


A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.A simple cycle in a undirected graph is a sequence of distinct vertices v1,v2,...,vt (t>2), such that for any i (1≤i<t) exists an edge between vertices vi and vi+1, and also exists an edge between vertices v1 and vt.A simple path in a undirected graph is a sequence of not necessarily distinct vertices v1,v2,...,vt (t>0), such that for any i (1≤i<t) exists an edge between vertices vi and vi+1 and furthermore each edge occurs no more than once. We'll say that a simple path v1,v2,...,vt starts at vertex v1 and ends at vertex vt.You've got a graph consisting of n vertices and m edges, that is a vertex cactus. Also, you've got a list of k pairs of interesting vertices xi,yi, for which you want to know the following information — the number of distinct simple paths that start at vertex xi and end at vertex yi. We will consider two simple paths distinct if the sets of edges of the paths are distinct.For each pair of interesting vertices count the number of distinct simple paths between them. As this number can be rather large, you should calculate it modulo 1000000007 (10^9+7).

The first line contains two space-separated integers n,m (2≤n≤10^5; 1≤m≤10^5) — the number of vertices and edges in the graph, correspondingly. Next m lines contain the description of the edges: the i-th line contains two space-separated integers ai,bi (1≤ai,bi≤n) — the indexes of the vertices connected by the i-th edge.
The next line contains a single integer k (1≤k≤10^5) — the number of pairs of interesting vertices. Next k lines contain the list of pairs of interesting vertices: the i-th line contains two space-separated numbers xi, yi (1≤xi,yi≤n; xi≠yi) — the indexes of interesting vertices in the i-th pair.
It is guaranteed that the given graph is a vertex cactus. It is guaranteed that the graph contains no loops or multiple edges. Consider the graph vertices are numbered from 1 to n.

Print k lines: in the i-th line print a single integer — the number of distinct simple ways, starting at xi and ending at yi, modulo 1000000007 (10^9+7).

var sol,a,b,n,m,j,i,t,t2,q:longint;
    c:array[1..100007]of array of longint;
    e,tin,tout,p,x,y,v,s,r,new,o,suma:array[0..100007]of longint;
    w:array[1..100007,0..20]of longint;

procedure dfs1(x,pr:longint);
var u,tu:longint;
begin
if v[x]=1 then exit;
 v[x]:=1;
 t:=t+1;
 s[t]:=x;
 r[x]:=t;
 for u:=0 to p[x] do if ((v[c[x,u]]=0)or(c[x,u]=pr))
 then dfs1(c[x,u],x) else
  begin
  tu:=r[c[x,u]];
  for j:=tu to t do new[s[j]]:=c[x,u];
  end;
 t:=t-1;
end;

procedure dfs2(x,pr:longint);
var u:longint;
begin
  t:=t+1;
  tin[x]:=t;
  suma[x]:=suma[pr]+o[x];
  w[x][0]:=pr;
  v[x]:=1;
  for u:=0 to p[x] do if v[c[x,u]]=0 then dfs2(c[x,u],x);
  t2:=t2+1;
  tout[x]:=t2;
end;

function f(x,y:longint):boolean;
begin
 f:=(tin[x]<=tin[y])and(tout[x]>=tout[y]);
end;

function lca(x,y:longint):longint;
begin
 if f(x,y) then lca:=x else
 if f(y,x) then lca:=y else
 begin
 for i:=20 downto 0 do
   if not f(w[x][i],y) then x:=w[x][i];
 lca:=w[x][0];
 end;
end;

begin
fillchar(o,sizeof(o),0);
fillchar(p,sizeof(p),-1);
readln(n,m);
for i:=1 to m do begin
 readln(x[i],y[i]);
 p[x[i]]:=p[x[i]]+1;
 p[y[i]]:=p[y[i]]+1;
 end;
 for i:=1 to n do setlength(c[i],p[i]+1);
 for j:=1 to n do p[j]:=-1;
 for i:=1 to m do
 begin
 p[x[i]]:=p[x[i]]+1;
 p[y[i]]:=p[y[i]]+1;
 c[y[i],p[y[i]]]:=x[i];
 c[x[i],p[x[i]]]:=y[i];
 end;
 fillchar(v,sizeof(v),0);
 t:=0;
 for i:=1 to n do new[i]:=i;
 dfs1(1,-1);

for i:=1 to m do begin
                  x[i]:=new[x[i]];
                  y[i]:=new[y[i]];
                 end;
fillchar(p,sizeof(p),-1);
for i:=1 to m do
if x[i]<>y[i] then begin
p[x[i]]:=p[x[i]]+1;
p[y[i]]:=p[y[i]]+1;
end else o[x[i]]:=1;

 for i:=1 to n do setlength(c[i],p[i]+1);
 for j:=1 to n do p[j]:=-1;
 for i:=1 to m do if x[i]<>y[i] then
 begin
 p[x[i]]:=p[x[i]]+1;
 p[y[i]]:=p[y[i]]+1;
 c[y[i],p[y[i]]]:=x[i];
 c[x[i],p[x[i]]]:=y[i];
 end;

 {
for i:=1 to n do
begin
if o[i]=1 then write(i,'* ') else write(i,'  ');
for j:=0 to p[i] do write(c[i,j],' ');
writeln;
end;}
  t:=0;
  t2:=0;
   fillchar(v,sizeof(v),0);
   fillchar(s,sizeof(s),0);
  dfs2(1,1);
  for j:=1 to 20 do
   for i:=1 to n do begin
   w[i][j]:=w[w[i][j-1]][j-1];
   end;
readln(q);
e[0]:=1;
for i:=1 to 100000 do e[i]:=(e[i-1] shl 1) mod 1000000007;
for i:=1 to q do  begin
readln(a,b);
a:=new[a];
b:=new[b];
m:=lca(a,b);
sol:=suma[a]+suma[b]-2*suma[m]+o[m];

writeln(e[sol]);
end;

end.


Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions:  a1≤a2≤...≤an;  a1≥a2≥...≥an. Help Petya find the two required positions to swap or else say that they do not exist.

The first line contains a single integer n (1≤n≤10^5). The second line contains n non-negative space-separated integers a1,a2,...,an — the elements of the array that Petya's mother presented him. All integers in the input do not exceed 10^9.

If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.

In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.

var a:array[1..100000]of LongInt;
n,i,j:LongInt;
eq:boolean;
function check(l,r:longint):boolean;
var i,x:longint;
aa,b:Boolean;
begin
   x:=a[l];
   a[l]:=a[r];
   a[r]:=x;
   aa:=true;
   for i:=2 to n do
     aa:=(aa)and( a[i]<=a[i-1]);
   if aa
   then begin
          check:=False;
          x:=a[l];
   a[l]:=a[r];
   a[r]:=x;
          Exit;
        end;
   b:=true;
   for i:=2 to n do
     b:=(b)and( a[i]>=a[i-1]);
   if b
   then begin
          check:=False;
          x:=a[l];
   a[l]:=a[r];
   a[r]:=x;
          Exit;
        end;
   check:=True;
end;
begin
     //reset(input,'input.txt');
     //rewrite(output,'output.txt');
     Readln(n);
     eq:=true;
     Read(a[1]);
     for i:=2 to n do
     begin
       Read(a[i]);
       eq:=(eq)and(a[i]=a[i-1])
     end;
     if eq
     then begin
       Writeln(-1);
       Halt;
     end;
     for i:=1 to n-1 do
     for j:=i+1 to n do
     begin
        if (a[i]<>a[j])and(check(i,j))
        then begin
          Writeln(i,' ',j);
          Halt(0);
        end;
     end;
     Writeln(-1);
end.


There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names.Political parties find their number in the ballot highly important. Overall there are m possible numbers: 1,2,...,m. Each of these 7 parties is going to be assigned in some way to exactly one number, at that, two distinct parties cannot receive the same number.The Little Elephant Political Party members believe in the lucky digits 4 and 7. They want to evaluate their chances in the elections. For that, they need to find out, how many correct assignments are there, such that the number of lucky digits in the Little Elephant Political Party ballot number is strictly larger than the total number of lucky digits in the ballot numbers of 6 other parties. Help the Little Elephant Political Party, calculate this number. As the answer can be rather large, print the remainder from dividing it by 1000000007 (10^9+7).

A single line contains a single positive integer m (7≤m≤10^9) — the number of possible numbers in the ballot.

In a single line print a single integer — the answer to the problem modulo 1000000007 (10^9+7).

{$R-,S-,Q-,I-,O+}
{$M 32000000}

{$APPTYPE CONSOLE}

uses Math;
const
inf = round(1e9);
maxn = round(1e5)+200;
md = round(1e9)+7;
var
m,i,j,k,l,lenm : longint;
dp : array [1..11,0..11,0..2] of int64;
cnt : array [0..11] of int64;
a : array [1..11] of longint;
ans : int64;

function lucky (x : longint) : boolean;
begin
 lucky:=(x=4) or (x=7);
end;

function go(sum,len : longint) : int64;
var
i : longint;
res : int64;
begin
 if len=6 then
 begin
  go:=1;
  exit;
 end;
 res:=0;
 for i:=0 to sum-1 do
 begin
  dec(cnt[i]);
  res:=res+((cnt[i]+1)*go(sum-i,len+1))mod md;
  inc(cnt[i]);
 end;
 go:=res;
end;

begin
 //reset (input,'input.txt');
 //rewrite (output,'output.txt');
 readln(m);
 lenm:=0;
 while m>0 do
 begin
  inc(lenm);
  a[lenm]:=m mod 10;
  m:=m div 10;
 end;
 for i:=1 to lenm shr 1 do
 begin
  l:=a[i]; a[i]:=a[lenm-i+1]; a[lenm-i+1]:=l;
 end;

 fillchar(dp,sizeof(dp),0);
 for i:=1 to 9 do
 begin
  if (i<a[1]) and not lucky(i) then inc(dp[1,0,0]);
  if (i=a[1]) and not lucky(i) then inc(dp[1,0,1]);
  if (i>a[1]) and not lucky(i) then inc(dp[1,0,2]);
  if (i<a[1]) and lucky(i) then inc(dp[1,1,0]);
  if (i=a[1]) and lucky(i) then inc(dp[1,1,1]);
  if (i>a[1]) and lucky(i) then inc(dp[1,1,2]);
 end;
 for i:=1 to lenm-1 do
  for j:=0 to i do
   for k:=0 to 2 do
   if dp[i,j,k]>0 then
    for l:=0 to 9 do
    begin
     if k=0 then
     begin
      if lucky(l) then dp[i+1,j+1,k]:=dp[i+1,j+1,k] + dp[i,j,k];
      if not lucky(l) then dp[i+1,j,k]:=dp[i+1,j,k] + dp[i,j,k];
     end;

     if k=1 then
     begin
      if l<a[i+1] then
      begin
       if lucky(l) then dp[i+1,j+1,0]:=dp[i+1,j+1,0] + dp[i,j,k];
       if not lucky(l) then dp[i+1,j,0]:=dp[i+1,j,0] + dp[i,j,k];
      end;
      if l=a[i+1] then
      begin
       if lucky(l) then dp[i+1,j+1,1]:=dp[i+1,j+1,1] + dp[i,j,k];
       if not lucky(l) then dp[i+1,j,1]:=dp[i+1,j,1] + dp[i,j,k];
      end;
      if l>a[i+1] then
      begin
       if lucky(l) then dp[i+1,j+1,2]:=dp[i+1,j+1,2] + dp[i,j,k];
       if not lucky(l) then dp[i+1,j,2]:=dp[i+1,j,2] + dp[i,j,k];
      end;
     end;

     if k=2 then
     begin
      if lucky(l) then dp[i+1,j+1,k]:=dp[i+1,j+1,k] + dp[i,j,k];
      if not lucky(l) then dp[i+1,j,k]:=dp[i+1,j,k] + dp[i,j,k];
     end;
    end;

 fillchar(cnt,sizeof(cnt),0);
 for i:=1 to lenm-1 do
  for j:=0 to i do
   for k:=0 to 2 do cnt[j]:=(cnt[j]+dp[i,j,k])mod md;
 for j:=0 to lenm do
  for k:=0 to 1 do cnt[j]:=(cnt[j]+dp[lenm,j,k]) mod md;

 ans:=0;
 for i:=1 to lenm do ans:=(ans+cnt[i]*go(i,0))mod md;
 writeln(ans);
end.


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

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

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

{$APPTYPE CONSOLE}
var
  bg,e,i,j,n:integer;
  q,a,f:array[0..101] of integer;
  d:array[1..101,1..101] of integer;
  tr:array[1..10001] of integer;

  procedure swap(var a,b:integer);
  var
   x:integer;
  begin
   x:=a;
   a:=b;
   b:=x;
  end;

begin
 {reset(input,'Input.txt');
 rewrite(output,'Output.txt');}
 read(n);
 For i:=1 to n do read(a[i]);

 For i:=1 to n do read(f[i]);

 Fillchar(d,sizeof(d),0);

 For i:=1 to n do
 begin
  If i-f[i]>0 then d[i,i-f[i]]:=1;
  If i+f[i]<=n then d[i,i+f[i]]:=1;
  For j:=1 to n do
   If abs(i-j)=f[j] then d[i,j]:=1;
 end;

 For i:=1 to n do
 begin
  bg:=1;
  e:=1;
  tr[e]:=i;
  For j:=1 to n do q[j]:=1000000000;
  q[i]:=0;

  while bg<=e do
  begin
   For j:=1 to n do If (d[tr[bg],j]=1) and (q[j]>q[tr[bg]]+1) then
   begin
    inc(e);
    tr[e]:=j;
    q[j]:=q[tr[bg]]+1;
   end;
   inc(bg);
  end;

  For j:=1 to n do If a[j]=i then
  begin
   If q[j]=1000000000 then
   begin
    writeln('NO');
    exit;
   end;
   break;
  end;
 end;
 writeln('YES');
end.


Yaroslav has an array p=p1,p2,...,pn (1≤pi≤n), consisting of n distinct integers. Also, he has m queries:  Query number i is represented as a pair of integers li, ri (1≤li≤ri≤n).  The answer to the query li,ri is the number of pairs of integers q, w (li≤q,w≤ri) such that pq is the divisor of pw. Help Yaroslav, answer all his queries.

The first line contains the integers n and m (1≤n,m≤2·10^5). The second line contains n distinct integers p1,p2,...,pn (1≤pi≤n). The following m lines contain Yaroslav's queries. The i-th line contains integers li,ri (1≤li≤ri≤n).

Print m integers — the answers to Yaroslav's queries in the order they appear in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

{$R-,S-,Q-,I-,O+}
{$M 32000000}

{$APPTYPE CONSOLE}

uses Math;
const
inf = round(1e9);
maxn = 2 * round(1e5) + 200;
md = round(1e9) + 7;
type
query = record
         ll,rr,ans,id : longint;
        end;
pair = record
        l,r : longint;
       end;
var
n,m,i,j,x,cnt,now : longint;
b,ans : array [1..maxn] of longint;
q : array [1..maxn] of query;
t : array [0..maxn] of longint;
p : array of pair;

procedure Add(x : longint);
begin
 while x <= n do
 begin
  inc(t[x]);
  x:=x or (x - 1) + 1;
 end;
end;

function count(x : longint) : longint;
var
res : longint;
begin
 res:=0;
 while x > 0 do
 begin
  res:=res + t[x];
  x:=x and (x - 1);
 end;
 count:=res;
end;

procedure SortPoint(l,r : longint);
var
i,j,id,x,y : longint;
tmp : pair;
begin
 i:=l;
 j:=r;
 id:=l + random(r - l + 1);
 x:=p[id].r; y:=p[id].l;
 repeat
  while (x > p[i].r) or (x = p[i].r) and (y > p[i].l) do inc(i);
  while (x < p[j].r) or (x = p[j].r) and (y < p[j].l) do dec(j);
  if i <= j then
  begin
   tmp:=p[i]; p[i]:=p[j]; p[j]:=tmp;
   inc(i);dec(j);
  end;
 until i > j;
 if i < r then SortPoint(i,r);
 if l < j then SortPoint(l,j);
end;

procedure SortQuery(l,r : longint);
var
i,j,id,x,y : longint;
tmp : query;
begin
 i:=l;
 j:=r;
 id:=l + random(r - l + 1);
 x:=q[id].rr; y:=q[id].ll;
 repeat
  while (x > q[i].rr) or (x = q[i].rr) and (y > q[i].ll) do inc(i);
  while (x < q[j].rr) or (x = q[j].rr) and (y < q[j].ll) do dec(j);
  if i <= j then
  begin
   tmp:=q[i]; q[i]:=q[j]; q[j]:=tmp;
   inc(i);dec(j);
  end;
 until i > j;
 if i < r then SortQuery(i,r);
 if l < j then SortQuery(l,j);
end;

begin
 //reset (input,'input.txt');
 //rewrite (output,'output.txt');
 randomize;
 readln(n,m);
 fillchar(b,sizeof(b),0);
 for i:=1 to n do
 begin
  read(x);
  b[x]:=i;
 end;
 readln;
 for i:=1 to m do
 begin
  readln(q[i].ll,q[i].rr);
  q[i].id:=i;
  q[i].ans:=0;
 end;

 for i:=1 to n do
 begin
  j:=i;
  while j <= n do
  begin
   if (b[i] > 0) and (b[j] > 0) then
   begin
    setlength(p,length(p) + 1);
    p[length(p) - 1].l:=min(b[i],b[j]);
    p[length(p) - 1].r:=max(b[i],b[j]);
   end;
   inc(j,i);
  end;
 end;
 cnt:=length(p);

 SortPoint(0,cnt - 1);
 SortQuery(1,m);
 fillchar(t,sizeof(t),0);

 now:=0;
 for i:=1 to m do
 begin
  while (now <= cnt - 1) and (p[now].r <= q[i].rr) do
  begin
   Add(p[now].l);
   inc(now);
  end;
  q[i].ans:=now - count(q[i].ll - 1);
 end;

 for i:=1 to m do ans[q[i].id]:=q[i].ans;
 for i:=1 to m do writeln(ans[i]);
end.


Smart Beaver is careful about his appearance and pays special attention to shoes so he has a huge number of pairs of shoes from the most famous brands of the forest. He's trying to handle his shoes carefully so that each pair stood side by side. But by the end of the week because of his very active lifestyle in his dressing room becomes a mess.Smart Beaver from ABBYY is not only the brightest beaver in the area, but he also is the most domestically oriented. For example, on Mondays the Smart Beaver cleans everything in his home.It's Monday morning. Smart Beaver does not want to spend the whole day cleaning, besides, there is much in to do and it’s the gym day, so he wants to clean up as soon as possible. Now the floors are washed, the dust is wiped off — it’s time to clean up in the dressing room. But as soon as the Smart Beaver entered the dressing room, all plans for the day were suddenly destroyed: chaos reigned there and it seemed impossible to handle, even in a week. Give our hero some hope: tell him what is the minimum number of shoes need to change the position to make the dressing room neat.The dressing room is rectangular and is divided into n×m equal squares, each square contains exactly one shoe. Each pair of shoes has a unique number that is integer from 1 to , more formally, a square with coordinates (i,j) contains an integer number of the pair which is lying on it. The Smart Beaver believes that the dressing room is neat only when each pair of sneakers lies together. We assume that the pair of sneakers in squares (i1,j1) and (i2,j2) lies together if |i1-i2|+|j1-j2|=1.

The first line contains two space-separated integers n and m. They correspond to the dressing room size. Next n lines contain m space-separated integers each. Those numbers describe the dressing room. Each number corresponds to a snicker.
It is guaranteed that:
  n·m is even.  All numbers, corresponding to the numbers of pairs of shoes in the dressing room, will lie between 1 and .  Each number from 1 to  will occur exactly twice. The input limits for scoring 30 points are (subproblem C1):
  2≤n,m≤8. The input limits for scoring 100 points are (subproblems C1+C2):
  2≤n,m≤80.

Print exactly one integer — the minimum number of the sneakers that need to change their location.

{$R+}{$Q-}{$O-}
Uses math;
Var m1,m:array [0..3200,0..3200] of LongInt;
a:array [1..2,1..100000] of longint;
a5,a4:array [0..3200,0..3200] of longint;
pred,m2,zz:array [1..100000] of longint;
i2,j2,used:array [1..3200] of Boolean;
mt:array [1..3200] of longint;
kol,i1,k,rez,n,i,j:longint;
s:longint;
f:boolean;
procedure add(i,j:longint);
begin
  m2[kol]:=j;
  pred[kol]:=zz[i];
  zz[i]:=kol;
end;
function dfs(v:longint):boolean;
Var i:longint;
begin
  if used[v]
  then begin dfs:=false; exit; end;
  used[v]:=true;
  i:=zz[v];
  while i<>0 do
  begin
    if (mt[m2[i]]=-1)or(dfs(mt[m2[i]]))
    then begin
          mt[m2[i]]:=v;
          dfs:=true;
          exit;
         end;
    i:=pred[i];
  end;
  dfs:=false;
end;
procedure dfs2(v:longint);
Var i:longint;
begin
  if i2[v]
  then exit;
  i2[v]:=true;
  i:=zz[v];
  while i<>0 do
  begin
    if (mt[m2[i]]<>-1)and(mt[m2[i]]<>v)
    then begin j2[m2[i]]:=True; dfs2(mt[a[2,i]]); end;
    i:=pred[i];
  end;
end;
begin
  //Assign(input,'input.txt'); reset(input);
  //Assign(output,'output.txt'); rewrite(output);
  Readln(n,k);
  for i:=1 to n do
  for j:=1 to k do
  read(a4[i,j]);
  for i:=1 to (n*k) div 2 do
  for j:=1 to (n*k) div 2 do
  m[i,j]:=10000;
  s:=0;
  i1:=0;
  for i:=1 to n do
  for j:=1 to k do
  if (i+j) mod 2=0
  then begin
        inc(s);
        a5[i,j]:=s;
       end
  else begin
        inc(i1);
        a5[i,j]:=i1;
       end;
  for i:=1 to n do
  for j:=1 to k do
  if (i+j) mod 2=0
  then begin
        if a4[i,j]=a4[i,j+1]
        then m[a5[i,j],a5[i,j+1]]:=0
        else m[a5[i,j],a5[i,j+1]]:=1;
        if a4[i,j]=a4[i,j-1]
        then m[a5[i,j],a5[i,j-1]]:=0
        else m[a5[i,j],a5[i,j-1]]:=1;
        if a4[i,j]=a4[i+1,j]
        then m[a5[i,j],a5[i+1,j]]:=0
        else m[a5[i,j],a5[i+1,j]]:=1;
        if a4[i,j]=a4[i-1,j]
        then m[a5[i,j],a5[i-1,j]]:=0
        else m[a5[i,j],a5[i-1,j]]:=1;
      end;
  n:=(n*k) div 2;
  k:=n;
  m1:=m;

  while 1=1 do
  begin
  for i:=1 to k do
  begin
    i1:=MaxLongint;
    for j:=1 to k do
    i1:=min(i1,m[i,j]);
    for j:=1 to k do
    m[i,j]:=m[i,j]-i1;
  end;
  for j:=1 to k do
  begin
    i1:=MaxLongint;
    for i:=1 to k do
    i1:=min(i1,m[i,j]);
    for i:=1 to k do
    m[i,j]:=m[i,j]-i1;
  end;
    FillChar(zz,SizeOf(zz),0);
    kol:=0;
    for i:=1 to k do
    for j:=1 to k do
    if m[i,j]=0
    then begin
          inc(kol);
          add(i,j);
          a[1,kol]:=i;
          a[2,kol]:=j;
         end;
    for i:=1 to k do
    mt[i]:=-1;
    for i:=1 to k do
    begin
      FillChar(used,SizeOf(used),false);
      dfs(i);
    end;
    f:=true;
    fillchar(used,sizeof(used),false);
    for i:=1 to k do
    if mt[i]=-1
    then f:=False
    else used[mt[i]]:=true;
    FillChar(i2,sizeof(i2),false);
    FillChar(j2,sizeof(j2),false);
    if f
    then Break;
    for i:=1 to k do
    if not used[i]
    then dfs2(i);
    i1:=MaxLongint;
    for i:=1 to k do
    if i2[i]
    then
    for j:=1 to k do
    if (not j2[j])and(m[i,j]<>0)
    then i1:=min(i1,m[i,j]);
    for i:=1 to k do
    if i2[i]
    then
    for j:=1 to k do
    m[i,j]:=m[i,j]-i1;
    for j:=1 to k do
    if j2[j]
    then  for i:=1 to k do
          m[i,j]:=m[i,j]+i1;
  end;
  m:=m1;
  rez:=0;
  for i:=1 to k do
  rez:=rez+m[mt[i],i];
  Writeln(rez);
end.


It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n×m centimeters (each cell is 1×1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. The only restriction is that she cannot jump out of the board.The flea can count the amount of cells that she can reach from the starting position (x,y). Let's denote this amount by dx,y. Your task is to find the number of such starting positions (x,y), which have the maximum possible value of dx,y.

The first line contains three integers n, m, s (1≤n,m,s≤10^6) — length of the board, width of the board and length of the flea's jump.

Output the only integer — the number of the required starting positions of the flea.

Var a,b,s,i,sum:longint;
i1,j1:int64;
begin
//  Assign(input,'input.txt'); reset(input);
//  Assign(output,'output.txt'); rewrite(output);
  read(a,b,s);
  i1:=0;
  sum:=1+(a-1) div s;
  for i:=1 to a do
  if 1+(a-i) div s+(i-1)div s=sum
  then inc(i1);
  a:=b;
  j1:=0;
  sum:=1+(a-1) div s;
  for i:=1 to a do
  if 1+(a-i) div s+(i-1)div s=sum
  then inc(j1);
  writeln(i1*j1);
end.


A little boy Petya dreams of growing up and becoming the Head Berland Plumber. He is thinking of the problems he will have to solve in the future. Unfortunately, Petya is too inexperienced, so you are about to solve one of such problems for Petya, the one he's the most interested in.The Berland capital has n water tanks numbered from 1 to n. These tanks are connected by unidirectional pipes in some manner. Any pair of water tanks is connected by at most one pipe in each direction. Each pipe has a strictly positive integer width. Width determines the number of liters of water per a unit of time this pipe can transport. The water goes to the city from the main water tank (its number is 1). The water must go through some pipe path and get to the sewer tank with cleaning system (its number is n). Petya wants to increase the width of some subset of pipes by at most k units in total so that the width of each pipe remains integer. Help him determine the maximum amount of water that can be transmitted per a unit of time from the main tank to the sewer tank after such operation is completed.

The first line contains two space-separated integers n and k (2≤n≤50, 0≤k≤1000). Then follow n lines, each line contains n integers separated by single spaces. The i+1-th row and j-th column contain number cij — the width of the pipe that goes from tank i to tank j (0≤cij≤10^6,cii=0). If cij=0, then there is no pipe from tank i to tank j.

Print a single integer — the maximum amount of water that can be transmitted from the main tank to the sewer tank per a unit of time.

In the first test Petya can increase width of the pipe that goes from the 1st to the 2nd water tank by 7 units.
In the second test Petya can increase width of the pipe that goes from the 1st to the 2nd water tank by 4 units, from the 2nd to the 3rd water tank by 3 units, from the 3rd to the 4th water tank by 2 units and from the 4th to 5th water tank by 1 unit.

{$R-,S-,Q-,I-,O+}
{$M 32000000}

{$APPTYPE CONSOLE}

uses Math;
const
    inf = round(1e9);
    maxn = round(1e1) + 200;
    md = round(1e9) + 7;
type
    node = record
             val, id : longint;
           end;
    edge = record
             u, f, t, cost : longint;
           end;
var
    n, k, i, j, heap_sz, ll, rr, mid : longint;
    cost : int64;
    e : array of edge;
    g : array [1..maxn] of array of longint;
    d, phi, vert, p, p_rib : array [1..maxn] of longint;
    h : array [1..maxn] of node;
    c : array [1..maxn, 1..maxn] of longint;

  procedure AddEdge(a, b, cap, cost : longint);
  var
     cur : edge;
  begin
    cur.u := cap; cur.f := 0; cur.t := b; cur.cost := cost;
    setlength(e, length(e) + 1);
    e[length(e) - 1] := cur;
    setlength(g[a], length(g[a]) + 1);
    g[a][length(g[a]) - 1] := length(e) - 1;

    cur.u := 0; cur.f := 0; cur.t := a; cur.cost := -cost;
    setlength(e, length(e) + 1);
    e[length(e) - 1] := cur;
    setlength(g[b], length(g[b]) + 1);
    g[b][length(g[b]) - 1] := length(e) - 1;
  end;

  procedure heapify(v : longint);
  var
    l, r, lowest : longint;
    t : node;
  begin
    l := v shl 1;
    r := v shl 1 + 1;
    if (l <= heap_sz) and (h[l].val < h[v].val) then lowest := l
                                                else lowest := v;
    if (r <= heap_sz) and (h[r].val < h[lowest].val) then lowest := r;
    if lowest <> v then
    begin
      vert[h[lowest].id] := v;
      vert[h[v].id] := lowest;
      t := h[v]; h[v] := h[lowest]; h[lowest] := t;
      heapify(lowest);
    end;
  end;

  procedure build_heap();
  var
     i : longint;
  begin
    heap_sz := n;
    for i := n shr 1 downto 1 do heapify(i);
  end;

  function extract_min() : longint;
  begin
    extract_min := h[1].id;
    h[1] := h[heap_sz];
    vert[h[heap_sz].id] := 1;
    dec(heap_sz);
    heapify(1);
  end;

  procedure decrease_key(v, x : longint);
  var
     t : node;
  begin
    h[v].val := x;
    while (v > 1) and (h[v shr 1].val > h[v].val) do
    begin
      vert[h[v].id] := v shr 1;
      vert[h[v shr 1].id] := v;
      t := h[v]; h[v] := h[v shr 1]; h[v shr 1] := t;
      v := v shr 1;
    end;
  end;

  procedure dijkstra(ss : longint);
  var
     v, i, id, w, t : longint;
  begin
    for i := 1 to n do
    begin
      d[i] := inf;
      vert[i] := i;
      h[i].val := inf;
      h[i].id := i;
    end;
    h[ss].val := 0;
    d[ss] := 0;
    build_heap();
    while heap_sz > 0 do
    begin
      v := extract_min();
      if d[v] = inf then break;
      for i := 0 to length(g[v]) - 1 do
      begin
        id := g[v][i];
        t := e[id].t;
        w := d[v] + e[id].cost + phi[v] - phi[t];
        if (w < d[t]) and (e[id].u - e[id].f > 0) then
        begin
          d[t] := w;
          p[t] := v;
          p_rib[t] := i;
          Decrease_Key(vert[t], d[t]);
        end;
      end;
    end;
  end;

  procedure FB(ss : longint);
  var
    i, j, r, id : longint;
    any : boolean;
  begin
    for i := 1 to n do d[i] := inf;
    d[ss] := 0;
    for i := 1 to n - 1 do
    begin
      any := false;
      for j := 1 to n do
        for r := 0 to length(g[j]) - 1 do
        begin
          id := g[j][r];
          if (e[id].u - e[id].f > 0) and (d[e[id].t] > d[j] + e[id].cost) then
          begin
            d[e[id].t] := d[j] + e[id].cost;
            any := true;
          end;
        end;
      if not any then break;
    end;

    for i := 1 to n do phi[i] := d[i];
  end;

  function mcmf(ss, tt, want : longint) : int64;
  var
     i, v, pv, pr, id : longint;
     maxflow, addflow, cost : int64;
  begin
    maxflow := 0;
    cost := 0;
    FB(ss);
    while maxflow < want do
    begin
      dijkstra(ss);
      if d[tt] = inf then break;
      for i := 1 to n do
      if d[i] < inf then phi[i] := phi[i] + d[i];

      addflow := want - maxflow;
      v := tt;
      while v <> ss do
      begin
        pv := p[v];
        pr := p_rib[v];
        id := g[pv][pr];
        addflow := min(addflow, e[id].u - e[id].f);
        v := pv;
      end;

      v := tt;
      while v <> ss do
      begin
        pv := p[v];
        pr := p_rib[v];
        id := g[pv][pr];
        e[id].f := e[id].f + addflow;
        e[id xor 1].f := e[id xor 1].f - addflow;
        cost := cost + int64(addflow) * e[id].cost;
        v := pv;
      end;

      maxflow := maxflow + addflow;
    end;

   if maxflow < want then mcmf := inf
                     else mcmf := cost;
  end;

begin
  //assign(input,'input.txt'); reset(input);
  //assign(output,'output.txt'); rewrite(output);
  randomize;
  readln(n, k);
  for i := 1 to n do
  begin
    for j := 1 to n do read(c[i][j]);
    readln;
  end;

  ll := 0;
  rr := 51 * round(1e6);
  while ll < rr do
  begin
    mid := (ll + rr) shr 1;
    for i := 1 to n do setlength(g[i], 0);
    setlength(e, 0);
    for i := 1 to n do
      for j := 1 to n do
      if c[i][j] > 0 then
      begin
        AddEdge(i, j, c[i][j], 0);
        AddEdge(i, j, inf, 1);
      end;
    cost := mcmf(1, n, mid);
    if cost <= k then ll := mid + 1
                 else rr := mid;
  end;
  setlength(e, 0);
  for i := 1 to n do
    for j := 1 to n do
    if c[i][j] > 0 then
    begin
      AddEdge(i, j, c[i][j], 0);
      AddEdge(i, j, inf, 1);
    end;
  cost := mcmf(1, n, ll);
  if cost > k then dec(ll);

  writeln(ll);
end.


Sereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. An interval of numbers is a pair of integers [l,r] (1≤l≤r≤m). Interval [l1,r1] belongs to interval [l2,r2] if the following condition is met: l2≤l1≤r1≤r2.Sereja wants to write out a sequence of n intervals [l1,r1], [l2,r2], ..., [ln,rn] on a piece of paper. At that, no interval in the sequence can belong to some other interval of the sequence. Also, Sereja loves number x very much and he wants some (at least one) interval in the sequence to have li=x. Sereja wonders, how many distinct ways to write such intervals are there?Help Sereja and find the required number of ways modulo 1000000007 (10^9+7).Two ways are considered distinct if there is such j (1≤j≤n), that the j-th intervals in two corresponding sequences are not equal.

The first line contains integers n, m, x (1≤n·m≤100000,1≤x≤m) — the number of segments in the sequence, the constraints on the numbers in segments and Sereja's favourite number.

In a single line print the answer modulo 1000000007 (10^9+7).

const w:array[1..3]of int64=(1,1,0);
      z:array[1..3]of int64=(-1,0,1);
var n,m,x,i,j,k,l,t,o:longint;
    f:array[0..999,0..999]of int64;
begin
  f[0,0]:=1;
  read(n,m,x);
  if m<n then
    begin
      write(0);
      halt
    end;
  for i:=1to m do
    begin
      if i<n then t:=i
      else t:=n;
      for j:=t downto 0do
        for k:=t-j downto 0do
          if f[j,k]>0then
            begin
              inc(f[j+1,k],f[j,k]);
              inc(f[j,k+1],f[j,k]);
              if x=i then f[j,k]:=0
              else if k>0then inc(f[j+1,k-1],f[j,k]);
              for o:=1to 3do
                if f[j+w[o],k+z[o]]>=1000000007then dec(f[j+w[o],k+z[o]],1000000007)
            end;
    end;
  for i:=1to n do
    f[n,0]:=f[n,0]*i mod 1000000007;
  write(f[n,0])
end.


On a cold winter evening our hero Vasya stood in a railway queue to buy a ticket for Codeforces championship final. As it usually happens, the cashier said he was going to be away for 5 minutes and left for an hour. Then Vasya, not to get bored, started to analyze such a mechanism as a queue. The findings astonished Vasya.Every man is characterized by two numbers: ai, which is the importance of his current task (the greater the number is, the more important the task is) and number ci, which is a picture of his conscience. Numbers ai form the permutation of numbers from 1 to n.Let the queue consist of n-1 people at the moment. Let's look at the way the person who came number n behaves. First, he stands at the end of the queue and the does the following: if importance of the task ai of the man in front of him is less than an, they swap their places (it looks like this: the man number n asks the one before him: "Erm... Excuse me please but it's very important for me... could you please let me move up the queue?"), then he again poses the question to the man in front of him and so on. But in case when ai is greater than an, moving up the queue stops. However, the man number n can perform the operation no more than cn times.In our task let us suppose that by the moment when the man number n joins the queue, the process of swaps between n-1 will have stopped. If the swap is possible it necessarily takes place.Your task is to help Vasya model the described process and find the order in which the people will stand in queue when all the swaps stops.

The first input line contains an integer n which is the number of people who has joined the queue (1≤n≤10^5). In the next n lines descriptions of the people are given in order of their coming — space-separated integers ai and ci (1≤ai≤n, 0≤ci≤n). Every description is located on s single line. All the ai's are different.

Output the permutation of numbers from 1 to n, which signifies the queue formed according to the above described rules, starting from the beginning to the end. In this succession the i-th number stands for the number of a person who will stand in line on the place number i after the swaps ends. People are numbered starting with 1 in the order in which they were given in the input. Separate numbers by a space.

program project2;

{$APPTYPE CONSOLE}
{$ASSERTIONS ON}

{$M 16384,10485760}
uses
  SysUtils,
  Math;

type
  tr = ^tree;

  tree = record
    max, a, y, cnt, numb: integer;
    l, r: tr;
  end;
var
  t:    tr;
  n, i: integer;
  a, c: array[1..100000] of integer;

  function get_max(t: tr): integer;
  begin
    if t = nil then
      Result := 0
    else
      Result := t^.max;
  end;

  procedure update_max(t: tr);
  var
    a: integer;
  begin
    if t <> nil then
    begin
      if get_max(t^.l) < get_max(t^.r) then
        a := get_max(t^.r)
      else
        a := get_max(t^.l);
      if a < t^.a then
        a    := t^.a;
      t^.max := a;
    end;
  end;

  function get_cnt(t: tr): integer;
  begin
    if t = nil then
      Result := 0
    else
      Result := t^.cnt;
  end;

  procedure update_cnt(t: tr);
  begin
    if t <> nil then
      t^.cnt := get_cnt(t^.l) + get_cnt(t^.r) + 1;
  end;

  function get_pos(a, c: integer; t: tr): integer;
  var
    place: integer;
  begin
    place := 0;
    while t <> nil do
    begin
      if (get_cnt(t^.l) > c) or (get_max(t^.l) > a) then
      begin
        t := t^.l;
        continue;
      end;
      Dec(c, get_cnt(t^.l));
      Inc(place, (get_cnt(t^.l)));
      if (c = 0) or (t^.a > a) then
        break;
      Dec(c);
      Inc(place);
      t := t^.r;
    end;
    Result := place;
  end;

  procedure split(t:tr;var l, r: tr; x: integer);
  begin
    if t = nil then
    begin
      l := nil;
      r := nil;
      exit;
    end;
    if get_cnt(t^.l) < x then
    begin
      l := t;
      split(t^.r, l^.r, r, x - get_cnt(t^.l) - 1);
    end
    else
    begin
      r := t;
      split(t^.l, l, r^.l, x);
    end;
    update_cnt(t);
    update_max(t);
    update_cnt(l);
    update_max(l);
    update_cnt(r);
    update_max(r);
    if l <> nil then
    begin
      assert(l^.l <> l);
      assert(l^.r <> l);
    end;
    if r <> nil then
    begin
      assert(r^.l <> r);
      assert(r^.r <> r);
    end;
  end;

  procedure merge(l,r:tr;var t: tr);
  begin
    if l = nil then
    begin
      t := r;
      update_cnt(t);
      update_max(t);
      exit;
    end;
    if r = nil then
    begin
      t := l;
      update_cnt(t);
      update_max(t);
      exit;
    end;
    if l^.y < r^.y then
    begin
      merge(l^.r, r, t);
      l^.r := t;
      t    := l;
      assert(t^.l <> t);
      assert(t^.r <> t);
    end
    else
    begin
      merge(l, r^.l, t);
      r^.l := t;
      t    := r;
      assert(t^.l <> t);
      assert(t^.r <> t);
    end;
    update_cnt(t);
    update_max(t);
  end;

  procedure add(var t: tr; a, y, c, numb: integer);
  var
    p, l, r, v: tr;
    pos: integer;
  begin
    pos := get_pos(a, c, t);
    new(p);
    p^.a    := a;
    p^.y    := y;
    p^.l    := nil;
    p^.r    := nil;
    p^.cnt  := 1;
    p^.max  := a;
    p^.numb := numb;
    split(t, l, r, pos);
    merge(l, p, v);
    merge(v, r, t);
    if t <> nil then
    begin
      assert(t^.l <> t);
      assert(t^.r <> t);
    end;
  end;

  procedure dfs(v: tr;h:integer);
  var i:integer;
  begin
    if v^.r <> nil then
      dfs(v^.r,h+1);
    //for i:=1 to h do
    //  write('+');
    Write(v^.numb,' ');
   // writeln(' ', v^.a , ' ', v^.max);
    if v^.l <> nil then
      dfs(v^.l,h+1);
  end;

begin
  randseed:=12345679;
  //Assign(input, 'input.txt');
  //Assign(output, 'output.txt');
  //reset(input);
  //rewrite(output);
  readln(n);
  t := nil;
  for i := 1 to n do
  begin
    readln(a[i], c[i]);
    add(t, a[i], random(1000000000), c[i], i);
    //dfs(t,1);
  //  writeln('=',i);
  //  writeln;
  end;
  dfs(t,1);
end.


Good old Berland has n cities and m roads. Each road connects a pair of distinct cities and is bidirectional. Between any pair of cities, there is at most one road. For each road, we know its length.We also know that the President will soon ride along the Berland roads from city s to city t. Naturally, he will choose one of the shortest paths from s to t, but nobody can say for sure which path he will choose.The Minister for Transport is really afraid that the President might get upset by the state of the roads in the country. That is the reason he is planning to repair the roads in the possible President's path.Making the budget for such an event is not an easy task. For all possible distinct pairs s,t (s<t) find the number of roads that lie on at least one shortest path from s to t.

The first line of the input contains integers n,m (2≤n≤500, 0≤m≤n·(n-1)/2) — the number of cities and roads, correspondingly. Then m lines follow, containing the road descriptions, one description per line. Each description contains three integers xi,yi,li (1≤xi,yi≤n,xi≠yi,1≤li≤10^6), where xi,yi are the numbers of the cities connected by the i-th road and li is its length.

Print the sequence of  integers c12,c13,...,c1n,c23,c24,...,c2n,...,cn-1,n, where cst is the number of roads that can lie on the shortest path from s to t. Print the elements of sequence c in the described order. If the pair of cities s and t don't have a path between them, then cst=0.

uses math;
type mass=array[0..500,0..500] of int64;
     maxx=array[0..500] of int64;
var m,m1,m2,res:mass;m3:maxx;ch,ch1:char;d,x1,x2,x3,c,kol,w,k,l,r,a,b,e,n:int64;i,z,j:longint;u:boolean;s:string;
const dd=-maxlongint;
Begin
//   assign(input,'input.txt');
//   assign(output,'output.txt');
   readln(n,k);
   for i:=1 to n do
      for z:=1 to n do
         if i<>z
         then Begin
                 m[i,z]:=maxlongint;
                 m1[i,z]:=maxlongint;
              end;
   for i:=1 to k do
      Begin
         readln(a,b,c);
         m[a,b]:=min(m[a,b],c);
         m[b,a]:=min(m[b,a],c);
         m1[a,b]:=min(m1[a,b],c);
         m1[b,a]:=min(m1[b,a],c);
         m2[a,b]:=1;
         m2[b,a]:=1;
      end;
   for i:=1 to n do
      for z:=1 to n do
         for j:=1 to n do
            if (m[i,z]<maxlongint) and (m[z,i]+m[i,j]<=m[z,j])
            then m[z,j]:=m[z,i]+m[i,j];
   for i:=1 to n do
     Begin
         fillchar(m3,sizeof(m3),0);
         for z:=1 to n do
            for j:=1 to n do
               if (z<>j) and (m[z,j]<>maxlongint) and (m[j,i]+m1[z,j]=m[z,i])
               then inc(m3[z]);
         for z:=1 to n do
            for j:=1 to n do
               if m[z,j]+m[j,i]=m[z,i]
               then inc(res[z,i],m3[j]);
     end;
   for i:=1 to n do
      for z:=i+1 to n do
         write(res[i,z],' ');
end.


Today s kilometer long auto race takes place in Berland. The track is represented by a straight line as long as s kilometers. There are n cars taking part in the race, all of them start simultaneously at the very beginning of the track. For every car is known its behavior — the system of segments on each of which the speed of the car is constant. The j-th segment of the i-th car is pair (vi,j,ti,j), where vi,j is the car's speed on the whole segment in kilometers per hour and ti,j is for how many hours the car had been driving at that speed. The segments are given in the order in which they are "being driven on" by the cars.Your task is to find out how many times during the race some car managed to have a lead over another car. A lead is considered a situation when one car appears in front of another car. It is known, that all the leads happen instantly, i. e. there are no such time segment of positive length, during which some two cars drive "together". At one moment of time on one and the same point several leads may appear. In this case all of them should be taken individually. Meetings of cars at the start and finish are not considered to be counted as leads.

The first line contains two integers n and s (2≤n≤100,1≤s≤10^6) — the number of cars and the length of the track in kilometers. Then follow n lines — the description of the system of segments for each car. Every description starts with integer k (1≤k≤100) — the number of segments in the system. Then k space-separated pairs of integers are written. Each pair is the speed and time of the segment. These integers are positive and don't exceed 1000. It is guaranteed, that the sum of lengths of all segments (in kilometers) for each car equals to s; and all the leads happen instantly.

Print the single number — the number of times some car managed to take the lead over another car during the race.

var
 a,b,i,j,k,n,tt1,tt2,x,ans,s,ss:longint;
 tt,ww:array [0..100,0..202] of longint;
 vv:array [0..100,0..202] of integer;
 zt:array [0..100] of integer;
 zz1,zz2,yy1,yy2:array [0..202] of longint;
function min(a,b:longint):longint;
 begin
 if a>b then
  begin
  min:=b;
  exit;
  end;
 min:=a;
 end;
procedure swap(var a,b:longint);
 var t:longint;
 begin
 t:=a; a:=b; b:=t;
 end;
procedure qsort(x,l,r:longint);
 var xx,i,j:longint;
 begin
 i:=l; j:=r;
 xx:=tt[x,(l+r) div 2];
 while i<=j do
  begin
  while tt[x,i]<xx do inc(i);
  while tt[x,j]>xx do dec(j);
  if i<=j then
   begin
   swap(ww[x,i],ww[x,j]);
   swap(tt[x,i],tt[x,j]);
   inc(i); dec(j);
   end;
  end;
 if l<j then qsort(x,l,j);
 if i<r then qsort(x,i,r);
 end;
begin
{ assign(input,'a.in');
reset(input);
assign(output,'a.out');
rewrite(output);   }
 readln(n,s);
 for i:=1 to n do
  begin
  read(k);
  for j:=1 to k do
   begin
   read(vv[i,j],tt[i,j+1]);
   ww[i,j+1]:=ww[i,j]+vv[i,j]*tt[i,j+1];
   tt[i,j+1]:=tt[i,j+1]+tt[i,j];
   end;
  zt[i]:=k+1;
  readln;
  end;
 for i:=1 to n-1 do
  for j:=i+1 to n do
   begin
   for k:=1 to zt[i] do
     begin
     zz1[k]:=ww[i,k]; yy1[k]:=tt[i,k];
     end;
   for k:=1 to zt[j] do
     begin
     zz2[k]:=ww[j,k]; yy2[k]:=tt[j,k];
     end;
   tt1:=zt[i]; tt2:=zt[j];
   x:=1;
   for k:=2 to zt[i] do
    begin
    if tt[i,k]>=tt[j,zt[j]] then break;
    while (tt[j,x]<=tt[i,k])  do inc(x);
    dec(x);
    if tt[j,x]=tt[i,k] then continue;
    inc(tt2); ww[j,tt2]:=ww[j,x]+(tt[i,k]-tt[j,x])*vv[j,x];
    tt[j,tt2]:=tt[i,k];
    end;
  x:=1;
  for k:=2 to zt[j] do
   begin
   if tt[j,k]>=tt[i,zt[i]] then break;
   while (tt[i,x]<=tt[j,k])  do inc(x);
   dec(x);
   if tt[i,x]=tt[j,k] then continue;
   inc(tt1); ww[i,tt1]:=ww[i,x]+(tt[j,k]-tt[i,x])*vv[i,x];
   tt[i,tt1]:=tt[j,k];
   end;
  qsort(i,1,tt1); qsort(j,1,tt2);
  x:=min(tt1,tt2);
  ss:=0;
  for k:=2 to x do
   begin
   if ww[i,k]>ww[j,k] then s:=1
    else if ww[i,k]<ww[j,k] then s:=-1
     else s:=ss;
   if ss*s=-1 then inc(ans);
   ss:=s;
   end;
   for k:=1 to zt[i] do
     begin
     ww[i,k]:=zz1[k]; tt[i,k]:=yy1[k];
     end;
  for k:=1 to zt[j] do
     begin
     ww[j,k]:=zz2[k]; tt[j,k]:=yy2[k];
     end;
  end;
 writeln(ans);
{ close(input);
close(output);   }
end.


On Bertown's main street n trees are growing, the tree number i has the height of ai meters (1≤i≤n). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This means that the heights of trees on ends (the 1st one and the n-th one) should be equal to each other, the heights of the 2-nd and the (n-1)-th tree must also be equal to each other, at that the height of the 2-nd tree should be larger than the height of the first tree by 1, and so on. In other words, the heights of the trees, standing at equal distance from the edge (of one end of the sequence) must be equal to each other, and with the increasing of the distance from the edge by 1 the tree height must also increase by 1. For example, the sequences "2 3 4 5 5 4 3 2" and "1 2 3 2 1" are beautiful, and '1 3 3 1" and "1 2 3 1" are not. Changing the height of a tree is a very expensive operation, using advanced technologies invented by Berland scientists. In one operation you can choose any tree and change its height to any number, either increase or decrease. Note that even after the change the height should remain a positive integer, i. e, it can't be less than or equal to zero. Identify the smallest number of changes of the trees' height needed for the sequence of their heights to become beautiful.

The first line contains integer n (1≤n≤10^5) which is the number of trees. The second line contains integers ai (1≤ai≤10^5) which are the heights of the trees.

Print a single number which is the minimal number of trees whose heights will have to be changed for the sequence to become beautiful.

{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  a, b : array[0..200000] of integer;
  i, n, max : integer;

begin
  //reset(input, 'input.txt');
  //rewrite(output, 'output.txt');

  read(n);
  fillchar(b, sizeof(b), 0);
  for i := 1 to n do begin
    read(a[i]);
    if i <= n div 2 then
      b[a[i] - i + 1] := b[a[i] - i + 1] + 1
    else
      b[a[i] - (n - i)] := b[a[i] - (n - i)] + 1;
  end;
  max := 1;
  for i := 2 to 200000 do
    if b[i] > b[max] then
      max := i;
  write(n - b[max]);

 // close(input);
 // close(output);
end.