Problem:
Problem D
Efficient Problem Set
You are planning a problem set for the upcoming programming contest.
The problem set should consist of one or more problems each allocated with a certain amount of points, which is a positive integer.
The score of each contestant is the sum of the points of the problems that the contestant correctly answers.
The total of points of problems in the problem set must be equal to the full score given by the contest organizer.
In addition, some of the contest sponsor companies want to give special prizes to the contestants first attaining prescribed scores exactly.
Thus, you have to make the problem set so that every prize-obtaining score specified by a sponsor can possibly be the score of a contestant at some point of time.
You have not prepared any problems yet, as you are planning to start it after deciding the points of each problem in the set.
Because it is troublesome to prepare many problems, you want to meet the above-described requirements with as few problems as possible.
For example, when the full score is 7 and the prize-obtaining scores are 2 and 5, you can meet them by preparing two problems with points 2 and 5.
When the full score is 7 and the prize-obtaining scores are 2 and 4, however, you have to prepare three problems, e.g., those with points 2, 2, and 3.
Find the minimum possible number of problems that meet the requirements.
Input
The input consists of multiple datasets.
Each dataset is in the following format.
n
s
n
is the full score of the contest (i.e., the total of points of problems), which is a positive integer not exceeding 100.
s
represents which values should have possibilities to be contestants' scores.
s
is a string of length (
n
+ 1) consisting of
o
's and
x
's, whose (
k
+ 1)-st character being an
o
means "contestants should have possibilities to get exactly
k
points as their scores", and being an
x
means it is not required, i.e., "either is fine whether contestants can get exactly
k
points as their scores or not".
The first and the last characters of
s
are always
o
's.
The end of the input is indicated by a line consisting of a zero.
The input consists of at most 100 datasets.
Output
For each dataset, output in a line the minimum possible number of problems that meet the requirements.
Sample Input
3
ooxo
5
oxxxxo
7
oxoxoxxo
7
oxoxxoxo
8
oxxooooxo
0
Output for the Sample Input
2
1
3
2
4

Submitted solutions:

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

#define MAXS 100   // 最大データセット数
#define MAXN 100   // 最大満点



int solve(int n, const string& s) {
    for (int k = 1; k <= n; ++k) {
        bool found = false;
        vector<int> tmp;

        function<void(int, int, int)> dfs = [&](int rem, int left, int last) {
            if (found) return;
            if (left == 0) {
                if (rem == 0) {
                    bitset<101> reachable;
                    reachable[0] = 1;
                    for (int p : tmp) {
                        reachable |= reachable << p;
                    }
                    for (int i = 0; i <= n; ++i) {
                        if (s[i] == 'o' && !reachable[i]) return;
                    }
                    found = true;
                }
                return;
            }

            for (int i = last; i <= rem; ++i) {
                tmp.push_back(i);
                dfs(rem - i, left - 1, i);
                tmp.pop_back();
            }
        };

        dfs(n, k, 1); 

        if (found) return k;
    }

    return -1;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    for (int i = 0; i < MAXS; ++i) {
        int n;
        if (!(cin >> n)) break;
        if (n == 0) break;

        string s;
        cin >> s;

        cout << solve(n, s) << "\n";
    }

    return 0;
}
accuracy: 1
time_ms: 700
memory_kb: 3464
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(...) std::begin(__VA_ARGS__), std::end(__VA_ARGS__)
#define rall(...) std::rbegin(__VA_ARGS__), std::rend(__VA_ARGS__)
#define OVERLOAD_REP(_1, _2, _3, _4, name, ...) name
#define REP1(n) for(ll i=0;i<(n);i++)
#define REP2(i, n) for (ll i=0;i<(n);i++)
#define REP3(i, a, n) for (ll i=a;i<(n);i++)
#define REP4(i, a, b, n) for(ll i=a;i<(n);i+=b)
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define OVERLOAD_RREP(_1, _2, _3, _4, name, ...) name
#define RREP1(n) for(ll i=(n)-1;i>=0;i--)
#define RREP2(i, n) for(ll i=(n)-1;i>=0;i--)
#define RREP3(i, a, n) for(ll i=(n)-1;i>=(a);i--)
#define RREP4(i, a, b, n) for(ll i=(n)-1;i>=(a);i-=(b))
#define rrep(...) OVERLOAD_RREP(__VA_ARGS__, RREP4, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define len(n) (long long)(n).size()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using vvs = vector<vs>;
using vvvs = vector<vvs>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vc = vector<char>;
using vvc = vector<vc>;
using vvvc = vector<vvc>;
using pll = pair<ll,ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;

ll intpow(ll a,ll b){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
        }
        a *= a;
        b /= 2;
    }
    return ans;
}
ll modpow(ll a,ll b,ll c){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
            ans %= c;
        }
        a *= a;
        a %= c;
        b /= 2;
    }
    return ans;
}

template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}

#define INT(...) int __VA_ARGS__; input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; input(__VA_ARGS__)
#define CHA(...) char __VA_ARGS__; input(__VA_ARGS__)
#define VLL(name,length) vll name(length);rep(i,length){cin >> name[i];}
#define VVLL(name,h,w) vvll name(h,vll(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLL(name,a,b,c) vvvll name(a,vvll(b,vll(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VI(name,length) vi name(length);rep(i,length){cin >> name[i];}
#define VVI(name,h,w) vvi name(h,vi(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVI(name,a,b,c) vvvi name(a,vvll(b,vi(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VLD(name,length) vld name(length);rep(i,length){cin >> name[i];}
#define VVLD(name,h,w) vvld name(h,vld(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLD(name,a,b,c) vvvld name(a,vvld(b,vld(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VC(name,length) vc name(length);rep(i,length){cin >> name[i];}
#define VVC(name,h,w) vvc name(h,vc(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVC(name,a,b,c) vvvc name(a,vvc(b,vc(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VS(name,length) vs name(length);rep(i,length){cin >> name[i];}
#define VVS(name,h,w) vvs name(h,vs(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVS(name,a,b,c) vvvs name(a,vvs(b,vs(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define PLL(name) pll name;cin>>name.first>>name.second;
#define VPLL(name,length) vpll name(length);rep(i,length){cin>>name[i].first>>name[i].second;}

void print(){cout << "\n";}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
    os << "[";
    for (size_t i = 0; i < vec.size(); ++i) {
        os << vec[i];
        if (i + 1 < vec.size()) os << ", ";
    }
    os << "]";
    return os;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::vector<std::pair<T1, T2>>& a) {
    os << "[";
    for (size_t j = 0; j < a.size(); ++j) {
        os << "(" << a[j].first << ", " << a[j].second << ")";
		if (j + 1 < a.size()) os << ", ";
    }
	os << "]";
    return os;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::vector<std::vector<std::pair<T1, T2>>>& mat) {
	os << "[";
    for (size_t i = 0; i < mat.size(); ++i) {
		os << "[";
        for (size_t j = 0; j < mat[i].size(); ++j) {
            os << "(" << mat[i][j].first << ", " << mat[i][j].second << ")";
			if (j + 1 < mat[i].size()) os << ", ";
        }
		os << "]";
		if (i + 1 < mat.size()) os << ", ";
    }
	os << "]";
    return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
    os << "{";
    bool first = true;
    for (const auto& x : s) {
        if (!first) os << ", ";
        os << x;
        first = false;
    }
    os << "}";
    return os;
}

template <typename K, typename V>
std::ostream& operator<<(std::ostream& os, const std::map<K, V>& m) {
    os << "{";
    bool first = true;
    for (const auto& [key, val] : m) {
        if (!first) os << ", ";
        os << key << ": " << val;
        first = false;
    }
    os << "}";
    return os;
}

template<class T, class... Ts>
void print(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';}

void write(){cout << "\n";}
template<class T, class... Ts>
void write(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';}
void write(vll x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvll x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vi x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvi x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvi x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vld x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvld x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvld x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vc x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvc x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvc x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vs x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvs x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvs x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(pll x){cout << x.first << ' ' << x.second << '\n';}
void write(vpll x){rep(i,len(x)){cout << x[i].first << ' ' << x[i].second << '\n';}}
void write(vvpll x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j].first << ' ' << x[i][j].second;if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}

template <typename T>
T sum(const std::vector<T>& v) {
    return std::accumulate(v.begin(), v.end(), T(0));
}

template<class T> bool chmin(T& a, const T& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U& b){ if(a > T(b)){ a = b; return 1; } return 0; }
template<class T, class U> bool chmax(T& a, const U& b){ if(a < T(b)){ a = b; return 1; } return 0; }



int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

    while(1){
        LL(n);
        if(n == 0){break;}
        STR(s);
        ll ans = 7;
        auto f = [&](vll a){
            ll res = 1LL<<60;
            ll x = 0;
            for(auto y:a){
                x += y;
            }
            x = n - x;
            if(x < 0 || x > n){return res;}
            a.push_back(x);
            if(len(a) >= ans){return res;}
            //print(a);
            bitset<101> b;
            b[0] = 1;
            for(auto x:a){
                bitset<101> nb = b | (b << x);
                swap(b,nb);
            }
            ll check = 1;
            rep(i,n+1){
                if(s[i] == 'o'){
                    if(b[i] == 0){
                        check = 0;
                        break;
                    }
                }
            }
            if(check){
                res = len(a);
            }
            return res;
        };
        chmin(ans,f({}));
        rep(i,1,n+1){
            chmin(ans,f({i}));
            rep(j,i+1,n+1){
                if(i + j > n){break;}
                chmin(ans,f({i,j}));
                rep(k,j+1,n+1){
                    if(i + j + k > n){break;}
                    chmin(ans,f({i,j,k}));
                    rep(l,k+1,n+1){
                        if(i + j + k + l > n){break;}
                        chmin(ans,f({i,j,k,l}));
                        rep(m,l+1,n+1){
                            if(i + j + k + l + m > n){break;}
                            chmin(ans,f({i,j,k,l,m}));
                        }
                    }
                }
            }
        }
        print(ans);
    }
}
accuracy: 1
time_ms: 1440
memory_kb: 3308
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
int n;
string s;
int ans;
void dfs(int depth,int last,int sum,int count,bitset<128> bs){
    if(count>=ans){
        return ;
    }
    if(depth==7){
        bool flag=true;
        for(int i=0;i<n+1;i++){
            if(s[i]=='o'&&!bs[i]){
                flag=false;
                break;
            }
        }
        if(flag){
            ans = min(ans,count);
        }
        return;
    }
    for(int i=last;i>=0;i--){
        if(sum+i>n){
            continue;
        }
        auto next=bs;
        if(i!=0){
            next|=(bs<<i);
            
        }
        dfs(depth+1,i,sum+i,count+(i!=0),next);
    }
}
int main(){
    while(true){
        cin >> n;
        if(n == 0) break;
        cin >> s;
        ans=7;
        bitset<128> bs;
        bs.set(0);
        dfs(0,n,0,0,bs);
        cout << ans << endl;
    }       
}
accuracy: 1
time_ms: 2820
memory_kb: 3440
final_rank: 7

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

#define int long long
using ll = long long;
ll INF = 2e18;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fi first
#define se second
#define endl "\n" // コメントアウトで随時出力

/*=========================================mint=======================================*/
const int mintMod = MOD2; // ここを変更
class mint
{
    long long x;

public:
    mint(long long x = 0) : x((x % mintMod + mintMod) % mintMod) {}
    long long val() const { return x; }
    mint operator-() const
    {
        return mint(-x);
    }
    mint &operator+=(const mint &a)
    {
        if ((x += a.x) >= mintMod)
            x -= mintMod;
        return *this;
    }
    mint &operator-=(const mint &a)
    {
        if ((x += mintMod - a.x) >= mintMod)
            x -= mintMod;
        return *this;
    }
    mint &operator*=(const mint &a)
    {
        (x *= a.x) %= mintMod;
        return *this;
    }
    mint operator+(const mint &a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const
    {
        return pow(mintMod - 2);
    }
    mint &operator/=(const mint &a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint &a) const
    {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream &os, const mint &m)
    {
        os << m.x;
        return os;
    }
    friend istream &operator>>(istream &is, mint &m)
    {
        long long v;
        is >> v;
        m = mint(v);
        return is;
    }
};
/*========================================================================================*/

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

template <typename T>
using vc = vector<T>; // prioriy_queueに必要なのでここにこれ書いてます
template <typename T>
using vv = vc<vc<T>>;

// 提出の際はコメントアウト
#define debug_x(x) cout << #x << " = " << (x) << endl
#define debug_vc(v)                    \
    {                                  \
        cout << #v << endl;            \
        ll n = size(v);                \
        rep(i, n) cout << v[i] << ' '; \
        cout << endl;                  \
    } // 一次元配列を出力する
#define debug_vv(v)                                        \
    {                                                      \
        cout << #v << endl;                                \
        ll n = size(v);                                    \
        rep(i, n)                                          \
        {                                                  \
            rep(j, size(v[i])) { cout << v[i][j] << ' '; } \
            cout << endl;                                  \
        }                                                  \
    } // 二次元配列を出力する

// #define debug_x(x) \
//     do             \
//     {              \
//     } while (0)
// #define debug_vc(v) \
//     do              \
//     {               \
//     } while (0)
// #define debug_vv(v) \
//     do              \
//     {               \
//     } while (0)

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define drep(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define nfor(i, s, n) for (ll i = s; i < n; i++)        // i=s,s+1...n-1 ノーマルfor
#define dfor(i, s, n) for (ll i = (s) - 1; i >= n; i--) // s-1スタートでnまで落ちる

using ld = long double;
using bl = bool;

template <class T>
using pq = priority_queue<T, vc<T>>; // 大きい順
template <class T>
using pq_g = priority_queue<T, vc<T>, greater<T>>; // 小さい順

using vl = vc<ll>;
using vvl = vv<ll>;
using vvvl = vv<vl>;
using vvvvl = vv<vvl>;
using vs = vc<string>;
using vvs = vv<string>;
using vb = vc<bl>;
using vvb = vv<bl>;
using vvvb = vv<vb>;
using vld = vc<ld>;
using vvld = vv<ld>;
using vvvld = vv<vld>;
using P = pair<ll, ll>;
using vP = vc<P>;
using vvP = vc<vP>;
using vvvP = vv<vP>;
using vmint = vc<mint>;
using vvmint = vv<mint>;
using vvvmint = vv<vmint>;

#define pb push_back
#define eb emplace_back

#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define YN                     \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    } // if(a==b)YN;
#define dame cout << -1 << endl

string dir = "DRUL";   // 第4象限の場合
vl di = {1, 0, -1, 0}; // vl di={1,1,0,-1,-1,-1,0,1};
vl dj = {0, 1, 0, -1}; // vl dj={0,1,1,1,0,-1,-1,-1};

bool out_grid(ll i, ll j, ll h, ll w)
{ // trueならcontinue
    return (!(0 <= i && i < h && 0 <= j && j < w));
}

ll n;
vl v = {1};
ll ans = 7;
vb isPoint;

void dp(ll cnt)
{
    // debug_vc(v);
    vb dp(n + 1);
    rep(i, 1 << cnt)
    {
        ll sum = 0;
        rep(j, cnt)
        {
            if (i & (1 << j))
                sum += v[j + 1];
        }
        dp[sum] = true;
    }
    bl ok = true;
    rep(k, n + 1)
    {
        if (isPoint[k] && !dp[k])
        {
            ok = false;
            break;
        }
    }
    if (ok)
    {
        ans = min(ans,cnt);
    }
    // debug_x(ans);
}

void dfs(ll cnt, ll sum)
{
    if (sum == n)
    {
        dp(cnt);
    }
    if (cnt >= 6)
    {
        return;
    }
    for (ll i = v.back(); i <= n - sum; i++)
    {
        v.pb(i);
        dfs(cnt + 1, sum + i);
        v.pop_back();
    }
}

void solve()
{
    string s;
    cin >> s;
    ans = 7;
    isPoint.assign(n+1,false);
    rep(i, n + 1)
    {
        if (s[i] == 'o')
            isPoint[i] = true;
    }
    // debug_vc(isPoint);
    dfs(0, 0);
    
    // rep(_,7){
    //     // if(p[].size()==0)continue;
    //     debug_vv(p[_]);
    // }

    // 
    cout << ans << endl;
    return;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    while (true)
    {
        cin >> n;
        if (n == 0)
            break;
        solve();
    }
    return 0;
}

/*
shift+alt+Fで成形
f2で変数名変更

スニペット
basic
 m:atcoder以外用
 ma:ABC/ARC用
 mahc:AHC用
math
 floor:床関数
 ceil:天井関数
 comv:二項係数
 modpow: a^b mod m
 GCD:最大公約数
 extGCD:拡張ユークリッド互除法
 PFD:素因数分解
 isprime:エラトステネスの篩
 matrixpow:行列累乗
data_structure
 seg:セグメント木
technic
 Compress:座標圧縮
 runlength:ランレングス圧縮
graph
 warshall:ワーシャルフロイド法
 dfs:深さ優先探索
 bfs:幅優先探索
 LCA:最近共通祖先
*/
accuracy: 1
time_ms: 4730
memory_kb: 3472
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define rrep(i, s, t) for(ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define TT template<typename T>
TT using vec = vector<T>;
template<class T1, class T2> bool chmin(T1 &x, T2 y) { return x > y ? (x = y, true) : false; }
template<class T1, class T2> bool chmax(T1 &x, T2 y) { return x < y ? (x = y, true) : false; }

struct io_setup {
    io_setup() {
        ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        cout << fixed << setprecision(15);
    }
} io_setup;

bool check(int N,vector<vector<int>>X,vector<vector<int>>Y){
    vector<pair<int,int>>at(N*N+1);
    rep(i,0,N)rep(j,0,N){
        at[Y[i][j]]={i,j};
    }
    rep(i,0,N)rep(j,0,N)rep(k,0,N)rep(l,0,N){
        if(abs(i-k)+abs(j-l)==1){
            int a=X[i][j],b=X[k][l];
            auto[x,y]=at[a];
            auto[z,w]=at[b];
            if(abs(x-z)+abs(y-w)<N/2)return false;
        }
    }
    return true;
}

int solve(int N,string S){
    int ans=1<<30;
    vector<int>vec;
    vector<bool>flag(N+1);
    rep(a,0,N+1){
        if(6*a>N-a)break;
        if(a)vec.push_back(a);
        rep(b,a,N+1-a){
            if(5*b>N-a-b)break;
            if(b)vec.push_back(b);
            rep(c,b,N+1-a-b){
                if(4*c>N-a-b-c)break;
                if(c)vec.push_back(c);
                rep(d,c,N+1-a-b-c){
                    if(3*d>N-a-b-c-d)break;
                    if(d)vec.push_back(d);
                    rep(e,d,N+1-a-b-c-d){
                        if(2*e>N-a-b-c-d-e)break;
                        if(e)vec.push_back(e);
                        rep(f,e,N+1-a-b-c-d-e){
                            if(f>N-a-b-c-d-e-f)break;
                            if(f)vec.push_back(f);
                            {
                                int g=N-a-b-c-d-e-f;
                                vec.push_back(g);
                                for(int bit=0;bit<1<<(int)vec.size();bit++){
                                    int cnt=0;
                                    rep(i,0,(int)vec.size()){
                                        if(bit>>i&1)cnt+=vec[i];
                                    }
                                    flag[cnt]=true;
                                }
                                bool ok=true;
                                rep(i,0,N+1){
                                    if(S[i]=='o'&&!flag[i]){
                                        ok=false;
                                        break;
                                    }
                                }
                                if(ok)return (int)vec.size();
                                vec.pop_back();
                                rep(i,0,N+1)flag[i]=false;
                            }
                            if(f)vec.pop_back();
                        }
                        if(e)vec.pop_back();
                    }
                    if(d)vec.pop_back();
                }
                if(c)vec.pop_back();
            }
            if(b)vec.pop_back();
        }
        if(a)vec.pop_back();
    }
    return -1;
}

int main() {
    while(1){
        int N;
        cin>>N;
        if(N==0)return 0;
        string S;
        cin>>S;
        int ans=solve(N,S);
        assert(ans!=-1);
        cout<<ans<<endl;
    }
}
accuracy: 1
time_ms: 2620
memory_kb: 3584
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

ll INF = 1e18;

template <typename A>
void chmin(A &l, const A &r) {
    if(r < l) l = r;
}
template <typename A>
void chmax(A &l, const A &r) {
    if(l < r) l = r;
}

vector<int> v;
vector<vector<int>> su;
vector<bitset<101>> w;
void init() {
    su.resize(101);
    auto check = [&](vector<int> &v) -> bitset<101> {
        vector<char> ok(101, 0);
        for(int i = 0; i < (1 << v.size()); i++) {
            ll sum = 0;
            for(int j = 0; j < v.size(); j++) {
                if(i & (1 << j)) sum += v[j];
            }
            ok[sum] = 1;
        }
        bitset<101> ret;
        for(int i = 0; i <= 100; i++) {
            if(ok[i]) ret.set(i, 1);
        }
        return ret;
    };
    auto make = [&](auto self, vector<int> &now, ll depth, ll sum) -> void {
        if(now.size()) {
            auto ret = check(now);
            su[sum].push_back(v.size());
            v.push_back(now.size());
            w.push_back(ret);
        }
        if(depth){
            int st = 1;
            if(now.size()) st = now.back();
            for(int i = st; i * depth <= (100 - sum); i++) {
                now.push_back(i);
                self(self, now, depth - 1, sum + i);
                now.pop_back();
            }
        }
    };
    for(int i = 1; i <= 6; i++) {
        vector<int> now;
        make(make, now, i, 0);
    }
}
ll n;
string s;
void input() { cin >> n >> s; }
void solve() {
    bitset<101> bt;
    for(int i = 0; i <= n; i++) {
        bt.set(i, (s[i] == 'x' ? 1 : 0));
    }
    for(int i = n + 1; i < 101; i++) {
        bt.set(i, 1);
    }
    ll ans = 7;
    bitset<101> fin;
    for(auto &i:su[n]) {
        auto res = bt | w[i];
        if(res.count() == 101) {
            if(ans>v[i])
            fin=w[i];
            chmin(ans,(ll)v[i]);
        }
    }
    cout << ans << endl;
}

ifstream in;
ofstream out;
int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if(argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    init();
    while(1) {
        input();
        if(n == 0) break;
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 1360
memory_kb: 101808
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ld = long double;
#undef long
#define long long long
#define ll long
#define vec vector
#define rep(i, n) for (long i = 0; i < n; i++)
#define all(a) begin(a), end(a)
#define sz(a) (int)(a).size()
template <typename T>
bool chmin(T &x, T y)
{
    if (y < x)
    {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &x, T y)
{
    if (x < y)
    {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> a)
{
    const int n = a.size();
    rep(i, n)
    {
        os << a[i];
        if (i + 1 != n)
            os << " ";
    }
    return os;
}
using iint = __int128_t;
struct S
{
    iint now;
    int gekai;
    int nok;
};
void solve()
{
    int n;
    cin >> n;
    if (n == 0)
        exit(0);
    string ss;
    cin >> ss;
    iint s = 0;
    rep(i, n + 1) if (ss[i] == 'o') s |= ((iint)1) << i;
    constexpr int INF = 105;
    vec<iint> ma(INF);
    rep(i, INF) ma[i] = (((iint)1) << i) - 1;
    vec<S> a;
    a.push_back({(iint)1, 1, n});
    int ans = 0;
    while (true)
    {
        ans++;
        vec<S> aa;
        for (auto [now, gekai, nok] : a)
        {
            for (int i = gekai; i <= n && i <= nok; i++)
            {
                iint nnow = (now | (now << i)) & ma[n + 1];
                if ((nnow & s) == s)
                {
                    cout << ans << endl;
                    return;
                }
                if ((now & s & ma[gekai]) != (s & ma[gekai]))
                    continue;
                aa.push_back({nnow, i, nok - i});
            }
        }
        swap(a, aa);
    }
}
int main()
{
    cin.tie(0)->sync_with_stdio(0), cout.tie(0);
    cout << fixed << setprecision(20);
    int t = 1;
    // cin >> t;
    while (1)
        solve();
}
accuracy: 1
time_ms: 220
memory_kb: 70780
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
bool solve();

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
template <class T>
inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, 1) : (0));
}
template <class T>
inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, 1) : (0));
}

int main() {
  while (solve());
  return 0;
}

bool solve() {
  int n;cin>>n;
  if (n==0) return 0;
  string s;cin>>s;
  int m=1;
  while(1<<m <=n)m++;
  vi v;
  int sum=0;
  int ans=1001010;
  bitset<101> dp(0);
  auto dfs=[&](auto dfs,int i)->void{
    if(sum==n&&sz(v)<=m){
      dp=0;
      dp[0]=1;
      for(auto x:v)dp|=dp<<x;
      bool ok = 1;
      rep(j,0,n+1)if(s[j]=='o'&&dp[j]==0)ok=0;
      if(ok)chmin(ans,sz(v));
    }
    if(sz(v)==m)return;
    if(sz(v)>=ans)return;
    for(int j=i;j<=n-sum;j++){
      v.push_back(j);
      sum+=j;
      dfs(dfs,j);
      sum-=j;
      v.pop_back();
    }
  };
  dfs(dfs,1);
  cout<<ans<<endl;
  return 1;
}
accuracy: 1
time_ms: 3160
memory_kb: 3456
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
bool solve();

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
template <class T>
inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, 1) : (0));
}
template <class T>
inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, 1) : (0));
}

int main() {
  while (solve());
  return 0;
}

bool solve() {
  int n;cin>>n;
  if (n==0) return 0;
  string s;cin>>s;
  int m=1;
  while(1<<m <=n)m++;
  vi v;
  int sum=0;
  int ans=1001010;
  bitset<101> dp(0);
  auto dfs=[&](auto dfs,int i)->void{
    if(sum==n&&sz(v)<=m){
      dp=0;
      dp[0]=1;
      for(auto x:v)dp|=dp<<x;
      bool ok = 1;
      rep(j,0,n+1)if(s[j]=='o'&&dp[j]==0)ok=0;
      if(ok)chmin(ans,sz(v));
    }
    if(sz(v)==m)return;
    if(sz(v)>=ans)return;
    if(sz(v)==m-1){
      int j=n-sum;
      if(j<1)return;
      v.push_back(j);
      sum+=j;
      dfs(dfs,j);
      sum-=j;
      v.pop_back();
      return;
    }
    for(int j=i;j<=n-sum;j++){
      v.push_back(j);
      sum+=j;
      dfs(dfs,j);
      sum-=j;
      v.pop_back();
    }
  };
  dfs(dfs,1);
  cout<<ans<<endl;
  return 1;
}
accuracy: 1
time_ms: 5690
memory_kb: 3456
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
bool solve();

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
template <class T>
inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, 1) : (0));
}
template <class T>
inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, 1) : (0));
}

int main() {
  while (solve());
  return 0;
}

bool solve() {
  int n;cin>>n;
  if (n==0) return 0;
  string s;cin>>s;
  int m=1;
  while(1<<m <=n)m++;
  vi v;
  int sum=0;
  int ans=1001010;
  bitset<101> dp(0);
  auto dfs=[&](auto dfs,int i)->void{
    if(sum==n&&sz(v)<=m){
      dp=0;
      dp[0]=1;
      for(auto x:v)dp|=dp<<x;
      bool ok = 1;
      rep(j,0,n+1)if(s[j]=='o'&&dp[j]==0)ok=0;
      if(ok)chmin(ans,sz(v));
    }
    if(sz(v)==m)return;
    if(sz(v)>=ans)return;
    // if(sz(v)==m-1){
    //   int j=n-sum;
    //   v.push_back(j);
    //   sum+=j;
    //   dfs(dfs,j);
    //   sum-=j;
    //   v.pop_back();
    //   return;
    // }
    for(int j=i;j<=n-sum;j++){
      v.push_back(j);
      sum+=j;
      dfs(dfs,j);
      sum-=j;
      v.pop_back();
    }
  };
  dfs(dfs,1);
  cout<<ans<<endl;
  return 1;
}
accuracy: 1
time_ms: 3160
memory_kb: 3456
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
bool solve();

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
template <class T>
inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, 1) : (0));
}
template <class T>
inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, 1) : (0));
}

int main() {
  while (solve());
  return 0;
}

bool solve() {
  int n;cin>>n;
  if (n==0) return 0;
  string s;cin>>s;
  int m=1;
  while(1<<m <=n)m++;
  vi v;
  int sum=0;
  int ans=1001010;
  bitset<101> dp(0);
  auto dfs=[&](auto dfs,int i)->void{
    if(sum==n&&sz(v)<=m){
      dp=0;
      dp[0]=1;
      for(auto x:v)dp|=dp<<x;
      bool ok = 1;
      rep(j,0,n+1)if(s[j]=='o'&&dp[j]==0)ok=0;
      if(ok)chmin(ans,sz(v));
    }
    if(sz(v)==m)return;
    if(sz(v)>=ans)return;
    if(sz(v)==m-1){
      int j=n-sum;
      v.push_back(j);
      sum+=j;
      dfs(dfs,j);
      sum-=j;
      v.pop_back();
      return;
    }
    for(int j=i;j<=n-sum;j++){
      v.push_back(j);
      sum+=j;
      dfs(dfs,j);
      sum-=j;
      v.pop_back();
    }
  };
  dfs(dfs,1);
  cout<<ans<<endl;
  return 1;
}
accuracy: 1
time_ms: 7230
memory_kb: 3456
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
bool solve();

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
template <class T>
inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, 1) : (0));
}
template <class T>
inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, 1) : (0));
}

int main() {
  while (solve());
  return 0;
}

bool solve() {
  int n;cin>>n;
  if (n==0) return 0;
  string s;cin>>s;
  int m=1;
  while(1<<m <=n)m++;
  vi v;
  int sum=0;
  int ans=1001010;
  bitset<101> dp(0);
  auto dfs=[&](auto dfs,int i)->void{
    if(sum==n&&sz(v)<=m){
      dp=0;
      dp[0]=1;
      rep(j,0,sz(v)){
        int u=v[j];
        dp|=(dp<<u);
      }
      bool ok = 1;
      rep(j,0,n+1)if(s[j]=='o'&&dp[j]==0)ok=0;
      if(ok){
        chmin(ans,sz(v));
      }
    }
    if(sz(v)==m)return;
    for(int j=i;j<=n-sum;j++){
      v.push_back(j);
      sum+=j;
      dfs(dfs,j);
      sum-=j;
      v.pop_back();
    }
  };
  dfs(dfs,1);
  cout<<ans<<endl;
  return 1;
}
accuracy: 1
time_ms: 5240
memory_kb: 3584
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(i=0;i<N;i++)
#define ll long long

vector<vector<ll>>P[7];
vector<ll>p;
void dfs(ll pre,ll rest){
    if(rest==0){
        P[p.size()].push_back(p);
        return;
    }
    if(p.size()==5){
        if(pre<=rest){
            p.push_back(rest);
            P[p.size()].push_back(p);
            p.pop_back();
        }
        return;
    }
    for(ll i=pre;i<=rest;i++){
        p.push_back(i);
        dfs(i,rest-i);
        p.pop_back();
    }
}

int main(void){
    ll i,j,k;

    ll N;
    string S;

    for(;;){
        cin>>N;
        if(N==0)break;
        cin>>S;
        vector<ll> need;
        rep(i,S.size()){
            if(S[i]=='o')need.push_back(i);
        }

        for(i=1;i<=6;i++)P[i].clear();
        dfs(1,N);

        ll ans=7;
        for(k=1;k<=6;k++){
            for(auto v:P[k]){
                bitset<101>dp(1);
                for(auto x:v){
                    for(i=N-x;0<=i;i--){
                        if(dp[i])dp.set(i+x);
                    }
                }

                ll cnt=0;
                for(auto n:need){
                    cnt+=dp[n];
                }

                if(cnt==need.size()){
                    ans=v.size();
                    break;
                }
            }
            if(ans!=7)break;
        }

        cout<<ans<<endl;
    }

    return 0;
}
accuracy: 1
time_ms: 3010
memory_kb: 21064
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
#else
  #define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

inline void solve() {
  int n;
  cin >> n;
  if (n == 0) exit(0);
  string s;
  cin >> s;
  bitset<101> flg;
  reverse(s.begin(), s.end());
  rep(i, n + 1) flg[i] = s[i] == 'o';
  int ans = 7;
  for (int p1 = 0; p1 <= n; p1++) {
    for (int p2 = p1; p1 + p2 <= n; p2++) {
      for (int p3 = p2; p1 + p2 + p3 <= n; p3++) {
        for (int p4 = p3; p1 + p2 + p3 + p4 <= n; p4++) {
          for (int p5 = p4; p1 + p2 + p3 + p4 + p5 <= n; p5++) {
            for (int p6 = p5; p1 + p2 + p3 + p4 + p5 + p6 <= n; p6++) {
              bitset<101> flg2;
              flg2[0] = true;
              flg2 |= flg2 << p1;
              flg2 |= flg2 << p2;
              flg2 |= flg2 << p3;
              flg2 |= flg2 << p4;
              flg2 |= flg2 << p5;
              flg2 |= flg2 << p6;
              if ((flg2 & flg) == flg) {
                int cnt = 6;
                if (p1 == 0) cnt--;
                if (p2 == 0) cnt--;
                if (p3 == 0) cnt--;
                if (p4 == 0) cnt--;
                if (p5 == 0) cnt--;
                if (p6 == 0) cnt--;
                ans = min(ans, cnt);
              }
            }
          }
        }
      }
    }
  }
  cout << ans << '\n';
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  while (true) solve();
  return 0;
}
accuracy: 1
time_ms: 2840
memory_kb: 3456
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using ull = unsigned long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
constexpr ll INF = ((1LL << 61) + (1LL << 30) - 1);

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  while(true) {
    ll n;
    cin >> n;
    if(n == 0) break;

    string s;
    cin >> s;
    ll o_cnt = 0;
    rep(i, s.size()) if(s[i] == 'o') o_cnt++;

    // 高々答えは 7
    // 99_C_5 が間に合う → 6 個まででできないなら 7 できるならそれが答え

    vector<bool> ok(s.size(), false);
    auto check = [&](const vector<ll>& g) -> bool {
      ok.assign(s.size(), false);
      ll cnt = 0;
      rep(i, (1LL << g.size())) {
        ll sum = 0;
        rep(j, g.size()) if(i & (1LL << j)) sum += g[j];
        if(!ok[sum] && s[sum] == 'o') {
          ok[sum] = true;
          cnt++;
        }
      }
      // cerr << "Checking group: ";
      // for(ll x: g) cerr << x << ' ';
      // cerr << " -> cnt: " << cnt << '\n';
      return cnt == o_cnt;
    };

    ll ans = 7, g_size;
    vector<ll> group;
    auto dfs = [&](auto self, ll sum) -> void {
      if(group.size() == g_size - 1) {
        if(n - sum < 0 || (group.empty() ? 0 : group.back()) > n - sum) return;
        group.emplace_back(n - sum);
        if(check(group)) ans = g_size;
        group.pop_back();
        return;
      }
      for(ll i = (group.empty() ? 1 : group.back()); i <= (n - sum) / 2; i++) {
        group.emplace_back(i);
        self(self, sum + i);
        if(ans != 7) return;
        group.pop_back();
      }
    };
    for(ll size = 1; size <= 6; size++) {
      g_size = size;
      group.clear();
      dfs(dfs, 0);
      if(ans != 7) break;
    }
    cout << ans << '\n';
  }

  return 0;
}
accuracy: 1
time_ms: 2500
memory_kb: 3396
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
#include <bit>
#include <bitset>
#include <algorithm>
const int MAXN = 101;
using bitset = std::bitset<MAXN>;
int N, BOUND;
std::string S;
bitset S_BIT;
// num: 現在の問題セットの問題数
// sum: 現在の問題セットの満点
// max: 現在の問題セットで一番点数が高い問題の点数
// dp : 実現可能な点数
int dfs(int num, int sum, int max, const bitset& dp) {
    if (num >= BOUND) return BOUND;
    if (sum == N) {
        if ((S_BIT | (S_BIT ^ dp)) == dp) {
            return num;
        }
        else {
            return BOUND;
        }
    }
    int res = BOUND;
    for (int i = max ; i <= N - sum ; i++) {
        bitset next_dp = dp | (dp << i); 
        res = std::min(res, dfs(num + 1, sum + i, i, next_dp));
    }
    return res;
}
int solve() {
    // 解は必ずBOUND以下
    BOUND = std::bit_width((unsigned)N);
    // std::bitsetのデフォルトコンストラクタは全部falseで初期化
    S_BIT = bitset{};
    for (int i = 0 ; i <= N ; i++) {
        S_BIT[i] = S[i] == 'o';
    }
    bitset start{};
    start[0] = 1;
    return dfs(0, 0, 1, start);
}
int main() {
    while (true) {
        std::cin >> N;
        if (N == 0) break;
        std::cin >> S;
        std::cout << solve() << '\n';
    }
}
accuracy: 1
time_ms: 1760
memory_kb: 3584
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <bit>
#include <bitset>
#include <algorithm>
const int MAXN = 101;
using bitset = std::bitset<MAXN>;
int N, BOUND;
std::string S;
bitset S_BIT;
// num: 現在の問題セットの問題数
// sum: 現在の問題セットの満点
// max: 現在の問題セットで一番点数が高い問題の点数
// dp : 実現可能な点数
int dfs(int num, int sum, int max, const bitset& dp) {
    if (num > BOUND) return (int)1e9;
    if (sum == N) {
        if ((S_BIT | (S_BIT ^ dp)) == dp) {
            return num;
        }
        else {
            return (int)1e9;
        }
    }
    int res = (int)1e9;
    for (int i = max ; i <= N - sum ; i++) {
        bitset next_dp = dp | (dp << i); 
        res = std::min(res, dfs(num + 1, sum + i, i, next_dp));
    }
    return res;
}
int solve() {
    // 解は必ずBOUND以下
    BOUND = std::bit_width((unsigned)N);
    // std::bitsetのデフォルトコンストラクタは全部falseで初期化
    S_BIT = bitset{};
    for (int i = 0 ; i <= N ; i++) {
        S_BIT[i] = S[i] == 'o';
    }
    bitset start{};
    start[0] = 1;
    return dfs(0, 0, 1, start);
}
int main() {
    while (true) {
        std::cin >> N;
        if (N == 0) break;
        std::cin >> S;
        std::cout << solve() << '\n';
    }
}
accuracy: 1
time_ms: 4040
memory_kb: 3584
final_rank: 11

code_snippet: #include <iostream>
#include <vector>
#include <bit>
#include <bitset>
#include <algorithm>
const int MAXN = 101;
using bitset = std::bitset<MAXN>;
int N, BOUND;
std::string S;
bitset S_BIT;
// num: 現在の問題セットの問題数
// sum: 現在の問題セットの満点
// max: 現在の問題セットで一番点数が高い問題の点数
// dp : 実現可能な点数
int dfs(int num, int sum, int max, bitset dp) {
    if (num > BOUND) return (int)1e9;
    if (sum == N) {
        if ((S_BIT | (S_BIT ^ dp)) == dp) {
            return num;
        }
        else {
            return (int)1e9;
        }
    }
    int res = (int)1e9;
    for (int i = max ; i <= N - sum ; i++) {
        bitset next_dp = dp | (dp << i); 
        res = std::min(res, dfs(num + 1, sum + i, i, next_dp));
    }
    return res;
}
int solve() {
    // 解は必ずBOUND以下
    BOUND = std::bit_width((unsigned)N);
    // std::bitsetのデフォルトコンストラクタは全部falseで初期化
    S_BIT = bitset{};
    for (int i = 0 ; i <= N ; i++) {
        S_BIT[i] = S[i] == 'o';
    }
    bitset start{};
    start[0] = 1;
    return dfs(0, 0, 1, start);
}
int main() {
    while (true) {
        std::cin >> N;
        if (N == 0) break;
        std::cin >> S;
        std::cout << solve() << '\n';
    }
}
accuracy: 1
time_ms: 4160
memory_kb: 3456
final_rank: 12

code_snippet: // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, a, b) for(long long i = (a); i < (b); i++) // [a, b)を昇順に
#define drep(i, a, b) for(long long i = (b) - 1; i >= a; i--) // [a, b)を降順に
#define all(v) v.begin(), v.end() // 昇順sortに
#define rall(v) v.rbegin(), v.rend() // 降順sortに
#define sz(x) (int)(x).size()
#define decimal(n) cout << fixed << setprecision(n);
#define debug(x) cerr << #x << " = " << x << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define yesno(condition) { if (condition) cout << "Yes" << endl; else cout << "No" << endl; }
using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>;
using ll = long long; using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>;
using lll = __int128;
// using mint = modint998244353;
const ll MOD = 998244353;
// using mint = modint;
// const ll MOD = 998244353;
// using mint = modint1000000007;
// const ll MOD = 1000000007;
// using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>;
using P = pair<ll, ll>; using T = tuple<ll, ll, ll>;
using vc = vector<char>;
const ll MAX = 5'000'009; const ll llINF = 2e18;
const int intINF = 2e9; const long double pi = acos(-1);
ll di[] = {0, -1, 0, 1, -1, -1, 1, 1};
ll dj[] = {1, 0, -1, 0, 1, -1, -1, 1};
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T, vector<T>>; //大きい順
template<class T> using pq_g = priority_queue<T, vector<T>, greater<T>>; //小さい順

bool isin(ll i, ll j, ll n, ll m) { return (0 <= i && i < n && 0 <= j && j < m); }
bool is_multipul_overflow(ll a, ll b, ll c) {
    // a * b > cかを判定する
    if (a == 0 || b == 0) return false;
    return (a <= c / b ? false : true);
}

template<class T, size_t n, size_t idx = 0>
auto make_vec(const size_t (&d)[n], const T& init) noexcept {
    if constexpr (idx < n) return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else return init;
}
template<class T, size_t n>
auto make_vec(const size_t (&d)[n]) noexcept {
    return make_vec(d, T{});
}
/**
 * Read a vector from input. Set start to 1 if you want it to be 1-indexed.
 */
template<typename T>
vector<T> read_vector(int N, int start = 0) {
    vector<T> v(start + N);
    for (int i = start; i < (int)v.size(); i++) {
        std::cin >> v[i];
    }
    return v;
}

void solve(int &n, string &s) {
    bitset<101> sbit;
    rep(i, 0, n + 1) {
        if(s[i] == 'o') {
            sbit.set(i);
        }
    }
    int maxProblemCount = 7;

    int ans = maxProblemCount;

    vector<int> scores;
    vector<int> maxscores = {n/7, n/6, n/5, n/4, n/3, n/2, n/1};
    int scoresum = 0;
    bool isfinished = false;
    function<void(ll)> dfs = [&](ll depth) -> void {
        if(depth == maxProblemCount - 1) {
            int lastscore = n - scoresum;
            if(lastscore < scores.back()) return ;

            scores.emplace_back(lastscore);

            // 判定
            bitset<101> curbit;
            curbit.set(0);
            rep(i, 0, sz(scores)) {
                bitset<101> nextbit = curbit;
                nextbit |= (curbit << scores[i]);
                swap(nextbit, curbit);
            }

            if((curbit & sbit) == sbit) {
                rep(i, 0, sz(scores)) {
                    if(scores[i] != 0) {
                        ans = maxProblemCount - i;
                        break;
                    }
                }
                isfinished = true;
            }

            scores.pop_back();
            return ;
        }

        int minscore = 0;
        if(depth > 0) minscore = scores.back();

        rep(i, minscore, maxscores[depth] + 1) {
            if(isfinished) return ;
            if(scoresum + i > n) break;
            
            scores.emplace_back(i);
            scoresum += i;

            dfs(depth + 1);

            if(isfinished) return ;
            scoresum -= i;
            scores.pop_back();
        }

    };

    dfs(0);
    cout << ans << endl;
}

int main() {
    int n;
    string s;
    while(true) {
        cin >> n;
        if(n == 0) return 0;
        cin >> s;
        solve(n, s);
    }
}
accuracy: 1
time_ms: 250
memory_kb: 3448
final_rank: 1

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T> void print(vector<T> A);

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    while (true) {
        int N;
        cin >> N;
        if (N == 0) {
            break;
        }
        string S;
        cin >> S;
        vector<int> sp;
        for (int i = 0; i < N + 1; i++) {
            if (S[i] == 'o') {
                sp.push_back(i);
            }
        }



        auto f = [&](vector<int> &ps) {
            int n = ps.size();
            bitset<101 * 7> dp;
            dp[0]=1;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 101; j++) {
                    int ind = 101 * i + j;
                    if (dp[ind] == 0) {
                        continue;
                    }

                    int nex_ind = 101 * (i + 1) + j;
                    dp[nex_ind] = 1;
                    if (j + ps[i] < 101) {
                        int nex_ind2 = 101 * (i + 1) + j + ps[i];
                        dp[nex_ind2]=1;
                    }
                }
            }
            bool ret=true;
            for (auto num : sp) {
                if (dp[101 * n + num] == 0) {
                    ret=false;
                }
            }
            
            return ret;
        };

        vector<int> lis;
        int sum=0;
        auto solve = [&](auto solve) {
            //if (lis.size())print(lis);
            int ret = 7;
            if (lis.size() == 7) {
                return ret;
            }
            if (sum == N) {
                if (f(lis)) {
                    ret=lis.size();
                }
                return ret;
            }
            if (lis.size() == 0) {
                for (int v = 1; v <= N; v++) {
                    lis.push_back(v);
                    sum += v;
                    ret=min(ret,solve(solve));
                    sum -= v;
                    lis.pop_back();
                }
            } else {
                for (int v = lis.back(); v <= N - sum; v++) {
                    lis.push_back(v);
                    sum += v;
                    ret=min(ret,solve(solve));
                    sum -= v;
                    lis.pop_back();
                }
            }
            return ret;
        };
        cout<<solve(solve)<<endl;
    }
}

template <typename T> void print(vector<T> A) {
    for (int i = 0; i < A.size() - 1; i++) {
        cout << A[i] << ' ';
    }
    cout << A[A.size() - 1] << endl;
    return;
}
accuracy: 1
time_ms: 6880
memory_kb: 3584
final_rank: 18