0.SS. Container 2D


Submit solution

Points: 3 (partial)
Time limit: 60.0s
Memory limit: 125M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, C, C++, C11, CLANG, CLANGX, Classical, COBOL, Coffee, CSC, D lang, DART, F95, FORTH, Fortrn, GAS32, GO, Haskell, Itercal, Java, kotlin, LEAN, LISP, LUA, MONOVB, Nasm, OCAML, Pascal, Perl, php, PIKE, prolog, Pypy, Python, Ruby 2, RUST, Scala, SCM, SED, SWIFT, TCL, TUR, V8JS, VB, ZIG

There is a container having horizontal size W and vertical size H. There are N rectangle items 1, 2, ..., N in which item i has horizontal size wi and vertical size hi. Find the way to place these N items into the container such that

  • The sides of items are packed in parallel with the sides of the container
  • The items cannot rotated
  • No two items overlap.

Input

The input consists of following lines

  • Line 1: contains two integer H and W \((1 \le H;W \le 30)\)
  • Line 2: contains N \((1 \le N \le 12)\)
  • Line i + 2 (i = 1; ... ;N): contains two integers hi and wi

Output

The output contains a unique number 0 (if we cannot place items) or 1 (if we can place items)

Example

Input

6 4 3 2 3 6 1 4 3

Output

1


Comments

There are no comments at the moment.