Pagini recente » Cod sursa (job #2792468) | Cod sursa (job #1568402) | Cod sursa (job #167505) | Cod sursa (job #1559339) | Cod sursa (job #134654)
Cod sursa(job #134654)
var f,g:text;
a:array[1..4010] of string[2];
m,n:integer;
x,y,z:char;
i,k,nr,o,u:longint;
procedure quick(s,d:integer);
var i,j:integer;
x,w:string[2];
begin
i:=s; j:=d; x:=a[(s+d)div 2];
repeat
while a[i]<x do inc(i);
while a[j]>x do dec(j);
if i<=j then
begin
w:=a[i]; a[i]:=a[j]; a[j]:=w;
inc(i); dec(j);
end
until i>j;
if i<d then quick(i,d);
if j>s then quick(s,j);
end;
function putere(x,i:longint):longint;
var a,j:longint;
begin
a:=1;
for j:=1 to i do
begin
a:=a*x;
a:=a mod 104659;
end;
putere:=a;
end;
begin
assign(f,'nrcuv.in'); reset(f);
assign(g,'nrcuv.out'); rewrite(g);
readln(f,n,m); k:=0;
for i:=1 to m do
begin
readln(f,x,z,y);
if x<>y then
begin
inc(k);
a[k]:=x+y;
inc(k);
a[k]:=y+x;
end
else
begin
inc(k);
a[k]:=x+y;
end;
end; nr:=1;
quick(1,k);
for i:=2 to k do
if a[i]<>a[i-1] then inc(nr);
o:=1;
for i:=1 to n do
begin
o:=o*26;
o:=o mod 104659;
end;
u:=0;
for i:=2 to n do
begin
u:=u+putere(u,i-1);
u:=u mod 104659;
end;
if o<u then writeln(g,o-u+104659)
else writeln(g,o-u);
close(g);
end.