static int pattern ( int x , int y ) {
  if ( dp [ y ] [ x ] > 0 ) return dp [ y ] [ x ] ;
  int a = src [ y ] [ x ] ;
  int ret = 1 ;
  if ( x > 0 && a > src [ y ] [ x - 1 ] ) ret = ( ret + pattern ( x - 1 , y ) ) % MOD ;
  if ( y > 0 && a > src [ y - 1 ] [ x ] ) ret = ( ret + pattern ( x , y - 1 ) ) % MOD ;
  if ( x < W - 1 && a > src [ y ] [ x + 1 ] ) ret = ( ret + pattern ( x + 1 , y ) ) % MOD ;
  if ( y < H - 1 && a > src [ y + 1 ] [ x ] ) ret = ( ret + pattern ( x , y + 1 ) ) % MOD ;
  return dp [ y ] [ x ] = ret ;
}

static int pattern ( int x , int y ) { if ( dp [ y ] [ x ] > 0 ) return dp [ y ] [ x ] ; int a = src [ y ] [ x ] ; int ret = 1 ; if ( x > 0 && a > src [ y ] [ x - 1 ] ) ret = ( ret + pattern ( x - 1 , y ) ) % MOD ; if ( y > 0 && a > src [ y - 1 ] [ x ] ) ret = ( ret + pattern ( x , y - 1 ) ) % MOD ; if ( x < W - 1 && a > src [ y ] [ x + 1 ] ) ret = ( ret + pattern ( x + 1 , y ) ) % MOD ; if ( y < H - 1 && a > src [ y + 1 ] [ x ] ) ret = ( ret + pattern ( x , y + 1 ) ) % MOD ; return dp [ y ] [ x ] = ret ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (decimal_integer_literal))) consequence: (return_statement (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))))) right: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) index: (identifier))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))))) right: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))))) right: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) index: (identifier))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))))) right: (identifier))))) (return_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (identifier)))))