I have written this code :

#include <iostream> #include <sstream> #include <string> using namespace std; int inp; char list [3005]; int jumpers [3005]; string input; int total_numbers; void clear_first_number() //for use with sstrem { int initial = 0; int final = 0; char buffer; for (int counter = 0; counter == counter ;++counter) { buffer = input[counter]; if (buffer == ' ') { final = counter; ++ final; break; } } input.erase(0, final); } int subtract (int one, int two) { int difference = one - two; if (difference < 0) { difference = -1*difference; } return difference; } int main() { for (;;)/> // main loop till no input { /*stringstream(input) >> total_numbers; if (input.length() == 0) { return 0; } stringstream(input) >> total_numbers;*/ int is_jolly = 1; input.clear(); getline (cin, input); if (input.length() == 0) { break; } stringstream(input) >> total_numbers; clear_first_number(); for (int i = 0 ; i < total_numbers; ++i)//process input string { stringstream(input) >> inp; jumpers[i] = inp; clear_first_number(); } /*for (int i = 0; i < total_numbers; ++i) { cin >> jumpers[i]; }*/ //set bool array all to false for (int e = 0; e < total_numbers; ++e) { list [e] = '0'; } //create subtractions for (int j = 0; j < total_numbers ; ++j) { int difference = subtract(jumpers[j], jumpers[j+1]); list[difference-1] = '1'; } /*//make those indexes true which are present for (int t = 0; t < total_numbers ; ++t) { list[jumpers[t]-1] = true; }*/ //check if jolly for (int d = 0; d < total_numbers-1; ++d) { if (list[d] == '0') { is_jolly = 0; break; } } //print statements if (is_jolly == 1) { cout << "Jolly\n"; } else { cout << "Not jolly\n"; } } return 0; }

But the judge is not accepting the program and is saying runtime error.

Could you please help me out and tell me where I am going wrong?