Problem

Source: 2023 KMO Final Round Day 2 Problem 5

Tags: combinatorics



Given a positive integer $n$, there are $n$ boxes $B_1,...,B_n$. The following procedure can be used to add balls. $$\text{(Procedure) Chosen two positive integers }n\geq i\geq j\geq 1\text{, we add one ball each to the boxes }B_k\text{ that }i\geq k\geq j.$$For positive integers $x_1,...,x_n$ let $f(x_1,...,x_n)$ be the minimum amount of procedures to get all boxes have its amount of balls to be a multiple of 3, starting with $x_i$ balls for $B_i(i=1,...,n)$. Find the largest possible value of $f(x_1,...,x_n)$. (If $x_1,...,x_n$ are all multiples of 3, $f(x_1,...,x_n)=0$.)