Problem:
Greedy, Greedy.
Once upon a time, there lived a dumb king. He always messes things up based on his whimsical ideas.
This time, he decided to renew the kingdom’s coin system. Currently the kingdom has three types of
coins of values 1, 5, and 25. He is thinking of replacing these with another set of coins.
Yesterday, he suggested a coin set of values 7, 77, and 777. “They look so fortunate, don’t they?” said
he. But obviously you can’t pay, for example, 10, using this coin set. Thus his suggestion was rejected.
Today, he suggested a coin set of values 1, 8, 27, and 64. “They are all cubic numbers. How beautiful!”
But another problem arises: using this coin set, you have to be quite careful in order to make changes
efficiently. Suppose you are to make changes for a value of 40. If you use a greedy algorithm, i.e.
continuously take the coin with the largest value until you reach an end, you will end up with seven
coins: one coin of value 27, one coin of value 8, and five coins of value 1. However, you can make
changes for 40 using five coins of value 8, which is fewer. This kind of inefficiency is undesirable, and
thus his suggestion was rejected again.
Tomorrow, he would probably make another suggestion. It’s quite a waste of time dealing with him, so
let’s write a program that automatically examines whether the above two conditions are satisfied.
Input
The input consists of multiple test cases. Each test case is given in a line with the format
n
c
1
c
2
. . .
c
n
where
n
is the number of kinds of coins in the suggestion of the king, and each
c
i
is the coin value.
You may assume 1 ≤
n
≤ 50 and 0 <
c
1
<
c
2
< . . . <
c
n
< 1000.
The input is terminated by a single zero.
Output
For each test case, print the answer in a line. The answer should begin with “Case #
i
: ”, where
i
is the
test case number starting from 1, followed by
“Cannot pay some amount” if some (positive integer) amount of money cannot be paid using
  the given coin set,
“Cannot use greedy algorithm” if any amount can be paid, though not necessarily with the
  least possible number of coins using the greedy algorithm,
“OK” otherwise.
Sample Input
3 1 5 25
3 7 77 777
4 1 8 27 64
0
Output for the Sample Input
Case #1: OK
Case #2: Cannot pay some amount
Case #3: Cannot use greedy algorithm

Submitted solutions:

code_snippet: #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>

using namespace std;

typedef long long LL;

const int N = 55, M = 100010, INF = 0x3f3f3f3f;

int w[N];
int f[M];

int main()
{
    int n, t = 1;
    while(scanf("%d", &n), n)
    {
        bool flag = true;
        for(int i = 1; i <= n; i ++)
        {
            scanf("%d", &w[i]);
            if(i > 1 && w[i] % w[i - 1])  flag = false;
        }
        
        if(w[1] != 1)  printf("Case #%d: Cannot pay some amount\n", t ++);
        else if(flag)  printf("Case #%d: OK\n", t ++);
        else{
            int m = w[n] * 2;
            
            f[0] = 0;
            for(int i = 1; i <= m; i ++)  f[i] = INF;
            
            for(int i = 1; i <= n; i ++)
                for(int j = w[i]; j <= m; j ++)
                    f[j] = min(f[j], f[j - w[i]] + 1);
            
            flag = true;
            for(int i = 1; i <= m; i ++)
            {
                int x = i, res = 0;
                for(int j = n; j && x; j --)
                {
                    res += x / w[j];
                    x %= w[j];
                }
                if(res > f[i])
                {
                    flag = false;
                    break;
                }
            }
            if(flag)  printf("Case #%d: OK\n", t ++);
            else  printf("Case #%d: Cannot use greedy algorithm\n", t ++);
        }
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3308
final_rank: 10

code_snippet: #include<bits/stdc++.h>

using namespace std;

int solve(int idx, int val, vector<vector<int>> &dp, vector<int> &coin) {
    if (val == 0)return 0;
    if (idx <= -1)return 1e5;
    int &ans = dp[val][idx];
    if (~ans)return ans;
    ans = 1e5;
    int take = 1e5 + 1, leave = solve(idx - 1, val, dp, coin);
    if (val - coin[idx] >= 0) {
        take = 1 + solve(idx, val - coin[idx], dp, coin);
    }
    ans = min(take, leave);
    return ans;
}

void acc(int n) {
    vector<int> coin(n);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> coin[i];
        sum += coin[i];
    }
    vector<vector<int>> dp(sum + 1, vector<int>(n, -1));
    if (coin[0] != 1) {
        cout << "Cannot pay some amount" << '\n';
        return;
    }
    for (int val = sum; val >= 1; val--) {
        int idx = -1;
        for (int j = 0; j < n; j++) {
            if (coin[j] <= val)idx = j;
        }
        int take = 1e5 + 1, leave = solve(idx - 1, val, dp, coin);
        if (val - coin[idx] >= 0) {
            take = 1 + solve(idx, val - coin[idx], dp, coin);
        }
        if (take > leave) {
            //cout << take << " " << leave << " " << val << '\n';
            cout << "Cannot use greedy algorithm" << '\n';
            return;

        }
    }
    cout << "OK" << '\n';
}

int main() {
    int n, cnt = 1;
    while (1) {
        cin >> n;
        if (n) {
            cout << "Case #" << cnt++ << ": ";
            acc(n);
        } else return 0;
    }
}
accuracy: 1
time_ms: 3600
memory_kb: 11436
final_rank: 20

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    int cs = 0;
    while (cin >> n, n) {
        cs += 1;
        printf("Case #%d: ", cs);
        vector<int> c(n);
        for (int i = 0; i < n; i++) {
            cin >> c[i];
        }
        if (c[0] != 1) {
            printf("Cannot pay some amount\n");
            continue;
        }
        int mx = c.back() * 2 + 1;
        vector<int> g(mx, 1e9), h(mx, 1e9);
        // greedy
        g[0] = 0;
        for (int i = 1, j = 0; i < mx; i++) {
            while (j + 1 < n and i >= c[j + 1]) {
                j += 1;
            }
            g[i] = g[i - c[j]] + 1;
        }
        // dp
        h[0] = 0;
        for (int i = 1; i < mx; i++) {
            for (int j = 0; j < n; j++) {
                if (i >= c[j]) {
                    h[i] = min(h[i], h[i - c[j]] + 1);
                }
            }
        }

        bool ok = true;
        for (int i = 0; i < mx; i++) {
            if (g[i] > h[i]) {
                ok = false;
            }
        }
        if (ok) {
            printf("OK\n");
        } else {
            printf("Cannot use greedy algorithm\n");
        }
    }
}
accuracy: 1
time_ms: 30
memory_kb: 3504
final_rank: 14

code_snippet: #include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

void f(int n,int no){
	int dp[3003];
	memset(dp,-1,sizeof(dp));
	int as[51];
	int t;
	for(int i=0;i<n;i++){
		cin>>as[i];
		t=as[i];
	}
	dp[0]=0;
	bool ok=true;
	for(int i=0;i<=t*2;i++){
		if(dp[i]==-1){
			ok=false;
			break;
		}
		for(int j=0;j<n;j++){
			int t1=dp[i]+1;
			int e1=i+as[j];
			if(dp[e1]==-1||dp[e1]>t1)dp[e1]=t1;
		}
	}
	if(ok==false){
		cout<<"Case #"<<no<<": Cannot pay some amount"<<endl;
		return ;	
	}
	ok=true;
	for(int i=1;i<=t*2;i++){
		int ans=0;
		int n1=i;
		for(int j=n-1;j>=0;j--){
			ans+=n1/as[j];
			n1=n1%as[j];
		}
		if(ans!=dp[i]){
			ok=false;
		}
	}
	if(ok==false){
		cout<<"Case #"<<no<<": Cannot use greedy algorithm"<<endl;
	}else{
		cout<<"Case #"<<no<<": OK"<<endl;
	}
	
	return ;
}
int main() {
	// your code goes here
	int no=1;
	while(true){
		int n;
		cin>>n;
		if(n==0)break;
		f(n,no);
		no++;
	}
	
	return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3092
final_rank: 13

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << '\n'
typedef long long ll;
typedef long double ld;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

//using mint = atcoder :: modint998244353;
//const ll MOD = 1000000007;
//const ll MOD = 998244353;

template <typename T> inline bool chmax(T &a, T b) {return a < b ? a = b, true : false;}
template <typename T> inline bool chmin(T &a, T b) {return a > b ? a = b, true : false;}

template <typename T>
void vin(vector<T> &v) {
    int l = v.size();
    for(int i = 0; i < l; i++) cin >> v[i];
}

template <typename T>
void vout(vector<T> &v) {
    int l = v.size();
    for(int i = 0; i < l; i++) cout << v[i] << " \n"[i == l - 1];
}

void solve(int n) {
    vector<int> c(n);
    vin(c);
    if(c[0] != 1) {
        print("Cannot pay some amount");
        return;
    } else {
        vector<int> dp(2001, 2005);
        dp[0] = 0;
        for(int i = 1; i <= 2000; i++) {
            for(int j = 0; j < n; j++) {
                if(c[j] > i) continue;
                chmin(dp[i], dp[i - c[j]] + 1);
            }
        }
        for(int i = 2000; i >= 1; i--) {
            int t = i;
            int cnt = 0;
            for(int j = n - 1; j >= 0; j--) {
                if(t >= c[j]) {
                    cnt += t / c[j];
                    t -= t / c[j] * c[j];
                }
            }
            if(cnt > dp[i]) {
                print("Cannot use greedy algorithm");
                return;
            }
        }
        print("OK");
        return;
    }
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(18);

    for(int ca = 1; ca <= 1000000000; ca++) {
        int n;  cin >> n;
        if(n == 0) return 0;
        cout << "Case #" << ca << ": ";
        solve(n);
    }
}
accuracy: 1
time_ms: 30
memory_kb: 3348
final_rank: 12

code_snippet: #pragma region Macros
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define drep(i,n) for(ll i = n-1;i >= 0;i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)\
    vector<type> name(size);\
    IN(name)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)\
    vector<vector<type>> name(h, vector<type>(w));\
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)\
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
using namespace std;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define si(c) (int)(c).size()
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DBL(...)\
    double __VA_ARGS__;\
    IN(__VA_ARGS__)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) {
    scan(head);
    IN(tail...);
}
template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
vi iota(int n) {
    vi a(n);
    iota(all(a), 0);
    return a;
}
template <typename T> vi iota(vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(all(res), 0);
    sort(all(res), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    sort(all(y));
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
int popcount(ll x) { return __builtin_popcountll(x); }
int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}
template <typename T> struct edge {
    int from, to;
    T cost;
    int id;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id) {}
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
using Tree = vector<vector<int>>;
using Graph = vector<vector<int>>;
template <class T> using Wgraph = vector<vector<edge<T>>>;
Graph getG(int n, int m = -1, bool directed = false, int margin = 1) {
    Tree res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        cin >> a >> b;
        a -= margin, b -= margin;
        res[a].emplace_back(b);
        if(!directed) res[b].emplace_back(a);
    }
    return move(res);
}
template <class T> Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) {
    Wgraph<T> res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        T c;
        cin >> a >> b >> c;
        a -= margin, b -= margin;
        res[a].emplace_back(b, c);
        if(!directed) res[b].emplace_back(a, c);
    }
    return move(res);
}
#define i128 __int128_t
#define ull unsigned long long int
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(15);
    }
} setup_io;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" :", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#define LOCAL
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#pragma endregion
//#include<atcoder/all>
//using namespace atcoder;
const int INF = 1001001001;
const int MX = 2200;
void solve(int n,vector<int> &a){
    reverse(all(a));
    vector<int> dp(MX,INF);
    dp[0] = 0;
    rep(i,n){
        rep(j,MX){
            if(j+a[i] < MX)chmin(dp[j+a[i]],dp[j]+1);
        }
    }
    // trace(dp);
    bool ok = true;
    rep(i,MX)if(dp[i] == INF)ok = false;
    if(!ok){
        cout << "Cannot pay some amount" << endl;
        return;
    }
    rep(i,MX){
        ll tmp = 0;
        ll cur = i;
        for(auto x:a){
            if(cur == 0)break;
            tmp += cur/x;
            cur %= x;
            if(cur == 0)break;
        }
        if(tmp != dp[i]){
            cout << "Cannot use greedy algorithm" << endl;
            return;
        }
    }
    cout << "OK" << endl;
    
}
int main(){
    for(int i = 1;;i++){
        INT(n);
        if(n == 0)return 0;
        VEC(int,a,n);
        cout << "Case #" << i << ": ";
        solve(n,a);
    }
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3240
final_rank: 11

code_snippet: #include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#define ll  long long 
using namespace std;
int n, a[1005], t, inf = 3000;
int u[3005], g[3005];
bool get()
{
	memset(u, 0, sizeof(u));
	memset(g, 0, sizeof(g));
	int mx = 1500;
	for (int i = 1; i <= 2 * mx; i++)
		u[i] = inf;
	for (int i = 0; i < n; i++)
		u[a[i]] = 1;
	for (int i = 1; i <= 2 * mx; i++)
	{
		if (u[i] != inf)	continue;
		for (int j = 1; j < i; j++)
		{
			u[i] = min(u[i], u[i - j] + u[j]);
		}
	}
	for (int i = 1; i <= 2 * mx; i++)
	{
		int cur = i;
		for (int j = n - 1; j >= 0; j--)
		{
			g[i] += cur / a[j];
			cur %= a[j];
			if (!cur) break;
		}
	}
	for (int i = 1; i <= 2 * mx; i++)
	{
		if (u[i] < g[i])
		return true;
	}
	return false;
}
signed main()
{
	while (~scanf("%d", &n) && n)
	{
		++t;
		printf("Case #%d: ", t);
		for (int i = 0; i < n; i++)	scanf("%d", &a[i]);
		sort(a, a + n);
		if (a[0] != 1)	printf("Cannot pay some amount\n");
		else if (get())	printf("Cannot use greedy algorithm\n");
		else	printf("OK\n");
	}
}
accuracy: 1
time_ms: 1570
memory_kb: 3300
final_rank: 19

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 2000

int N,test_case = 1;
int coin[50],dp[NUM],greedy[NUM];
int minimum;


int calc_greedy(int number){

	int ret = 0;
	int rest = number;

	for(int i = N-1; i >= 0; i--){
		if(coin[i] > rest)continue;

		ret += rest/coin[i];
		rest = rest%coin[i];

		if(rest == 0)break;
	}

	return ret;
}


void func(){

	for(int i = 0; i < N; i++)scanf("%d",&coin[i]);

	if(coin[0] != 1){
		printf("Case #%d: Cannot pay some amount\n",test_case);
		return;
	}

	for(int i = 1; i < NUM; i++)dp[i] = BIG_NUM;

	dp[0] = 0;
	for(int i = 0; i < N; i++){
		for(int k = 1; coin[i]*k < NUM; k++){
			for(int num = NUM-1; num-coin[i]*k >= 0; num--){
				if(dp[num-coin[i]*k] == BIG_NUM)continue;

				dp[num] = min(dp[num],dp[num-coin[i]*k]+k);
			}
		}
	}

	for(int number = 1; number < NUM; number++){
		greedy[number] = calc_greedy(number);
	}

	bool FLG = true;

	for(int i = 1; i < NUM; i++){
		if(dp[i] != greedy[i]){
			FLG = false;
			break;
		}
	}

	if(!FLG){
		printf("Case #%d: Cannot use greedy algorithm\n",test_case);
		return;
	}

	printf("Case #%d: OK\n",test_case);
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
		test_case++;
	}
	return 0;
}
accuracy: 1
time_ms: 1030
memory_kb: 3188
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
int n;
int c[100];
  
int greedy(int x){
  int res=0;
  for(int i=n-1;i>=0;i--){
    res+=x/c[i];
    x%=c[i];
  }
  return res;
}
  
int dp[5000];
  
void solve(){
  if(c[0]!=1){
    printf("Cannot pay some amount");
    return;
  }
  
  fill( dp, dp+5000, 1e9);
  dp[0]=0;
    
  for(int i=0;i<n;i++){
    int val=c[i];
    for(int j=0;j<2000;j++){
      if(j-val>=0)dp[j]=min(dp[j],dp[j-val]+1);
    }
  }
    
  for(int num=0;num<2000;num++){
    int cost=greedy(num);
    if(cost!=dp[num]){
      //      cout<<num<<' '<<cost<<' '<<dp[num]<<endl;
      printf("Cannot use greedy algorithm");
      return;
    }
  }
  
  for(int j=2000;j<5000;j++){
  
    for(int i=0;i<n;i++){
      int val=c[i];      
      dp[j]=min(dp[j],dp[j-val]+1);
    }
      
    if( dp[j]!=dp[j- c[n-1] ]+1 ){
      printf("Cannot use greedy algorithm");
      return;
    }
  }
  printf("OK");
}
  
int main(){
  for(int tc=1;;tc++){
    scanf("%d",&n);
    if(n==0)break;
    for(int i=0;i<n;i++)scanf("%d",&c[i]);
    printf("Case #%d: ",tc);
    solve();
    printf("\n");
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3132
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
int n;
int c[100];
 
int greedy(int x){
  int res=0;
  for(int i=n-1;i>=0;i--){
    res+=x/c[i];
    x%=c[i];
  }
  return res;
}
 
int dp[5000];
 
void solve(){
  if(c[0]!=1){
    printf("Cannot pay some amount");
    return;
  }
 
  fill( dp, dp+5000, 1e9);
  dp[0]=0;
   
  for(int i=0;i<n;i++){
    int val=c[i];
    for(int j=0;j<2000;j++){
      if(j-val>=0)dp[j]=min(dp[j],dp[j-val]+1);
    }
  }
   
  for(int num=0;num<2000;num++){
    int cost=greedy(num);
    if(cost!=dp[num]){
      //      cout<<num<<' '<<cost<<' '<<dp[num]<<endl;
      printf("Cannot use greedy algorithm");
      return;
    }
  }
 
  for(int j=2000;j<5000;j++){
 
    for(int i=0;i<n;i++){
      int val=c[i];      
      dp[j]=min(dp[j],dp[j-val]+1);
    }
     
    if( dp[j]!=dp[j- c[n-1] ]+1 ){
      printf("Cannot use greedy algorithm");
      return;
    }
  }
  printf("OK");
}
 
int main(){
  for(int tc=1;;tc++){
    scanf("%d",&n);
    if(n==0)break;
    for(int i=0;i<n;i++)scanf("%d",&c[i]);
    printf("Case #%d: ",tc);
    solve();
    printf("\n");
  }
  return 0;
}


/*
#include<bits/stdc++.h>
using namespace std;

struct state{
  int qy,qx,ay,ax,f;
};

int W,H;
int syA,sxA;
int syQ,sxQ;

char t[30][30];
int d[30][30][30][30][2];// 0-> qturn 1->aturn
int C[30][30][30][30][2];// 0-> qturn 1->aturn
int dy[]={-1,0,1,0,0};
int dx[]={0,1,0,-1,0};

bool inField(int y,int x){
  return (0<=y&&y<H&&0<=x&&x<W&&t[y][x]!='#');
}

queue< state > que;

void init(){
  while( !que.empty() ) que.pop();
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(t[i][j]=='#')continue;
      
      for(int k=0;k<H;k++){
        for(int l=0;l<W;l++){
          if(t[k][l]=='#')continue;
          
          int cc;

          cc=5;
          for(int dir=0;dir<4;dir++){
            int ny=k+dy[dir];
            int nx=l+dx[dir];
            if(!inField(ny,nx))cc--;
          }
          C[i][j][k][l][0]=cc;
          d[i][j][k][l][0]=0;

          cc=5;
          for(int dir=0;dir<4;dir++){
            int ny=i+dy[dir];
            int nx=j+dx[dir];
            if(!inField(ny,nx))cc--;
          }
          
          C[i][j][k][l][1]=cc;
          d[i][j][k][l][1]=0;
        }
      }
    }
  }


        
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      if(t[i][j]!='#')
      for(int k=0;k<H;k++)
        for(int l=0;l<W;l++)
          if(t[k][l]!='#')
            for(int f=0;f<2;f++)
              if(i==k&&j==l&&f==0)
                que.push( (state){i,j,k,l,f} ), d[i][j][k][l][f]=-1;
              else if(t[i][j]=='E'&&f==0)
                que.push( (state){i,j,k,l,f} ), d[i][j][k][l][f]=1;

}

string winstr="Queen can escape.";
string losestr="Army can catch Queen.";
string drawstr="Queen can not escape and Army can not catch Queen.";

string solve(){
  while(!que.empty()){
    state s=que.front();que.pop();
    C[s.qy][s.qx][s.ay][s.ax][s.f]=0;

    int &judge=d[s.qy][s.qx][s.ay][s.ax][s.f];
    if(s.f==0){
      
      int flg=-1;
      for(int dir=0;dir<5;dir++){
        int nqy=s.qy+dy[dir];
        int nqx=s.qx+dx[dir];
        if(inField(nqy,nqx))
          if(d[nqy][nqx][s.ay][s.ax][1-s.f]==1)flg=1;
      }
      if(judge==0)judge=flg;
      
      for(int dir=0;dir<5;dir++){
        int nay=s.ay+dy[dir];
        int nax=s.ax+dx[dir];
        if(!inField(nay,nax))continue;
        
        int &cc=C[s.qy][s.qx][nay][nax][1-s.f];
        cc--;
        if(judge==-1&&cc>0)cc=0;
        if(cc==0)que.push( (state){s.qy,s.qx,nay,nax,1-s.f} );
      }
      
      
    }else if(s.f==1){
      int flg=1;
      for(int dir=0;dir<5;dir++){
        int nay=s.ay+dy[dir];
        int nax=s.ax+dx[dir];
        if(inField(nay,nax))
          if(d[s.qy][s.qx][nay][nax][1-s.f]==-1)flg=-1;
      }
      if(judge==0)judge=flg;

      for(int dir=0;dir<5;dir++){
        int nqy=s.qy+dy[dir];
        int nqx=s.qx+dx[dir];
        if(!inField(nqy,nqx))continue;
        int &cc=C[nqy][nqx][s.ay][s.ax][1-s.f];
        cc--;
        if(judge==1&&cc>0)cc=0;
        if(cc==0)que.push( (state){nqy,nqx,s.ay,s.ax,1-s.f} );
      }
    }
    if(1){
      cout<<s.qy<<' '<<s.qx<<' '<<s.ay<<' '<<s.ax<<' '<<s.f<<endl;
      cout<<d[s.qy][s.qx][s.ay][s.ax][s.f]<<endl;
      cout<<"C[0][0][0][1][0] = "<<C[0][0][0][1][0]<<endl;
      cout<<endl;
    }
    if( s.qy == syQ && s.qx == sxQ &&
        s.ay == syA && s.ax == sxA &&
        s.f  == 0 ){
      if( d[s.qy][s.qx][s.ay][s.ax][s.f] == 1 )return winstr;
      else return losestr;
    }
  }
  return drawstr;
}

int main(){
  while(1){
    
    cin>>W>>H;
    if(W==0&&H==0)break;
    
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        char ch;
        cin>>ch;
        t[i][j]=ch;
        if(ch=='A'){
          syA=i;sxA=j;
        }
        if(ch=='Q'){
          syQ=i;sxQ=j;
        }
      }
    }
    init();
    
    cout<<solve()<<endl;
  }
  return 0;
}

*/
accuracy: 1
time_ms: 40
memory_kb: 3128
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
int n;
int c[100];

int greedy(int x){
  int res=0;
  for(int i=n-1;i>=0;i--){
    res+=x/c[i];
    x%=c[i];
  }
  return res;
}

int dp[5000];

void solve(){
  if(c[0]!=1){
    printf("Cannot pay some amount");
    return;
  }

  fill( dp, dp+5000, 1e9);
  dp[0]=0;
  
  for(int i=0;i<n;i++){
    int val=c[i];
    for(int j=0;j<2000;j++){
      if(j-val>=0)dp[j]=min(dp[j],dp[j-val]+1);
    }
  }
  
  for(int num=0;num<2000;num++){
    int cost=greedy(num);
    if(cost!=dp[num]){
      //      cout<<num<<' '<<cost<<' '<<dp[num]<<endl;
      printf("Cannot use greedy algorithm");
      return;
    }
  }

  for(int j=2000;j<5000;j++){

    for(int i=0;i<n;i++){
      int val=c[i];      
      dp[j]=min(dp[j],dp[j-val]+1);
    }
    
    if( dp[j]!=dp[j- c[n-1] ]+1 ){
      printf("Cannot use greedy algorithm");
      return;
    }
  }
  printf("OK");
}

int main(){
  for(int tc=1;;tc++){
    scanf("%d",&n);
    if(n==0)break;
    for(int i=0;i<n;i++)scanf("%d",&c[i]);
    printf("Case #%d: ",tc);
    solve();
    printf("\n");
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3180
final_rank: 9

code_snippet: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[55], dp[50009], greed[50009];
int main() {
	int cnt = 0;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) cin >> a[i];
		fill(dp + 1, dp + 50001, 999999999);
		fill(greed + 1, greed + 50001, 999999999);
		for (int i = 1; i <= 50000; i++) {
			int ptr = -1;
			for (int j = 0; j < n && i >= a[j]; j++) {
				dp[i] = min(dp[i], dp[i - a[j]] + 1);
				ptr = j;
			}
			if (ptr != -1) greed[i] = greed[i - a[ptr]] + 1;
		}
		bool ret1 = true, ret2 = true;
		for (int i = 1; i <= 50000; i++) {
			if (dp[i] == 999999999) ret1 = false;
			if (dp[i] < greed[i]) ret2 = false;
		}
		cout << "Case #" << ++cnt << ": ";
		if (!ret1) cout << "Cannot pay some amount" << endl;
		else if (!ret2) cout << "Cannot use greedy algorithm" << endl;
		else cout << "OK" << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 980
memory_kb: 3436
final_rank: 17

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
int n, c[100], d, dp[50001], s;
void solve() {
	if (c[0] != 1) { cout << "Cannot pay some amount" << endl; return; }
	for (int i = 0; i <= s; i++)dp[i] = 9999999; dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= s - c[i]; j++) {
			dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1);
		}
	}
	for (int i = 1; i <= s; i++) {
		int t = 0, r = i;
		for (int j = n - 1; j >= 0; j--) {
			t += r / c[j]; r %= c[j];
		}
		if (dp[i] < t) { cout << "Cannot use greedy algorithm" << endl; return; }
	}
	cout << "OK" << endl;
}
int main() {
	while (true) {
		cin >> n; if (n == 0)break; s = 0; d++; cout << "Case #" << d << ": ";
		for (int i = 0; i < n; i++) { cin >> c[i]; s += c[i]; }
		solve();
	}
	return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 3092
final_rank: 15

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	int cnt=0;
	while(cin>>n,n){
		cnt++;
		cout<<"Case #"<<cnt<<": ";
		vi in(n);
		rep(i,n)cin>>in[i];
		if(in[0]!=1){
			cout<<"Cannot pay some amount"<<endl;
			continue;
		}
		int r=(n==1?in[n-1]:in[n-1]+in[n-2])+10;
		vi dp(r+10,inf);
		dp[0]=0;
		rep(i,n)rep(j,dp.size())if(dp[j]!=inf){
			if(j+in[i]<dp.size())dp[j+in[i]]=min(dp[j+in[i]],dp[j]+1);
		}
		bool h=true;
		rep(i,dp.size()){
			int t=i;
			int co=0;
			for(int j=n-1;j>=0;j--){
				while(t>=in[j]){
					co++;
					t-=in[j];
				}
			}
			if(co!=dp[i])h=false;
		}
		if(h)cout<<"OK"<<endl;
		else cout<<"Cannot use greedy algorithm"<<endl;
	}
}
accuracy: 1
time_ms: 90
memory_kb: 1212
final_rank: 4

code_snippet: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
 
using namespace std;
 
#define MAX_N 50
#define MAX 50001
#define INF 1e9
int n, c[MAX_N];
 
int getNum(){
    int cost[MAX];
 
    memset(cost,0,sizeof(cost));
    cost[0] = 1;
    for(int i = 0 ; i < n ; i++){
	for(int j = 0 ; j < MAX-c[i] ; j++){
	    cost[c[i]+j] += cost[j];
	}
    }
 
    for(int i = 0 ; i < MAX ; i++){
	if(cost[i] == 0){
	    return 1;
	}
    }
 
    fill(cost,cost+MAX,INF);
    cost[0] = 0;
    for(int i = 0 ; i < n ; i++){
	for(int j = c[i] ; j < MAX ; j++){
	    cost[j] = min(cost[j], cost[j-c[i]]+ 1);
	}
    }
 
    int s = MAX-1;
    for(int i = s ; i >= 1 ; i--){
	int rem = i, cnt = 0;
	for(int j = n-1 ; j >= 0 ; j--){
	    if(rem >= c[j]){
		cnt += rem / c[j];
		rem %= c[j];
	    }
	}
	if(cost[i] != cnt){
	    return 2;
	}
    }
 
    return 3;
}
 
int main(){
    int Tc = 1;
 
    while(scanf("%d" ,&n), n){
	for(int i = 0 ; i < n ; i++){
	    scanf("%d" , c+i);
	}
	int num = getNum();
	printf("Case #%d: " ,Tc++);
	if(num == 1){
	    puts("Cannot pay some amount");
	}else if(num == 2){
	    puts("Cannot use greedy algorithm");
	}else{
	    puts("OK");
	}
    }
    return 0;
}
accuracy: 1
time_ms: 1140
memory_kb: 3376
final_rank: 18

code_snippet: #include<iostream>
#include<algorithm>
#define INF (1e9)
#define N c[n-1]*2-1
using namespace std;
int main(){
  int n,c[50],k=0;
  while(cin>>n&&n){
    k++;
    for(int i=0;i<n;i++)cin>>c[i];
    cout<<"Case #"<<k<<": ";
    if(c[0]==1){
      int dp[2001]={};
      for(int i=1;i<=N;i++)dp[i]=INF;
      for(int i=0;i<n;i++)
	for(int j=c[i];j<=N;j++)
	  dp[j]=min(dp[j],dp[j-c[i]]+1);
      int f=0;
      for(int i=1;i<=N;i++){
	int a=0,s=i;
	for(int j=n-1;s!=0;j--){
	  a+=s/c[j];
	  s%=c[j];
	}
	if(a!=dp[i]){f=1;break;}
      }
      if(f)cout<<"Cannot use greedy algorithm"<<endl;
      else cout<<"OK"<<endl;
    }
    
    else cout<<"Cannot pay some amount"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1168
final_rank: 1

code_snippet: #include<iostream>
#include<algorithm>
#define INF (1e9)
#define N c[n-1]*2
using namespace std;
int main(){
  int n,c[50],k=0;
  while(cin>>n&&n){
    k++;
    for(int i=0;i<n;i++)cin>>c[i];
    cout<<"Case #"<<k<<": ";
    if(c[0]==1){
      int dp[2001]={};
      for(int i=1;i<=N;i++)dp[i]=INF;
      for(int i=0;i<n;i++)
	for(int j=c[i];j<=N;j++)
	  dp[j]=min(dp[j],dp[j-c[i]]+1);
      int f=0;
      for(int i=1;i<=N;i++){
	int a=0,s=i;
	for(int j=n-1;s!=0;j--){
	  a+=s/c[j];
	  s%=c[j];
	}
	if(a!=dp[i]){f=1;break;}
      }
      if(f)cout<<"Cannot use greedy algorithm"<<endl;
      else cout<<"OK"<<endl;
    }
    
    else cout<<"Cannot pay some amount"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 1168
final_rank: 3

code_snippet: #include<iostream>
#include<algorithm>
#define INF (1e9)
#define N c[n-1]*2-2
using namespace std;
int main(){
  int n,c[50],k=0;
  while(cin>>n&&n){
    k++;
    for(int i=0;i<n;i++)cin>>c[i];
    cout<<"Case #"<<k<<": ";
    if(c[0]==1){
      int dp[2001]={};
      for(int i=1;i<=N;i++)dp[i]=INF;
      for(int i=0;i<n;i++)
	for(int j=c[i];j<=N;j++)
	  dp[j]=min(dp[j],dp[j-c[i]]+1);
      int f=0;
      for(int i=1;i<=N;i++){
	int a=0,s=i;
	for(int j=n-1;s!=0;j--){
	  a+=s/c[j];
	  s%=c[j];
	}
	if(a!=dp[i]){f=1;break;}
      }
      if(f)cout<<"Cannot use greedy algorithm"<<endl;
      else cout<<"OK"<<endl;
    }
    
    else cout<<"Cannot pay some amount"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1168
final_rank: 1

code_snippet: #include <iostream>
#include <algorithm>
#define INF (1e9)
#define J 2000
#define N 50
using namespace std;
int main(){
  int n,c[N],dp[J],dn[J],C=0;
  while(1){
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>c[i];
    for(int i=0;i<J;i++) dp[i]=dn[i]=INF;
    dp[0]=0;
    for(int i=0;i<n;i++)
      for(int j=1;j<J;j++)
	if(j>=c[i]) dp[j]=min(dp[j],dp[j-c[i]]+1);
    reverse(c,c+n);
    for(int i=0;i<J;i++){
      int cnt=0,sum=i;
      for(int j=0;j<n;j++){
	cnt+=sum/c[j];
	sum%=c[j];
      }
      if(sum==0) dn[i]=cnt;
    }
    int flag=0;
    for(int i=1;i<J;i++){
      if(dp[i]==INF||dn[i]==INF){
	flag=1;
	break;
      }
      if(dp[i]!=dn[i]){
	flag=2;
	break;
      }
    }
    C++;
    cout<<"Case #"<<C<<": ";
    if(!flag) cout<<"OK"<<endl;
    else if(flag==1) cout<<"Cannot pay some amount"<<endl;
    else cout<<"Cannot use greedy algorithm"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 1180
final_rank: 6

code_snippet: #include <iostream>
#include <algorithm>
#define INF (1e9)
#define J 2000
#define N 50
using namespace std;
int main(){
  int n,c[N],dp[J],dn[J],C=0;
  while(1){
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>c[i];
    for(int i=0;i<J;i++) dp[i]=dn[i]=INF;
    sort(c,c+n);
    dp[0]=0;
    for(int i=0;i<n;i++)
      for(int j=1;j<J;j++)
	if(j>=c[i]) dp[j]=min(dp[j],dp[j-c[i]]+1);
    sort(c,c+n);
    reverse(c,c+n);
    for(int i=0;i<J;i++){
      int cnt=0,sum=i;
      for(int j=0;j<n;j++){
	cnt+=sum/c[j];
	sum%=c[j];
      }
      if(sum==0) dn[i]=cnt;
    }
    int flag=0;
    for(int i=1;i<J;i++){
      if(dp[i]==INF||dn[i]==INF){
	flag=1;
	break;
      }
      if(dp[i]!=dn[i]){
	flag=2;
	break;
      }
    }
    C++;
    cout<<"Case #"<<C<<": ";
    if(!flag) cout<<"OK"<<endl;
    else if(flag==1) cout<<"Cannot pay some amount"<<endl;
    else cout<<"Cannot use greedy algorithm"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 1196
final_rank: 5