with Ada.Text_IO;
procedure Main is
   type Data is array (Positive range <>) of Integer;
   type R (D : Natural) is record
      V : Data (1 .. D);
   end record;
   type S (E : Positive) is new R (D => E);
   subtype Small is Positive range 1 .. 10;
   type T (Size : Small := 2) is new R (Size);

   function Sum (X : R) return Integer is
      Total : Integer := 0;
   begin
      for I in X.V'Range loop
         if X.V (I) in -1000 .. 1000 and then Total in -1_000_000 .. 1_000_000 then
            Total := Total + X.V (I);
         end if;
      end loop;
      return Total;
   end Sum;

   X : constant S (3) := (E => 3, V => (1, 2, 3));
   Y : constant R := R (X);
   Z : constant S := S (Y);
   W : T;
begin
   Ada.Text_IO.Put_Line (Positive'Image (X.E) & Natural'Image (Y.D) & Positive'Image (Z.E));
   Ada.Text_IO.Put_Line (Integer'Image (Sum (R (X))) & Integer'Image (Sum (R (Z))));
   W := (Size => 1, V => (1 => 7));
   Ada.Text_IO.Put_Line (Positive'Image (W.Size) & Integer'Image (W.V (1)) & " " & Boolean'Image (W'Constrained) & " " & Boolean'Image (X'Constrained));
end Main;
