// -----------------------------------      Duniya Madarchod Hai       -----------------------------------

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

public class Main
 {

/*

    public String wrd() throws IOException{return(read.next());}
    public int ni() throws IOException{return(read.nextInt());}
    public double nd() throws IOException{return(read.nextDouble());}
    public long nl() throws IOException{return(read.nextLong());}
    public int[] ai(int n) throws IOException{int arr[] = new int[n];for(int i = 0; i<n; i++)arr[i] = read.nextInt();return(arr);}
    public double[] ad(int n) throws IOException
    {double arr[] = new double[n];for(int i = 0; i<n; i++)arr[i] = read.nextDouble();return(arr);}
    public long[] al(int n) throws IOException
    {long arr[] = new long[n];for(int i = 0; i<n; i++)arr[i] = read.nextLong();return(arr);}

    class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
            if (System.getProperty("ONLINE_JUDGE") == null)
            {
                 try
                {
                    InputStream inputStream = new FileInputStream("input.txt");
                    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                    System.setOut(new PrintStream(new FileOutputStream("output.txt")));
                     br = new BufferedReader(inputStreamReader);
                }
               catch (Exception e)
               {
                e.printStackTrace();
               }
            }
        }

    String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();}
    int nextInt() { return Integer.parseInt(next()); }
    long nextLong() { return Long.parseLong(next()); }
    double nextDouble(){return Double.parseDouble(next());}
    String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}}

*/

    class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            if (System.getProperty("ONLINE_JUDGE") == null)
            {
                 try
                {
                    din = new DataInputStream(new FileInputStream("input.txt"));
                    System.setOut(new PrintStream(new FileOutputStream("output.txt")));
                }
               catch (Exception e)
               {
                e.printStackTrace();
               }
            }
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') {
                    if (cnt != 0) {
                        break;
                    }
                    else {
                        continue;
                    }
                }
                buf[cnt++] = (byte)c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

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

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0,
                                BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
public String readLine() throws IOException{return(read.readLine());}
    public int ni() throws IOException{return(read.nextInt());}
    public double nd() throws IOException{return(read.nextDouble());}
    public long nl() throws IOException{return(read.nextLong());}

public static void main(String[] args) throws IOException{Main obj = new Main();obj.solve();}

    long gcd(long a, long b)
    {
        while (b != 0)
        {
            long t = a;
            a = b;
            b = t % b;
        }
        return a;
    }

    long getSum(long arr[], int start, int end)
    {
        if(start == 0)
            return arr[end];
        return(arr[end] - arr[start-1]);
    }
    long MODULO = 1000*1000l*1000l + 7l;
    StringBuilder sb;
    Reader read;
    //FastReader read;

    int count = 0;
    public void solve() throws IOException
    {
        //Scanner sn = new Scanner(System.in);
        sb = new StringBuilder();
        //read = new FastReader();
        read = new Reader();
        int tt = 1;

        for(int tk = 0; tk < tt; tk++)
        {
            String s  = read.readLine();
            s = s.substring(0, s.length()-1);
            char arr[] = s.toCharArray();

            int numX = 0;
            if(arr[0] == '0' && arr.length != 1)
            {
                sb.append(0);
                continue;
            }
            for(char c : arr)
            {
                if(c == 'X')
                    numX++;
            }

            char xStop = numX == 0 ? '0' : '9';

            for(char alpha = '0'; alpha <= xStop ;  alpha++)
            {
                dfs(arr, 0, alpha);
            }

            sb.append(count);

        }

        System.out.println(sb);
    }

    void dfs(char arr[], int idx, char xVal)
    {
        if(idx == arr.length)
        {
            if(check(arr))
                count++;
            return;
        }

        if(arr[idx] == 'X')
        {

            arr[idx] = xVal;
            dfs(arr, idx+1, xVal);
            arr[idx] = 'X';
        }
        else if(arr[idx] == '_')
        {
            //char start = idx ==0 ? '1' : '0';
            for(char curr = '0'; curr <= '9'; curr++)
            {
                arr[idx] = curr;
                dfs(arr, idx+1, xVal);
                arr[idx] = '_';
            }
        }
        else
        {
            dfs(arr, idx+1, xVal);
        }
    }

    boolean check(char arr[])
    {
        if(arr[0] == '0' && arr.length > 1)
            return false;
        //bSystem.out.println("AT CHECK  "+Arrays.toString(arr));
        int temp = 0;
        for(int i = 0; i<arr.length; i++)
        {
            int num = arr[i] - '0';
            temp = temp * 10 + num;
        }

        return(temp % 25 == 0);
    }
}


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

public class P1575D {
    public static void main(String[] args) throws IOException {
        MyScanner scanner = new MyScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        char[] s = scanner.nextToken().toCharArray();
        int ans = 0;

        if (s.length == 1) {
            if (s[0] == '0' || s[0] == '_' || s[0] == 'X') {
                ans = 1;
            }
        } else {
            int n = s.length;
            if (!(s[n - 1] == 'X' && s[n - 2] == 'X')) {
                // put 25
                if (canPut(s, n - 1, '5') && canPut(s, n - 2, '2')) {
                    char[] s1 = Arrays.copyOf(s, n);
                    put(s1, n - 1, '5');
                    put(s1, n - 2, '2');
                    ans += possible(s1);
                }
                // put 50
                if (canPut(s, n - 1, '0') && canPut(s, n - 2, '5')) {
                    char[] s1 = Arrays.copyOf(s, n);
                    put(s1, n - 1, '0');
                    put(s1, n - 2, '5');
                    ans += possible(s1);
                }
                // put 75
                if (canPut(s, n - 1, '5') && canPut(s, n - 2, '7')) {
                    char[] s1 = Arrays.copyOf(s, n);
                    put(s1, n - 1, '5');
                    put(s1, n - 2, '7');
                    ans += possible(s1);
                }
            }
            // put 00
            if (s[n - 1] == 'X' && s[n - 2] == 'X') {
                char[] s1 = Arrays.copyOf(s, n);
                put(s1, n - 1, '0');
                ans += possible(s1);
            } else if (canPut(s, n - 1, '0') && canPut(s, n - 2, '0')) {
                char[] s1 = Arrays.copyOf(s, n);
                put(s1, n - 1, '0');
                put(s1, n - 2, '0');
                ans += possible(s1);
            }
        }
        writer.println(ans);

        writer.flush();
    }

    private static boolean canPut(char[] s, int p, char d) {
        if (s[p] == 'X' || s[p] == '_') {
            return true;
        }
        return s[p] == d;
    }

    private static void put(char[] s, int p, char d) {
        if (s[p] == 'X') {
            replace(s, d);
        } else {
            s[p] = d;
        }
    }

    private static void replace(char[] s, char d) {
        for (int i = 0; i < s.length; i++) {
            if (s[i] == 'X') {
                s[i] = d;
            }
        }
    }

    private static int possible(char[] s) {
        int p = 1;

        if (s[0] == '0') {
            return 0;
        }
        if (s[0] == '_') {
            p *= 9;
        } else if (s[0] == 'X') {
            p *= 9;
            replace(s, '1');
        }
        for (int i = 1; i < s.length; i++) {
            if (s[i] == '_') {
                p *= 10;
            } else if (s[i] == 'X') {
                p *= 10;
                replace(s, '1');
            }
        }

        return p;
    }

    private static class MyScanner {
        private BufferedReader reader;
        private StringTokenizer st;

        public MyScanner(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

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

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

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


import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[])
    {
        FastReader input=new FastReader();
        PrintWriter out=new PrintWriter(System.out);
        int T=1;
        while(T-->0)
        {
            String s=input.next();
            if(s.length()==1)
            {
                if(s.charAt(0)=='0' || s.charAt(0)=='_' || s.charAt(0)=='X') out.println(1);
                else out.println(0);
            }
            else
            {
                int f=0;
                for(int i=0;i<s.length();i++)
                {
                    if(s.charAt(i)=='X')
                    {
                        f=1;
                        break;
                    }
                }
                if(f==0)
                {
                    out.println(fun(s));
                }
                else
                {
                    int sum=0;
                    for(int i=0;i<10;i++)
                    {
                        char ch[]=s.toCharArray();
                        for(int j=0;j<s.length();j++)
                        {
                            if(ch[j]=='X')
                            {
                                ch[j]=(char)(i+'0');
                            }
                        }
                        String str=String.copyValueOf(ch);
                        sum+=fun(str);
                    }
                    out.println(sum);
                }
            }
        }
        out.close();
    }
    public static int fun(String s)
    {
        int n=s.length();
        int p=0;
        if(s.charAt(0)!='0')p=1;
        for(int i=0;i<n-2;i++)
        {
            if(s.charAt(i)=='_')
            {
                if(i==0) p*=9;
                else p*=10;
            }
        }
        int p1=0;
        if(s.charAt(n-1)=='_' && s.charAt(n-2)=='_')
        {
            p1=4;
            if(n==2) p1=3;
        }
        else if(s.charAt(n-1)=='_')
        {
            if(s.charAt(n-2)=='0' || s.charAt(n-2)=='5' || s.charAt(n-2)=='2' || s.charAt(n-2)=='7') p1=1;
        }
        else if(s.charAt(n-2)=='_')
        {
            if(s.charAt(n-1)=='0')
            {
                p1=2;
                if(n==2) p1=1;
            }
            else if(s.charAt(n-1)=='5')
            {
                p1=2;
            }
        }
        else
        {
            int val=Integer.valueOf(s.substring(n-2));
            if(val%25==0) p1=1;
        }
        int pro=p*p1;
        return pro;
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt()
        {
            return Integer.parseInt(next());
        }
        long nextLong()
        {
            return Long.parseLong(next());
        }
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
        String nextLine()
        {
            String str="";
            try
            {
                str=br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.*;
import java.lang.Math;
import java.lang.reflect.Array;
import java.util.*;
import javax.swing.text.DefaultStyledDocument.ElementSpec;

public final class Solution {

  static BufferedReader br = new BufferedReader(
    new InputStreamReader(System.in)
  );
  static BufferedWriter bw = new BufferedWriter(
    new OutputStreamWriter(System.out)
  );
  static StringTokenizer st;

  /*write your constructor and global variables here*/

  static class sortCond implements Comparator<Pair<Integer, Integer>> {

    @Override
    public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) {
      if (p1.a <= p2.a) {
        return -1;
      } else {
        return 1;
      }
    }
  }

  static class Rec {

    int a;
    int b;
    long c;

    Rec(int a, int b, long c) {
      this.a = a;
      this.b = b;
      this.c = c;
    }
  }

  static class Pair<f, s> {

    f a;
    s b;

    Pair(f a, s b) {
      this.a = a;
      this.b = b;
    }
  }

  interface modOperations {
    int mod(int a, int b, int mod);
  }

  static int findBinaryExponentian(int a, int pow, int mod) {
    if (pow == 1) {
      return a;
    } else if (pow == 0) {
      return 1;
    } else {
      int retVal = findBinaryExponentian(a, (int) pow / 2, mod);
      int val = (pow % 2 == 0) ? 1 : a;
      return modMul.mod(modMul.mod(retVal, retVal, mod), val, mod);
    }
  }

  static int findPow(int a, int b, int mod) {
    if (b == 1) {
      return a % mod;
    } else if (b == 0) {
      return 1;
    } else {
      int res = findPow(a, (int) b / 2, mod);
      return modMul.mod(res, modMul.mod(res, (b % 2 == 1 ? a : 1), mod), mod);
    }
  }

  static int bleft(int ele, int[] sortedArr) {
    int l = 0;
    int h = sortedArr.length - 1;
    int ans = -1;
    while (l <= h) {
      int mid = l + (int) (h - l) / 2;
      if (sortedArr[mid] < ele) {
        ans = mid;
        l = mid + 1;
      } else if (sortedArr[mid] >= ele) {
        h = mid - 1;
      }
    }
    return ans;
  }

  static int gcd(int a, int b) {
    int div = b;
    int rem = a % b;
    while (rem != 0) {
      int temp = rem;
      rem = div % rem;
      div = temp;
    }
    return div;
  }

  static long[] log(long no, long n) {
    long i = 1;
    int cnt = 0;
    long sum = 0l;
    long arr[] = new long[2];
    while (i < no) {
      sum += i;
      cnt++;
      if (sum == n) {
        arr[0] = 1l * cnt;
        arr[1] = sum;
        break;
      }
      i *= 2l;
    }
    if (arr[0] == 0) {
      arr[0] = cnt;
      arr[1] = sum;
    }
    return arr;
  }

  static modOperations modAdd = (int a, int b, int mod) -> {
    return (a % mod + b % mod) % mod;
  };
  static modOperations modSub = (int a, int b, int mod) -> {
    return (int) ((1l * a % mod - 1l * b % mod + 1l * mod) % mod);
  };
  static modOperations modMul = (int a, int b, int mod) -> {
    return (int) ((1l * (a % mod) * 1l * (b % mod)) % (1l * mod));
  };
  static modOperations modDiv = (int a, int b, int mod) -> {
    return modMul.mod(a, findBinaryExponentian(b, mod - 1, mod), mod);
  };

  static HashSet<Integer> primeList(int MAXI) {
    int[] prime = new int[MAXI + 1];
    HashSet<Integer> obj = new HashSet<>();
    for (int i = 2; i <= (int) Math.sqrt(MAXI) + 1; i++) {
      if (prime[i] == 0) {
        obj.add(i);
        for (int j = i * i; j <= MAXI; j += i) {
          prime[j] = 1;
        }
      }
    }
    for (int i = (int) Math.sqrt(MAXI) + 1; i <= MAXI; i++) {
      if (prime[i] == 0) {
        obj.add(i);
      }
    }
    return obj;
  }

  static int[] factorialList(int MAXI, int mod) {
    int[] factorial = new int[MAXI + 1];
    factorial[2] = 1;
    for (int i = 3; i < MAXI + 1; i++) {
      factorial[i] = modMul.mod(factorial[i - 1], i, mod);
    }
    return factorial;
  }

  static void put(HashMap<Integer, Integer> cnt, int key) {
    if (cnt.containsKey(key)) {
      cnt.replace(key, cnt.get(key) + 1);
    } else {
      cnt.put(key, 1);
    }
  }

  static long arrSum(ArrayList<Long> arr) {
    long tot = 0;
    for (int i = 0; i < arr.size(); i++) {
      tot += arr.get(i);
    }
    return tot;
  }

  static int ord(char b) {
    return (int) b - (int) 'a';
  }

  static int optimSearch(int[] cnt, int lower_bound, int pow, int n) {
    int l = lower_bound + 1;
    int h = n;
    int ans = 0;
    while (l <= h) {
      int mid = l + (h - l) / 2;
      if (cnt[mid] - cnt[lower_bound] == pow) {
        return mid;
      } else if (cnt[mid] - cnt[lower_bound] < pow) {
        ans = mid;
        l = mid + 1;
      } else {
        h = mid - 1;
      }
    }
    return ans;
  }

  static Pair<Long, Integer> ret_ans(ArrayList<Integer> ans) {
    int size = ans.size();
    int mini = 1000000000 + 1;
    long tit = 0l;
    for (int i = 0; i < size; i++) {
      tit += 1l * ans.get(i);
      mini = Math.min(mini, ans.get(i));
    }
    return new Pair<>(tit - mini, mini);
  }

  static int factorList(
    HashMap<Integer, Integer> maps,
    int no,
    int maxK,
    int req
  ) {
    int i = 1;
    while (i * i <= no) {
      if (no % i == 0) {
        if (i != no / i) {
          put(maps, no / i);
        }
        put(maps, i);
        if (maps.get(i) == req) {
          maxK = Math.max(maxK, i);
        }
        if (maps.get(no / i) == req) {
          maxK = Math.max(maxK, no / i);
        }
      }
      i++;
    }
    return maxK;
  }

  static ArrayList<Integer> getKeys(HashMap<Integer, Integer> maps) {
    ArrayList<Integer> vals = new ArrayList<>();
    for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
      vals.add(map.getKey());
    }
    return vals;
  }

  static ArrayList<Integer> getValues(HashMap<Integer, Integer> maps) {
    ArrayList<Integer> vals = new ArrayList<>();
    for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
      vals.add(map.getValue());
    }
    return vals;
  }

  static int getMax(ArrayList<Integer> arr) {
    int max = arr.get(0);
    for (int i = 1; i < arr.size(); i++) {
      if (arr.get(i) > max) {
        max = arr.get(i);
      }
    }
    return max;
  }

  static int getMin(ArrayList<Integer> arr) {
    int max = arr.get(0);
    for (int i = 1; i < arr.size(); i++) {
      if (arr.get(i) < max) {
        max = arr.get(i);
      }
    }
    return max;
  }

  static int list[][] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };

  /*write your  methods and classes here*/

  public static void main(String[] args) throws IOException {
    String s = br.readLine();
    int n = s.length();
    int i;
    if (
      (s.charAt(0) == '0' || s.charAt(0) == '_' || s.charAt(0) == 'X') &&
      s.length() == 1
    ) {
      bw.write("1\n");
      bw.flush();
    } else if (s.length() == 1) {
      bw.write("0\n");
      bw.flush();
    } else if (s.charAt(0) == '0') {
      bw.write("0\n");
      bw.flush();
    } else {
      String digits[] = { "25", "50", "75", "00" };
      String arr1[] = { "__", "_X", "X_", "XX" };
      int way[] = { 4, 4, 4, 1 };
      way[1] = s.charAt(0) == 'X' ? 2 : 4;
      way[2] = s.charAt(0) == 'X' ? 3 : 4;
      way[0] = s.length() == 2 ? 3 : way[0];
      way[1] = s.length() == 2 ? 3 : way[1];
      int ways = 0;
      String v = s.substring(n - 2, n);
      for (i = 0; i < 4; i++) {
        if (v.equals(digits[i])) {
          ways = 1;
        }
      }
      if (v.charAt(0) == '_' || v.charAt(0) == 'X') {
        ways = 2;
        if (v.charAt(1) == '0' && s.charAt(0) == 'X') {
          ways = 1;
        }
      } else if (v.charAt(1) == '_' || v.charAt(1) == 'X') {
        ways = 1;
      }
      for (i = 0; i < 4; i++) {
        if (v.equals(arr1[i])) {
          //System.out.println(arr1[i] + " " + i + " " + way[i]);
          ways = way[i];
        }
      }
      //System.out.println(ways);
      if (v.equals("XX") && s.charAt(0) == 'X') {
        ways = 0;
      }

      if (
        v.charAt(0) != '2' &&
        v.charAt(0) != '5' &&
        v.charAt(0) != '7' &&
        v.charAt(0) != '0' &&
        v.charAt(0) != 'X' &&
        v.charAt(0) != '_'
      ) {
        ways = 0;
      }
      if (
        v.charAt(1) != '0' &&
        v.charAt(1) != '5' &&
        v.charAt(1) != 'X' &&
        v.charAt(1) != '_'
      ) {
        ways = 0;
      }

      boolean ok = false;
      long toti = 1l;
      for (i = 0; i < s.length() - 2; i++) {
        if (s.charAt(i) == 'X') {
          ok = true;
        }
        if (s.charAt(i) == '_') {
          if (i == 0) {
            toti *= 9l;
          } else {
            toti *= 10l;
          }
        }
      }
      if (v.charAt(0) != 'X' && v.charAt(1) != 'X') {
        if (ok) {
          if (s.charAt(0) == 'X') {
            toti *= 1l * 9;
          } else {
            toti *= 1l * 10;
          }
        }
      }
      //System.out.println(ways);
      toti *= 1l * ways;
      bw.write(Long.toString(toti) + "\n");
      bw.flush();
    }
  }
}


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

public class E {

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

        String s = sc.next();
        int l = s.length();

        if(l < 2){
            if(s.equals("0") || s.equals("_") || s.equals("X")){
                System.out.println(1);
            }
            else{
                System.out.println(0);
            }
            System.exit(0);
        }
        else if(l == 2){
            int count = 0;
            for(int i=10;i<=95;i+=5){
                if(i%25 != 0)
                    continue;
                String str = Integer.toString(i);

                if('0'<=s.charAt(0) && s.charAt(0)<='9'){
                    if('0'<=s.charAt(1) && s.charAt(1)<='9'){
                        if(s.equals(str)){
                            count++;
                        }
                    }
                    else {
                        if(s.charAt(0)==str.charAt(0))
                            count++;
                    }
                }
                else if(s.charAt(0)=='_'){
                    if('0'<=s.charAt(1) && s.charAt(1)<='9'){
                        if(s.charAt(1)==str.charAt(1)){
                            count++;
                        }
                    }
                    else {
                        count++;
                    }
                }
                else{
                    if('0'<=s.charAt(1) && s.charAt(1)<='9'){
                        if(s.charAt(1)==str.charAt(1)){
                            count++;
                        }
                    }
                    else if(s.charAt(1)=='_'){
                        count++;
                    }
                }
            }

            System.out.println(count);
            System.exit(0);
        }
        else{
            int start = (int) (Math.pow(10, l-1));
            int end = (int) (Math.pow(10, l));

            int count = 0;
            for(int i=start;i<end;i+=25){
                String str = Integer.toString(i);

                Set<Character> set = new HashSet<>();
                boolean flag = true;
                for(int j=0;j<l;j++){
                    if(s.charAt(j)=='_')
                        continue;
                    else if(s.charAt(j)=='X'){
                        set.add(str.charAt(j));
                    }
                    else if(s.charAt(j)!=str.charAt(j)){
                        flag = false;
                        break;
                    }
                }

                if(flag && set.size() < 2){
                    count++;
                }
            }

            System.out.println(count);
        }

        /*int dash = 0, x = 0;
        for(int i=0;i<l;i++){
            if(s.charAt(i)=='X')
                x++;
            else if(s.charAt(i)=='_')
                dash++;
        }

        if((s.charAt(l-2)=='0' && s.charAt(l-1)=='0') || (s.charAt(l-2)=='2' && s.charAt(l-1)=='5') || (s.charAt(l-2)=='5' && s.charAt(l-1)=='0') || (s.charAt(l-2)=='7' && s.charAt(l-1)=='5')){
            if(s.charAt(0)=='_'){
                int ans = (int) (9 * Math.pow(10, dash - 1));
                if(x > 0)
                    ans *= 10;

                System.out.println(ans);
            }
            else if(s.charAt(0)=='X'){
                int ans = (int) (Math.pow(10, dash));
                ans *= 9;

                System.out.println(ans);
            }
            else{
                int ans = (int) Math.pow(10, dash);
                if(x > 0)
                    ans *= 10;

                System.out.println(ans);
            }
        }
        else if(s.charAt(l-2)=='_'){
            dash--;
            if(s.charAt(l-1)=='0' || s.charAt(l-1)=='5'){
                if(s.charAt(0)=='_'){
                    int ans = (int) (9 * Math.pow(10, dash - 1));
                    if(x > 0)
                        ans *= 10;

                    ans *= 2;

                    System.out.println(ans);
                }
                else if(s.charAt(0)=='X'){
                    int ans = (int) (Math.pow(10, dash));
                    ans *= 9;

                    ans *= 2;

                    System.out.println(ans);
                }
                else{
                    int ans = (int) Math.pow(10, dash);
                    if(x > 0)
                        ans *= 10;

                    ans *= 2;

                    System.out.println(ans);
                }
            }
            else if(s.charAt(l-1)=='_'){
                dash--;
                if(s.charAt(0)=='_'){
                    int ans = (int) (9 * Math.pow(10, dash - 1));
                    if(x > 0)
                        ans *= 10;

                    ans *= 4;

                    System.out.println(ans);
                }
                else if(s.charAt(0)=='X'){
                    int ans = (int) (Math.pow(10, dash));
                    ans *= 9;

                    ans *= 4;

                    System.out.println(ans);
                }
                else{
                    int ans = (int) Math.pow(10, dash);
                    if(x > 0)
                        ans *= 10;

                    ans *= 4;

                    System.out.println(ans);
                }
            }
            else if(s.charAt(l-1)=='X'){
                if(s.charAt(0)=='_'){
                    int ans = (int) (9 * Math.pow(10, dash - 1));
                    ans *= 4;

                    System.out.println(ans);
                }
                else if(s.charAt(0)=='X'){
                    int ans = (int) (Math.pow(10, dash));
                    ans *= 4;

                    System.out.println(ans);
                }
                else{
                    int ans = (int) Math.pow(10, dash);
                    ans *= 4;

                    System.out.println(ans);
                }
            }
            else{
                System.out.println();
            }
        }
        else if(s.charAt(l-2)=='X'){
            if(s.charAt(l-1)=='0'){
                if(s.charAt(0)=='_'){
                    int ans = (int) (9 * Math.pow(10, dash - 1));
                    ans *= 2;

                    System.out.println(ans);
                }
                else if(s.charAt(0)=='X'){
                    int ans = (int) (Math.pow(10, dash));

                    System.out.println(ans);
                }
                else{
                    int ans = (int) Math.pow(10, dash);

                    ans *= 2;

                    System.out.println(ans);
                }
            }
            else if(s.charAt(l-1)=='5'){
                if(s.charAt(0)=='_'){
                    int ans = (int) (9 * Math.pow(10, dash - 1));
                    ans *= 2;

                    System.out.println(ans);
                }
                else if(s.charAt(0)=='X'){
                    int ans = (int) (Math.pow(10, dash));
                    ans *= 2;

                    System.out.println(ans);
                }
                else{
                    int ans = (int) Math.pow(10, dash);

                    ans *= 2;

                    System.out.println(ans);
                }
            }
            else if(s.charAt(l-1)=='_'){
                dash--;
                if(s.charAt(0)=='_'){
                    int ans = (int) (9 * Math.pow(10, dash - 1));
                    if(x > 0)
                        ans *= 10;

                    ans *= 4;

                    System.out.println(ans);
                }
                else if(s.charAt(0)=='X'){
                    int ans = (int) (Math.pow(10, dash));
                    ans *= 9;

                    ans *= 4;

                    System.out.println(ans);
                }
                else{
                    int ans = (int) Math.pow(10, dash);
                    if(x > 0)
                        ans *= 10;

                    ans *= 4;

                    System.out.println(ans);
                }
            }
            else if(s.charAt(l-1)=='X'){
                if(s.charAt(0)=='_'){
                    int ans = (int) (9 * Math.pow(10, dash - 1));
                    ans *= 4;

                    System.out.println(ans);
                }
                else if(s.charAt(0)=='X'){
                    int ans = (int) (Math.pow(10, dash));
                    ans *= 4;

                    System.out.println(ans);
                }
                else{
                    int ans = (int) Math.pow(10, dash);
                    ans *= 4;

                    System.out.println(ans);
                }
            }
            else{
                System.out.println();
            }
        }
        else{
            System.out.println(0);
        }*/

        sc.close();
    }
}


// OM NAMAH SHIVAY
// Stay strong. Be brave. Always belief.
// NOT WITH MY GIO

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

public class Vaibhav {

    static boolean prime[];

    static class Pair implements Comparable<Pair> {
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair o) {

            return (int)(this.a - o.a);
            //else return this.b - o.b;
        }
    }

    static long power(long x, long y, long p) {
        if (y == 0) return 1;
        if (x == 0) return 0;
        long res = 1l;
        x = x % p;
        while (y > 0) {
            if (y % 2 == 1) res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    static void sort(long[] a) {
        ArrayList<Long> l = new ArrayList<>();
        for (long i : a) l.add(i);
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

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

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

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

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

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

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

    static void sieveOfEratosthenes(int n) {
        prime = new boolean[n + 1];
        for (int i = 0; i <= n; i++) prime[i] = true;
        for (int p = 2; p * p <= n; p++) {
            if (prime[p] == true) {
                for (int i = p * p; i <= n; i += p) prime[i] = false;
            }
        }
    }

    public static int log2(int x) {
        return (int) (Math.log(x) / Math.log(2));
    }

    static long binomialCoeff(long n, long r) {
        if (r > n) return 0l;
        long m = 1000000007l;
        long inv[] = new long[(int) r + 1];
        inv[0] = 1;
        if (r + 1 >= 2) inv[1] = 1;
        for (int i = 2; i <= r; i++) {
            inv[i] = m - (m / i) * inv[(int) (m % i)] % m;
        }
        long ans = 1l;
        for (int i = 2; i <= r; i++) {
            ans = (int) (((ans % m) * (inv[i] % m)) % m);
        }
        for (int i = (int) n; i >= (n - r + 1); i--) {
            ans = (int) (((ans % m) * (i % m)) % m);
        }
        return ans;
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    static long[] facts=new long[3_000_00];
    //don't care about your feelings

    static long mul(long a, long b) {
        return a*b%mod;
    }

    static long add(long a, long b) {
        return (a+b)%mod;
    }

    /*static void precomp() {
        facts[0]=1;
        for (int i=1; i<facts.length; i++) facts[i]=mul(facts[i-1], i);
    }

    static long exp(long base, long pow) {
        if (pow==0) return 1;
        long half=exp(base, pow/2);
        if (pow%2==0) return mul(half, half);
        return mul(half, mul(half, base));
    }

    static long modInv(long x) {
        return exp(x, mod-2);
    }

    static long nCk(int n, int k) {
        if(n<k) return 0;
        return mul(facts[n], mul(modInv(facts[k]), modInv(facts[n-k])));
    }
*/

    static BigInteger bi(String str) {
        return new BigInteger(str);
    }

    // Author - vaibhav_1710
    static FastScanner fs = null;
    static long mod = 1_000_000_007;
    static int[][] dirs = {{0, -1},
            {-1, 0},
            {0, 1},
            {1, 0},
    };

    static int pk[];
    public static void main(String[] args) {
        fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;

        outer:
        while (t-- > 0) {
            String s = fs.next();
            int len = s.length();
            int max = (int)Math.pow(10,len)-1;
            int min = (int)Math.pow(10,len-1);
            if(min==1)min--;
            if(s.charAt(0)=='0' && s.length()>1){
                out.println("0");
                continue outer;
            }
            long ans=0;
            for(int i=min;i<=max;i++){
                if(i%25==0) {
                    ans += (can(i, s) == true ? 1 : 0);
                }
            }
            out.println(ans);
        }
        out.close();
    }

    public static boolean can(int v,String s){
        String ss = Integer.toString(v);
        char king_me = '?';
        for(int i=0;i<ss.length();i++){
         if(s.charAt(i)!='_' && s.charAt(i)!='X'){
             if(s.charAt(i)!=ss.charAt(i)){
                 return false;
             }
         }else if(s.charAt(i)=='_') {
             continue;
         }else if(s.charAt(i)=='X'){
             if(king_me!='?' && ss.charAt(i)!=king_me){
                 return false;
             }else if(king_me=='?'){
                 king_me = ss.charAt(i);
             }else{
                 continue;
             }
         }
        }
            return true;
    }

}


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

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();

        char s[]=bu.readLine().toCharArray();
        boolean x=false;
        int n=s.length,i;
        for(i=0;i<n;i++) x|=s[i]=='X';

        int ans=0;
        char s2[]=new char[n];
        for(i=0;i<10;i++)
        {
            int j;
            for(j=0;j<n;j++)
            if(s[j]=='X') s2[j]=(char)('0'+i);
            else s2[j]=s[j];
            if(s2[0]=='0') continue;    //not possible

            int dp[][]=new int[2][25],cur=1,l,k;
            dp[0][0]=1;
            for(j=0;j<n;j++)
            {
                for(k=0;k<25;k++) dp[cur][k]=0;
                int lo=0,hi=9,nxt;
                if(s2[j]!='_') lo=hi=(s2[j]-'0');
                else if(s2[j]=='_' && j==0) lo++;

                for(k=0;k<25;k++)
                for(l=lo;l<=hi;l++)
                {
                    nxt=(k*10+l)%25;
                    dp[cur][nxt]+=dp[cur^1][k];
                }
                cur^=1;
            }

            ans+=dp[cur^1][0];
            if(!x) break;
        }

        if(n==1 && (s[0]=='_' || s[0]=='X' || s[0]=='0')) ans++;
        System.out.println(ans);
    }
}


import java.util.*;

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

/**
 * @author Naitik
 *
 */
public class Main

{
	 static FastReader sc=new FastReader();
	 static long dp[][][];
	 //static int v[][];
	 static int mod=998244353;;
//	 static int mod=1000000007;
	 static long max;
	 static long bit[];
	 static long bit1[];
//	 static long seg[];
	 //static long fact[];
//	 static long A[];
	// static TreeMap<Integer,Integer> map;
	 //static StringBuffer sb=new StringBuffer("");
	 static HashMap<Integer,Integer> map;
	   static PrintWriter out=new PrintWriter(System.out);
	  public static void main(String[] args)
{

		 //  StringBuffer sb=new StringBuffer("");
		  int ttt=1;
		     // ttt =i();
	        outer :while (ttt-- > 0)
			{
	        	char A[]=s().toCharArray();
	        	if(A.length==1 && A[0]=='0') {
	        		System.out.println("1");
	        		return;
	        	}
	        	if(A[0]=='0') {
	        		System.out.println("0");
	        		return;
	        	}
	        	if(A.length==1) {
	        		if(A[0]=='X' || A[0]=='_') {
	        			System.out.println("1");
	        			return;
	        		}
	        	}
	        	dp=new long[A.length+1][25][11];
	        	fill(dp);
	        	System.out.println(go(A, 0, 0, 10));

	        }
	        //System.out.println(sb.toString());
		     out.close();

	    //CHECK FOR N=1                    //CHECK FOR M=0
        //CHECK FOR N=1                    //CHECK FOR M=0
       	//CHECK FOR N=1

    }
	  static long go(char A[],int i,int pv,int v) {
		  if(i==A.length) {
			  if(pv==0)
				  return 1;
			  return 0;
		  }
		  if(dp[i][pv][v]!=-1)
			  return dp[i][pv][v];
		  long ans=0;
		  if(A[i]=='_') {
			  for(int j=0;j<10;j++) {
				  if(i==0 && j==0)
					  continue;
				  int y=pv*10+j;
				  y%=25;
				  ans+=go(A, i+1, y, v);
			  }
		  }
		  else if(A[i]=='X') {
			  if(v!=10) {
				  ans+=go(A, i+1, (pv*10+v)%25, v);
			  }
			  else {
				  for(int j=0;j<10;j++) {
					  if(i==0 && j==0)
						  continue;
					  int y=pv*10+j;
					  y%=25;
					  ans+=go(A, i+1, y, j);
				  }
			  }
		  }
		  else {
			  ans+=go(A, i+1, (pv*10+A[i]-'0')%25, v);
		  }
		  return dp[i][pv][v]=ans;
	  }

static class Pair implements Comparable<Pair>
     {
    	 int x;
    	 int y;
    	 int z;
    	 Pair(int x,int y){
    		 this.x=x;
    		 this.y=y;
    		// this.z=z;

    	 }
		@Override
		public int compareTo(Pair o) {
			if(this.x>o.x)
				return +1;
			else if(this.x<o.x)
				return -1;
			else {
				if(this.y>o.y)
					return 1;
				else if(this.y<o.y)
					return -1;
				else
					return 0;
			}
		}
//		public int hashCode()
//		{
//			final int temp = 14;
//			int ans = 1;
//			ans =x*31+y*13;
//			return ans;
//		}
//		@Override
//		public boolean equals(Object o)
//		{
//			if (this == o) {
//				return true;
//			}
//			if (o == null) {
//				return false;
//			}
//			if (this.getClass() != o.getClass()) {
//				return false;
//			}
//			Pair other = (Pair)o;
//			if (this.x != other.x || this.y!=other.y) {
//				return false;
//			}
//			return true;
//		}
//
		/* FOR TREE MAP PAIR USE */

//		public int compareTo(Pair o) {
// 			if (x > o.x) {
// 				return 1;
// 			}
// 			if (x < o.x) {
// 				return -1;
// 			}
// 			if (y > o.y) {
// 				return 1;
// 			}
// 			if (y < o.y) {
// 				return -1;
// 			}
// 			return 0;
// 		}

     }

//static int find(int A[],int a) {
//	  if(A[a]<0)
//		  return a;
//	  return A[a]=find(A, A[a]);
//}
static int find(int A[],int a) {
	  if(A[a]==a)
		  return a;
	  return A[a]=find(A, A[a]);
}
//FENWICK TREE
static void update(int i, int x){
	for(; i < bit.length; i += (i&-i))
		bit[i] += x;
}

static int sum(int i){
	int ans = 0;
	for(; i > 0; i -= (i&-i))
		ans += bit[i];
	return ans;
}
static void update1(int i, long x){
	for(; i < bit1.length; i += (i&-i))
		bit1[i] += x;
}

static int sum1(int i){
	int ans = 0;
	for(; i > 0; i -= (i&-i))
		ans += bit1[i];
	return ans;
}
//END
static void add(int v) {
	if(!map.containsKey(v)) {
		map.put(v, 1);
	}
	else {
		map.put(v, map.get(v)+1);
	}
}
static void remove(int v) {
	if(map.containsKey(v)) {
		map.put(v, map.get(v)-1);
		if(map.get(v)==0)
			map.remove(v);
	}
}
public static int upper(int A[],int k,int si,int ei)
{
	int l=si;
	int u=ei;
	int ans=-1;
	while(l<=u) {
		int mid=(l+u)/2;
		if(A[mid]<=k) {
			ans=mid;
			l=mid+1;
		}
		else {
			u=mid-1;
		}
	}
	return ans;
}
public static int lower(int A[],int k,int si,int ei)
{
	int l=si;
	int u=ei;
	int ans=-1;
	while(l<=u) {
		int mid=(l+u)/2;
		if(A[mid]<=k) {
			l=mid+1;
		}
		else {
			ans=mid;
			u=mid-1;
		}
	}
	return ans;

}
static int[] copy(int A[]) {
	int B[]=new int[A.length];
	for(int i=0;i<A.length;i++) {
		B[i]=A[i];
	}
	return B;
}
static long[] copy(long A[]) {
	long B[]=new long[A.length];
	for(int i=0;i<A.length;i++) {
		B[i]=A[i];
	}
	return B;
}
static int[] input(int n) {
	int A[]=new int[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.nextInt();
	   }
	   return A;
   }
static long[] inputL(int n) {
	long A[]=new long[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.nextLong();
	   }
	   return A;
   }
static String[] inputS(int n) {
	String A[]=new String[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.next();
	   }
	   return A;
   }
static long sum(int A[]) {
	long sum=0;
	for(int i : A) {
		sum+=i;
	}
	return sum;
}
static long sum(long A[]) {
	long sum=0;
	for(long i : A) {
		sum+=i;
	}
	return sum;
}
static void reverse(long A[]) {
	int n=A.length;
	long B[]=new long[n];
	for(int i=0;i<n;i++) {
		B[i]=A[n-i-1];
	}
	for(int i=0;i<n;i++)
		A[i]=B[i];

}
static void reverse(int A[]) {
	int n=A.length;
	int B[]=new int[n];
	for(int i=0;i<n;i++) {
		B[i]=A[n-i-1];
	}
	for(int i=0;i<n;i++)
		A[i]=B[i];

}
static void input(int A[],int B[]) {
	   for(int i=0;i<A.length;i++) {
		   A[i]=sc.nextInt();
		   B[i]=sc.nextInt();
	   }
}
static int[][] input(int n,int m){
	int A[][]=new int[n][m];
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			A[i][j]=i();
		}
	}
	return A;
}
static char[][] charinput(int n,int m){
	char A[][]=new char[n][m];
	for(int i=0;i<n;i++) {
		String s=s();
		for(int j=0;j<m;j++) {
			A[i][j]=s.charAt(j);
		}
	}
	return A;
}

static int max(int A[]) {
	int max=Integer.MIN_VALUE;
	for(int i=0;i<A.length;i++) {
		max=Math.max(max, A[i]);
	}
	return max;
}
static int min(int A[]) {
	int min=Integer.MAX_VALUE;
	for(int i=0;i<A.length;i++) {
		min=Math.min(min, A[i]);
	}
	return min;
}
static long max(long A[]) {
	long max=Long.MIN_VALUE;
	for(int i=0;i<A.length;i++) {
		max=Math.max(max, A[i]);
	}
	return max;
}
static long min(long A[]) {
	long min=Long.MAX_VALUE;
	for(int i=0;i<A.length;i++) {
		min=Math.min(min, A[i]);
	}
	return min;
}
static long [] prefix(long A[]) {
	long p[]=new long[A.length];
	p[0]=A[0];
	for(int i=1;i<A.length;i++)
		p[i]=p[i-1]+A[i];
	return p;
}
static long [] prefix(int A[]) {
	long p[]=new long[A.length];
	p[0]=A[0];
	for(int i=1;i<A.length;i++)
		p[i]=p[i-1]+A[i];
	return p;
}
static long [] suffix(long A[]) {
	long p[]=new long[A.length];
	p[A.length-1]=A[A.length-1];
	for(int i=A.length-2;i>=0;i--)
		p[i]=p[i+1]+A[i];
	return p;
}
static long [] suffix(int A[]) {
	long p[]=new long[A.length];
	p[A.length-1]=A[A.length-1];
	for(int i=A.length-2;i>=0;i--)
		p[i]=p[i+1]+A[i];
	return p;
}
static void fill(int dp[]) {
	Arrays.fill(dp, -1);
}
static void fill(int dp[][]) {
	for(int i=0;i<dp.length;i++)
	Arrays.fill(dp[i], -1);
}
static void fill(int dp[][][]) {
	for(int i=0;i<dp.length;i++) {
		for(int j=0;j<dp[0].length;j++) {
			Arrays.fill(dp[i][j],-1);
		}
	}
}
static void fill(int dp[][][][]) {
	for(int i=0;i<dp.length;i++) {
		for(int j=0;j<dp[0].length;j++) {
			for(int k=0;k<dp[0][0].length;k++) {
			Arrays.fill(dp[i][j][k],-1);
			}
		}
	}
}
static void fill(long dp[]) {
	Arrays.fill(dp, -1);
}
static void fill(long dp[][]) {
	for(int i=0;i<dp.length;i++)
	Arrays.fill(dp[i], -1);
}
static void fill(long dp[][][]) {
	for(int i=0;i<dp.length;i++) {
		for(int j=0;j<dp[0].length;j++) {
			Arrays.fill(dp[i][j],-1);
		}
	}
}
static void fill(long dp[][][][]) {
	for(int i=0;i<dp.length;i++) {
		for(int j=0;j<dp[0].length;j++) {
			for(int k=0;k<dp[0][0].length;k++) {
			Arrays.fill(dp[i][j][k],-1);
			}
		}
	}
}
static int min(int a,int b) {
	return Math.min(a, b);
}
static int min(int a,int b,int c) {
	return Math.min(a, Math.min(b, c));
}
static int min(int a,int b,int c,int d) {
	return Math.min(a, Math.min(b, Math.min(c, d)));
}
static int max(int a,int b) {
	return Math.max(a, b);
}
static int max(int a,int b,int c) {
	return Math.max(a, Math.max(b, c));
}
static int max(int a,int b,int c,int d) {
	return Math.max(a, Math.max(b, Math.max(c, d)));
}
static long min(long a,long b) {
	return Math.min(a, b);
}
static long min(long a,long b,long c) {
	return Math.min(a, Math.min(b, c));
}
static long min(long a,long b,long c,long d) {
	return Math.min(a, Math.min(b, Math.min(c, d)));
}
static long max(long a,long b) {
	return Math.max(a, b);
}
static long max(long a,long b,long c) {
	return Math.max(a, Math.max(b, c));
}
static long max(long a,long b,long c,long d) {
	return Math.max(a, Math.max(b, Math.max(c, d)));
}

static long power(long x, long y, long p)
{

	if(y==0)
		return 1;
	if(x==0)
		return 0;
    long res = 1;
    x = x % p;

    while (y > 0) {

        if (y % 2 == 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }

    return res;
}
static long power(long x, long y)
{

	if(y==0)
		return 1;
	if(x==0)
		return 0;
    long res = 1;

    while (y > 0) {

        if (y % 2 == 1)
            res = (res * x);

        y = y >> 1;
        x = (x * x);
    }

    return res;
}
static void print(int A[]) {
	for(int i : A) {
		System.out.print(i+" ");
	}
	System.out.println();
}
static void print(long A[]) {
	for(long i : A) {
		System.out.print(i+" ");
	}
	System.out.println();
}
static long mod(long x) {
	  return ((x%mod + mod)%mod);
}
static String reverse(String s) {
	StringBuffer p=new StringBuffer(s);
	p.reverse();
	return p.toString();
}

     static int i() {
    	 return sc.nextInt();
     }
     static String s() {
    	 return sc.next();
     }
     static long l() {
    	 return sc.nextLong();
     }
     static void sort(int[] A){
        int n = A.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            int tmp = A[i];
            int randomPos = i + rnd.nextInt(n-i);
            A[i] = A[randomPos];
            A[randomPos] = tmp;
        }
        Arrays.sort(A);
     }
     static void sort(long[] A){
	        int n = A.length;
	        Random rnd = new Random();
	        for(int i=0; i<n; ++i){
	            long tmp = A[i];
	            int randomPos = i + rnd.nextInt(n-i);
	            A[i] = A[randomPos];
	            A[randomPos] = tmp;
	        }
	        Arrays.sort(A);
	     }
  static String sort(String s) {
 	 Character ch[]=new Character[s.length()];
 	 for(int i=0;i<s.length();i++) {
 		 ch[i]=s.charAt(i);
 	 }
 	 Arrays.sort(ch);
 	 StringBuffer st=new StringBuffer("");
 	 for(int i=0;i<s.length();i++) {
 		 st.append(ch[i]);
 	 }
 	 return st.toString();
  }
  static HashMap<Integer,Integer> hash(int A[]){
	  HashMap<Integer,Integer> map=new HashMap<Integer, Integer>();
	  for(int i : A) {
		  if(map.containsKey(i)) {
			  map.put(i, map.get(i)+1);
		  }
		  else {
			  map.put(i, 1);
		  }
	  }
	  return map;
  }
  static TreeMap<Integer,Integer> tree(int A[]){
	  TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>();
	  for(int i : A) {
		  if(map.containsKey(i)) {
			  map.put(i, map.get(i)+1);
		  }
		  else {
			  map.put(i, 1);
		  }
	  }
	  return map;
  }
     static boolean prime(int n)
	    {
	        if (n <= 1)
	            return false;
	        if (n <= 3)
	            return true;
	        if (n % 2 == 0 || n % 3 == 0)
	            return false;
	        double sq=Math.sqrt(n);

	        for (int i = 5; i <= sq; i = i + 6)
	            if (n % i == 0 || n % (i + 2) == 0)
	                return false;
	        return true;
	    }
     static boolean prime(long n)
	    {
	        if (n <= 1)
	            return false;
	        if (n <= 3)
	            return true;
	        if (n % 2 == 0 || n % 3 == 0)
	            return false;
	        double sq=Math.sqrt(n);

	        for (int i = 5; i <= sq; i = i + 6)
	            if (n % i == 0 || n % (i + 2) == 0)
	                return false;
	        return true;
	    }
     static int gcd(int a, int b)
     {
         if (a == 0)
             return b;
         return gcd(b % a, a);
     }
     static long gcd(long a, long b)
     {
         if (a == 0)
             return b;
         return gcd(b % a, a);
     }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


import java.util.*;
import java.io.*;
public class DivisibleByTwentyFive {
    public static void main(String[] args) throws IOException {
        Reader in = new Reader();
        PrintWriter out = new PrintWriter(System.out);

        String s = in.next();
        int end = 1;
        for (int i = 0; i < s.length(); i++) {
           end *= 10;
        }
        int res = 0;
        for (int i = 0; i < end; i += 25) {
            if (match(s, i)) {
                res++;
            }
        }
        out.println(res);

        out.close();
    }
    public static boolean match(String s, int n) {
        int x = -1;
        for (int i = s.length() - 1; i >= 0; i--) {
            int d = n % 10;
            if (s.charAt(i) == 'X') {
                if (x >= 0 && x != d) {
                    return false;
                }
                x = d;
            } else if (s.charAt(i) != '_') {
                if (s.charAt(i) - '0' != d) {
                    return false;
                }
            }
            if (s.length() > 1 && i == 0 && d == 0) {
                return false;
            }
            n /= 10;
        }
        return true;
    }
    static class Reader {
        BufferedReader in;
        StringTokenizer st;
        public Reader() {
            in = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        }
        public String nextLine() throws IOException {
            st = new StringTokenizer("");
            return in.readLine();
        }
        public String next() throws IOException {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(in.readLine());
            }
            return st.nextToken();
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }
    public static void sort(int[] arr) {
        List<Integer> list = new ArrayList<>();
        for (int i : arr) {
            list.add(i);
        }
        Collections.sort(list);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = list.get(i);
        }
    }
}


//package school3;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashSet;
import java.util.Scanner;

public class F5 {
	Scanner in;
	PrintWriter out;
//	String INPUT = "100000 10";
	String INPUT = "";

	int[] dec(int n, int m)
	{
		if(n <= m){
			return new int[]{n, 0};
		}else if(n <= 2 * m){
			return new int[]{n - m, n - m};
		}else{
			return new int[]{n - 2 * m - 1, m};
		}
	}

	int enc(int x, int y, int m)
	{
		if(y == 0){
			return x;
		}else if(x == y){
			return x + m;
		}else{
			return x + 2 * m + 1;
		}
	}

	void solve()
	{
		int m = ni();
		int n = ni();
		if(n <= Math.sqrt(Math.sqrt(m))){
			solveH(m, n);
		}else{
			solveB(m, n);
		}
	}

	void solveB(int m, int n){
			// (a, 0), (a, a), (a, m)
			BitSet visitedo = new BitSet();
			BitSet visitedh = new BitSet();
			BitSet q = new BitSet();
			q.set(0);
			boolean iso = true;
			int step = 0;

			outer:
			while(!q.isEmpty()){
//				tr(step, q);
				BitSet nq = new BitSet();
				if(iso){
					visitedh.or(q);
				}else{
					visitedo.or(q);
				}
				for(int cur = q.nextSetBit(0);cur != -1;cur = q.nextSetBit(cur+1)){
					if(!iso && cur == 2 * m)break outer;
					int[] co = dec(cur, m);
					if(iso){
						{
							if(co[1] == 0){
								int inf = co[0] + 1;
								int sup = Math.min(m, co[0] + n);
								if(inf <= sup){
									nq.set(enc(inf, 0, m), enc(sup, 0, m) + 1);
								}
							}
						}
						{
							int inf = Math.max(co[0], co[1]);
							if(co[0] == co[1])inf++;
							int sup = Math.min(m, (n + co[0] + co[1]) / 2);

							if(inf <= sup){
								nq.set(enc(inf, inf, m), enc(sup, sup, m) + 1);
							}
						}
						{
							int inf = co[0];
							if(co[1] == m)inf++;
							int sup = Math.min(m - 1, co[0] + n - m + co[1]);
							if(inf <= sup){
								nq.set(enc(inf, m, m), enc(sup, m, m) + 1);
							}
						}
					}else{
						{
							if(co[1] == m){
								int inf = co[0] - 1;
								int sup = Math.max(0, co[0] - n);
								if(sup <= inf){
									nq.set(enc(sup, m, m), enc(inf, m, m) + 1);
								}
							}
						}
						{
							int inf = Math.min(co[0], co[1]);
							if(co[0] == co[1])inf--;
							int sup = Math.max(0, (-n + co[0] + co[1]) / 2);

							if(sup == 0)sup++;
							if(sup <= inf){
								nq.set(enc(sup, sup, m), enc(inf, inf, m) + 1);
							}
						}
						{
							int inf = co[0];
							if(co[1] == 0)inf--;
							int sup = Math.max(0, co[0] - n + co[1]);
							if(sup <= inf){
								nq.set(enc(sup, 0, m), enc(inf, 0, m) + 1);
							}
						}
					}
				}
				if(iso){
					nq.andNot(visitedo);
				}else{
					nq.andNot(visitedh);
				}
				q = nq;
				step++;
				iso = !iso;
			}
			if(q.isEmpty()){
				out.println(-1);
			}else{
				out.println(step);
			}
	}

	void solveH(int m, int n){

		// (a, 0), (a, a), (a, m)
		HashSet<Integer> visitedo = new HashSet<Integer>();
		HashSet<Integer> visitedh = new HashSet<Integer>();
		HashSet<Integer> q = new HashSet<Integer>();
		q.add(0);
		boolean iso = true;
		int step = 0;

		outer:
		while(!q.isEmpty()){
//			tr(step, q);
			HashSet<Integer> nq = new HashSet<Integer>();
			if(iso){
				visitedh.addAll(q);
			}else{
				visitedo.addAll(q);
			}
			for(int cur : q){
				if(!iso && cur == 2 * m)break outer;
				int[] co = dec(cur, m);
				if(iso){
					{
						if(co[1] == 0){
							int inf = co[0] + 1;
							int sup = Math.min(m, co[0] + n);
							if(inf <= sup){
								for(int i = enc(inf, 0, m);i <= enc(sup, 0, m);i++){
									nq.add(i);
								}
							}
						}
					}
					{
						int inf = Math.max(co[0], co[1]);
						if(co[0] == co[1])inf++;
						int sup = Math.min(m, (n + co[0] + co[1]) / 2);

						if(inf <= sup){
							for(int i = enc(inf, inf, m);i <= enc(sup, sup, m);i++){
								nq.add(i);
							}
						}
					}
					{
						int inf = co[0];
						if(co[1] == m)inf++;
						int sup = Math.min(m - 1, co[0] + n - m + co[1]);
						if(inf <= sup){
							for(int i = enc(inf, m, m);i <= enc(sup, m, m);i++){
								nq.add(i);
							}
						}
					}
				}else{
					{
						if(co[1] == m){
							int inf = co[0] - 1;
							int sup = Math.max(0, co[0] - n);
							if(sup <= inf){
								for(int i = enc(sup, m, m);i <= enc(inf, m, m);i++){
									nq.add(i);
								}
							}
						}
					}
					{
						int inf = Math.min(co[0], co[1]);
						if(co[0] == co[1])inf--;
						int sup = Math.max(0, (-n + co[0] + co[1]) / 2);

						if(sup == 0)sup++;
						if(sup <= inf){
							for(int i = enc(sup, sup, m);i <= enc(inf, inf, m);i++){
								nq.add(i);
							}
						}
					}
					{
						int inf = co[0];
						if(co[1] == 0)inf--;
						int sup = Math.max(0, co[0] - n + co[1]);
						if(sup <= inf){
							for(int i = enc(sup, 0, m);i <= enc(inf, 0, m);i++){
								nq.add(i);
							}
						}
					}
				}
			}
			if(iso){
				nq.removeAll(visitedo);
			}else{
				nq.removeAll(visitedh);
			}
			q = nq;
			step++;
			iso = !iso;
		}
		if(q.isEmpty()){
			out.println(-1);
		}else{
			out.println(step);
		}
	}

	void run() throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

//		long s = System.currentTimeMillis();
		solve();
		out.flush();
//		long g = System.currentTimeMillis();
//		System.out.println(g - s + "ms");
	}

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

	int ni() { return Integer.parseInt(in.next()); }
	void tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }
}


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

public class DTask {

    public static void main(String[] args) throws IOException {
        MyInputReader in = new MyInputReader(System.in);
        long a1 = in.nextInt();
        long b1 = in.nextInt();
        long a2 = in.nextInt();
        long b2 = in.nextInt();
        int l = in.nextInt();
        int r = in.nextInt();
        MutableLong xm = new MutableLong(0);
        MutableLong ym = new MutableLong(1);
        long a = a1;
        long b = -a2;
        long c = b2 - b1;
        long g = gcd(Math.abs(a), Math.abs(b), xm, ym);
        if (c % g != 0) {
            System.out.println("0");
            return;
        }
        if (a1 == 0 && a2 == 0) {
            if (b1 != b2) {
                fail();
            }
            if (b1 == b2 && b1 < l && b2 > r) {
                fail();
            }
            System.out.println(1);
            return;
        }
        long msa = a > 0 ? 1 : -1;
        long msb = b > 0 ? 1 : -1;
        long x = (long) ((c / g) * msa * xm.v);
        long y = (long) ((c / g) * msb * ym.v);
        long minx;
        long maxx;
        if (a1 == 0) {
            minx = Integer.MIN_VALUE;
            maxx = Integer.MAX_VALUE;
        } else {
            minx = (l - b1) / a1;
            maxx = (r - b1) / a1;
        }
        long miny;
        long maxy;
        if (a2 == 0) {
            miny = Integer.MIN_VALUE;
            maxy = Integer.MAX_VALUE;
        } else {
            miny = (l - b2) / a2;
            maxy = (r - b2) / a2;
        }
        minx = Math.max(minx, 0);
        miny = Math.max(miny, 0);
        long ad = b / g;
        long bd = a / g;
        Pair p1 = bounds(x, ad, minx, maxx);
        Pair p2 = bounds(y, -bd, miny, maxy);
        long m1 = Math.max(p1.min, p2.min);
        long m2 = Math.min(p2.max, p1.max);
        if (m1 > m2) {
            fail();
        }
        long vars = Math.abs(m2 - m1) + 1;

        long pos = m2;
        long l1 = x + pos * (b / g);
        long ans = a1 * l1 + b1;

        long posy = m1;
        long k1 = y - posy * (a / g);
        long ansy = a2 * k1 + b2;

        if (ans < l || ans > r) {
            vars -= 1;
        }
        if (ansy < l || ansy > r) {
            vars -= 1;
        }
        /*System.out.println(ans);
        System.out.println(ansy);*/
        System.out.println(Math.max(vars, 0));
    }

    static Pair bounds(long init, long step, long min, long max) {
        long src = step;
        long lo = -1;
        long hi = -1;
        step = Math.abs(step);
        if (init == min) {
            lo = min;
        } else if (init < min) {
            long mult = (min - init) / step;
            lo = init + mult * step;
            if (lo < min) {
                lo += step;
            }
        } else {
            long mult = (init - min) / step;
            lo = init - mult * step;
            if (lo < min) {
                lo += step;
            }
        }
        if (lo > max) {
            fail();
        }
        lo = (lo - init) / src;
        if (init == max) {
            hi = init;
        } else if (init > max) {
            long mult = (init - max) / step;
            hi = init - mult * step;
            if (hi > max) {
                hi -= step;
            }
        } else {
            long mult = (max - init) / step;
            hi = init + mult * step;
            if (hi > max) {
                hi -= step;
            }
        }
        if (hi < min) {
            fail();
        }
        hi = (hi - init) / src;
        if (hi < lo) {
            long tmp = hi;
            hi = lo;
            lo = tmp;
        }
        return new Pair(lo, hi);
    }

    static void fail() {
        System.out.println("0");
        System.exit(0);
    }

    static long gcd(long a, long b, MutableLong x, MutableLong y) {
        if (a == 0) {
            x.v = 0;
            y.v = 1;
            return b;
        }
        long g = gcd(b % a, a, x, y);
        long x1 = x.v;
        long y1 = y.v;
        x.v = y1 - (b / a) * x1;
        y.v = x1;
        return g;
    }

    static class Pair {

        long min;
        long max;

        public Pair(long min, long max) {
            this.min = min;
            this.max = max;
        }
    }

    static class MutableLong {

        long v;

        public MutableLong(long v) {
            this.v = v;
        }

    }

    static class MyInputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public MyInputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

}


import java.util.Scanner;

public class cf877a {

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

		String n = sc.nextLine();

		String[] arr = {"Danil","Olya","Slava","Ann","Nikita"};

		int have= 0;

		for (String s : arr) {
			int prev =0;
			while (n.indexOf(s, prev) != -1) {
				have++;
				prev  = n.indexOf(s, prev)+1;
				if (prev == -1) {
					break;
				}
			}
		}

		System.out.println(have == 1 ? "YES" : "NO");
	}

}


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

public class Divisibilityby25 {

	void solve(Scanner in, PrintWriter out) {
		String s = in.next();
		int l = s.length();
		int min = Integer.MAX_VALUE;

		for (int i = 0; i < l; i++) {

			for (int j = 0; j < l; j++) {
				int m = 0;
				char[] a = s.toCharArray();

				if (i == j)
					continue;

				for (int k = i; k < l - 1; k++) {
					char c = a[k];
					a[k] = a[k + 1];
					a[k + 1] = c;
					m++;
				}

				for (int k = j - ((j > i) ? 1 : 0); k < l - 2; k++) {
					char c = a[k];
					a[k] = a[k + 1];
					a[k + 1] = c;
					m++;
				}

				int pos = -1;

				for (int k = 0; k < l - 2; k++) {

					if (a[k] != '0') {
						pos = k;
						break;
					}
				}

				for (int k = pos; k > 0; k--) {

					char c = a[k - 1];
					a[k - 1] = a[k];
					a[k] = c;
					m++;
				}
				long n = Long.parseLong(new String(a));
				if (n % 25 == 0) {
					min = Math.min(m, min);

				}

			}

		}

		if (min == Integer.MAX_VALUE)
			out.println(-1);
		else
			out.println(min);

	}

	void run() {
		try (Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out);) {
			solve(in, out);
		}
	}

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


import java.util.*;
import java.io.*;
import java.math.*;
public class Main{

	//static int p=1000000007;

	static long pr = 998244353;

	static BigInteger p =  new BigInteger(998244353+"");

	static void err() {
		System.out.println(-1);
	}

	public static void main (String args[])throws IOException{
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);

		int t = 1;
		//t = sc.nextInt();

		while(t-->0) {

			long n=sc.nextInt(), m=sc.nextInt(), l=sc.nextInt(), r=sc.nextInt(), k=r-l, even=k/2+1, odd=(k+1)/2;

			if((n*m)%2==1) {
				out.print(new BigInteger(k+1+"").modPow(new BigInteger(n*m+""), p));
			}else {

				BigInteger temp1 = new BigInteger(even+odd+"").modPow(new BigInteger(n*m+""), p);
				BigInteger temp2 = new BigInteger(even-odd+"").modPow(new BigInteger(n*m+""), p);

				out.println(((Long.parseLong(temp1.toString())+Long.parseLong(temp2.toString()))*(pr+1)/2)%pr);
			}

		}
		out.flush();
	}

	public static String reverseString(String str){
	    StringBuilder sb=new StringBuilder(str);
	    sb.reverse();
	    return sb.toString();
	}

	static boolean isPalindrome(String str)
    {
        int i = 0, j = str.length() - 1;

        while (i < j) {

            if (str.charAt(i) != str.charAt(j))
                return false;

            i++;
            j--;
        }
        return true;
    }

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

	public static int abs(int x) {return ((x > 0) ? x : -x);}
	public static long abs(long x) {return ((x > 0) ? x : -x);}

	public static int max(int a, int b) {return Math.max(a, b);}
	public static long max(long a, long b) {return Math.max(a, b);}

	public static int min(int a, int b) {return Math.min(a, b);}
	public static long min(long a, long b) {return Math.min(a, b);}

	 static int gcd(int a, int b)
	    {
	        if (a == 0)
	            return b;
	        return gcd(b % a, a);
	    }

    static int modInverse(int a, int m)
    {
        int g = gcd(a, m);
        if (g != 1)
            return -1;
        else
        	return power(a, m - 2, m);

    }

    // To compute x^y under modulo m
    static int power(int x, int y, int m)
    {
        if (y == 0)
            return 1;

        int p = power(x, y / 2, m) % m;
        p = (p * p) % m;

        if (y % 2 == 0)
            return p;
        else
            return (x * p) % m;
    }

    static int[] primeGenerator(int num) {
    	int length=0, arr[]=new int[num], a=num, factor=1;
    	if(num%2==0) {
    		while(num%2==0) {
    			num/=2;
    			factor*=2;
    		}
    		arr[length++]=factor;
    	}
    	for(int i=3; i*i<=a; i++) {
    		factor=1;
    		if(num%i==0) {
        		while(num%i==0) {
        			num/=i;
        			factor*=i;
        		}
        		arr[length++]=factor;
    		}
    	}
    	if(num>1)
    		arr[length++]=num;
    	return Arrays.copyOfRange(arr, 0, length);
    }

    static boolean isPrime(int n)
    {
        // Corner cases
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

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

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

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

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

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

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

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}
}

class Pair{
	int x;
	int y;
	Pair(int a, int b){
		x=a;
		y=b;
	}

	void print() {
		System.out.println(this.x+" "+this.y);
	}
}


import java.io.*;
import java.util.*;
public class Main{
	static int mod=998244353;
	static long fastpow(long n,long ti) {
		 if (ti == 0)
		        return 1l;
		if(ti%2==0) {
			long y=fastpow(n, ti/2);
			long k=y*y;
			k%=mod;
			return k;
		}
		else {
			long y=fastpow(n, ti/2);
			long k=((n*y)%mod)*y;
			k%=mod;
			return k;
		}
	}
	static long modInv(long x) {
		return fastpow(x, mod-2);
	}
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		long n=sc.nextInt(),m=sc.nextInt(),l=sc.nextInt(),r=sc.nextInt();
		if(l==r) {
			pw.println(1);
			pw.flush();
			return;
		}

		long odds=((r+1)/2)-(l/2),evens=(r/2)-((l-1)/2);

		long ans;

		if((n*m)%2==1) {
			ans=fastpow(odds+evens, (n*m));
		}
		else {
			ans=(fastpow(odds+evens, (n*m))+fastpow(odds-evens, (n*m)))%mod;
			ans=(ans*modInv(2))%mod;
		}
		pw.println(ans);

		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		static void shuffle(int[]in) {
			for(int i=0;i<in.length;i++) {
				int idx=(int)(Math.random()*in.length);
				int tmp=in[i];
				in[i]=in[idx];
				in[idx]=tmp;
			}
		}
		static void shuffle(long[]in) {
			for(int i=0;i<in.length;i++) {
				int idx=(int)(Math.random()*in.length);
				long tmp=in[i];
				in[i]=in[idx];
				in[idx]=tmp;
			}
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

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

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void addX(int[]in,int x) {
		for(int i=0;i<in.length;i++)in[i]+=x;
	}
	static void addX(long[]in,int x) {
		for(int i=0;i<in.length;i++)in[i]+=x;
	}
}


import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.Flushable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.InputMismatchException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	static class TaskAdapter implements Runnable {
		@Override
		public void run() {
			long startTime = System.currentTimeMillis();
			InputStream inputStream = System.in;
			OutputStream outputStream = System.out;
			FastReader in = new FastReader(inputStream);
			Output out = new Output(outputStream);
			EHeightAllTheSame solver = new EHeightAllTheSame();
			solver.solve(1, in, out);
			out.close();
			System.err.println(System.currentTimeMillis()-startTime+"ms");
		}

	}

	public static void main(String[] args) throws Exception {
		Thread thread = new Thread(null, new TaskAdapter(), "", 1<<28);
		thread.start();
		thread.join();
	}

	static class EHeightAllTheSame {
		private final int mod = 998244353;

		public EHeightAllTheSame() {
		}

		public void solve(int kase, InputReader in, Output pw) {
			long nn = in.nextInt(), nm = in.nextInt(), l = in.nextInt(), r = in.nextInt();
			long n = nn*nm;
			if((n&1)==1) {
				pw.println(Utilities.math.pow(r-l+1, n, mod));
			}else {
				long x = Utilities.math.pow(r-l+1, n, mod);
				if(((r-l+1)&1)==1) {
					x++;
				}
				pw.println((x*499122177L)%mod);
			}
		}

	}

	static interface InputReader {
		int nextInt();

	}

	static class Output implements Closeable, Flushable {
		public StringBuilder sb;
		public OutputStream os;
		public int BUFFER_SIZE;
		public boolean autoFlush;
		public String lineSeparator;

		public Output(OutputStream os) {
			this(os, 1<<16);
		}

		public Output(OutputStream os, int bs) {
			BUFFER_SIZE = bs;
			sb = new StringBuilder(BUFFER_SIZE);
			this.os = new BufferedOutputStream(os, 1<<17);
			autoFlush = false;
			lineSeparator = System.lineSeparator();
		}

		public void println(long l) {
			println(String.valueOf(l));
		}

		public void println(String s) {
			sb.append(s);
			println();
			if(autoFlush) {
				flush();
			}else if(sb.length()>BUFFER_SIZE >> 1) {
				flushToBuffer();
			}
		}

		public void println() {
			sb.append(lineSeparator);
		}

		private void flushToBuffer() {
			try {
				os.write(sb.toString().getBytes());
			}catch(IOException e) {
				e.printStackTrace();
			}
			sb = new StringBuilder(BUFFER_SIZE);
		}

		public void flush() {
			try {
				flushToBuffer();
				os.flush();
			}catch(IOException e) {
				e.printStackTrace();
			}
		}

		public void close() {
			flush();
			try {
				os.close();
			}catch(IOException e) {
				e.printStackTrace();
			}
		}

	}

	static class FastReader implements InputReader {
		final private int BUFFER_SIZE = 1<<16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer;
		private int bytesRead;

		public FastReader(InputStream is) {
			din = new DataInputStream(is);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

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

		private boolean isDigit(byte b) {
			return b>='0'&&b<='9';
		}

		private byte skipToDigit() {
			byte ret;
			while(!isDigit(ret = read())&&ret!='-') ;
			return ret;
		}

		private void fillBuffer() {
			try {
				bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			}catch(IOException e) {
				e.printStackTrace();
				throw new InputMismatchException();
			}
			if(bytesRead==-1) {
				buffer[0] = -1;
			}
		}

		private byte read() {
			if(bytesRead==-1) {
				throw new InputMismatchException();
			}else if(bufferPointer==bytesRead) {
				fillBuffer();
			}
			return buffer[bufferPointer++];
		}

	}

	static class Utilities {
		public static class math {
			public static long pow(long base, long exp, long mod) {
				long ans = 1, cur = base;
				while(exp>0) {
					if((exp&1)>0) {
						ans = (ans*cur)%mod;
					}
					cur = (cur*cur)%mod;
					exp >>= 1;
				}
				return ans;
			}

		}

	}
}


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

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

    static class EHeightAllTheSame {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            long n = s.nextLong(), m = s.nextLong(), k = n * m;
            long l = s.nextLong(), r = s.nextLong(), len = r - l + 1;
            long mod = 998244353;

            if (k % 2 == 1) {
                out.println(EHeightAllTheSame.Maths.power(len, n * m, mod));
                return;
            }

            long ans = (EHeightAllTheSame.Maths.power(len, k, mod) + EHeightAllTheSame.Maths.power(len % 2, k, mod)) * EHeightAllTheSame.Maths.power(2, mod - 2, mod) % mod;
            out.println(ans);
        }

        private static class Maths {
            static long power(long x, long y, long p) {
                long res = 1;
                x = x % p;

                while (y > 0) {
                    if ((y & 1) == 1)
                        res = (res * x) % p;
                    y = y >> 1;
                    x = (x * x) % p;
                }
                return res;
            }

        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(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++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long 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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Map.Entry;

import java.util.Random;
import java.util.TreeSet;

public final class CF_630_D2_E
{

	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputFlush(Object o){try {out.write(""+ o+"\n");out.flush();} catch (Exception e) {}}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}

	// Global vars
	static BufferedWriter out;
	static InputReader reader;

	static void test() {
		log("testing");

		Random r=new Random();
		int NTESTS=100000;
		int NMAX=100;
		for (int t=0;t<NTESTS;t++) {

		}

		log("done");

	}

	static int st;

	static class Composite implements Comparable<Composite>{

		long v;
		int idx;
		long x;
		long d;

		public int compareTo(Composite X) {
			if (v<X.v)
				return -1;
			if (v>X.v)
				return 1;
			return idx-X.idx;
		}

		public Composite(long v, int idx, long x, long d) {
			this.v = v;
			this.idx = idx;
			this.x = x;
			this.d = d;
		}

	}

	static long powerMod(long b,long e,long m){
		long x=1;
		while (e>0) {
			if (e%2==1)
				x=(b*x)%m;
			b=(b*b)%m;
			e=e/2;
		}
		return x;
	}

	static void process() throws Exception {

		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader = new InputReader(System.in);

		long n=reader.readInt();
		long m=reader.readInt();
		int L=reader.readInt();
		int R=reader.readInt();

		long mod=998244353;
		long inv2=powerMod(2,mod-2,mod);

		long ans=0;
		long nm=n*m;

		// solution
		// case 1: if at least one set is even, we can achieve
		// case 2! problem is if both set are odd size. In this case it does not work...
		// if n*m is odd, we are always case 1
		// if n*m is even, depends..

		long diff=R-L+1;
		long p1=diff/2;
		long p2=diff-p1;
		if (nm%2==1) {
			// whatever the distribution it will work
			ans=powerMod(diff,nm,mod);

		} else {
			// A+B = nm
			// A even, B good
			// A in 2,4...nm,

			long pp1=diff;
			long pp2=Math.abs(p1-p2);

			long opt1=powerMod(pp1,nm,mod);
			long opt2=powerMod(pp2,nm,mod);
			long opt=opt1+opt2;
			opt%=mod;
			opt*=inv2;
			opt%=mod;
			ans=opt;

		}
		output(ans);

		try {
			out.close();
		} catch (Exception Ex) {
		}

	}

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

	}

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

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

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final String readString(int L) throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder(L);
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

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

}
/*

5
1 4 5 2 3

 */


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

/**
 * Created by Katushka on 11.03.2020.
 */
public class B {
    static int[] readArray(int size, InputReader in) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    final static long MOD = 998244353;

    private static long fastPow(long x, long y) {
        if (x == 1) {
            return 1;
        }
        if (y == 0) {
            return 1;
        }
        long p = fastPow(x, y / 2) % MOD;
        p = p * p % MOD;
        if (y % 2 == 1) {
            p = p * x % MOD;
        }
        return p;
    }

    private static long obrat2() {
        return fastPow(2, MOD - 2);
    }

    public static void main(String[] args) throws FileNotFoundException {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        long n = in.nextInt();
        long m = in.nextInt();
        long l = in.nextInt();
        long r = in.nextInt();
        if (n % 2 != 0 && m % 2 != 0) {
            out.println(fastPow((r - l + 1), n * m));
        } else {
            long res1 = fastPow((r - l + 1), n * m - 1);
            long res;
            if ((r - l + 1) % 2 == 0) {
                res = res1 * ((r - l + 1) / 2) % MOD;
            } else {
                res = (res1 * ((r - l + 2) / 2) % MOD + MOD - (res1 + MOD - 1) % MOD * obrat2() % MOD) % MOD;
            }
            out.println(res);
        }

        out.close();
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}


import java.util.Scanner;

public class ProblemE {

	public static long M = 998244353;

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

		Scanner s = new Scanner(System.in);
		long m = s.nextLong();
		long n = s.nextLong();

		long l = s.nextLong();
		long r = s.nextLong();

		long T = m * n;
		long num = r - l + 1;

		long a = exp(num, T);
		//System.out.println(a);
		if(T%2 == 1) {
			System.out.println(a);
		}

		else {
			if(num % 2 == 0)
				System.out.println((a * exp(2, M-2))%M);
			else
				System.out.println(((a + 1)%M * exp(2, M-2))%M);

		}

	}

	public static long exp(long a, long b) {
		long m = M;
		if(b == 0)
			return 1;
		else if(b == 1)
			return a;
		else if(a == 1)
			return 1;
		else if(b%2 == 0)
			return exp((a*a)%m, b/2);
		else
			return (exp((a*a)%m, b/2) * a)%m;
	}

}


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

public class e{

	static long mod = 998244353;

	public static void main(String[] args){
		JS scan = new JS();
		long n = scan.nextLong();
		long m = scan.nextLong();
		long L = scan.nextLong();
		long R = scan.nextLong();
		long h = R-L;

		long e = 0;
		long o = 0;
		if(h % 2 == 1){
			long d = (h+1)/2;
			e = d;
			o = d;
		}
		else{
			long d = h/2;
			e = d;
			o = d;
			if(L % 2 == 1) o++;
			else e++;
		}

		long[][] mat = {{e, o},{o, e}};
		long[][] pphard = pow(mat, m*n);
		long ans = pphard[0][0];
		if((n*m)%2==1) ans += pphard[0][1];
		System.out.println(ans%mod);
	}

	static long[][] pow(long[][] a, long pow){
		if(pow == 0) return iden(a.length);
		if(pow % 2 == 1){
			long[][] res = pow(a, pow-1);
			return mult(res, a);
		}
		long[][] res = pow(a, pow/2);
		return mult(res, res);
	}

	static long[][] iden(int n){
		long[][] res = new long[n][n];
		for(int i = 0; i < n; i++) res[i][i] = 1;
		return res;
	}

	static long[][] mult(long[][] a, long[][] b){
		long[][] res = new long[a.length][b[0].length];
		for(int i = 0; i < a.length; i++){
			for(int j = 0; j < b[0].length; j++){
				for(int k = 0; k < a[0].length; k++){
					res[i][j] += (a[i][k]%mod)*(b[k][j]%mod);
					res[i][j] %= mod;
				}
			}
		}
		return res;
	}

	static class JS{
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}

		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}

}


import java.util.Scanner;
import java.math.BigInteger;
import java.util.Vector;

public class Main {
	public static void main(String[] args) {
		BigInteger MOD = BigInteger.valueOf(998244353);

		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long m = sc.nextLong();
		long L = sc.nextLong();
		long R = sc.nextLong();

		long k = R - L + 1;

		if (n * m % 2 == 1) {
			BigInteger exp = BigInteger.valueOf(n * m);
			BigInteger base = BigInteger.valueOf(k);
			System.out.println(base.modPow(exp, MOD));
		} else {
			long e, o;
			BigInteger E, O, exp;
			e = R / 2 - (L - 1) / 2;
			o = k - e;
			E = BigInteger.valueOf(e);
			O = BigInteger.valueOf(o);
			exp = BigInteger.valueOf(n * m);
			BigInteger a = E.add(O).modPow(exp, MOD);
			BigInteger b = E.subtract(O).modPow(exp, MOD);
			System.out.println(a.add(b).multiply(MOD.add(BigInteger.ONE)).divide(BigInteger.valueOf(2)).mod(MOD));

		}

	}
}


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

public class HeightAllTheSame {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(in.readLine());
		long N = Long.parseLong(st.nextToken());
		long M = Long.parseLong(st.nextToken());
		long L = Long.parseLong(st.nextToken());
		long R = Long.parseLong(st.nextToken());
		if((N * M) % 2 == 1) {
			out.println(pow(R - L + 1, N * M));
		} else if((R - L + 1) % 2 == 0) {
			out.println((pow(R - L + 1, N * M) * (long)(998244353 + 1) / 2) % 998244353);
		} else {
			out.println(((pow(R - L + 1, N * M) + 1) * (long)(998244353 + 1) / 2) % 998244353);
		}
		in.close();
		out.close();
	}
	static long pow(long a, long b) {
		long res = 1;
		while(b > 0) {
			if(b % 2 == 1) {
				res = (res * a) % 998244353;
				b--;
			}
			a = (a * a) % 998244353;
			b /= 2;
		}
		return res;
	}
}