system: You are a text-to-SQL generator. Given a database schema and a question, reply with a single valid SQLite query that answers it. Output only the SQL on one line, with no explanation and no markdown.

user: Schema:
CREATE TABLE institution_details (
  unitid integer PRIMARY KEY,
  chronname text,
  city text,
  state text,
  level text,
  control text,
  basic text,
  hbcu text,
  flagship text,
  long_x real,
  lat_y real,
  site text,
  student_count integer,
  awards_per_value real,
  awards_per_state_value real,
  awards_per_natl_value real,
  exp_award_value integer,
  exp_award_state_value integer,
  exp_award_natl_value integer,
  exp_award_percentile integer,
  ft_pct real,
  fte_value integer,
  fte_percentile integer,
  med_sat_value text,
  med_sat_percentile text,
  aid_value integer,
  aid_percentile integer,
  endow_value text,
  endow_percentile text,
  grad_100_value real,
  grad_100_percentile integer,
  grad_150_value real,
  grad_150_percentile integer,
  pell_value real,
  pell_percentile integer,
  retain_value real,
  retain_percentile integer,
  ft_fac_value real,
  ft_fac_percentile integer,
  vsa_year text,
  vsa_grad_after4_first text,
  vsa_grad_elsewhere_after4_first text,
  vsa_enroll_after4_first text,
  vsa_enroll_elsewhere_after4_first text,
  vsa_grad_after6_first text,
  vsa_grad_elsewhere_after6_first text,
  vsa_enroll_after6_first text,
  vsa_enroll_elsewhere_after6_first text,
  vsa_grad_after4_transfer text,
  vsa_grad_elsewhere_after4_transfer text,
  vsa_enroll_after4_transfer text,
  vsa_enroll_elsewhere_after4_transfer text,
  vsa_grad_after6_transfer text,
  vsa_grad_elsewhere_after6_transfer text,
  vsa_enroll_after6_transfer text,
  vsa_enroll_elsewhere_after6_transfer text,
  similar text,
  state_sector_ct integer,
  carnegie_ct integer,
  counted_pct text,
  nicknames text,
  cohort_size integer
);
CREATE TABLE institution_grads (
  unitid integer,
  year integer,
  gender text,
  race text,
  cohort text,
  grad_cohort text,
  grad_100 text,
  grad_150 text,
  grad_100_rate text,
  grad_150_rate text
);
CREATE TABLE state_sector_grads (
  stateid integer,
  state text,
  state_abbr text,
  control text,
  level text,
  year integer,
  gender text,
  race text,
  cohort text,
  grad_cohort text,
  grad_100 text,
  grad_150 text,
  grad_100_rate text,
  grad_150_rate text,
  grad_cohort_ct integer
);
CREATE TABLE state_sector_details (
  stateid integer PRIMARY KEY,
  state text,
  state_post text,
  level text PRIMARY KEY,
  control text PRIMARY KEY,
  schools_count integer,
  counted_pct text,
  awards_per_state_value text,
  awards_per_natl_value real,
  exp_award_state_value text,
  exp_award_natl_value integer,
  state_appr_value text,
  state_appr_rank text,
  grad_rate_rank text,
  awards_per_rank text
);
-- foreign keys: institution_grads.unitid -> institution_details.unitid; state_sector_grads.stateid -> state_sector_details.stateid; state_sector_grads.state -> institution_details.state; state_sector_details.state -> institution_details.state

Hint: percent rank for median SAT value within sector refers to med_sat_percentile; over 500 graduates refers to grad_cohort > 500; in 2011 refers to year = 2011;

Question: Among the institutes in the state of Alabama whose percent rank for median SAT value within sector is 77, how many of them have over 500 graduates in total in 2011?

assistant: SELECT COUNT(DISTINCT T1.chronname) FROM institution_details AS T1 INNER JOIN institution_grads AS T2 ON T2.unitid = T1.unitid WHERE T1.state = 'Alabama' AND T1.med_sat_percentile = '100' AND T2.year = 2011 AND T2.grad_cohort > 500