Can someone please help me why my question is returning the wrong answer on submitting the answer. while testing with sample input it is working as expected.
Thanks in advance.
/* package codechef; // don’t place package name! */
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef {
public static void main(String[] args) throws java.lang.Exception {
Scanner scanner = new Scanner(System.in);
int inputLength = 0;
if (scanner.hasNext()) {
inputLength = scanner.nextInt();
}
while (inputLength-- > 0) {
int sa = 0;
int sb = 0;
int emptyCells = 0;
if (scanner.hasNext()) {
if (scanner.hasNext()) {
emptyCells = scanner.next().length() - 2;
}
if (scanner.hasNext()) {
sa = scanner.nextInt();
}
if (scanner.hasNext()) {
sb = scanner.nextInt();
}
int saInc = 1;
int sbInc = emptyCells;
boolean unsafe = false;
for (int i = 0; i < emptyCells; i++) {
saInc += sa;
sbInc -= sb;
if (saInc == sbInc) {
System.out.println("unsafe");
unsafe = true;
}
}
if (!unsafe) {
System.out.println("safe");
}
}
}
}
}