Set validation for maximum rows on child table - based on data from Master table (Student group )

At student group doctype there is field called Max Strength when i set 20 in it , then i can’t insert more than 20 row at the child table (Student Group Student) , i want to split this value based on student source .
1- i add a new filed at student group student called ( student_source) this field with two options (x , Y )

I want to add new two fields at master table called max for X and Max for y , so if i set 10 at max for x then i can’t insert more than 10 rows at this child table , also the same case for field max for y … @umair