#include<stdio.h> #include<string.h> #include<algorithm> #include<queue> #define MAXN 105 using namespace std; int v[MAXN][MAXN][MAXN]; int a,b,c,flag; struct node { int x,y,z; int step; }; bool judge(node k) { if( (k.x == k.y && k.z == 0) || (k.x == k.z && k.y == 0) || (k.z == k.y && k.x == 0) ) return 1; return 0; } void bfs() { queue <node> q; node s,temp; s.x = a; s.y = 0; s.z = 0; s.step = 0; v[s.x][s.y][s.z] = 1;//標記該狀態已存在過 q.push(s); while(!q.empty()) { temp = q.front(); q.pop(); int num; if(judge(temp)) { printf("%d\n",temp.step); flag = 1; return ; } if(temp.x > 0) { if(temp.y < b)//x-->y { num = b - temp.y;//表示b中還差多少裝滿 s.z = temp.z; s.step = temp.step + 1; if(temp.x > num) { s.x = temp.x - num; s.y = b; } else { s.x = 0; s.y = temp.x + temp.y; } if(!v[s.x][s.y][s.z]) { v[s.x][s.y][s.z] = 1; q.push(s); } } if(temp.z < c)//x-->z { num = c - temp.z; s.y = temp.y; s.step = temp.step + 1; if(temp.x > num) { s.x = temp.x - num; s.z = c; } else { s.x = 0; s.z = temp.x + temp.z; } if(!v[s.x][s.y][s.z]) { v[s.x][s.y][s.z] = 1; q.push(s); } } } if(temp.y > 0) { if(temp.x < a)//y-->x { num = a - temp.x; s.z = temp.z; s.step = temp.step + 1; if(temp.y > num) { s.y = temp.y - num; s.x = a; } else { s.y = 0; s.x = temp.y + temp.x; } if(!v[s.x][s.y][s.z]) { v[s.x][s.y][s.z] = 1; q.push(s); } } if(temp.z < c)//y-->z { num = c - temp.z; s.x = temp.x; s.step = temp.step + 1; if(temp.y > num) { s.y = temp.y - num; s.z = c; } else { s.y = 0; s.z = temp.y + temp.z; } if(!v[s.x][s.y][s.z]) { v[s.x][s.y][s.z] = 1; q.push(s); } } } if(temp.z > 0) { if(temp.x < a)//z-->x { num = a - temp.x; s.y = temp.y; s.step = temp.step + 1; if(temp.z > num) { s.z = temp.z - num; s.x = a; } else { s.z = 0; s.x = temp.x + temp.z; } if(!v[s.x][s.y][s.z]) { v[s.x][s.y][s.z] = 1; q.push(s); } } if(temp.y < b)//z-->y { num = b - temp.y; s.x = temp.x; s.step = temp.step + 1; if(temp.z > num) { s.z = temp.z - num; s.y = b; } else { s.z = 0; s.y = temp.y + temp.z; } if(!v[s.x][s.y][s.z]) { v[s.x][s.y][s.z] = 1; q.push(s); } } } } } int main() { while(scanf("%d%d%d",&a,&b,&c) && (a + b + c)) { memset(v,0,sizeof(v)); flag = 0; bfs(); if(!flag) printf("NO\n"); } return 0; }