title: Split arrays of natural numbers according to a requirement
body: <p>I have two arrays <code>{A<sub>i</sub>}</code> and <code>{B<sub>i</sub>}</code> of natural numbers. The sums of all elements are equal.</p>
  
  <p>I need to split each element of the two arrays into three natural numbers:</p>
  
  <p><code>A<sub>i</sub> = A1<sub>i</sub> + A2<sub>i</sub> + A3<sub>i</sub></code>
  <code>B<sub>i</sub> = B1<sub>i</sub> + B2<sub>i</sub> + B3<sub>i</sub></code></p>
  
  <p>such that the sum of all elements of A1 is equal to the sum of all elements of B1 and the same for all the other pairs.</p>
  
  <p>The important part I initially forgot about:</p>
  
  <p>Each element from A1<sub>j</sub>, A2<sub>j</sub>, A3<sub>j</sub> should be between A<sub>j</sub>/3-2 and A<sub>j</sub>/3+2 or at least equal to one of these numbers</p>
  
  <p>Each element from B1<sub>j</sub>, B2<sub>j</sub>, B3<sub>j</sub> should be between  B<sub>j</sub>/3-2 and B<sub>j</sub>/3+2 or at least equal to one of these numbers</p>
  
  <p>So the elements of arrays must be split in almost equal parts</p>
  
  <p>I look for some more elegant solution than just calculating all possible variant for both arrays.</p>