import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.bitmanip;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n, ma, mb; readV(n, ma, mb);
  int[] a, b, c; readC(n, a, b, c);

  auto n1 = n/2, n2 = n-n1, inf = 10^^9;

  auto t = new int[][](n2*10+1, n2*10+1);
  foreach (ref ti; t) ti[] = inf;

  foreach (i; 0..1<<n2) {
    auto as = a[n1..$].indexed(i.bitsSet).sum;
    auto bs = b[n1..$].indexed(i.bitsSet).sum;
    auto cs = c[n1..$].indexed(i.bitsSet).sum;
    t[as][bs] = min(t[as][bs], cs);
  }

  auto ans = inf;
  foreach (i; 0..1<<n1) {
    auto as = a.indexed(i.bitsSet).sum;
    auto bs = b.indexed(i.bitsSet).sum;
    auto cs = c.indexed(i.bitsSet).sum;

    foreach (a2; 0..n2*10+1) {
      if (as+a2 == 0 || (as+a2)%mb != 0) continue;
      auto b2 = (as+a2)/mb*ma-bs;
      if (b2 < 0 || b2 > n2*10) continue;
      ans = min(ans, cs+t[a2][b2]);
    }
  }

  writeln(ans >= inf ? -1 : ans);
}
