import java.util.*; public class Exercises19{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); int numberOfSushi = sc.nextInt(); int[] sushiArray = new int[numberOfSushi]; ArrayDeque stack = new ArrayDeque(); ArrayList sum = new ArrayList(); for (int n = 0; n < numberOfSushi; n++){ sushiArray[n] = sc.nextInt(); stack.add(new Sushi(sushiArray[n], n)); } while (stack.size() > 0){ Sushi sushi = stack.pop(); if(sushi.indexOfSushi + 1 >= numberOfSushi - 1){ sum.add(sushi.sumOfTaste); }else{ for (int n = (sushi.indexOfSushi + 2); n < numberOfSushi; n++){ stack.push(new Sushi(sushi.sumOfTaste + sushiArray[n], n)); } } } Collections.sort(sum); System.out.println(sum.get(sum.size() - 1)); } } class Sushi { public int sumOfTaste; public int indexOfSushi; Sushi(int sum, int index){ sumOfTaste += sum; indexOfSushi = index; } }