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

int main() {
    int n , k;
    scanf("%d %d" , &n , &k);
    vector<int> V(n);

    for(auto &x : V)
        scanf("%d" , &x);

    int num = 0;
    set<vector<int> > se;
    se.insert(vector<int>(1));
    set<int> have;
    for(int i = 0 ; i < n && num != k ; ++i) {
        for(auto it = se.begin() ; it != se.end() ; ++it) {
            if(have.find(-(*it)[0] + V[i]) == have.end()) {
                have.insert(-(*it)[0] + V[i]);
                vector<int> temp = *it;
                temp[0] -= V[i];
                temp.push_back(V[i]);
                int sz = temp.size();
                printf("%d " , sz - 1);
                for(int j = 1 ; j < sz ; ++j)
                    printf("%d " , temp[j]);
                printf("\n");
                ++num;
                se.insert(temp);
            }
        }
    }
    return 0;
}


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

int main() {
    int n , k;
    scanf("%d %d" , &n , &k);
    vector<int> V(n);

    for(auto &x : V)
        scanf("%d" , &x);

    sort(V.begin() , V.end());

    int num = 0;
    for(int i = 0 ; i < n && num != k ; ++i , ++num)
        printf("1 %d\n"  , V[i]);

    for(int i = n - 1 ; i >= 0 && num != k ; --i){
        for(int j = i - 1 ; j >= 0 && num != k ; --j , ++num) {
            printf("%d " , n - i);
            for(int l = n - 1 ; l >= i ; --l){
                printf("%d " , V[l]);
            }
            printf("%d\n" , V[j]);
        }
    }
    return 0;
}


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

int main() {
    int n , k;
    scanf("%d %d" , &n , &k);
    vector<int> V(n);

    for(auto &x : V)
        scanf("%d" , &x);

    int num = 0;
    set<vector<int> > se;
    se.insert(vector<int>(1));
    set<int> have;
    for(int i = 0 ; i < n && num != k ; ++i) {
        for(auto it = se.begin() ; it != se.end() ; ++it) {
            if(have.find(-(*it)[0] + V[i]) == have.end()) {
                have.insert(-(*it)[0] + V[i]);
                vector<int> temp = *it;
                temp[0] -= V[i];
                temp.push_back(V[i]);
                int sz = temp.size();
                printf("%d " , sz - 1);
                for(int j = 1 ; j < sz ; ++j)
                    printf("%d " , temp[j]);
                printf("\n");
                ++num;
                se.insert(temp);
            }
            if(num == k)break;
        }
    }
    return 0;
}


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

int main() {
    int n , k;
    scanf("%d %d" , &n , &k);
    vector<int> V(n);

    for(auto &x : V)
        scanf("%d" , &x);

    int num = 0;
    for(int i = 0 ; i < n && num != k ; ++i , ++num)
        printf("1 %d\n"  , V[i]);

    for(int i = n - 1 ; i >= 0 && num != k ; --i){
        for(int j = i - 1 ; j >= 0 && num != k ; --j , ++num) {
            printf("%d " , n - i);
            for(int l = n - 1 ; l >= i ; --l){
                printf("%d " , V[l]);
            }
            printf("%d\n" , V[j]);
        }
    }
    return 0;
}


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

int main() {
    int n , k;
    scanf("%d %d" , &n , &k);
    vector<int> V(n);

    for(auto &x : V)
        scanf("%d" , &x);

    int num = 0;
    vector<vector<int> > se(1 , vector<int> (1));
    set<int> have;
    for(int i = 0 ; i < n && num != k ; ++i) {
        for(int j = se.size() - 1 ; j >= 0 ; --j){
            if(have.find(se[j][0] + V[i]) == have.end()) {
                have.insert(se[j][0] + V[i]);
                vector<int> temp = se[j];
                temp[0] += V[i];
                temp.push_back(V[i]);
                int sz = temp.size();
                printf("%d " , sz - 1);
                for(int j = 1 ; j < sz ; ++j)
                    printf("%d " , temp[j]);
                printf("\n");

                se.push_back(temp);
                ++num;
            }
            if(num == k)break;
        }

        sort(se.begin() , se.end());
    }
    return 0;
}


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

int main() {
    int n , k;
    scanf("%d %d" , &n , &k);
    vector<int> V(n);

    for(auto &x : V)
        scanf("%d" , &x);

    int num = 0;
    set<vector<int> > se;
    se.insert(vector<int>(1));
    set<int> have;
    for(int i = 0 ; i < n && num != k ; ++i) {
        for(auto it = se.begin() ; it != se.end() ; ++it) {
            if(have.find(-(*it)[0] + V[i]) == have.end()) {
                have.insert(-(*it)[0] + V[i]);
                vector<int> temp = *it;
                temp[0] -= V[i];
                temp.push_back(V[i]);
                int sz = temp.size();
                printf("%d " , sz - 1);
                for(int j = 1 ; j < sz ; ++j)
                    printf("%d " , temp[j]);
                printf("\n");
                ++num;
                se.insert(temp);
            }
            if(num == k)break;
        }
    }
    return 0;
}


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

int main() {
    int n, k;
    scanf("%d %d", &n, &k);

    vector<int> a(n);

    for (auto &x : a)
        scanf("%d", &x);

    sort(a.rbegin(), a.rend());

    int last = 0;
    int use = 0;
    for (int i = 0; i < k; ++i) {
        if (use == n) {
            ++last;
            use = last;
        }
        int c = last + 1;
        printf("%d ", c);
        for (int j = 0; j < last; ++j) {
            printf("%d ", a[j]);
        }
        if (use != n) printf("%d\n", a[use]);
        ++use;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <string>
#include <limits>
#include <string.h>
#include <math.h>
#include <stack>
#include <functional>
using namespace std;
int main(){
  int n, k, a;
  vector<int> v;
  cin>>n>>k;
  for(int i = 0; i < n; ++i){
    cin>>a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  for(int i = 0; i < n && k; ++i){
    for(int j = n - 1 - i; j >= 0 && k; j--){
      cout<<i + 1<<" ";
      for(int q = n - 1; q >= n - i; q--){
	cout<<v[q]<<" ";
      }
      cout<<v[j]<<endl;
      k--;
    }
  }
  return 0;
}


#include <iostream>
#include <cstring>
#include <set>

using namespace std;

int a[50];
set<int> st;

void inc(string &s){
	int i = 0;
	s[i]++;
	for ( ; i < (int)s.length(); i++ )
		if ( s[i] == '2' ){
			s[i] = '0';
			s[i + 1]++;
		}
	return;
}

void print(string &s){
	int sum = 0;
	int ans = 0;
	for ( int i = 0; i < (int)s.length(); i++ )
		if ( s[i] == '1' ){
			++sum;
			ans += a[i];
		}
	if ( st.find(ans) != st.end() ){
		inc(s);
		print(s);
		return;
	}
	st.insert(ans);
	cout << sum << ' ';
	for ( int i = 0; i < (int)s.length(); i++ )
		if ( s[i] == '1' )
			cout << a[i] << ' ';
	cout << endl;
}

int main(){
	int n, k;
	cin >> n >> k;
	string s;
	for ( int i = 0; i < 100; i++ )
		s += '0';
	for ( int i = 0; i < n; i++ )
		cin >> a[i];

	s[0] = '1';
	for ( int i = 0; i < k; i++ ){
		print(s);
		inc(s);
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <set>

using namespace std;

int a[50];
set<int> st;

void inc(string &s){
	int i = 0;
	s[i]++;
	for ( ; i < (int)s.length(); i++ )
		if ( s[i] == '2' ){
			s[i] = '0';
			s[i + 1]++;
		}
	return;
}

void print(string &s){
	int sum = 0;
	for ( int i = 0; i < (int)s.length(); i++ )
		if ( s[i] == '1' )
			++sum;
	if ( st.find(sum) != st.end() ){
		inc(s);
		print(s);
		return;
	}
	cout << sum << ' ';
	for ( int i = 0; i < (int)s.length(); i++ )
		if ( s[i] == '1' )
			cout << a[i] << ' ';
	cout << endl;
}

int main(){
	int n, k;
	cin >> n >> k;
	string s;
	for ( int i = 0; i < 100; i++ )
		s += '0';
	for ( int i = 0; i < n; i++ )
		cin >> a[i];

	s[0] = '1';
	for ( int i = 0; i < k; i++ ){
		print(s);
		inc(s);
	}
	return 0;
}


#include <iostream>
#include <cstring>

using namespace std;

int a[50];

void inc(string &s){
	int i = 0;
	s[i]++;
	for ( ; i < (int)s.length(); i++ )
		if ( s[i] == '2' ){
			s[i] = '0';
			s[i + 1]++;
		}
	return;
}

void print(string s){
	int sum = 0;
	for ( int i = 0; i < (int)s.length(); i++ )
		if ( s[i] == '1' )
			++sum;
	cout << sum << ' ';
	for ( int i = 0; i < (int)s.length(); i++ )
		if ( s[i] == '1' )
			cout << a[i] << ' ';
	cout << endl;
}

int main(){
	int n, k;
	cin >> n >> k;
	string s;
	for ( int i = 0; i < 100; i++ )
		s += '0';
	for ( int i = 0; i < n; i++ )
		cin >> a[i];

	s[0] = '1';
	for ( int i = 0; i < k; i++ ){
		print(s);
		inc(s);
	}
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int a[50];

int main(){
	int n, k;
	cin >> n >> k;
	string s;
	for ( int i = 0; i < n; i++ )
		cin >> a[i];
	sort(a, a + n, greater<int>());

	for ( int i = 0; i < n && k; i++ ){
		for ( int j = i; j < n && k; j++ ){
			cout << i + 1 << ' ';
			for ( int q = 0; q < i; q++ )
				cout << a[q] << ' ';
			cout << a[j] << endl;
			k--;
		}
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main () {
    int n, k;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n);
    int count = 0;
    int toBePrinted[n];
    while (k != 0) {
      for (int i = n - count - 1; i >= 0; i--) {
        cout << count + 1 << " ";
        for (int j = 0; j < count; j++) {
          cout <<  toBePrinted[j] << " ";
        }
        cout <<  arr[i] << endl;
        k--;
        if (k == 0) break;
      }
      toBePrinted[count] = arr[n - count - 1];
      count++;
    }
}


#include <bits/stdc++.h>
#define endl "\n"
#define FOR(x, y, z) for (int x = (y); x < (z); ++x)
#define FORR(x, y, z) for (int x = (y); x > (z); --x)
#define GET(a, n) for (int i = 0; i < (n); ++i) cin >> a[i];
#define GETM(a, n, m) for (int i = 0; i < (n); ++i) for (int j = 0; j < m; ++j) cin >> a[i][j];
#define PRINTM(a, n, m) for (int i = 0; i < (n); ++i) { for (int j = 0; j < m; ++j) cout << a[i][j] << " ";  cout << endl; };
#define PRINT(a, n) for (int i = 0; i < (n); ++i) cout << a[i] << " ";
#define IT(a) a.begin(), a.end()
#define DEB(a) cout << #a << " = " << a << endl; cout.flush();
#define IFDEB(b, a) if (b) { cout << #a << " = " << a << endl; cout.flush(); }
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
typedef vector <vector <int>> VVI;
typedef pair <int, int> PII;
template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; FOR(i, 0, n) sum += v[i]; return sum; }
struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio;

int main()
{
    int n, k;
    cin >> n >> k;
    vector <int> v(n);
    GET(v, n);
    sort(v.rbegin(), v.rend());
    vector <vector <int>> res;
    FOR (i, 0, n) {
        FOR (j, i, n) {
            res.resize(res.size() + 1);
            FOR (l, 0, i) {
                res.back().push_back(v[l]);
            }
            res.back().push_back(v[j]);
        }
    }
    res.resize(k);
    for (auto i: res) {
        cout << i.size() << " ";
        for (auto j: i) {
            cout << j << " ";
        }
        cout << endl;
    }
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <list>
#include <bitset>
#include <cassert>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std; typedef long double ld; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const double EPS = 1e-6; char TEMPORARY_CHAR; typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; typedef complex<ld> cbase; inline void fft (vector<cbase> &a, bool invert) {int n = (int)a.size(); for (int i = 1, j = 0; i < n; ++i) {int bit = n >> 1; for (; j >= bit; bit >>= 1) j -= bit; j += bit; if (i < j) swap(a[i], a[j]);} for (int len = 2; len <= n; len <<= 1) {ld ang = 2 * PI / len * (invert ? -1 : 1); cbase wlen(cos(ang), sin(ang)); for (int i = 0; i < n; i += len) {cbase w(1); for (int j=0; j < len / 2; ++j) {cbase u = a[i + j], v = a[i + j + len / 2] * w; a[i + j] = u + v; a[i + j + len / 2] = u - v; w *= wlen;}}} if (invert) for (int i = 0; i < n; ++i) a[i] /= n;} inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(ll a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[20]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;} struct lnum {vector <int> a; int base; lnum(int num = 0, int base = 1000000000):base(base) {if (!num) a.resize(1); while(num) {a.pb(num % base); num /= base;}} inline int len() const {return a.size();} lnum & operator=(const lnum &l) {if (this != &l) {a = l.a; base = l.base;} return *this;} inline friend lnum operator+(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int ln = l.len(), rn = r.len(); int n = max(ln, rn); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = o; if (i < ln) s += l.a[i]; if (i < rn) s += r.a[i]; o = s >= base; if (o) s -= base; ret.a[i] = s;} if (o) ret.a.push_back(1); return ret;} inline friend lnum operator-(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int n = l.len(); int rn = r.len(); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = l.a[i] - o; if (i < rn) s -= r.a[i]; o = s < 0; if (o) s += base; ret.a[i] = s;} if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator*(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; if (l.len() * r.len() > 1000000) {vector<cbase> fa (l.a.begin(), l.a.end()), fb (r.a.begin(), r.a.end()); int n = 1; while (n < max (l.len(), r.len())) n <<= 1; n <<= 1; fa.resize (n), fb.resize (n); fft (fa, false), fft (fb, false); for (int i = 0; i < n; ++i) fa[i] *= fb[i]; fft (fa, true); ret.a.resize(n); for (int i = 0; i < n; ++i) ret.a[i] = int (fa[i].real() + 0.5); int carry = 0; for (int i=0; i < n; ++i) {ret.a[i] += carry; carry = ret.a[i] / base; ret.a[i] %= base;}} else {ret.a.resize(l.len() + r.len()); for (int i = 0; i < l.len(); ++i) for (int j = 0, carry = 0; j < r.len() || carry; ++j) {long long cur = ret.a[i + j] + (ll)l.a[i] * (j < r.len() ? r.a[j] : 0) + carry; ret.a[i + j] = cur % base; carry = cur / base;}} while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator/(const lnum &l, const int &r) {lnum ret(0, l.base); ret.a.resize(l.len()); int carry = 0; for(int i = l.len() - 1; i >= 0; --i) {long long cur = l.a[i] + (ll)carry * l.base; ret.a[i] = cur / r; carry = cur % r;} while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back(); return ret;}  inline friend bool operator<(const lnum &l, const lnum &r) {if (l.len() < r.len()) return true; if (l.len() > r.len()) return false; int n = l.len(); for(int i = n - 1; i >= 0; --i) {if (l.a[i] < r.a[i]) return true; if (l.a[i] > r.a[i]) return false;} return false;} inline friend bool operator>(const lnum &l, const lnum &r) {return r < l;} inline friend bool operator==(const lnum &l, const lnum &r) {if (l.len() != r.len()) return false; int n = l.len(); for(int i = n - 1; i; --i) {if (l.a[i] != r.a[i]) return false;} return true;} inline friend bool operator!=(const lnum &l, const lnum &r) {return !(l == r);} inline void print() {if (base == 1000000000) {printf("%d", a.back()); for(int i = a.size() - 2; i >=0; --i) printf("%09d", a[i]);} else {for(int i = a.size() - 1; i >= 0; --i) printf("%d", a[i]);}}};

bool cmp(const PII & a, const PII & b)
{
    return a.x < b.x;
}

bool cmp2(const PII & a, const PII & b)
{
    return a.x == b.x;
}

int main()
{
    in(n); in(k);
    vector <pair <int, int> > can[n + 1];
    can[0].pb(mp(0, 0));
    int a[n];
    forn(i, n)
    {
        a[i] = nxt();
        forn(j, can[i].size())
        {
            can[i + 1].pb(mp(can[i][j].x, 0));
            can[i + 1].pb(mp(can[i][j].x + a[i], 1));
        }
        sort(all(can[i + 1]), cmp);
        int s = min(k + 1, unique(can[i + 1].begin(), can[i + 1].end(), cmp2) - can[i + 1].begin());
        can[i + 1].resize(s);
    }
    assert(can[n].size() > k);
    For(i, 1, k)
    {
        int cur = can[n][i].x;
        vector <int> ans;
        ford(j, n)
        {
            PII t =  *lower_bound(all(can[j + 1]), mp(cur, 0), cmp);
            if (t.y)
            {
                ans.pb(a[j]);
                cur -= a[j];
            }
        }
        cout << ans.size();
        forn(i, ans.size())
            cout << " " << ans[i];
        cout << endl;
    }
    return 0;
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <list>
#include <bitset>
#include <cassert>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std; typedef long double ld; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const double EPS = 1e-6; char TEMPORARY_CHAR; typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; typedef complex<ld> cbase; inline void fft (vector<cbase> &a, bool invert) {int n = (int)a.size(); for (int i = 1, j = 0; i < n; ++i) {int bit = n >> 1; for (; j >= bit; bit >>= 1) j -= bit; j += bit; if (i < j) swap(a[i], a[j]);} for (int len = 2; len <= n; len <<= 1) {ld ang = 2 * PI / len * (invert ? -1 : 1); cbase wlen(cos(ang), sin(ang)); for (int i = 0; i < n; i += len) {cbase w(1); for (int j=0; j < len / 2; ++j) {cbase u = a[i + j], v = a[i + j + len / 2] * w; a[i + j] = u + v; a[i + j + len / 2] = u - v; w *= wlen;}}} if (invert) for (int i = 0; i < n; ++i) a[i] /= n;} inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(ll a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[20]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;} struct lnum {vector <int> a; int base; lnum(int num = 0, int base = 1000000000):base(base) {if (!num) a.resize(1); while(num) {a.pb(num % base); num /= base;}} inline int len() const {return a.size();} lnum & operator=(const lnum &l) {if (this != &l) {a = l.a; base = l.base;} return *this;} inline friend lnum operator+(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int ln = l.len(), rn = r.len(); int n = max(ln, rn); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = o; if (i < ln) s += l.a[i]; if (i < rn) s += r.a[i]; o = s >= base; if (o) s -= base; ret.a[i] = s;} if (o) ret.a.push_back(1); return ret;} inline friend lnum operator-(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int n = l.len(); int rn = r.len(); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = l.a[i] - o; if (i < rn) s -= r.a[i]; o = s < 0; if (o) s += base; ret.a[i] = s;} if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator*(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; if (l.len() * r.len() > 1000000) {vector<cbase> fa (l.a.begin(), l.a.end()), fb (r.a.begin(), r.a.end()); int n = 1; while (n < max (l.len(), r.len())) n <<= 1; n <<= 1; fa.resize (n), fb.resize (n); fft (fa, false), fft (fb, false); for (int i = 0; i < n; ++i) fa[i] *= fb[i]; fft (fa, true); ret.a.resize(n); for (int i = 0; i < n; ++i) ret.a[i] = int (fa[i].real() + 0.5); int carry = 0; for (int i=0; i < n; ++i) {ret.a[i] += carry; carry = ret.a[i] / base; ret.a[i] %= base;}} else {ret.a.resize(l.len() + r.len()); for (int i = 0; i < l.len(); ++i) for (int j = 0, carry = 0; j < r.len() || carry; ++j) {long long cur = ret.a[i + j] + (ll)l.a[i] * (j < r.len() ? r.a[j] : 0) + carry; ret.a[i + j] = cur % base; carry = cur / base;}} while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator/(const lnum &l, const int &r) {lnum ret(0, l.base); ret.a.resize(l.len()); int carry = 0; for(int i = l.len() - 1; i >= 0; --i) {long long cur = l.a[i] + (ll)carry * l.base; ret.a[i] = cur / r; carry = cur % r;} while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back(); return ret;}  inline friend bool operator<(const lnum &l, const lnum &r) {if (l.len() < r.len()) return true; if (l.len() > r.len()) return false; int n = l.len(); for(int i = n - 1; i >= 0; --i) {if (l.a[i] < r.a[i]) return true; if (l.a[i] > r.a[i]) return false;} return false;} inline friend bool operator>(const lnum &l, const lnum &r) {return r < l;} inline friend bool operator==(const lnum &l, const lnum &r) {if (l.len() != r.len()) return false; int n = l.len(); for(int i = n - 1; i; --i) {if (l.a[i] != r.a[i]) return false;} return true;} inline friend bool operator!=(const lnum &l, const lnum &r) {return !(l == r);} inline void print() {if (base == 1000000000) {printf("%d", a.back()); for(int i = a.size() - 2; i >=0; --i) printf("%09d", a[i]);} else {for(int i = a.size() - 1; i >= 0; --i) printf("%d", a[i]);}}};

bool cmp(const PII & a, const PII & b)
{
    return a.x < b.x;
}

bool cmp2(const PII & a, const PII & b)
{
    return a.x == b.x;
}

int main()
{
    in(n); in(k);
    vector <pair <int, int> > can[n + 1];
    can[0].pb(mp(0, 0));
    int a[n];
    forn(i, n)
    {
        a[i] = nxt();
        forn(j, can[i].size())
        {
            can[i + 1].pb(mp(can[i][j].x, 0));
            can[i + 1].pb(mp(can[i][j].x + a[i], 1));
        }
        sort(all(can[i + 1]), cmp);
        int s = unique(can[i + 1].begin(), can[i + 1].end(), cmp2) - can[i + 1].begin();
        can[i + 1].resize(s);
    }
    assert(can[n].size() > k);
    For(i, 1, k)
    {
        int cur = can[n][i].x;
        vector <int> ans;
        ford(j, n)
        {
            PII t =  *lower_bound(all(can[j + 1]), mp(cur, 0), cmp);
            if (t.y)
            {
                ans.pb(a[j]);
                cur -= a[j];
            }
        }
        cout << ans.size();
        forn(i, ans.size())
            cout << " " << ans[i];
        cout << endl;
    }
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <ctime>
#include <climits>
#include <iomanip>
#include <sstream>
using namespace std;

typedef long long LL;
#define tr(container, it)for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = (a); i < (int)(b); i++)

int GCD (int a, int b) { if (!a) return b; return GCD(b%a, a);}

vector<int> cur;
vector<int> a;
int n, k;
set<int> taken;

void go(int at, int sum, vector<vector<int>>&ans) {
    //cout<<at<<" "<<sum<<" "<<ans.size()<<"\n";
    if (taken.find(sum) == taken.end()) {
        taken.insert(sum);
        ans.PB(cur);
    }
    if (at >= n) return;
    if (ans.size() >= k) return;
    go(at+1, sum, ans);
    cur.PB(a[at]);
    go(at+1, sum+a[at], ans);
    cur.pop_back();
}

int main() {
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);

    cin>>n>>k;
    vector<vector<int>>ans;
    REP(i, 0, n) {
        int z; cin>>z; a.PB(z);
        taken.insert(z);
        ans.PB({z});
    }
    REP(i, 0, n) {
        REP(j, i+1, n) {
            int sum = 0;
            REP(k, i, j+1) sum += a[k];
            if (taken.find(sum) == taken.end()) {
                taken.insert(sum);
                vector<int> cur;
                REP(k, i, j+1) cur.PB(a[k]);
                ans.PB(cur);
            }
        }
    }
    REP(i, 0, n) {
        cur.clear();
        cur.PB(a[i]);
        go(i+1, a[i], ans);
    }

    REP(i, 0, k) {
        cout<<ans[i].size()<<" ";
        REP(j, 0, ans[i].size()) cout<<ans[i][j]<<" ";
        cout<<"\n";
    }

    clock_t endTime = clock();
    cerr<<"\nTime:"<< double(endTime - startTime) / CLOCKS_PER_SEC <<" seconds\n" ;
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <ctime>
#include <climits>
#include <iomanip>
#include <sstream>
using namespace std;

typedef long long LL;
#define tr(container, it)for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = (a); i < (int)(b); i++)

int GCD (int a, int b) { if (!a) return b; return GCD(b%a, a);}

vector<int> cur;
vector<int> a;
int n, k;
set<int> taken;

void go(int at, int sum, vector<vector<int>>&ans) {
    //cout<<at<<" "<<sum<<" "<<ans.size()<<"\n";
    if (sum > 0 && taken.find(sum) == taken.end()) {
        taken.insert(sum);
        ans.PB(cur);
    }
    if (at >= n) return;
    if (ans.size() >= k) return;
    go(at+1, sum, ans);
    cur.PB(a[at]);
    go(at+1, sum+a[at], ans);
    cur.pop_back();
}

int main() {
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);

    cin>>n>>k;
    vector<vector<int>>ans;
    REP(i, 0, n) {
        int z; cin>>z; a.PB(z);
        taken.insert(z);
        ans.PB({z});
    }
    int c = 0;
    REP(r, 0, 1000000) {
        random_shuffle(a.begin(), a.end());
        if (ans.size() >= k) break;
        REP(i, 0, n) {
            REP(j, i+1, n) {
                c++;
                int sum = 0;
                REP(k, i, j+1) sum += a[k];
                if (taken.find(sum) == taken.end()) {
                    taken.insert(sum);
                    vector<int> cur;
                    REP(k, i, j+1) cur.PB(a[k]);
                    ans.PB(cur);
                }
            }
        }
    }
    cur.reserve(n+1);
    sort(a.begin(), a.end());//, greater<int>());
    //cout<<ans.size()<<" "<<k<<" "<<c+n<<endl;
    //return 0;
    //go(0, 0, ans);

    REP(i, 0, k) {
        cout<<ans[i].size()<<" ";
        REP(j, 0, ans[i].size()) cout<<ans[i][j]<<" ";
        cout<<"\n";
    }

    clock_t endTime = clock();
    cerr<<"\nTime:"<< double(endTime - startTime) / CLOCKS_PER_SEC <<" seconds\n" ;
    return 0;
}


//In the name of ALLAH
//Beauty Pageant

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

const int N=50+5;

int a[N],cnt=0;
vector<int> ans[N*N];

inline void solve(int t){
    if (!t) ans[cnt++].push_back(a[t]);
    else{
        for (int i=0;i<=t;i++) ans[cnt].push_back(a[i]);
        cnt++;
        for (int j=0;j<t;j++,cnt++)
            for (int i=0;i<=t;i++)
                if (i!=j)
                    ans[cnt].push_back(a[i]);
    }
}

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for (int i=0;i<n;i++)
        scanf("%d",a+i);

    sort(a,a+n);
    for (int i=0;cnt<k;i++)
        solve(i);
    for (int i=0;i<k;i++){
        printf("%d ",(int)ans[i].size());
        for (int j=0;j<(int)ans[i].size();j++)
            printf("%d ",ans[i][j]);
        printf("\n");
    }

    return 0;
}


/*
    let k>n

    - print all the num once since all are distinct
    - print 1max+ any other one
    - print 2man+ any other one

    stop when reach k

*/

#include <bits/stdc++.h>

#define l(i,n) for(int i=0;i<n;i++)

#define pii pair<int,int>
#define DB()    cout<<"I'm in!"<<endl

typedef long long LL;

using namespace std;

int main(){
std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    int a[n];
    l(i,n) cin>>a[i];

    sort(a,a+n);
    reverse(a,a+n);

    vector<int> L;
    l(i,n){
        for(int j=i;j<n;j++ ){
            if(k==0) break;
            cout<<i+1<<" ";
            l(p,L.size()) cout<<" "<<a[L[p]];
            cout<<" "<<a[j]<<endl;

            k--;
        }
        L.push_back(i);
    }

return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define FOREQ(i,k,n) for(int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); ++i)
#define SZ(v) (int)((v).size())
#define MEMSET(v,h) memset((v),(h),sizeof(v))

struct P {
  int s;
  int a;
  int n;
  set<P>::iterator i;

  bool operator<(P const &p) const {
    return s < p.s;
  }
};

int main() {
  int n, k; cin >> n >> k;
  int a[55] = {0};

  REP(i, n) cin >> a[i];
  sort(a, a+n);

  set<P> s;
  s.insert((P){ 0, 0, 0, s.end() });

  REP(i, n) {
    set<P> q = s;
    FORIT(it, q) {
      s.insert((P){ it->s + a[i], a[i], it->n+1, s.find(*it) });
    }
    if(SZ(s) >= k+1) break;
  }

  FORIT(it, s) {
    if(it->n != 0) {
      cout << it->n;
      for(auto jt = it; jt->n; jt = jt->i) {
        cout << ' ' << jt->a;
      }
      cout << endl;
    }
  }
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define FOREQ(i,k,n) for(int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); ++i)
#define SZ(v) (int)((v).size())
#define MEMSET(v,h) memset((v),(h),sizeof(v))

struct P {
  int s;
  int a;
  int n;
  set<P>::iterator i;

  bool operator<(P const &p) const {
    return s < p.s;
  }
};

int main() {
  int n, k; cin >> n >> k;
  int a[55] = {0};

  REP(i, n) cin >> a[i];
  sort(a, a+n);

  set<P> s;
  s.insert((P){ 0, 0, 0, s.end() });

  REP(i, n) {
    set<P> q = s;
    FORIT(it, q) {
      s.insert((P){ it->s + a[i], a[i], it->n+1, s.find(*it) });
    }
    if(SZ(s) >= k+1) break;
  }

  int cnt = 0;
  FORIT(it, s) {
    if(it->n) {
      cout << it->n;
      for(auto jt = it; jt->n; jt = jt->i) {
        cout << ' ' << jt->a;
      }
      cout << endl;
      if(++cnt == k) break;
    }
  }
}


//Name         : Shinchan Nohara
//Age          : 5 years
//Organisation : Kasukabe Defense Force

#include <iostream>
#include <ctime>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cassert>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <iterator>
#include <fstream>
using namespace std;

typedef long long 		int64;
typedef vector<int> 		vi;
typedef string 			ST;
typedef stringstream 		SS;
typedef vector< vector<int> > 	vvi;
typedef pair<int,int> 		ii;
typedef vector<string> 		vs;
/*
#if __cplusplus > 199711L	// for g++0x, value of __cplusplus must be greater thana 199711L.
	#define tr(i, c)	for(auto i = begin(c); i != end(c); i++)
#else
	#define tr(i, c)	for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#endif
*/
#define DEBUG(x)	cout << #x << " = " << x << "\n"
#define endl		("\n")
#define tr(i, c)	for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define PI		M_PI
#define E 		M_E
#define	ep		1e-9

#define	Sf		scanf
#define	Pf		printf

#define forn(i, n)	for(int i = 0, lets_stop_here = (int)n; i <  lets_stop_here; i++)
#define forab(i, a, b)	for(int i = a, lets_stop_here = (int)b; i <= lets_stop_here; i++)
#define rep(i, a, b)	for(int i = a, lets_stop_here = (int)b; i >= lets_stop_here; i--)

#define	all(c)		(c).begin(), (c).end()
#define	CL(a, b)	memset(a, b, sizeof(a))
#define mp		make_pair
#define pb		push_back

#define	present(x, c)	((c).find(x) != (c).end())	//map & set//
#define	cpresent(x, c)	(find( (c).begin(), (c).end(), x) != (c).end())	//vector & list//

#define read(n)		scanf("%d", &n)
#define write(n)	printf("%d ", n)
#define writeln(n)	printf("%d\n", n)
/*
#ifdef DEBUG
	#undef DEBUG
#endif
#define DEBUG
*/

int main()
{
	int N, K;
	cin >> N >> K;
	vi arr(N);
	forn(i, N)
		cin >> arr[i];

	map <int, int> par;
	par[0] = 0;

	for(auto x : arr) {
		map <int, int> tmp;
		for(auto it =  par.rbegin(); it != par.rend(); it++)
			tmp[it->first + x] = x;
		tr(it, tmp)
			if(par.find(it->first) == par.end())
				par[it->first] = it->second;

		if(par.size() > K+2)
			break;
	}
/*
	tr(it, par)
		cout << it->first << " " << it->second << endl;
	cout << endl;
*/
	auto it = par.begin();
	it++;

	forn(i, K) {
		assert(it != par.end());
	//	cout << "printing path for " << it->first << ": ";
		vi tmp;
		int v = it->first;
		while(v != 0) {
			tmp.pb(par[v]);
			v -= par[v];
		}

		cout << tmp.size() << " ";
		tr(it, tmp)
			write(*it);
		cout << endl;
		it++;
	}

	return 0;
}


//Name         : Shinchan Nohara
//Age          : 5 years
//Organisation : Kasukabe Defense Force

#include <iostream>
#include <ctime>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cassert>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <iterator>
#include <fstream>
using namespace std;

typedef long long 		int64;
typedef vector<int> 		vi;
typedef string 			ST;
typedef stringstream 		SS;
typedef vector< vector<int> > 	vvi;
typedef pair<int,int> 		ii;
typedef vector<string> 		vs;
/*
#if __cplusplus > 199711L	// for g++0x, value of __cplusplus must be greater thana 199711L.
	#define tr(i, c)	for(auto i = begin(c); i != end(c); i++)
#else
	#define tr(i, c)	for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#endif
*/
#define DEBUG(x)	cout << #x << " = " << x << "\n"
#define endl		("\n")
#define tr(i, c)	for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define PI		M_PI
#define E 		M_E
#define	ep		1e-9

#define	Sf		scanf
#define	Pf		printf

#define forn(i, n)	for(int i = 0, lets_stop_here = (int)n; i <  lets_stop_here; i++)
#define forab(i, a, b)	for(int i = a, lets_stop_here = (int)b; i <= lets_stop_here; i++)
#define rep(i, a, b)	for(int i = a, lets_stop_here = (int)b; i >= lets_stop_here; i--)

#define	all(c)		(c).begin(), (c).end()
#define	CL(a, b)	memset(a, b, sizeof(a))
#define mp		make_pair
#define pb		push_back

#define	present(x, c)	((c).find(x) != (c).end())	//map & set//
#define	cpresent(x, c)	(find( (c).begin(), (c).end(), x) != (c).end())	//vector & list//

#define read(n)		scanf("%d", &n)
#define write(n)	printf("%d ", n)
#define writeln(n)	printf("%d\n", n)
/*
#ifdef DEBUG
	#undef DEBUG
#endif
#define DEBUG
*/

int main()
{
	int N, K;
	cin >> N >> K;
	vi arr(N);
	forn(i, N)
		cin >> arr[i];

	map <int, int> par;
	par[0] = 0;

	for(auto x : arr) {
		for(auto it = par.rbegin(); it != par.rend() && par.size() < K+10; it++)
			par[it->first + x] = x;
	}
/*
	tr(it, par)
		cout << it->first << " " << it->second << endl;
	cout << endl;
*/
	auto it = par.begin();
	it++;

	forn(i, K) {
//		cout << "printing path for " << it->first << ": ";
		vi tmp;
		int v = it->first;
		while(v != 0) {
			tmp.pb(par[v]);
			v -= par[v];
		}

		cout << tmp.size() << " ";
		tr(it, tmp)
			write(*it);
		cout << endl;
		it++;
	}

	return 0;
}


//Name         : Shinchan Nohara
//Age          : 5 years
//Organisation : Kasukabe Defense Force

#include <iostream>
#include <ctime>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cassert>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <iterator>
#include <fstream>
using namespace std;

typedef long long 		int64;
typedef vector<int> 		vi;
typedef string 			ST;
typedef stringstream 		SS;
typedef vector< vector<int> > 	vvi;
typedef pair<int,int> 		ii;
typedef vector<string> 		vs;
/*
#if __cplusplus > 199711L	// for g++0x, value of __cplusplus must be greater thana 199711L.
	#define tr(i, c)	for(auto i = begin(c); i != end(c); i++)
#else
	#define tr(i, c)	for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#endif
*/
#define DEBUG(x)	cout << #x << " = " << x << "\n"
#define endl		("\n")
#define tr(i, c)	for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define PI		M_PI
#define E 		M_E
#define	ep		1e-9

#define	Sf		scanf
#define	Pf		printf

#define forn(i, n)	for(int i = 0, lets_stop_here = (int)n; i <  lets_stop_here; i++)
#define forab(i, a, b)	for(int i = a, lets_stop_here = (int)b; i <= lets_stop_here; i++)
#define rep(i, a, b)	for(int i = a, lets_stop_here = (int)b; i >= lets_stop_here; i--)

#define	all(c)		(c).begin(), (c).end()
#define	CL(a, b)	memset(a, b, sizeof(a))
#define mp		make_pair
#define pb		push_back

#define	present(x, c)	((c).find(x) != (c).end())	//map & set//
#define	cpresent(x, c)	(find( (c).begin(), (c).end(), x) != (c).end())	//vector & list//

#define read(n)		scanf("%d", &n)
#define write(n)	printf("%d ", n)
#define writeln(n)	printf("%d\n", n)
/*
#ifdef DEBUG
	#undef DEBUG
#endif
#define DEBUG
*/

void printPath( map <int, int> &par, int v) {
	while(par[v] != 0) {
		write(v);
		v = par[v];
	}
	cout << endl;
}

int main()
{
	int N, K;
	cin >> N >> K;
	vi arr(N);
	forn(i, N)
		cin >> arr[i];

	map <int, int> par;
	par[0] = 0;

	for(auto x : arr) {
		for(auto it = par.rbegin(); it != par.rend() && par.size() < K+10; it++)
			par[it->first + x] = x;
	}
/*
	tr(it, par)
		cout << it->first << " " << it->second << endl;
	cout << endl;
*/
	auto it = par.rbegin();

	forn(i, K) {
//		cout << "printing path for " << it->first << ": ";
		vi tmp;
		int v = it->first;
		while(v != 0) {
			tmp.pb(par[v]);
			v -= par[v];
		}
		cout << tmp.size() << " ";
		tr(it, tmp)
			write(*it);
		cout << endl;
//		printPath(m, it->first);
		it++;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REV(i,b,a) for(int i=(a);i>=(b);i--)
#define mp make_pair
#define pb push_back
#define oo (1<<30)
#define sz(v) (int)v.size()
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define mem(s,v) memset(s,v,sizeof(s))
#define ppc(x) __builtin_popcount((x))
#define iter(it,s) for(__typeof(s.begin())it = s.begin();it!=s.end();it++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

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

int arr[55], n, k;

vector<vi> res;
map <pi, bool> vis;
map <int, bool> found;

void bfs () {
  queue <pair<pi, vi> >q;
  FOR (i , 0 , n)
    q.push(mp(mp(i, arr[i]), vi (1, arr[i]))), vis[mp(i, arr[i])] = 1;
  while (sz(q)) {
    int idx = q.front().first.first, cnt = q.front().first.second;
    vi v = q.front().second;
    q.pop();
    if (!found[cnt]) {
      res.pb(v);
      found[cnt] = 1;
      if (sz(res) == k)
        break;
    }
    if (idx + 1 < n && !vis.count(mp(cnt + arr[idx + 1],idx + 1)))
      v.pb(arr[idx + 1]), q.push(mp(mp(idx + 1, cnt + arr[idx + 1]), v)), v.pop_back(), vis[mp(cnt + arr[idx + 1], idx + 1)] = 1;
    if (idx + 1 < n && !vis.count(mp(cnt,idx + 1)))
      q.push(mp(mp(idx + 1, cnt), v)), vis[mp(cnt, idx + 1)] = 1;
  }
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("test.in", "rt", stdin);
//	freopen("o.txt", "wt", stdout);
#endif
	cin >> n >> k;
	FOR (i , 0 , n)
	  cin >> arr[i];
	sort (arr, arr + n);
	bfs();
	FOR (i , 0 , sz(res)) {
	  cout << sz(res[i]);
	  FOR (j , 0 , sz(res[i]))
	      cout << " " << res[i][j];
	  cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REV(i,b,a) for(int i=(a);i>=(b);i--)
#define mp make_pair
#define pb push_back
#define oo (1<<30)
#define sz(v) (int)v.size()
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define mem(s,v) memset(s,v,sizeof(s))
#define ppc(x) __builtin_popcount((x))
#define iter(it,s) for(__typeof(s.begin())it = s.begin();it!=s.end();it++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

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

int arr[55], n, k;

vector<vi> res;
bool vis[2505][55], found[2505];

void bfs () {
  queue <pair<pi, vi> >q;
  FOR (i , 0 , n)
    q.push(mp(mp(i, arr[i]), vi (1, arr[i]))), vis[i][arr[i]] = 1;
  while (sz(q)) {
    int idx = q.front().first.first, cnt = q.front().first.second;
    vi v = q.front().second;
    q.pop();
    if (!found[cnt]) {
      res.pb(v);
      found[cnt] = 1;
      if (sz(res) == k)
        break;
    }
    if (idx + 1 < n && !vis[cnt + arr[idx + 1]][idx + 1])
      v.pb(arr[idx + 1]), q.push(mp(mp(idx + 1, cnt + arr[idx + 1]), v)), v.pop_back(), vis[cnt + arr[idx + 1]][idx + 1] = 1;
    if (idx + 1 < n && !vis[cnt][idx + 1])
      q.push(mp(mp(idx + 1, cnt), v)), vis[cnt][idx + 1] = 1;
  }
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("test.in", "rt", stdin);
//	freopen("o.txt", "wt", stdout);
#endif
	cin >> n >> k;
	FOR (i , 0 , n)
	  cin >> arr[i];
	sort (arr, arr + n);
	bfs();
	FOR (i , 0 , sz(res)) {
	  cout << sz(res[i]);
	  FOR (j , 0 , sz(res[i]))
	      cout << " " << res[i][j];
	  cout << endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N,K;
int as[51];
set<ll> used;
int main(){

  cin>>N>>K;
  for(int i=0;i<N;i++)cin>>as[i];
  sort(as,as+N,greater<int>());
  for(int i=0;i<N;i++){
    K--;
    cout<<1<<" "<<as[i]<<endl;
    if(K==0)break;
  }
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(K==0)break;
      cout<<2<<" "<<as[i]<<" "<<as[j]<<endl;
      K--;
    }
    if(K==0)break;
  }

  return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N,K;
int as[51];
set<ll> used;
int main(){

  cin>>N>>K;
  for(int i=0;i<N;i++)cin>>as[i];
  for(ll mask=1;;mask++){
    ll sum=0;
    for(int i=0;i<N;i++){
      if((mask>>i)&1)sum+=as[i];
    }
    if(used.count(sum)==0){
      used.insert(sum);
      K--;
      vector<int> v;
      for(int i=0;i<N;i++){
        if((mask>>i)&1)v.push_back(i);
      }
      cout<<v.size()<<" ";
      for(int i=0;i<(int)v.size();i++){
        cout<<as[v[i]];
        if(i==(int)v.size()-1)cout<<endl;
        else cout<<" ";
      }
    }
    if(K==0)break;
  }

  return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N,K;
int as[51];
set<ll> used;
int main(){

  cin>>N>>K;
  for(int i=0;i<N;i++)cin>>as[i];
  sort(as,as+N,greater<int>());
  vector<int> cand;
  for(int i=0;i<N;i++){
    for(int j=i;j<N;j++){
      if(K>0){
        vector<int> v=cand;
        v.push_back(as[j]);
        cout<<v.size();
        for(int k=0;k<(int)v.size();k++)
          cout<<" "<<v[k];
        cout<<endl;
        K--;
      }
    }
    cand.push_back(as[i]);
  }

  return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N,K;
int as[51];
set<ll> used;
int main(){

  cin>>N>>K;
  for(int i=0;i<N;i++)cin>>as[i];
  sort(as,as+N,greater<int>());
  for(int i=0;i<N;i++){
    K--;
    cout<<1<<" "<<as[i]<<endl;
    if(K==0)break;
  }
  for(int i=1;i<N;i++){
      if(K==0)break;
      cout<<2<<" "<<as[0]<<" "<<as[i]<<endl;
      K--;
      if(K==0)break;
  }

  return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N,K;
int as[51];
set<ll> used;
int main(){

  cin>>N>>K;
  for(int i=0;i<N;i++)cin>>as[i];
  sort(as,as+N,greater<int>());
  for(int i=0;i<N;i++){
    K--;
    cout<<1<<" "<<as[i]<<endl;
    if(K==0)break;
  }
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(K==0)break;
      cout<<2<<" "<<as[i]<<" "<<as[j]<<endl;
    }
    if(K==0)break;
  }

  return 0;
}


#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <fstream>
#include <queue>
using namespace std;

void solve(istream &in, ostream &out) {
	int n, k;
	in >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		in >> a[i];
	sort(a.begin(), a.end());

	for (int i = 0; i < n; i++) {
		if (k--)
			out << 1 << ' ' << a[i] << endl;
	}
}

int main() {
	solve(cin, cout);
	return 0;
}


#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

void solve(istream &in, ostream &out)
{
	int n, k;
	in >> n >> k;
	int a[n];
	for (int i = 0; i < n; ++i)
		in >> a[i];

	sort(a, a + n);

	int c = 0;

	for (int j = 0; j < n; ++j) {
		for (int i = 0; i < n - j; ++i) {
			out << j + 1 << " " << a[i];
			for (int l = 0; l < j; ++l)
				out << " " << a[n - 1 - l];
			out << endl;
			if (++c == k)
				return;
		}
	}
}

int main() {
	solve(cin, cout);
	return 0;
}


# include <bits/stdc++.h>

using namespace std;

string s;
int ans;

int main() {
    cin >> s;
    for(int i = 0;i < s.size();i++) {
        int k = 0, cnt = 0;
        for(int j = i;j < s.size();j++) {
            if(s[j] == '(') {
                k++;
            }
            if(s[j] == ')') {
                k--;
            }
            if(s[j] == '?') {
                k--;
                cnt++;
            }
            if(k < 0) {
                if(cnt > 0) {
                    cnt--;
                    k++;
                    k++;
                } else {
                    break;
                }
            }
            if(k == 0) {
                ans++;
            }
        }
    }
    cout << ans;
}


# include <bits/stdc++.h>

using namespace std;

# define ll long long

const ll N = 1e5 + 10;
const ll mod = 1e9 + 7;

string s;
ll cnt, ans, us[5010][5010];

int main() {
    cin >> s;
    for(int i = 0;i < s.size();i++) {
        deque <char> dk, dq;
        cnt = 0;
        ll k = 0;
        for(int j = i;j < s.size();j++) {
            if(s[j] == '(') {
                dk.push_back(s[j]);
                dq.push_back(s[j]);
            }
            else {
                if(s[j] == ')') {
                    if(dq.size() == 0) {
                        dq.push_back(s[j]);
                    } else {
                        if(dq.back() == '(') {
                            dq.pop_back();
                            if(dq.size() == 0 && us[i][j] == 0 && k % 2 == 0) {
                                ans++;
                                us[i][j] = 1;
                            }
                        }
                    }
                    if(dk.size() == 0) {
                        if(cnt > 0) {
                            cnt--;
                            if(cnt % 2 == 0 && us[i][j] == 0) {
                                ans++;
                                us[i][j] = 1;
                            }
                        } else {
                            dk.push_back(s[j]);
                        }
                    } else {
                        if(dk.back() == '(') {
                            dk.pop_back();
                        } else {
                            if(cnt > 0) {
                                cnt--;
                            } else {
                                dk.push_back(s[j]);
                            }
                        }
                    }
                }
                if(s[j] == '?') {
                    cnt++;
                    k++;
                    if(dq.size() > 0) {
                        if(dq.back() == '(') {
                            dq.pop_back();
                            k--;
                        }
                    }
                    if(dq.size() == 0 && us[i][j] == 0 && k % 2 == 0) {
                        us[i][j] = 1;
                        ans++;
                    }
                }
            }
            if(cnt % 2 == 0 && dk.size() == 0 && us[i][j] == 0) {
                ans++;
                us[i][j] = 1;
            }
        }
        dk.clear();
        dq.clear();
        cnt = 0;
        for(int j = i;j < s.size();j++) {
            if(s[j] == '(') dk.push_back(s[j]);
            else {
                if(s[j] == ')') {
                    if(dk.size() == 0) {
                        if(cnt > 0) {
                            cnt--;
                            if(cnt % 2 == 0 && us[i][j] == 0) {
                                ans++;
                                us[i][j] = 1;
                            }
                        } else {
                            dk.push_back(s[j]);
                        }
                    } else {
                        if(dk.back() == '(') {
                            dk.pop_back();
                            if(us[i][j] == 0 && dk.size() == 0 && cnt % 2 == 0) {
                                ans++;
                                us[i][j] = 1;
                            }
                        } else {
                            if(cnt > 0) {
                                cnt--;
                            } else {
                                dk.push_back(s[j]);
                            }
                        }
                    }
                }
                if(s[j] == '?') {
                    if(dk.size() > 0) {
                        if(dk.back() == '(') {
                            dk.pop_back();
                        }
                        if(dk.size() == 0 && us[i][j] == 0 && cnt % 2 == 0) {
                            ans++;
                            us[i][j] = 1;
                        }
                    } else {
                        cnt++;
                    }
                }
            }
            if(dk.size() == 0 && cnt % 2 == 0 && us[i][j] == 0) {
                us[i][j] = 1;
                ans++;
            }
        }
        dk.clear();
    }
  //  for(int i = 0;i < s.size();i++) {
  //      for(int j = i;j < s.size();j++) {
  //          cout << i << " " << j << " " << us[i][j] << '\n';
  //      }
  //  }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b-1;i>=a;i--)

char s[5010];
int fu[5010][5010];

int main(){

	int j, i, k, n, m = 0;

	cin >> s;
	n=strlen(s);

	int ans = 0;

	FOR(i, 0, n){
		m = 0;
		FOR(j, i, n){
			if(s[j] != ')') m++;
			else m--;
			if(m < 0){
				FOR(k, j, n) fu[i][k] = -1;
				break;
			}
			fu[i][j] = m;
		}
	}

	RFOR(i, 0, n){
		m = 0;
		RFOR(j, 0, i + 1){
			if(s[j] != '(') m++;
			else m--;
			if(m < 0)break;
			if(fu[j][i] < 0) continue;
			if(fu[j][i] % 2 == 0){
				ans++;
			}
		}
	}

	cout<<ans<<endl;

	return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

///ok.

int main()
{
    string s;
    int len;

    cin>>s;
    len=s.length();

    int rez=0;
    int pot;
    int balanss;

    for(int i=0; i<len-1; ++i){
        if(s[i]==')')continue;

        balanss=1;
        pot=0;

        for(int j=i+1; j<len; ++j){
            if(s[j]=='(')++balanss;
            else if(s[j]==')'){
                --balanss;
                if(balanss==-1){
                    if(pot>0){
                        --pot;
                        balanss=1;
                    }
                    else break;
                }
            }
            else{
                if(balanss==0)balanss=1;
                else{
                    --balanss;
                    ++pot;
                }
            }
            if(balanss==0)++rez;
        }
    }

    cout<<rez<<endl;

    return 0;
}//main


#include <iostream>
#include <cstring>

using namespace std;

//parbaudit vai OK???
//nav ok laika limits!!

int main()
{
    string s;
    int len;

    cin>>s;
    len=s.length();

    int rez=0;
    int atv,aizv;
    int pot_atv, pot_aizv;
    int jaut_sk;
    int st;
    int atv2,aizv2;

    for(int i=0; i<len-1; ++i){
        if(s[i]==')')continue;

        s[i]='(';
        atv=0;
        aizv=0;
        pot_atv=0;
        pot_aizv=0;
        jaut_sk=0;

        for(int j=i; j<len; ++j){
            if(s[j]=='(')++atv;
            else if(s[j]==')')++aizv;
            else{
                ++jaut_sk;
                if(atv-aizv+pot_atv>0)++pot_aizv;
                ++pot_atv;
            }
            st=atv-aizv;
            if(st+pot_atv<0)break;

            aizv2=(st+jaut_sk)/2;
            if((st+jaut_sk)&1)++aizv2;

            atv2=jaut_sk-aizv2;
            if(atv2>=0 && atv2<=pot_atv && aizv2<=pot_aizv && aizv2-atv2==st){
                ++rez;
            }
        }
    }

    cout<<rez<<endl;

    return 0;
}//main


#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    string s;
    int len;

    cin>>s;
    len=s.length();

    int rez=0;
    int pot;
    int balanss;

    for(int i=0; i<len-1; ++i){
        if(s[i]==')')continue;

        balanss=1;
        pot=0;

        for(int j=i+1; j<len; ++j){
            if(s[j]=='(')++balanss;
            else if(s[j]==')'){
                --balanss;
                if(balanss==-1){
                    if(pot>0){
                        --pot;
                        balanss=1;
                    }
                    else break;
                }
            }
            else{
                if(balanss==0)balanss=1;
                else{
                    --balanss;
                    ++pot;
                }
            }
            if(balanss==0)++rez;
        }
    }

    cout<<rez<<endl;

    return 0;
}//main


/*
 		Resilience is the greatest of all virtues.
 		Code by rajiv
 */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define CASET  int t;cin>>t;while(t--)
 #define FORN(i,x,y) for(int i=x;i<y;i++)
 #define MAXN 100005
 #define INF 10000000010
 #define MOD 1000000007
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD
 #define PI 3.141592653589793

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef vector<VPII > VVPII ;
 const int N = 5050 ;

 int qm[N] ;
 int ans[N][N] ;
 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;
    string s ; cin >> s ;
    int n = s.size() ;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int minopen = 0 ; int maxopen = 0 ;
        if (s[i]==')') continue ;
        for(int j = i ; j < n ; j++){
            if (s[j]=='('){
                minopen++ ; maxopen++ ;
            }
            if (s[j]==')'){
                minopen-- ; maxopen-- ;
                if (maxopen < 0) break ;
                minopen = max(minopen,0) ;
            }
            if (s[j]=='?'){
                minopen-- ; maxopen++ ;
                if (minopen < 0) minopen = 0 ;
            }
            if ((j-i)%2==1 && minopen<=0 && maxopen>=0){
                ans++ ;
            }
        }
    }
    cout << ans << el ;

 }


/*
 		Resilience is the greatest of all virtues.
 		Code by rajiv
 */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define CASET  int t;cin>>t;while(t--)
 #define FORN(i,x,y) for(int i=x;i<y;i++)
 #define MAXN 100005
 #define INF 10000000010
 #define MOD 1000000007
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD
 #define PI 3.141592653589793

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef vector<VPII > VVPII ;
 const int N = 5050 ;

 int qm[N] ;
 int ans[N][N] ;
 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;
    string s ; cin >> s ;
    int n = s.size() ;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int minopen = 0 ; int maxopen = 0 ;
        if (s[i]==')') continue ;
        for(int j = 0 ; j < n ; j++){
            if (s[j]=='('){
                minopen++ ; maxopen++ ;
            }
            if (s[j]==')'){
                minopen-- ; maxopen-- ;
                if (maxopen < 0) break ;
                minopen = max(minopen,0) ;
            }
            if (s[j]=='?'){
                minopen-- ; maxopen++ ;
                if (minopen < 0) minopen = 0 ;
            }
            if ((j-i)%2==1 && minopen<=0 && maxopen>=0){
                ans++ ;
            }
        }
    }
    cout << ans << el ;

 }


/*
 		Resilience is the greatest of all virtues.
 		Code by rajiv
 */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define CASET  int t;cin>>t;while(t--)
 #define FORN(i,x,y) for(int i=x;i<y;i++)
 #define MAXN 100005
 #define INF 10000000010
 #define MOD 1000000007
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD
 #define PI 3.141592653589793

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef vector<VPII > VVPII ;
 const int N = 5050 ;

 int qm[N] ;
 int ans[N][N] ;
 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;
    string s ; cin >> s ;
    s = '@'+s ;
    memset(qm,0,sizeof qm) ;
    for(int i = 1 ; i < s.size() ; i++){
        qm[i] =qm[i-1] ;
        if (s[i]=='?'){
            qm[i] += 1 ;
        }
    }
    int ans = 0 ;
    for(int i = 1 ; i < s.size() ; i++){
        int ret = (s[i]==')')?-1:1 ;
        int fl = (s[i]=='?') ;
        if (ret < 0) continue ;
        for(int j = i+1 ; j < s.size() ; j++){
            ret += (s[j]==')')?-1:1 ;
            if ((j-i) % 2 == 0) continue ;
            if (s[j]=='(') continue ;
            int nqm = qm[j] - qm[i-1] ;
            int temp = ret ;
            if (temp < 0) continue ;
            if (temp == 0){
                ans++ ;
                continue ;
            }
            if (fl) nqm-- ;
            while (nqm--){
                temp -= 2 ;
                if (temp == 0){
                    ans++ ;
                    break ;
                }
            }

        }
    }
    cout << ans << el ;
    return 0 ;
 }


/*
 		Resilience is the greatest of all virtues.
 		Code by rajiv
 */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define CASET  int t;cin>>t;while(t--)
 #define FORN(i,x,y) for(int i=x;i<y;i++)
 #define MAXN 100005
 #define INF 10000000010
 #define MOD 1000000007
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD
 #define PI 3.141592653589793

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef vector<VPII > VVPII ;
 const int N = 5050 ;

 int qm[N] ;
 int ans[N][N] ;
 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;
    string s ; cin >> s ;
    int n = s.size() ;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int minopen = 0 ; int maxopen = 0 ;
        for(int j = 0 ; j < n ; j++){
            if (s[j]=='('){
                minopen++ ; maxopen++ ;
            }
            if (s[j]==')'){
                minopen-- ; maxopen-- ;
                if (maxopen < 0) break ;
            }
            if (s[j]=='?'){
                minopen-- ; maxopen++ ;
                if (minopen < 0) minopen = 0 ;
            }
            if ((j-i)%2==1 && minopen<=0 && maxopen>=0){
                ans++ ;
            }
        }
    }
    cout << ans << el ;

 }


/*
 		Resilience is the greatest of all virtues.
 		Code by rajiv
 */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define CASET  int t;cin>>t;while(t--)
 #define FORN(i,x,y) for(int i=x;i<y;i++)
 #define MAXN 100005
 #define INF 10000000010
 #define MOD 1000000007
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD
 #define PI 3.141592653589793

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef vector<VPII > VVPII ;
 const int N = 5050 ;

 int qm[N] ;
 int ans[N][N] ;
 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;
    string s ; cin >> s ;
    s = '@'+s ;
    memset(qm,0,sizeof qm) ;
    for(int i = 1 ; i < s.size() ; i++){
        qm[i] =qm[i-1] ;
        if (s[i]=='?'){
            qm[i] += 1 ;
        }
    }
    int ans = 0 ;
    for(int i = 1 ; i < s.size() ; i++){
        int ret = (s[i]==')')?-1:1 ;
        if (ret < 0) continue ;
        for(int j = i+1 ; j < s.size() ; j++){
            ret += (s[j]==')')?-1:1 ;
            if ((j-i) % 2 == 0) continue ;
            if (s[j]=='(') continue ;
            int nqm = qm[j] - qm[i-1] ;
            int temp = ret ;
            // cout << "i: " << i << sp << "j: " << j << sp << "ret: " << ret << " nqm: " << nqm << el;
            if (temp < 0) continue ;
            if (temp == 0){
                //cout << "YES!" << el ;
                ans++ ;
                continue ;
            }
            while (nqm--){
                temp -= 2 ;
                if (temp == 0){
                    //cout << "YES!" << el ;
                    ans++ ;
                    break ;
                }
            }

        }
    }
    cout << ans << el ;
    return 0 ;
 }


/*
 		Resilience is the greatest of all virtues.
 		Code by rajiv
 */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define CASET  int t;cin>>t;while(t--)
 #define FORN(i,x,y) for(int i=x;i<y;i++)
 #define MAXN 100005
 #define INF 10000000010
 #define MOD 1000000007
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD
 #define PI 3.141592653589793

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef vector<VPII > VVPII ;
 const int N = 5050 ;

 int qm[N] ;
 int ans[N][N] ;
 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;
    string s ; cin >> s ;
    s = '@'+s ;
    memset(qm,0,sizeof qm) ;
    for(int i = 1 ; i < s.size() ; i++){
        qm[i] =qm[i-1] ;
        if (s[i]=='?'){
            qm[i] += 1 ;
        }
    }
    int ans = 0 ;
    for(int i = 1 ; i < s.size() ; i++){
        int ret = (s[i]==')')?-1:1 ;
        int fl = (s[i]=='?') ;
        if (ret < 0) continue ;
        for(int j = i+1 ; j < s.size() ; j++){
            ret += (s[j]==')')?-1:1 ;
            if ((j-i) % 2 == 0) continue ;
            if (s[j]=='(') continue ;
            int nqm = qm[j] - qm[i-1] ;
            int temp = ret ;
            if (temp < 0) continue ;
            if (temp == 0){
                ans++ ;
                continue ;
            }
            while (nqm--){
                temp -= 2 ;
                if (temp == 0){
                    if (!fl) ans++ ;
                    else if (fl && nqm >0) ans++ ;
                    break ;
                }
            }

        }
    }
    cout << ans << el ;
    return 0 ;
 }


/*
 		Resilience is the greatest of all virtues.
 		Code by rajiv
 */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define CASET  int t;cin>>t;while(t--)
 #define FORN(i,x,y) for(int i=x;i<y;i++)
 #define MAXN 100005
 #define INF 10000000010
 #define MOD 1000000007
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD
 #define PI 3.141592653589793

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef vector<VPII > VVPII ;
 const int N = 5050 ;

 int qm[N] ;
 int ans[N][N] ;
 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;
    string s ; cin >> s ;
    int n = s.size() ;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int minopen = 0 ; int maxopen = 0 ;

        for(int j = i ; j < n ; j++){
            if (s[j]=='('){
                minopen++ ; maxopen++ ;
            }
            if (s[j]==')'){
                minopen-- ; maxopen-- ;
                if (maxopen < 0) break ;
                minopen = max(minopen,0) ;
            }
            if (s[j]=='?'){
                minopen-- ; maxopen++ ;
                if (minopen < 0) minopen = 0 ;
            }
            if ((j-i)%2==1 && minopen<=0 && maxopen>=0){
                ans++ ;
            }
        }
    }
    cout << ans << el ;

 }


/*
 		Resilience is the greatest of all virtues.
 		Code by rajiv
 */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define CASET  int t;cin>>t;while(t--)
 #define FORN(i,x,y) for(int i=x;i<y;i++)
 #define MAXN 100005
 #define INF 10000000010
 #define MOD 1000000007
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD
 #define PI 3.141592653589793

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef vector<VPII > VVPII ;
 const int N = 5050 ;

 int qm[N] ;
 int ans[N][N] ;
 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;
    string s ; cin >> s ;
    int n = s.size() ;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int minopen = 0 ; int maxopen = 0 ;
        for(int j = 0 ; j < n ; j++){
            if (s[j]=='('){
                minopen++ ; maxopen++ ;
            }
            if (s[j]==')'){
                minopen-- ; maxopen-- ;
                if (maxopen < 0) break ;
            }
            if (s[j]=='?'){
                minopen-- ; maxopen++ ;
                if (minopen < 0) minopen = 0 ;
            }
            if ((r-l)%2==1 && minopen<=0 && maxopen>=0){
                ans++ ;
            }
        }
    }
    cout << ans << el ;

 }


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
using namespace std;
typedef long long ll;

#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson  root << 1
#define rson  root << 1 | 1

char s[100005];

int l[100005];
int r[100005];

int misl[100005];
int misr[100005];
int mis[100005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    int len=strlen(s);
    int cnt=0;

    for(int i=0; i<len; i++)
    {
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        memset(misl,0,sizeof(misl));
        memset(misr,0,sizeof(misr));
        memset(mis,0,sizeof(mis));
        int Mis=0;
        int L=0;
        int R=0;
        if(s[i]==')')
            continue;
        for(int j=i; j<len; j++)
        {
            if(s[j]=='(')
                L++;
            else if(s[j]==')')
                R++;
            else
            {
                Mis++;
                if(Mis>L)
                {
                    Mis--;
                    L++;
                }
            }
            if(Mis+R>L)
            {
                if(Mis>0)
                {
                    Mis--;
                    L++;
                }
            }
            if((j-i)%2==1&&(L+Mis)>=R&&(R+Mis)>=L)
                cnt++;
        }
    }
    cout<<cnt<<endl;
}

/*

?????)(???

*/


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
using namespace std;
typedef long long ll;

#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson  root << 1
#define rson  root << 1 | 1

char s[100005];

int l[100005];
int r[100005];

int misl[100005];
int misr[100005];
int mis[100005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    int len=strlen(s);
    int cnt=0;
    for(int i=0; i<len; i++)
    {
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        memset(misl,0,sizeof(misl));
        memset(misr,0,sizeof(misr));
        memset(mis,0,sizeof(mis));
        for(int j=i; j<len; j++)
        {
            if(j==0)
            {
                if(s[j]=='(')
                    l[j]++;
                else if(s[j]==')')
                    r[j]++;
                else if(s[j]=='?')
                    mis[j]++;
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
            }
            else
            {
                l[j]+=l[j-1];
                r[j]+=r[j-1];
                mis[j]+=mis[j-1];
                if(s[j]=='(')
                    l[j]++;
                else if(s[j]==')')
                    r[j]++;
                else if(s[j]=='?')
                    mis[j]++;
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
                //if(s[j]==')'&&((r[j]>l[j]+mis[j])||((r[j]>l[j])&&(mis[j]-(r[j]-l[j]))%2==1)))
                    //break;
                if(r[j]>0&&l[j]==0&&mis[j]==0)
                    break;
                if(s[j]==')'&&(l[j]+mis[j]==r[j]||l[j]==mis[j]+r[j]||(l[j]==r[j]&&mis[j]%2==0)||(l[j]<r[j]&&(mis[j]-(r[j]-l[j]))%2==0)))
                {
                    cnt++;
                    //cout<<i<<" "<<j<<endl;
                }
                else if(s[j]=='?')
                {
                    //if(i==6)
                    //{
                        //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<" "<<i<<" "<<j<<endl;
                        //if((mis[j]-(l[j]-r[j]))%2==0)
                            //cout<<111<<endl;
                    //}                    //cout<<j<<endl;
                    //cout<<111<<endl;
                    if(l[j]==0&&r[j]==0&&mis[j]%2==0)
                    {
                        //cout<<j<<endl;
                        //cout<<111<<endl;
                        cnt++;
                        //cout<<i<<" "<<j<<endl;
                        //cout<<cnt<<endl;
                    }
                    else if(l[j]+mis[j]==r[j]||l[j]==mis[j]+r[j]||(l[j]==r[j]&&mis[j]%2==0))
                    {
                        //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<" "<<i<<" "<<j<<endl;
                        //cout<<i<<" "<<j<<endl;
                        cnt++;
                    }
                    //if(l[j]>r[j]&&(mis[j]-(l[j]-r[j]))%2==1)
                        //break;
                    if((l[j]>r[j]&&(mis[j]-(l[j]-r[j]))%2==0)&&(mis[j]-(l[j]-r[j])!=0))
                    {
                        //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<" "<<i<<" "<<j<<endl;
                        //cout<<i<<" "<<j<<endl;
                        cnt++;
                    }
                    //if(i==6&&j==9)
                        //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<" "<<(mis[j]-(l[j]-r[j]))%2<<endl;
                }
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
            }
            //cout<<cnt<<" "<<i<<" "<<j<<endl;
        }
    }
    cout<<cnt<<endl;
}

/*

?????)(???

*/


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
using namespace std;
typedef long long ll;

#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson  root << 1
#define rson  root << 1 | 1

char s[100005];

int l[100005];
int r[100005];

int misl[100005];
int misr[100005];
int mis[100005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    int len=strlen(s);
    int cnt=0;

    for(int i=0; i<len; i++)
    {
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        memset(misl,0,sizeof(misl));
        memset(misr,0,sizeof(misr));
        memset(mis,0,sizeof(mis));
        int Mis=0;
        int L=0;
        int R=0;
        if(s[i]==')')
            continue;
        for(int j=i; j<len; j++)
        {
            if(s[j]=='(')
                L++;
            else if(s[j]==')')
                R++;
            else
            {
                Mis++;
                if(Mis>L)
                {
                    Mis--;
                    L++;
                }
            }
            if(Mis+R>L)
            {
                if(Mis>0)
                {
                    Mis--;
                    L++;
                }
                else
                    break;
            }
            if((j-i)%2==1&&(L+Mis)>=R&&(R+Mis)>=L)
                cnt++;
        }
    }
    cout<<cnt<<endl;
}

/*

?????)(???

*/


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
using namespace std;
typedef long long ll;

#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson  root << 1
#define rson  root << 1 | 1

char s[100005];

int l[100005];
int r[100005];

int misl[100005];
int misr[100005];
int mis[100005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    int len=strlen(s);
    int cnt=0;
    for(int i=0; i<len; i++)
    {
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        memset(misl,0,sizeof(misl));
        memset(misr,0,sizeof(misr));
        memset(mis,0,sizeof(mis));
        for(int j=i; j<len; j++)
        {
            if(j==0)
            {
                if(s[j]=='(')
                    l[j]++;
                else if(s[j]==')')
                    r[j]++;
                else if(s[j]=='?')
                    mis[j]++;
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
            }
            else
            {
                l[j]+=l[j-1];
                r[j]+=r[j-1];
                mis[j]+=mis[j-1];
                if(s[j]=='(')
                    l[j]++;
                else if(s[j]==')')
                    r[j]++;
                else if(s[j]=='?')
                    mis[j]++;
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
                if(s[j]==')'&&(r[j]>l[j]+mis[j]))
                    break;
                if(s[j]==')'&&(l[j]+mis[j]==r[j]||l[j]==mis[j]+r[j]||(l[j]==r[j]&&mis[j]%2==0)))
                    cnt++;
                else if(s[j]=='?')
                {
                    //cout<<j<<endl;
                    //cout<<111<<endl;
                    if(l[j]==0&&r[j]==0&&mis[j]%2==0)
                    {
                        //cout<<j<<endl;
                        //cout<<111<<endl;
                        cnt++;
                        //cout<<cnt<<endl;
                    }
                    else if(l[j]+mis[j]==r[j]||l[j]==mis[j]+r[j]||(l[j]==r[j]&&mis[j]%2==0))
                        cnt++;
                }
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
            }
        }
    }
    cout<<cnt<<endl;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
using namespace std;
typedef long long ll;

#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson  root << 1
#define rson  root << 1 | 1

char s[100005];

int l[100005];
int r[100005];

int misl[100005];
int misr[100005];
int mis[100005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    int len=strlen(s);
    int cnt=0;
    for(int i=0; i<len; i++)
    {
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        memset(misl,0,sizeof(misl));
        memset(misr,0,sizeof(misr));
        memset(mis,0,sizeof(mis));
        for(int j=i; j<len; j++)
        {
            if(j==0)
            {
                if(s[j]=='(')
                    l[j]++;
                else if(s[j]==')')
                    r[j]++;
                else if(s[j]=='?')
                    mis[j]++;
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
            }
            else
            {
                l[j]+=l[j-1];
                r[j]+=r[j-1];
                mis[j]+=mis[j-1];
                if(s[j]=='(')
                    l[j]++;
                else if(s[j]==')')
                    r[j]++;
                else if(s[j]=='?')
                    mis[j]++;
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
                //if(s[j]==')'&&((r[j]>l[j]+mis[j])||((r[j]>l[j])&&(mis[j]-(r[j]-l[j]))%2==1)))
                    //break;
                if(s[j]==')'&&(l[j]+mis[j]==r[j]||l[j]==mis[j]+r[j]||(l[j]==r[j]&&mis[j]%2==0)||(l[j]<r[j]&&(mis[j]-(r[j]-l[j]))%2==0)))
                    cnt++;
                else if(s[j]=='?')
                {
                    //if(i==6)
                    //{
                        //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<" "<<i<<" "<<j<<endl;
                        //if((mis[j]-(l[j]-r[j]))%2==0)
                            //cout<<111<<endl;
                    //}                    //cout<<j<<endl;
                    //cout<<111<<endl;
                    if(l[j]==0&&r[j]==0&&mis[j]%2==0)
                    {
                        //cout<<j<<endl;
                        //cout<<111<<endl;
                        cnt++;
                        //cout<<cnt<<endl;
                    }
                    else if(l[j]+mis[j]==r[j]||l[j]==mis[j]+r[j]||(l[j]==r[j]&&mis[j]%2==0))
                    {
                        //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<" "<<i<<" "<<j<<endl;
                        //cout<<i<<" "<<j<<endl;
                        cnt++;
                    }
                    if(l[j]>r[j]&&(mis[j]-(l[j]-r[j]))%2==1)
                        break;
                    if((l[j]>r[j]&&(mis[j]-(l[j]-r[j])%2==0))&&(mis[j]-(l[j]-r[j])!=0))
                    {
                        //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<" "<<i<<" "<<j<<endl;
                        cnt++;
                    }
                }
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
            }
            //cout<<cnt<<" "<<i<<" "<<j<<endl;
        }
    }
    cout<<cnt<<endl;
}

/*

?????)(???

*/


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
using namespace std;
typedef long long ll;

#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson  root << 1
#define rson  root << 1 | 1

char s[100005];

int l[100005];
int r[100005];

int misl[100005];
int misr[100005];
int mis[100005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    int len=strlen(s);
    int cnt=0;
    for(int i=0; i<len; i++)
    {
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        memset(misl,0,sizeof(misl));
        memset(misr,0,sizeof(misr));
        memset(mis,0,sizeof(mis));
        for(int j=i; j<len; j++)
        {
            if(j==0)
            {
                if(s[j]=='(')
                    l[j]++;
                else if(s[j]==')')
                    r[j]++;
                else if(s[j]=='?')
                    mis[j]++;
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
            }
            else
            {
                l[j]+=l[j-1];
                r[j]+=r[j-1];
                mis[j]+=mis[j-1];
                if(s[j]=='(')
                    l[j]++;
                else if(s[j]==')')
                    r[j]++;
                else if(s[j]=='?')
                    mis[j]++;
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
                //if(s[j]==')'&&((r[j]>l[j]+mis[j])||((r[j]>l[j])&&(mis[j]-(r[j]-l[j]))%2==1)))
                    //break;
                if(r[j]>0&&l[j]==0&&mis[j]==0)
                    break;
                if(s[j]==')'&&(l[j]+mis[j]==r[j]||l[j]==mis[j]+r[j]||(l[j]==r[j]&&mis[j]%2==0)||(l[j]<r[j]&&(mis[j]-(r[j]-l[j]))%2==0)))
                    cnt++;
                else if(s[j]=='?')
                {
                    //if(i==6)
                    //{
                        //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<" "<<i<<" "<<j<<endl;
                        //if((mis[j]-(l[j]-r[j]))%2==0)
                            //cout<<111<<endl;
                    //}                    //cout<<j<<endl;
                    //cout<<111<<endl;
                    if(l[j]==0&&r[j]==0&&mis[j]%2==0)
                    {
                        //cout<<j<<endl;
                        //cout<<111<<endl;
                        cnt++;
                        //cout<<cnt<<endl;
                    }
                    else if(l[j]+mis[j]==r[j]||l[j]==mis[j]+r[j]||(l[j]==r[j]&&mis[j]%2==0))
                    {
                        //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<" "<<i<<" "<<j<<endl;
                        //cout<<i<<" "<<j<<endl;
                        cnt++;
                    }
                    //if(l[j]>r[j]&&(mis[j]-(l[j]-r[j]))%2==1)
                        //break;
                    if((l[j]>r[j]&&(mis[j]-(l[j]-r[j])%2==0))&&(mis[j]-(l[j]-r[j])!=0))
                    {
                        //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<" "<<i<<" "<<j<<endl;
                        cnt++;
                    }
                }
                //cout<<l[j]<<" "<<r[j]<<" "<<mis[j]<<endl;
            }
            //cout<<cnt<<" "<<i<<" "<<j<<endl;
        }
    }
    cout<<cnt<<endl;
}

/*

?????)(???

*/