Chocolate in its many forms is enjoyed by millions of people around the world every day. It is a truly universal candy available in virtually every country around the world.
You find that the only thing better than eating chocolate is to share it with friends. Unfortunately your friends are very picky and have different appetites: some would like more and others less of the chocolate that you offer them. You have found it increasingly difficult to determine whether their demands can be met. It is time to writte a program that solves the problem once and for all!
Your chocolate comes as a rectangular bar. The bar consists of same-sized rectangular pieces. To share the chocolate you may break one bar into two pieces along a division between rows or columns of the bar. You or the may then repeatedly break the resulting pieces in the same manner. Each of your friends insists on a getting a single rectangular portion of the chocolate that has a specified number of pieces. You are a little bit insistent as well: you will break up your bar only if all of it can be distributed to your friends, with none left over.
For exampla, Figure 9 shows one way that a chocolate bar consisting of 3 x 4 pieces can be split into 4 parts that contain 6, 3, 2, and 1 pieces respectively, by breanking it 3 times (This corresponds to the first sample input.)

Input
The input consists of multiple test cases each describing a chocolate bar to share. Each description starts with a line containing a single integer n (1



The input is terminated by a line containing the integer zero.
Output
For each test case, first display its case number. Then display whether it is possible to break the chocolate in the desired way: display ``Yes" if it is possible, and ``No" otherwise. Follow the format of the sample output.
Sample Input
4 3 4 6 3 2 1 2 2 3 1 5 0
Sample Output
Case 1: Yes Case 2: No
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
const int MAXN=20;
const int e2[]={0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288};
int n,x,y,t;
int a[MAXN];
int f[110][66000];
int g[66000];
int list[66000];
int next[66000];
inline int min(int a,int b)
{
return a<b?a:b;
}
void init()
{
t=0;
scanf("%d %d",&x,&y);
for(int i=1;i<=n;++i)
{
scanf("%d",a+i);
t+=a[i];
}
}
bool get(int x,int area,int s)
{
if(f[x][s]!=-1)
return f[x][s];
int i,j,y=area/x;
for(i=1;i<=(x>>1);++i)
{
for(j=list[i*y];j!=-1;j=next[j])
if((j|s)==s)
{
if(get(min(i,y),i*y,j)&&get(min(x-i,y),area-i*y,s-j))
return f[x][s]=1;
}
}
for(i=1;i<=(y>>1);++i)
{
for(j=list[i*x];j!=-1;j=next[j])
if((j|s)==s)
{
if(get(min(i,x),i*x,j)&&get(min(y-i,x),area-i*x,s-j))
return f[x][s]=1;
}
}
return f[x][s]=0;
}
void solve()
{
if(t!=x*y)
{
printf("NO\n");
return;
}
memset(g,0,sizeof(g));
int i,j,k;
for(i=0;i<e2[n+1];++i)
for(j=1;j<=n;++j)
if((i&e2[j])>0)
g[i]+=a[j];
memset(list,0xff,sizeof(list));
for(i=0;i<e2[n+1];++i)
{
next[i]=list[g[i]];
list[g[i]]=i;
}
memset(f,0xff,sizeof(f));
f[0][0]=1;
for(i=1;i<=n;++i)
{
k=(int)(sqrt(double(a[i])));
for(j=1;j<=k;++j)
if(a[i]%j==0)
f[j][e2[i]]=1;
}
if(get(min(x,y),x*y,e2[n+1]-1))
printf("Yes\n");
else
printf("No\n");
}
int main()
{
int CASE=0;
while((scanf("%d",&n)!=EOF)&&n)
{
init();
printf("Case %d: ",++CASE);
solve();
}
return 0;
}