public class AAA {
  public static void main(String[] args) {
    int[] x = { 1, 2, 34, 2, 1, 2 };
    int s = sum(x);
    System.out.println(s);
    
    String s = "  CBD  ";
    System.out.println(isPalindrome(s));
  }
  public static boolean isPalindrome(String s) {
    boolean b = isPalindrome(s, 0, s.length() - 1);
    return b;
  }
  public static boolean isPalindrome(String s, int left, int right) {
    // left และ right กำหนดขอลเขตของ s
    if (left >= right) return true;
    if (!s.substring(left, left + 1).equals(s.substring(right, right + 1)) return false;
    return isPalindrome(s, left+1, right-1);
  }
  public static int sum(int[] x) {
    int s = sum(x, x.length - 1);
    return s;
  }
  public static int sum(int[] x, int right) { // x[0] + ... + x[right]
    if (right < 0) return 0;
    int s = sum(x, right - 1) + x[right];
    return s;
  }

}
