public static int maxProfitIII(int[] prices) {
        // write your code here
        int[] p=prices;
        int n=p.length;
        if (n<=1)
            return 0;
        int[] f=new int[n];
        f[0]=0;
        int t=p[0];
        for (int i=1;i<n;++i) {
            t=Math.min(t,p[i]);
            f[i]=Math.max(f[i-1],p[i]-t);
        }
        t=p[n-1];
        int rel=f[n-1];
        for (int i=n-2,lm=0;i>=0;--i) {
            t=Math.max(t,p[i]);
            lm=Math.max(lm, t-p[i]);
            int x=i>0?f[i-1]:0;
            rel=Math.max(rel, x+lm);
        }
        return rel; 
    }