You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).For example, for string "010210" we can perform the following moves:   "010210" $$$\rightarrow$$$ "100210";  "010210" $$$\rightarrow$$$ "001210";  "010210" $$$\rightarrow$$$ "010120";  "010210" $$$\rightarrow$$$ "010201". Note than you cannot swap "02" $$$\rightarrow$$$ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).String $$$a$$$ is lexicographically less than string $$$b$$$ (if strings $$$a$$$ and $$$b$$$ have the same length) if there exists some position $$$i$$$ ($$$1 \le i \le |a|$$$, where $$$|s|$$$ is the length of the string $$$s$$$) such that for every $$$j < i$$$ holds $$$a_j = b_j$$$, and $$$a_i < b_i$$$.

The first line of the input contains the string $$$s$$$ consisting only of characters '0', '1' and '2', its length is between $$$1$$$ and $$$10^5$$$ (inclusive).

Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).

              const eps=0.00000001;  besk1=200000008;  nn=1600000;
             { modul=1000000007;  }
   besk=8000000000000000000;
   label 22,1,2,3,4;
    type    real=extended;   double=extended;
    mas=array [-10..nn] of int64;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..nn] of longint;mass1=^mass;
    var posi,posj,diam,modul,oldt,ot1,time,pos,prod,ll,rr,posx,posy,gr,n,dloch,newdl,oldn,oldm,ost,ot,aa,bb,cc,p1,p2,p3,p4,kk,znamzz,kolperiod,znam,tperiod,start,finish,kol1,kol2,lavel,x0,p0,t2,t1,jj,w,ii,ogr,q,p,pp,tt,oldtt,qq,qq1,qq2,q1,q2,pmax,imax,t,nm,m,smin,cen:int64;
   pp0,mask,k,i1,j1,step1, step, i,j:longint;
   y:mas;
    ppp,prob1,prob2,prob3,pr1new,pr2new,pr3new,pr1,pr2,pr3:zap;
    oldpos,finot,vv,znak:int64;
    aold:mas;
    px,py,xc,yc,xxc,yyc:extended;
    del:array[-1..100001,-1..150] of longint;
    kolright,a,fact,next,prev,x,xx,yy,str,kol,s,name,d,dnew, voltay,l,r,c,z,day,b:array[-300000..2600000] of int64;
    zz:array[0..125000000] of byte;
    ppole:array[-10..1002,-10..1005] of char;
    pole,ddd,dd1,dd2,dd3,dd4,dd,ddsum:array[-10..1201,-10..1220] of int64;
   newzan,marked,zanx,zany:array[-1000000..2000000] of boolean;
    sss1,sss2:string;
    def,left,right,udal,stepen,koled,dl,och,newoch,place,newnabor,stoim,nabor:array[-10..200005] of int64;
     zanleft,zanright,zan,fl:array[-100000..10000000] of boolean;
    ss1,ss2,ss:string;ch,ch1,ch2:char;
    binkoef,numleft,numright,dr: array [-10..60,-10..60] of int64;
    s3,s2,s1:array[-100..200000] of string;

    grr :array [-10..2010,-10..2010] of boolean;
    maxpr:array[0..nn] of string;
    sss:array[-10..nn] of string;
     tx,ty,vel,x1,y1,ott,v0,v1,s0,t0:int64;
     zv:point;
     ugol,rot,temp,sumtemp,vol,newx,newy:array[-1000..400000] of int64;
     sq,sqx,sqy,ottt,aaa,bbb,ccc:extended;
     xxx,yyy,yot:double;
       flag2,flag,flag1:boolean;

  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 nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

     function summ(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p2+xx.p2*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=t1 div tt mod modul;
    t2:=t2 div tt mod modul;
    ott.p1:=t1; ott.p2:=t2;

   summ:=@ott;
 end;

{     function prod(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=(t1 div tt) mod modul;
    t2:=(t2 div tt) mod modul;
    ott.p1:=t1; ott.p2:=t2;

   prod:=@ott;
 end;
 }

    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 degg(a,k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=degg(a,k-1)*a mod modul else
   begin  p:=degg(a,k shr 1); degg:=p*p mod modul;   end;

end;

{function prost(tt:longint):boolean;
var aa:extended; i,p,t:longint;  fl:boolean;
 begin
   fl:=true;
   aa:=tt;
   aa:=sqrt(aa);
   t:=round(aa);
   for i:=2 to t do if tt mod i=0 then fl:=false;

   prost:=fl;
 end;
 }
function arcsin(pp:extended):extended;
var tt:extended;
begin
   if (abs(pp)<=1+eps)and (abs(pp)>=1-eps)
   then if pp>0 then arcsin:=pi/2 else arcsin:=-pi/2;
   tt:=1-pp*pp;
   if abs(tt)>=0 then
     begin
        arcsin:=arctan(pp/sqrt(tt));

     end;

end;

function gl(ch:char):boolean;
begin
 if (ch='o')or (ch='a')or(ch='e')or(ch='u')or(ch='i') then gl:=true else gl:=false;

end;

begin

  { assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
   }
      readln(ss);
      n:=length(ss);
     { writeln(ss);
     } for i:=1 to n do if ss[i]='2' then begin ll:=i; break; end;
      for i:=1 to n do if ss[i]='2' then begin rr:=i;  end;
     { writeln('ll= ',ll,' rr= ',rr);
     } for i:=1 to ll do if ss[i]='0' then inc(p0);
      for i:=1 to ll do if ss[i]='1' then inc(pp0);
      if ll=0 then
        begin
           p0:=0; p1:=0;
           for i:=1 to n do if ss[i]='0' then inc(p0);
           for i:=1 to n do if ss[i]='1' then inc(p1);
           for i:=1 to p0 do write('0');
           for i:=1 to p1 do write('1');

          goto 1;
        end;

      for i:=1 to n do if ss[i]='1' then inc(p1);
      for i:=1 to p0 do write('0');
      for i:=1 to p1 do write('1');
      for i:=ll to rr do if (ss[i]='0')or(ss[i]='2') then
        begin inc(q); write(ss[i]); end;
     for i:=1 to n-p0-p1-q do write('0');

   1:          close(output);
end.


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

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

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

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

{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Var
   a,b:Array[1..100000] of Integer;
   s:Array[1..100,1..100] of Integer;
   used:Array[1..100] of Boolean;
   i,n,m:Integer;
Procedure Dfs(i:Integer);
Var
   j:Integer;
Begin
   used[i]:=true;
   For j:=1 To n Do
      If (s[i,j]=1) and (not(used[j])) Then Dfs(j);
End;
Begin
   Read(n,m);
   For i:=1 To m Do Read(a[i],b[i]);
   For i:=1 To m Do Begin
      s[a[i],b[i]]:=1;
      s[b[i],a[i]]:=1;
   End;
   If n<>m Then Begin
      Write('NO');
      Halt;
   End;
   Dfs(1);
   For i:=1 To n Do
      If not(used[i]) Then Begin
         Write('NO');
         Halt;
      End;
   Write('FHTAGN!');
End.


When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number k. Moreover, petricium la petricium stands for number k^2, petricium la petricium la petricium stands for k^3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.Petya's invention brought on a challenge that needed to be solved quickly: does some number l belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.

The first input line contains integer number k, the second line contains integer number l (2≤k,l≤2^31-1).

You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number l.

{$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}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}

const filename='x';
      oo=maxlongint div 2;
      eps=1e-6;
      eee=1e-21;

var qq,cc,rr:array[0..1000000]of longint;
    qc:array[0..2000,0..2000]of int64;
    ss:array[0..1000]of string;
    s,s0,s1,s2,s3:string;
    x,y,z,xx,yy,zz,x0,y0,z0,x1,x2,x3,y1,y2,y3,z1,z2,z3:extended;
    res,cur:int64;
    aa,bb,u,v,nt,ii,jj,kk,nn,mm,n,m,q,c,q0,c0,q1,c1,q2,c2,q3,c3,max,min:longint;
    test,ll,t,tt:longint;
    b,bbb,b0,b1,b2,b3:boolean;

procedure init;
  begin
  assign(input,filename+'.in');
  assign(output,filename+'.out');
  reset(input);
  rewrite(output);
  end;

procedure fin;
  begin
  close(input);
  close(output);
  end;

procedure clear;
var i,j,k:longint;
  begin
  fillchar(qc,sizeof(qc),0);
  end;

procedure load;
var i,j,k:longint;
  begin
  end;

procedure save;
var i,j,k:longint;
  begin
  end;

function gcd(q,c:int64):int64;
  begin
  while ((q>0)and(c>0)) do
    if q>c then q:=q mod c else c:=c mod q;
  if q>0 then gcd:=q else gcd:=c;
  end;

procedure run;
var i,j,k,z,s:longint;
    r,m,x:int64;
  begin
  //init;
  read(n,cur);
  x:=n;
  res:=0;
  while x<cur do
    begin
    x:=x*n;
    inc(res);
    end;
  if x=cur then begin writeln('YES'); writeln(res); end else writeln('NO');
  end;

begin
nt:=1;
//readln(nt);
for test:=1 to nt do
  begin
  clear;
  load;
  run;
  save;
  end;
end.


You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.

The first line contains integers n and k — the number and digit capacity of numbers correspondingly (1≤n,k≤8). Next n lines contain k-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits.

Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule.

In the first sample, if we rearrange the digits in numbers as (3,1,4,2), then the 2-nd and the 4-th numbers will equal 5237 and 2537 correspondingly (they will be maximum and minimum for such order of digits).
In the second sample, if we swap the second digits and the first ones, we get integers 100, 99 and 102.

{$R+ Q+ I+}
{$APPTYPE CONSOLE}
uses
  Sysutils;
var
   p : array[1..8] of integer;
   a : array[1..8,1..8] of integer;
   k,n,ans : integer;
   c : array[1..8] of integer;
   status : array[1..8] of boolean;
procedure search(i : integer);
var
   kol,r,j,min,max : integer;
begin
     if i = k then begin
        kol := 1;
        for r := 1 to n do p[r] := 0;
        for j := k downto 1 do begin
                for r := 1 to n do
                p[r] := p[r] + a[r][c[j]]*kol;
            kol := kol*10;
        end;
        min := high(min);
        max := low(max);
        for r := 1 to n do begin
            if p[r] > max then max := p[r];
            if p[r] < min then min := p[r];
        end;
        if max - min < ans then ans := max - min;
        exit;
     end;
     for j := 1 to k do begin
         if status[j] = true then continue;
         inc(i);
         c[i] := j;
         status[j] := true;
         search(i);
         status[j] := false;
         dec(i);
     end;
end;
var
   i,j : integer;
   ch : char;
begin
     readln(n,k);
     for i := 1 to n do begin
         for j := 1 to k do begin
             read(ch);
             a[i][j] := strtoint(ch);
         end;
         readln;
     end;
     ans := high(ans);
     search(0);
     write(ans);
end.


A PIN code is a string that consists of exactly $$$4$$$ digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.Polycarp has $$$n$$$ ($$$2 \le n \le 10$$$) bank cards, the PIN code of the $$$i$$$-th card is $$$p_i$$$.Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all $$$n$$$ codes would become different.Formally, in one step, Polycarp picks $$$i$$$-th card ($$$1 \le i \le n$$$), then in its PIN code $$$p_i$$$ selects one position (from $$$1$$$ to $$$4$$$), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different.Polycarp quickly solved this problem. Can you solve it?

The first line contains integer $$$t$$$ ($$$1 \\le t \\le 100$$$) — the number of test cases in the input. Then test cases follow.
The first line of each of $$$t$$$ test sets contains a single integer $$$n$$$ ($$$2 \\le n \\le 10$$$) — the number of Polycarp's bank cards. The next $$$n$$$ lines contain the PIN codes $$$p_1, p_2, \\dots, p_n$$$ — one per line. The length of each of them is $$$4$$$. All PIN codes consist of digits only.

Print the answers to $$$t$$$ test sets. The answer to each set should consist of a $$$n + 1$$$ lines
In the first line print $$$k$$$ — the least number of changes to make all PIN codes different. In the next $$$n$$$ lines output the changed PIN codes in the order corresponding to their appearance in the input. If there are several optimal answers, print any of them.

     const eps=1e-14;
     besk=2002000000000000000; label 4,1,3,2,44,22;
     type mas=array[-100..1200000+1] of int64;
    integer=longint;    zap=record  x,y,z:extended; end;
    zap1=^zap;
    var qqq,oldpos,jj,kolvzv,sdvig,start,dl,len,i1,j1,mask,stepp,n2,i,j,k,l,step,k1,mesto,num:longint;
   ss3,ss,ss1,ss2:string;
   pqqq:zap;  bet,al:extended;
   pt,ott1,ott2:zap;
  ver:array[-1..500,-1..5] of extended;
   verugad:array[-2..200,-2..200,-2..200] of extended;
   ot1,ot2,oldgr,predsum,pmin,tmin,pos,aa,bb,kool,sum,number,imin,kolreber,kolstan,qq,kol,chisl,znam,n,m,ttt,numpos,vx,vy,ans,up,down,xmin,xmax,ymin,ymax,imax,t3,qq1,qq2,q1,q2,ost,koll,w,dx,dy,finish,time,p3,p4,qqqq,ii,tt,pmax,pmax2,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,tmax,summax,nn,kk,modul,t0,n1,q,t,p:int64; flag1:boolean;
  left,right,pow,znum,z,stan,a2,invx,invy,summ,place,str,b2,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
  vel,zapas,razn,oldll,oldrr,ppp,shag,posx,posy,minx,miny,maxx,maxy,kolplus,kolminus,razr,jmax,gr,grr,ener,dob,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
  zzan,prost,marked,zan:array[-1000000..1000000] of boolean;
   zznum,zz,ll,rr,zpl,zmi,path,lx,a3,a4,dd1,dd2,predok,a1,b1,strok:array[-10000..1500000] of int64;
   ppole:array[-1000000..3000000] of char;
   str1,str2,stroka:array[-1000..1000000] of char;
 dinam:array[-100000..1000000] of extended;
 t1,t2,al1,bet1,cosa,sina,cosb,sinb,rx,ry,sdvigx,sdvigy,px,py,h1,h2,h,l1,l2,otmax,v:int64;
  dd,ssumitog,profil,zzz:array[-10..2100,-10..2100] of int64;
  sp,sss:array[-10..2000000] of string;
  newpole,pole:array[-1..2100,-1..2700] of char;
  blizpr,ddd,ddinv,dnech,poschet,posnechet:array[-10..390000,-1..6] of int64;
  poss:int64;
  ch:char;
  ff,flagg1:boolean;
  oldx,oldy,numx,numy,xleft,xright,s,znach,nomer,newplace,newstr,next,prev,xx,yy,aold,x,y:array[-10000..1700002] of int64;
  dp:array[0..3,-1..910,0..12] of int64;
   function srav(i,j:longint):boolean; label 44;
        begin
         if (a[i]<a[j]) then begin srav:=true; goto 44;  end;
        if a[i]>a[j] then begin  srav:=false; goto 44;   end;
         if a[i]=a[j] then if a1[i]>a1[j] then srav:=true else srav:=false;
             44:
        end;

      procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
         begin
        i:=l;j:=m; flag:=true; step:=0;while flag do begin
       if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
        inc(step);inc(i);
        {writeln('step=',step,' i=',i);} end;
       if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[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];b2[l+step]:=a2[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];b2[l+step]:=a2[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];a2[i]:=b2[i]; end;
                 until (k>=n);

              end;

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

{   function evkl(a,b:int64):zap1; var d,x,y,r,q,i,j,k,x1,x2,y1,y2:int64;
   tt:zap; tt1:zap1;  fl:boolean;
begin
   fl:=false;
   if a<b then begin r:=a;a:=b;b:=r; fl:=true; end;
   x2:=1;x1:=0;y2:=0;y1:=1;
   while b>0 do
      begin q:=a div b; r:=a mod b; x:=x2-q*x1;y:=y2-q*y1;
           a:=b;b:=r;x2:=x1;x1:=x;y2:=y1;y1:=y;
      end;
    if not fl then begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=x;tt.p3:=y; tt1:=@tt; end else
             begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=y;tt.p3:=x; tt1:=@tt; end;
          evkl:=tt1;
end;

 }
      function phi(a,b:double):double; label 222;var p:double;
         begin
          if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
          if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
         if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
         if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
         if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
         222: phi:=p;
        end;

   function nod(a,b:int64):int64; var p,t:int64;
           begin
             a:=abs(a); b:=abs(b);
             if (a>0)and(b>0) then
            begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
                  p:=a;
              end else if a=0 then p:=b else p:=a;
              nod:=p;
            end;
                      function arccos(tt:extended):extended;
              begin
                if abs(tt)>1-1e-13 then
                if tt>0 then  arccos:=0 else arccos:=pi;
                if tt=0 then arccos:=pi/2 else
                if abs(tt)<=1-1e-13 then if tt>=0 then arccos:=arctan(sqrt(1-tt*tt)/tt)
                else arccos:=pi+arctan(sqrt(1-tt*tt)/tt);

              end;

      function nok(a,b:int64):int64;
       begin  nok:=(a*b) div nod(a,b);  end;

     function degg(a:int64;k:int64):int64; var p:int64;
          begin
           if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
             begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

         end;

     function zaprmax(left,right:longint):int64;
        begin
              if left>=right then zaprmax:=y[left] else
         begin
          if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
              begin
              if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
              if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);
              end;

          end;

         end;

      function zaprmin(left,right:longint):int64;
        begin
        if left>=right then zaprmin:=y[left] else
           begin
         if not odd(left) and odd(right) then zaprmin:=zaprmin(left shr 1,right shr 1) else
            begin
             if odd(left) then  zaprmin:=min(zaprmin(left+1,right),y[left]);
             if not odd(right) then zaprmin:=min(zaprmin(left,right-1),y[right]);
             end;
           end;

                        end;

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

   function nomerr(gr:int64):int64;
    var ot,aa,bb,cc:int64; fl:boolean;
         begin
        aa:=1; bb:=p;  cc:=aa; fl:=false;
          while abs(aa-bb)>1 do
             begin
               cc:=(aa+bb) shr 1;
                writeln('cc=++ ',cc);
              if y[cc]<gr then aa:=cc else bb:=cc;

             end;
              writeln(' cc= ',cc);
           {  cc:=max(cc-3,0);
               }  repeat inc(cc) until y[cc]>=gr;
                  if y[cc]=gr then fl:=true else fl:=false;
                  if fl then nomerr:=a1[cc] else nomerr:=-1000;
                   nomerr:=cc;
         end;

   function pprost(pp:longint):boolean;
    var i,j,t:longint; tt:extended; fl:boolean;
       begin
       tt:=pp;
       tt:=sqrt(tt);
       fl:=true;
       for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;
       pprost:=fl;
       end;

   function gl(c:char):boolean;
          begin
      if (c='a')or (c='o')or(c='e')or(c='i')or(c='u') then gl:=true else gl:=false;
          end;
        function koren(a,b,c,d,t:extended):boolean;
        var ot,p,q:extended;
        begin
          p:=abs(a); if abs(b)>p then p:=abs(b); if abs(c)>p then p:=abs(c); if abs(d)>p then p:=abs(d);
          ot:=a*t*t*t+b*t*t+c*t+d;
          if abs(ot)<eps*p then koren:=true else
        end;

        function mnog(a,b,c,d,t:extended):extended;
        begin  mnog:=a*t*t*t+b*t*t+c*t+d;  end;

        function kor(a,b,c,d,left,right:extended):extended;
        var  p1,p2,ll,rr,mm:extended; k:longint;

        begin
         ll:=left; rr:=right;  k:=0;
         while k<100 do
           begin
              inc(k);
              mm:=(ll+rr)/2;
              if mnog(a,b,c,d,mm)*mnog(a,b,c,d,ll)<=0 then rr:=mm else ll:=mm;

           end;

         kor:=mm;
        end;

         function roots(a,b,c,d:int64):zap1;  label 98,97;
         var disk,l,r,m,left,right,aa,bb,cc:extended;  ans:zap;
        begin
          aa:=3*a;
          bb:=2*b;
          cc:=c;
          disk:=bb*bb-4*aa*cc;
          if disk<0 then begin   goto 98;  end;
          left:=(-bb-sqrt(disk))/(2*aa);
          right:=(-bb+sqrt(disk))/(2*aa);
          if abs(left-right)<eps then begin  ans.x:=left; ans.y:=left;ans.z:=left;  end;
         { writeln('left= ',left:0:25,' right= ',right:0:25);
         } if koren(a,b,c,d,left) then ans.x:=left else
          begin aa:=kor(a,b,c,d,-besk,left);
          writeln('aa= ',aa:0:7);
          if koren(a,b,c,d,aa) then ans.x:=aa;  end;
          aa:=kor(a,b,c,d,left,right);
          writeln('aa= ',aa:0:7);
          if koren(a,b,c,d,aa) then ans.y:=aa;

          aa:=kor(a,b,c,d,right,besk);
          writeln('aa= ',aa:0:7);
          if koren(a,b,c,d,aa) then ans.z:=aa;

        98:
         roots:=@ans;
        end;

begin
  { assign (input,'D:\Projects\input.txt');reset(input);
   assign (output,'D:\Projects\output.txt'); rewrite(output);
   }
   read(q);
 for stepp:=1 to q do
 begin
   readln(p);
   for i:=1 to p do readln(sss[i]);
   for i:=1 to p do x[i]:=i;
   for i:=1 to p do for j:=1 to p-1 do if sss[j]>sss[j+1] then
     begin t:=x[j]; x[j]:=x[j+1]; x[j+1]:=t;
     ss:=sss[j]; sss[j]:=sss[j+1]; sss[j+1]:=ss;  end;

   ot:=0;
  { for i:=1 to p do writeln(sss[i],' ',x[i]);
   }

   for i:=1 to p do zan[i]:=false;
   for i:=1 to p-1 do if sss[i]=sss[i+1] then begin inc(ot); zan[i+1]:=true;  end;
   writeln(ot);
   for i:=1 to p do for j:=1 to 4 do  ddd[i,j]:=ord(sss[i,j])-48;
    for step:=1 to p do if zan[step] then

     begin
       { writeln('step= ',step);
       }   for i:=1 to 4 do for k:=0 to 9 do
            begin
               for l:=1 to 4 do y[l]:=ddd[step,l];
            {   for l:=1 to 4 do write(y[l],' '); writeln;
             }
               y[i]:=k;
          {     for l:=1 to 4 do write(y[l],' '); writeln;
          }     ss:='';
               for l:=1 to 4 do ss:=ss+chr(y[l]+48);
               flag:=false;
               for l:=1 to p do if (ss=sss[l])and(l<>step) then flag:=true;
           {    writeln('try ss= ',ss,' flag= ',flag);
            }   if not flag then begin sss[step]:=ss; sp[step]:=ss; goto 2;   end;

            end;
  2:
        for i:=1 to p do sp[i]:=sss[i];
     end else sp[step]:=sss[step];

    for i:=1 to p do sss[x[i]]:=sp[i];
    for i:=1 to p do writeln(sss[i]);

 end;

    1: close (output);
end.


HQ9+ is a joke programming language which has only four one-character instructions: "H" prints "Hello, World!", "Q" prints the source code of the program itself, "9" prints the lyrics of "99 Bottles of Beer" song,  "+" increments the value stored in the internal accumulator.Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.

The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.

Output "YES", if executing the program will produce any output, and "NO" otherwise.

In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  i : integer;
  s : string;
  flag : boolean;

begin
  readln(input, s);
  flag := false;
  for i := 1 to length(s) do
    begin
        if (ord(s[i]) >= 33) and (ord(s[i]) <= 126) then
          begin
              if (s[i] = 'H') or (s[i] = '9') or (s[i] = 'Q') then
                begin
                 flag := true;
                 break;
                end;
          end;
    end;
    if flag then
      writeln(output, 'YES')
    else
      writeln(output, 'NO');

end.

[{'input': ['Hi!\r\n'], 'output': ['YES\r\n']}, {'input': ['Codeforces\r\n'], 'output': ['NO\r\n']}, {'input': ['a+b=c\r\n'], 'output': ['NO\r\n']}, {'input': ['hq-lowercase\r\n'], 'output': ['NO\r\n']}, {'input': ['Q\r\n'], 'output': ['YES\r\n']}, {'input': ['9\r\n'], 'output': ['YES\r\n']}, {'input': ['H\r\n'], 'output': ['YES\r\n']}, {'input': ['+\r\n'], 'output': ['NO\r\n']}, {'input': ['~\r\n'], 'output': ['NO\r\n']}, {'input': ['dEHsbM\'gS[\\brZ_dpjXw8f?L[4E"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR\r\n'], 'output': ['YES\r\n']}, {'input': ['tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC\r\n'], 'output': ['YES\r\n']}, {'input': ['@F%K2=%RyL/\r\n'], 'output': ['NO\r\n']}, {'input': ['juq)k(FT.^G=G\\zcqnO"uJIE1_]KFH9S=1c"mJ;F9F)%>&.WOdp09+k`Yc6}"6xw,Aos:M\\_^^:xBb[CcsHm?J\r\n'], 'output': ['YES\r\n']}, {'input': ['6G_"Fq#<AWyHG=Rci1t%#Jc#x<Fpg\'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)\r\n'], 'output': ['YES\r\n']}, {'input': ['Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C\r\n'], 'output': ['YES\r\n']}, {'input': ['p-UXsbd&f\r\n'], 'output': ['NO\r\n']}, {'input': ['<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S\'>yz8cKgVHWZ]kV0>_\r\n'], 'output': ['YES\r\n']}, {'input': ['f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf"!#qh]\r\n'], 'output': ['YES\r\n']}, {'input': ['}do5RU<(w<q["-NR)IAH_HyiD{\r\n'], 'output': ['YES\r\n']}, {'input': ["Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8\r\n"], 'output': ['YES\r\n']}, {'input': ['sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z"k2S{NF7btLa3_TyXG4XZ:`(t&"\'^M|@qObZxv\r\n'], 'output': ['YES\r\n']}, {'input': ['%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`\r\n'], 'output': ['YES\r\n']}, {'input': ['OKBB5z7ud81[Tn@P"nDUd,>@\r\n'], 'output': ['NO\r\n']}, {'input': ["y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv\r\n"], 'output': ['YES\r\n']}, {'input': ['EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh\r\n'], 'output': ['YES\r\n']}, {'input': ['UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp\r\n'], 'output': ['NO\r\n']}, {'input': ['!3YPv@2JQ44@)R2O_4`GO\r\n'], 'output': ['YES\r\n']}, {'input': ['Kba/Q,SL~FMd)3hOWU\'Jum{9"$Ld4:GW}D]%tr@G{hpG:PV5-c\'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\\r\n'], 'output': ['YES\r\n']}, {'input': ['NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e"C)q_L\r\n'], 'output': ['NO\r\n']}, {'input': ["y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&\r\n"], 'output': ['YES\r\n']}, {'input': ['+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}\r\n'], 'output': ['YES\r\n']}, {'input': ['Uh3>ER](J\r\n'], 'output': ['NO\r\n']}, {'input': ['!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,\r\n'], 'output': ['YES\r\n']}, {'input': ['KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!\r\n'], 'output': ['YES\r\n']}, {'input': ['[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@\r\n'], 'output': ['YES\r\n']}, {'input': ["'jdL(vX\r\n"], 'output': ['NO\r\n']}, {'input': ['Q;R+aay]cL?Zh*uG"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5\r\n'], 'output': ['YES\r\n']}, {'input': ['{Q@#<LU_v^qdh%gGxz*pu)Y"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s\r\n'], 'output': ['YES\r\n']}, {'input': ['~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J\'jJB)$ujfPAq"G<S9flGyakZg!2Z.-NJ|2{F>]\r\n'], 'output': ['YES\r\n']}, {'input': ['Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&"ioE&7zP"\'xHAY;:x%@SnS]Mr{R|})gU\r\n'], 'output': ['YES\r\n']}, {'input': ['ZA#:U)$RI^sE\\vuAt]x"2zipI!}YEu2<j$:H0_9/~eB?#->\r\n'], 'output': ['YES\r\n']}, {'input': ['&ppw0._:\\p-PuWM@l}%%=\r\n'], 'output': ['NO\r\n']}, {'input': ['P(^pix"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr\r\n'], 'output': ['YES\r\n']}, {'input': ['`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q\r\n'], 'output': ['YES\r\n']}, {'input': [",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0\r\n"], 'output': ['YES\r\n']}, {'input': ['VXB&r9Z)IlKOJ:??KDA\r\n'], 'output': ['YES\r\n']}, {'input': ['")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R\r\n'], 'output': ['YES\r\n']}, {'input': ["2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C\r\n"], 'output': ['YES\r\n']}, {'input': ['O.&=qt(`z(\r\n'], 'output': ['NO\r\n']}, {'input': ['_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB\'-scSg$$|"jAzY0N>QkHHGBZj2c"=fhRlWd5;5K|GgU?7h]!;wl@\r\n'], 'output': ['YES\r\n']}, {'input': ['+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp\r\n'], 'output': ['YES\r\n']}, {'input': ['U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8\r\n'], 'output': ['YES\r\n']}, {'input': ['!0WKT:$O\r\n'], 'output': ['NO\r\n']}, {'input': ["1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)\r\n"], 'output': ['YES\r\n']}, {'input': ['[u3"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12"`^\'/u*h%AFmPJ>e1#Yly\r\n'], 'output': ['YES\r\n']}, {'input': ["'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(\r\n"], 'output': ['NO\r\n']}, {'input': ['Qv)X8\r\n'], 'output': ['YES\r\n']}, {'input': ['aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%"R(?ouBD>_=y"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F\r\n'], 'output': ['YES\r\n']}, {'input': ['e{}2vQ+/r@p0}cLKNe4MCk\r\n'], 'output': ['YES\r\n']}, {'input': ['mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH\r\n'], 'output': ['YES\r\n']}, {'input': ['Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky\r\n'], 'output': ['YES\r\n']}, {'input': ['mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky\r\n'], 'output': ['YES\r\n']}, {'input': ['1H1\r\n'], 'output': ['YES\r\n']}, {'input': ['+Q\r\n'], 'output': ['YES\r\n']}, {'input': ['1ab\r\n'], 'output': ['NO\r\n']}, {'input': ['!\r\n'], 'output': ['NO\r\n']}, {'input': ['0+\r\n'], 'output': ['NO\r\n']}, {'input': ['+H\r\n'], 'output': ['YES\r\n']}, {'input': ['cH\r\n'], 'output': ['YES\r\n']}, {'input': ['+8\r\n'], 'output': ['NO\r\n']}, {'input': ['8+\r\n'], 'output': ['NO\r\n']}, {'input': ['++++++++++++++++++++++++++\r\n'], 'output': ['NO\r\n']}, {'input': ['(+)\r\n'], 'output': ['NO\r\n']}, {'input': ['H+\r\n'], 'output': ['YES\r\n']}, {'input': ['a!\r\n'], 'output': ['NO\r\n']}, {'input': ['++++++++++++++\r\n'], 'output': ['NO\r\n']}, {'input': ['+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n'], 'output': ['NO\r\n']}, {'input': ['8\r\n'], 'output': ['NO\r\n']}, {'input': ['3\r\n'], 'output': ['NO\r\n']}, {'input': ['HQ9\r\n'], 'output': ['YES\r\n']}, {'input': ['+++H\r\n'], 'output': ['YES\r\n']}, {'input': ['++++++++++\r\n'], 'output': ['NO\r\n']}, {'input': ['HHHHHHH\r\n'], 'output': ['YES\r\n']}, {'input': ['abacabaH\r\n'], 'output': ['YES\r\n']}, {'input': ['+G\r\n'], 'output': ['NO\r\n']}]


You are given a sequence of positive integers a1,a2,...,an. Find all such indices i, that the i-th element equals the arithmetic mean of all other elements (that is all elements except for this one).

The first line contains the integer n (2≤n≤2·10^5). The second line contains elements of the sequence a1,a2,...,an (1≤ai≤1000). All the elements are positive integers.

Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to n.
If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line.

program Project2;
Var m:array [1..200000] of integer;
n,i,j,k:integer;
begin
//  Assign(Input,'input.txt');
//  Assign(Output,'output.txt');
  Readln(n);
  k:=0;
  for i:=1 to n do
  begin
    read(m[i]);
    k:=k+m[i];
  end;
  j:=0;
  for i:=1 to n do
  if ((k-m[i]) mod (n-1)=0)and((k-m[i])div (n-1)=m[i])
  then Inc(j);
  Writeln(j);
  for i:=1 to n do
  if ((k-m[i]) mod (n-1)=0)and((k-m[i])div (n-1)=m[i])
  then write(i,' ');
end.


Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there.If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift.Now Petya wants to know for each friend i the number of a friend who has given him a gift.

The first line contains one integer n (1≤n≤100) — the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi — the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.

Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i.

Program qq;
var n,i:integer;
var A,B:array [1..100] of integer;
begin
read(n);
for i:=1 to n do begin
read(A[i]);
B[A[i]]:=i;
end;
for i:= 1 to n do begin
write(B[i]);
write(' ');
end;
end.


One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly n pages.Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week.Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book.

The first input line contains the single integer n (1≤n≤1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero.

Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.

Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second sample:
On Monday of the first week Petr will read the first page. On Monday of the second week Petr will read the second page and will finish reading the book.

var a:array[1..7]of longint;
n,k:longint;
begin
read(n);
for k:=1 to 7 do read(a[k]);
k:=0;
while n>0 do
begin
inc(k);
if k=8 then k:=1;
dec(n,a[k]);
end;
writeln(k);
end.


So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.

The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.

Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.

In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L".

var
  s1, s2, s3: string;
  i: longint;
  c: char;
  a: array['A'..'Z'] of longint;

begin
  readln(s1);
  readln(s2);
  readln(s3);
  for i := 1 to length(s1) do
    inc(a[s1[i]]);
  for i := 1 to length(s2) do
    inc(a[s2[i]]);
  for i := 1 to length(s3) do
    dec(a[s3[i]]);
  for c := 'A' to 'Z' do
    if a[c] <> 0 then begin
      write('NO');
      halt;
    end;
  write('YES');
end.

[{'input': ['SANTACLAUS\r\nDEDMOROZ\r\nSANTAMOROZDEDCLAUS\r\n'], 'output': ['YES\r\n']}, {'input': ['PAPAINOEL\r\nJOULUPUKKI\r\nJOULNAPAOILELUPUKKI\r\n'], 'output': ['NO\r\n']}, {'input': ['BABBONATALE\r\nFATHERCHRISTMAS\r\nBABCHRISTMASBONATALLEFATHER\r\n'], 'output': ['NO\r\n']}, {'input': ['B\r\nA\r\nAB\r\n'], 'output': ['YES\r\n']}, {'input': ['ONDOL\r\nJNPB\r\nONLNJBODP\r\n'], 'output': ['YES\r\n']}, {'input': ['Y\r\nW\r\nYW\r\n'], 'output': ['YES\r\n']}, {'input': ['OI\r\nM\r\nIMO\r\n'], 'output': ['YES\r\n']}, {'input': ['VFQRWWWACX\r\nGHZJPOQUSXRAQDGOGMR\r\nOPAWDOUSGWWCGQXXQAZJRQRGHRMVF\r\n'], 'output': ['YES\r\n']}, {'input': ['JUTCN\r\nPIGMZOPMEUFADQBW\r\nNWQGZMAIPUPOMCDUB\r\n'], 'output': ['NO\r\n']}, {'input': ['Z\r\nO\r\nZOCNDOLTBZKQLTBOLDEGXRHZGTTPBJBLSJCVSVXISQZCSFDEBXRCSGBGTHWOVIXYHACAGBRYBKBJAEPIQZHVEGLYH\r\n'], 'output': ['NO\r\n']}, {'input': ['IQ\r\nOQ\r\nQOQIGGKFNHJSGCGM\r\n'], 'output': ['NO\r\n']}, {'input': ['ROUWANOPNIGTVMIITVMZ\r\nOQTUPZMTKUGY\r\nVTVNGZITGPUNPMQOOATUUIYIWMMKZOTR\r\n'], 'output': ['YES\r\n']}, {'input': ['OVQELLOGFIOLEHXMEMBJDIGBPGEYFG\r\nJNKFPFFIJOFHRIFHXEWYZOPDJBZTJZKBWQTECNHRFSJPJOAPQT\r\nYAIPFFFEXJJNEJPLREIGODEGQZVMCOBDFKWTMWJSBEBTOFFQOHIQJLHFNXIGOHEZRZLFOKJBJPTPHPGY\r\n'], 'output': ['YES\r\n']}, {'input': ['NBJGVNGUISUXQTBOBKYHQCOOVQWUXWPXBUDLXPKX\r\nNSFQDFUMQDQWQ\r\nWXKKVNTDQQFXCUQBIMQGQHSLVGWSBFYBUPOWPBDUUJUXQNOQDNXOX\r\n'], 'output': ['YES\r\n']}, {'input': ['IJHHGKCXWDBRWJUPRDBZJLNTTNWKXLUGJSBWBOAUKWRAQWGFNL\r\nNJMWRMBCNPHXTDQQNZ\r\nWDNJRCLILNQRHWBANLTXWMJBPKUPGKJDJZAQWKTZFBRCTXHHBNXRGUQUNBNMWODGSJWW\r\n'], 'output': ['YES\r\n']}, {'input': ['SRROWANGUGZHCIEFYMQVTWVOMDWPUZJFRDUMVFHYNHNTTGNXCJ\r\nDJYWGLBFCCECXFHOLORDGDCNRHPWXNHXFCXQCEZUHRRNAEKUIX\r\nWCUJDNYHNHYOPWMHLDCDYRWBVOGHFFUKOZTXJRXJHRGWICCMRNEVNEGQWTZPNFCSHDRFCFQDCXMHTLUGZAXOFNXNVGUEXIACRERU\r\n'], 'output': ['YES\r\n']}, {'input': ['H\r\nJKFGHMIAHNDBMFXWYQLZRSVNOTEGCQSVUBYUOZBTNKTXPFQDCMKAGFITEUGOYDFIYQIORMFJEOJDNTFVIQEBICSNGKOSNLNXJWC\r\nBQSVDOGIHCHXSYNYTQFCHNJGYFIXTSOQINZOKSVQJMTKNTGFNXAVTUYEONMBQMGJLEWJOFGEARIOPKFUFCEMUBRBDNIIDFZDCLWK\r\n'], 'output': ['YES\r\n']}, {'input': ['DSWNZRFVXQ\r\nPVULCZGOOU\r\nUOLVZXNUPOQRZGWFVDSCANQTCLEIE\r\n'], 'output': ['NO\r\n']}, {'input': ['EUHTSCENIPXLTSBMLFHD\r\nIZAVSZPDLXOAGESUSE\r\nLXAELAZ\r\n'], 'output': ['NO\r\n']}, {'input': ['WYSJFEREGELSKRQRXDXCGBODEFZVSI\r\nPEJKMGFLBFFDWRCRFSHVEFLEBTJCVCHRJTLDTISHPOGFWPLEWNYJLMXWIAOTYOXMV\r\nHXERTZWLEXTPIOTFRVMEJVYFFJLRPFMXDEBNSGCEOFFCWTKIDDGCFYSJKGLHBORWEPLDRXRSJYBGASSVCMHEEJFLVI\r\n'], 'output': ['NO\r\n']}, {'input': ['EPBMDIUQAAUGLBIETKOKFLMTCVEPETWJRHHYKCKU\r\nHGMAETVPCFZYNNKDQXVXUALHYLOTCHM\r\nECGXACVKEYMCEDOTMKAUFHLHOMT\r\n'], 'output': ['NO\r\n']}, {'input': ['NUBKQEJHALANSHEIFUZHYEZKKDRFHQKAJHLAOWTZIMOCWOVVDW\r\nEFVOBIGAUAUSQGVSNBKNOBDMINODMFSHDL\r\nKLAMKNTHBFFOHVKWICHBKNDDQNEISODUSDNLUSIOAVWY\r\n'], 'output': ['NO\r\n']}, {'input': ['VXINHOMEQCATZUGAJEIUIZZLPYFGUTVLNBNWCUVMEENUXKBWBGZTMRJJVJDLVSLBABVCEUDDSQFHOYPYQTWVAGTWOLKYISAGHBMC\r\nZMRGXPZSHOGCSAECAPGVOIGCWEOWWOJXLGYRDMPXBLOKZVRACPYQLEQGFQCVYXAGBEBELUTDAYEAGPFKXRULZCKFHZCHVCWIRGPK\r\nRCVUXGQVNWFGRUDLLENNDQEJHYYVWMKTLOVIPELKPWCLSQPTAXAYEMGWCBXEVAIZGGDDRBRT\r\n'], 'output': ['NO\r\n']}, {'input': ['PHBDHHWUUTZAHELGSGGOPOQXSXEZIXHZTOKYFBQLBDYWPVCNQSXHEAXRRPVHFJBVBYCJIFOTQTWSUOWXLKMVJJBNLGTVITWTCZZ\r\nFUPDLNVIHRWTEEEHOOEC\r\nLOUSUUSZCHJBPEWIILUOXEXRQNCJEGTOBRVZLTTZAHTKVEJSNGHFTAYGY\r\n'], 'output': ['NO\r\n']}, {'input': ['GDSLNIIKTO\r\nJF\r\nPDQYFKDTNOLI\r\n'], 'output': ['NO\r\n']}, {'input': ['AHOKHEKKPJLJIIWJRCGY\r\nORELJCSIX\r\nZVWPXVFWFSWOXXLIHJKPXIOKRELYE\r\n'], 'output': ['NO\r\n']}, {'input': ['ZWCOJFORBPHXCOVJIDPKVECMHVHCOC\r\nTEV\r\nJVGTBFTLFVIEPCCHODOFOMCVZHWXVCPEH\r\n'], 'output': ['NO\r\n']}, {'input': ['AGFIGYWJLVMYZGNQHEHWKJIAWBPUAQFERMCDROFN\r\nPMJNHMVNRGCYZAVRWNDSMLSZHFNYIUWFPUSKKIGU\r\nMCDVPPRXGUAYLSDRHRURZASXUWZSIIEZCPXUVEONKNGNWRYGOSFMCKESMVJZHWWUCHWDQMLASLNNMHAU\r\n'], 'output': ['NO\r\n']}, {'input': ['XLOWVFCZSSXCSYQTIIDKHNTKNKEEDFMDZKXSPVLBIDIREDUAIN\r\nZKIWNDGBISDB\r\nSLPKLYFYSRNRMOSWYLJJDGFFENPOXYLPZFTQDANKBDNZDIIEWSUTTKYBKVICLG\r\n'], 'output': ['NO\r\n']}, {'input': ['PMUKBTRKFIAYVGBKHZHUSJYSSEPEOEWPOSPJLWLOCTUYZODLTUAFCMVKGQKRRUSOMPAYOTBTFPXYAZXLOADDEJBDLYOTXJCJYTHA\r\nTWRRAJLCQJTKOKWCGUH\r\nEWDPNXVCXWCDQCOYKKSOYTFSZTOOPKPRDKFJDETKSRAJRVCPDOBWUGPYRJPUWJYWCBLKOOTUPBESTOFXZHTYLLMCAXDYAEBUTAHM\r\n'], 'output': ['NO\r\n']}, {'input': ['QMIMGQRQDMJDPNFEFXSXQMCHEJKTWCTCVZPUAYICOIRYOWKUSIWXJLHDYWSBOITHTMINXFKBKAWZTXXBJIVYCRWKXNKIYKLDDXL\r\nV\r\nFWACCXBVDOJFIUAVYRALBYJKXXWIIFORRUHKHCXLDBZMXIYJWISFEAWTIQFIZSBXMKNOCQKVKRWDNDAMQSTKYLDNYVTUCGOJXJTW\r\n'], 'output': ['NO\r\n']}, {'input': ['XJXPVOOQODELPPWUISSYVVXRJTYBPDHJNENQEVQNVFIXSESKXVYPVVHPMOSX\r\nLEXOPFPVPSZK\r\nZVXVPYEYOYXVOISVLXPOVHEQVXPNQJIOPFDTXEUNMPEPPHELNXKKWSVSOXSBPSJDPVJVSRFQ\r\n'], 'output': ['YES\r\n']}, {'input': ['OSKFHGYNQLSRFSAHPXKGPXUHXTRBJNAQRBSSWJVEENLJCDDHFXVCUNPZAIVVO\r\nFNUOCXAGRRHNDJAHVVLGGEZQHWARYHENBKHP\r\nUOEFNWVXCUNERLKVTHAGPSHKHDYFPYWZHJKHQLSNFBJHVJANRXCNSDUGVDABGHVAOVHBJZXGRACHRXEGNRPQEAPORQSILNXFS\r\n'], 'output': ['YES\r\n']}, {'input': ['VYXYVVACMLPDHONBUTQFZTRREERBLKUJYKAHZRCTRLRCLOZYWVPBRGDQPFPQIF\r\nFE\r\nRNRPEVDRLYUQFYRZBCQLCYZEABKLRXCJLKVZBVFUEYRATOMDRTHFPGOWQVTIFPPH\r\n'], 'output': ['YES\r\n']}, {'input': ['WYXUZQJQNLASEGLHPMSARWMTTQMQLVAZLGHPIZTRVTCXDXBOLNXZPOFCTEHCXBZ\r\nBLQZRRWP\r\nGIQZXPLTTMNHQVWPPEAPLOCDMBSTHRCFLCQRRZXLVAOQEGZBRUZJXXZTMAWLZHSLWNQTYXB\r\n'], 'output': ['YES\r\n']}, {'input': ['MKVJTSSTDGKPVVDPYSRJJYEVGKBMSIOKHLZQAEWLRIBINVRDAJIBCEITKDHUCCVY\r\nPUJJQFHOGZKTAVNUGKQUHMKTNHCCTI\r\nQVJKUSIGTSVYUMOMLEGHWYKSKQTGATTKBNTKCJKJPCAIRJIRMHKBIZISEGFHVUVQZBDERJCVAKDLNTHUDCHONDCVVJIYPP\r\n'], 'output': ['YES\r\n']}, {'input': ['OKNJOEYVMZXJMLVJHCSPLUCNYGTDASKSGKKCRVIDGEIBEWRVBVRVZZTLMCJLXHJIA\r\nDJBFVRTARTFZOWN\r\nAGHNVUNJVCPLWSVYBJKZSVTFGLELZASLWTIXDDJXCZDICTVIJOTMVEYOVRNMJGRKKHRMEBORAKFCZJBR\r\n'], 'output': ['YES\r\n']}, {'input': ['OQZACLPSAGYDWHFXDFYFRRXWGIEJGSXWUONAFWNFXDTGVNDEWNQPHUXUJNZWWLBPYL\r\nOHBKWRFDRQUAFRCMT\r\nWIQRYXRJQWWRUWCYXNXALKFZGXFTLOODWRDPGURFUFUQOHPWBASZNVWXNCAGHWEHFYESJNFBMNFDDAPLDGT\r\n'], 'output': ['YES\r\n']}, {'input': ['OVIRQRFQOOWVDEPLCJETWQSINIOPLTLXHSQWUYUJNFBMKDNOSHNJQQCDHZOJVPRYVSV\r\nMYYDQKOOYPOOUELCRIT\r\nNZSOTVLJTTVQLFHDQEJONEOUOFOLYVSOIYUDNOSIQVIRMVOERCLMYSHPCQKIDRDOQPCUPQBWWRYYOXJWJQPNKH\r\n'], 'output': ['YES\r\n']}, {'input': ['WGMBZWNMSJXNGDUQUJTCNXDSJJLYRDOPEGPQXYUGBESDLFTJRZDDCAAFGCOCYCQMDBWK\r\nYOBMOVYTUATTFGJLYUQD\r\nDYXVTLQCYFJUNJTUXPUYOPCBCLBWNSDUJRJGWDOJDSQAAMUOJWSYERDYDXYTMTOTMQCGQZDCGNFBALGGDFKZMEBG\r\n'], 'output': ['YES\r\n']}, {'input': ['CWLRBPMEZCXAPUUQFXCUHAQTLPBTXUUKWVXKBHKNSSJFEXLZMXGVFHHVTPYAQYTIKXJJE\r\nMUFOSEUEXEQTOVLGDSCWM\r\nJUKEQCXOXWEHCGKFPBIGMWVJLXUONFXBYTUAXERYTXKCESKLXAEHVPZMMUFTHLXTTZSDMBJLQPEUWCVUHSQQVUASPF\r\n'], 'output': ['YES\r\n']}, {'input': ['IDQRX\r\nWETHO\r\nODPDGBHVUVSSISROHQJTUKPUCLXABIZQQPPBPKOSEWGEHRSRRNBAVLYEMZISMWWGKHVTXKUGUXEFBSWOIWUHRJGMWBMHQLDZHBWA\r\n'], 'output': ['NO\r\n']}, {'input': ['IXFDY\r\nJRMOU\r\nDF\r\n'], 'output': ['NO\r\n']}, {'input': ['JPSPZ\r\nUGCUB\r\nJMZZZZZZZZ\r\n'], 'output': ['NO\r\n']}, {'input': ['AC\r\nA\r\nBBA\r\n'], 'output': ['NO\r\n']}, {'input': ['UIKWWKXLSHTOOZOVGXKYSOJEHAUEEG\r\nKZXQDWJJWRXFHKJDQHJK\r\nXMZHTFOGEXAUJXXJUYVJIFOTKLZHDKELJWERHMGAWGKWAQKEKHIDWGGZVYOHKXRPWSJDPESFJUMKQYWBYUTHQYEFZUGKQOBHYDWB\r\n'], 'output': ['NO\r\n']}, {'input': ['PXWRXRPFLR\r\nPJRWWXIVHODV\r\nXW\r\n'], 'output': ['NO\r\n']}, {'input': ['CHTAZVHGSHCVIBK\r\nEQINEBKXEPYJSAZIMLDF\r\nZCZZZZDZMCZZEZDZZEZZZZQZZBZZZOZZCZE\r\n'], 'output': ['NO\r\n']}, {'input': ['GXPZFSELJJNDAXYRV\r\nUYBKPMVBSOVOJWMONLTJOJCNQKMTAHEWLHOWIIBH\r\nHCWNFWJPEJIWOVPTBMVCRJLSISSVNOHCKLBFMIUAIMASQWPXEYXBOXQGFEMYJLBKDCZIMJNHOJEDGGANIVYKQTUOSOVOPWHVJGXH\r\n'], 'output': ['NO\r\n']}, {'input': ['LFGJCJJDUTUP\r\nOVSBILTIYCJCRHKCIXCETJQJJ\r\nGIJJTJCLTJJJ\r\n'], 'output': ['NO\r\n']}, {'input': ['GIO\r\nPRL\r\nPRL\r\n'], 'output': ['NO\r\n']}, {'input': ['A\r\nB\r\nABC\r\n'], 'output': ['NO\r\n']}, {'input': ['KKK\r\nKKK\r\nZZZZZ\r\n'], 'output': ['NO\r\n']}, {'input': ['ZMYGQLDBLAPN\r\nZFJBKWHROVNPSJQUDFTHOCGREUFLYIWYICD\r\nZMJZZEDAZANKZZZZZZEZZBZDZZZZZZKHZZFZZZDZNZMDZZA\r\n'], 'output': ['NO\r\n']}]


Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types:   replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4);  swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task.

The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 10^5.

Print on the single line the single number — the minimum number of operations needed to convert string a into string b.

In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites.

program P145A;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  fin='';
  fou='';

var
  a,b:string;
  fi,fo:text;
  n:longint;

procedure Enter();
begin
  Assign(fi,fin);Reset(fi);
  Readln(fi,a);
  Readln(fi,b);
  Close(fi);
  n:=length(a);
end;

function  getmax(x,y:longint):longint;
begin
  if (x>y) then result:=x else result:=y;
end;

procedure Solve();
var
  i:longint;
  d1,d2:longint;
begin
  d1:=0;d2:=0;
  for i:=1 to n do
    if (a[i]<>b[i]) then
      if (a[i]='4') then inc(d1)
      else inc(d2);
  Assign(fo,fou);Rewrite(fo);
  Write(fo,getmax(d1,d2));
  Close(fo);
end;

begin
  Enter();
  Solve();
  { TODO -oUser -cConsole Main : Insert code here }
end.


A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.

The first line of the input data contains numbers n and m (1≤n,m≤50), n — amount of lines, and m — amount of columns on Bob's sheet. The following n lines contain m characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square.

Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
	i, j, n, m,
	si, ei, sj, ej: Integer;
	l: array[1..50, 1..50] of Char;

begin
	FillChar(l, sizeof(l), 0);
	Readln(n, m);
	si := n; sj := m;
	ei := 1; ej := 1;
	for i:=1 to n do
	begin
		for j:=1 to m do
		begin
			Read(l[i, j]);
			if l[i, j]='*' then
			begin
				if i>ei then ei := i;
				if i<si then si := i;
				if j>ej then ej := j;
				if j<sj then sj := j;
			end;
		end;
		Readln;
	end;
	for i:=si to ei do
	begin
		for j:=sj to ej do
		begin
			Write(l[i, j]);
		end;
		Writeln;
	end;
end.


This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt.To make a toast, each friend needs nl milliliters of the drink, a slice of lime and np grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?

The first and only line contains positive integers n, k, l, c, d, p, nl, np, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.

Print a single integer — the number of toasts each friend can make.

A comment to the first sample:
Overall the friends have 4*5=20 milliliters of the drink, it is enough to make 20/3=6 toasts. The limes are enough for 10*8=80 toasts and the salt is enough for 100/1=100 toasts. However, there are 3 friends in the group, so the answer is min(6,80,100)/3=2.

uses
  Math;

var
  n, k, l, c, d, p, nl, np: longint;

begin
  read(n, k, l, c, d, p, nl, np);
  write(min((k * l) div nl, min(c * d, p div np)) div n);
end.


You are given a tetrahedron. Let's mark its vertices with letters A, B, C and D correspondingly. An ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex D to itself in exactly n steps. In other words, you are asked to find out the number of different cyclic paths with the length of n from vertex D to itself. As the number can be quite large, you should print it modulo 1000000007 (10^9+7).

The first line contains the only integer n (1≤n≤10^7) — the required length of the cyclic path.

Print the only integer — the required number of ways modulo 1000000007 (10^9+7).

The required paths in the first sample are:
  D-A-D  D-B-D  D-C-D

const m:longint= 1000000007;
var newd,newabc,d,abc,n:int64;
    i:longint;
begin
 read(n);
 D:=0;
 ABC:=1;
 for i:=2 to n do
  begin
   NewABC:=(ABC*2+D) mod M;
   NewD:=(ABC*3) mod M;
   ABC:=NewABC;
   D:=NewD;
  end;
 write(D);

end.


According to a new ISO standard, a flag of every country should have a chequered field n×m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.

The first line of the input contains numbers n and m (1≤n,m≤100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.

Output YES, if the flag meets the new ISO standard, and NO otherwise.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
	n, m, i, j: Integer;
	l, h: Char;
	OK: Boolean;
	flag: array[1..100, 1..100] of Char;

begin
	Readln(n, m);
	FillChar(flag, sizeof(flag), 0);
	OK := true;
	for i:=1 to n do
	begin
		for j:=1 to m do Read(flag[i, j]);
		Readln;
	end;
	l := flag[1, 1];
	for i:= 1 to n do
	begin
		h := flag[i, 1];
		for j:=2 to m do
		begin
			if flag[i, j]<>h then
			begin
				Writeln('NO');
				Exit;
			end;
		end;
		if i=1 then continue;
		if h=l then
		begin
			OK := false;
			break;
		end;
		l := h;
	end;

	if OK then Writeln('YES')
	else Writeln('NO');
end.


The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n×n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:    Elements of the main diagonal.   Elements of the secondary diagonal.   Elements of the "middle" row — the row which has exactly  rows above it and the same number of rows below it.   Elements of the "middle" column — the column that has exactly  columns to the left of it and the same number of columns to the right of it.    The figure shows a 5×5 matrix.   The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix.

The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0≤aij≤100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
  1≤n≤5 The input limitations for getting 100 points are:
  1≤n≤101

Print a single integer — the sum of good matrix elements.

In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.

program codeforces;

{$APPTYPE CONSOLE}
{$R+ Q+ I+}

uses
  SysUtils;

var
  i,j,k,n: integer;
  a: array[1..101,1..101]of integer;
  b: array[1..101,1..101]of boolean;
  sum: int64;
begin
  read(n);
  for i:=1 to n do
    for j:=1 to n do
      read(a[i][j]);
  for i:=1 to n do b[i][i]:=true;
  for i:=1 to n do b[n div 2 +1][i]:=true;
  for i:=1 to n do b[i][n div 2 +1]:=true;
  k:=n;
  for i:=1 to n do begin
    b[k][i]:=true;
    dec(k);
  end;
  sum:=0;
  for i:=1 to n do
    for j:=1 to n do
      if b[i][j] then sum:=sum+a[i][j];
  write(sum);
end.


Theatre Square in the capital city of Berland has a rectangular shape with the size n×m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a×a.What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

The input contains three positive integer numbers in the first line: n,m and a (1≤n,m,a≤10^9).

program TestMath;

uses
  Math, SysUtils, Variants;

function AddNumStrings (Str1, Str2 : string): string;
var
  i : integer;
  carryStr : string;
  worker : integer;
  workerStr : string;
begin
  Result := inttostr (length(Str1));
  Result := '';
  carryStr := '0';

  // make numbers the same length
  while length(Str1) < length(Str2) do
    Str1 := '0' + Str1;

  while length(Str1) > length(Str2) do
    Str2 := '0' + Str2;

  i := 0;
  while i < length(Str1) do
  begin
    worker := strtoint(copy(Str1, length(str1)-i, 1)) +
              strtoint(copy(Str2, length(str2)-i, 1)) +
              strtoint (carryStr);
    if worker > 9 then
    begin
      workerStr := inttostr(worker);
      carryStr := copy(workerStr, 1, 1);
      result := copy(workerStr, 2, 1) + result;
    end
    else
    begin
      result := inttostr(worker) + result;
      carryStr := '0';
    end;

    inc(i);
  end; { while }
  if carryStr <> '0' then
    result := carryStr + result;
end;

function MultiplyNumStrings (Str1, Str2 : string): string;
var
  i, j : integer;
  carryStr : string;
  worker : integer;
  workerStr : string;
  tempResult : string;
begin
  Result := '';
  carryStr := '0';
  tempResult := '';

  // process each digit of str1
  for i := 0 to length(Str1) - 1 do
  begin
    while length(tempResult) < i do
      tempResult := '0' + tempResult;

    // process each digit of str2
    for j := 0 to length(Str2) - 1 do
    begin
      worker := (strtoint(copy(Str1, length(str1)-i, 1)) *
                 strtoint(copy(Str2, length(str2)-j, 1))) +
                strtoint (carryStr);
      if worker > 9 then
      begin
        workerStr := inttostr(worker);
        carryStr := copy(workerStr, 1, 1);
        tempResult := copy(workerStr, 2, 1) + tempResult;
      end
      else
      begin
        tempResult := inttostr(worker) + tempResult;
        carryStr := '0';
      end;
    end; { for }
    if carryStr <> '0' then
      tempResult := carryStr + tempResult;
    carryStr := '0';

    result := addNumStrings (tempResult, Result);
    tempResult := '';
  end; { for }

  if carryStr <> '0' then
    result := carryStr + result;
end;

var
  n, m, a: Int64;
begin
     readln(n, m, a);
     writeln(MultiplyNumStrings(VarToStr(Math.Ceil(n / a)), VarToStr(Math.Ceil(m / a))));
end.


This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1 ≤ p1<p2<...<pk ≤ |s|) a subsequence of string s = s1s2... s|s|, where |s| is the length of string s. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y| if either |x| > |y| and x1=y1, x2=y2, ...,x|y|=y|y|, or there exists such number r (r<|x|, r<|y|) that x1=y1, x2=y2, ..., xr=yr and xr+1>yr+1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".String s = s1s2... s|s| is a palindrome if it matches string rev(s) = s|s|s|s|-1... s1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".

The only input line contains a non-empty string s consisting of lowercase English letters only. Its length does not exceed 10.

Print the lexicographically largest palindromic subsequence of string s.

Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".

{$R+}
Uses SysUtils, Math;
var s: string;
    i, j: integer;
    c: char;
begin
{assign(input,'input.txt');reset(input);
assign(output,'output.txt');rewrite(output); }
read(s);
c := chr(1);
for I := 1 to length(s) do
if ord(s[i]) > ord(c) then c := s[i];

for I := 1 to length(s) do
  if s[i] = c then write(s[i]);

end.

[{'input': ['radar\r\n'], 'output': ['rr\r\n']}, {'input': ['bowwowwow\r\n'], 'output': ['wwwww\r\n']}, {'input': ['codeforces\r\n'], 'output': ['s\r\n']}, {'input': ['mississipp\r\n'], 'output': ['ssss\r\n']}, {'input': ['tourist\r\n'], 'output': ['u\r\n']}, {'input': ['romka\r\n'], 'output': ['r\r\n']}, {'input': ['helloworld\r\n'], 'output': ['w\r\n']}, {'input': ['zzzzzzzazz\r\n'], 'output': ['zzzzzzzzz\r\n']}, {'input': ['testcase\r\n'], 'output': ['tt\r\n']}, {'input': ['hahahahaha\r\n'], 'output': ['hhhhh\r\n']}, {'input': ['abbbbbbbbb\r\n'], 'output': ['bbbbbbbbb\r\n']}, {'input': ['zaz\r\n'], 'output': ['zz\r\n']}, {'input': ['aza\r\n'], 'output': ['z\r\n']}, {'input': ['dcbaedcba\r\n'], 'output': ['e\r\n']}, {'input': ['abcdeabcd\r\n'], 'output': ['e\r\n']}, {'input': ['edcbabcde\r\n'], 'output': ['ee\r\n']}, {'input': ['aaaaaaaaab\r\n'], 'output': ['b\r\n']}, {'input': ['testzzzzzz\r\n'], 'output': ['zzzzzz\r\n']}, {'input': ['zzzzzzwait\r\n'], 'output': ['zzzzzz\r\n']}, {'input': ['rrrrrqponm\r\n'], 'output': ['rrrrr\r\n']}, {'input': ['zzyzyy\r\n'], 'output': ['zzz\r\n']}, {'input': ['aababb\r\n'], 'output': ['bbb\r\n']}, {'input': ['zanzibar\r\n'], 'output': ['zz\r\n']}, {'input': ['hhgfedcbaa\r\n'], 'output': ['hh\r\n']}, {'input': ['aabcdefghh\r\n'], 'output': ['hh\r\n']}, {'input': ['aruaru\r\n'], 'output': ['uu\r\n']}, {'input': ['uraura\r\n'], 'output': ['uu\r\n']}, {'input': ['aru\r\n'], 'output': ['u\r\n']}, {'input': ['aburvabur\r\n'], 'output': ['v\r\n']}, {'input': ['ura\r\n'], 'output': ['u\r\n']}, {'input': ['eurottat\r\n'], 'output': ['u\r\n']}, {'input': ['referee\r\n'], 'output': ['rr\r\n']}, {'input': ['joking\r\n'], 'output': ['o\r\n']}, {'input': ['seriously\r\n'], 'output': ['y\r\n']}, {'input': ['sets\r\n'], 'output': ['t\r\n']}, {'input': ['test\r\n'], 'output': ['tt\r\n']}, {'input': ['klmgameklm\r\n'], 'output': ['mmm\r\n']}, {'input': ['dfkjafdkdd\r\n'], 'output': ['kk\r\n']}, {'input': ['zzzzzzzzzz\r\n'], 'output': ['zzzzzzzzzz\r\n']}, {'input': ['aaaaaaaaaa\r\n'], 'output': ['aaaaaaaaaa\r\n']}, {'input': ['buzz\r\n'], 'output': ['zz\r\n']}, {'input': ['b\r\n'], 'output': ['b\r\n']}, {'input': ['y\r\n'], 'output': ['y\r\n']}, {'input': ['yy\r\n'], 'output': ['yy\r\n']}, {'input': ['zz\r\n'], 'output': ['zz\r\n']}, {'input': ['bb\r\n'], 'output': ['bb\r\n']}, {'input': ['aa\r\n'], 'output': ['aa\r\n']}, {'input': ['a\r\n'], 'output': ['a\r\n']}, {'input': ['z\r\n'], 'output': ['z\r\n']}, {'input': ['zz\r\n'], 'output': ['zz\r\n']}, {'input': ['zzazazzzaz\r\n'], 'output': ['zzzzzzz\r\n']}, {'input': ['hellhellhe\r\n'], 'output': ['llll\r\n']}, {'input': ['hellohello\r\n'], 'output': ['oo\r\n']}, {'input': ['refer\r\n'], 'output': ['rr\r\n']}]


A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as x points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result.He knows that the contest number 300 was unusual because there were only two problems. The contest lasted for t minutes, the minutes are numbered starting from zero. The first problem had the initial cost of a points, and every minute its cost reduced by da points. The second problem had the initial cost of b points, and every minute this cost reduced by db points. Thus, as soon as the zero minute of the contest is over, the first problem will cost a-da points, and the second problem will cost b-db points. It is guaranteed that at any moment of the contest each problem has a non-negative cost.Arkady asks you to find out whether Valera could have got exactly x points for this contest. You should assume that Valera could have solved any number of the offered problems. You should also assume that for each problem Valera made no more than one attempt, besides, he could have submitted both problems at the same minute of the contest, starting with minute 0 and ending with minute number t-1. Please note that Valera can't submit a solution exactly t minutes after the start of the contest or later.

The single line of the input contains six integers x,t,a,b,da,db (0≤x≤600; 1≤t,a,b,da,db≤300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first and the second problem lose per minute, correspondingly.
It is guaranteed that at each minute of the contest each problem has a non-negative cost, that is, a-i·da≥0 and b-i·db≥0 for all 0≤i≤t-1.

If Valera could have earned exactly x points at a contest, print "YES", otherwise print "NO" (without the quotes).

In the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points.

{$apptype console}
{$I+,R+,Q+}
Uses SysUtils;

Var
  x,t,a,b,a1,b1:integer;
  i,j,z,f:integer;
Begin
  readln(x,t,a,b,a1,b1);
  if x=0 then begin
    writeln('YES');
    exit;
  end;
  for i:=0 to t-1 do begin
    z:=x-a+a1*i;
    if z=0 then begin
      writeln('YES');
      exit;
    end;
    for j:=0 to t-1 do begin
      if z<0 then break;
      f:=z-b+b1*j;
      if f=0 then begin
        writeln('YES');
        exit;
      end;
    end;
  end;
  for i:=0 to t-1 do begin
    z:=x-b+b1*i;
    if z=0 then begin
      writeln('YES');
      exit;
    end;
  end;
  writeln('NO');
End.


One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.He took a checkered white square piece of paper, consisting of n×n cells. After that, he started to paint the white cells black one after the other. In total he painted m different cells on the piece of paper. Since Valera was keen on everything square, he wondered, how many moves (i.e. times the boy paints a square black) he should make till a black square with side 3 can be found on the piece of paper. But Valera does not know the answer to this question, so he asks you to help him.Your task is to find the minimum number of moves, till the checkered piece of paper has at least one black square with side of 3. Otherwise determine that such move does not exist.

The first line contains two integers n and m (1≤n≤1000, 1≤m≤min(n·n,10^5)) — the size of the squared piece of paper and the number of moves, correspondingly.
Then, m lines contain the description of the moves. The i-th line contains two integers xi, yi (1≤xi,yi≤n) — the number of row and column of the square that gets painted on the i-th move.
All numbers on the lines are separated by single spaces. It is guaranteed that all moves are different. The moves are numbered starting from 1 in the order, in which they are given in the input. The columns of the squared piece of paper are numbered starting from 1, from the left to the right. The rows of the squared piece of paper are numbered starting from 1, from top to bottom.

On a single line print the answer to the problem — the minimum number of the move after which the piece of paper has a black square with side 3. If no such move exists, print -1.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
   var
   a,b:array[0..1001,0..1001] of integer;
   n,m,ans,i,x,y:integer;
begin
  readln(n,m);
  fillchar(a,sizeof(a),0);
  fillchar(b,sizeof(b),0);
  ans:=-1;
   for i:=1 to m do
   begin
     readln(x,y);
     if (ans<>-1) then continue;
     b[x,y]:=1;
     a[x,y]:=1;
     inc(a[x,y],b[x-1,y-1]);
     inc(a[x,y],b[x-1,y]);
     inc(a[x,y],b[x-1,y+1]);
     inc(a[x,y],b[x,y-1]);
     inc(a[x,y],b[x,y+1]);
     inc(a[x,y],b[x+1,y-1]);
     inc(a[x,y],b[x+1,y]);
     inc(a[x,y],b[x+1,y+1]);

     inc(a[x-1,y-1]);
     inc(a[x-1,y]);
     inc(a[x-1,y+1]);
     inc(a[x,y-1]);
     inc(a[x,y+1]);
     inc(a[x+1,y-1]);
     inc(a[x+1,y]);
     inc(a[x+1,y+1]);
     if (ans<>-1) then continue;
     if (a[x,y]=9)or(a[x-1,y-1]=9)or(a[x-1,y]=9)or(a[x-1,y+1]=9)or(a[x,y-1]=9)or(a[x,y+1]=9)or(a[x+1,y-1]=9)or(a[x+1,y]=9)or(a[x+1,y+1]=9)
     then ans:=i;
   end;
   writeln(ans);

end.


The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.

The first line contains a single integer n (1≤n≤10^5) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 10^9.
You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities.

Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).

In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".

{$APPTYPE CONSOLE}
{$O-}

uses
  SysUtils,
  Math;

var
  a: array[1..100500] of integer;
  n, i, k, mn, c: integer;

begin
  //reset(input, 'input.txt');
  //rewrite(output, 'output.txt');
  read(n);
  mn := maxint;
  for i := 1 to n do begin
    read(a[i]);
    if a[i] < mn then begin
      mn := a[i];
      k := i;
    end;
  end;
  c := 0;
  for i := 1 to n do
    if a[i] = mn then
      inc(c);
  if c > 1 then
    write('Still Rozdil')
  else
    write(k);
end.


Let's consider equation:x^2+s(x)·x-n=0, where x,n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots.

A single line contains integer n (1≤n≤10^18) — the equation parameter.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x>0), that the equation given in the statement holds.

In the first test case x=1 is the minimum root. As s(1)=1 and 1^2+1·1-2=0.
In the second test case x=10 is the minimum root. As s(10)=1+0=1 and 10^2+1·10-110=0.
In the third test case the equation has no roots.

uses math;
var n:int64;a,b,r,res,c,z,j,max1,l1,e,x4:int64;k,x3,y3,x1,y1,x2,y2,x,y:extended;i:integer;
function check(x,i:int64):boolean;
var b:int64;
Begin
    b:=0;
    while x>0 do
       Begin
          inc(b,x mod 10);
          x:=x div 10;
       end;
    if b=i
    then check:=true
    else check:=false;
end;
begin
//  assign(input,'input.txt');
//  assign(output,'output.txt');
  readln(n);
  res:=100000000000000;
  for i:=1 to 90 do
     Begin
        if i*i+4*n>0
        then Begin
                x:=i*i+4*n;
                if abs(sqrt(x)-round(sqrt(x)))>0.0000000001
                then continue;
                if check(round((-i+round(sqrt(x)))/2),i)
                then res:=min(res,round((-i+sqrt(x))/2));
                if check(round((-i-round(sqrt(x)))/2),i)
                then res:=min(res,round((-i-sqrt(x))/2));
             end;
     end;
  if res<>100000000000000
  then writeln(res)
  else writeln(-1);
end.


The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.

The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.

If the word t is a word s, written reversely, print YES, otherwise print NO.

program A41;

{$APPTYPE CONSOLE}

uses
  SysUtils;
  var s, p:string;
  i, c:integer;
begin
  readln(s);
  readln(p);
  c:=0;
  for i:=1 to length(s) do if (s[i] <> p[length(s) - i + 1]) then c:=1;
  if c = 0 then writeln('YES')
  else writeln('NO');
end.

[{'input': ['code\r\nedoc\r\n'], 'output': ['YES\r\n']}, {'input': ['abb\r\naba\r\n'], 'output': ['NO\r\n']}, {'input': ['code\r\ncode\r\n'], 'output': ['NO\r\n']}, {'input': ['abacaba\r\nabacaba\r\n'], 'output': ['YES\r\n']}, {'input': ['q\r\nq\r\n'], 'output': ['YES\r\n']}, {'input': ['asrgdfngfnmfgnhweratgjkk\r\nasrgdfngfnmfgnhweratgjkk\r\n'], 'output': ['NO\r\n']}, {'input': ['z\r\na\r\n'], 'output': ['NO\r\n']}, {'input': ['asd\r\ndsa\r\n'], 'output': ['YES\r\n']}, {'input': ['abcdef\r\nfecdba\r\n'], 'output': ['NO\r\n']}, {'input': ['ywjjbirapvskozubvxoemscfwl\r\ngnduubaogtfaiowjizlvjcu\r\n'], 'output': ['NO\r\n']}, {'input': ['mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\r\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf\r\n'], 'output': ['NO\r\n']}, {'input': ['bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\r\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp\r\n'], 'output': ['NO\r\n']}, {'input': ['pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\r\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb\r\n'], 'output': ['NO\r\n']}, {'input': ['gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\r\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom\r\n'], 'output': ['NO\r\n']}, {'input': ['umeszdawsvgkjhlqwzents\r\nhxqhdungbylhnikwviuh\r\n'], 'output': ['NO\r\n']}, {'input': ['juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\r\nibqvffmfktyipgiopznsqtrtxiijntdbgyy\r\n'], 'output': ['NO\r\n']}, {'input': ['zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\r\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko\r\n'], 'output': ['NO\r\n']}, {'input': ['nkgwuugukzcv\r\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv\r\n'], 'output': ['NO\r\n']}, {'input': ['incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\r\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd\r\n'], 'output': ['NO\r\n']}, {'input': ['w\r\nw\r\n'], 'output': ['YES\r\n']}, {'input': ['vz\r\nzv\r\n'], 'output': ['YES\r\n']}, {'input': ['ry\r\nyr\r\n'], 'output': ['YES\r\n']}, {'input': ['xou\r\nuox\r\n'], 'output': ['YES\r\n']}, {'input': ['axg\r\ngax\r\n'], 'output': ['NO\r\n']}, {'input': ['zdsl\r\nlsdz\r\n'], 'output': ['YES\r\n']}, {'input': ['kudl\r\nldku\r\n'], 'output': ['NO\r\n']}, {'input': ['zzlzwnqlcl\r\nlclqnwzlzz\r\n'], 'output': ['YES\r\n']}, {'input': ['vzzgicnzqooejpjzads\r\nsdazjpjeooqzncigzzv\r\n'], 'output': ['YES\r\n']}, {'input': ['raqhmvmzuwaykjpyxsykr\r\nxkysrypjkyawuzmvmhqar\r\n'], 'output': ['NO\r\n']}, {'input': ['ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\r\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn\r\n'], 'output': ['YES\r\n']}, {'input': ['muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\r\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum\r\n'], 'output': ['YES\r\n']}, {'input': ['vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\r\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv\r\n'], 'output': ['YES\r\n']}, {'input': ['mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\r\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm\r\n'], 'output': ['NO\r\n']}, {'input': ['dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\r\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd\r\n'], 'output': ['NO\r\n']}, {'input': ['gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\r\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg\r\n'], 'output': ['YES\r\n']}, {'input': ['sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\r\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis\r\n'], 'output': ['YES\r\n']}, {'input': ['ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\r\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy\r\n'], 'output': ['NO\r\n']}, {'input': ['wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\r\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw\r\n'], 'output': ['YES\r\n']}, {'input': ['imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\r\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi\r\n'], 'output': ['YES\r\n']}, {'input': ['bikydffiuisckpvzqlteqfhegsagimodb\r\nbdomigasgehfqetlqzvpkcsiuiffdykib\r\n'], 'output': ['YES\r\n']}]


One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.

The first line contains an integer n (1≤n≤100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.

Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.

var s:array[0..1000]of string;
i,j,k,n,r,res:longint;
begin
readln(n);
for i:=1 to n do readln(s[i]);
for i:=1 to n do
for j:=i+1 to n do
if s[i]>s[j] then begin s[0]:=s[i]; s[i]:=s[j]; s[j]:=s[0]; end;
for i:=1 to n do
for j:=i to n do
if s[i]=s[j] then begin k:=j-i+1; if res<k then begin res:=k; r:=i; end; end;
writeln(s[r]);
end.

[{'input': ['1\r\nABC\r\n'], 'output': ['ABC\r\n']}, {'input': ['5\r\nA\r\nABA\r\nABA\r\nA\r\nA\r\n'], 'output': ['A\r\n']}, {'input': ['2\r\nXTSJEP\r\nXTSJEP\r\n'], 'output': ['XTSJEP\r\n']}, {'input': ['3\r\nXZYDJAEDZ\r\nXZYDJAEDZ\r\nXZYDJAEDZ\r\n'], 'output': ['XZYDJAEDZ\r\n']}, {'input': ['3\r\nQCCYXL\r\nQCCYXL\r\nAXGLFQDD\r\n'], 'output': ['QCCYXL\r\n']}, {'input': ['3\r\nAZID\r\nEERWBC\r\nEERWBC\r\n'], 'output': ['EERWBC\r\n']}, {'input': ['3\r\nHNCGYL\r\nHNCGYL\r\nHNCGYL\r\n'], 'output': ['HNCGYL\r\n']}, {'input': ['4\r\nZZWZTG\r\nZZWZTG\r\nZZWZTG\r\nZZWZTG\r\n'], 'output': ['ZZWZTG\r\n']}, {'input': ['4\r\nA\r\nA\r\nKUDLJMXCSE\r\nA\r\n'], 'output': ['A\r\n']}, {'input': ['5\r\nPHBTW\r\nPHBTW\r\nPHBTW\r\nPHBTW\r\nPHBTW\r\n'], 'output': ['PHBTW\r\n']}, {'input': ['5\r\nPKUZYTFYWN\r\nPKUZYTFYWN\r\nSTC\r\nPKUZYTFYWN\r\nPKUZYTFYWN\r\n'], 'output': ['PKUZYTFYWN\r\n']}, {'input': ['5\r\nHH\r\nHH\r\nNTQWPA\r\nNTQWPA\r\nHH\r\n'], 'output': ['HH\r\n']}, {'input': ['10\r\nW\r\nW\r\nW\r\nW\r\nW\r\nD\r\nW\r\nD\r\nD\r\nW\r\n'], 'output': ['W\r\n']}, {'input': ['19\r\nXBCP\r\nTGACNIH\r\nXBCP\r\nXBCP\r\nXBCP\r\nXBCP\r\nXBCP\r\nTGACNIH\r\nXBCP\r\nXBCP\r\nXBCP\r\nXBCP\r\nXBCP\r\nTGACNIH\r\nXBCP\r\nXBCP\r\nTGACNIH\r\nTGACNIH\r\nXBCP\r\n'], 'output': ['XBCP\r\n']}, {'input': ['33\r\nOWQWCKLLF\r\nOWQWCKLLF\r\nOWQWCKLLF\r\nPYPAS\r\nPYPAS\r\nPYPAS\r\nOWQWCKLLF\r\nPYPAS\r\nOWQWCKLLF\r\nPYPAS\r\nPYPAS\r\nOWQWCKLLF\r\nOWQWCKLLF\r\nOWQWCKLLF\r\nPYPAS\r\nOWQWCKLLF\r\nPYPAS\r\nPYPAS\r\nPYPAS\r\nPYPAS\r\nOWQWCKLLF\r\nPYPAS\r\nPYPAS\r\nOWQWCKLLF\r\nOWQWCKLLF\r\nPYPAS\r\nOWQWCKLLF\r\nOWQWCKLLF\r\nPYPAS\r\nPYPAS\r\nOWQWCKLLF\r\nPYPAS\r\nPYPAS\r\n'], 'output': ['PYPAS\r\n']}, {'input': ['51\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\nNC\r\n'], 'output': ['NC\r\n']}, {'input': ['89\r\nH\r\nVOCI\r\nVOCI\r\nH\r\nVOCI\r\nH\r\nH\r\nVOCI\r\nVOCI\r\nVOCI\r\nH\r\nH\r\nH\r\nVOCI\r\nVOCI\r\nVOCI\r\nH\r\nVOCI\r\nVOCI\r\nH\r\nVOCI\r\nVOCI\r\nVOCI\r\nH\r\nVOCI\r\nH\r\nVOCI\r\nH\r\nVOCI\r\nH\r\nVOCI\r\nVOCI\r\nH\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nH\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nH\r\nVOCI\r\nH\r\nH\r\nVOCI\r\nH\r\nVOCI\r\nH\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nH\r\nH\r\nVOCI\r\nH\r\nH\r\nVOCI\r\nH\r\nVOCI\r\nH\r\nVOCI\r\nVOCI\r\nH\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nVOCI\r\nH\r\nH\r\nH\r\nH\r\nH\r\nVOCI\r\nH\r\nVOCI\r\nH\r\nVOCI\r\nVOCI\r\n'], 'output': ['VOCI\r\n']}, {'input': ['100\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nM\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\nHA\r\n'], 'output': ['HA\r\n']}, {'input': ['100\r\nG\r\nG\r\nS\r\nS\r\nG\r\nG\r\nS\r\nS\r\nG\r\nS\r\nS\r\nS\r\nG\r\nS\r\nG\r\nG\r\nS\r\nG\r\nS\r\nS\r\nG\r\nS\r\nS\r\nS\r\nS\r\nS\r\nG\r\nS\r\nG\r\nS\r\nS\r\nG\r\nG\r\nG\r\nS\r\nS\r\nS\r\nS\r\nG\r\nS\r\nS\r\nG\r\nG\r\nG\r\nG\r\nG\r\nS\r\nG\r\nG\r\nS\r\nS\r\nS\r\nS\r\nS\r\nG\r\nG\r\nS\r\nG\r\nG\r\nG\r\nG\r\nG\r\nS\r\nS\r\nG\r\nS\r\nS\r\nS\r\nS\r\nG\r\nS\r\nS\r\nG\r\nS\r\nG\r\nG\r\nG\r\nG\r\nG\r\nG\r\nG\r\nG\r\nG\r\nG\r\nG\r\nS\r\nS\r\nG\r\nS\r\nS\r\nS\r\nS\r\nG\r\nG\r\nG\r\nS\r\nG\r\nG\r\nG\r\nS\r\n'], 'output': ['G\r\n']}, {'input': ['100\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nOBH\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\nWL\r\n'], 'output': ['WL\r\n']}]


Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.

The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.

Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.

program Word;

uses
  SysUtils;

var
  s: String;
  i, capTotal, sLength: integer;
begin
  Readln(s);
  capTotal := 0;
  sLength := Length(s);
  for i := 1 to sLength do
  begin
    if s[i] in ['A'..'Z'] then
       Inc(capTotal);
  end;
  if capTotal > sLength - capTotal then
     writeln(UpperCase(s))
  else
      writeln(LowerCase(s));
end.

[{'input': ['HoUse\r\n'], 'output': ['house\r\n']}, {'input': ['ViP\r\n'], 'output': ['VIP\r\n']}, {'input': ['maTRIx\r\n'], 'output': ['matrix\r\n']}, {'input': ['BNHWpnpawg\r\n'], 'output': ['bnhwpnpawg\r\n']}, {'input': ['VTYGP\r\n'], 'output': ['VTYGP\r\n']}, {'input': ['CHNenu\r\n'], 'output': ['chnenu\r\n']}, {'input': ['ERPZGrodyu\r\n'], 'output': ['erpzgrodyu\r\n']}, {'input': ['KSXBXWpebh\r\n'], 'output': ['KSXBXWPEBH\r\n']}, {'input': ['qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv\r\n'], 'output': ['qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv\r\n']}, {'input': ['Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd\r\n'], 'output': ['amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd\r\n']}, {'input': ['ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv\r\n'], 'output': ['isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv\r\n']}, {'input': ['XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg\r\n'], 'output': ['xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg\r\n']}, {'input': ['RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak\r\n'], 'output': ['RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK\r\n']}, {'input': ['DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw\r\n'], 'output': ['DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW\r\n']}, {'input': ['NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB\r\n'], 'output': ['NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB\r\n']}, {'input': ['igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge\r\n'], 'output': ['igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge\r\n']}, {'input': ['Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw\r\n'], 'output': ['ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw\r\n']}, {'input': ['YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks\r\n'], 'output': ['yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks\r\n']}, {'input': ['CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz\r\n'], 'output': ['CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ\r\n']}, {'input': ['WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg\r\n'], 'output': ['WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG\r\n']}, {'input': ['VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO\r\n'], 'output': ['VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO\r\n']}, {'input': ['EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd\r\n'], 'output': ['EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD\r\n']}, {'input': ['EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas\r\n'], 'output': ['ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas\r\n']}, {'input': ['AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm\r\n'], 'output': ['AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM\r\n']}, {'input': ['DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn\r\n'], 'output': ['dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn\r\n']}, {'input': ['t\r\n'], 'output': ['t\r\n']}, {'input': ['N\r\n'], 'output': ['N\r\n']}, {'input': ['kv\r\n'], 'output': ['kv\r\n']}, {'input': ['Ur\r\n'], 'output': ['ur\r\n']}, {'input': ['CN\r\n'], 'output': ['CN\r\n']}]


Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:  Include a person to the chat ('Add' command).  Remove a person from the chat ('Remove' command).  Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.

Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
  +<name> for 'Add' command.  -<name> for 'Remove' command.  <sender_name>:<message_text> for 'Send' command. <name> and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can't start or end with a space. <message_text> can be an empty line.
It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc.
All names are case-sensitive.

Print a single number — answer to the problem.

+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate

+Mike
-Mike
+Mike
Mike:Hi   I am here
-Mike
+Kate
-Kate

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
	line: string;
	p, cnt, traffic: Integer;
	member: array[1..101] of string;

procedure	Add(name: string);
begin
	Inc(cnt);
	member[cnt] := name;
end;
procedure	Remove(name: string);
var
	i: Integer;
begin
	i := 1;
	while i<=cnt do
	begin
		if member[i]=name then
		begin
			while i<cnt do
			begin
				member[i] := member[i+1];
				Inc(i);
			end;
			member[i] := '';
			Dec(cnt);
			break;
		end;
		Inc(i);
	end;
end;

begin
	cnt := 0;
	traffic := 0;
	while not EOF do
	begin
		Readln(line);
		if line='' then break;
		if line[1]='+' then
		begin
			Delete(line, 1, 1);
			Add(line);
		end
		else if line[1]='-' then
		begin
			Delete(line, 1, 1);
			Remove(line);
		end
		else begin
			p := Pos(':', line);
			Inc(traffic, cnt*(Length(line)-p));
		end;
	end;
	Writeln(traffic);
end.

[{'input': ['+Mike\r\nMike:hello\r\n+Kate\r\n+Dmitry\r\n-Dmitry\r\nKate:hi\r\n-Kate\r\n'], 'output': ['9\r\n']}, {'input': ['+Mike\r\n-Mike\r\n+Mike\r\nMike:Hi   I am here\r\n-Mike\r\n+Kate\r\n-Kate\r\n'], 'output': ['14\r\n']}, {'input': ['+Dmitry\r\n+Mike\r\nDmitry:All letters will be used\r\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM\r\nDmitry:And digits too\r\nDmitry:1234567890 0987654321\r\n-Dmitry\r\n'], 'output': ['224\r\n']}, {'input': ['+Dmitry\r\n+Mike\r\n+Kate\r\nDmitry:\r\n'], 'output': ['0\r\n']}, {'input': ['+Dmitry\r\nDmitry:No phrases with spaces at the beginning and at the end\r\n+Mike\r\nDmitry:spaces    spaces\r\n-Dmitry\r\n'], 'output': ['86\r\n']}, {'input': ['+XqD\r\n+aT537\r\nXqD:x6ZPjMR1DDKG2\r\nXqD:lLCriywPnB\r\n-XqD\r\n'], 'output': ['46\r\n']}, {'input': ['+8UjgAJ\r\n8UjgAJ:02hR7UBc1tqqfL\r\n-8UjgAJ\r\n+zdi\r\n-zdi\r\n'], 'output': ['14\r\n']}, {'input': ['+6JPKkgXDrA\r\n+j6JHjv70An\r\n+QGtsceK0zJ\r\n6JPKkgXDrA:o4\r\n+CSmwi9zDra\r\nQGtsceK0zJ:Zl\r\nQGtsceK0zJ:0\r\nj6JHjv70An:7\r\nj6JHjv70An:B\r\nQGtsceK0zJ:OO\r\n'], 'output': ['34\r\n']}, {'input': ['+1aLNq9S7uLV\r\n-1aLNq9S7uLV\r\n+O9ykq3xDJv\r\n-O9ykq3xDJv\r\n+54Yq1xJq14F\r\n+0zJ5Vo0RDZ\r\n-54Yq1xJq14F\r\n-0zJ5Vo0RDZ\r\n+lxlH7sdolyL\r\n-lxlH7sdolyL\r\n'], 'output': ['0\r\n']}, {'input': ['+qlHEc2AuYy\r\nqlHEc2AuYy:YYRwD0 edNZgpE nGfOguRWnMYpTpGUVM aXDKGXo1Gv1tHL9\r\nqlHEc2AuYy:yvh3GsPcImqrvoUcBNQcP6ezwpU0 xAVltaKZp94VKiNao\r\nqlHEc2AuYy:zuCO6Opey L  eu7lTwysaSk00zjpv zrDfbt8l  hpHfu\r\n+pErDMxgVgh\r\nqlHEc2AuYy:I1FLis  mmQbZtd8Ui7y 1vcax6yZBMhVRdD6Ahlq7MNCw\r\nqlHEc2AuYy:lz MFUNJZhlqBYckHUDlNhLiEkmecRh1o0t7alXBvCRVEFVx\r\npErDMxgVgh:jCyMbu1dkuEj5TzbBOjyUhpfC50cL8R900Je3R KxRgAI dT\r\nqlHEc2AuYy:62b47eabo2hf vSUD7KioN ZHki6WB6gh3u GKv5rgwyfF\r\npErDMxgVgh:zD5 9 ympl4wR gy7a7eAGAn5xVdGP9FbL6hRCZAR6O4pT6zb\r\n'], 'output': ['615\r\n']}, {'input': ['+adabacaba0\r\n'], 'output': ['0\r\n']}, {'input': ['+acabadab\r\n+caba0aba\r\n'], 'output': ['0\r\n']}, {'input': ['+dabaca\r\n-dabaca\r\n+aba0ab\r\n'], 'output': ['0\r\n']}, {'input': ['+cab\r\n+abac\r\n-abac\r\n+baca\r\n'], 'output': ['0\r\n']}, {'input': ['+cabadabac\r\n-cabadabac\r\n+abacaba1ab\r\n-abacaba1ab\r\n+ba0abaca\r\n'], 'output': ['0\r\n']}, {'input': ['+adabacaba\r\n-adabacaba\r\n+aca\r\naca:caba\r\n-aca\r\n+bacaba\r\n-bacaba\r\n+aba\r\n-aba\r\n+bad\r\n'], 'output': ['4\r\n']}, {'input': ['+acabadab\r\n-acabadab\r\n+aba0abacab\r\n+baca\r\n+abacaba0ab\r\n-baca\r\n-abacaba0ab\r\n-aba0abacab\r\n+cab\r\n-cab\r\n+abacabada\r\n-abacabada\r\n+badabaca\r\n-badabaca\r\n+badaba\r\n'], 'output': ['0\r\n']}, {'input': ['+badabac\r\nbadabac:abacabad\r\n-badabac\r\n+0ab\r\n-0ab\r\n+dabacab\r\n-dabacab\r\n+a0ab\r\n-a0ab\r\n+0abaca\r\n-0abaca\r\n+dabac\r\n-dabac\r\n+abaca\r\n-abaca\r\n+bacabada\r\n-bacabada\r\n+aca\r\n-aca\r\n+abadabaca\r\n-abadabaca\r\n+acaba\r\n-acaba\r\n+abacabadab\r\n-abacabadab\r\n'], 'output': ['8\r\n']}]