import java.io.FileInputStream;

public class Main {

    static byte[] entrada;
    static int ponteiro;
    static final StringBuilder saida = new StringBuilder();

    public static void main(String[] args) throws Exception {

        lerEntrada();
        processar();
        escreverSaida();

    }

    static void processar() {

            int x = nextInt();
            int soma = 0, maior = 0, cont = 0;
            for (int j = 0; j < x; j++) {

                int x = nextInt();
            int soma = 0, maior = 0, cont = 0;
            for (int j = 0; j < x; j++) {

                int n = nextInt();
                if(n == 1){

                    cont++;
                    soma--;
                }else{

                    soma++;
                }

                if(soma < 0){

                    soma = 0;
                }
                if(soma > maior){

                    maior = soma;
                }
            }

            saida.append(maior+cont).append("\n");

    }

    static void lerEntrada() throws Exception {
        entrada = new byte[System.in.available()];
        System.in.read(entrada);

    }

    static void escreverSaida() throws Exception {
        System.out.write(saida.toString().getBytes());
        System.out.flush();
    }

    static boolean hashNext() {
        return ponteiro < entrada.length;
    }

    static boolean skipIgnored() {
        while (true) {
            if (!hashNext()) {
                return false;
            }
            if (entrada[ponteiro] <= ' ') {
                ponteiro++;
            } else {
                break;
            }
        }
        return true;
    }

    static void voltarPonteiro() {
        if (hashNext()) {
            ponteiro--;
        }
    }

    static int nextInt() {
        int n = 0;
        if (skipIgnored()) {
            char c;
            while (hashNext()) {
                c = (char) entrada[ponteiro++];
                if (c < '0' || c > '9') {
                    voltarPonteiro();
                    break;
                }
                n = n * 10 + (c - 48);
            }
        }
        return n;
    }

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author Roger Flores Vargas
 */
public class Unlucky_Ticket {
    public static void main(String[] args) {
        Scanner entrada = new Scanner(System.in);
        int n = entrada.nextInt();
        entrada.nextLine();
        String num = entrada.nextLine();
        char[] left, right;
        left = copiar(0, n, num);
        right = copiar(n, 2 * n, num);
        Arrays.sort(left);
        Arrays.sort(right);
        boolean unlucky = comparar(left, right);
        if(unlucky)
            System.out.println("YES");
        else
            System.out.println("NO");
    }

    private static boolean comparar(char[] left, char[] right){
        boolean res = true;
        if(left[0] < right[0]){
            for (int i = 0; i < right.length; i++) {
                res = left[i] < right[i];
            }
        }
        else{
            for (int i = 0; i < right.length; i++) {
                res = left[i] > right[i];
            }
        }
        return res;
    }

    private static char[] copiar(int i, int j, String cad){
        char[] res = new char[j-i];
        for (int k = 0; k < res.length; k++) {
            res[k] = cad.charAt(i+k);
        }
        return res;
    }
}


import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: mihai
 * Date: 2/3/12
 * Time: 10:45 PM
 */
public class problemB {
    private static double[] list = new double[101];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] digits = new int[202];
        int N = sc.nextInt();
        String s = sc.nextLine();
        s = sc.nextLine();
        for (int i = 0; i < 2 * N; i++) {
            char c = s.charAt(i);
            digits[i] = c - '0';
        }

        Arrays.sort(digits, 0, N);
        Arrays.sort(digits, N, 2*N);

        boolean leftBigger = true;
        boolean rightBigger = true;

        for (int i = 0; i < N; i++) {
            if (digits[i] <= digits[N+i]) leftBigger = false;
            if (digits[i] => digits[N+i]) rightBigger = false;
        }

        if (leftBigger || rightBigger)  System.out.println("YES");
        else System.out.println("NO");

    }
}


import java.io.*;
import java.util.*;
public class unluckyticket1
{
    public static void main(String ar[])throws IOException
    {
        unluckyticket ob=new unluckyticket();
        BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(x.readLine());
        String s=x.readLine();
        String s1=s.substring(0,n),s2=s.substring(n);
        s1=ob.sort(s1,n);
        s2=ob.sort(s2,n);
        int greater=0,lesser=0,equal=0,f=0;
        char c1=' ',c2=' ';
        StringBuilder sb = new StringBuilder(s2);
        for(int i=0;i<n;i++)
        {
            c1=s1.charAt(i);
            for(int j=0;j<n;j++)
            {
                c2=sb.charAt(j);
                if(c1!=c2 && c2!='a')
                {
                    if(c1>c2)
                    {
                        sb.setCharAt(j, 'a');
                        greater++;
                        break;
                    }
                    else
                    {
                        sb.setCharAt(j, 'a');
                        lesser++;
                        break;
                    }
                }
                else if(c1==c2 && c2!='a')
                    equal++;
            }
            if((greater>0 && lesser>0))
                {
                    f=1;
                    break;
                }
        }
        if(f!=1)
        {
            if(greater!=n && equal>0)
                f=1;
            if(lesser!=n && equal>0)
                f=1;
        }
        if(f==0)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
    //sorting the s1 and s2
    String sort(String s,int n)
    {
        char c=' ';
        String m="";
        StringBuilder sb = new StringBuilder(s);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n-1;j++)
            {
                if(sb.charAt(j)>sb.charAt(j+1))
                {
                    c=sb.charAt(j);
                    sb.setCharAt(j, sb.charAt(j+1));
                    sb.setCharAt(j+1,c );
                }
            }
        }
        m=sb.toString();
        return m;
    }
}


import java.util.Scanner;
public class UnluckyTicket {
    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        int n= input.nextInt();
        n= n*2;
        int a[]=new int [n];
        for (int i=0; i<=n-1;i++){
            a[i]=input.nextInt();
        }
        for (int j=0;j<=(n-1)/2;j++){
            if(a[j]<a[n-1-j]){
                if (j==(n-1)/2){
                    System.out.print("YES");
                    }

            }
        }
        for (int k=0;k<=(n-1)/2;k++){
            if(a[k]>a[n-1-k]){
                if(k==(n-1)/2){
                    System.out.print("NO");
                }
            }


//package HR;

import java.util.*;
import java.math.*;
//import java.io.*;

public class Test_inhert {

    static class pair {

        public int x;
        public int y;
    }

    public static void main(String[] args) {
        FastReader in = new FastReader(System.in);
        int a = in.nextInt();
        int x = in.nextInt();
        int f = in.nextInt();
        int k = in.nextInt();
        int i = 1;
        int b = x;
        int ans = 0;
        int odd = f;
        int even = a - f;
        boolean flag = true;
        while (i <= k) {
            if ((i & 1) == 1) {
                b -= odd;
                if (b < 0) {
                    flag = false;
                    break;
                }
                if (b < even) {
                    ++ans;
                    b = x;
                    b -= even;
                } else if (i + 1 <= k && b < even * 2) {
                    ++ans;
                    b = x;
                    b -= even;
                } else if (b >= even * 2 || (i == k && b >= even)) {
                    b -= even;
                } else {
                    flag = false;
                    break;
                }
            } else {
                b -= even;
                if (b < 0) {
                    flag = false;
                    break;
                }
                if (b < odd) {
                    ++ans;
                    b = x;
                    b -= odd;
                } else if (i + 1 <= k && b < odd * 2) {
                    ++ans;
                    b = x;
                    b -= odd;
                } else if (b >= odd * 2 || (i == k && b >= odd)) {
                    b -= odd;
                } else {
                    flag = false;
                    break;
                }
            }
            ++i;
        }
        System.out.println(flag == true ? ans : -1);
    }

    private static class FastReader {

        private InputStream stream;

        private byte[] buf = new byte[1024];

        private int curChar;

        private int numChars;

        private FastReader.SpaceCharFilter filter;

        FastReader(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            long ret = 0;
            int c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg) {
                c = read();
            }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) {
                return -ret;
            }
            return ret;
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {

            boolean isSpaceChar(int ch);
        }
    }
}


public class bus{
public static void main (String [] args){
long i;
long a;
long b;
long f;
long k;
long cb = b;

	if (k == 1)
	{
		if (b >= a)
		{
			System.out.print(0);
			System.out.print("\n");
		}
		else if (b >= f != 0 && b >= a - f)
		{
			System.out.print(1);
			System.out.print("\n");
		}
		else
		{
			System.out.print(-1);
			System.out.print("\n");
		}

		return 0;
	}

	if (k == 2)
	{
		if (b >= 2 * a)
		{
			System.out.print(0);
			System.out.print("\n");
		}
		else if (b >= a + a - f || (b >= f != 0 && b >= (a + a - f)))
		{
			System.out.print(1);
			System.out.print("\n");
		}
		else if (b >= f != 0 && b >= 2 * (a - f))
		{
			System.out.print(2);
			System.out.print("\n");
		}
		else
		{
			System.out.print(- 1);
			System.out.print("\n");
		}

		return 0;
	}

	final long x1 = 2 * (a - f);
	final long x2 = 2 * f;

	if (b < f || b < x1 || b < x2)
	{
		System.out.print(-1);
		System.out.print("\n");

		return 0;
	}

	cb -= f;
	long stops = 0;
	for (i = 0; i != k - 1; ++i)
	{
		if (i % 2 == 0)
		{
			if (cb < x1)
			{
				cb = b;
				++stops;
			}

			cb -= x1;
		}
		else
		{
			if (cb < x2)
			{
				cb = b;
				++stops;
			}

			cb -= x2;
		}
	}

	if (i % 2 == 0)
	{
		if (cb < a - f)
		{
			++stops;
		}
	}
	else
	{
		if (cb < f)
		{
			++stops;
		}
	}

	System.out.print(stops);
	System.out.print("\n");
}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        long a = in.nextLong();
        long b = in.nextLong();
        long f = in.nextLong();
        long k = in.nextLong();
        long c = 0;
        long tb = b;
        if ((2 * (a - f) < b) && (2 * f < b)) {
            for(int i = 0; i < k;i++){
                if(i!=k-1) {
                    if (i % 2 == 0) {
                        if (b >= 2 * a - f) {
                            b = b - a;
                        } else {
                            c++;
                            b = tb - (a - f);
                        }
                    } else {
                        if (b >= a + f) {
                            b = b - a;
                        } else {
                            c++;
                            b = tb - f;
                        }
                    }
                }else{
                    if (i % 2 == 0) {
                        if (b >= a) {
                            b = b - a;
                        } else {
                            c++;
                            b = tb - (a - f);
                        }
                    } else {
                        if (b >= a) {
                            b = b - a;
                        } else {
                            c++;
                            b = tb - f;
                        }
                    }
                }
            }
        } else {
            if(a*k/b=>1){
                System.out.println(0);
                return;
            }
            System.out.println(-1);
            return;
        }
        System.out.println(c);
    }
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class C864C {
public static void main(String[] args) {
	Scanner sc = new Scanner (new BufferedInputStream(System.in));
	int a = sc.nextInt(),b=sc.nextInt(),f=sc.nextInt(),k=sc.nextInt();
	sc.close();
	//标志位显示是去还是回;
	int flag=1;
	//油箱到加油站时
	int t=b-f;
	//加油次数
	int count=0;
	while(k>0) {
		if(flag==1) {
			//油箱不够跑完下面的路
			if(t<(a-f)*2) {
				t=b;
				//满油状态下是否能够跑完
			if(t<(a-f)*2) {
				//不能就输出-1
				System.out.println(-1);
				return ;
			}else {
				//能跑完
				count++;
				t=t-(a-f)*2;
			}
			}else {
				t=t-(a-f)*2;
			}
			flag=0;
			k--;
		}else {
			if(k!=1) {
			//油箱不够跑完下面的路
			if(t<2*f) {
				t=b;
				//满油状态下是否能够跑完
				if(t<2*f) {
					//不能就输出-1
					System.out.println(-1);
					return ;
				}else {
					//能跑完
					count++;
					t=b-2*f;
				}
			}else {
				t=b-2*f;
			}
		}else {
			if(t<f) {
				t=b;
				//满油状态下是否能够跑完
				if(t<f) {
					//不能就输出-1
					System.out.println(-1);
					return ;
				}else {
					//能跑完
					count++;
					t=b-2*f;
				}
			}
		}
			k--;
			flag=1;
		}
	}
	System.out.println(count);
}
}


import java.util.Scanner;

public class 554A {

    public static void main(String[] args) {
        String s = new SCanner(System.in).nextLine();
        int repeated = 0;
        for (int i = 0; i < s.length() - 1; i++) {
            if (s.charAt(i) == s.charAt(i+1)) repeated++;
        }
        System.out.println(25*(s.length+1)+s.length()-repeated);
    }

}


import java.util.*;
import java.io.*;
public class Photos{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String s=sc.nextInt();
    HashSet<String> hs=new HashSet<>();
    for(int i=0;i<=s.length();i++){
      for(int j='a';j<='z';j++){
        char c=char(j);
        hs.add(s.substring(0,i)+c+s.substring(i));
      }
    }
    System.out.println(hs.size());
  }
}


import java.io.*;
import java.util.*;
import java.lang.*;

public class b {
  public static void main(String[] args) {
    b solver = new b();
  }

  b() {
    InputReader in = new InputReader();
    in.init(System.in);

    String s = in.next();
    System.out.println(s.length * 25 + 26);
  }
}

class InputReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;

  public void init(InputStream input) {
    reader = new BufferedReader(
            new InputStreamReader(input),
            32768);
    tokenizer = null;
  }

  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  public int nextInt() {
    return Integer.parseInt(next());
  }

  public long nextLong() {
    return Long.parseLong(next());
  }
}


public class Main {
    public static void main(String [] args) {
        String string = java.util.Scanner(System.in).next();
        System.out.println(string.length() * 26 + 26 - string.length());
    }
}


import java.util.Date;
public class B {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
ArrayList<Integer> a = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
a.add(reader.nextInt());
}

ArrayList<Integer> b = new ArrayList<Integer>(a);
ArrayList<Integer> x = new ArrayList<Integer>();
ArrayList<Integer> z = new ArrayList<Integer>();

for (int i = 1; i < n-1; i++) {
b.remove(i);
for (int j = 0; j < b.size()-1 ; j++) {
x.add(b.get(j+1) - b.get(j));
}
Collections.sort(x);
z.add(x.get(x.size() - 1));
x = new ArrayList<Integer>();
b = new ArrayList<Integer>(a);
}
Collections.sort(z);

System.out.println(z.get(0));
}
}


import java.util.Scanner;
import java.lang.Math;

public class Difficulty{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);

        int numHolds = scan.nextInt();

        long difficulty=0;
        long minimumGap=Integer.MAX_VALUE;

        int holdOne = scan.nextInt();
        int second = scan.nextInt();
        difficulty = (second-holdOne);
        int prev = holdOne;
        int current = second;
        for(int i=0;i<numHolds-1;i++){
            int next = scan.nextInt();

            difficulty = Math.max(next - current);
            minimumGap = Math.min(minimumGap, next - prev);

            prev = current;
            current = next;
        }

        System.out.println(Math.max(minimumGap, difficulty));
    }
}


import java.util.Scanner;
import java.lang.Math;

public class Difficulty{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);

        int numHolds = scan.nextInt();

        long difficulty=0;
        long minimumGap=Integer.MAX_VALUE;

        int holdOne = scan.nextInt();
        int second = scan.nextInt();
        difficulty = (second-holdOne);
        int prev = holdOne;
        int current = second;
        for(int i=0;i<numHolds-1;i++){
            int next = scan.nextInt();

            difficulty = Math.max(next - current);
            minimumGap = Math.min(minimumGap, next - prev);

            prev - current;
            current = next;
        }

        System.out.println(Math.max(minimumGap, difficulty));
    }
}


public class B {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
ArrayList<Integer> a = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
a.add(reader.nextInt());
}

ArrayList<Integer> b = new ArrayList<Integer>(a);
ArrayList<Integer> x = new ArrayList<Integer>();
ArrayList<Integer> z = new ArrayList<Integer>();

for (int i = 1; i < n-1; i++) {
b.remove(i);
for (int j = 0; j < b.size()-1 ; j++) {
x.add(b.get(j+1) - b.get(j));
}
Collections.sort(x);
z.add(x.get(x.size() - 1));
x = new ArrayList<Integer>();
b = new ArrayList<Integer>(a);
}
Collections.sort(z);

System.out.println(z.get(0));
}
}


import java.util.Scanner;
public class HelloWorld {
  public static void main(String[] args) {
  int i,count=0;
  String str;
  	Scanner sc = new Scanner(System.in);
  	System.out.println("enter a string");
  	str = sc.next();
	for(i=0;i<str.length();i++){
		if(str.charAt(i).equals(H) || str.charAt(i).equals(Q)){
			count+=1;
					}
		else
			System.out.println("NO");
	}
	if(count >= 1){
		System.out.println("YES");
	}
  }
}


import java.util.Scanner;
public class HQ9{
    private static Scanner s = new Scanner(System.in);
    public static void main(String[] args){
        String p = s.nextLine();
        boolean flag = false;
        for(int i=0;i<p.length();i++)
         if( p[i]=='H' || p[i]=='Q'|| p[i]=='9' || p[i]=='+' && p[i] >= 33 && p[i] <=126)
         {flag = true;
         break;}

         if(flag)
         System.out.print("YES");
         else
         System.out.print("NO");
    }
}


import java.util.Scanner;
public class a

{
public static void main(String []aa)
{
int f=0;
Scanner sc=new Scanner(System.in);
String str;
str=sc.next();
int b=str.length();
for(int i=0;i<b;i++)
{
char c=str.charAt(i);
if(c=='Q' || c=='H'|| c=='9'|| c=='+')

	{System.out.println("YES");
	f++;
	break;
	}
else
	pass;
}
if(f==0)
System.out.println("NO");

}
}


import java.util.Scanner;
public class Exa
{public static void main(String args[])
{Scanner s=new Scanner(System.in);
 String se=s.next();
// char c[]=se.toCharArray();
 if(s.contains('H')||s.contains('Q')||s.contains('9')||s.contains('+'))
  System.out.println("YES");
 else
 System.out.println("NO");
}
}


	import java.util.ArrayList;
import java.util.Scanner;

	public class CodeF {

		public static void main(String [] args) {
			Scanner sc=new Scanner(System.in);
			int a =sc.nextInt();
			int b=sc.nextInt();
			int c=sc.nextInt();
			if (c==0) {
		        if (b==a) {
		            System.out.print( "YES");
		        } else {
		            System.out.print("NO");
		        }
		    } else if ((b<a&&c>0) )
		        System.out.print("NO");
		      else if(b>a&&c<0)
		        	System.out.print("NO");
		     else {
		        if ((b-a%c==0) {
		        	System.out.print( "YES");
		        } else {
		        	System.out.print( "NO");
		        }
		    }

		}

	}


public class B {

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int c = Integer.parseInt(st.nextToken());
		if((b-a)==c || (c!=0 && (b-a)%c==0)) {
			if((b>=a && c>=0) || (b<a && c<0))
			System.out.println("YES");
			else
			System.out.println("NO");
		}
			else
			System.out.println("NO");

	}

}


import java.io.*;
import java.util.*;
public class InfiniteSequence {
public static String Sequence(){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt();
int n = a+c;
String s = "NO";
if(c == 0  & b != 0){
return "NO"
}
while(n <= b){
if(n == b){
s = "YES";
break;
}
n = n+c;
}
return s;
}
public static void main(String[] args) throws IOException
{
PrintWriter r = new PrintWriter(System.out);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
Scanner sc = new Scanner(System.in);
String s = "YES";
r.println(Sequence());
r.flush();
}
}


import java.io.*;
import java.util.*;
public class InfiniteSequence {
public static String Sequence(){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt();
int n = a+c;
String s = "NO";
if(c == 0 & a == 0 & b !=0){
return "NO"
}
while(n <= b){
if(n == b){
s = "YES";
break;
}
n = n+c;

}
return s;
}
public static void main(String[] args) throws IOException
{
PrintWriter r = new PrintWriter(System.out);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
Scanner sc = new Scanner(System.in);
String s = "YES";
r.println(Sequence());
r.flush();
}
}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class Main
{
	public BufferedReader in;
	public PrintStream out;

	public int calc(int a, int b)
	{
		if (a<b)
		{
			return calc(b,a);
		}

		if (b==1)
		{
			return a-b;
		}

		return  calc(b, a% b) + a/b;
	}

	public void test()
	{
		int n = readInt();
		int min = n-1;
		int c;

		for (int k=2; k<n; k++)
		{
			c = calc(n,k);
			if (c<min)
			{
				min = c;
			}
		}

		out.println(min);
	}

	public void run()
	{
		try
		{
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;

			//in = new BufferedReader(new FileReader("in.txt"));
			//out = new PrintStream(new File("out.txt"));

		}
		catch (Exception e)
		{
			return;
		}

		//while (true)
		{
			//int t = readInt(); for (int i=0; i<t; i++)
			{
				test();
			}
		}
	}

	public static void main(String args[])
	{
		new Main().run();
	}

	private StringTokenizer tokenizer = null;

	public int readInt()
	{
        return Integer.parseInt(readToken());
    }

    public long readLong()
	{
        return Long.parseLong(readToken());
    }

    public double readDouble()
	{
        return Double.parseDouble(readToken());
    }

	public String readLn()
	{
		try
		{
			String s;
			while ((s = in.readLine()).length()==0);
			return s;
		}
		catch (Exception e)
		{
			return "";
		}
	}

    public String readToken()
	{
		try
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}
		catch (Exception e)
		{
			return "";
		}
    }

	public int[] readIntArray(int n)
	{
		int[] x = new int[n];
		readIntArray(x, n);
		return x;
	}

	public void readIntArray(int[] x, int n)
	{
		for (int i=0; i<n; i++)
		{
			x[i] = readInt();
		}
	}
}


import java.math.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int a, b;
        int ans = n - 1;
        for (int i = 1; i < (n + 1) / 2; i++) {
            int t = 1;
            a = i;
            b = n - i;
            while (true) {
                //System.out.println(a + "    " + b);1    1    44
                if (a == 1) {
                    t = t + b - 1;
                    break;
                } else if (a == 0) {
                    t = n - 1;
                }
                t += b / a;
                b = b % a;

                int c = a;
                a = b;
                b = c;
            }
            if (t < ans) {
                ans = t;
            }
        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import static java.lang.System.*;

public class pon {

    static BufferedReader br;

    public static void init() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public static String getString() {
        try {
            if (br == null) {
                init();
            }
            return br.readLine();
        } catch (Exception e) {
        }
        return "";
    }

    public static Integer getInt() {
        try {
            if (br == null) {
                init();
            }
            return Integer.parseInt(br.readLine());
        } catch (Exception e) {
        }
        return 0;
    }

    public static Integer[] getIntArr() {
        try {
            if (br == null) {
                init();
            }
            String temp[] = br.readLine().split(" ");
            Integer temp2[] = new Integer[temp.length];
            for (int i = 0; i < temp.length; i++) {
                temp2[i] = Integer.parseInt(temp[i]);
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }
    static int inp = 0;
    static ArrayList<Integer> ans=new ArrayList<Integer>();
    public static void main(String[] ar) {
        int init[] = {1, 1};
        int c = 0;
        inp = getInt();
        //sol(init, c);
        new solver(init, c, inp, ans).start();
        try{
            Thread.sleep(900);
        }catch(Exception e){

        }
        int min=ans.get(0);
        for(int i=0;i<ans.size();i++){
            if(ans.get(i)<min){
                min=ans.get(i);
            }
        }
        System.out.println(min);
    }

    public static void sol(int[] init, int c) {

        int max = Math.max(init[0], init[1]);
        int min = Math.min(init[0], init[1]);
        if (max > inp) {
            return;
        } else if (max == inp) {
            //System.out.println(c);
            ans.add(c);
            return;
        } else if (max < inp) {
            c++;
            sol(new int[]{max + min, max}, c);
            sol(new int[]{max + min, min}, c);
        }

    }
}
class solver extends Thread{
    int init[];
    int c;
    int inp;
    ArrayList<Integer> ans;
    solver(int[] init,int c,int inp,ArrayList<Integer> ans){
        this.init=init;
        this.c=c;
        this.inp=inp;
        this.ans=ans;
    }

    public void run(){

        int max = Math.max(init[0], init[1]);
        int min = Math.min(init[0], init[1]);
        if (max > inp) {
            return;
        } else if (max == inp) {
            //System.out.println(c);
            ans.add(c);
            return;
        } else if (max < inp) {
            c++;
            new solver(new int[]{max + min, max}, c,inp,ans).start();
            new solver(new int[]{max + min, min}, c,inp,ans).start();
        }

    }
}


import java.util.Scanner;

public class B {
    public static int getMin(int f,int s) {
        if(f==s) {
            if(f==1&&s==1) return 0;
            return 3000000;
        }
        int min=Math.min(f,s);
        int max=Math.max(f,s);
        if(min==1) return max-1;
        return ((max/min))+getMin(max%min,min);
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n==1){
            System.out.println(0); return;
        }
        int min=2*n;
        for(int i=1;i<=n/2;i++) {
            //System.out.println(getMin(i,n-i));
            min=Math.min(min,1+getMin(i,n-i));
        }
        System.out.println(min);
    }
}


import edu.princeton.cs.algs4.In;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.Inet4Address;
import java.util.*;

import java.util.Iterator;
import java.util.NoSuchElementException;

public class Main {

    private static Scanner scanner;

    static void solution() {
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int n = scanner.nextInt();

        if (n - (a + b - c) < 1) System.out.println(-1);
        else System.out.println(n - (a + b - c));
    }

    public static void main(String args[]) {
        scanner = new Scanner(System.in);
        solution();
    }
}


import java.util.Scanner;

public class Sampl2
{

	public static void main(String[] args)
	{	Scanner s = new Scanner(System.in);
                int a = s.nextInt();
                int b = s.nextInt();
                int c = s.nextInt();
                int n = s.nextInt();
                int y = a+b-c;
                if(y < n & y=> 0 & c<=a & c<=b){
                    System.out.println(n-y);
                }else{
                    System.out.println("-1");
                }

	}
}


import java.util.Scanner;

public class tooth
{
	public static void main(String[]args)
	{
		Scanner sc=new Scanner(System.in);

		long a,b,c,n,i,s;
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		n=sc.nextInt();

		x=a-c;
		y=b-c;
		x=x+y+c;

		z=n-x;

		if(z>=1)
		{
			System.out.println(z);
		}
		else
		{
			System.out.println("-1");
		}

	}

}


import java.util.Scanner;

public class Sampl21
{

	public static void main(String[] args)
	{	Scanner s = new Scanner(System.in);
                int a = s.nextInt();
                int b = s.nextInt();
                int c = s.nextInt();
                int n = s.nextInt();
                y = a+b-c;
                if(y < n){
                    System.out.println(n-y);
                }else{
                    System.out.println("-1");
                }

	}
}


import java.util.Scanner;

public class robots {
    public static void main(String[] args) {
        int s=-1;s1=0;s2=0;x=0;
        Scanner scan=new Scanner(System.in);

            int n=scan.nextInt();
        int[] a=new int[n];
          int[] b=new int[n];
         for (int i = 0; i < n; i++) {
            a[i]=scan.nextInt();
            s1=s1+a[i];
        }
         for (int i = 0; i < n; i++) {
            b[i]=scan.nextInt();
            s2+=b[i];
        }
         //System.out.println("s1 and s2 "+s1+""+s2);
        for (int i = 0; i < n; i++) {
            if(a[i]==1&&b[i]==0)
            {
            x++;
            }}
            if(s2>s1)
            {
                s=s2-s1;
                s=s/x;
                s+=2;

            } System.out.println(s);
        }

}


import java.util.Scanner;

public class robots {
    public static void main(String[] args) {
        int s=-1,s1,s2,x;
        Scanner scan=new Scanner(System.in);

            int n=scan.nextInt();
        int[] a=new int[n];
          int[] b=new int[n];
         for (int i = 0; i < n; i++) {
            a[i]=scan.nextInt();
            s1=s1+a[i];
        }
         for (int i = 0; i < n; i++) {
            b[i]=scan.nextInt();
            s2+=b[i];
        }
         //System.out.println("s1 and s2 "+s1+""+s2);
        for (int i = 0; i < n; i++) {
            if(a[i]==1&&b[i]==0)
            {
            x++;
            }}
            if(s2>s1)
            {
                s=s2-s1;
                s=s/x;
                s+=2;

            } System.out.println(s);

}


import java.util.Scanner;
public class Contest_for_Robots
    public static void main (String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    System.out.println(y);
}
}


import java.util.Scanenr;
public class Contest_For_Robots
    public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int ans = 0;
        int [] res = new int(x);
        for (int i = 0; i < x ; i++){
            res[i] = sc.nextInt();
        }
        for (int i = 0; i< x ; i++){
            if(res[i] == 0 && res[i + x] == 1)
                ans = ans + 1;

        }
        System.out.println(Math.floor((ans + 1)/2.0)));

}


import java.io.*;
import java.util.*;

public class Solution{

 public static void main(String[] args) {

     Scanner in = new Scanner(System.in);

     int n,m,amin=10,bmin=10,temp,i;

     n=in.nextInt();
     m=in.nextInt();

     for(i=1;i<=n;i++){
    	 temp=in.nextInt();
    	 amin=Math.min(amin, temp);
     }

     for(i=1;i<=m;i++){
    	 temp=in.nextInt();
    	 bmin=Math.min(bmin, temp);
     }

     if(amin==bmin){
    	 System.out.println(amin);
    	 return;
     }
     if(amin<bmin){
    	 temp=amin;
    	 amin=bmin;
    	 bmin=temp;
     }
     if(bmin!=0){
    	 System.out.println((bmin*10+amin));
     }
     else{
    	 System.out.println((amin*10));
     }

 }


import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int size1=sc.nextInt();
        int size2=sc.nextInt();
        int[] arr1=new int[size1];
        int[] arr2=new int[size2];
        for(int i=0;i<size1;i++)arr1[i]=sc.nextInt();
        for(int i=0;i<size2;i++)arr2[i]=sc.nextInt();
        Arrays.sort(arr1);
        Arrays.sort(arr2);
        boolean flag2=false;
        for(int i=0;i<size1;i++){
            boolean flag=false;
            for(int j=0;j<size2;j++){
                if(arr1[i]==arr2[i]){
                    System.out.println(arr1[i]);
                    flag=true;
                    break;
                }
            }
            if(flag){flag2=true;break;}
        }
        if(flag2)continue;
        if(arr1[0]==arr2[0])System.out.println(arr1[0]);
        else if(arr1[0]<arr2[0]) System.out.println(arr1[0]+""+arr2[0]);

        else if(arr1[0]>arr2[0]) System.out.println(arr2[0]+""+arr1[0]);
    }
}


public class Main {

  public static boolean search (Integer[] arr, int key, int min, int max) {
    if (max < min) {
      return false;
    } else if (arr[(max - min)/2] == key) {
      return true;
    }
    else if (arr[(max - min)/2] > key) {
      return search(arr, key, min, (max - min)/2);
    }
    else {
      return search(arr, key, (max - min)/2, max);
    }
  }

  public static int findMin (Integer[] arr) {
    int min = arr[0];
    for (int i = 1; i < arr.length; i++) {
      if (arr[i] < min) {
        min = arr[i];
      }
    }
    return min;
  }

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int lenOne = in.nextInt();
    int lenTwo = in.nextInt();
    Integer[] arrOne = new Integer[lenOne];
    Integer[] arrTwo = new Integer[lenTwo];
    ArrayList common = new ArrayList();

    for (int i = 0; i < lenOne; i++) {
      arrOne[i] = in.nextInt();
    }
    for (int i = 0; i < lenTwo; i++) {
      arrTwo[i] = in.nextInt();
    }
    for (int i = 0; i < lenOne; i++) {
      if (search(arrTwo, arrOne[i], 0, arrTwo.length)) {
        common.add(arrOne[i]);
      }
    }
    if (!common.isEmpty()) {
      int retVal = findMin((Integer[]) common.toArray());
      System.out.println(retVal);
    } else {
      int digitOne = findMin(arrOne);
      int digitTwo = findMin(arrTwo);
      if (digitOne <= digitTwo) {
        System.out.println(digitOne*10 + digitTwo);
      } else {
        System.out.println(digitTwo*10 + digitOne);
      }
    }
  }
}


import java.util.*;
public class KK{

    public static Scanner scn = new Scanner(System.in);

    public static int findMin(int[] arr, int n){
      int min = arr[0];

      for (int i=0; i<n;i++ ) {
        if(arr[i]<min) min = arr[i];
      }

      return min;
    }

    public static void  main(String ... lovatics){

      int n = scn.nextInt();
      int m = scn.nextInt();
      int x[] = new int [10];

      int arr[] = new int[n];
      int brr[] = new int[m];

      for (int i=0;i<n ;i++ ) {
        arr[i] = scn.nextInt();
        x[arr[i]]++;
      }

       for (int i=0;i<m ;i++ ) {
        brr[i] = scn.nextInt();
        x[arr[i]]++;
      }

boolean flag ;
      for (int i=0; i<10; i++) {
        if(x[i]==2) {
          System.out.println(i);
          flag = true;
        }
      }

      int a = findMin(arr, n);
      int b = findMin(brr, m);

      if(!flag )
      if(a==b) System.out.println(a);
      else if(a<b) System.out.println((a*10+b));
      else System.out.println((b*10+a));

  }
}


public class Suits {

    public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
    int a = input.nextInt();
    int b = input.nextInt();
    int c = input.nextInt();
    int d = input.nextInt();
    int e = input.nextInt();
    int f = input.nextInt();

    if(f > e)
    {
        int min1 , result1 ;
        min1 = min(b,c,d);
        result1 = min1 * f;
        b = b - min1;
        c = c - min1;
        d = d - min1;
        if( d > 0)
        {
            int min2 , result2;
            min2 = Math.min(a,d);
            result2 = min2 * e;
            System.out.println(result1+result2);
        }
        else{
        System.out.println(result1);
            }
    }

    if(e > f)
    {
        int min1, result1;
        min1 = Math.min(a,d);
        result1 = min1 * e;
        a = a - min1;
        d = d - min1;
        if( d > 0)
        {
            int min2 , result2;
            min2 = min(b,c,d);
            result2 = min2 * f;
            System.out.println(result1+result2);
        }
        else
        {
            System.out.println(result1);
        }
    }
    }
    public static int min(int a , int b ,int c)
    {
       int m = Math.min(a,b);
       return Math.min(m,c);
    }

}


miport java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.math.BigInteger;
  import java.util.*;
 public class GraphAdjacencyList
{

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    static int bin(String st)
    {
        int ans=0;
        int ind=0;
        for(int i=st.length()-1;i>=0;i--)
        {
            ans+=((int)st.charAt(i)-48)*(int)Math.pow(2, ind++);
        }
        return ans;

    }
//    static String binn(int a)
//    {
//        String s="";
//        while(a!=0)
//        {
//            s=Integer.toString(a%2)+s;
//            a/=2;
//        }
//        return s;
//    }
    public static void main(String[] args)
    {
        FastReader s=new FastReader();
        int t=s.nextInt();
        while(t-->0)
        {
       int a=s.nextInt();
       int b=s.nextInt();
              int c=s.nextInt();
 int d=s.nextInt();
       int e=s.nextInt();
       int f=s.nextInt();
int cost=0;
       if(e>f)
       {
           int val=0;
           if(a>d)
               val=d;
           else
               val=a;
           cost+=val*e;
           d-=val;
           val=(int)Math.min(b, Math.min(c, d));
           cost+=val*f;
       }
       else
       {
            int val=0;
             val=(int)Math.min(b, Math.min(c, d));

           cost+=val*f;
           d-=val;
           if(a>d)
               val=d;
           else
               val=a;
           cost+=val*e;

       }
             System.out.println
                     (cost);

    }
 }
 }


import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long a=sc.nextInt();
		long b=sc.nextInt();
		long c=sc.nextInt();
		long d=sc.nextInt();
		long e=sc.nextInt();
		long f=sc.nextInt();
		long x=Math.min(b,c);
		long m=Math.min(a,d)*e+Math.min(x,(d-Math.min(a,d)))*f;
		long n=Math.min(x,d)*f+Math.min(a,(d-Math.min(x,d)))*e;
		System.out.println(Math.max(ans,ans1));
	}
}


public class Suits_1271A {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int ties = input.nextInt();
		int scarves = input.nextInt();
		int vests = input.nextInt();
		int jackets = input.nextInt();
		int costF = input.nextInt();
		int costS = input.nextInt();
		int cost = 0, min = 0;
		if (costS > costF) {
			min = Math.min(scarves, Math.min(vests, jackets));
			cost += min * costS;
			scarves -= min;
			vests -= min;
			jackets -= min;
			min = Math.min(ties, jackets);
			cost += min * costF;
		} else {
			min = Math.min(ties, jackets);
			cost += min * costF;
			ties -= min;
			jackets -= min;
			min = Math.min(scarves, Math.min(vests, jackets));
			cost += min * costS;
			scarves -= min;
			vests -= min;
			jackets -= min;
		}
		System.out.println(cost);
		input.close();
	}
}


import java.util.*;

public class now{
	public static void main(String[]args){
		Scanner in = new Scanner(System.in);
		BigInteger x = in.nextBigInteger();
		BigInteger y = in.nextBigInteger();
		while (x != y){
			if (x > y)
				x = x - y;
			else
				y = y - x;
		}
		System.out.println("The GCD is " + x);
	}
}


public class Solution{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String a= scanner.nextString();
        String b = scanner.nextString();
        if(a.equals(b)) System.out.println(a);
        System.out.prtinln("1");
        return;
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;

public class solver {

	public static String nod(BigInteger a, BigInteger b){

		BigInteger c;

		if(a.compareTo(b) < 0){
			c = a;
			a = b;
			b = c;
		}

		while(! a.mod(b).equals(BigInteger.ZERO)){
			c = a.mod(b);
			a = b;
			b = c;
		}

		return b.toString();

	}
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out, "utf-8"));

		StringTokenizer st = new StringTokenizer(in.readLine());

		BigInteger a = new BigInteger(st.nextToken()), b = new BigInteger(st.nextToken());

		out.write( nod(a,b));

		out.flush();
		System.exit(0);
	}

}


import java.math.BigInteger;
import java.util.*;
public class code{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int ans = 0;
	BigInteger a,b,x;
	a=sc.nextBigInteger();
	b=sc.nextBigInteger();

	System.out.println(a.equals(b)?a:1);

	}


import java.lang.Math; // headers MUST be above the first class
import java.util.*;

// one class needs to have a main() method
public class HelloWorld
{
  // arguments are passed using the text field below this editor
  public static void main(String[] args)
  {
    Scanner cin = new Scanner(System.in);
    String ret = "";

    int[][] m = new int [3][3];

    for(int i = 0; i < 3; i++){
        String line= cin.next();
        for(int j = 0; j < 3; j++){
           char a = line.charAt(j);
           if(a == '.'){
               m[i][j] = -1;
           }
           else if (a =='X'){
               m[i][j] = 1;
           }
           else {
               m[i][j] = 0;
           }
        }
    }

    int num_x = 0, num_o = 0;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            if(m[i][j] == 1){
                num_x++;
            }
            else if(m[i][j] == 0){
                num_o++;
            }
        }
    }

    if(num_x > 4 || num_o > 4 || num_x - num_o < 0 || num_x - num_o > 1){
        ret = "illegal";
        System.out.println(ret);
        return;
    }

    if(num_x - num_o == 1 && !ret.equals("illegal")){
        ret = "second";
    }
    else if(num_x - num_o == 0 && !ret.equals("illegal")){
        ret = "first";
    }

    boolean first_won = false, second_won = false;
    if(pure_row(m, 0, 1) || pure_row(m, 1, 1) || pure_row(m, 2, 1)
    || pure_col(m, 0, 1) || pure_col(m, 1, 1) || pure_col(m, 2, 1)
    || pure_cross1(m,1) || pure_cross2(m,1)){
        first_won = true;
    }

    if(pure_row(m, 0, 0) || pure_row(m, 1, 0) || pure_row(m, 2, 0)
    || pure_col(m, 0, 0) || pure_col(m, 1, 0) || pure_col(m, 2, 0)
    || pure_cross1(m, 0) || pure_cross2(m, 0)){
        second_won = true;
    }

    //draw

    if (first_won && second_won){
        ret = "draw";
        System.output.println(ret);
        return;
    }
    else if(first_won){
        ret = "the first player won";
    }
    else if(second_won){
        ret = "the second player won";
    }
    else if(!(playable_row(m, 0) || playable_row(m, 1) || playable_row(m, 2)
      || playable_col(m, 0) || playable_col(m, 1) || playable_col(m, 2)
      || playable_cross1(m) || playable_cross2(m))){
        ret = "draw";
     }

     System.out.println(ret);
  }

  static boolean playable_row(int[][]m, int row){
      boolean p1= true, p2 = true;
      for(int i = 0; i < 3; i++){
          if (m[row][i] == 0){
              p1 = false;
          }
          if (m[row][i] == 1){
              p2 = false;
          }
      }
      return (p1 || p2);
  }

  static boolean playable_col(int[][]m, int col){
      boolean p1= true, p2 = true;
      for(int i = 0; i < 3; i++){
          if (m[i][col] == 0){
              p1 = false;
          }
          if (m[i][col] == 1){
              p2 = false;
          }
      }
      return (p1 || p2);
  }

    static boolean playable_cross1(int[][]m){
      boolean p1= true, p2 = true;
      for(int i = 0; i < 3; i++){
          if (m[i][i] == 0){
              p1 = false;
          }
          if (m[i][i] == 1){
              p2 = false;
          }
      }
      return (p1 || p2);
  }
  static boolean playable_cross2(int[][]m){
      boolean p1= true, p2 = true;
      for(int i = 0; i < 3; i++){
          if (m[i][2-i] == 0){
              p1 = false;
          }
          if (m[i][2-i] == 1){
              p2 = false;
          }
      }
      return (p1 || p2);
  }

  static boolean pure_row(int [][] m, int row, int player){
      boolean n = true;
      for(int i = 0; i < 3; i++){
          if (m[row][i] != player){
              n = false;
          }
      }
      return n;
  }
  static  boolean pure_col(int [][] m, int col, int player){
        boolean n = true;
        for(int i = 0; i < 3; i++){
            if(m[i][col] != player){
                n = false;
            }
        }
        return n;
      }

  static boolean pure_cross1(int[][] m, int player){
        boolean n = true;
        for(int i = 0; i < 3; i++){
            if(m[i][i] != player){
                n = false;
            }
        }
        return n;
  }
  static boolean pure_cross2(int[][] m, int player){
        boolean n = true;
        for(int i = 0; i < 3; i++){
            if(m[i][2-i] != player){
                n = false;
            }
        }
        return n;
  }

}


import java.util.*;
import java.io.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        char[][] board = new char[3][3];
        for(int i = 0; i < 3; i++)
            board[i] = in.nextLine().toCharArray();
        // now test board
        // how is it illegal?
        // more than one difference
        boolean fwin = win(board, 'X'),
                swin = win(board, 'O');
        int c1 = count(board, 'X'), c2 = count(board, 'O');
        if(fwin && swin || Math.abs(c1 - c2) > 1) System.out.println("illegal");
        if(fwin) System.out.println("the first player won");
        if(swin) System.out.println("the second player won");
        if(filled(board)) System.out.println("draw");
        if(c1 > c2) System.out.println("second");
        else System.out.println("first");
    }

    static boolean filled(char[][] board)
    {
        return count(board, '.') == 0;
    }

    static boolean win(char[][] b, char t)
    {
        for(int i = 0; i < 3; i++)
        {
            if(b[i][0] == b[i][1] && b[i][1] == b[i][2] && b[i][2] == t) return true;
            if(b[0][i] == b[0][i] && b[1][i] == b[2][i] && b[2][i] == t) return true;
        }
        if(b[0][0] == b[1][1] && b[1][1] == b[2][2] && b[2][2] == t) return true;
        if(b[0][2] == b[1][1] && b[1][1] == b[2][0] && b[2][0] == t) return true;

    }

    static int count(char[][] b, char t)
    {
        int re = 0;
        for(char[] bb : b) for(char ch : bb) if(ch == t) re++;
        return re;
    }
}


import java.util.Scanner;
public class Solution{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[][] t = new char[3][3];
        for(int i=0;i<2;i++){
            String tmp = sc.next();
            for(int j=0;j<2;j++) t[i][j] = tmp.charAt(j);
        }
        int cx = 0;
        int co = 0;
        for(int i=0;i<2;i++){
            for(int j=0;j<2;j++){
                if(char[i][j]=='X') cx++;
                if(char[i][j]=='0') co++;
            }
        }
        if(cx+co<9){
            if(cx-co==1) System.out.println("second");
            else if(co-cx==1) System.out.println("first");
            else System.out.println("illegal");
            return;
        }
        if(cx-co!=1&&co-cx!=1){
            System.out.println("illegal");
            return;
        }
        for(int i=0;i<2;i++){
            if(t[0][i]==t[1][i]&&t[1][i]==t[2][i]){
                if(t[2][i]=='0'){
                    System.out.println("the second player won");
                    return;
                }else{
                    System.out.println("the first player won");
                    return;
                }
            }
            if(t[i][0]==t[i][1]&&t[i][1]==t[i][2]){
                if(t[i][2]=='0'){
                    System.out.println("the second player won");
                    return;
                }else{
                    System.out.println("the first player won");
                    return;
                }
            }
        }
        if((t[0][0]==t[1][1]&&t[1][1]==t[2][2]) ||
            (t[0][2]==t[1][1]&&t[1][1]==t[2][0])){
            if(t[1][1]=='0'){
                System.out.println("the second player won");
                return;
            }else{
                System.out.println("the first player won");
                return;
            }
        }
        System.out.println("draw");
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class sol
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        Map<String,Integer> map = new HashMap<>();
        for(int i=1;i<n;i++)
        {
            if(map.containsKey(s.substring(i-1,i)))
            {
                map.put(s.substring(i-1,i),map.get(s.substring(i-1,i))++);
            }
            else
            {
                map.put(s.substring(i-1,i),1);
            }
        }
        int max = 0;
        String ans = "";
        for(Map.Entry e : map.entrySet())
        {
            if((int)e.getValue() > max)
            {
                max = (int)e.getValue();
                ans = (String)e.getKey();
            }
        }
        System.out.println(ans);
    }
}


public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int length = scanner.nextInt();
        scanner.skip("\n");
        String input = scanner.nextLine();
        int res = 0;
        String saveS = null;

        for (int i = 0; i < input.length() - 1;i++){
            int res1 = 0;
            char first = input.charAt(i);
            char second = input.charAt(i+1);
             String doubleS = Character.toString(first) + Character.toString(second);
            for (int i1 = 0; i1 < input.length()-1; i1++){
                first = input.charAt(i1);
                second = input.charAt(i1+1);
                String doubleS1 = Character.toString(first) + Character.toString(second);
                if (doubleS.equals(doubleS1)) res1++;

            }
            if (res1 > res) {res = res1; saveS =doubleS;};
        }

        System.out.print(saveS);
    }
}


import java.util.Scanner;

public class a {
	public static void main(String[] args)
	{ int c=0,large=-100;
	String r=" ";
	Scanner sc =new Scanner(System.in);
	String s = sc.nextLine();

	int l=s.length();
	for(int i=0;i<l-1;i++)
	{
		c=0;
		for(int j=0;j<l-1;j++)
		{
			int k= s.substring(i,i+2).compareTo(s.substring(j,j+2));
			if(k==0)

				c++;

		}
		if(c>large)
		{large=c;
		r=s.substring(i,i+2);
		}

	}
	System.out.println(r);

	}


import java.util.*;
public class codeforces{
    private static Scanner scan;
    public static void main(String args[]){
        scan=new Scanner(System.in);

        int n=scan.nextInt();
        String s=scan.nextLine();
        int i;
        String [] substring=new string[s.length];

        for(i=0;i<s.length()-1;i++){

          String temp = String.valueOf(s.charAt(i))+String.valueOf(s.charAt(i+1));

          substring[i]=temp;
        }
        int j=0;
        count=1;
        String sub='';
        int Max=Integer.MIN_VALUE;
        for(i=0;i<substring.length();i++){

            count=1;
            for(j=i+1;j<substring.length();j++){
                if(substring[i].equals(substring[j])){
                    count++;
                }
            }
            if(count>Max){
            Max=count;
            sub=substring[i];
            }
        }
        System.out.println(sub);
    }
}


import org.bouncycastle.util.Arrays;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class A {
	public static void main(String... args) throws IOException {
		long time = 0;
		if(args.length != 0) {
			System.setIn(new FileInputStream(args[0]));
			time = System.currentTimeMillis();
		} else if(!Boolean.parseBoolean(System.getProperty("ONLINE_JUDGE"))) {
			main("input.txt");
			return;
		}
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		List<Integer> r = new ArrayList<Integer>();
		for(int i = 1; n != 0; i++) {
			if((n & 1) != 0)
				r.add(i);
			n >>>= 1;
		}
		Collections.reverse(r);
		for(int i = 0; i < r.size(); i++) {
			if(i != 0)
				System.out.print(' ');
			System.out.print(r.get(i));
		}
		System.out.println();

		if(time != 0)
			System.out.println(System.currentTimeMillis() - time);
	}
}


import java.util.Scanner;
public class CF618A
{
  public static void main(String[] args)
  {
    Scanner scan=new Scanner(System.in);
    int n=scan.nextInt();
    int t=n;
    int l=0;
    while(temp>0)
    {
      temp>>=1;
      ++l
    }
    temp=1<<(l-1);
    String s="";
    for(int i=l;i>0;--i)
    {
      if(n&temp!=0)
        s+=(s.lenth==0?i:(" "+i));
      temp>>=1;
    }
    System.out.print(s);
  }
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class abc {

	public static void main(String[] args) {
		Stack st = new Stack(0);
		int n;
		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		for(int i=0;i<n;i++){
			st.push(1);
			st.check();
		}
		st.print();
	}
}

	public class Stack {
	    int max;
	    int key[];
	    int index;
	    int count;
	    Stack(int h){
	    	this.max=100000;
	    	this.index=0;
	    	count=0;
	    	this.key = new int[100000];
	    }
	    public void push(int x){
	    	if(index==max){
	    		return ;
	    	}
	    	else {
	    		key[index]=x;
	    		index++;
	    		count++;
	    	}
	    }
	    public int pop(){
	    	if(index<=0)
	    		return 0;
	    	else {
	    		count--;
	    		return key[--index];

	    	}
	    }
	    public void check(){
	    	while((index-2)>=0&&key[index-1]==key[index-2]){
	    		key[index-2]=key[index-2]+1;
	    		index--;
	    		count--;
	    	}
	    }
	    public void print(){
	    	for(int i=0;i<index;i++)
	    		System.out.println(key[i]+" ");
	    }

}


import java.util.Scanner;

public class RoundWunderA {

	static int[] power = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536};

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int i;
		while (num > 0) {
			for (i = 0; i < power.length; i++) {
				if (power[i] > num && power[i] / 2 <= num) {
					System.out.print(i + " ");
					num -= power[i - 1];
				}
			}
		}
		System.out.println();
		in.close();
	}
}


public class SolutionB {

      public static void main(String args[])throws IOException{
              Scanner sc = new Scanner(System.in);
              int a = sc.nextInt();
              int b = sc.nextInt();
              int mask = 0;
              a++;
              while(mask != b){
                     int m = 1;
                     int d = a;
                     mask = 0;
                     while(d > 0){
                            int dig = d % 10;
                            d /= 10;
                            if((dig == 4) || (dig == 7)){
                                   mask = m * dig + mask;
                                   m *= 10;
                            }
                     }
                    // System.out.println(mask);
                     if(mask == b)break;
                     a++;
              }
              System.out.println(a);
      }
}


package Problems;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class CF_146B_LuckyMask {
	static int luckyDivision(int num){
		int resultt = 0 ;
		int mult = 1;
		while(num>0){
		if(num%10==7||num%10==4){result+=num%10*mult;mult*=10; }
		num=num/10;
		}
	return resultt ;
	}
public static void main(String[]args)throws Exception{
Scanner sc = new Scanner(System.in);
int a  = sc.nextInt();
int b = sc.nextInt();
if(b>a){
	System.out.println(b);
	return;
}

int result = a+1;
while( luckyDivision(result)!=b){
	result++;
}
System.out.println(result);
}
}


public class B104 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n1=in.nextInt();
        int n2=in.nextInt();

        String n=String.valueOf(n1);
        String m=String.valueOf(n2);
        boolean flag=false;

        for(int i=n1+1;i<100000;i++){
            String now=String.valueOf(i);
            for(int j=0;j<now.length();j++){

                if(m.indexOf(now.charAt(j))>=0) {m=m.replaceFirst(""+now.charAt(j),"");}

            }
            if(m.equals("")) {System.out.println(i);break;}
            m=String.valueOf(n2);
        }

    }

}


//package CF;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {
    public static boolean check(String a, String b){
	int i = 0, j = 0;
	for (; i < a.length(); i++)
	{
	    if(a.charAt(i) == b.charAt(j))
		j++;
	}
	return j >= b.length();
    }
    public static void main(String[] args) throws IOException
    {
	Scanner bf = new Scanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	int a = bf.nextInt();
	String b = bf.next();
	int c = a+1;
	while(!check(""+c,b))
	    c++;
	out.println(c);
	out.flush();
	out.close();
    }
    static class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s)
	{
	    br = new BufferedReader(new InputStreamReader(s));
	}

	public String next() throws IOException
	{
	    while (st == null || !st.hasMoreTokens())
		st = new StringTokenizer(br.readLine());
	    return st.nextToken();
	}

	public int nextInt() throws IOException
	{
	    return Integer.parseInt(next());
	}

	public long nextLong() throws IOException
	{
	    return Long.parseLong(next());
	}

	public String nextLine() throws IOException
	{
	    return br.readLine();
	}

	public double nextDouble() throws IOException
	{
	    String x = next();
	    StringBuilder sb = new StringBuilder("0");
	    double res = 0, f = 1;
	    boolean dec = false, neg = false;
	    int start = 0;
	    if (x.charAt(0) == '-')
	    {
		neg = true;
		start++;
	    }
	    for (int i = start; i < x.length(); i++)
		if (x.charAt(i) == '.')
		{
		    res = Long.parseLong(sb.toString());
		    sb = new StringBuilder("0");
		    dec = true;
		} else
		{
		    sb.append(x.charAt(i));
		    if (dec)
			f *= 10;
		}
	    res += Long.parseLong(sb.toString()) / f;
	    return res * (neg ? -1 : 1);
	}

	public boolean ready() throws IOException
	{
	    return br.ready();
	}
    }

}


import java.util.Scanner;
public class Main{
    public int add(int a,int b){
        return a+b;
    }

    public static void main(String[] args){
        int[] arr=new int[2];
        for(int i=0;i<2;i++){
            Scanner in =new Scanner(System.in);
            arr[i]=in.nextInt();
        }

        System.out.println(add(arr[0],arr[1]));
    }
}


import java.util.Scanner;

public class SUM {

    /**
     * @param args

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println((long) sc.nextInt() + sc.nextInt());
        sc.close();

    }
}


public class Main {

	public static void main(String [] args) {
		Scanner sc= new Scanner(System.in);
		boolean flag=false;
		int x=0,y=0;
		while(!flag){
			try {
				flag=true;
				 x= sc.nextInt();
				if(x<0 || x>1000){
					flag=false;
				}
			}
		catch (Exception e) {
		flag=false;
		}

		}
		 flag=false;
		while(!flag){
			try {
				flag=true;
				 y= sc.nextInt();
				if(y<0 || y>1000){
					flag=false;
				}
			}
		catch (Exception e) {
		flag=false;
		}
		}

		System.out.println(x+y);
	}
}


public class ElsagheerFools {

	public static void main(String [] args) throws IOException{

		System.out.println(1000);
	}
}


import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner Sc = new Scanner(System.in);
        int r = Sc.nextInt();
        int c = Sc.nextInt();
        int r_empty = 0;
        int c_vis[] = new [c];
        int cnt = 0;

        String s[] = new String[r];
        for(int i = 0 ; i < r ; i++)
        {
            s[i] = Sc.next();
            if(s[i].indexOf('S') == -1)
            {
                cnt += c;
                r_empty++;

            }
            else
            {
                c_vis[s[i].indexOf('S')] = 1;
            }
        }

        for(int i = 0 ; i < c; i++)
        {
            if(c_vis[i] != 1) cnt += (r - r_empty);
        }

        System.out.println(cnt);

    }
}


public class Codeforce {

	public static void main(String[]  args){

		Scanner scan = new Scanner(System.in);

		 int r, c, count = 0, total = 0;

		 r = scan.nextInt();
		 c = scan.nextInt();

		 String str[] = new String[r];
		 int row[] = new int[r];

		 scan.nextLine();

		for(int i=0; i < r; i++){
			str[i] = scan.nextLine();
		}

		for(int i=0; i < r; i++){
			for(int j=0; j < c; j++){
				if(str[i].charAt(j) != 'S')
					count++;
				else
					break;
			}
			if(count == c){
				total += count;
				row[i] = 1;
			}
			count = 0;
		}
		count = 0;

		for(int i=0; i < c; i++){
			for(int j=0; j < r; j++){
				if(str[j].charAt(i) == 'S'){
					count = 0;
					break;
				}
				else if(row[j] != 1)
					count++;
			}

			total  += count;
		}
		System.out.println(total);

	}
}


import java.util.*;
import java.io.*;
public class Pretty {

	public static void main(String[] args) throws IOException {
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int m = stdin.nextInt();
		int [] a = new int[n];
		int [] b = new int[m];
		unordered_map < int,int > mp,mp2;

	}

}

Binary Search, Music Notes, Costume Party, Team Tic Tac Toe

/*
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,a[10],b[10];
    cin >> n >> m;
    unordered_map < int,int > mp,mp2;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        mp[a[i]] = 1;
    }
    for(int i=0;i<m;i++)
    {
        cin >> b[i];
        mp2[b[i]] = 1;
    }
    sort(a,a+n);
    sort(b,b+m);
    for(int i=1;i<=9;i++)
    {
        if(mp[i]==1 && mp2[i]==1)
        {
            cout << i << endl;
            return 0;
        }
    }
    if(a[0]>b[0])
        swap(a[0],b[0]);
    cout << a[0] << b[0] << endl;
}
*/


import java.util.Scanner ;
public class Main{
public static void main(String[] args)
{
 int r , c , k ,count;
Scanner in = new Scanner(System.in) ;
r= in.nextInt() ;
c = in.nextInt() ;

char[][] cr = new char[r][c] ;
for( int i = 0 ; i < r ; i++)
 for( int j =0 ; j < c ; j++)
  cr[i][j] = in.nextInt() ;
for(int i = 0 ; i < r; i++)
{
  k = c ;
  for(int j = 0 ; j < c ; j++)
   {
     if( cr[i][j] == 'S')
      break ;
     k-- ;
   }
   if( k== 0)
    for( int j = 0 ; j < c; j++)
       cr[i][j] = '*' ;
}
for( int j = 0 ; j < c; j++)
{ k = r ;
  for( int i = 0 ; i < r ; i++)
  { if(cr[i][j] == 'S')
     break ;
   k--
  }
  if( k== 0)
   for( int i= 0 ; i <r ; i++)
     cr[i][j] = '*' ;
}
for( int i =0 ; i < r; i++)
 for( int j = 0 ; j < c ;j++)
  if( cr[ i][j] == '*')
    count ++ ;
System.out.println( count) ;
}
}


(totalup%2!=0&&totaldown%2==0)||(totalup%2==0&&totaldown%2!=0)import java.util.Scanner;
public class dominos {
   public static void main(String[] args)
   {
    Scanner S=new Scanner(System.in);
    int n=S.nextInt();
    int x[]=new int [n];
    int y[]=new int [n];

    int o,totalup=0,totaldown=0;

    for (int i=0;i<n;i++)
    {
        x[i]=S.nextInt();
        totalup+=x[i];
        y[i]=S.nextInt();
        totaldown+=y[i];
    }
    if (n==1)
    {
        if(totalup%2!=0||totaldown%2!=0)System.out.println(-1);
        else System.out.println(0);
    }
    else
    {
        if(totalup%2==0&&totaldown%2==0)System.out.println(0);
        else if(totalup%2!=0&&totaldown%2!=0)System.out.println(1);
        else
            System.out.println(-1);

    }

    }

}


public class EvenDomino {

	public static void main(String[] args) {
		java.util.Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt(); in.nextLine();

		java.util.ArrayList<Integer> top = new java.util.ArrayList<Integer>();
		java.util.ArrayList<Integer> bot = new java.util.ArrayList<Integer>();
		boolean diff1 = false, diff2 = false;
		for ( int i = 0; i < n; i++ ) {
			String [] inp = in.nextLine().split(" ");
			int t = Integer.parseInt(inp[0]), b = Integer.parseInt(inp[1]);

			if( diff1 && (t != b ))
				diff2 = true;
			if ( t != b )
				diff1 = true;

			top.add(t);
			bot.add(b);
		}

		boolean t = sum(top)%2 == 0, b = sum(bot)%2==0;

		if ( t && b) {
			System.out.println(0);
		}
		else if ( !t && !b && top.size() > 1 && diff) {
			System.out.println(1);
		}
		else
			System.out.println(-1);

	}

	public static int sum(java.util.ArrayList<Integer> a) {
		int sum = 0;
		for ( int i : a )
			sum += i;
		return sum;
	}

}


import java.util.*;
public class A
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int sum1=0,sum2=0;
        int n=sc.nextInt();
        int nn=n,flag=0;
        while(n-->0)
        {
            int x=sc.nextInt();
            int y=sc.nextInt();
            if(x%2==0&&y%2==1||x%2==1&&y%2==0)
            flag=1;
            sum1+=x;
            sum2+=y;
        }
        if(sum1%2==0&&sum2%2==0)
        System.out.println(0);
        else if(sum1%2==0&&sum2%2==1||sum1%2==1&&sum2%2==0)
        System.out.println(-1);
        else(sum1%2==1&&sum2%2==1)
        {
            if(flag==1)
            System.out.println(1);
            else
            System.out.println(-1);
        }
    }
}


public class Problem353ADomino {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int s1 = 0;
		int s2 = 0;
		int count = 0;
		for(int i=0;i<n;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			s1+=a;
			s2+=b;
			if(a%2 != b%2) {
				count++;
			}
			if(a%2==0 && b%2==0) {
				System.out.println('0');
			}
			else if(count>0 && count%2==0) {
				System.out.println('1');
			}
			else {
				System.out.println("-1");
			}
		}

	}

}


import java.io.*;
import java.util.*;

public class c
{
	static final long MOD = 1000000007;
	public static void main(String[] args)
	{
		FastScanner in = new FastScanner();
		int n = in.nextInt();
		int m = in.nextInt();
		ArrayList<Integer> adj[] = new ArrayList[2*n];
		int comp[] = new int[2*n];
		for(int i = 0; i < 2*n; i++)
			adj[i] = new ArrayList<>();

		for(int i = 0; i < m; i++)
		{
			int a = in.nextInt()-1;
			int b = in.nextInt()-1;
			int c = in.nextInt();

			if(c == 1) // love
			{
				adj[a].add(b);
				adj[b].add(a);
				adj[a+n].add(b+n);
				adj[b+n].add(a+n);
			}
			else
			{
				adj[a].add(b+n);
				adj[b+n].add(a);
				adj[b].add(a+n);
				adj[a+n].add(b);
			}
		}

		int id = 1;
		for(int i = 0; i < 2*n; i++)
		{
			if(comp[i] != 0) continue;

			ArrayDeque<Integer> q = new ArrayDeque<>();
			q.add(i);
			comp[i] = id;
			while(!q.isEmpty())
			{
				int u = q.poll();

				for(int v : adj[u])
				{
					if(comp[v] != 0) continue;
					comp[v] = id;
					q.add(v);
				}
			}

			id++;
		}
		id--;

		boolean flag = true;
		for(int i = 0; i < n; i++)
			if(comp[i] == comp[i+n])
				flag = false;

		if(flag)
			System.out.println(pow(2, (id/2)-1));
		else
			System.out.println(0);
	}

	private static long pow(long b, int e)
	{
		if(e == 0)
			return 1;
		if(e == 1)
			return b;

		long ret = pow(b, e/2);
		ret = (ret * ret) % MOD;
		if((e & 1) == 1)
			ret = (ret * b) % MOD;

		return ret;
	}

	public static class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s)
		{
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken()
		{
			while (st == null || !st.hasMoreElements())
			{
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(nextToken());
		}

		long nextLong()
		{
			return Long.parseLong(nextToken());
		}

		double nextDouble()
		{
			return Double.parseDouble(nextToken());
		}

		String next()
		{
			return nextToken();
		}
	}
}


import java.util.*;

public class Main {

    static final long MOD = 1_000_000_007;

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt(), M = scan.nextInt();

        long sol = 0;
        for(int i=1;i<=N;i++){
            sol += exp(2, M) - i;
            sol %= MOD;
        }
        sol += MOD;
        sol %= MOD;

        System.out.println(sol);

    }

    public long exp(long a, long b) {
        if(b==0)return 1L;
        long temp = exp(a,b>>1);
        return (b%2)==0 ? (temp*temp)%MOD : (a*((temp*temp)%MOD))%MOD;
    }
}


import java.math.BigInteger;
import java.util.*;

public class Example {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        String s = "1";
        for (int i = 0; i < m; i++) {
            s += "0";
        }
        BigInteger p = new BigInteger("1000000009");
        BigInteger x = (new BigInteger(s, 2)).mod(p);
        BigInteger ans = BigInteger.ONE;
        for (int i = 1; i <= n; i++) {
            x = x.subtract(BigInteger.ONE);
            ans = ans.multiply(x).mod(p);
        }
        System.out.println(ans.toString());
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		StreamInputReader in = new StreamInputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    private static final long MOD = 1000000009;

    public void solve(int testNumber, StreamInputReader in, PrintWriter out) {
        /*int M = 7;
        int num = 0;
        for(int i = 1; i <= M; i++)
            for(int j = 1; j <= M; j++)
                for(int k = 1; k <= M; k++)
                for(int l = 1; l <= M; l++)
                for(int m = 1; m <= M; m++)
                for(int n = 1; n <= M; n++)
                for(int o = 1; o <= M; o++)
                for(int p = 1; p <= M; p++) {
                    int[] A = {i, j, k, l, m, n, o, p};
                    if(!wool(A)) {
                        //out.println(i + " " + j + " " + k + " " + l);
                        num++;
                    }
                }
        out.print(num);*/

        int N = in.nextInt();
        int M = in.nextInt();

        if(N >= (1 << M)) {
            out.print(0);
            return;
        }

        long ways = 1;

        long p = 1;
        for(int i = 0; i < M; i++)
            p = (p << 1) % MOD;

        for(long i = p - 1; i >= p - N; i = (i - 1 + MOD) % MOD) {
            ways = (ways * i) % MOD;
        }

        out.print(ways);
	}

    }

class StreamInputReader extends InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public StreamInputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    }

abstract class InputReader {

    public abstract int read();

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }


//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    public static class Task {

        public class Maxflow {
            class Edge {
                int t, rev;
                long cap, f;
                public Edge(int t, int rev, long cap) {
                    this.t = t;
                    this.rev = rev;
                    this.cap = cap;
                }
            }
            public Maxflow(int n) {
                graph = new List[n];
                for (int i = 0; i < n; i++) {
                    graph[i] = new ArrayList<>();
                }
            }
            List<Edge>[] graph;
            void addEdge(int s, int t, long cap) {
                graph[s].add(new Edge(t, graph[t].size(), cap));
                graph[t].add(new Edge(s, graph[s].size() - 1, 0));
//                System.err.println(s + " " + t + " " + cap);
            }

            boolean dinicBFS(int src, int dest, int[] dist) {
                Arrays.fill(dist, -1);
                dist[src] = 0;
                int[] Q = new int[graph.length];
                int sizeQ = 0;
                Q[sizeQ++] = src;
                for (int i = 0; i < sizeQ; i++) {
                    int u = Q[i];
                    for (Edge e: graph[u]) {
                        if (dist[e.t] < 0 && e.f < e.cap) {
                            dist[e.t] = dist[u] + 1;
                            Q[sizeQ++] = e.t;
                        }
                    }
                }
                return dist[dest] >= 0;
            }

            long dinicDFS(int[] ptr, int[] dist, int dest, int u, long f) {
                if (u == dest) return f;
                for (;ptr[u] < graph[u].size(); ++ptr[u]) {
                    Edge e =  graph[u].get(ptr[u]);
                    if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {
                        long df = dinicDFS(ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));
                        if (df > 0) {
                            e.f += df;
                            graph[e.t].get(e.rev).f -= df;
                            return df;
                        }
                    }
                }
                return 0;
            }

            long maxFLow(int src, int dest) {
                long flow = 0;
                int[] dist = new int[graph.length];
                while (dinicBFS(src, dest, dist)) {
                    int[] ptr = new int[graph.length];
                    while (true) {
                        long df = dinicDFS(ptr, dist, dest, src, Long.MAX_VALUE);
                        if (df == 0) break;
                        flow += df;
                    }
                }
                return flow;
            }
        }

        public class MinCostFlowBF {
            List<Edge>[] graph;
            class Edge {
                int to, f, cap, cost, rev;

                Edge(int v, int cap, int cost, int rev) {
                    this.to = v;
                    this.cap = cap;
                    this.cost = cost;
                    this.rev = rev;
                }
            }

            public MinCostFlowBF(int n) {
                graph = new List[n];
                for (int i = 0; i < n; i++)
                    graph[i] = new ArrayList<Edge>();
            }

            public void addEdge(int s, int t, int cap, int cost) {
                graph[s].add(new Edge(t, cap, cost, graph[t].size()));
                graph[t].add(new Edge(s, 0, -cost, graph[s].size() - 1));
            }

            void bellmanFord(int s, int[] dist, int[] prevnode, int[] prevedge, int[] curflow) {
                int n = graph.length;
                Arrays.fill(dist, 0, n, Integer.MAX_VALUE);
                dist[s] = 0;
                curflow[s] = Integer.MAX_VALUE;
                boolean[] inqueue = new boolean[n];
                int[] q = new int[n];
                int qt = 0;
                q[qt++] = s;
                for (int qh = 0; (qh - qt) % n != 0; qh++) {
                    int u = q[qh % n];
                    inqueue[u] = false;
                    for (int i = 0; i < graph[u].size(); i++) {
                        Edge e = graph[u].get(i);
                        if (e.f >= e.cap)
                            continue;
                        int v = e.to;
                        int ndist = dist[u] + e.cost;
                        if (dist[v] > ndist) {
                            dist[v] = ndist;
                            prevnode[v] = u;
                            prevedge[v] = i;
                            curflow[v] = Math.min(curflow[u], e.cap - e.f);
                            if (!inqueue[v]) {
                                inqueue[v] = true;
                                q[qt++ % n] = v;
                            }
                        }
                    }
                }
            }

            public int[] minCostFlow(int s, int t, int maxf) {
                int n = graph.length;
                int[] dist = new int[n];
                int[] curflow = new int[n];
                int[] prevedge = new int[n];
                int[] prevnode = new int[n];

                int flow = 0;
                int flowCost = 0;
                while (flow < maxf) {
                    bellmanFord(s, dist, prevnode, prevedge, curflow);
                    if (dist[t] == Integer.MAX_VALUE)
                        break;
                    int df = Math.min(curflow[t], maxf - flow);
                    flow += df;
                    for (int v = t; v != s; v = prevnode[v]) {
                        Edge e = graph[prevnode[v]].get(prevedge[v]);
                        e.f += df;
                        graph[v].get(e.rev).f -= df;
                        flowCost += df * e.cost;
                    }
                }
                return new int[]{flow, flowCost};
            }
        }

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int k = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            int[] pos = new int[n];
            for (int i = 0; i < k; i++) {
                pos[sc.nextInt() - 1]++;
            }
            int T = 100;
            MinCostFlowBF mf = new MinCostFlowBF((T + 1) * n + 2);
            for (int i = 0; i < n; i++) {
                if (pos[i] > 0)
                    mf.addEdge(0, i + 1, pos[i], 0);
            }
            for (int i = 0; i < T; i++) {
                for (int j = 0; j < n; j++) {
                    mf.addEdge(1 + i * n + j, 1 + (i + 1) * n + j, k, 0);
                }
            }
            for (int i = 0; i <= T; i++) {
                for (int j = 1; j <= n; j++) {
                    mf.addEdge(1 + i * n, (T + 1) * n + 1, 1, c * i);
                }
            }
            for (int i = 0; i < m; i++) {
                int a = sc.nextInt() - 1;
                int b = sc.nextInt() - 1;
                for (int j = 0; j < T; j++) {
                    int cost = 0;
                    for (int l = 1; l <= k; l++) {
                        mf.addEdge(1 + j * n + a, 1 + (j + 1) * n + b, 1, l * l * d - cost);
                        mf.addEdge(1 + j * n + b, 1 + (j + 1) * n + a, 1, l * l * d - cost);
                        cost = l * l * d;
                    }
                }
            }
            int[] flowAndCost = mf.minCostFlow(0, (T + 1) * n + 1, k);
            System.err.println(flowAndCost[0]);
            pw.println(flowAndCost[1]);
        }
    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("input"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("output"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}