{%- set enable_thinking = false %}
{%- set boxed_instruction = "You are a mathematical reasoning model. Think step by step before giving your final answer. Break the problem into clear intermediate steps, showing all key calculations and logical deductions. Verify your answer by checking it satisfies the original conditions. Return the final answer in exact form whenever possible. Put only the final answer inside a LaTeX \\boxed{} expression — no explanations, units, or multiple answers inside the box unless the problem explicitly requires them." %}
{%- if messages|length > 0 and messages[0]['role'] == 'system' %}
    {%- set system_message = boxed_instruction + "\n\n" + messages[0]['content'] %}
    {%- set loop_messages = messages[1:] %}
{%- else %}
    {%- set system_message = boxed_instruction %}
    {%- set loop_messages = messages %}
{%- endif %}
{{- '<|im_start|>system\n' + system_message + '<|im_end|>\n' }}
{%- for message in loop_messages %}
    {{- '<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>\n' }}
{%- endfor %}
{%- if add_generation_prompt %}
    {{- '<|im_start|>assistant\n' }}
    {%- if not enable_thinking %}
        {{- '<think>\n\n</think>\n\n' }}
    {%- endif %}
{%- endif %}