public class Solution {
    public int[] multiply(int[] A) {
        int N = A.length;
        int[] ls = new int[N];
        ls[0] = A[0];
        for(int i = 1; i < N; i++)
            ls[i] = ls[i - 1] * A[i];
        int[] rs = new int[N];
        rs[N - 1] = A[N - 1];
        for(int i = N - 2; i > -1; i--)
            rs[i] = rs[i + 1] * A[i];
        int[] ans = new int[N];
        ans[0] = rs[1];
        ans[N - 1] = ls[N - 2];
        for(int i = 1; i < N - 1; i++)
            ans[i] = ls[i - 1] * rs[i + 1];
        return ans;
    }
}