We label the digits of the unknown number as vwxyz. 
 Since vwxyz and 71794 have 0 matching digits, then $v \neq 7$ and $w \neq 1$ and $x \neq 7$ and $y \neq 9$ and $z \neq 4$. 
 Since vwxyz and 71744 have 1 matching digit, then the preceding information tells us that $y=4$. 
 Since $v w x 4 z$ and 51545 have 2 matching digits and $w \neq 1$, then $v w x y z$ is of one of the following three forms: $5 w x 4 z$ or $v w 54 z$ or $v w x 45$. 
 Case 1: vwxyz $=5 w x 4 z$ 
 Since $5 w x 4 z$ and 21531 have 1 matching digit and $w \neq 1$, then either $x=5$ or $z=1$. 
 If $x=5$, then $5 w x 4 z$ and 51545 would have 3 matching digits, which violates the given condition. Thus, $z=1$. 
 Thus, $v w x y z=5 w x 41$ and we know that $w \neq 1$ and $x \neq 5,7$. 
 To this point, this form is consistent with the 1st, 2 nd, 3 rd and 7 th rows of the table. 
 Since $5 w x 41$ and 59135 have 1 matching digit, this is taken care of by the fact that $v=5$ and we note that $w \neq 9$ and $x \neq 1$. 
 Since $5 w x 41$ and 58342 have 2 matching digits, this is taken care of by the fact that $v=5$ and $y=4$, and we note that $w \neq 8$ and $x \neq 3$. 
 Since $5 w x 41$ and 37348 have 2 matching digits and $y=4$, then either $w=7$ or $x=3$. 
 But we already know that $x \neq 3$, and so $w=7$. 
 Therefore, vwxyz $=57 x 41$ with the restrictions that $x \neq 1,3,5,7$. 
 We note that the integers $57041,57241,57441,57641,57841,57941$ satisfy the requirements, so are all possibilities for Sam's numbers. 
 Case 2: vwxyz $=v w 54 z$ 
 Since $v w 54 z$ and 51545 have only 2 matching digits, so $v \neq 5$ and $z \neq 5$. 
 Since $v w 54 z$ and 21531 have 1 matching digit, then this is taken care of by the fact that $x=5$, and we note that $v \neq 2$ and $z \neq 1$. (We already know that $w \neq 1$.) 
 Since $v w 54 z$ and 59135 have 1 matching digit, then $v=5$ or $w=9$ or $z=5$. 
 This means that we must have $w=9$. 
 Thus, vwxyz $=v 954 z$ and we know that $v \neq 2,7,5$ and $z \neq 1,4,5$. 
 To this point, this form is consistent with the 1 st, 2 nd, 3 rd , 4 th, and 7 th rows of the table. 
 Since $v 954 z$ and 58342 have 2 matching digits and $v \neq 5$, then $z=2$. 
 Since $v 9542$ and 37348 have 2 matching digits, then $v=3$. 
 In this case, the integer 39542 is the only possibility, and it satisfies all of the requirements. 
 Case 3: vwxyz $=v w x 45$ 
 Since $v w x 45$ and 21531 have 1 matching digit and we know that $w \neq 1$, then $v=2$ or $x=5$. 
 But if $x=5$, then $v w 545$ and 51545 would have 3 matching digits, so $x \neq 5$ and $v=2$. 
 Thus, vwxyz $=2 w x 45$ and we know that $w \neq 1$ and $x \neq 5,7$. 
 To this point, this form is consistent with the 1st, 2 nd, 3rd and 7 th rows of the table. 
 Since $2 w x 45$ and 59135 have 1 matching digit, this is taken care of by the fact that $z=5$ and we note that $w \neq 9$ and $x \neq 1$. 
 Since $2 w x 45$ and 58342 have 2 matching digits, then $w=8$ or $x=3$, but not both. 
 Since $2 w x 45$ and 37348 have 2 matching digits, then $w=7$ or $x=3$, but not both. 
 If $w=8$, then we have to have $x \neq 3$, and so neither $w=7$ nor $x=3$ is true. 
 Thus, it must be the case that $x=3$ and $w \neq 7,8$. 
 Therefore, vwxyz $=2 w 345$ with the restrictions that $w \neq 1,7,8,9$. 
 We note that the integers $20345,22345,23345,24345,25345,26345$ satisfy the requirements, so are all possibilities for Sam's numbers. 
 Thus, there are 13 possibilities for Sam's numbers and the sum of these is 526758.
What is the sum of all of the possibilities for Sam's number if Sam thinks of a 5-digit number, Sam's friend Sally tries to guess his number, Sam writes the number of matching digits beside each of Sally's guesses, and a digit is considered "matching" when it is the correct digit in the correct position?