There are a million numbered chairs at a large round table. The Sultan has seated a million wise men on them. Each of them sees the thousand people following him in clockwise order. Each of them was given a cap of black or white color, and they must simultaneously write down on their own piece of paper a guess about the color of their cap. Those who do not guess will be executed. The wise men had the opportunity to agree on a strategy before the test. What is the largest number of survivors that they can guarantee?
To solve this problem, we need to determine the maximum number of wise men who can guarantee their survival by guessing the color of their own cap correctly. The wise men can see the caps of the next 1000 people in the clockwise direction and can agree on a strategy beforehand.

1. **Upper Bound Analysis:**
   - Suppose the strategy for each wise man \(i\) is \(b_i = f_i(a_{i+1}, \dots, a_{i+1000})\), where \(b_i\) is the guess for the color of his own cap and \(a_j\) represents the color of the cap of the \(j\)-th wise man.
   - The Sultan can assign the colors \(a_{10^6-1000+1}, \dots, a_{10^6}\) arbitrarily.
   - For any wise man \(i\), the Sultan can set \(a_i = 1 - f_i(a_{i+1}, \dots, a_{i+1000})\), ensuring that \(b_i\) is incorrect.
   - This implies that the Sultan can force at least \(10^6 - 1000\) wise men to guess incorrectly, leaving at most 1000 wise men who can guess correctly.
   - Therefore, the upper bound on the number of survivors is 1000.

2. **Lower Bound Analysis:**
   - Consider a strategy where the first wise man (wise man 1) uses the function \(f_1(a_2, \dots, a_{1001}) = a_2 + a_3 + \dots + a_{1001} + 1 \mod 2\).
   - For other wise men \(i\), the function is similar but without the \(+1\): \(f_i(a_{i+1}, \dots, a_{i+1000}) = a_{i+1} + a_{i+2} + \dots + a_{i+1000} \mod 2\).
   - This strategy ensures that at least one wise man (the first one) will guess correctly because the sum of the caps he sees plus 1 will give him the correct parity of his own cap.
   - Therefore, the lower bound on the number of survivors is at least 1.

3. **Optimal Strategy:**
   - To maximize the number of survivors, we need to find a strategy that allows more than 1 wise man to guess correctly.
   - One possible strategy is for each wise man to guess the color of his cap based on the parity of the sum of the caps he sees.
   - Specifically, wise man \(i\) can guess \(b_i = a_{i+1} + a_{i+2} + \dots + a_{i+1000} \mod 2\).
   - This strategy ensures that the parity of the sum of the caps seen by each wise man is consistent, allowing them to make an educated guess about their own cap.
   - However, this strategy does not guarantee that more than 1 wise man will guess correctly, as the Sultan can still manipulate the cap assignments to force incorrect guesses.

Conclusion:
Given the constraints and the Sultan's ability to manipulate the cap assignments, the largest number of survivors that can be guaranteed is 1000.

The final answer is \(\boxed{1000}\).