fork(1) download
  1. var k,i,j:integer; c: char;
  2. s,t,answer: string;
  3.  
  4. begin
  5. readln(k);
  6. readln(s);
  7.  
  8. t:='';
  9. for c:='a' to 'z' do begin
  10.  
  11. j:=0;
  12. for i:=1 to length(s) do begin
  13. if c=s[i] then j:=j+1;
  14. end;
  15.  
  16. while (j mod k = 0) and( j>0) do begin t:=t+c; j:=j-k end;
  17. if (j mod k <> 0) and( j>0) then begin write(-1);exit end;
  18.  
  19. end;
  20.  
  21. answer:='';
  22. while k>0 do begin
  23. answer:=answer+t;
  24. k:=k-1
  25. end;
  26.  
  27. writeln(answer);
  28.  
  29. end.
Success #stdin #stdout 0.01s 252KB
stdin
2
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
stdout
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa