program StudentStatsWithData;
uses math;

const
  TOTAL_STUDENTS = 24;
  { ご提示いただいた実際のデータ（24人分） }
  RAW_DATA: array[0..TOTAL_STUDENTS - 1] of Integer = (
    42, 48, 50, 50, 51, 73, 64, 77, 74, 90, 
    48, 43, 57, 55, 94, 41, 38, 52, 44, 68, 
    71, 74, 78, 81
  );

var
  Scores: array[0..TOTAL_STUDENTS - 1] of Integer;
  I, J, Temp, PassCount: Integer;
  Sum, Average, Variance, StdDev, Median: Real;

begin
  { 1. 定数配列から作業用配列へデータをコピー }
  Sum := 0;
  PassCount := 0;
  for I := 0 to TOTAL_STUDENTS - 1 do
  begin
    Scores[I] := RAW_DATA[I];
    Sum := Sum + Scores[I];
    if Scores[I] >= 60 then
      PassCount := PassCount + 1;
  end;

  { 2. 基本統計量の計算 }
  Average := Sum / TOTAL_STUDENTS;

  { 3. 中央値を求めるためのソート（バブルソート） }
  for I := 0 to TOTAL_STUDENTS - 2 do
    for J := 0 to TOTAL_STUDENTS - 2 - I do
      if Scores[J] > Scores[J + 1] then
      begin
        Temp := Scores[J];
        Scores[J] := Scores[J + 1];
        Scores[J + 1] := Temp;
      end;

  { 最高点と最低点はソート後の配列の両端から取得 }
  { （Scores配列は昇順に並び替えられています） }
  if TOTAL_STUDENTS mod 2 <> 0 then
    Median := Scores[TOTAL_STUDENTS div 2]
  else
    Median := (Scores[(TOTAL_STUDENTS div 2) - 1] + Scores[TOTAL_STUDENTS div 2]) / 2.0;

  { 4. 標準偏差の計算 }
  Variance := 0;
  for I := 0 to TOTAL_STUDENTS - 1 do
    Variance := Variance + Sqr(Scores[I] - Average);
  Variance := Variance / TOTAL_STUDENTS;
  StdDev := Sqrt(Variance);

  { 5. 結果の出力 }
  WriteLn('==================================');
  WriteLn('【集計結果（実際のデータ 24人分）】');
  WriteLn('==================================');
  WriteLn('平均点   : ', Average:0:2);
  WriteLn('中央値   : ', Median:0:1);
  WriteLn('最高点   : ', Scores[TOTAL_STUDENTS - 1]);
  WriteLn('最低点   : ', Scores[0]);
  WriteLn('標準偏差 : ', StdDev:0:2);
  WriteLn('合格者数 : ', PassCount, ' 人 / ', TOTAL_STUDENTS, ' 人');
  WriteLn('----------------------------------');
  
  { 6. 各学生の偏差値を出力（点数の高い順に見やすく表示） }
  WriteLn('【各学生の点数と偏差値（降順）】');
  for I := TOTAL_STUDENTS - 1 downto 0 do
  begin
    if StdDev = 0 then
      WriteLn('点数: ', Scores[I]:2, ' -> 偏差値: 50.0')
    else
      WriteLn('点数: ', Scores[I]:2, ' -> 偏差値: ', (10 * (Scores[I] - Average) / StdDev + 50):0:1);
  end;
  WriteLn('==================================');
  
  ReadLn; { 画面を閉じずに一時停止 }
end.