 # Heights of Frustration :(

## I’ve been trying to solve this problem ‘sum of pairs’ http://www.codechef.com/problems/PAIRSUM, I’m done with the code and I’ve checked it with tons and tons of inputs, it seems to work quite fine and i’ve read the question a thousand times to see if i’ve made any mistake! I’m just not able to figure out whats wrong with the code ! , i’m getting RUNTIME ERROR (NZEC) , for some odd reason i’m getting an exception thrown during run time ! i’ve tried a lot to fix it ! it just gets me down i’m not able to find the problem , I’ll be glad if any of you guys could provide some assistance ! Thanks in advance.

public class sumofpairs {

``````public static void main(String[] args) throws Exception {

InputStream input = System.in;

int length, i, j, index, temp, max = 0;
ArrayList<Integer> sums = new ArrayList<Integer>();
int[] numbers = new int[length];
int[] count = new int;

for (i = 0; i < length; i++) {
}

for (i = 0; i < length; i++) {
for (j = i + 1; j < length; j++) {
temp = numbers* + numbers[j];

if ((index = contains(sums, temp)) == -1) {
} else {

count[index]++;
if (max < count[index])
max = count[index];

}
}
}

max = max * 2 + 2;

System.out.println(max);

}

public static int contains(ArrayList<Integer> sum, int key) {
int index;
Iterator<Integer> i = sum.iterator();

for (index = 0; i.hasNext(); index++) {
if (i.next() == key)
return index;
}
return -1;
}
``````

}

``````private InputStream stream;
private byte[] buf = new byte;
private int curChar;
private int numChars;
private SpaceCharFilter filter;

this.stream = stream;
}

if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}

while (isSpaceChar(c))
int sgn = 1;
if (c == '-') {
sgn = -1;
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
} while (!isSpaceChar(c));
return res * sgn;
}

public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '
``````

’ || c == ‘\r’ || c == ’ ’ || c == -1;
}

``````public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
``````

}

In your `main` method, maybe you need to use `System.exit(0)` when the program is done. Maybe your class has to be named `Main` instead of `sumofpairs`.

If none of the above works, maybe your program throws an exception when it is being tested.

If none of the above works, you could try using the `java.util.Scanner` class instead of your `InputReaders`.

You could replace the throws Exception with throws IOException to know whether the Runtime error is caused while input or while code execution further you can implement try-catch blocks to localize the point of exception in your code.

Your class cannot be public, use

``````class sumofpairs {
...
}
`````` Thanks for your response, but while uploading the program i always change the name to Main and upload… it still shows runtime error !
and also i never use Scanner coz its much slower plus its sure to give a TLE ! and since i’m using java, i don’t think i’ll explicitly have to give System.exit(0) and i’ve never done that before when i had my solutions accepted by the codechef compiler !!
Still not able to figure out whats wrong !! java experts !!! kindly tell me the problem with the code Sure i’ll try that out 