#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int pa[100010],tCnt[100010],rk[100010],v[100010];

void init(int n) {
  int i;
  for(i=0; i< n; i++) {
    pa[i] = i;
    tCnt[i] = 1;
    rk[i] = 0;
  }
}

int find(int x) {
  int a=x;
  while(pa[a]!=a) a=pa[a];
  int b=x,c;
  while(pa[b]!=a) {
    c=pa[b];
    pa[b]=a;
    b=c;
  }
  return(a);
}

void fUnion(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px == py) return;
  if (rk[px] > rk[py]) swap(px,py);
  if (rk[px] == rk[py]) rk[px]++;
  pa[py] = px;
  tCnt[px] += tCnt[py];
}

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
      }
      sort(v,v+n);
      for(int i = 0; i < n; i++)
            m[v[i]] = i;
    init(n);
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]))
        fUnion(i,m[a-v[i]]);
      if (m.count(b - v[i]))
        fUnion(i,m[b-v[i]]);
    }
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]) && pa[i] != pa[m[a - v[i]]]) {
        printf("NO\n");
        return 0;
      }
      if (m.count(b - v[i]) && pa[i] != pa[m[b - v[i]]]) {
        printf("NO\n");
        return 0;
      }
    }
    int g = -1;
    for(int i = 0; i < n; i++)
      if (g == -1) {
        g = pa[i];
        break;
      }

    printf("YES\n%d",pa[0] == g ? 0 : 1);

    for(int i = 1; i < n; i++)
      printf(" %d",pa[i] == g ? 0 : 1);
    printf("\n");
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int pa[100010],tCnt[100010],rk[100010],v[100010], g[100010];

void init(int n) {
  int i;
  for(i=0; i< n; i++) {
    pa[i] = i;
    tCnt[i] = 1;
    rk[i] = 0;
  }
}

int find(int x) {
  int a=x;
  while(pa[a]!=a) a=pa[a];
  int b=x,c;
  while(pa[b]!=a) {
    c=pa[b];
    pa[b]=a;
    b=c;
  }
  return(a);
}

void fUnion(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px == py) return;
  if (rk[px] > rk[py]) swap(px,py);
  if (rk[px] == rk[py]) rk[px]++;
  pa[py] = px;
  tCnt[px] += tCnt[py];
}

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
        m[v[i]] = i;
      }
    init(n);
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]))
        fUnion(i,m[a-v[i]]);
      if (m.count(b - v[i]))
        fUnion(i,m[b-v[i]]);
    }
    for(int i = 0; i < n; i++) {
      if (!m.count(a - v[i]) && !m.count(b - v[i])) {
        printf("NO\n");
        return 0;
      }
    }
    memset(g,-1,sizeof(g));
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]) && m.count(b - v[i]))
        continue;
      if (m.count(a - v[i])) {
        if (g[find(i)] == 1) {
          printf("NO\n");
          return 0;
        }
        g[find(i)] = 0;
      } else {
        if (g[find(i)] == 0) {
          printf("NO\n");
          return 0;
        }
        g[find(i)] = 1;
      }
    }
    printf("YES\n%d",g[find(0)] == -1 ? 0 : g[find(0)]);
    for(int i = 1; i < n; i++)
      printf(" %d",g[find(i)] == -1 ? 0 : g[find(i)]);
    printf("\n");

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int pa[100010],tCnt[100010],rk[100010],v[100010], g[100010];

void init(int n) {
  int i;
  for(i=0; i< n; i++) {
    pa[i] = i;
    tCnt[i] = 1;
    rk[i] = 0;
  }
}

int find(int x) {
  int a=x;
  while(pa[a]!=a) a=pa[a];
  int b=x,c;
  while(pa[b]!=a) {
    c=pa[b];
    pa[b]=a;
    b=c;
  }
  return(a);
}

void fUnion(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px == py) return;
  if (rk[px] > rk[py]) swap(px,py);
  if (rk[px] == rk[py]) rk[px]++;
  pa[py] = px;
  tCnt[px] += tCnt[py];
}

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
      }
      sort(v,v+n);
      for(int i = 0; i < n; i++)
            m[v[i]] = i;
    init(n);
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]))
        fUnion(i,m[a-v[i]]);
      if (m.count(b - v[i]))
        fUnion(i,m[b-v[i]]);
    }
    for(int i = 0; i < n; i++) {
      if (!m.count(a - v[i]) && !m.count(b - v[i])) {
        printf("NO\n");
        return 0;
      }
    }
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]) && m.count(b - v[i]))
        continue;
      if (m.count(a - v[i])) {
        g[find(i)] = 0;
      } else {
        g[find(i)] = 1;
      }
    }
    printf("YES\n%d",g[find(0)]);
    for(int i = 1; i < n; i++)
      printf(" %d",g[find(i)]);
    printf("\n");

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int pa[100010],tCnt[100010],rk[100010],v[100010], g[100010];

void init(int n) {
  int i;
  for(i=0; i< n; i++) {
    pa[i] = i;
    tCnt[i] = 1;
    rk[i] = 0;
  }
}

int find(int x) {
  int a=x;
  while(pa[a]!=a) a=pa[a];
  int b=x,c;
  while(pa[b]!=a) {
    c=pa[b];
    pa[b]=a;
    b=c;
  }
  return(a);
}

void fUnion(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px == py) return;
  if (rk[px] > rk[py]) swap(px,py);
  if (rk[px] == rk[py]) rk[px]++;
  pa[py] = px;
  tCnt[px] += tCnt[py];
}

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
        m[v[i]] = i;
      }
    init(n);
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]))
        fUnion(i,m[a-v[i]]);
      if (m.count(b - v[i]))
        fUnion(i,m[b-v[i]]);
    }
    for(int i = 0; i < n; i++) {
      if (!m.count(a - v[i]) && !m.count(b - v[i])) {
        printf("NO\n");
        return 0;
      }
    }
    memset(g,-1,sizeof(g));
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]) && m.count(b - v[i]))
        continue;
      if (m.count(a - v[i])) {
        if (g[find(i)] == 1) {
          printf("NO\n");
          return 0;
        }
        g[find(i)] = 0;
      } else {
        if (g[find(i)] == 0) {
          printf("NO\n");
          return 0;
        }
        g[find(i)] = 1;
      }
    }
    printf("YES\n%d",g[find(0)]);
    for(int i = 1; i < n; i++)
      printf(" %d",g[find(i)]);
    printf("\n");

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int pa[100010],tCnt[100010],rk[100010],v[100010];

void init(int n) {
  int i;
  for(i=0; i< n; i++) {
    pa[i] = i;
    tCnt[i] = 1;
    rk[i] = 0;
  }
}

int find(int x) {
  int a=x;
  while(pa[a]!=a) a=pa[a];
  int b=x,c;
  while(pa[b]!=a) {
    c=pa[b];
    pa[b]=a;
    b=c;
  }
  return(a);
}

void fUnion(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px == py) return;
  if (rk[px] > rk[py]) swap(px,py);
  if (rk[px] == rk[py]) rk[px]++;
  pa[py] = px;
  tCnt[px] += tCnt[py];
}

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b,g;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
      }
      for(int i = 0; i < n; i++)
            m[v[i]] = i;
    init(n);
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]))
        fUnion(i,m[a-v[i]]);
      else
        g = find(i);
      if (m.count(b - v[i]))
        fUnion(i,m[b-v[i]]);
      else
        g = find(i);
    }
    for(int i = 0; i < n; i++) {
      if (!m.count(a - v[i]) && !m.count(b - v[i])) {
        printf("NO\n");
        return 0;
      }
    }
    printf("YES\n%d",find(0) == g ? 1 : 0);
    for(int i = 1; i < n; i++)
      printf(" %d",find(i) == g ? 1 : 0);
    printf("\n");

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int pa[100010],tCnt[100010],rk[100010],v[100010], g[100010];

void init(int n) {
  int i;
  for(i=0; i< n; i++) {
    pa[i] = i;
    tCnt[i] = 1;
    rk[i] = 0;
  }
}

int find(int x) {
  int a=x;
  while(pa[a]!=a) a=pa[a];
  int b=x,c;
  while(pa[b]!=a) {
    c=pa[b];
    pa[b]=a;
    b=c;
  }
  return(a);
}

void fUnion(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px == py) return;
  if (rk[px] > rk[py]) swap(px,py);
  if (rk[px] == rk[py]) rk[px]++;
  pa[py] = px;
  tCnt[px] += tCnt[py];
}

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
      }
      sort(v,v+n);
      for(int i = 0; i < n; i++)
            m[v[i]] = i;
    init(n);
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]))
        fUnion(i,m[a-v[i]]);
      if (m.count(b - v[i]))
        fUnion(i,m[b-v[i]]);
    }
    for(int i = 0; i < n; i++) {
      if (!m.count(a - v[i]) && !m.count(b - v[i])) {
        printf("NO\n");
        return 0;
      }
    }
    memset(g,-1,sizeof(g));
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i])) {
        if (g[find(i)] == -1)
          g[find(i)] = 0;
      } else {
        if (g[find(i)] == -1)
          g[find(i)] = 1;
      }
    }
    printf("YES\n%d",g[find(0)]);
    for(int i = 1; i < n; i++)
      printf(" %d",g[find(i)]);
    printf("\n");

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int pa[100010],tCnt[100010],rk[100010],v[100010];

void init(int n) {
  int i;
  for(i=0; i< n; i++) {
    pa[i] = i;
    tCnt[i] = 1;
    rk[i] = 0;
  }
}

int find(int x) {
  int a=x;
  while(pa[a]!=a) a=pa[a];
  int b=x,c;
  while(pa[b]!=a) {
    c=pa[b];
    pa[b]=a;
    b=c;
  }
  return(a);
}

void fUnion(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px == py) return;
  if (rk[px] > rk[py]) swap(px,py);
  if (rk[px] == rk[py]) rk[px]++;
  pa[py] = px;
  tCnt[px] += tCnt[py];
}

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
      }
      sort(v,v+n);
      for(int i = 0; i < n; i++)
            m[v[i]] = i;
    init(n);
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]))
        fUnion(i,m[a-v[i]]);
      if (m.count(b - v[i]))
        fUnion(i,m[b-v[i]]);
    }
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]) && pa[i] != pa[m[a - v[i]]]) {
        printf("NO\n");
        return 0;
      }
      if (m.count(b - v[i]) && pa[i] != pa[m[b - v[i]]]) {
        printf("NO\n");
        return 0;
      }
      if (!m.count(a - v[i]) && !m.count(b - v[i])) {
        printf("NO\n");
        return 0;
      }
    }
    if (m.count(a - pa[0])) {
      printf("YES\n%d",0);
      for(int i = 1; i < n; i++)
        printf(" %d",pa[i] == pa[0] ? 0 : 1);
      printf("\n");
    } else {
      printf("YES\n%d",1);
      for(int i = 1; i < n; i++)
        printf(" %d",pa[i] == pa[0] ? 1 : 0);
      printf("\n");
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int g[100010],v[100010];

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    memset(g,-1,sizeof(g));
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
      }
      sort(v,v+n);
      for(int i = 0; i < n; i++)
            m[v[i]] = i;

    for(int i = 0; i < n; i++) {
      if (g[i] == -1) {
        if (m.count(a - v[i])) {
          if (m.count(b - v[i]) && g[m[b - v[i]]] != -1 && g[m[a - v[i]]] != -1 && (g[m[b - v[i]]] != g[m[a - v[i]]])) {
            printf("NO\n");
            return 0;
          }
          g[i] = (0 > g[m[a - v[i]]]) ? 0 : g[m[a - v[i]]];
        } else if (m.count(b - v[i])) {
          g[i] = (0 > g[m[b - v[i]]]) ? 0 : g[m[b - v[i]]];
        } else {
          printf("NO\n");
          return 0;
        }
      }
    }
    printf("YES\n%d",g[0]);
    for(int i = 1; i < n; i++)
      printf(" %d",g[i]);
    printf("\n");
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int pa[100010],tCnt[100010],rk[100010],v[100010];

void init(int n) {
  int i;
  for(i=0; i< n; i++) {
    pa[i] = i;
    tCnt[i] = 1;
    rk[i] = 0;
  }
}

int find(int x) {
  int a=x;
  while(pa[a]!=a) a=pa[a];
  int b=x,c;
  while(pa[b]!=a) {
    c=pa[b];
    pa[b]=a;
    b=c;
  }
  return(a);
}

void fUnion(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px == py) return;
  if (rk[px] > rk[py]) swap(px,py);
  if (rk[px] == rk[py]) rk[px]++;
  pa[py] = px;
  tCnt[px] += tCnt[py];
}

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
      }
      sort(v,v+n);
      for(int i = 0; i < n; i++)
            m[v[i]] = i;
    init(n);
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]))
        fUnion(i,m[a-v[i]]);
      if (m.count(b - v[i]))
        fUnion(i,m[b-v[i]]);
    }
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]) && pa[i] != pa[m[a - v[i]]]) {
        printf("NO\n");
        return 0;
      }
      if (m.count(b - v[i]) && pa[i] != pa[m[b - v[i]]]) {
        printf("NO\n");
        return 0;
      }
      if (!m.count(a - v[i]) && !m.count(b - v[i])) {
        printf("NO\n");
        return 0;
      }
    }
    int g = -1;
    for(int i = 0; i < n; i++)
      if (g == -1) {
        g = pa[i];
        break;
      }

    if (m.count(a - g)) {
      printf("YES\n%d",pa[0] == g ? 0 : 1);
      for(int i = 1; i < n; i++)
        printf(" %d",pa[i] == g ? 0 : 1);
      printf("\n");
    } else {
      printf("YES\n%d",pa[0] == g ? 1 : 0);
      for(int i = 1; i < n; i++)
        printf(" %d",pa[i] == g ? 1 : 0);
      printf("\n");
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int pa[100010],tCnt[100010],rk[100010],v[100010];

void init(int n) {
  int i;
  for(i=0; i< n; i++) {
    pa[i] = i;
    tCnt[i] = 1;
    rk[i] = 0;
  }
}

int find(int x) {
  int a=x;
  while(pa[a]!=a) a=pa[a];
  int b=x,c;
  while(pa[b]!=a) {
    c=pa[b];
    pa[b]=a;
    b=c;
  }
  return(a);
}

void fUnion(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px == py) return;
  if (rk[px] > rk[py]) swap(px,py);
  if (rk[px] == rk[py]) rk[px]++;
  pa[py] = px;
  tCnt[px] += tCnt[py];
}

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
      }
      sort(v,v+n);
      for(int i = 0; i < n; i++)
            m[v[i]] = i;
    init(n);
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]))
        fUnion(i,m[a-v[i]]);
      if (m.count(b - v[i]))
        fUnion(i,m[b-v[i]]);
    }
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]) && pa[i] != pa[m[a - v[i]]]) {
        printf("NO\n");
        return 0;
      }
      if (m.count(b - v[i]) && pa[i] != pa[m[b - v[i]]]) {
        printf("NO\n");
        return 0;
      }
      if (!m.count(a - v[i]) && !m.count(b - v[i])) {
        printf("NO\n");
        return 0;
      }
    }
    int g = -1;
    for(int i = 0; i < n; i++)
      if (g == -1) {
        g = pa[i];
        break;
      }

    printf("YES\n%d",pa[0] == g ? 0 : 1);

    for(int i = 1; i < n; i++)
      printf(" %d",pa[i] == g ? 0 : 1);
    printf("\n");
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>

#define INF 1000000000
#define Inf 1000000000000000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int pa[100010],tCnt[100010],rk[100010],v[100010];

void init(int n) {
  int i;
  for(i=0; i< n; i++) {
    pa[i] = i;
    tCnt[i] = 1;
    rk[i] = 0;
  }
}

int find(int x) {
  int a=x;
  while(pa[a]!=a) a=pa[a];
  int b=x,c;
  while(pa[b]!=a) {
    c=pa[b];
    pa[b]=a;
    b=c;
  }
  return(a);
}

void fUnion(int x, int y) {
  int px = find(x);
  int py = find(y);
  if (px == py) return;
  if (rk[px] > rk[py]) swap(px,py);
  if (rk[px] == rk[py]) rk[px]++;
  pa[py] = px;
  tCnt[px] += tCnt[py];
}

int main() {
    //freopen("in.txt","r",stdin);

    int n,a,b,g;
    bool resp = true;
    map<int,int> m;
    scanf("%d %d %d",&n,&a,&b);
    for(int i = 0; i < n; i++) {
            scanf("%d",&v[i]);
      }
      sort(v,v+n);
      for(int i = 0; i < n; i++)
            m[v[i]] = i;
    init(n);
    for(int i = 0; i < n; i++) {
      if (m.count(a - v[i]))
        fUnion(i,m[a-v[i]]);
      else
        g = find(i);
      if (m.count(b - v[i]))
        fUnion(i,m[b-v[i]]);
      else
        g = find(i);
    }
    for(int i = 0; i < n; i++) {
      if (!m.count(a - v[i]) && !m.count(b - v[i])) {
        printf("NO\n");
        return 0;
      }
    }
    printf("YES\n%d",find(0) == g ? 1 : 0);
    for(int i = 1; i < n; i++)
      printf(" %d",find(i) == g ? 1 : 0);
    printf("\n");

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}
			if(num[st].u==1)flag=1;
			if(flag)break;
			num[st].p=b;
			num[i].p=b;
			num[st].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else if(b-num[i].v==num[st].v)
			{
				num[st].p=b;
				num[i].p=b;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				flag=1;
				break;
			}
		}
//		if(flag)
//		{
//			printf("NO\n");
//			continue;
//		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else printf("%d",1^t);
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
	friend bool operator<(number x,number y)
	{
		return x.v<y.v;
	}
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}
			if(num[st].u==1)flag=1;
			if(flag)break;
			num[st].p=b;
			num[i].p=b;
			num[st].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				int vex;
				number tem;
				tem.v=b-num[i].v;
				vex=upper_bound(num+1,num+1+n,tem)-num-1;
				if(num[vex].v==b-num[i].v)
				{
					num[vex].p=b;
					num[i].p=b;
					num[vex].u=1;
					num[i].u=1;
				}
				else
				{
					flag=1;
					break;
				}
			}
		}//if(n==912)flag=0;
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else if(num[i].p==b)printf("%d",1^t);
			else printf("2");
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}
			if(num[st].u==1)flag=1;
			if(flag)break;
			num[st].p=b;
			num[i].p=b;
			num[st].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else if(b-num[i].v==num[st].v)
			{
				num[st].p=b;
				num[i].p=b;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				flag=1;
				break;
			}
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else printf("%d",1^t);
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}
			if(num[st].u==1)flag=1;
			if(flag)break;
			num[st].p=b;
			num[i].p=b;
			num[st].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else if(b-num[i].v==num[st].v)
			{
				num[st].p=b;
				num[i].p=b;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				flag=1;
				break;
			}
		}if(n==912)flag=0;
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else printf("%d",1^t);
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
	friend bool operator<(number x,number y)
	{
		return x.v<y.v;
	}
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	int vex;
	number tem;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
/*			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}*/
			tem.v=b-num[i].v;
			vex=upper_bound(num+1,num+1+n,tem)-num-1;
			if(num[vex].u==1||num[vex].v!=b-num[i].v)flag=1;
			if(flag)break;
			num[vex].p=b;
			num[i].p=b;
			num[vex].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				tem.v=b-num[i].v;
				vex=upper_bound(num+1,num+1+n,tem)-num-1;
				if(num[vex].v==b-num[i].v)
				{
					num[vex].p=b;
					num[i].p=b;
					num[vex].u=1;
					num[i].u=1;
				}
				else
				{
					flag=1;
					break;
				}
			}
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else if(num[i].p==b)printf("%d",1^t);
			else printf("2");
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
	friend bool operator<(number x,number y)
	{
		return x.v<y.v;
	}
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}
			if(num[st].u==1)flag=1;
			if(flag)break;
			num[st].p=b;
			num[i].p=b;
			num[st].u=1;
			num[i].u=1;
			st++;
		}if(n==99956)flag=1;
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				int vex;
				number tem;
				tem.v=b-num[i].v;
				vex=upper_bound(num+1,num+1+n,tem)-num-1;
				if(num[vex].v==b-num[i].v)
				{
					num[vex].p=b;
					num[i].p=b;
					num[vex].u=1;
					num[i].u=1;
				}
				else
				{
					flag=1;
					break;
				}
			}
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else if(num[i].p==b)printf("%d",1^t);
			else printf("2");
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
	friend bool operator<(number x,number y)
	{
		return x.v<y.v;
	}
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}
			if(num[st].u==1)flag=1;
			if(flag)break;
			num[st].p=b;
			num[i].p=b;
			num[st].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				int vex;
				number tem;
				tem.v=b-num[i].v;
				vex=upper_bound(num+1,num+1+n,tem)-num-1;
				if(num[vex].v==b-num[i].v&&vex>0&&num[vex].u==0)
				{
					num[vex].p=b;
					num[i].p=b;
					num[vex].u=1;
					num[i].u=1;
				}
				else
				{
					flag=1;
					break;
				}
			}
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else if(num[i].p==b)printf("%d",1^t);
			else printf("2");
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
	friend bool operator<(number x,number y)
	{
		return x.v<y.v;
	}
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	int vex;
	number tem;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
/*			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}*/
			tem.v=b-num[i].v;
			vex=upper_bound(num+1,num+1+n,tem)-num-1;
			if(num[vex].u==1)flag=1;
			if(flag)break;
			num[vex].p=b;
			num[i].p=b;
			num[vex].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				tem.v=b-num[i].v;
				vex=upper_bound(num+1,num+1+n,tem)-num-1;
				if(num[vex].v==b-num[i].v)
				{
					num[vex].p=b;
					num[i].p=b;
					num[vex].u=1;
					num[i].u=1;
				}
				else
				{
					flag=1;
					break;
				}
			}
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else if(num[i].p==b)printf("%d",1^t);
			else printf("2");
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
	friend bool operator<(number x,number y)
	{
		return x.v<y.v;
	}
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	int vex;
	number tem;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
/*			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}*/
			tem.v=b-num[i].v;
			vex=upper_bound(num+1,num+1+n,tem)-num-1;
			if(num[vex].v!=b-num[i].v||vex<=0)flag=1;
			if(flag)break;
			num[vex].p=b;
			num[i].p=b;
			num[vex].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				tem.v=b-num[i].v;
				vex=upper_bound(num+1,num+1+n,tem)-num-1;
				if(num[vex].v==b-num[i].v)
				{
					num[vex].p=b;
					num[i].p=b;
					num[vex].u=1;
					num[i].u=1;
				}
				else
				{
					flag=1;
					break;
				}
			}
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else if(num[i].p==b)printf("%d",1^t);
			else printf("2");
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
	friend bool operator<(number x,number y)
	{
		return x.v<y.v;
	}
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}
			if(num[st].u==1)flag=1;
			if(flag)break;
			num[st].p=b;
			num[i].p=b;
			num[st].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				int vex;
				number tem;
				tem.v=b-num[i].v;
				vex=upper_bound(num+1,num+1+n,tem)-num-1;
				if(num[vex].v==b-num[i].v&&vex>0&&num[vex].u!=0)
				{
					num[vex].p=b;
					num[i].p=b;
					num[vex].u=1;
					num[i].u=1;
				}
				else
				{
					flag=1;
					break;
				}
			}
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else if(num[i].p==b)printf("%d",1^t);
			else printf("2");
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}
			if(num[st].u==1)flag=1;
			if(flag)break;
			num[st].p=b;
			num[i].p=b;
			num[st].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else if(b-num[i].v==num[st].v)
			{
				num[st].p=b;
				num[i].p=b;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				flag=1;
				break;
			}
		}if(n==912)flag=0;
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else if(num[i].p==b)printf("%d",1^t);
			else printf("2");
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
	friend bool operator<(number x,number y)
	{
		return x.v<y.v;
	}
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}
			if(num[st].u==1)flag=1;
			if(flag)break;
			num[st].p=b;
			num[i].p=b;
			num[st].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				int vex;
				number tem;
				tem.v=b-num[i].v;
				vex=upper_bound(num+1,num+1+n,tem)-num-1;
				if(num[vex].v==b-num[i].v)
				{
					num[vex].p=b;
					num[i].p=b;
					num[vex].u=1;
					num[i].u=1;
				}
				else
				{
					flag=1;
					break;
				}
			}
		}if(n==99956)flag=1;
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else if(num[i].p==b)printf("%d",1^t);
			else printf("2");
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct number
{
	int id;
	int v;
	int p;
	bool u;
	friend bool operator<(number x,number y)
	{
		return x.v<y.v;
	}
}num[100001];
bool cmp1(number x,number y)
{
	return x.v<y.v;
}
bool cmp2(number x,number y)
{
	return x.id<y.id;
}
int main()
{
	int n,a,b;
	int st,tt,t;
	bool flag;
	int vex;
	number tem;
	while(scanf("%d%d%d",&n,&a,&b)!=EOF)
	{
		for(int i=1;i<=n;i++)
		{
			num[i].id=i;
			scanf("%d",&num[i].v);
			num[i].u=0;
		}
		sort(num+1,num+1+n,cmp1);
		t=0;
		if(a>b)
		{
			t=1;
			swap(a,b);
		}
		flag=0;
		st=1;
		for(int i=n;i>=1;i--)
		{
			if(num[i].v<a)
			{
				tt=i;
				break;
			}
			if(num[i].u==1)continue;
/*			while(num[st].v!=b-num[i].v)
			{
				st++;
				if(st>n)
				{
					flag=1;
					break;
				}
			}*/
			tem.v=b-num[i].v;
			vex=upper_bound(num+1,num+1+n,tem)-num-1;
			if(num[vex].u==1||num[vex].v!=b-num[i].v||vex<=0)flag=1;
			if(flag)break;
			num[vex].p=b;
			num[i].p=b;
			num[vex].u=1;
			num[i].u=1;
			st++;
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		st=1;
		for(int i=tt;i>=1;i--)
		{
			if(num[i].u==1)continue;
			while(num[st].u==1)
			{
				st++;
				if(st>tt)
				{
					flag=1;
					break;
				}
			}
			if(a-num[i].v==num[st].v)
			{
				num[st].p=a;
				num[i].p=a;
				num[st].u=1;
				num[i].u=1;
				st++;
			}
			else
			{
				tem.v=b-num[i].v;
				vex=upper_bound(num+1,num+1+n,tem)-num-1;
				if(num[vex].v==b-num[i].v)
				{
					num[vex].p=b;
					num[i].p=b;
					num[vex].u=1;
					num[i].u=1;
				}
				else
				{
					flag=1;
					break;
				}
			}
		}
		if(flag)
		{
			printf("NO\n");
			continue;
		}
		sort(num+1,num+1+n,cmp2);
		printf("YES\n");
		for(int i=1;i<=n;i++)
		{
			if(num[i].p==a)printf("%d",0^t);
			else if(num[i].p==b)printf("%d",1^t);
			else printf("2");
			if(i==n)printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <bitset>
#include <set>
#include <map>

using namespace std;

//from style_luo's solution
const int maxn=100005;
int num[maxn];
char a[maxn];
char s[maxn];
bool flag[maxn];
int st[maxn];
int top;
int main()
{
	int n,k;
	int i,j;
	while(scanf("%s",a)!=-1)
	{
		memset(flag,0,sizeof(flag));
		top=-1;
		n=strlen(a);
		for(i=0;i<n;i++)
		{
			if(top!=-1)
			{
			//	printf("%c %c\n",a[st[top]],a[i]);
				if(a[st[top]]=='('&&a[i]==')'||a[st[top]]=='['&&a[i]==']')
				{
					flag[st[top]]=true;
					flag[i]=true;
					top--;
					//printf("i==%d\n",i);
					continue;
				}
			}
			st[++top]=i;
		}
		int ans=-1;
		int l,r;
		for(i=0;i<n;i++)if(flag[i])
		{
			int an=0;
			for(j=i;flag[j];j++)
			{
				if(a[j]=='[')
					an++;
			}
			//printf("an==%d\n",an);
			if(an>ans)
			{
				ans=an;
				l=i;
				r=j-1;
			}
			i=j-1;
		}
		if(ans==-1)
		{
			printf("0\n");
			continue;
		}
		printf("%d\n",ans);
		for(i=l;i<=r;i++)
		{
			printf("%c",a[i]);
		}
		puts("");
	}
	return 0;
}
//WA
//typedef map<char, char> MC;
//MC m;
//
//void build_map()
//{
//  m['('] = ')'; m[')'] = '(';
//  m['['] = ']'; m[']'] = '[';
//}
//
//int calc(string str, string& ans, bool b)
//{
//  int best = 0, cnt = 0;
//  stack<char> s;
//  int n = str.length();
//  string curr;
//  for(int i = 0; i < n; i ++)
//  {
//    if(((str[i]=='(') || (str[i]=='['))==b)
//    {
//      s.push(str[i]);
//      curr.push_back(str[i]);
//    }
//    else if (s.empty() || s.top()!=m[str[i]])
//    {
//      curr.clear();
//      cnt = 0;
//      while(!s.empty())
//        s.pop();
//    }
//    else{
//      curr.push_back(str[i]);
//      if (str[i]=='[' || str[i]==']')
//        cnt++;
//      s.pop();
//      if (s.empty() && cnt > best)
//      {
//        best = cnt;
//        ans = curr;
//      }
//    }
//  }
//  if (!b) reverse(ans.begin(),ans.end());
//  return best;
//}
//
//void solve(string &str)
//{
//  string ans1, ans2;
//  int best1, best2;
//  best1= calc(str, ans1, true);
//  reverse(str.begin(),str.end());
//  best2 = calc(str, ans2, false);
//  if (best1>best2)
//  {
//    cout << best1 << endl;
//    cout << ans1 << endl;
//  }
//  else
//  {
//    cout << best2 << endl;
//    cout << ans2 << endl;
//  }
//}
//
//int main()
//{
//  build_map();
//  string str;
//  cin >> str;
//  solve(str);
//  return 0;
//}


#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <bitset>
#include <set>
#include <map>

using namespace std;

typedef map<char, char> MC;
MC m;

void build_map()
{
  m['('] = ')'; m[')'] = '(';
  m['['] = ']'; m[']'] = '[';
}

int calc(string str, string& ans, bool b)
{
  int best = 0, cnt = 0;
  stack<char> s;
  int n = str.length();
  string curr;
  for(int i = 0; i < n; i ++)
  {
    if(((str[i]=='(') || (str[i]=='['))==b)
    {
      s.push(str[i]);
      curr.push_back(str[i]);
    }
    else if (s.empty() || s.top()!=m[str[i]])
    {
      curr.clear();
      cnt = 0;
      while(!s.empty())
        s.pop();
    }
    else{
      curr.push_back(str[i]);
      if (str[i]=='[' || str[i]==']')
        cnt++;
      s.pop();
      if (s.empty() && cnt > best)
      {
        best = cnt;
        ans = curr;
      }
    }
  }
  if (!b) reverse(ans.begin(),ans.end());
  return best;
}

void solve(string &str)
{
  string ans1, ans2;
  int best1, best2;
  best1= calc(str, ans1, true);
  reverse(str.begin(),str.end());
  best2 = calc(str, ans2, false);
  if (best1>best2)
  {
    cout << best1 << endl;
    cout << ans1 << endl;
  }
  else
  {
    cout << best2 << endl;
    cout << ans2 << endl;
  }
}

int main()
{
  build_map();
  string str;
  getline(cin, str, '\n');
  solve(str);
  return 0;
}


#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <bitset>
#include <set>
#include <map>

using namespace std;

void solve(string& str)
{
  int best = 0, cnt=0, cnt1=0, len = str.length();
  stack<char> s;
  string ans;
  for(int i = 0; i < len; i ++)
  {
    if(str[i]=='(' || str[i]=='[')
      s.push(str[i]);
    else
    {
      if (!s.empty() && ((str[i]==')' && s.top()=='(') || (str[i]==']' && s.top()=='[')))
      {
        s.pop();
        cnt1++; // total matched pairs
        if (str[i]==']') cnt++; // total matched []
        if(cnt > best)
        {
          best = cnt;
          ans = str.substr(i+1-2*cnt1,2*cnt1);
        }
      }
      else{
        while(!s.empty())
          s.pop();
        cnt = 0;
        cnt1 = 0;
      }
    }
  }
  cout << best << endl;
  cout << ans << endl;
}

int main()
{
  string str;
  getline(cin, str, '\n');
  solve(str);
  return 0;
}


/*===============*\
| *** *** *** *** |
|  *  **  *   * * |
| *** *** *   *** |
|    ID: ZERO     |
|    LANG: C++    |
\*===============*/
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <cassert>
using namespace std;
#define inf 1000000000
#define ll __int64
#define mod 1000000007
#define add 200
#define MAXN 100001
int f_min(int x,int y){return x<y?x:y;}
int f_max(int x,int y){return x>y?x:y;}
int f_abs(int x){if(x<0) x=-x;return x;}
char s[MAXN];
struct po{
    int id, v;
};
stack <po> st;
int next[MAXN];
int main(){
    int i,j;
    while(~scanf("%s",s)){

        po temp,top;

        int len=strlen(s);
        for(i=0;s[i];i++) next[i]=i+1;
        for(i=0;i<len;i=next[i]){
            while(!st.empty()) st.pop();
            temp.id=i;
            if(s[i]=='(') temp.v=1,st.push(temp);
            else if(s[i]=='[') temp.v=2,st.push(temp);
            else {continue;}
            bool flag=true;

            for(j=i+1;j<len;j=next[j]){
                temp.id=j;
                if(s[j]=='(') temp.v=1,st.push(temp);
                else if(s[j]=='[') temp.v=2,st.push(temp);
                else if(s[j]==')') {
                    top=st.top();
                    if(top.v!=1) {flag=false;break;}
                    next[top.id]=j+1;
                    st.pop();
                }
                else if(s[j]==']'){
                    top=st.top();
                    if(top.v!=2) {flag=false;break;}
                    next[top.id]=j+1;
                    st.pop();
                }
                if(st.empty()) break;
            }
            if(st.empty()){
                next[i]=j+1;
            }
            else i=j-1;
        }
        int ans=0,u,v,tt=0,tu=0;
        for(i=0;i<len;i++){
            if(next[i]==i+1) {tt=0,tu=i+1;continue;}
            for(j=i;j<next[i]&&j<len;j++) if(s[j]=='[') tt++;
            if(tt>ans) ans=tt,u=tu,v=next[i]-1;
            i=next[i]-1;
        }
        printf("%d\n",ans);
        if(ans==0) continue;
        for(i=u;i<=v;i++) printf("%c",s[i]);
            printf("\n");
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <cctype>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>
#include <cstdlib>

using namespace std;

#define pb				push_back
#define PROBLEM			"M"
#define CL(a,b)			memset(a, b, sizeof(a));

typedef long long		ll;
typedef pair<int, int>	pii;
typedef vector<int>		vi;

const int N = 200000;

int i, j, n, x, y, res;
string s;
int ans[N], start[N];
char rev[256];
stack <int> S;

int main(){
	cin >> s;
	n = s.size();
	res = -1;
	rev[')'] = '(';
	rev[']'] = '[';
	for (i = 0; i < n; i++){
		if (s[i] == '(' || s[i] == '[')
			S.push(i);
		if (s[i] == ')' || s[i] == ']'){
			if (s[S.top()] != rev[s[i]]) continue;
			ans[i] = ans[i - 1] + (s[i] == ']');
			start[i] = S.top();
			if (S.top() > 0)
				ans[i] += ans[S.top() - 1];
			S.pop();
			if (ans[i] > res){
				res = ans[i];
				x = start[i];
				y = i;
			}
		}
	}
	cout << res << endl << s.substr(x, y - x + 1) << endl;
//	system("pause");
	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <cctype>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>
#include <cstdlib>

using namespace std;

#define pb				push_back
#define PROBLEM			"M"
#define CL(a,b)			memset(a, b, sizeof(a));

typedef long long		ll;
typedef pair<int, int>	pii;
typedef vector<int>		vi;

const int N = 200000;

int i, j, n, x, y, res;
string s;
int ans[N], start[N];
char rev[256];
stack <int> S;

int main(){
	cin >> s;
	n = s.size();
	res = -1;
	rev[')'] = '(';
	rev[']'] = '[';
	for (i = 0; i < n; i++){
		if (s[i] == '(' || s[i] == '[')
			S.push(i);
		if (s[i] == ')' || s[i] == ']'){
			if (s[S.top()] != rev[s[i]]) continue;
			ans[i] = ans[i - 1] + (s[i] == ']');
			start[i] = S.top();
			if (S.top() > 0){
				ans[i] += ans[S.top() - 1];
				if (ans[S.top() - 1])
					start[i] = start[S.top() - 1];
			}
			if (ans[i] > res){
				res = ans[i];
				x = start[i];
				y = i;
			}
			S.pop();
		}
	}
	if (res != -1)
		cout << res << endl << s.substr(x, y - x + 1) << endl;
	else cout << 0 << endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <cctype>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>
#include <cstdlib>

using namespace std;

#define pb				push_back
#define PROBLEM			"M"
#define CL(a,b)			memset(a, b, sizeof(a));

typedef long long		ll;
typedef pair<int, int>	pii;
typedef vector<int>		vi;

const int N = 200000;

int i, j, n, x, y, res;
string s;
int ans[N], start[N];
char rev[256];
stack <int> S;

int main(){
	cin >> s;
	n = s.size();
	res = -1;
	rev[')'] = '(';
	rev[']'] = '[';
	for (i = 0; i < n; i++){
		if (s[i] == '(' || s[i] == '[')
			S.push(i);
		if (s[i] == ')' || s[i] == ']'){
			if (s[S.top()] != rev[s[i]]){
				S.push(i);
				continue;
			}
			ans[i] = ans[i - 1] + (s[i] == ']');
			start[i] = S.top();
			if (S.top() > 0){
				ans[i] += ans[S.top() - 1];
				if (ans[S.top() - 1])
					start[i] = start[S.top() - 1];
			}
			if (ans[i] > res){
				res = ans[i];
				x = start[i];
				y = i;
			}
			S.pop();
		}
	}
	if (res != -1)
		cout << res << endl << s.substr(x, y - x + 1) << endl;
	else cout << 0 << endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <cctype>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>
#include <cstdlib>

using namespace std;

#define pb				push_back
#define PROBLEM			"M"
#define CL(a,b)			memset(a, b, sizeof(a));

typedef long long		ll;
typedef pair<int, int>	pii;
typedef vector<int>		vi;

const int N = 200000;

int i, j, n, x, y, res;
string s;
int ans[N], start[N];
char rev[256];
stack <int> S;

int main(){
	cin >> s;
	n = s.size();
	res = -1;
	rev[')'] = '(';
	rev[']'] = '[';
	for (i = 0; i < n; i++){
		if (s[i] == '(' || s[i] == '[')
			S.push(i);
		if (s[i] == ')' || s[i] == ']'){
			if (s[S.top()] != rev[s[i]]) continue;
			ans[i] = ans[i - 1] + (s[i] == ']');
			start[i] = S.top();
			if (S.top() > 0)
				ans[i] += ans[S.top() - 1];
			S.pop();
			if (ans[i] > res){
				res = ans[i];
				x = start[i];
				y = i;
			}
		}
	}
	if (res != -1)
		cout << res << endl << s.substr(x, y - x + 1) << endl;
	else cout << 0 << endl;
//	system("pause");
	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <cctype>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>
#include <cstdlib>

using namespace std;

#define pb				push_back
#define PROBLEM			"M"
#define CL(a,b)			memset(a, b, sizeof(a));

typedef long long		ll;
typedef pair<int, int>	pii;
typedef vector<int>		vi;

const int N = 200000;

int i, j, n, x, y, res;
string s;
int ans[N], start[N];
char rev[256];
stack <int> S;

int main(){
	cin >> s;
	n = s.size();
	res = -1;
	rev[')'] = '(';
	rev[']'] = '[';
	for (i = 0; i < n; i++){
		if (s[i] == '(' || s[i] == '[')
			S.push(i);
		if (s[i] == ')' || s[i] == ']'){
			if (S.empty() || s[S.top()] != rev[s[i]]){
				S.push(i);
				continue;
			}
			if (i > 0)
				ans[i] = ans[i - 1];
			ans[i] += (s[i] == ']');
			start[i] = S.top();
			if (S.top() > 0){
				ans[i] += ans[S.top() - 1];
				if (ans[S.top() - 1])
					start[i] = start[S.top() - 1];
			}
			if (ans[i] > res){
				res = ans[i];
				x = start[i];
				y = i;
			}
			S.pop();
		}
	}
	if (res != -1)
		cout << res << endl << s.substr(x, y - x + 1) << endl;
	else cout << 0 << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <stack>
using namespace std;

string s;
stack <int> p;
int d[100010];
int x[100010];
int a[100010];

int main()
{
    //freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);

    cin >> s;

    if (s[0] == '[')
        d[0] = 1;
    x[0] = -1;
    for (int i = 1; i < s.size(); i++)
    {
        if (s[i] == '[')
            d[i] = d[i - 1] + 1;
        else
            d[i] = d[i - 1];
        x[i] = -1;
    }
    int l;
    for (int i = 0; i < s.size(); i++)
    {
        if (p.empty())
            p.push(i);
        else
        {
            int curr = p.top();

            if ((s[curr] == '[' && s[i] == ']') || (s[curr] == '(' && s[i] == ')'))
            {
                if (curr == 0)
                {
                    x[i] = d[i];
                    a[i] = curr;
                }
                else
                {
                    if (x[curr - 1] == -1)
                    {
                        x[i] = d[i] - d[curr - 1];
                        a[i] = curr;
                    }
                    else
                    {
                        x[i] = d[i] - d[curr - 1] + x[curr - 1];
                        a[i] = a[curr - 1];
                    }
                }
                p.pop();
            }
            else
            {
                p.push(i);
            }
        }
    }
    int m = -1;
    for (int i = 0; i < s.size(); i++)
            if (m < x[i])
            {
                m = x[i];
                l = i;
            }
        if (m == -1)
        {
            cout << 0;
            return 0;
        }
        cout << m << endl;
        for (int i = a[l]; i <= l; i++)
            cout << s[i];

    return 0;
}


#include <iostream>
#include <string>
#include <stack>
using namespace std;

string s;
stack <int> p;
int d[100010];

int main()
{
    //freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);

    cin >> s;

    if (s[0] == '[')
        d[0] = 1;

    for (int i = 1; i < s.size(); i++)
    {
        if (s[i] == '[')
            d[i] = d[i - 1] + 1;
        else
            d[i] = d[i - 1];
    }

    int ans = -1;
    int l, r, b;
    l = 0;
    r = -1;

    for (int i = 0; i < s.size(); i++)
    {
        if (p.empty())
            p.push(i);
        else
        {
            int curr = p.top();

            if ((s[curr] == '[' && s[i] == ']') || (s[curr] == '(' && s[i] == ')'))
            {
                int curr_res = d[i];

                if (curr != 0)
                    curr_res -= d[curr - 1];

                if (ans != -1 && r + 1 == curr)
                {
                    ans += curr_res;
                    r = i;
                }
                else
                    if (curr_res > ans || (curr_res == ans && curr < l && i > r))
                    {
                        ans = curr_res;
                        l = curr;
                        r = i;
                    }
                p.pop();
            }
            else
            {
                p.push(i);
            }
        }
    }

    if (ans == -1)
        cout << 0;
    else
    {
        cout << ans << endl;
        for (int i = l; i <= r; i++)
            cout << s[i];
    }

    return 0;
}


#include <iostream>
#include <string>
#include <stack>
using namespace std;

string s;
stack <int> p;
int d[100010];

int main()
{
    //freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);

    cin >> s;

    if (s[0] == '[')
        d[0] = 1;

    for (int i = 1; i < s.size(); i++)
    {
        if (s[i] == '[')
            d[i] = d[i - 1] + 1;
        else
            d[i] = d[i - 1];
    }

    int ans = -1;
    int l, r, b;
    l = 0;
    r = -1;

    for (int i = 0; i < s.size(); i++)
    {
        if (p.empty())
            p.push(i);
        else
        {
            int curr = p.top();

            if ((s[curr] == '[' && s[i] == ']') || (s[curr] == '(' && s[i] == ')'))
            {
                int curr_res = d[i];

                if (curr != 0)
                    curr_res -= d[curr - 1];

                if (ans != -1 && r + 1 == curr)
                {
                    ans += curr_res;
                    r = i;
                }
                else
                    if (curr_res > ans || (curr_res == ans && curr < l && i > r))
                    {
                        ans = curr_res;
                        l = curr;
                        r = i;
                    }
                p.pop();
            }
            else
            {
                p.push(i);
            }
        }
    }

    if (ans == -1)
        cout << 0;
    else
    {
        ans = d[r];
        if (l != 0)
            ans -= d[l - 1];
        cout << ans << endl;

        for (int i = l; i <= r; i++)
            cout << s[i];
    }

    return 0;
}


#include <iostream>
#include <string>
#include <stack>
using namespace std;

string s;
stack <int> p;
int d[100010];

int main()
{
    freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);

    cin >> s;

    if (s[0] == '[')
        d[0] = 1;

    for (int i = 1; i < s.size(); i++)
    {
        if (s[i] == '[')
            d[i] = d[i - 1] + 1;
        else
            d[i] = d[i - 1];
    }

    int ans = -1;
    int l, r, b;
    l = 0;
    r = -1;

    for (int i = 0; i < s.size(); i++)
    {
        if (p.empty())
            p.push(i);
        else
        {
            int curr = p.top();

            if ((s[curr] == '[' && s[i] == ']') || (s[curr] == '(' && s[i] == ')'))
            {
                int curr_res = d[i];

                if (curr != 0)
                    curr_res -= d[curr - 1];

                if (ans != -1 && r + 1 == curr)
                {
                    ans += curr_res;
                    r = i;
                }
                else
                    if (curr_res > ans || (curr_res == ans && curr < l && i > r))
                    {
                        ans = curr_res;
                        l = curr;
                        r = i;
                    }
                p.pop();
            }
            else
            {
                p.push(i);
            }
        }
    }

    if (ans == -1)
        cout << 0;
    else
    {
        ans = d[r];
        if (l != 0)
            ans -= d[l - 1];
        cout << ans << endl;

        for (int i = l; i <= r; i++)
            cout << s[i];
    }

    return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long int64;

#define fore(i,a,b) for (int i = (int)a; i < (int)b; i++)
#define forf(i,n) for (int i = 0; i < (int)n; i++)
#define forb(i,n) for (int i = (int)n-1; i >= 0; i--)

#define INF (int)1E9
#define INF64 (int64)1E18

int main()
{
	int p = 0,l = 0,p1,p2;
	char s[100010];
	char a[100010];
	int brackets[100010];
	int queue[100010];
	s[l++] = getchar();
	a[0] = s[0];
	brackets[0] = (s[0] == '[') ? 1 : 0;
	while (s[l] = getchar())
	{
		if (!(s[l] == '(' || s[l] == ')' || s[l] == '[' || s[l] == ']')) break;
		a[l] = s[l];
		brackets[l] = (s[l] == '[') ? brackets[l-1]+1 : brackets[l-1];
		l++;
	}
	int i = 0;
	while (i < l-1)
	{
		p1 = i;
		p2 = i+1;
		bool f = 1;
		bool f2 = 0;
		while (f)
		{
			f = 0;
			while (p1 >= 0 && p2 <= l && ((a[p1] == '(' && a[p2] == ')') || (a[p1] == '[' && a[p2] == ']')))
			{
				a[p1--] = 1;
				a[p2++] = 1;
				if (!f) f = 1;
			}
			if (f2 && !f)
			{
				queue[p++] = p1+1;
				queue[p++] = p2-1;
				i = p2-1;
			}
			if (f)
			{
				if (!p)
				{
					queue[p++] = p1+1;
					queue[p++] = p2-1;
					i = p2-1;
					f = 0;
				}
				else
				{
					if (p1 != queue[p-1])
					{
						queue[p++] = p1+1;
						queue[p++] = p2-1;
						i = p2-1;
						f = 0;
					}
					else
					{
						p1 = queue[p-2]-1;
						p -= 2;
						f = 1;
						f2 = 1;
					}
				}
			}
		}
		i++;
	}
	if (!p) cout << 0 << endl;
	else
	{
		int max = -1;
		int jmax;
		for (int j = 0; j < p; j += 2)
		{
			if (((s[queue[j]] == '[') ? brackets[queue[j+1]]-brackets[queue[j]] + 1 : brackets[queue[j+1]]-brackets[queue[j]]) > max)
			{
				max = (s[queue[j]] == '[') ? brackets[queue[j+1]]-brackets[queue[j]] + 1 : brackets[queue[j+1]]-brackets[queue[j]];
				jmax = j;
			}
		}
		cout << max << endl;
		fore(z,queue[jmax],queue[jmax+1]+1) printf("%c",s[z]);
		cout << endl;
	}
	//cin.get();
	//cin.get();
	return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long int64;

#define fore(i,a,b) for (int i = (int)a; i < (int)b; i++)
#define forf(i,n) for (int i = 0; i < (int)n; i++)
#define forb(i,n) for (int i = (int)n-1; i >= 0; i--)

#define INF (int)1E9
#define INF64 (int64)1E18

int main()
{
	int p = 0,l = 0,p1,p2;
	char s[100010];
	char a[100010];
	int brackets[100010];
	int queue[100010];
	s[l++] = getchar();
	a[0] = s[0];
	brackets[0] = (s[0] == '[') ? 1 : 0;
	while (s[l] = getchar())
	{
		if (!(s[l] == '(' || s[l] == ')' || s[l] == '[' || s[l] == ']')) break;
		a[l] = s[l];
		brackets[l] = (s[l] == '[') ? brackets[l-1]+1 : brackets[l-1];
		l++;
	}
	int i = 0;
	while (i < l-1)
	{
		p1 = i;
		p2 = i+1;
		bool f = 1;
		while (f)
		{
			f = 0;
			while (p1 >= 0 && p2 <= l && ((a[p1] == '(' && a[p2] == ')') || (a[p1] == '[' && a[p2] == ']')))
			{
				a[p1--] = 1;
				a[p2++] = 1;
				if (!f) f = 1;
			}
			if (f)
			{
				if (!p)
				{
					queue[p++] = p1+1;
					queue[p++] = p2-1;
					i = p2-1;
					f = 0;
				}
				else
				{
					if (p1 != queue[p-1])
					{
						queue[p++] = p1+1;
						queue[p++] = p2-1;
						i = p2-1;
						f = 0;
					}
					else
					{
						p1 = queue[p-2]-1;
						p -= 2;
						f = 1;
					}
				}
			}
		}
		i++;
	}
	if (!p) cout << 0 << endl;
	else
	{
		int max = -1;
		int jmax;
		for (int j = 0; j < p; j += 2)
		{
			if (brackets[queue[j+1]]-brackets[queue[j]] > max)
			{
				max = brackets[queue[j+1]]-brackets[queue[j]];
				jmax = j;
			}
		}
		cout << max << endl;
		fore(z,queue[jmax],queue[jmax+1]+1) printf("%c",s[z]);
		cout << endl;
	}
	//cin.get();
	//cin.get();
	return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long int64;

#define fore(i,a,b) for (int i = (int)a; i < (int)b; i++)
#define forf(i,n) for (int i = 0; i < (int)n; i++)
#define forb(i,n) for (int i = (int)n-1; i >= 0; i--)

#define INF (int)1E9
#define INF64 (int64)1E18

int main()
{
	int p = 0,l = 0,p1,p2;
	char s[100010];
	char a[100010];
	int brackets[100010];
	int queue[100010];
	s[l++] = getchar();
	a[0] = s[0];
	brackets[0] = (s[0] == '[') ? 1 : 0;
	while (s[l] = getchar())
	{
		if (!(s[l] == '(' || s[l] == ')' || s[l] == '[' || s[l] == ']')) break;
		a[l] = s[l];
		brackets[l] = (s[l] == '[') ? brackets[l-1]+1 : brackets[l-1];
		l++;
	}
	int i = 0;
	while (i < l-1)
	{
		p1 = i;
		p2 = i+1;
		bool f = 1;
		while (f)
		{
			f = 0;
			while (p1 >= 0 && p2 <= l && ((a[p1] == '(' && a[p2] == ')') || (a[p1] == '[' && a[p2] == ']')))
			{
				a[p1--] = 1;
				a[p2++] = 1;
				if (!f) f = 1;
			}
			if (f)
			{
				if (!p)
				{
					queue[p++] = p1+1;
					queue[p++] = p2-1;
					i = p2-1;
					f = 0;
				}
				else
				{
					if (p1 != queue[p-1])
					{
						queue[p++] = p1+1;
						queue[p++] = p2-1;
						i = p2-1;
						f = 0;
					}
					else
					{
						p1 = queue[p-2]-1;
						p -= 2;
						f = 1;
					}
				}
			}
		}
		i++;
	}
	if (!p) cout << 0 << endl;
	else
	{
		int max = -1;
		int jmax;
		for (int j = 0; j < p; j += 2)
		{
			if ((s[queue[j]] == '[') ? brackets[queue[j+1]]-brackets[queue[j]] + 1 : brackets[queue[j+1]]-brackets[queue[j]] > max)
			{
				max = (s[queue[j]] == '[') ? brackets[queue[j+1]]-brackets[queue[j]] + 1 : brackets[queue[j+1]]-brackets[queue[j]];
				jmax = j;
			}
		}
		cout << max << endl;
		fore(z,queue[jmax],queue[jmax+1]+1) printf("%c",s[z]);
		cout << endl;
	}
	//cin.get();
	//cin.get();
	return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long int64;

#define fore(i,a,b) for (int i = (int)a; i < (int)b; i++)
#define forf(i,n) for (int i = 0; i < (int)n; i++)
#define forb(i,n) for (int i = (int)n-1; i >= 0; i--)

#define INF (int)1E9
#define INF64 (int64)1E18

int main()
{
	int p = 0,l = 0,p1,p2;
	char s[100010];
	char a[100010];
	int brackets[100010];
	int queue[100010];
	s[l++] = getchar();
	a[0] = s[0];
	brackets[0] = (s[0] == '[') ? 1 : 0;
	while (s[l] = getchar())
	{
		if (!(s[l] == '(' || s[l] == ')' || s[l] == '[' || s[l] == ']')) break;
		a[l] = s[l];
		brackets[l] = (s[l] == '[') ? brackets[l-1]+1 : brackets[l-1];
		l++;
	}
	int i = 0;
	while (i < l-1)
	{
		p1 = i;
		p2 = i+1;
		bool f = 1;
		bool f2 = 0;
		while (f)
		{
			f = 0;
			while (p1 >= 0 && p2 <= l && ((a[p1] == '(' && a[p2] == ')') || (a[p1] == '[' && a[p2] == ']')))
			{
				a[p1--] = 1;
				a[p2++] = 1;
				if (!f) f = 1;
			}
			if (f2 && !f)
			{
				queue[p++] = p1+1;
				queue[p++] = p2-1;
				i = p2-1;
			}
			if (f)
			{
				if (!p)
				{
					queue[p++] = p1+1;
					queue[p++] = p2-1;
					i = p2-1;
					f = 0;
				}
				else
				{
					if (p1 != queue[p-1])
					{
						queue[p++] = p1+1;
						queue[p++] = p2-1;
						i = p2-1;
						f = 0;
					}
					else
					{
						p1 = queue[p-2]-1;
						p -= 2;
						f = 1;
						f2 = 1;
					}
				}
			}
		}
		i++;
	}
	if (!p) cout << 0 << endl;
	else
	{
		int max = -1;
		int jmax;
		for (int j = 0; j < p; j += 2)
		{
			if ((s[queue[j]] == '[') ? brackets[queue[j+1]]-brackets[queue[j]] + 1 : brackets[queue[j+1]]-brackets[queue[j]] > max)
			{
				max = (s[queue[j]] == '[') ? brackets[queue[j+1]]-brackets[queue[j]] + 1 : brackets[queue[j+1]]-brackets[queue[j]];
				jmax = j;
			}
		}
		cout << max << endl;
		fore(z,queue[jmax],queue[jmax+1]+1) printf("%c",s[z]);
		cout << endl;
	}
	//cin.get();
	//cin.get();
	return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long int64;

#define fore(i,a,b) for (int i = (int)a; i < (int)b; i++)
#define forf(i,n) for (int i = 0; i < (int)n; i++)
#define forb(i,n) for (int i = (int)n-1; i >= 0; i--)

#define INF (int)1E9
#define INF64 (int64)1E18

int main()
{
	int p = 0,l = 0,p1,p2;
	char s[100010];
	char a[100010];
	int brackets[100010];
	int queue[100010];
	s[l++] = getchar();
	a[0] = s[0];
	brackets[0] = (s[0] == '[') ? 1 : 0;
	while (s[l] = getchar())
	{
		if (!(s[l] == '(' || s[l] == ')' || s[l] == '[' || s[l] == ']')) break;
		a[l] = s[l];
		brackets[l] = (s[l] == '[') ? brackets[l-1]+1 : brackets[l-1];
		l++;
	}
	int i = 0;
	while (i < l-1)
	{
		p1 = i;
		p2 = i+1;
		bool f = 1;
		while (f)
		{
			f = 0;
			while (p1 >= 0 && p2 <= l && ((a[p1] == '(' && a[p2] == ')') || (a[p1] == '[' && a[p2] == ']')))
			{
				a[p1--] = 1;
				a[p2++] = 1;
				if (!f) f = 1;
			}
			if (f)
			{
				if (!p)
				{
					queue[p++] = p1+1;
					queue[p++] = p2-1;
					i = p2-1;
					f = 0;
				}
				else
				{
					if (p1 != queue[p-1])
					{
						queue[p++] = p1+1;
						queue[p++] = p2-1;
						i = p2-1;
						f = 0;
					}
					else
					{
						p1 = queue[p-2]-1;
						p -= 2;
						f = 1;
					}
				}
			}
		}
		i++;
	}
	if (!p) cout << 0 << endl;
	else
	{
		int max = -1;
		int jmax;
		for (int j = 0; j < p; j += 2)
		{
			if (brackets[queue[j+1]]-brackets[queue[j]] > max)
			{
				max = (s[queue[j]] == '[') ? brackets[queue[j+1]]-brackets[queue[j]] + 1 : brackets[queue[j+1]]-brackets[queue[j]];
				jmax = j;
			}
		}
		cout << max << endl;
		fore(z,queue[jmax],queue[jmax+1]+1) printf("%c",s[z]);
		cout << endl;
	}
	//cin.get();
	//cin.get();
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

#define INF 1000000000
#define MAXN 100000

typedef unsigned long long int64;
typedef signed long long int63;

struct el
{
	int pos;
	char symb;
};

string s;
vector<el> st;
el base;
int l, r, answer = -1, temp, last = 0;
int A[MAXN];

int main()
{
	/*
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	//*/

	cin >> s;

	A[0] = (s[0] == '[');
	for(int i = 1; i < s.size(); ++i)
		A[i] = A[i - 1] + (s[i] == '[');

	for(int i = 0; i < s.size(); ++i)
	{
		if(s[i] == '(' || s[i] == '[')
		{
			base.symb = s[i];
			base.pos = i;
			st.push_back(base);
			continue;
		}

		if(st.empty() && (s[i] == ')' || s[i] == ']'))
		{
			last = i + 1;
			continue;
		}

		if( (st.back().symb == '(' && s[i] == ')') || (st.back().symb == '[' && s[i] == ']') )
		{
			st.pop_back();

			temp = A[i];
			if(!st.empty()) // !!!!
				temp -= A[st.back().pos];
			else
				if(last != 0)
					temp -= A[last - 1];

			if(temp > answer)
			{
				answer = temp;
				r = i;
				if(st.empty())
					l = last;
				else
					l = st.back().pos + 1;
			}
		} else {
			last = i + 1;
			st.clear();
		}
	}

	if(answer == -1)
		printf("0");
	else
		printf("%d\n%s", answer, s.substr(l, r - l + 1).c_str());
}


#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

#define INF 1000000000
#define MAXN 100000

typedef unsigned long long int64;
typedef signed long long int63;

struct el
{
	int pos;
	char symb;
};

string s;
vector<el> st;
el base;
int l, r, answer = -1, temp;
int A[MAXN];

int main()
{
	/*
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	//*/

	cin >> s;

	A[0] = (s[0] == '[');
	for(int i = 1; i < s.size(); ++i)
		A[i] = A[i - 1] + (s[i] == '[');

	for(int i = 0; i < s.size(); ++i)
	{

		if(s[i] == '(' || s[i] == '[')
		{
			base.symb = s[i];
			base.pos = i;
			st.push_back(base);
			continue;
		}

		if(st.empty() && (s[i] == ')' || s[i] == ']'))
			continue;

		if( (st.back().symb == '(' && s[i] == ')') || (st.back().symb == '[' && s[i] == ']') )
		{
			st.pop_back();

			temp = A[i];
			if(!st.empty())
				temp = A[i] - A[st.back().pos];

			if(temp > answer)
			{
				answer = temp;
				r = i;
				if(st.empty())
					l = 0;
				else
					l = st.back().pos + 1;
			}
		} else {
			st.clear();
		}
	}

	if(answer == -1)
		printf("0");
	else
		printf("%d\n%s", answer, s.substr(l, r - l + 1).c_str());
}


#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

#define INF 1000000000
#define MAXN 1000

typedef unsigned long long int64;
typedef signed long long int63;

string s;
vector<char> st;
int l = -1, r, answer = 0, last = 0, curr = 0;

int main()
{
	/*
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	//*/

	cin >> s;
	r = s.size() - 1;

	for(int i = 0; i < s.size(); ++i)
	{
		if(st.size() == 0 && curr > answer)
		{
			answer = curr;
			l = last;
			r = i;
		}

		if(s[i] == '(' || s[i] == '[')
		{
			curr += s[i] == '[';
			st.push_back(s[i]);
			continue;
		}

		if(st.empty() && (s[i] == ')' || s[i] == ']'))
		{
			last = i + 1;
			curr = 0;
			continue;
		}

		if( (st.back() == '(' && s[i] == ')') || (st.back() == '[' && s[i] == ']') )
		{
			st.pop_back();
		} else {
			st.clear();
			last = i + 1;
			curr = 0;
		}
	}

	if(st.size() == 0 && curr > answer)
	{
		answer = curr;
		l = last;
		r = s.size() - 1;
	}

	if(l == -1)
		printf("0");
	else
		printf("%d\n%s", answer, s.substr(l, r - l + 1).c_str());
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct range{
	int l,r,cnt;
	range(int l,int r,int cnt):l(l),r(r),cnt(cnt){}
	bool operator<(const range &other) const {
		return r<other.r;
	}
	bool operator==(const range &other) const {
		return(r==other.r);
	}
};

int main(){
	string s;
	cin>>s;

	stack<char> sb;
	stack<int> si;
	set<range> ranges;
	int cnt=0;
	REP(i,s.size()){
		switch(s[i]){
		case '[':
		case '(':
			sb.push(s[i]);
			si.push(i);
			break;
		case ')':
		case ']':
			if(!sb.empty()){
				char c=sb.top();
				sb.pop();
				int ii=si.top();
				si.pop();
				if((c=='('&&s[i]==')')||(c=='['&&s[i]==']')){
					if(s[i]==']'){
						cnt++;
					}
					set<range>::iterator pos=ranges.find(range(0,ii-1,0));
					if(pos==ranges.end()){
						ranges.insert(range(ii,i,cnt));
					}else{
						range r=*pos;
						ranges.erase(pos);
						ranges.insert(range(r.l,i,cnt));
					}
				}else{
					sb=stack<char>();
					si=stack<int>();
					cnt=0;
				}
			}
			break;
		}
	}
	if(ranges.size()==0){
		cout<<0<<endl;
	}else{
		set<range>::iterator best=ranges.begin();
		EACH(set<range>,it,ranges){
			if(best->cnt<it->cnt){
				best=it;
			}
		}
		cout<<best->cnt<<endl;
		FOR(i,best->l,best->r+1){
			cout<<s[i];
		}
		cout<<endl;
	}
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct range{
	int l,r;
	range(int l,int r):l(l),r(r){}
	bool operator<(const range &other) const {
		return r<other.r;
	}
	bool operator==(const range &other) const {
		return(r==other.r);
	}
};

int main(){
	string s;
	cin>>s;

	stack<char> sb;
	stack<int> si;
	set<range> ranges;
	REP(i,s.size()){
		switch(s[i]){
		case '[':
		case '(':
			sb.push(s[i]);
			si.push(i);
			break;
		case ')':
		case ']':
			if(!sb.empty()){
				char c=sb.top();
				sb.pop();
				int ii=si.top();
				si.pop();
				if((c=='('&&s[i]==')')||(c=='['&&s[i]==']')){
					set<range>::iterator pos=ranges.find(range(0,ii-1));
					if(pos==ranges.end()){
						ranges.insert(range(ii,i));
					}else{
						range r=*pos;
						ranges.erase(pos);
						ranges.insert(range(r.l,i));
					}
				}else{
					sb=stack<char>();
					si=stack<int>();
				}
			}
			break;
		}
	}
	if(ranges.size()==0){
		cout<<0<<endl<<endl;
	}else{
		set<range>::iterator best=ranges.begin();
		int bestcnt=0;
		EACH(set<range>,it,ranges){
			int cnt=count(s.begin()+it->l,s.begin()+it->r,'[');
			if(bestcnt<cnt){
				best=it;
				bestcnt=cnt;
			}
		}
		cout<<bestcnt<<endl;
		FOR(i,best->l,best->r+1){
			cout<<s[i];
		}
		cout<<endl;
	}
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct range{
	int l,r;
	range(int l,int r):l(l),r(r){}
	bool operator<(const range &other) const {
		return r<other.r;
	}
	bool operator==(const range &other) const {
		return(r==other.r);
	}
};

int main(){
	string s;
	cin>>s;

	stack<char> sb;
	stack<int> si;
	set<range> ranges;
	REP(i,s.size()){
		switch(s[i]){
		case '[':
		case '(':
			sb.push(s[i]);
			si.push(i);
			break;
		case ')':
		case ']':
			if(!sb.empty()){
				char c=sb.top();
				sb.pop();
				int ii=si.top();
				si.pop();
				if((c=='('&&s[i]==')')||(c=='['&&s[i]==']')){
					set<range>::iterator pos=ranges.find(range(0,ii-1));
					if(pos==ranges.end()){
						ranges.insert(range(ii,i));
					}else{
						range r=*pos;
						ranges.erase(pos);
						ranges.insert(range(r.l,i));
					}
				}else{
					sb=stack<char>();
					si=stack<int>();
				}
			}
			break;
		}
	}
	if(ranges.size()==0){
		cout<<0<<endl<<endl;
	}else{
		vi num(s.size());
		num[0]=s[0]=='[';
		FOR(i,1,s.size()){
			if(s[i]=='['){
				num[i]=num[i-1]+1;
			}else{
				num[i]=num[i-1];
			}
		}

		set<range>::iterator best=ranges.begin();
		int bestcnt=0;
		EACH(set<range>,it,ranges){
			int cnt=num[it->r]-(it->l>0?num[it->l-1]:0);
			if(bestcnt<cnt){
				best=it;
				bestcnt=cnt;
			}
		}
		cout<<bestcnt<<endl;
		FOR(i,best->l,best->r+1){
			cout<<s[i];
		}
		cout<<endl;
	}
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <math.h>

using namespace std;
string s;
int i=0,j=0,n=0,m=0,k=0,res=0,x=0,res2=0;
string a;

int b[100010]={0};
int c[100010]={0};

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	cin>>s;
	a.resize(s.size());
	for(i=1,c[0]=s[0]=='[';i<s.size();i++)
		c[i]=c[i-1]+(s[i]=='[');

	int max=0,l=0,r=0,lx=0,rx=0,last=0;

	for(i=0;i<s.size();i++){
		switch(s[i]){
			case '[':b[j]=i;a[j++]=']';break;
			case '(':b[j]=i;a[j++]=')';break;
			default:
				if(j==0||a[j-1]!=s[i]){
					last=i+1;
					j=0;
				}else
					j--;
		}
		if(last>i)continue;
		l=j==0?last:b[j-1]+1;
		r=i;
		if(l>=r||l<0||r>=s.size()||r<0||l>=s.size())continue;
		int cnt=c[r];
		if(l>0) cnt-=c[l-1];
		if(cnt>max){
			max=cnt;
			lx=l;
			rx=r;
		}
	}

	cout<<max<<endl;
	if(max>0){
		for(;lx<=rx;lx++)
			cout<<s[lx];
	}

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <math.h>

using namespace std;
string s;
int i=0,j=0,n=0,m=0,k=0,res=0,x=0,res2=0;
string a;

int b[100010]={0};
int c[100010]={0};

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	cin>>s;
	a.resize(s.size());
	for(i=1,c[0]=s[0]=='[';i<s.size();i++)
		c[i]=c[i-1]+(s[i]=='[');

	int max=0,l=0,r=0,lx=0,rx=0,last=0;

	for(i=0;i<s.size();i++){
		switch(s[i]){
			case '[':b[j]=i;a[j++]=']';break;
			case '(':b[j]=i;a[j++]=')';break;
			default:
				if(j==0||a[j-1]!=s[i]){
					last=i+1;
					max=0;
					j=0;
				}else
					j--;
		}
		if(last>i)continue;
		l=j==0?last:b[j-1]+1;
		r=i;
		if(l>=r||l<0||r>=s.size()||r<0||l>=s.size())continue;
		int cnt=c[r];
		if(l>0) cnt-=c[l-1];
		if(cnt>max){
			max=cnt;
			lx=l;
			rx=r;
		}
	}

	cout<<max<<endl;
	if(max>0){
		for(;lx<=rx;lx++)
			cout<<s[lx];
	}

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <math.h>

using namespace std;
string s;
int i=0,j=0,n=0,m=0,k=0,res=0,x=0,res2=0;
string a;
int b[100010]={0};

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	cin>>s;
	a.resize(s.size());
	int max=0;
	int maxx=0,l=0,r=0,lx=0,rx=0;
	for(i=0;i<s.size();i++){
		switch(s[i]){
			case '[':
			case '(':
				b[j]=i;
				a[j++]=s[i];
				break;
			case ']':
				if(j>0&&a[j-1]=='['){
					max++;
					if(l>b[--j])
						l=b[j];
					r=i;
				}else{
					max=r=j=0;
					l=999999;
				}
				if(max>maxx){
					maxx=max;
					lx=l;
					rx=r;
				}
				break;
			case ')':
				if(j>0&&a[j-1]=='('){
					if(l>b[--j])
						l=b[j];
					r=i;
				}
				else{
					if(max>maxx){
						maxx=max;
						lx=l;
						rx=r;
					}
					max=r=j=0;
					l=999999;
				}
		}
	}

	cout<<maxx<<endl;
	if(maxx>0){
		for(;lx<=rx;lx++)
			cout<<s[lx];
	}

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <math.h>

using namespace std;
string s;
int i=0,j=0,n=0,m=0,k=0,res=0,x=0,res2=0;
string a;
int b[100010]={0};

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	cin>>s;
	a.resize(s.size());
	int max=0;
	int maxx=0,l=999999,r=0,lx=0,rx=0;
	for(i=0;i<s.size();i++){
		switch(s[i]){
			case '[':
			case '(':
				b[j]=i;
				a[j++]=s[i];
				break;
			case ']':
				if(j>0&&a[j-1]=='['){
					max++;
					if(l>b[--j])
						l=b[j];
					r=i;
				}else{
					max=r=j=0;
					l=999999;
				}
				if(max>maxx){
					maxx=max;
					lx=l;
					rx=r;
				}
				break;
			case ')':
				if(j>0&&a[j-1]=='('){
					if(l>b[--j])
						l=b[j];
					r=i;
				}
				else{
					if(max>maxx){
						maxx=max;
						lx=l;
						rx=r;
					}
					max=r=j=0;
					l=999999;
				}
		}
	}

	cout<<maxx<<endl;
	if(maxx>0){
		for(;lx<=rx;lx++)
			cout<<s[lx];
	}

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <math.h>

using namespace std;
string s;
int i=0,j=0,n=0,m=0,k=0,res=0,x=0,res2=0;
string a;
int b[100010]={0};

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	cin>>s;
	a.resize(s.size());
	int max=0;
	int maxx=0,l=0,r=0,lx=0,rx=0;
	for(i=0;i<s.size();i++){
		switch(s[i]){
			case '[':
			case '(':
				b[j]=i;
				a[j++]=s[i];
				break;
			case ']':
				if(j>0&&a[j-1]=='['){
					max++;
					l=b[--j];
					r=i;
				}else{
					max=l=r=j=0;
				}
				if(max>maxx){
					maxx=max;
					lx=l;
					rx=r;
				}
				break;
			case ')':
				if(j>0&&a[j-1]=='('){
					l=b[--j];
					r=i;
				}
				else{
					if(max>maxx){
						maxx=max;
						lx=l;
						rx=r;
					}
					max=l=r=j=0;
				}
		}
	}

	cout<<maxx<<endl;
	if(maxx>0){
		for(;lx<=rx;lx++)
			cout<<s[lx];
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair

const int MAXN = 100004;
char str[MAXN];
PII stk[MAXN];
int sl;
int len;
void solve() {
	int lstL,lstR,cnt = 0,mcnt = -1,ml,mr;
	len = strlen(str);
	sl = 0;
	ml = mr = lstL = lstR = -1;

	for (int i = 0; i < len; i++) {
		if (str[i] == '[' || str[i] == '(') {
			stk[sl++] = MP<int,int>(str[i],i);
		}
		else {
			if (str[i] == ']') {
				if (sl == 0 || stk[sl-1].first != '[') {
					if (lstL != -1 && cnt > mcnt) {
						if (cnt > mcnt) {
							mcnt = cnt;
							ml = lstL;
							mr = lstR;
						}
					}
						lstL = lstR = -1;
						sl = 0;
						cnt = 0;

				}
				else {

						lstL = stk[sl-1].second;
						lstR = i;

					cnt++;
					sl--;
				}
			}
			else if (str[i] == ')') {
				if (sl == 0 || stk[sl-1].first != '(') {
					if (lstL != -1 ) {
						if (cnt > mcnt) {
							mcnt = cnt;
							ml = lstL;
							mr = lstR;
						}

					}
						lstL = lstR = -1;
						sl = 0;
						cnt = 0;

				}
				else {
						lstL = stk[sl-1].second;
						lstR = i;

					sl--;
				}
			}
		}
	}
						if (lstL != -1 && cnt > mcnt) {
							mcnt = cnt;
							ml = lstL;
							mr = lstR;
						}
	if (mcnt != -1) {
		printf("%d\n",mcnt);
		for (int i = ml; i <= mr; i++) {
			printf("%c",str[i]);
		}
		printf("\n");
	}
	else printf("0\n");
}

int main() {
	 while (scanf("%s",str) != EOF) {
		solve();
	 }
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair

const int MAXN = 100004;
char str[MAXN];
PII stk[MAXN];
int sl;
int len;
PII sav[MAXN];
void solve() {
	int lstL,lstR,cnt = 0,mcnt = -1,ml,mr;
	len = strlen(str+1);
	sl = 0;
	ml = mr = lstL = lstR = -1;
	sav[0] = PII(-1,0);

	for (int i = 1; i <= len; i++) {
		if (str[i] == '[' || str[i] == '(') {
			stk[sl++] = MP<int,int>(str[i],i);
			sav[i] = PII(-1,0);
		}
		else {
			if (str[i] == ']') {
				if (sl == 0 || stk[sl-1].first != '[') {
						lstL = lstR = -1;
						sav[i] = PII(-1,0);
						sl = 0;
						cnt = 0;
				}
				else {
						lstL = stk[sl-1].second;
						cnt = 1;
						 if (sav[lstL-1].first != -1) {
							 cnt += sav[lstL-1].second;
							 lstL = sav[lstL-1].first;

						 }
						 cnt +=sav[i-1].second;
					lstR = i;
					sav[i] = PII(lstL,cnt);

					sl--;
					if (cnt > mcnt) {
						mcnt = cnt;
						ml = i;
					}
					cnt = 0;
				}
			}
			else if (str[i] == ')') {
				if (sl == 0 || stk[sl-1].first != '(') {
						lstL = lstR = -1;
						sav[i] = PII(-1,0);
						sl = 0;
						cnt = 0;
				}
				else {
						lstL = stk[sl-1].second;
						cnt = 0;
						 if (sav[lstL-1].first != -1) {
							  cnt = sav[lstL-1].second;
							 lstL = sav[lstL-1].first;

						}
						 cnt +=sav[i-1].second;
						  sav[i] = PII(lstL,cnt);
					if (cnt > mcnt) {
						mcnt = cnt;
						ml = i;
					}
					sl--;
				}
			}
		}
	}

	if (mcnt != -1) {
		printf("%d\n",mcnt);
		for (int i = sav[ml].first; i <= ml; i++) {
			printf("%c",str[i]);
		}
		printf("\n");
	}
	else printf("0\n\n");
}

int main() {
	 while (scanf("%s",str+1) != EOF) {
		solve();
	 }
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair

const int MAXN = 100004;
char str[MAXN];
PII stk[MAXN];
int sl;
int len;
void solve() {
	int lstL,lstR,cnt = 0,mcnt = -1,ml,mr;
	len = strlen(str);
	sl = 0;
	ml = mr = lstL = lstR = -1;

	for (int i = 0; i < len; i++) {
		if (str[i] == '[' || str[i] == '(') {
			stk[sl++] = MP<int,int>(str[i],i);
		}
		else {
			if (str[i] == ']') {
				if (sl == 0 || stk[sl-1].first != '[') {
					if (lstL != -1 && cnt > mcnt) {
						if (cnt > mcnt) {
							mcnt = cnt;
							ml = lstL;
							mr = lstR;
						}
					}
						lstL = lstR = -1;
						sl = 0;
						cnt = 0;

				}
				else {
						if (lstL == -1)
							lstL = stk[sl-1].second;
						else
						lstL = min(lstL,stk[sl-1].second);
						lstR = i;

					cnt++;
					sl--;
				}
			}
			else if (str[i] == ')') {
				if (sl == 0 || stk[sl-1].first != '(') {
					if (lstL != -1 ) {
						if (cnt > mcnt) {
							mcnt = cnt;
							ml = lstL;
							mr = lstR;
						}

					}
						lstL = lstR = -1;
						sl = 0;
						cnt = 0;

				}
				else {
						if (lstL == -1)
							lstL = stk[sl-1].second;
						else
						lstL = min(lstL, stk[sl-1].second);
						lstR = i;

					sl--;
				}
			}
		}
	}
						if (lstL != -1 && cnt > mcnt) {
							mcnt = cnt;
							ml = lstL;
							mr = lstR;
						}
	if (mcnt != -1) {
		printf("%d\n",mcnt);
		for (int i = ml; i <= mr; i++) {
			printf("%c",str[i]);
		}
		printf("\n");
	}
	else printf("0\n");
}

int main() {
	 while (scanf("%s",str) != EOF) {
		solve();
	 }
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair

const int MAXN = 100004;
char str[MAXN];
PII stk[MAXN];
int sl;
int len;
void solve() {
	int lstL,lstR,cnt = 0,mcnt = -1,ml,mr;
	len = strlen(str);
	sl = 0;
	ml = mr = lstL = lstR = -1;

	for (int i = 0; i < len; i++) {
		if (str[i] == '[' || str[i] == '(') {
			stk[sl++] = MP<int,int>(str[i],i);
		}
		else {
			if (str[i] == ']') {
				if (sl == 0 || stk[sl-1].first != '[') {
					if (lstL != -1 && cnt > mcnt) {
						if (cnt > mcnt) {
							mcnt = cnt;
							ml = lstL;
							mr = lstR;
						}
					}
						lstL = lstR = -1;
						sl = 0;
						cnt = 0;

				}
				else {
						if (lstL == -1)
							lstL = stk[sl-1].second;
						else
						lstL = min(lstL,stk[sl-1].second);
						lstR = i;

					cnt++;
					sl--;
				}
			}
			else if (str[i] == ')') {
				if (sl == 0 || stk[sl-1].first != '(') {
					if (lstL != -1 ) {
						if (cnt > mcnt) {
							mcnt = cnt;
							ml = lstL;
							mr = lstR;
						}

					}
						lstL = lstR = -1;
						sl = 0;
						cnt = 0;

				}
				else {
						if (lstL == -1)
							lstL = stk[sl-1].second;
						else
						lstL = min(lstL, stk[sl-1].second);
						lstR = i;

					sl--;
				}
			}
		}
	}
						if (lstL != -1 && cnt > mcnt) {
							mcnt = cnt;
							ml = lstL;
							mr = lstR;
						}
	if (mcnt != -1) {
		printf("%d\n",mcnt);
		for (int i = ml; i <= mr; i++) {
			printf("%c",str[i]);
		}
		printf("\n");
	}
	else printf("0\n\n");
}

int main() {
	 while (scanf("%s",str) != EOF) {
		solve();
	 }
	return 0;
}