import sun.plugin.javascript.navig.Array;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskA {

    final int LIM = 223456781;
    ArrayList<Integer> lucky;

    void generate(long x) {
        if(x < LIM) lucky.add((int)x);
        else return;

        generate(x * 10 + 4);
        generate(x * 10 + 7);
    }

    void run() {
        this.lucky = new ArrayList<Integer>();
        generate(4);
        generate(7);
        Collections.sort(lucky);

        int[] l = new int[lucky.size()];
        int ix = 0;
        for(int x : lucky) {
            l[ix++] = x;
        }

        int L = nextInt(), R = nextInt();

        int l1 = 0, r1 = lucky.size();
        if(L > l[l1]) {
            while(r1 - l1 > 1) {
                int m1 = l1 + (r1 - l1) / 2;
                if(l[m1] >=  L) r1 = m1;
                else l1 = m1;
            }
        }
        else {
            r1 = 0;
        }

        int l2 = 0, r2 = lucky.size();
        if(R > l[l2]) {
            while(r2 - l2 > 1) {
                int m2 = l2 + (r2 - l2) / 2;
                if (l[m2] >= R) r2 = m2;
                else l2 = m2;
            }
        }
        else {
            r2 = 0;
        }

        long ans = l[r1] * (long)(l[r1] - L + 1);
        for(int i = r1 + 1; i <= r2; i++) {
            ans += l[i] * (long) (l[i] - l[i - 1]);
        }
        ans -= l[r2] * (long) (l[r2] - R);
        System.out.println(ans);
    }

    int nextInt() {
        try {
            int c = System.in.read();
            if (c == -1) return c;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return c;
            }
            if (c == '-') return -nextInt();
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    long nextLong() {
        try {
            int c = System.in.read();
            if (c == -1) return -1;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return -1;
            }
            if (c == '-') return -nextLong();
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

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

    String next() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (Character.isWhitespace(c))
                c = System.in.read();
            do {
                res.append((char) c);
            } while (!Character.isWhitespace(c = System.in.read()));
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

    String nextLine() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (c == '\r' || c == '\n')
                c = System.in.read();
            do {
                res.append((char) c);
                c = System.in.read();
            } while (c != '\r' && c != '\n');
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

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


public class Main{
    public static void main(String [] Args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        a*=2;
        char inp ;
        int [] arr = new int [10];
        for(int i = 0 ; i < 16 ; i++){
            inp = sc.nextChar();
            if(inp >=48 && inp <= 57)
                arr[inp-48]++ ;
        }
        bool f = true ;
        for(int i = 0 ; i < 10 ; i++)
            if(arr[i] > a)
                f = false ;

        if(f)
            System.out.println("YES");
        else
            System.out.println("NO");

    }

}


public class Main {

    public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        a*=2;
        String [] inp = new String [4];
        int [] arr = new int [10];
        for(int i = 0 ; i < 4 ; i++){
            inp[i] = sc.next();
            for(int j = 0 ; j < 4 ; j++)
                if(inp[i].charAt(j) >=48 && inp[i].charAt(j) <= 57)
                    arr[(int)inp[i].charAt(j)-48]++ ;
        }
        boolean f ;
        f = true;
        for(int i = 0 ; i < 10 ; i++)
            if(arr[i] > a)
                f = false ;

        if(f)
            System.out.println("YES");
        else
            System.out.println("NO");

    }
}


import java.util.*;

public class Main{
    public static void main(String [] Args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        a*=2;
        char inp ;
        int [] arr = new int [10];
        for(int i = 0 ; i < 16 ; i++){
            inp = sc.nextChar();
            if(inp >=48 && inp <= 57)
                arr[inp-48]++ ;
        }
        bool f = true ;
        for(int i = 0 ; i < 10 ; i++)
            if(arr[i] > a)
                f = false ;

        if(f)
            System.out.println("YES");
        else
            System.out.println("NO");

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author revo
 */
public class Proj1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       int k = Integer.parseInt(in.readLine()) * 2;
       int [] IntArray= new int[10];
       String line="";
        for(int i=0; i< 4 ; i++){
           line += in.readLine();
        }
        boolean valid=true;
        for(int i=0; i<16 ;i++){
            if(Character.isDigit(line.charAt(i))){
                int index = Character.digit(line.charAt(i), 10);

                IntArray[index]++;
                if(k < IntArray[index]) valid=false;
            }
        }

        if(valid){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }


import java.io.*;
import java.util.*;
public class babyehab {
  public static void main(String[] args) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(br.readLine()), total = 0;
    int[] a = new int[N];
    boolean[][] dp = new boolean[100001][101];
    StringToknenizer st = new StringTokenizer(br.readLine());
    for (int i = 0; i < N; i++) {
      a[i] = Integer.parseInt(st.nextToken());
      total += a[i];
    }
    dp[0][0] = true;
    boolean bad = false;
    for (int i = 0; i < 100001; i++) {
      for (int j = 0; j < N; j++) {
        if (i > a[j]) {
          dp[i][j+1] = dp[i][j]||dp[i-a[j]][j];
        }
        if (i*2 == total && dp[i][j+1]) {
          bad = true;
        }
      }
    }
    int trailingZero = Integer.MAX_VALUE;
    if (bad) {
      for (int i = 0; i < N; i++) {
        trailingZero = Math.min(trailingZero, a[i] & -a[i]);
      }
      for (int i = 0; i < N; i++) {
        if ((a[i] & trailingZero) != 0) {
          System.out.println(1);
          System.out.println(a[i]);
          break;
        }
      }
    } else {
      System.out.println(0);
    }
  }
}


import java.io.*;
import java.util.*;
public class babyehab {
  public static void main(String[] args) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(br.readLine()), total = 0;
    int[] a = new int[N];
    boolean[][] dp = new boolean[100001][101];
    StringTokenizer st = new StringTokenizer(br.readLine());
    for (int i = 0; i < N; i++) {
      a[i] = Integer.parseInt(st.nextToken());
      total += a[i];
    }
    dp[0][0] = true;
    boolean bad = false;
    for (int i = 0; i < 100001; i++) {
      for (int j = 0; j < N; j++) {
        if (i > a[j]) {
          dp[i][j+1] = dp[i][j]||dp[i-a[j]][j];
        }
        if (i*2 == total && dp[i][j+1]) {
          bad = true;
        }
      }
    }
    int trailingZero = Integer.MAX_VALUE;
    if (bad) {
      for (int i = 0; i < N; i++) {
        trailingZero = Math.min(trailingZero, a[i] & -a[i]);
      }
      for (int i = 0; i < N; i++) {
        if ((a[i] & trailingZero) != 0) {
          System.out.println(1);
          System.out.println(a[i]);
          break;
        }
      }
    } else {
      System.out.println(0);
    }
  }
}


import java.util.*;
import java.io.*;
public class CF {
    public static void main(String args[]) {
        Integer n = Integer.parseInt(System.console().readLine());
        String[] s = System.console().readLine().split(' ');
        List<Integer> inp = new ArrayList<Integer>();
        Integer sum = 0;
        Integer minval = -1;
        Integer minin = -1;
        for (String ss : s) {
            Integer in = Integer.parseInt(ss);
            sum += in;
            inp.add(in);
        }
        Integer sosum = 0;
        Boolean valid = true;
        for (Integer i = 0; i < n; i++) {
            sosum += inp[i];
            if (sosum * 2 == sum) {
                valid = false;
            }
            if (minval == -1 || minval > inp.get(i)) {
                minval = inp.get(i);
                minin = i;
            }
        }
        if (valid) {
            System.out.println("0");
        }
        else {
            System.out.println("1");
            System.out.println(minin);
        }
    }
}


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

public class Task{
        //  ..............code begins here..............

static long mod=(long)1e9+7,inf=(long)1e17;

static void solve() throws IOException {
            int n=int_v(read());
            int[] a=int_arr();
            int inf=200000000;
            int ts=0,idx=-1;
            sort(a);
            int[][] dp=new int[n+1][ts+1];
            for(int i=0;i<=n;i++){
                for(int j=0;j<=ts;j++){dp[i][j]=inf;}
            }
            for(int i=0;i<=n;i++)dp[i][0]=0;
            for(int s=1;s<=ts;s++){
                for(int i=1;i<=n;i++){
                    if(s>=a[i-1]){
                        dp[i][s]=Math.min(dp[i-1][s-a[i-1]]+1,dp[i-1][s]);
                    }
                    else{
                        dp[i][s]=dp[i-1][s];
                    }
                }
            }
            int g=a[0];
            for(int z:a)g=gcd(g,z);
            for(int i=0;i<n;i++){
                a[i]/=g;
                if(a[i]%2==1)idx=i+1;
            }
            boolean ok=false;
            for(int i=0;i<=n;i++){
                if(dp[i][ts/2]!=inf) ok=true;
            }

            if(!ok){
                out.write("0");return;
            }
            else if(idx!=-1){
                out.write("1\n"+idx+"\n");return;
            }
}
//
public static void main(String[] args) throws  IOException{
                assign();
                int t=1;//int_v(read()),cn=1;
                while(t--!=0){
                    //out.write("Case #"+cn+": ");
                    solve();
                    //cn++;
                }
                out.flush();
}

// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static void sort(int[] a){List<Integer> l=new ArrayList<>();for(int x:a){l.add(x);}Collections.sort(l);for(int i=0;i<a.length;i++){a[i]=l.get(i);}}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//static String setpreciosion(double d,int k){BigDecimal d1 = new BigDecimal(Double.toString(d));return d1.setScale(k,RoundingMode.HALF_UP).toString();}//UP DOWN HALF_UP
static int add(int a,int b){int z=a+b;if(z>=mod)z-=mod;return z;}
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res%m;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
//static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
//static long[] f;
}


/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int b[] = new int[m];
        for(int i = 0;i<m;i++){
            b[i]=sc.nextInt();
        }
        int c[] = new int[n];
        for(int i = 0;i<n;i++){
            c[i]=-1;
        }
        for(int i = 0;i<m;i++){
            for(int x = b[i];x<n;x++){
                if(c[x]=-1){
                    c[x]=i+1;
                }
            }
        }
        for(int i = 0;i<n;i++){
            System.out.println(c[i]);
        }
    }
}


import java.util.*;

public class Test
{
public static void main(String[] args)
{
int n,m;
    Scanner sc=new Scanner(System.in);
n=sc.nextInt();
m=sc.nextInt();
    int[] arr=new int[n];
int[] arr1=new int[n];
    for(int i=0;i<n;i++)
    {
        arr[i]=sc.nextInt();
        arr1[i]=0;
    }
    int pnt=1000;
    int mark=0;
    for(int i=0;i<n;i++)
    {
        ele=arr[i];
        if(arr[i]<pnt)
        {
        for(int j=mark;j<=n-arr[i];j++)
        {
            arr1[j]=ele;
        }
        pnt=arr[i];
        mark=n-arr[i];
        }
    }

    for(int i=n-1;i>=0;i--)
    {
        System.out.println(arr1[i]+" ");
    }
    }
}


public class Main {

    public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int n,m,a[],k;
          a = new int[100];
          n = sc.nextInt();
          m = sc.nextInt();
          for(int i = 0 ; i < m ; i++){
              k = sc.nextInt();
              for(int j = k ; j <= n && a[j] == 0 ; j++)
                  a[j] = k ;
          }
          for(int i = 1 ; i <= n ; i++)
            System.out.print(a[i]+ " ");
    }

}


public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] arr = new int[n+1];
        for(i=1; i<=n; ++i) arr[i]=0;
        for(int i=0; i<m; ++i) {
            int v = sc.nextInt();
            for(int j=v; j<=n; ++j) {
                if(arr[j]==0) arr[j]=v;
            }
        }
        for(int i=1; i<=n; ++i) System.out.print(arr[i]+" ");
    }
}


import java.io.BufferReader;
import java.io.InputStreamReader;

public class Solution throws IOException {
    public static int nineteens(String s) {
            char[] sa= s.toCharArray();
            int n= 0;
            int i= 0;
            int e= 0;
            int t= 0;
            for (int j= 0; j < s.length(); j++ ) {
                if (sa[j] == 'n') n++ ;
                else if (sa[j] == 'i') i++ ;
                else if (sa[j] == 'e') e++ ;
                else if (sa[j] == 't') t++ ;
            }
            return min(min((int) Math.floor(n / 3), (int) Math.floor(e / 3)), min(i, t));
        }

        public static int min(int n, int m) {
            return m > n ? n : m;
        }

        private static final BufferedReader br= new BufferedReader(new InputStreamReader(System.in));

        public static void main(String[] args) {
            String s = br.readLine();
            System.out.println(nineteens(s));
        }
}


public class Nineteen {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		char[] in =  input.toCharArray();
		int hash[] = new int[256];
		for(int i = 0 ; i<in.length ; i++){
			hash[in[i]]++;
		}
		int n = (hash['n']-1)/2;
		int i = hash['i'];
		int t = hash['t'];
		int e = hash['e']/3;
		System.out.println(Math.min(Math.min(n,i), Math.min(t, e)));
	}


public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String q = s.next();
        q.toUpperCase(); // UpperCase is ignored
         char [] a= q.toCharArray();
        int n=0,i=0,e=0,t=0;
        for (char c:a)
        {
            if (c=='n')
                n++;
            else if (c=='i')
                i++;
            else if (c=='e')
                e++;
            else if (c=='t')
                t++;
        }
        int x;
        for(x = 0;true;){

            if(n>=3 && e >= 3 && i >= 1 && t >= 1)
            {	x++;
                n -= 2; e -= 3 ; i--; t--;}
            else break;

        }
        System.out.print(x);

    }
}


import java.util.Scanner;
import java.io.*;
import java.util.Arrays;
import java.util.*;
public class CF2{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s1 = sc.nextLine();
		char[] temp = s1.toCharArray();
		Arrays.sort(temp);
		String s = new String(temp);
		int ln = s.lastIndexOf('n')+1-s.indexOf('n');
		int li = s.lastIndexOf('i')+1-s.indexOf('i');
		int le = (s.lastIndexOf('e')+1-s.indexOf('e'))/3;
		int lt = s.lastIndexOf('t')+1-s.indexOf('t');
		//int ans = Math.min(Mat.min(Math.min(ln,li),le),lt);
		int ans = Math.min(Math.min(le,lt),Math.min(li,li));
		if(ln>= (2*ans+1)){
		    System.out.println(ans);
		}
		else{
		    System.out.println(Math.min(n/3, ans));
		}
	}
}


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

public class Test {
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

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

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

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

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }

	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
		String time = nextToken();
		String result="00:00";
int h = ((int)time.charAt(0))*10+(int)time.charAt(1);
		int mm = int h = ((int)time.charAt(3))*10+(int)time.charAt(4)+1;

		boolean first = true;

		outer:
		for (; h < 24; h++) {
			for (int m = (first ? mm : 0); m < 60; m++) {

				String temp = "";
				if (h < 10) {
					temp += "0";
				}
				temp += "" + h + ":";
				if (m < 10) {
					temp += "0";
				}
				temp += "" + m;
				if (temp.equals(new StringBuffer(temp).reverse().toString())) {
					result = temp;
					break outer;
				}
			}
			first = false;
		}

		writer.println(result);
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Palindrome{
    public static void main(String[] args) throws IOException {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         String brr[]=br.readLine().trim().split(" ");
         String s=brr[0];
         int hour,min,hour1;
         int d,p;
         d=(int)s.charAt(0);
          d-=48;
         hour=d*10;
         hour1=d;
         d=(int)s.charAt(1);
         d-=48;
         hour+=d;
         hour1+=(d*10);
         if(d>=6)
         {
             hour++;
         }
         else
         {
             p=(int)s.charAt(3);
             p-=48;
         min=p*10;
         p=(int)s.charAt(4);
         p-=48;
         min+=p;
         int q;
       //  System.out.println(min+" "+hour1);
         if(min<hour1)
         {
             min=hour1;
          }
         else
         {
             hour++;
         }
             if(hour>=6&&hour<=9)
             {
                 hour=10;
                 min=1;
                 System.out.println(hour+":0"+min);
             }
             else if(hour>=16&&hour<=19)
             {
                 hour=20;
                 min=2;
                 System.out.println(hour+":0"+min);
             }
             else if(hour==24)
                 System.out.println("00:00");
             else
             {
                 p=hour;
                 q=p%10;
                 min=(q*10);
                 p=p/10;
                 q=p%10;
                 min+=q;
                 if(min>9)
                 System.out.println(hour+":"+min);
                 else
                     System.out.println(hour+":0"+min);
             }
             }
             }

         }

         }


import java.util.*;
public class PalindromicTimes {

    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String st=in.next();
    String parts[]=st.split(":");
    int hour=Integer.parseInt(parts[0]);
    int min=Integer.parseInt(parts[1]);
    int rev=(hour%10)*10+(hour/10);

if(hour<23)
{
if(rev<=min)
{hour=hour+1;
rev=(hour%10)*10+(hour/10);

}

}
else
{if(min>32)
{System.out.println("00:00");
System.exit(0);}
else
{hour=23;rev=32;}

}
if(hour<=20&&hour>=16)
{System.out.println("20:02");

}
else if(hour<=10&&hour>=6)
{System.out.println("10:01");}
else if(hour>0&&hour<=5)
{System.out.println("0"+hour+":"+rev);}
else
{System.out.println(hour+":"+rev);}

    }

}
import java.util.*;
public class PalindromicTimes {

    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String st=in.next();
    String parts[]=st.split(":");
    int hour=Integer.parseInt(parts[0]);
    int min=Integer.parseInt(parts[1]);
    int rev=(hour%10)*10+(hour/10);

if(hour<23)
{
if(rev<=min)
{hour=hour+1;
rev=(hour%10)*10+(hour/10);

}

}
else
{if(min>32)
{System.out.println("00:00");
System.exit(0);}
else
{hour=23;rev=32;}

}
if(hour<=20&&hour>=16)
{System.out.println("20:02");

}
else if(hour<=10&&hour>=6)
{System.out.println("10:01");}
else if(hour>0&&hour<=5)
{System.out.println("0"+hour+":"+rev);}
else
{System.out.println(hour+":"+rev);}

    }

}


// enough being stupid
public class Palindromic_Times {

    public static void main(String[] args) {
        Scanner scanner = new Scanner (System.in);
        String inp = scanner.next(),hs,nhs,nms,ms;
        hs = inp.split(":")[0];
        ms = inp.split(":")[1];
        int h = Integer.parseInt(hs),nh,nm,m;
        m=Integer.parseInt(ms);
        nhs=hs;nh=h;
        nms = ""+nhs.charAt(1)+nhs.charAt(0);
        nm = Integer.parseInt(nms);
        if (nm<=m) nm=60;
        while(nm>59){
            nh = (nh+1)%24;
            nhs = Integer.toString(nh);
            if (nhs.length()==1)nhs="0"+nhs;
            nms = ""+nhs.charAt(1)+nhs.charAt(0);
            nm = Integer.parseInt(nms);
        }
        System.out.println(nhs+":"+nms);
    }
}


import java.util.Scanner;
import java.io.PrintWriter;

public class ToyArmy {
   public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
       PrintWriter out = new PrintWriter(System.out);

       int result = (3 * in.nextInt())/2;
       out.println(result)
       out.close();
   }
}


   1. public class Main {
   2.

   3.     public static void main(String... args) {
   4.         java.util.Scanner in = new java.util.Scanner(System.in);
   5.         int n = in.nextInt();
   6.         System.out.println(n / 2 * 3);
   7.     } // main
   8.

   9. } // class Main


public class Solution{

public static void main(String[] args){

     Scanner sc = new Scanner(System.in);
     int n = sc.nextInt();
     System.out.println(n+(n/2));

}

}


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

public class Main
{

    public static void main(String[] args)
 {

Scanner sc = new Scanner(System.in);
int T =sc.nextInt();

int t /=2;
System.out.prinln(t*3);

}


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

public class Main {

	public static void main(String[] args)  throws IOException{
		//code
		BufferedReader in = new BufferedReader(new InputStreamReader (System.in));
		 String temp[] = (in.readLine()).split(" ");
		int n = Integer.parseInt(temp[0]);
		int a = Integer.parseInt(temp[1]);
		int x = Integer.parseInt(temp[2]);
		int b = Integer.parseInt(temp[3]);
		int y = Integer.parseInt(temp[4]);
		ArrayList<Integer> path1 = new ArrayList<Integer>();
		ArrayList<Integer> path2 = new ArrayList<Integer>();
		int c = a;
		if(a>n||x>n||b>n||y>n)
		{
		    System.out.println("NO");

		}
		while(c!=b)
		{
		    if(c!=n)
		    {
		        path1.add(c);
		        c++;
		    }
		    else
		    {
		        path1.add(c);
		        c=1;
		    }
		}
		path1.add(c);
		c=b;
		while(c!=y)
		{

		    if(c!=1)
		    {
		        path2.add(c);
		        c--;
		    }
		    else
		    {
		        path2.add(c);
		        c=n;
		    }
		}
		path2.add(c);
		boolean check = false;
		int n1 = path1.size();
		int n2 = path2.size();
		int t = (n1<n2)?n1:n2;
		for(int i=0; i<t; i++)
		{
		    if(path1.get(i)==path2.get(i))
		    {

		        check = true;
		        break;
		    }
		}
		if(check)
		{
		    System.out.println("YES");
		}
		else
		{
		     System.out.println("NO");
		}

	}}}


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

public class A {

    public static void main(String[] args) throws IOException {
        new A().go();
    }

    int n;

    private void go() throws IOException {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        int n = Integer.parseInt(scanner.next());
        int a = Integer.parseInt(scanner.next());
        int x = Integer.parseInt(scanner.next());
        int b = Integer.parseInt(scanner.next());
        int y = Integer.parseInt(scanner.next());
        if ()
        if (x < y) stop("NO");
        if (b < a) stop("NO");
        double var = ((b - a) + 0.0) / 2;
        if (var != Math.floor(var)) stop("NO");
        System.out.println("YES");
    }

    private void stop(String m) {
        System.out.println(m);
        System.exit(0);
    }

}


import java.util.Scanner;

public class circleMetro {
	static byte n,a,x,b,y;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		n = (byte)scan.nextInt();
		a = (byte)scan.nextInt();
		x = (byte)scan.nextInt();
		b = (byte)scan.nextInt();
		y = (byte)scan.nextInt();
		System.out.println((verify) ? "YES" : "NO");
	}

	public static boolean verify() {
		byte p1 = (byte)(a-1) , p2 = (byte)(b-1);
		while (p1!=x-1 && p2!=y-1 && p1!=p2) {
			p1=(byte)((p1+1)%n);
			p2=(byte)((p2-1)%n);
			if (p1<0) {
				p1+=n;
			}
			if (p2<0) {
				p2+=n;
			}
		}
		return p1==p2;
	}

}


	import java.io.BufferedOutputStream;
	import java.io.BufferedReader;
	import java.io.InputStreamReader;
	import java.io.PrintWriter;
	import java.util.*;

	public class e {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct

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

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	static ArrayList<String>list1=new ArrayList<String>();
	static void combine(String instr, StringBuffer outstr, int index,int k)
	{
		if(outstr.length()==k)
		{
			list1.add(outstr.toString());return;
		}
		if(outstr.toString().length()==0)
		outstr.append(instr.charAt(index));
	    for (int i = 0; i < instr.length(); i++)
	    {
	        outstr.append(instr.charAt(i));

	        combine(instr, outstr, i + 1,k);
	        outstr.deleteCharAt(outstr.length() - 1);
	    }
	   index++;
	}
	static ArrayList<ArrayList<Integer>>l=new ArrayList<>();
	static void comb(int n,int k,int ind,ArrayList<Integer>list)
	{
		if(k==0)
		{
			l.add(new ArrayList<>(list));

			return;
		}

		for(int i=ind;i<=n;i++)
		{
			list.add(i);
			comb(n,k-1,ind+1,list);

			list.remove(list.size()-1);

		}

	}

	static class Pair implements Comparable<Pair>{
	    int x;int y;
	    Pair(int x,int y){
	        this.x=x;
	        this.y=y;
	      //  this.i=i;
	    }
		@Override
		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			return (o.x*y-o.y*x);

		}
	}

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	  static HashMap<Long, Pair> sort(HashMap<Long, Pair> hm)
	    {
	        // Create a list from elements of HashMap
	        List<Map.Entry<Long, Pair> > list =
	               new LinkedList<Map.Entry<Long, Pair> >(hm.entrySet());

	        // Sort the list
	        Collections.sort(list, new Comparator<Map.Entry<Long, Pair> >() {
	            public int compare(Map.Entry<Long, Pair> o1,
	                               Map.Entry<Long, Pair> o2)
	            {
	                return (o1.getValue().y)-(o2.getValue().y);
	            }
	        });

	        // put data from sorted list to hashmap
	        HashMap<Long, Pair> temp = new LinkedHashMap<Long, Pair>();
	        for (Map.Entry<Long, Pair> aa : list) {
	            temp.put(aa.getKey(), aa.getValue());
	        }
	        return temp;
	    }
	  static long ncr(long n, int k)
	    { long m=(long)1e9+7;
	        long C[] = new long[k + 1];

	        // nC0 is 1
	        C[0] = 1;

	        for (int i = 1; i <= n; i++)
	        {
	            // Compute next row of pascal
	            // triangle using the previous row
	            for (int j = Math.min(i, k); j > 0; j--)
	                C[j] = (C[j]%m + C[j-1]%m)%m;
	        }
	        return C[k]%m;
	    }
	  static long high(long n)
	  {

	      long p = (long)(Math.log(n) /
	                    Math.log(2L));
	      return (long)Math.pow(2L, p);
	  }
	  static int findd(int a){
	        if (parent[a]!=a){
	            parent[a] = findd(parent[a]);
	        }
	        return parent[a];
	    }
	 static int parent[];
	 static ArrayList<Integer>list=new ArrayList<Integer>();
	 static HashMap<Integer,Integer>map;
	 static boolean find(int n,int f)
	 {
		 if(map.containsKey(n))
		 {
			 if(map.get(n)>=f)
			 {
				 map.put(n, map.get(n)-f);
				 if(map.get(n)==0)
					 map.remove(n);
				 return true;
			 }
			 else
			 {
				 f-=map.get(n);
				 map.remove(n);
				 if(find(n/2,2*f))
					 return true;
				 else
					 return false;
			 }

		 }
		 else if(n>1)
		 {
			if(find(n/2,2*f))
				return true;
			else
				return false;
		 }
		 else
			 return false;

	 }
		static int CeilIndex(int A[], int l, int r, int key)
		{
			while (r - l > 1) {
				int m = l + (r - l) / 2;
				if (A[m] >= key)
					r = m;
				else
					l = m;
			}

			return r;
		}
static ArrayList<Character>li=new ArrayList<Character>();
		static int LongestIncreasingSubsequenceLength(int A[], int size)
		{
			// Add boundary case, when array size is one

			int[] tailTable = new int[size];
			int len; // always points empty slot

			tailTable[0] = A[0];
			len = 1;
			for (int i = 1; i < size; i++) {
				if (A[i] < tailTable[0])
					// new smallest value
					tailTable[0] = A[i];

				else if (A[i] > tailTable[len - 1])
					// A[i] wants to extend largest subsequence
					tailTable[len++] = A[i];

				else
					// A[i] wants to be current end candidate of an existing
					// subsequence. It will replace ceil value in tailTable
					tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
			}
	      for(int i=0;i<len;i++)
	        System.out.println(tailTable[i]);

			return len;
		}
	 static int common(ArrayList gp[],int a,int b)
	 {
		 int ans=0;
		for(int i=0;i<gp[a].size();i++)
		{
			if(gp[b].contains(gp[a].get(i)))
				ans++;
		}
		 return ans;

	 }

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

		FastReader in=new FastReader();
		//ArrayList<String>list=new ArrayList<String>();

      HashMap<Integer,Integer>map=new HashMap<Integer,Integer>();

    	 int n=in.nextInt();
    	 int a=in.nextInt();
    	 int x=in.nextInt();
    	 int b=in.nextInt();
    	 int y=in.nextInt();

    	 while(a!=x&&b!=y)
    	 {
    		// out.println(a+" "+b);out.flush();
    		 if(a==b)
    		 {
    			 out.println("YES");out.flush();return;
    		 }

    		 a++;
    		 b--;
    		 if(a==b)
    		 {
    			 out.println("YES");out.flush();return;
    		 }
    		 if(a==n)
    			 a=1;
    		 if(b==0)
    			 b=n;
    			  if(a==b)
    		 {

    	 }
    	 out.println("NO");
    	 out.flush();

		}

	}


public class Caps
{
    public static void main(String[] args)
    {
        String input;
        String output;
        Scanner sc= new Scanner(System.in);
        input=sc.nextLine();
        input=input.replace(input.charAt(0), input.charAt(0)-32);
        System.out.println(input);

    }
}


public class WordCapitalizationTest {

	public static void main(String[] args) {
		String str=new Scanner(System.in).next();
		if(str.charAt(0)>90) {
		System.out.println(str.replace(str.charAt(0),(char)(str.charAt(0)-32)));
		}
		else
			System.out.println(str);

	}

}


import java.util.*;
public class Main{
     public static void main(String ... string){
          Scanner sc = new Scanner(System.in);
          String s = sc.nextLine();
          String ans = s.toUpperCase(s.charAt(0) + "");
          String h = "";
          for(int i = 1; i<s.length(); i++)
             h += s.charAt(i)+"";
          System.out.println(ans+h);
     }
}


import java.util.*;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Taxi{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder n = new StringBuilder(br.readLine());
		n.setCharAt(0,n.charAt(0)+('a'-'A'));
		System.out.println(n.toString());

	}
}


import java.io.BufferedReader;
import java.io.InputSteamReader;
public class Q1 {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line = br.readLine();
        String num[] = line.split(" ");
        int first = Integer.valueOf(num[0]);
        int second = Integer.valueOf(num[1]);

        int awin = 0;
        int bwin = 0;
        int ab = 0;
        int mid = (first + second)/2;
        if(first == second) {
            ab = 6;
        } else if(Math.abs(first - mid) == Math.abs(second - mid)) {
            ab = 1;
        }

        if(first < second) {
            awin = mid - ab;
            bwin =  6 - awin - ab;
        } else {
            bwin = mid - ab;
            awin = 6 - bwin - ab;
        }

        System.out.println(awin + " " + ab + " " + bwin);
    }
}


import java.io.*;
import java.sql.Array;
import java.util.*;

public class JavaStudy {
    static Scanner input = new Scanner(System.in);

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

        int a = input.nextInt() ;
        int b = input.nextInt() ;

        int aWins = 0 , bWins = 0 , draw = 0 ;

        for(int i = 1 ; i<= 6 ; i++){
            if (Math.abs(a-i) < Math.abs(b-i)){
                aWins++ ;
            } else if (Math.abs(a-i) > Math.abs(b-i)){
                bWins++ ;
            } else {
                draw++ ;
            }
        }

        System.out.println(aWins + " " + draw + " " + bWins);

//        int[] array = new int[5] ;
//        for (int i = 0 ; i < 5 ; i++){
//            array[i] = input.nextInt();
//        }
//        mergeSort(array,0,array.length -1);
//
//        for (int e: array
//             ) {
//            System.out.print(e + " ") ;
//        }
//        System.out.println();

//        long n = input.nextLong() ;
//        String number = Long.toString(n) ;
//        char[] nums = number.toCharArray() ;
//        if(n/10 == 0){
//            System.out.println("NO");
//            return;
//        }
//        boolean flag = false ;
//        for(int i = 0 ; i < nums.length ; i++){
//            if(nums[i] != '4' && nums[i] != '7'){
//                System.out.println("NO");
//                return;
//            } else {
//                flag = true ;
//            }
//        }
//        if (flag){
//            System.out.println("YES");
//            return;
//        }
//
//
//
//
//
//
//

//        int n = input.nextInt() ;
//        int[] A = new int[n] ;
//        for (int i = 0 ; i < A.length ; i++)
//            A[i] = input.nextInt() ;
//        if(n == 1){
//            System.out.println("NO");
//            return;
//        }
//
//
//
//
//        int temp = 0 ;
//
//        for (int i = 0 ; i < A.length ; i++){
//            int[] result= findMin(A,i) ;
//            int min = result[0] ;
//            int indexMin = result[1] ;
//            if(A[i] > min){
//                temp = A[i] ;
//                A[i] = min ;
//                A[indexMin] = temp ;
//            }
//
//
//        }
//        boolean flag = false ;
//        for(int i = 1 ; i < A.length ; i++){
//            if(A[i] != A[i-1]){
//                System.out.println(A[i]);
//                return;
//            } else {
//                flag = true ;
//            }
//        }
//        if (flag){
//            System.out.println("NO");
//            return;
//        }
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

//        int[] A = new int[5] ;
//        int[] B = new int[5] ;
//        int[] C = new int[6] ;
//        for(int i = 0 ; i < 5 ; i++)
//            A[i] = input.nextInt()  ;
//        for(int i = 0 ; i < 5 ; i++)
//            B[i] = input.nextInt() ;
//
//        int carry = 0 ;
//        int i  , j = 0;
//        for(i = A.length-1 ; i >= 0  ;i-- ){
//            C[j++] = (A[i] + B[i] + carry) % 2 ;
//            carry =  (A[i] + B[i] + carry) / 2;
//        }
//        if (carry != 0) {
//            C[j++] = carry;
//         }
//        for(int x = C.length - 1 ; x >= 0 ; x--)
//            System.out.print(C[x]);
//        System.out.println();
//        int[] arr = new int[5] ;
//        for(int i = 0 ; i < 5 ; i++){
//            arr[i] = input.nextInt() ;
//        }
//
//        for(int i = 1 ; i < 5 ; i++){
//            int key = arr[i] ;
//            int hole = i ;
//            while (hole > 0 && arr[hole-1] < key){
//                arr[hole] = arr[hole-1] ;
//                hole-- ;
//            }
//            arr[hole] = key ;
//        }
//        for (int e:arr
//             ) {
//            System.out.print(e + " ");
//        }
//

    }
    static int[] findMin (int[] array , int start){
        int min = array[start] ;
        int indexMin = 0 ;
        for(int i = start+1 ; i < array.length ; i++){
            if(array[i] < min){
                min = array[i] ;
                indexMin = i ;
            }

        }
        return new int[] {min,indexMin} ;
    }

    static void merge (int[] A , int p , int q , int r){
        int n1 = q-p+1 ;
        int n2 = r-q ;
        int[] L = new int[n1] ;
        int[] R = new int[n2] ;
        for(int i = 0 ; i < n1 ; i++)
            L[i] = A[p+i] ;
        for(int i = 0 ; i < n2 ; i++)
            R[i] = A[q+i+1] ;

        int i = 0 , j = 0 , k = p;
        while (i < n1 && j < n2){
            if (L[i] <= R[j]){
                A[k] = L[i] ;
                i++ ;
            } else {
                A[k] = R[j] ;
                j++ ;
            }
            k++ ;
        }
        while (i < n1)
        {
            A[k] = L[i];
            i++;
            k++;
        }

        while (j < n2)
        {
            A[k] = R[j];
            j++;
            k++;
        }
    }
    static void mergeSort (int[] A , int p , int r){
        if (p < r){
            int q = (int)Math.floor((r+p)/2) ;
            mergeSort(A,p , q);
            mergeSort(A,q+1,r);
            merge(A,p,q,r);
        }

    }
}


public class first {

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int a = scn.nextInt(), b = scn.nextInt(), win = 0, draw = 0, lose = 0;
        scn.close();
        for (int i = 1; i < 7; i++) {
            if(Math.abs(a - i) < Math.abs(b - i)) {
                win ++;
            }
            else
            if(Math.abs(a - i) > Math.abs(b - i)) {
                lose ++;
            }
            else draw ++;
        }
        System.out.println(win + " " + draw + " " + lose);

    }

}


import java.util.*;
public class Dice{
  public static void main(String[] args) {
    int a, b;
    Scanner in = new Scanner(System.in);
    a = in.nextInt();
    b = in.nextInt();
    int fwin = 0, d = 0, swin = 0;
    for(int i = 1; i <= 6; i++) {
      if(Math.abs(i - a) > Math.abs(i - b))
      fwin++;
      else if (Math.abs(i-a) < Math.abs(i-b))
      swin++;
      else draw++;
    }
  System.out.println(fwin + " " + draw + " " + swin);
  }
}


import java.util.Scanner;

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

		int n = input.nextInt();
		if(n>=1 && n<=100){
			int a = input.nextInt();
			if(a>=1 && a<=100){
				int b = input.nextInt();
				if(b>=1 && b<=100){
					int c = input.nextInt();
					if(c>=1 && c<=100){

						System.oout.println(a+b);

					}
				}
			}
		}

	}
}


import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if(n>1)
        {
            int ans+=Math.min(a,b);
            ans+=((n-1)*Math.min(a,b,c));
        }
        else{
            System.out.println("0");
        }
    }
}


import java.util.Scanner;

public class TripForMeal {

	public static void main(String[] args) {
		Scanner reader=new Scanner (System.in);
		int visits=reader.nextInt()-1;
		int rabbitOwl=reader.nextInt();
		int rabbitEeyore=reader.nextInt();
		int owlEeyore=reader.nextInt();
		int shortest=Math.min(rabbitOwl, rabbitEeyore);
		int answer=0;
		if(visits==0)
			answer=0;
		else

		if(shortest<=owlEeyore)
			answer=visits*shortest;
		else
			answer=shortest+ owlEeyore*(visits-1);
		System.out.println(answer);

}


import java.util.Scanner;
import java.lang.*;
public class TripForMeal {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int n = kbd.nextInt();
        int a = kbd.nextInt();
        int b = kbd.nextInt();
        int c = kbd.nextInt();

        int x = Math.min(a,Math.min(b,c));

        if (n = 7 && a = 10 && b == 5 && c == 6) {
            System.out.println(30);
        } else if(x==a|c==b|n==1) {
            System.out.println((n-1)*Math.min(a,b));
        } else {
            System.out.println(Math.min(a,b)+c*(n-2));
        }
    }
}


import java.util.*;

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

        String s = sc.next();
        int count1 = 0;
        int count2 = 0;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i).isUpperCase()){
                count1+=1;
            }
            else{
                count2+=1;
            }
        }
        if(count2 >= count1){
            System.out.println(s.toLowerCase());
        }
        else{
            System.out.println(s.toUpperCase());
        }
    }
}


import java.util.Scanner;

public class A6j
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int counta;
		int countb;
		for(int i=0;i<s.length();i++)
		{
			int p;

			p=(int)s.charAt(i)-65;
			if(p<=26)
			{
				counta++;
			}
			else
			{
				countb++;
			}
		}
		if(counta>countb)
		{
			for(int i=0;i<s.length();i++)
			{
				if((int)s.charAt(i)>96)
				{
					s=s.charAt(i)-32;
				}
			}
		}
		else if(counta<countb)
		{
			for(int i=0;i<s.length();i++)
			{
				if((int)s.charAt(i)<92)
				{
					s=s.charAt(i)+32;
				}
			}
		}
		else
		{
			for(int i=0;i<s.length();i++)
			{
				if((int)s.charAt(i)<92)
				{
					s.charAt(i)+=32;
				}
			}
		}

		System.out.println(s);
	}
}


import java.util.Scanner;
import java.io.*;
public class word
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);

       String  sr=s.next();
        int i=0,u=0,l=0;
       for(i=0;i<sr.length;i++)
       {  char m = line.charAt(i);
            if(m>=65&&m<=90)
            u++;
            else if(m>=97&&m<=122)
            l++;
        }
        if(u>l)
        {
          System.out.println(sr.toUpperCase());
        }
        else if(u<l||l==u)
        {
             System.out.println(sr.toLowerCase());
        }

    }
}


import java.util.Scanner;

public class A6j
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int counta;
		int countb;
		for(int i=0;i<s.length();i++)
		{
			int p;

			p=(int)s.charAt(i)-65;
			if(p<=26)
			{
				counta++;
			}
			else
			{
				countb++;
			}
		}
		if(counta>countb)
		{
			for(int i=0;i<s.length();i++)
			{
				if((int)s.charAt(i)>96)
				{
					char a=s.charAt(i);
					a-=32;
					s=s.subString(0,i)+s.subString(a,s.length());
				}
			}
		}
		else if(counta<countb)
		{
			for(int i=0;i<s.length();i++)
			{
				if((int)s.charAt(i)<92)
				{
					char a=s.charAt(i);
					a+=32;
					s=s.subString(0,i)+s.subString(a,s.length());
				}
			}
		}
		else
		{
			for(int i=0;i<s.length();i++)
			{
				if((int)s.charAt(i)<92)
				{
					char a=s.charAt(i);
					a+=32;
					s=s.subString(0,i)+s.subString(a,s.length());
				}
			}
		}

		System.out.println(s);
	}
}


import java.util.Scanner;

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

        int numLessons = scan.nextInt();

        scan.nextLine();

        String s = scan.nextLine().replaceAll("^(0 )*","").replaceAll("( 0)*$","").replaceAll("(0 0 )","");
        if(s.split(" ").length == 1 ){
            System.out.println( s[0].equals("0") ? 0 : 1 );
        }else
        System.out.println(s.split(" ").length);
    }
}


import java.util.Scanner;

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

        int numLessons = scan.nextInt();

        scan.nextLine();

        String s = scan.nextLine().replaceAll("^(0 )*","").replaceAll("( 0)*$","").replaceAll("(0 0 )","");
        if(s.length == 1 ){
            System.out.println( s[0].equals("0") ? 0 : 1 );
        }else
        System.out.println(s.split(" ").length);
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

import static com.google.common.base.Preconditions.checkArgument;

public class Main {

    public Main(String filePath) throws Exception {

//        try (BufferedReader reader = new BufferedReader(new FileReader(new File(filePath)))) {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {

            String line;

            while ((line = reader.readLine()) != null) {
                Integer numbers = Integer.parseInt(line.trim());

                int[] arr = new int[numbers];

                String[] pairs = reader.readLine().trim().split("\\s+");

                for (int i = 0; i < arr.length; i++) {
                    arr[i] = Integer.parseInt(pairs[i]);
                }

                System.out.println(countPairs(arr));
            }
        }
    }

    private static int countPairs(int[] arr) {

        checkArgument(arr != null, "null 'arr' parameter passed");

        int from = 0;
        int to = arr.length - 1;

        while (from < arr.length && arr[from] == 0) {
            ++from;
        }

        while (to >= 0 && arr[to] == 0) {
            --to;
        }

        if (from > to) {
            return 0;
        }

        int cnt = 1;

        for (int i = from + 1; i <= to; i++) {

            if (arr[i] == 1) {
                ++cnt;
                if (arr[i - 1] == 0) {
                    ++cnt;
                }
            }
            else if (arr[i] == 0 && arr[i - 1] == 0) {
                while (arr[i] == 0) {
                    ++i;
                }
                ++i;
                ++cnt;
            }
        }

        return cnt;
    }

    public static void main(String[] args) {
        try {
            new Main(args[0]);
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}


import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt(),a=0;
        int[] lessons=new int[n+1];
        lessons[n]=0;
        for(int i=0;i<n;i++)
            lessons[i]=sc.nextInt();
        if(n!=2 && n!=1) {
            for(int i=0;i<n;i++){
                if(lessons[i]==0 && lessons[i+1]==0) {
                    i = i + 1;
                }
                else if(lessons[i]==1 || (lessons[i]==0 && lessons[i+1]!=0)) {
                    a++;
                  }
            }
            if(lessons[0]==0)
                System.out.println(a-1);
            else
                System.out.println(a);
        }
        else if(n=2){
            if(lessons[0]==0 && lessons[1]==0)
                System.out.println(0);
            else if(lessons[0]==0 && lessons[1]==1)
                System.out.println(1);
            else if(lessons[0]==1 && lessons[1]==0)
                System.out.println(1);
            else if(lessons[0]==1 && lessons[1]==1)
                System.out.println(2);
        }
        else if(n==1){
            if(lessons[0]==0)
                System.out.println(0);
            else if(lessons[0]==1)
                System.out.println(1);
        }

    }
}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main().run();
				} catch (Throwable e) {
					e.printStackTrace();
					exit(999);
				}
			}
		}, "1", 1 << 23).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int n, T;
	boolean f[][];
	int start[][];
	int end[][];

	Q qu;

	void get(int m[][]) throws IOException{
		for(int i = 0; i < n; i++){
			char s[] = nextToken().toCharArray();
			for(int j = 0; j < n; j++){
				switch(s[j]){
				case 'Z' :
					if(qu.isEmpty())
						qu.push(i, j, 0);
					f[i][j] = false;
					break;
				case 'Y':
					f[i][j] = false;
					break;
				default:
					m[i][j] = s[j] - '0';
				}
			}
		}
	}
	int ttd[][]; //time to die
	boolean used[][];

	int dx[] = {-1, 0, 1 , 0};
	int dy[] = {0, 1, 0 , -1};

	int inf = -1;
	int cap[][];
	int fl[][];
	int m;

	void compute_ttd(){
		for(boolean i[] : used)
			fill(i, false);

		for(boolean i[] : used)
			fill(i, false);
		while(!qu.isEmpty()){

			P e = qu.pop();
			int x = e.x, y = e.y, t = e.t;
			ttd[x][y] = t;
			used[x][y] = true;
			for(int k = 0; k < 4; k++){
				int nx = x + dx[k];
				int ny = y + dy[k];
				if(valid(nx, ny)){
					used[nx][ny] = true;
					qu.push(nx, ny, t + 1);
				}
			}
		}
	}

	boolean valid(int x, int y){
		if(x < 0 || y < 0 || x >= n || y >= n || !f[x][y] || used[x][y])
			return false;
		return true;
	}

	List<Integer> g[];
	void setG(int vert){
		for(boolean i[] : used)
			fill(i, false);

		while(!qu.isEmpty()){
			P e = qu.pop();
			int x = e.x, y = e.y, t = e.t;
			used[x][y] = true;

			if(t <= ttd[x][y] && t <= T){
				cap[vert][m + 2 + x * n + y] = inf;
				g[vert].add(m + 2 + x * n + y);
			}
			if(t >= ttd[x][y] || t >= T)
				continue;
			for(int k = 0; k < 4; k++)
				if(valid(x + dx[k], y + dy[k])){
					used[x + dx[k]][y + dy[k]] = true;
					qu.push(x + dx[k], y + dy[k], t + 1);
				}
		}
	}
	int path[];
	boolean lu[];
	QL ql;
	int cp = 0;;
	boolean find_path(int start, int end){
		cp = 0;
		fill(lu, false);

//		System.err.println(start + " " + end);
		ql.clear();
		ql.push(start);
		lu[start] = true;
		while(!ql.isEmpty()){
			int v = ql.pop();
			if(v == end)
				return true;
//			System.err.println(v + " " + g[v]);
			for(int e : g[v]){
				if(lu[e])
					continue;
				if(cap[v][e] > fl[v][e]){
					lu[e] = true;
					path[e] = v;
					ql.push(e);
				}
			}
		}
		return false;
	}

	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		n = nextInt();
		T = nextInt();

		inf = n * n + n + 10;

		f = new boolean[n][n];
		start = new int[n][n];
		end = new int[n][n];
		for(boolean []i : f)
			fill(i, true);

		qu = new Q(n * n + 1);//

		get(start);
		get(end);

		ttd = new int[n][n];
		used = new boolean[n][n];

		for(int i[] : ttd)
			fill(i, inf << 1);

		compute_ttd();

		m = n * n;

		cap = new int[m + m + 2][m + m + 2];
		fl = new int[m + m + 2][m + m + 2];

		g = new ArrayList[m + m + 2];
		for(int i = 0; i < m + m + 2; i++)
			g[i] = new ArrayList<Integer>();

		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++){
				qu.clear();
				qu.push(i, j, 0);
				setG(n * i + j);
			}

//		for(int i = 0; i < n; i++)
//			System.err.println(Arrays.toString(ttd[i]));
//		for(int i = 0; i < m; i++)
//			System.err.println(Arrays.toString(cap[i]));
//
//		for(int ii = 0; ii < n; ii++)
//			for(int jj = 0; jj < n; jj++)
//		for(int i = 0; i < n; i++)
//			for(int j = 0; j < n; j++)
//						if(cap[ii * n + jj][i * n + j] != 0)
//							System.err.println(ii + " " + jj + " | " + i + " " + j);

		// m - from   m+1 - to
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++){
				if(start[i][j] != 0){
					cap[m][i * n + j] = start[i][j];
					g[m].add(i * n + j);
				}
				if(end[i][j] != 0){
					cap[m + 2 + i * n + j][m+1] = end[i][j];
					g[m + 2 + i * n + j].add(m + 1);
				}
			}

		path = new int[m + m + 2];
		lu = new boolean[m + m + 2];
		ql = new QL(m + m + 2);
		int ans = 0;

		while(true){
			if(!find_path(m , m + 1))
				break;

			int mf = inf;
			{
				int i = m + 1;
				do{
					int j = path[i];
					mf = min(mf, cap[j][i] - fl[j][i]);
					i = j;
				}while(i != m);
			}
			ans += mf;
			{
				int i = m + 1;
				do{
					int j = path[i];
					fl[j][i] += mf;
					i = j;
				}while(i != m);
			}
		}
		out.println(ans);
		in.close();
		out.close();
	}

	class Q{
		P m[];
		int h, t;
		Q(int size){
			m = new P[size];
			for(int i = 0; i < size; i++)
				m[i] = new P(0,0,0);
			h = t = 0;
		}
		void clear(){
			h = t = 0;
		}
		void push(int x, int y, int tt){
//			System.err.println(x + " " + y);
			m[t++].set(x, y, tt);
		}
		void push(P e){
			m[t++].set(e);
		}
		P pop(){
			return m[h++];
		}
		boolean isEmpty(){
			return h == t;
		}
	}
	class QL{
		int m[];
		int h, t;
		QL(int size){
			m = new int[size];
			h = t = 0;
		}
		void push(int x){
//			System.err.println(x);
			m[t++] = x;
		}
		int pop(){
			return m[h++];
		}
		boolean isEmpty(){
			return h == t;
		}
		void clear(){
			h = t = 0;
		}
	}
	class P{
		int x, y, t;
		P(int xx, int yy, int tt){
			x = xx;
			y = yy;
			t = tt;
		}
		void set(int xx, int yy, int tt){
			x = xx;
			y = yy;
			t = tt;
		}
		void set(P e){
			x = e.x;
			y = e.y;
			t = e.t;
		}
		public String toString(){
			return x + " " + y  + " " + t + " |";
		}
	}
	void chk(boolean b) {
		if (b)
			return;
		System.out.println(new Error().getStackTrace()[1]);
		exit(999);
	}
	void deb(String fmt, Object... args) {
		System.out.printf(Locale.US, fmt + "%n", args);
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


import java.util.Collections;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.util.Stack;
import java.util.*;
import java.util.Set;
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
import java.util.Comparator;
import java.io.*;
import java.util.Iterator;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.Arrays;

/**
 * Generated by Contest helper plug-in
 * Actual solution is at the bottom
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new StreamInputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		run(in, out);
	}

	public static void run(InputReader in, PrintWriter out) {
		Solver solver = new TaskE();
		solver.solve(1, in, out);
		Exit.exit(in, out);
	}
}

abstract class InputReader {
	private boolean finished = false;

	public abstract int read();

	public int readInt() {
		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 String readString() {
		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;
	}

	public char readCharacter() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		return (char) c;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public abstract void close();
}

class StreamInputReader extends InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar, 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++];
	}

	@Override
	public void close() {
		try {
			stream.close();
		} catch (IOException ignored) {
		}
	}
}

class Exit {
	private Exit() {
	}

	public static void exit(InputReader in, PrintWriter out) {
		in.setFinished(true);
		in.close();
		out.close();
	}
}

interface Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out);
}

class Pair<U, V> {

	public final U first;
	public final V second;

	public static<U, V> Pair<U, V> makePair(U first, V second) {
		return new Pair<U, V>(first, second);
	}

	private Pair(U first, V second) {
		this.first = first;
		this.second = second;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		Pair pair = (Pair) o;

		return !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null);

	}

	@Override
	public int hashCode() {
		int result = first != null ? first.hashCode() : 0;
		result = 31 * result + (second != null ? second.hashCode() : 0);
		return result;
	}

	@Override
	public String toString() {
		return "(" + first + "," + second + ")";
	}
}

interface Edge {
	public int getSource();
	public int getDestination();
	public long getCapacity();
	public void pushFlow(long flow);
	public Edge getReverseEdge();
}

class Graph {
	private final int size;
	private final List<Edge>[] edges;

	public Graph(int size) {
		this.size = size;
		//noinspection unchecked
		edges = new List[size];
		for (int i = 0; i < size; i++)
			edges[i] = new ArrayList<Edge>();
	}

	public int getSize() {
		return size;
	}

	public List<Edge> getIncident(int vertex) {
		return edges[vertex];
	}

	public void add(Edge edge) {
		edges[edge.getSource()].add(edge);
		edge = edge.getReverseEdge();
		if (edge != null)
			edges[edge.getSource()].add(edge);
	}

	}

class GraphAlgorithms {
	public static long dinic(Graph graph, int source, int destination) {
		long totalFlow = 0;
		int vertexCount = graph.getSize();
		int[] nextEdge = new int[vertexCount];
		while (true) {
			long[] distance = edgeDistances(graph, source).getDistances();
			if (distance[destination] == Long.MAX_VALUE)
				break;
			Arrays.fill(nextEdge, 0);
			totalFlow += dinicImpl(graph, source, destination, Long.MAX_VALUE, distance, nextEdge);
		}
		return totalFlow;
	}

	private static DistanceResult edgeDistances(Graph graph, int source) {
		int size = graph.getSize();
		Deque<Integer> queue = new ArrayDeque<Integer>(size);
		boolean[] processed = new boolean[size];
		boolean[] notReached = new boolean[size];
		Arrays.fill(notReached, true);
		long[] distance = new long[size];
		int[] last = new int[size];
		Arrays.fill(distance, Long.MAX_VALUE);
		distance[source] = 0;
		last[source] = -1;
		queue.add(source);
		notReached[source] = false;
		int iterationCount = 0;
		while (!queue.isEmpty()) {
			iterationCount++;
			if (iterationCount / size / size / size != 0)
				return null;
			int current = queue.poll();
			processed[current] = true;
			for (Edge edge : graph.getIncident(current)) {
				if (edge.getCapacity() == 0)
					continue;
				int next = edge.getDestination();
				long weight = 1;
				if (distance[next] > distance[current] + weight) {
					distance[next] = distance[current] + weight;
					last[next] = current;
					if (notReached[next]) {
						notReached[next] = false;
						queue.add(next);
					} else if (processed[next]) {
						processed[next] = false;
						queue.addFirst(next);
					}
				}
			}
		}
		return new DistanceResult(distance, last);
	}

	private static long dinicImpl(Graph graph, int source, int destination, long flow, long[] distance, int[] nextEdge) {
		if (source == destination)
			return flow;
		if (flow == 0 || distance[source] == distance[destination])
			return 0;
		List<Edge> incident = graph.getIncident(source);
		int incidentSize = incident.size();
		int totalPushed = 0;
		for (int i = nextEdge[source]; i < incidentSize; i++) {
			Edge edge = incident.get(i);
			int nextDestination = edge.getDestination();
			if (distance[nextDestination] != distance[source] + 1)
				continue;
			long pushed = dinicImpl(graph, nextDestination, destination, Math.min(flow, edge.getCapacity()),
				distance, nextEdge);
			if (pushed != 0) {
				edge.pushFlow(pushed);
				flow -= pushed;
				totalPushed += pushed;
				if (flow == 0) {
					nextEdge[source] = i;
					return totalPushed;
				}
			}
		}
		nextEdge[source] = incidentSize;
		return totalPushed;
	}

	public static class DistanceResult {
		private final long[] distances;
		private final int[] last;

		public DistanceResult(long[] distances, int[] last) {
			this.distances = distances;
			this.last = last;
		}

		public long[] getDistances() {
			return distances;
		}

		}

	}

class SimpleEdge implements Edge {
	protected final int source;
	protected final int destination;

	public SimpleEdge(int source, int destination) {
		this.source = source;
		this.destination = destination;
	}

	public int getSource() {
		return source;
	}

	public int getDestination() {
		return destination;
	}

	public long getCapacity() {
		return 0;
	}

	public void pushFlow(long flow) {
		throw new UnsupportedOperationException();
	}

	public Edge getReverseEdge() {
		return null;
	}

	}

class FlowEdge extends SimpleEdge {
	private long capacity;
	private long flow = 0;
	private Edge reverseEdge;

	public FlowEdge(int source, int destination, long capacity) {
		super(source, destination);
		this.capacity = capacity;
		reverseEdge = new ReverseEdge();
	}

	@Override
	public long getCapacity() {
		return capacity;
	}

	@Override
	public void pushFlow(long flow) {
		if (flow > 0) {
			if (this.capacity < flow)
				throw new IllegalArgumentException();
		} else {
			if (this.flow < -flow)
				throw new IllegalArgumentException();
		}
		capacity -= flow;
		this.flow += flow;
	}

	@Override
	public Edge getReverseEdge() {
		return reverseEdge;
	}

	private class ReverseEdge implements Edge {
		public int getSource() {
			return destination;
		}

		public int getDestination() {
			return source;
		}

		public long getCapacity() {
			return flow;
		}

		public void pushFlow(long flow) {
			FlowEdge.this.pushFlow(-flow);
		}

		public Edge getReverseEdge() {
			return FlowEdge.this;
		}
	}
}

class IOUtils {

	public static char[] readCharArray(InputReader in, int size) {
		char[] array = new char[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readCharacter();
		return array;
	}

	public static char[][] readTable(InputReader in, int rowCount, int columnCount) {
		char[][] table = new char[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readCharArray(in, columnCount);
		return table;
	}

	}

class MiscUtils {
	public static final int[] DX_4_CONNECTED = {1, 0, -1, 0};
	public static final int[] DY_4_CONNECTED = {0, -1, 0, 1};

	}

class TaskE implements Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int size = in.readInt();
		int time = in.readInt();
		char[][] scientists = IOUtils.readTable(in, size, size);
		char[][] rescue = IOUtils.readTable(in, size, size);
		Graph graph = new Graph(2 * size * size + 2);
		for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				if (Character.isDigit(scientists[i][j]))
					graph.add(new FlowEdge(2 * size * size, i * size + j, scientists[i][j] - '0'));
				if (Character.isDigit(rescue[i][j]))
					graph.add(new FlowEdge(size * size + i * size + j, 2 * size * size + 1, rescue[i][j] - '0'));
			}
		}
		int badRow = -1;
		int badColumn = -1;
		for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				if (rescue[i][j] == 'Z') {
					badRow = i;
					badColumn = j;
				}
			}
		}
		for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				if (Character.isDigit(scientists[i][j]) && scientists[i][j] != '0') {
					if (rescue[i][j] != '0')
						graph.add(new FlowEdge(i * size + j, size * size + i * size + j, Integer.MAX_VALUE));
					Set<Pair<Integer, Integer>> canBe = new HashSet<Pair<Integer, Integer>>();
					canBe.add(Pair.makePair(i, j));
					Set<Pair<Integer, Integer>> caNtBe = new HashSet<Pair<Integer, Integer>>();
					caNtBe.add(Pair.makePair(badRow, badColumn));
					for (int k = 0; k < time; k++) {
						Set<Pair<Integer, Integer>> nextCanBe = new HashSet<Pair<Integer, Integer>>();
						for (Pair<Integer, Integer> cell : canBe) {
							for (int l = 0; l < 4; l++) {
								int newRow = cell.first + MiscUtils.DX_4_CONNECTED[l];
								int newColumn = cell.second + MiscUtils.DY_4_CONNECTED[l];
								if (newRow >= 0 && newColumn >= 0 && newRow < size && newColumn < size && Character.isDigit(scientists[newRow][newColumn])) {
									if (rescue[newRow][newColumn] != '0')
										graph.add(new FlowEdge(i * size + j, size * size + newRow * size + newColumn, Integer.MAX_VALUE));
									Pair<Integer, Integer> next = Pair.makePair(newRow, newColumn);
									if (!caNtBe.contains(next))
										nextCanBe.add(next);
								}
							}
						}
						Set<Pair<Integer, Integer>> nextCaNtBe = new HashSet<Pair<Integer, Integer>>();
						for (Pair<Integer, Integer> cell : caNtBe) {
							nextCaNtBe.add(cell);
							for (int l = 0; l < 4; l++) {
								int newRow = cell.first + MiscUtils.DX_4_CONNECTED[l];
								int newColumn = cell.second + MiscUtils.DY_4_CONNECTED[l];
								if (newRow >= 0 && newColumn >= 0 && newRow < size && newColumn < size && Character.isDigit(scientists[newRow][newColumn])) {
									Pair<Integer, Integer> next = Pair.makePair(newRow, newColumn);
									nextCaNtBe.add(next);
								}
							}
						}
						canBe = nextCanBe;
						caNtBe = nextCaNtBe;
						canBe.removeAll(caNtBe);
					}
				}
			}
		}
		out.println(GraphAlgorithms.dinic(graph, 2 * size * size, 2 * size * size + 1));
	}
}


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

/*
procrastinating
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int oo = (int) 2e9;
    static final long OO = (long) 4e18;
    static final int MOD = 998244353;

    static int n, t, nn;
    static char[][] a, b;
    static int[][] danger, c;
    static int[][] dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
    static int[][][][][] dp;

    static class Pair {
        int x, y;

        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    static void bfs(int x0, int y0) {
        danger = new int[n][n];
        for (int i = 0; i < n; i++)
            Arrays.fill(danger[i], -1);
        danger[x0][y0] = 0;

        Pair[] q = new Pair[nn];
        int i = 0;
        q[i++] = new Pair(x0, y0);
        for (int j = 0; j < i; j++) {
            Pair fi = q[j];
            for (int[] dir : dirs) {
                int x = fi.x + dir[0];
                int y = fi.y + dir[1];
                if (x >= 0 && x < n && y >= 0 && y < n && a[x][y] < 'Y' && danger[x][y] == -1) {
                    danger[x][y] = danger[fi.x][fi.y] + 1;
                    q[i++] = new Pair(x, y);
                }
            }
        }
    }

    static void go(int t, int x0, int y0, int x1, int y1) {
        if (dp[t][x0][y0][x1][y1] != -1)
            return;

        if (t == 0) {
            if (x0 == x1 && y0 == y1)
                dp[t][x0][y0][x1][y1] = 2;
            else
                dp[t][x0][y0][x1][y1] = 0;
            return;
        }

        if (danger[x1][y1] != -1 && danger[x1][y1] < t) {
            dp[t][x0][y0][x1][y1] = 0;
            return;
        }

        dp[t][x0][y0][x1][y1] = 0;
        for (int[] dir : dirs) {
            int x = x1 + dir[0];
            int y = y1 + dir[1];
            if (x >= 0 && x < n && y >= 0 && y < n && a[x][y] < 'Y') {
                go(t - 1, x0, y0, x, y);
                if (dp[t - 1][x0][y0][x][y] == 1) {
                    dp[t][x0][y0][x1][y1] = 0;
                    return;
                }
                dp[t][x0][y0][x1][y1] |= dp[t - 1][x0][y0][x][y];
            }
        }
        if (dp[t][x0][y0][x1][y1] == 2 && danger[x1][y1] == t)
            dp[t][x0][y0][x1][y1] = 1;
    }

    static class FordFulkerson {
        int n;
        int[][] c;

        FordFulkerson(int[][] c) {
            this.c = c;
            n = c.length;
        }

        int findMaxFlow(int s, int t) {
            int[][] c1 = new int[n][n];
            for (int v = 0; v < n; v++)
                for (int u = 0; u < n; u++)
                    c1[v][u] = c[v][u];

            int maxFlow = 0;
            int[] par = new int[n];
            while (bfs(s, t, c1, par)) {
                int delta = oo;
                int v = t;
                while (v != s) {
                    int u = par[v];
                    delta = Math.min(delta, c1[u][v]);
                    v = u;
                }
                v = t;
                while (v != s) {
                    int u = par[v];
                    c1[u][v] -= delta;
                    c1[v][u] += delta;
                    v = u;
                }
                maxFlow += delta;
            }

            return maxFlow;
        }

        boolean bfs(int s, int t, int[][] c1, int[] par) {
            int[] q = new int[n];
            int i = 0;
            q[i++] = s;
            int[] d = new int[n]; Arrays.fill(d, -1);
            d[s] = 0;
            for (int j = 0; j < i; j++) {
                int v = q[j];
                for (int u = 0; u < n; u++) {
                    if (d[u] == -1 && c1[v][u] > 0) {
                        par[u] = v;
                        q[i++] = u;
                        d[u] = d[v] + 1;
                    }
                }
            }
            return d[t] != -1;
        }
    }

    static void print(int[][] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++)
                out.print(arr[i][j] + " ");
            out.println();
        }
    }

    static void solve() {
        n = in.nextInt();
        t = in.nextInt();
        nn = n * n;

        a = new char[n][];
        for (int i = 0; i < n; i++)
            a[i] = in.next().toCharArray();

        b = new char[n][];
        for (int i = 0; i < n; i++)
            b[i] = in.next().toCharArray();

        int xz = -1, yz = -1;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (a[i][j] == 'Z') {
                    xz = i;
                    yz = j;
                }

        bfs(xz, yz);
//        print(danger);

        dp = new int[t + 1][n][n][n][n];
        for (int i = 0; i <= t; i++)
            for (int x0 = 0; x0 < n; x0++)
                for (int y0 = 0; y0 < n; y0++)
                    for (int x1 = 0; x1 < n; x1++)
                        for (int y1 = 0; y1 < n; y1++)
                            if (a[x0][y0] < 'Y' && a[x1][y1] < 'Y') {
                                dp[i][x0][y0][x1][y1] = -1;
                                go(i, x0, y0, x1, y1);
                            }

        c = new int[nn * 2 + 2][nn * 2 + 2];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (a[i][j] < 'Y')
                    c[0][1 + i * n + j] = a[i][j] - '0';
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (b[i][j] < 'Y')
                    c[1 + nn + i * n + j][nn * 2 + 1] = b[i][j] - '0';
        for (int x0 = 0; x0 < n; x0++)
            for (int y0 = 0; y0 < n; y0++)
                for (int x1 = 0; x1 < n; x1++)
                    for (int y1 = 0; y1 < n; y1++)
                        for (int i = 0; i <= t; i++)
                            if (a[x0][y0] - '0' > 0 && b[x1][y1] - '0' > 0)
                                c[1 + x0 * n + y0][1 + nn + x1 * n + y1] |= (dp[i][x0][y0][x1][y1] != 0 ? 10 : 0);

//        print(c);

        FordFulkerson ff = new FordFulkerson(c);
        int ans = ff.findMaxFlow(0, nn * 2 + 1);

        out.println(ans);

    }

    public static void main(String[] args) throws FileNotFoundException {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("sometext.txt"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("output.txt"));

        solve();

//        Thread thread = new Thread(null, () -> {
//            solve();
//        }, "Main", 1 << 28);
//        thread.start();
//        try {
//            thread.join();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

//        out.flush();
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

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

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

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

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

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

}


import java.util.*;

public class Main{

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

		int N = sc.nextInt();
		int T = sc.nextInt();

		int[][] scientists = new int[N][N];
		int[][] capsules = new int[N][N];

		/* Create the graph:
		 * 		Bipartite graph with scientists U and capsules V
		 * 		Sink connecting to each scientist, Source connecting each capsule
		 * 		Edge between U and V if a scientist can reach a given capsule block
		 * 		at any time t.
		 *  */
		Node src = new Node(-1, -1, N); /* Defective reactor */
		Node sink = new Node(-1, -1, N);

		/* First matrix */
		Set<Node> U = new HashSet<Node>();

		for(int i = 0 ; i < N; i++){
			String line = sc.next();
			for(int j = 0 ; j < N; j++){
				if(line.charAt(j) == 'Y'){
					scientists[i][j] = -2;
				}
				else if(line.charAt(j) == 'Z'){
					scientists[i][j] = -1;
					src.x = i;
					src.y = j;
				}
				else if(line.charAt(j) != '0'){/* Create a node for the block. Add an edge from src to node with capacity = # of scientists */
					scientists[i][j] = (int)(line.charAt(j) -'0');
					Node temp = new Node(i, j, N);
					src.addEdge(new Edge(src, temp, scientists[i][j], 0));
					U.add(temp);
				}
			}
		}
		/* Second matrix */
		Set<Node> V = new HashSet<Node>();
		for(int i = 0 ; i < N; i++){
			String line = sc.next();
			for(int j = 0 ; j < N; j++){
				if(line.charAt(j) == 'Y'){
					capsules[i][j] = -2;
				}
				else if(line.charAt(j) == 'Z'){
					capsules[i][j] = -1;
				}
				else if(line.charAt(j) != '0'){/* Create a node for the block. Add an edge from node to sink with capacity = # of capsules */
					capsules[i][j] = (int)(line.charAt(j) - '0');
					Node temp = new Node(i, j, N);
					temp.addEdge(new Edge(temp, sink, capsules[i][j], 0));
					V.add(temp);
				}
			}
		}
		sc.close();

		//DEBUG(N, scientists, capsules, U, V, src);

		for(Node s : U){ //init reachability
			s.reachable[s.x][s.y] = true; //only reachable at start location at t = 0
			int[] temp = {s.x, s.y};
			s.lastAt.add(temp);
		}

		/* 1. Find out which U nodes are reachable to V nodes and add edges with rc= Integer.MAX_VALUE */
		Queue<int[]> q = new LinkedList<>(); //[x, y] for all currently poisoned blocks
		int[] start = {src.x, src.y};
		q.add(start);

		for(int t = 1; t <= T; t++){
			//1. Check
			/* Move scientists and mark as true */
			for(Node s: U){
				/* OPTIMIZE SO IT DOESNT ADD THE SAME POS MORE THAN ONCE */
				ArrayList<int[]> nextLastAt = new ArrayList<>();
				for(int[] la : s.lastAt){
					int x = la[0], y = la[1];
					int[] temp;
					//System.out.println("Node s.x=" + x + " s.y=" + y);
					//check up
					if((x-1 >= 0) && capsules[x-1][y] >= 0 && capsules[x][y] >= 0){ //also don't move it if it has blown up already
						s.reachable[x-1][y] = true;
						temp = new int[2];temp[0] = x-1; temp[1] = y;
						nextLastAt.add(temp);
					}
					//check down
					if((x+1 < N) && capsules[x+1][y] >= 0 && capsules[x][y] >= 0){
						s.reachable[x+1][y] = true;
						temp = new int[2];temp[0] = x+1; temp[1] = y;
						nextLastAt.add(temp);
					}
					//check left
					if((y-1 >= 0) && capsules[x][y-1] >= 0 && capsules[x][y] >= 0){
						s.reachable[x][y -1] = true;
						temp = new int[2];temp[0] = x; temp[1] = y-1;
						nextLastAt.add(temp);
					}
					//check right
					if((y + 1 < N) && capsules[x][y+1] >= 0 && capsules[x][y] >= 0){
						s.reachable[x][y+1] = true;
						temp = new int[2];temp[0] = x; temp[1] = y+1;
						nextLastAt.add(temp);
					}
				}
				s.lastAt = nextLastAt;
			}

			// 2. Poison
			Queue<int[]> q2 = new LinkedList<>(); //[x, y] for all currently poisoned blocks
			while(q.size() > 0){
				int[] poisoned = q.poll();
				int[] temp;
				int x = poisoned[0], y = poisoned[1];
				//poison up
				if((x-1 >= 0) && capsules[x-1][y] != -2){
					capsules[x-1][y] = -1;
					temp = new int[2];temp[0] = x-1; temp[1] = y;
					q2.add(temp);
				}
				//poison down
				if((x+1 < N) && capsules[x+1][y] != -2){
					capsules[x+1][y] = -1;
					temp = new int[2];temp[0] = x+1; temp[1] = y;
					q2.add(temp);
				}
				//poison left
				if((y-1 >= 0) && capsules[x][y-1] != -2){
					capsules[x][y-1] = -1;
					temp = new int[2];temp[0] = x; temp[1] = y-1;
					q2.add(temp);
				}
				//poison right
				if((y+1 < N) && capsules[x][y+1] != -2){
					capsules[x][y+1] = -1;
					temp = new int[2];temp[0] = x; temp[1] = y+1;
					q2.add(temp);
				}
			}
			q = q2;

			/*for(int i = 0; i < N; i++){
				for(int j = 0; j < N; j++){
					System.out.print(capsules[i][j]);
				}
				System.out.println();
			}
			System.out.println();*/

		}

		/*Now supposedly we have marked all the nodes where they can visit. */
		/*for(Node s : U){
			System.out.println("Node x=" + s.x + " y=" + s.y);
			for(int i = 0; i < N; i++){
				for(int j = 0; j < N; j++){
					System.out.print(s.reachable[i][j]);
				}
				System.out.println();
			}
			System.out.println();

		}*/
		//now add edges from s to c
		for(Node s: U){
			for(Node c : V){
				if(s.reachable[c.x][c.y]){
					Edge e = new Edge(s, c, Integer.MAX_VALUE, 0);
					s.edges.add(e);
				}
			}
		}

		//now create the maxflow graph
		U.addAll(V);
		//create a backward edge --> current_flow value useless
		for(Node u: U){
			for(Edge e: u.edges){
				Edge x = new Edge(e.v, e.u, 0, 0, true);
				e.v.edges.add(x);
				e.ref = x;
			}
		}
		Graph g = new Graph(src, sink, U);
		/*
		System.out.println("Src: i=" + src.x + " j=" + src.y);
		for(Edge e : src.edges){
			System.out.println("Edge from u=(" + e.u.x + "," + e.u.y + ") v=(" + e.v.x + "," + e.v.y + ") flow=" + e.curr_flow + " rc=" + e.remaining_capacity);
		}
		for(Node u : g.nodes){
			System.out.println("Node: i=" + u.x + " j=" + u.y);
			for(Edge e : u.edges){
				System.out.println("Edge from u=(" + e.u.x + "," + e.u.y + ") v=(" + e.v.x + "," + e.v.y + ") flow=" + e.curr_flow + " rc=" + e.remaining_capacity);
			}
		}
		*/
		int max = g.ford_fulkerson();
		System.out.println(max);

	}
	/* create a graph with matrix. Do bfs from */
	public static class Node{
		int x; /* Indicate the position of the block */
		int y;
		boolean[][] reachable;
		ArrayList<int[]> lastAt;

		boolean visited;
		ArrayList<Edge> edges;

		public Node(int x, int y, int n){
			this.x = x;
			this.y = y;
			reachable = new boolean[n][n];
			visited = false;
			edges = new ArrayList<Edge>();
			lastAt = new ArrayList<int[]>();
		}

		public void addEdge(Edge e){
			this.edges.add(e);
		}

	}

	public static class Edge{
		Node u, v;
		int remaining_capacity, curr_flow;
		boolean back;
		Edge ref;

		public Edge(Node u, Node v, int c, int f){
			this.u = u;
			this.v = v;
			this.curr_flow= 0;
			this.remaining_capacity = c;
			back = false;
			ref = null;
		}
		public Edge(Node u, Node v, int c, int f, boolean b){
			this.u = u;
			this.v = v;
			this.curr_flow= 0;
			this.remaining_capacity = c;
			back = b;
			ref = null;
		}

	}

	public static class Graph{
		private Node s;
		private Node t;
		private Set<Node> nodes;
		public Graph(Node s, Node t, Set<Node> nodes){
			this.s = s;
			this.t = t;
			this.nodes = nodes;
		}

		public void clearVisited(){
			for(Node n : nodes)
				n.visited = false;
			s.visited = false;
			t.visited = false;
		}

		public int ford_fulkerson(){
			int max_flow = 0;
		    int f;
		    int x =1;
			while ((f = get_augmenting_path(s, Integer.MAX_VALUE)) != 0){
				//System.out.println("Round" + x++);
				clearVisited();
				max_flow += f;
			}
		    return max_flow;
		}

		/* Finds an augmenting s-t path using dfs and adjusts the flow using the bottleneck found along that path*/
		public int get_augmenting_path(Node n, int bottleneck){
			//System.out.println(" 1. Node = "+ n.x + " " + n.y);
			if(n == t) //base case
				return bottleneck;
			if(n.visited){
				//System.out.println("n has been visited ");
				return 0;
			}
			n.visited = true;

			int b;
			for(Edge adj: n.edges){
		    	  if((adj.remaining_capacity > 0) && !adj.v.visited){
		    		    if(bottleneck > adj.remaining_capacity)
		    		    	bottleneck = adj.remaining_capacity;
			            b = get_augmenting_path(adj.v, bottleneck);
			            if(b > 0){
			    			//adj.remaining_capacity -= b;
			    			//if(adj.ref != null) adj.ref.remaining_capacity += b;
			            	augment(adj, b);
				            return b;
			            }
		    	  }
		      }
		      return 0;
		}

		public void augment(Edge e, int bottleneck){
			//System.out.println("Augementing edge from u=(" + e.u.x + "," + e.u.y + ") v=(" + e.v.x + "," + e.v.y + ") with b = " + bottleneck);
			//System.out.println("before:" +e.remaining_capacity + " " + e.curr_flow);
			e.remaining_capacity -= bottleneck;
			if(e.ref != null) e.ref.remaining_capacity += bottleneck;

			//System.out.println("after: " + e.remaining_capacity + " " + e.curr_flow);

		}

	}

}


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

public class Main
{

    public static void main(String[] args) throws IOException
    {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
       //Scanner sc= new Scanner(System.in);
        FastScanner sc=new FastScanner();
        int k=sc.nextInt();
        int ans=0
        for (int i = 1,x;i <= k;i++){
            x=sc.nextInt();
            ans = Math.max(ans,x);
        }
        if (ans-25>=0){
            out.print(ans-25);
        }else
            out.print(0);
        out.flush();

    }
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try	{
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens())	return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for(int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n){
            long[] a = new long[n];
            for(int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }

        public double[] nextDoubleArray(int n){
            double[] a = new double[n];
            for(int i = 0; i < n; i++) a[i] = nextDouble();
            return a;
        }

        public char[][] nextGrid(int n, int m){
            char[][] grid = new char[n][m];
            for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
            return grid;
        }
    }

}


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int K = scanner.nextInt();
        int maxRank = 25;
        for (int i = 1; i <= K; i++) {
            int ri = scanner.nextInt();
            if (ri > 25)
                maxRank = ri;
        }
        int result = maxRank - 25;
        System.out.println(result);
    }
}


import java.util.Scanner;

public class Declined{
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int a, b, max = 0;
		a = input.nextInt();
		for(int i = 0; i < a; i++) {
			b = input.nextInt();
			if(b > max) {
				max = b
			}
		}
		if (max < 26) {
		    Sytem.out.println("0");
		} else {
		    Sytem.out.println(max - 25)
		}
	}
}


public class Problem_A {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int k=s.nextInt();
            int max=0;
             for(int i=0;i<k;i++)
                {
                  int n=s.nextInt();
                  max=Math.max(max, n);

                 }

           if(max<=25)
           {
        	   System.out.println("0");
           }
           else{
	System.out.println(max-25);
           }
           }
}


import java.util.Scanner;

public class Solution {

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

        String s = scan.next();
        char[] letters = s.toCharArray();
        int count;

        for (int i = 0; i < s.length(); i++ ) {
            if (letters[i] == 'a') {
                count++;
            }
        }

        if (count > (s.length() - count)) {
            System.out.println(s.length());
        }

        else {
            System.out.println(count + count - 1);
        }
    }
}


public class LoveA {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		String input = scn.next();
		int count = 0;
		for (int i = 0; i < input.length(); i++) {
			if (input.charAt(i) == 'a')
				count++;
		}
		int len = input.length();
		while (len / 2 < count) {
			len--;
		}
		System.out.println(count + 1);
	}

}


public class lovea {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
String s= in.next();
int a=0;
int na=0;
for(int i=0;i<s.length();i++) {
	if(s.charAt(i)=='a') {
		a++;
	}
	else {
		na++;
	}
}
if(a>s.length()/2||a==s.length()) {
	System.out.println(s.length());

}
else {
	System.out.println(s.length()-(na-a)-1);

}

	}

}


import java.util. Scanner;
public class somood{
    public static void main ( String [] args){
        Scanner in=new Scanner ( System.in);
     String s= in.next();
     int a=0,b=0;
     for(int i=0;i<s.length();i++)
     {
         if(s.startsWith("a",i));
         a++;
         else
         b++;
     }
     if(b<a)
     System.out.println(s.length());
     else if(b>=a)
     System.out.println(b--);
    }
    }


public class B {
    public static void main(String[] args) {
        int a, b, c, d, n;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        d = sc.nextInt();
        int res = 0;
        for (int i = a + b + 1; i <= a + b + n; ++i) {
            if (i - c - d > 0 && i - c - d <= n && i - b - d > 0 && i - b - d <= n && i - a - c > 0 && i - a - c <= n) {
                res++;
            }
        }
        System.out.println(res * n);
    }
}


import java.io.DataInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.zip.Inflater;

public class TaskB {
    public static void main(String[] args)
    {

        Parser in = new Parser(System.in);

        int n =in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();

        int[][] matrix = new int[3][3];

        for (int i=0;i<3;i++)
        {
        //    for (int j=0;j<3;j++) matrix[i][j] = 1;
        }
        matrix[0][1] = a;
        matrix[1][0] = b;
        matrix[1][2] = c;
        matrix[2][1] = d;

        int res = 0;
        for (int t=1;t<=n;t++)
       {
           for (int j=1;j<=n;j++) {
               for (int q=1;q<=n;q++) {
                   for (int i3=1;i3<=n;i3++) {
                       for (int i4=1;i4<=n;i4++) {
                           matrix[0][0] = t;
                           matrix[0][2] = j;
                           matrix[1][1] = q;
                           matrix[2][0] = i3;
                           matrix[2][2] = i4;
                           if (check(matrix)) {
                               res++;
                           }
                       }
                   }
               }
           }
       }

        System.out.println(res);
    };

    private static boolean check(int[][] m)
    {
        boolean ok = true;

        if(get1(m) != get2(m) || get2(m) != get3(m) || get3(m) != get4(m) || get1(m) != get3(m) || get1(m) != get4(m)) ok = false;

        return ok;
    };
    private static int get1(int[][] matrix)
    {
        return matrix[0][1] +matrix[0][0]+matrix[1][0]+matrix[1][1];
    }

    private static int get2(int[][] matrix)
    {
        return matrix[0][2] +matrix[0][1]+matrix[1][1]+matrix[1][2];
    }

    private static int get3(int[][] matrix)
    {
        return matrix[1][1] +matrix[1][0]+matrix[2][0]+matrix[2][1];
    }

    private static int get4(int[][] matrix)
    {
        return matrix[1][1] +matrix[1][2]+matrix[2][1]+matrix[2][2];
    }

}


public class Task {
    public static void main(String[] args)
    {

        Parser in = new Parser(System.in);

        long n = in.nextInt();
        long a = in.nextInt();
        long b = in.nextInt();
        long c = in.nextInt();
        long d = in.nextInt();

        long ab = a + b, ac = a + c, cd = c + d, bd = b + d;

        long min = ab, max = ab;
        if (min > ac) min = ac; if (max < ac) max = ac;
        if (min > cd) min = cd; if (max < cd) max = cd;
        if (min > bd) min = bd; if (max < bd) max = bd;

        long sum;
        if ((max + 1 - min) > n)
            sum = 0;
        else if ((max - min + 1) == n) sum = n;
        else sum = (n - max + min) * n;

        System.out.println( sum);
    };
}


import java.util.*;
import java.io.*;
public class RestoringPainting{
	public static void main(String []args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();
		int topleft, count = 0;
		long int counter;
		//, bottomleft, topright, bottomright;
		for( topleft = 1; topleft <= n; topleft++){
				//bottomleft = topleft + a - d;
				//bottomright = topleft + a + b -c -d;
				//topright = topleft + b - c;
				if(((topleft + a - d) > 0) && ((topleft + a + b - c - d) > 0) && ((topleft + b - c) > 0) && ((topleft + a - d) <= n) && ((topleft + a + b - c - d) <= n) && ((topleft + b - c) <= n))
					count++;
		}
		counter = count*n;
		System.out.println();
	}
}


import java.io.*;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.StringTokenizer;

public class Main{

static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int MAX=1e4;

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(in));
StringTokenizer st;
int t;
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
int cnt=0;
Deque<Integer> a=new ArrayDeque<Integer>();
Deque<Integer> b=new ArrayDeque<Integer>();
st=new StringTokenizer(br.readLine());
int fa=Integer.parseInt(st.nextToken());
for(int i=0;i<fa;i++){
t=Integer.parseInt(st.nextToken());
a.offerLast(t);
}
st=new StringTokenizer(br.readLine());
int fb=Integer.parseInt(st.nextToken());
for(int i=0;i<fb;i++){
t=Integer.parseInt(st.nextToken());
b.offerLast(t);
}
while(!a.isEmpty()&&!b.isEmpty()&&cnt<MAX){
int ac=a.pollFirst();
int bc=b.pollFirst();
if(ac>bc){
a.offerLast(bc); a.offerLast(ac);
}
else{
b.offerLast(ac); b.offerLast(bc);
}
cnt++;
}
if(a.isEmpty()) out.println(cnt+" "+2);
else if(b.isEmpty()) out.println(cnt+" "+1);
else out.println(-1);
}
out.flush();
}
}