Okay, let me try to figure out this math problem. So, there are N students, and the teacher is dividing them into groups. When she puts them in groups of 8, the last group has 5 students. That means N divided by 8 leaves a remainder of 5. Similarly, when she divides them into groups of 6, the last group has 3 students, so N divided by 6 leaves a remainder of 3. And N is less than 50. We need to find all possible N that satisfy these conditions and then sum them up.

First, let me write down the conditions mathematically. If N divided by 8 leaves a remainder of 5, then N can be expressed as 8k + 5 for some integer k. Similarly, N divided by 6 leaves a remainder of 3, so N can also be written as 6m + 3 for some integer m. So, we have two equations:

1. N = 8k + 5
2. N = 6m + 3

Since both equal N, we can set them equal to each other: 8k + 5 = 6m + 3. Let's rearrange this equation to find a relationship between k and m. Subtract 3 from both sides: 8k + 2 = 6m. Then, divide both sides by 2: 4k + 1 = 3m. So, 3m = 4k + 1. That means m must be such that when multiplied by 3, it gives a number that's one more than a multiple of 4. So, m = (4k + 1)/3. Since m must be an integer, (4k + 1) must be divisible by 3. So, 4k + 1 ≡ 0 mod 3. Let's solve for k.

4k + 1 ≡ 0 mod 3
4k ≡ -1 mod 3
But -1 mod 3 is 2, so 4k ≡ 2 mod 3
Since 4 ≡ 1 mod 3, this simplifies to k ≡ 2 mod 3. So, k must be congruent to 2 modulo 3. Therefore, k can be written as 3t + 2 for some integer t. Let's substitute back into N = 8k + 5:

N = 8*(3t + 2) + 5 = 24t + 16 + 5 = 24t + 21

So, N must be of the form 24t + 21. Now, since N < 50, let's find all possible t such that 24t + 21 < 50.

Subtract 21: 24t < 29
Divide by 24: t < 29/24 ≈ 1.208

Since t must be a non-negative integer (since k is non-negative as it's the number of groups), possible values of t are 0 and 1.

For t=0: N = 24*0 +21 =21
For t=1: N=24*1 +21=45
Check if these values satisfy the original conditions.

First, N=21:
Divide by 8: 21 ÷8=2 with remainder 5. Correct.
Divide by 6:21 ÷6=3 with remainder 3. Correct.
So 21 is valid.

N=45:
45 ÷8=5 with remainder 5. Correct.
45 ÷6=7 with remainder 3. Correct.
So 45 is also valid.

Check t=2: 24*2 +21=72+21=93, which is greater than 50. So, t=2 is too big. So, only 21 and 45 are possible. Therefore, the sum is 21 +45=66.

Wait, but let me double-check if there are other possible numbers. Let's list all numbers less than 50 that leave remainder 5 when divided by 8. Starting from 5:

5, 13, 21, 29, 37, 45, 53,... But since N <50, up to 45. So numbers are 5,13,21,29,37,45.

Now check which of these numbers leave remainder 3 when divided by 6.

Check each:

5 ÷6: remainder 5. Not 3. Reject.
13 ÷6: 13-12=1. Remainder 1. Not 3. Reject.
21 ÷6=3*6=18, 21-18=3. Remainder 3. Accept.
29 ÷6=4*6=24, 29-24=5. Remainder 5. Reject.
37 ÷6=6*6=36, 37-36=1. Remainder 1. Reject.
45 ÷6=7*6=42, 45-42=3. Remainder 3. Accept.

So only 21 and 45 satisfy both conditions. Therefore, sum is 66. That's the answer.

But wait, let me confirm once more. Maybe I missed another number. Let's check the numbers again:

Numbers less than 50 that are 5 mod8: 5,13,21,29,37,45.

Check each for mod6=3:

5 mod6=5≠3
13 mod6=1≠3
21 mod6=3 ✔️
29 mod6=5≠3
37 mod6=1≠3
45 mod6=3 ✔️

So yes, only 21 and 45. So sum is 66. Therefore, the answer is 66.
Therefore, the sum of all possible values of $N$ is $\boxed{66}$.
</think>