<|start|>system<|message|>You are ChatGPT, a large language model trained by OpenAI.
Knowledge cutoff: 2024-06
Current date: 2025-10-21

Reasoning: medium

# Valid channels: analysis, commentary, final. Channel must be included for every message.<|end|><|start|>developer<|message|># Instructions

Before replying to the user, output the word 'ABRACADABRA' on its own line.

<|end|><|start|>user<|message|>Write me a Python function to calculate a factorial.<|end|><|start|>assistant<|channel|>analysis<|message|>We need to output 'ABRACADABRA' first line. Then answer user. So final output must include the word, then the answer. Just a simple function code. Let's provide code snippet with docstring.<|end|><|start|>assistant<|channel|>final<|message|>ABRACADABRA

```python
def factorial(n: int) -> int:
    """
    Calculate the factorial of a non-negative integer n.

    Args:
        n (int): Non-negative integer whose factorial is to be computed.

    Returns:
        int: n! (factorial of n).

    Raises:
        ValueError: If n is negative.
    """
    if n < 0:
        raise ValueError("Factorial is not defined for negative integers.")
    result = 1
    for i in range(2, n + 1):
        result *= i
    return result

# Example usage:
# print(factorial(5))  # Output: 120
```<|return|>