import java.util.*; public class CloudyDay { private static HashMap sortByValues(HashMap map) { List list = new LinkedList(map.entrySet()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((Comparable) ((Map.Entry) (o2)).getValue()) .compareTo(((Map.Entry) (o1)).getValue()); } }); HashMap sortedHashMap = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); sortedHashMap.put(entry.getKey(), entry.getValue()); } return sortedHashMap; } public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); HashMap map=new HashMap(); int l[]=new int[n]; int p[]=new int[n]; for(int i=0;imax) { max=q[i]; maxi=i; } } for(int i=0;i smap = sortByValues(map); max=0; maxi=0; int maxj=0; for(int i=0;i=maxi && i<=maxj) sum+=smap.get(i); else if(i < a.length) { if(a[i]!=1) sum+=smap.get(i); } else if(i>a.length) sum+=smap.get(i); } System.out.println(sum); } }