using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; static class Program{ const int mod=(int)1e9+7; static List[] li; static bool[] b; static int[] h; static char[][] t; static Uf uf; static void Main(){ Sc sc=new Sc(); var s=sc.Ia; int n=s[0],m=s[1]; li=new List[n+1]; b=new bool[n+1]; h=new int[n+1]; t=new char[n+1][]; uf=new Uf((n+1)*7); for(int i=1;i<=n;i++){ li[i]=new List(); t[i]=sc.S.ToCharArray(); for(int j = 0;j<7;j++) { if(t[i][j]=='1'&&t[i][(j+1)%7]=='1'){ uf.Union(i*7+j,i*7+(j+1)%7); } } } for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i