I am looking for a review on the following code which is for this question. I am looking for a general review of the code. I am specifically also looking for advice on how to make this code run more efficiently.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.util.*;
public class Main
{
public static void main(String args[]) throws IOException
{
int S[] = new int[100000];
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
String s[] = in.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int m = Integer.parseInt(s[1]);
String St = in.readLine();
char num[] = St.toCharArray();
for (int j = 0; j < m; j++)
{
String r1 = in.readLine();
int r = Integer.parseInt(r1);
int sum1 = 0, sum2 = 0;
for (int p = 0, len = num[r - 1]; p < r - 1; p++)
{
int diff = len - num[p];
if (diff < 0)
sum1 = sum1 + diff;
else
sum2 = sum2 + diff;
}
out.println((sum2 - sum1));
}
out.flush();
out.close();
}
}