public static ArrayList<Long> productExcludeItself(ArrayList<Integer> A) {
        // write your code
        int n=A.size();
        if (n<=1)
            return new ArrayList<Long>();
        long []pre=new long[n];
        long []suf=new long[n];
        pre[0]=A.get(0);
        for (int i=1;i<n;++i)
            pre[i]=pre[i-1]*A.get(i);
        suf[n-1]=A.get(n-1);
        for (int i=n-2;i>=0;--i)
            suf[i]=suf[i+1]*A.get(i);
        long[]r=new long[n];
        r[0]=suf[1];
        r[n-1]=pre[n-2];
        for (int i=1;i<n-1;++i)
            r[i]=pre[i-1]*suf[i+1];
        ArrayList<Long>rel=new ArrayList<>();
        for(long a:r)
            rel.add(a);
        return rel;
    }