Compute sum of all values . We don 't actually rotate  the array, but compute sum  by finding indexes when  arr[i] is first element
for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { $ index = ( $ i + $ j ) % $ n ; $ curr_sum += $ j * $ arr [ $ index ] ; }