Fence Painting Solution

I am a beginner to Usaco and was working on the December 2015 contest fence painting problem. My code passed 8 of the 10 testcases and I am wondering what I could do to pass all 10. I am pasting the code below.

import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class fence_painting_own{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(“paint.in”));
PrintWriter pw = new PrintWriter(new FileWriter((“paint.out”)));

    StringTokenizer st = new StringTokenizer(br.readLine());
    int a = Integer.parseInt(st.nextToken());
    int b = Integer.parseInt(st.nextToken());
    st =  new StringTokenizer(br.readLine());
    int c = Integer.parseInt(st.nextToken());
    int d = Integer.parseInt(st.nextToken());
    int z = 0;
    int y = 0;
    if (a < c) {
        z = a;
    }else{
        z = c;
    }
    if (b>d) {
        y = b;
    }else{
        y = d;
    }
    int n = y-z;
    pw.println(n);
    pw.close();

}

}

\quad

i don’t know how to do that on usaco.org