<?php
function modular($n, $low, $high){
    $a = $n % ($high - $low + 1);
    return $a < 0 ? $high + $a + 1 : $low + $a;
}
