    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            string var=a;
            cin>>a;
            cin>>b;
            vlli oper;
            if(n==1 && b[0]!=a[0])
            {
                oper.pb(1);
                cout<<1<<" ";
                tr(oper,it)cout<<*it;cout<<endl;
                continue;
            }
            blli(i,n-1,0)
            {
                //complete shuffle
                if(b[i]==a[i])continue;
                oper.pb(i+1);
                char temp1=a[0];
                char temp2=a[i];
                if(temp1=='0')a[i]='1';
                else a[i]='0';
                if(temp2=='0')a[0]='1';
                else a[0]='0';
                if(b[i]==a[0])
                {
                    oper.pb(1);
                    if(a[0]=='0')a[0]='1';
                    else a[0]='0';
                }
                oper.pb(i+1);
                if(a[i]=='1')a[0]='0';
                else a[0]='1';
            }
            lli szoper=sz(oper);
            if(szoper>2*n)
            {
                a=var;
                flli(i,0,n-1)
                {
                    if(a[i]=='0')a[i]='1';
                    else a[i]='0';
                }
                reverse(all(a));
                oper.clear();
                oper.pb(n);
                blli(i,n-1,0)
                {
                    //complete shuffle
                    if(b[i]==a[i])continue;
                    oper.pb(i+1);
                    char temp1=a[0];
                    char temp2=a[i];
                    if(temp1=='0')a[i]='1';
                    else a[i]='0';
                    if(temp2=='0')a[0]='1';
                    else a[0]='0';
                    if(b[i]==a[0])
                    {
                        oper.pb(1);
                        if(a[0]=='0')a[0]='1';
                        else a[0]='0';
                    }
                    oper.pb(i+1);
                    if(a[i]=='1')a[0]='0';
                    else a[0]='1';
                }
                szoper=sz(oper);
            }
            cout<<szoper<<" ";
            tr(oper,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    void funccall(string &a, string &b, vlli &oper)
    {
        lli n=sz(a);
        blli(i,n-1,0)
        {
            if(a[i]==b[i])continue;
            if(i==0)
            {
                oper.pb(1);
                continue;
            }
            char temp1,temp2;
            if(i>1)
            {
                char temp1=a[0];
                char temp2=a[i];
                if(temp1=='0')a[i]='1';
                else a[i]='0';
                if(temp2=='0')a[0]='1';
                else a[0]='0';
                oper.pb(i+1);
            }
            if(b[i]==a[0])
            {
                oper.pb(1);
                temp1=a[0];
                if(temp1=='0')a[0]='1';
                else a[0]='0';
            }
            oper.pb(i+1);
            temp1=a[0];
            temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
        }
    }
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            cin>>a;
            cin>>b;
            string var=a;
            vlli oper;
            funccall(var,b,oper);
            lli szoper=sz(oper);
            lli count=0;
            while(count<10 && szoper>2*n)
            {
                var=a;
                oper.clear();
                oper.pb(n);
                flli(i,0,n-count-1)
                {
                    if(var[i]=='0')var[i]='1';
                    else var[i]='0';
                }
                count++;
                reverse(var.begin(),var.begin()+n-count);
                funccall(var,b,oper);
                szoper=sz(oper);
            }

            //check if we have two same operation then replace it by one
            vlli final;
            lli index=0;
            while(index<szoper)
            {
                lli tem=oper[index];
                lli tempcount=0;
                while(index<szoper && tem==oper[index])
                {
                    index++;
                    tempcount++;
                }
                if(tempcount%2!=0)final.pb(tem);
            }
            szoper=sz(final);
            cout<<szoper<<" ";
            tr(final,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    void funccall(string &a, string &b, vlli &oper)
    {
        lli n=sz(a);
        blli(i,n-1,0)
        {
            if(a[i]==b[i])continue;
            if(i==0)
            {
                oper.pb(1);
                continue;
            }
            char temp1,temp2;
            if(i>1)
            {
                char temp1=a[0];
                char temp2=a[i];
                if(temp1=='0')a[i]='1';
                else a[i]='0';
                if(temp2=='0')a[0]='1';
                else a[0]='0';
                oper.pb(i+1);
            }
            if(b[i]==a[0])
            {
                oper.pb(1);
                temp1=a[0];
                if(temp1=='0')a[0]='1';
                else a[0]='0';
            }
            oper.pb(i+1);
            temp1=a[0];
            temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
        }
    }
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            cin>>a;
            cin>>b;
            string var=a;
            vlli oper;
            funccall(var,b,oper);
            lli szoper=sz(oper);
            if(szoper>2*n)
            {
                oper.clear();
                oper.pb(n);
                flli(i,0,n-1)
                {
                    if(a[i]=='0')a[i]='1';
                    else a[i]='0';
                }
                reverse(all(a));
                funccall(a,b,oper);
                szoper=sz(oper);
            }
            //check if we have two same operation then replace it by one
            vlli final;
            lli index=0;
            while(index<szoper)
            {
                lli tem=oper[index];
                lli tempcount=0;
                while(index<szoper && tem==oper[index])
                {
                    index++;
                    tempcount++;
                }
                if(tempcount%2!=0)final.pb(tem);
            }
            szoper=sz(final);
            cout<<szoper<<" ";
            tr(final,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            cin>>a;
            cin>>b;
            vlli oper;
            if(n==1 && b[0]!=a[0])
            {
                oper.pb(1);
                cout<<1<<" ";
                tr(oper,it)cout<<*it;cout<<endl;
                continue;
            }
            blli(i,n-1,0)
            {
                //complete shuffle
                if(b[i]==a[i])continue;
                oper.pb(i+1);
                char temp1=a[0];
                char temp2=a[i];
                if(temp1=='0')a[i]='1';
                else a[i]='0';
                if(temp2=='0')a[0]='1';
                else a[0]='0';
                if(b[i]==a[0])
                {
                    oper.pb(1);
                    if(a[0]=='0')a[0]='1';
                    else a[0]='0';
                }
                oper.pb(i+1);
                if(a[i]=='1')a[0]='0';
                else a[0]='1';
            }
            lli szoper=sz(oper);
            if(szoper>2*n)
            {
                flli(i,0,n-1)
                {
                    if(a[i]=='0')a[i]='1';
                    else a[i]='0';
                }
                reverse(all(a));
                oper.clear();
                oper.pb(n);
                blli(i,n-1,0)
                {
                    //complete shuffle
                    if(b[i]==a[i])continue;
                    oper.pb(i+1);
                    char temp1=a[0];
                    char temp2=a[i];
                    if(temp1=='0')a[i]='1';
                    else a[i]='0';
                    if(temp2=='0')a[0]='1';
                    else a[0]='0';
                    if(b[i]==a[0])
                    {
                        oper.pb(1);
                        if(a[0]=='0')a[0]='1';
                        else a[0]='0';
                    }
                    oper.pb(i+1);
                    if(a[i]=='1')a[0]='0';
                    else a[0]='1';
                }
                szoper=sz(oper);
            }
            cout<<szoper<<" ";
            tr(oper,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    void funccall(string &a, string &b, vlli &oper)
    {
        lli n=sz(a);
        blli(i,n-1,0)
        {
            if(a[i]==b[i])continue;
            if(i==0)
            {
                oper.pb(1);
                continue;
            }
            char temp1,temp2;
            if(i>2)
            {
                char temp1=a[0];
                char temp2=a[i];
                if(temp1=='0')a[i]='1';
                else a[i]='0';
                if(temp2=='0')a[0]='1';
                else a[0]='0';
                oper.pb(i+1);
            }
            if(b[i]==a[0])
            {
                oper.pb(1);
                temp1=a[0];
                if(temp1=='0')a[0]='1';
                else a[0]='0';
            }
            oper.pb(i+1);
            temp1=a[0];
            temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
        }
    }
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            cin>>a;
            cin>>b;
            string var=a;
            vlli oper;
            funccall(var,b,oper);
            lli szoper=sz(oper);
            if(szoper>2*n)
            {
                var=a;
                oper.clear();
                oper.pb(n);
                flli(i,0,n-1)
                {
                    if(a[i]=='0')a[i]='1';
                    else a[i]='0';
                }
                reverse(all(a));
                funccall(a,b,oper);
                szoper=sz(oper);
            }
            if(szoper>2*n)
            {
                oper.clear();
                oper.pb(n-1);
                flli(i,0,n-2)
                {
                    if(var[i]=='0')var[i]='1';
                    else var[i]='0';
                }
                reverse(var.begin(),var.begin()+n-1);
                funccall(var,b,oper);
                szoper=sz(oper);
            }
            //check if we have two same operation then replace it by one
            vlli final;
            lli index=0;
            while(index<szoper)
            {
                lli tem=oper[index];
                lli tempcount=0;
                while(index<szoper && tem==oper[index])
                {
                    index++;
                    tempcount++;
                }
                if(tempcount%2!=0)final.pb(tem);
            }
            szoper=sz(final);
            cout<<szoper<<" ";
            tr(final,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


import java.util.*;
 import java.lang.*;
 import java.io.*;

 public class s {
	public static void main( String[] args ) {
		Scanner sc= new Scanner(System.in);
		int cases=0;
		if(sc.hasNext())
		cases=sc.nextInt();
		while(cases>0){
		cases--;
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[]a1=new int[n];
		int[]a2=new int[m];

	    for(int i=0;i<n;i++){
	        a1[i]=sc.nextInt();
	        }

	    for(int j=0;j<m;j++){
	        a2[j]=sc.nextInt();

	        }
	        int count=0;
	        for(int i=0;i<n;i++){
	             for(int j=0;j<m;j++){
	               if( a1[i]==a2[j]){
	                System.out.println("YES");
	                count=1;
	                System.out.println("1 "+String.valueOf(a1[i]));
	                break;
	        }
	        if(count==1){
	             break;
	        }
	    }
	    if(count==1){
	             break;
	        }
	  }
	  if(count==0){
	       System.out.println("NO");
	  }
	}
}
}


import java.util.*;
 import java.lang.*;
 import java.io.*;

 public class s {
	public static void main( String[] args ) {
		Scanner sc= new Scanner(System.in);
		int cases=0;
		if(sc.hasNext())
		cases=sc.nextInt();
		while(cases>0){
		cases--;
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[]a1=new int[n];
		int[]a2=new int[m];

	    for(int i=0;i<n;i++){
	        a1[i]=sc.nextInt();
	        }

	    for(int j=0;j<m;j++){
	        a2[j]=sc.nextInt();

	        }
	        int count=0;
	        for(int i=0;i<n;i++){
	             for(int j=0;j<m;j++){
	               if( a1[i]==a2[j]){
	                System.out.println("YES");
	                count=1;
	                System.out.println("1 "+String.valueOf(a1[i]));
	                break;
	        }
	        if(count==1){
	             break;
	        }
	    }
	  }
	  if(count==0){
	       System.out.println("NO");
	  }
	}
}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Problem3 {
    public static void main (String [] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        //--------------------------START CODING HERE-----------------------------

        int t = Integer.parseInt(f.readLine());

        while(t-- > 0)
        {
            StringTokenizer st = new StringTokenizer(f.readLine());

            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());

            st = new StringTokenizer(f.readLine());

            int[] aArr = new int[a];
            for(int i = 0; i < a; i++)
            {
                aArr[i] = Integer.parseInt(st.nextToken());
            }

            st = new StringTokenizer(f.readLine());
            int[] bArr = new int[b];
            for(int i = 0; i < b; i++)
            {
                bArr[i] = Integer.parseInt(st.nextToken());
            }

            boolean toBreak = false;

            for(int e: aArr)
            {
                for(int l: bArr)
                {
                    if(e==l)
                    {
                        out.println("YES");
                      toBreak=true;
                      out.println(1+" "+e);
                    }
                }
                if(toBreak)break;
            }
            if(!toBreak)out.print("NO");

        }
        out.close();
    }
}


import javax.print.attribute.SupportedValuesAttribute;
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.util.function.Predicate;

public class Problem1 {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }

    static class TaskB {

        public static int binarySearch(int arr[], int low, int high, int key)
        {
            int mid = (low + high)/2;
            while( low <= high )
            {
                if ( arr[mid] < key )
                {
                    low = mid + 1;
                }
                else if ( arr[mid] == key )
                {
                    return mid;
                }else
                {
                    high = mid - 1;
                }
                mid = (low + high)/2;
            }
            if( low > high )
            {
                return -1;
            }
            return -1;
        }

        public static int[][] maxPos;

        public void solve(InputReader in, PrintWriter out) {
            int T = in.nextInt();

            while(T-->0)
            {
                int n = in.nextInt();
                int m = in.nextInt();

                HashSet<Integer> set = new HashSet<>();
                for(int i = 0; i < n; i++)
                {
                    set.add(in.nextInt());
                }

                boolean good = true;

                int[] arr = new int[m];
                for(int i = 0; i < m; i++)
                {
                    arr[i] = in.nextInt();
                }
                for(int i = 0; i < m; i++)
                {
                    if(set.contains(arr[i]))
                    {
                        good = false;
                        out.println("YES");
                        out.println(1+" "+arr[i]);
                        break;
                    }
                }
                if(good)out.println("NO");
            }
        }
    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer = new StringTokenizer("");

        public InputReader(InputStream inputStream) {
            this.reader = new BufferedReader(
                    new InputStreamReader(inputStream));
        }

        public String next() {
            while (!tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Problem3 {
    public static void main (String [] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        //--------------------------START CODING HERE-----------------------------

        int t = Integer.parseInt(f.readLine());

        while(t-- > 0)
        {
            StringTokenizer st = new StringTokenizer(f.readLine());

            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());

            st = new StringTokenizer(f.readLine());

            int[] aArr = new int[a];
            for(int i = 0; i < a; i++)
            {
                aArr[i] = Integer.parseInt(st.nextToken());
            }

            st = new StringTokenizer(f.readLine());
            int[] bArr = new int[b];
            for(int i = 0; i < b; i++)
            {
                bArr[i] = Integer.parseInt(st.nextToken());
            }

            boolean toBreak = false;

            for(int e: aArr)
            {
                for(int l: bArr)
                {
                    if(e==l)
                    {
                        out.println("YES");
                      toBreak=true;
                      out.println(1+" "+e);
                    }
                }
                if(toBreak)break;
            }
            if(!toBreak)out.println("NO");

        }
        out.close();
    }
}


import java.io.*;
import java.util.*;
import java.util.Collection;
import java.util.Set;
import java.util.HashSet;
import java.util.ArrayList;

public class Solution {

    public static void main (String[] args) throws java.lang.Exception
    {
        try {

        Scanner ob =new Scanner(System.in);
        int t=ob.nextInt();
        while(t-->0)
        {
            int n=ob.nextInt();
            int m=ob.nextInt();
            int a[]=new int[n];
            int b[]=new int[m];
            List<Integer> c=new ArrayList<Integer>();
            int k=0,dep=0;
            int l=0;
            for(int i=0;i<n;i++)
            a[i]=ob.nextInt();
            for(int i=0;i<m;i++)
            b[i]=ob.nextInt();
            for(int i=0;i<n;i++)
            {
                for(int j=k;j<m;j++)
                {
                    if(a[i]==b[j])
                    {
                        k=j;
                        dep=1;
                        c.add(a[i]);
                    }
                }
            }
            if(dep==1)
            {
                System.out.println("YES");
                int le=c.size();
                System.out.print(le+" ");
                for(int i=0;i<le;i++)
                System.out.print(c.get(i)+" ");
                System.out.println();
            }
            else
            System.out.println("NO");
        }
            } catch(Exception e) {
        } finally {
        }
}
}


import java.io.*;
import java.util.*;
import java.util.Collection;
import java.util.Set;
import java.util.HashSet;
import java.util.ArrayList;

public class Solution {

    public static void main (String[] args) throws java.lang.Exception
    {
        try {

        Scanner ob =new Scanner(System.in);
        int t=ob.nextInt();
        while(t-->0)
        {
            int n=ob.nextInt();
            int m=ob.nextInt();
            int a[]=new int[n];
            int b[]=new int[m];

            int k=0,dep=0;
            int l=0,c=0;
            for(int i=0;i<n;i++)
            a[i]=ob.nextInt();
            for(int i=0;i<m;i++)
            b[i]=ob.nextInt();
            for(int i=0;i<n;i++)
            {
                for(int j=k;j<m;j++)
                {
                    if(a[i]==b[j])
                    {
                        k=j;
                        dep=1;
                        c=a[i];
                        break;
                    }
                }
            }
            if(dep==1)
            {
                System.out.println("YES");

                System.out.println(1+" "+c);

            }
            else
            System.out.println("NO");
        }
            } catch(Exception e) {
        } finally {
        }
}
}


import java.util.*;
import java.io.*;

public class common_sub {
  static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  public static void solve() throws IOException {
    StringTokenizer st = new StringTokenizer(br.readLine());
    int n = Integer.parseInt(st.nextToken());
    int m = Integer.parseInt(st.nextToken());
    HashSet<Integer> a = new HashSet<Integer>();
    HashSet<Integer> b = new HashSet<Integer>();
    StringTokenizer st2 = new StringTokenizer(br.readLine());
    StringTokenizer st3 = new StringTokenizer(br.readLine());
    for (int i = 0; i < n; i++) a.add(Integer.parseInt(st2.nextToken()));
    for (int i = 0; i < n; i++) b.add(Integer.parseInt(st3.nextToken()));
    for (int i : a) {
      if(b.contains(i)) {
        System.out.println("YES");
        System.out.println(1 + " " + i);
        return;
      }
    }
    System.out.println("NO");
  }
  public static void main(String[] args) throws IOException {
    int t = Integer.parseInt(br.readLine());
    for (int i = 0; i < t; i++) solve();
  }
}


import java.util.*;
import java.io.*;

public class common_sub {
  static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  public static void solve() throws IOException {
    StringTokenizer st = new StringTokenizer(br.readLine());
    int n = Integer.parseInt(st.nextToken());
    int m = Integer.parseInt(st.nextToken());
    HashSet<Integer> a = new HashSet<Integer>();
    HashSet<Integer> b = new HashSet<Integer>();
    StringTokenizer st2 = new StringTokenizer(br.readLine());
    StringTokenizer st3 = new StringTokenizer(br.readLine());
    for (int i = 0; i < n; i++) a.add(Integer.parseInt(st2.nextToken()));
    for (int i = 0; i < m; i++) b.add(Integer.parseInt(st3.nextToken()));
    for (int i : a) {
      if(b.contains(i)) {
        System.out.println("YES");
        System.out.println(1 + " " + i);
        return;
      }
    }
    System.out.println("NO");
  }
  public static void main(String[] args) throws IOException {
    int t = Integer.parseInt(br.readLine());
    for (int i = 0; i < t; i++) solve();
  }
}


import java.util.Scanner;

public class A1382 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- > 0){
            int an = sc.nextInt();
            int bn = sc.nextInt();
            int[] a = new int[an];
            int[] b = new int[bn];
            for(int i = 0; i < an; i++){
                a[i] = sc.nextInt();
            }
            for(int i = 0; i < bn; i++){
                b[i] = sc.nextInt();
            }
            int temp = -1;
            for(int i = 0; i < an; i++){
                int a_ = a[i];
                for(int j = 0; j < bn; j++){
                    if(a_==b[j]){
                        temp = a_;
                        break;
                    }
                }
            }
            if(temp!=-1){
                System.out.println("YES\n1 " + temp);
            }else{
                System.out.println("NO");
            }
        }
    }
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        if(!(sc.hasNext()))
            return;
        int T = sc.nextInt();
        while(T-- > 0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int l =0,last=0;
            int [] a = new int [n];
            int [] b = new int[m];
            int flag =1,ele=0;
            for(int i = 0; i<n ; i++ ){
                a[i] = sc.nextInt();
            }
            for(int i = 0; i<m ; i++ ){
                b[i] = sc.nextInt();
                for(int j =0; j<n; j++) {
                    if(b[i] == a[j]){
                        flag = 0;
                        ele = b[i];
                    }
                }
            }

            if(flag == 1)
                System.out.println("NO");
            else{
                System.out.println("Yes \n 1 "+ ele);
            }
        }
    }
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        if(!(sc.hasNext()))
            return;
        int T = sc.nextInt();
        while(T-- > 0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int l =0,last=0;
            int [] a = new int [n];
            int [] b = new int[m];
            for(int i = 0; i<n ; i++ ){
                a[i] = sc.nextInt();
            }
            for(int i = 0; i<m ; i++ ){
                b[i] = sc.nextInt();
            }
            int [] c = new int[n];
            for(int i = 0; i<n ; i++){
                for(int j = last; j<m ; j++){
                    if(a[i] == b[j]){
                        last =j;
                        c[l]=a[i];
                        l++;
                    }
                }
            }
            if(l>0)
                System.out.println("YES");
            else {
                System.out.println("NO");
                continue;
            }
            if(l == m || l==n){
                System.out.print("1 ");
                System.out.println(a[0]);
                continue;
            }
            System.out.print(l + " ");
            for(int i=0;i<l ;i++){
                System.out.print(c[i] + " ");
            }
            System.out.println();
        }
    }
}


import java.util.*;

public class Main {

  private static void solve(Set<Integer> set1, Set<Integer> set2) {
    for (int num : set1) {
      if (set2.contains(num)) {
        System.out.println("YES");
        System.out.println(1 + " " + num);
        return;
      }
    }
    System.out.println("NO");
  }

  public static void main(String[] args) {
    int testCaseCnt = scanner.nextInt();
    for (int i = 0; i < testCaseCnt; i++) {
      int n = scanner.nextInt();
      int m = scanner.nextInt();
      Set<Integer> set1 = new HashSet<>();
      Set<Integer> set2 = new HashSet<>();
      for (int j = 0; j < n; j++) {
        set1.add(scanner.nextInt());
      }
      for (int j = 0; j < m; j++) {
        set2.add(scanner.nextInt());
      }
      solve(set1, set2);
    }
  }

  private static final Scanner scanner = new Scanner(System.in);
}


import java.util.*;

public class Main {

  private static void solve(String s1, String s2, int n) {
    Queue<String> queue = new ArrayDeque<>(List.of(s1));
    Set<String> seen = new HashSet<>(List.of(s1));
    Map<String, Pair> map = new HashMap<>();
    while (!queue.isEmpty()) {
      int size = queue.size();
      for (int i = 0; i < size; i++) {
        String curr = queue.poll();
        if (curr.equals(s2)) {
          List<String> res = reconstruct(map, curr);
          System.out.println(res.size() + " " + String.join(" ", res));
          return;
        }
        for (int j = 1; j <= n; j++) {
          String next = transform(curr, j);
          if (seen.add(next)) {
            queue.offer(next);
            map.put(next, new Pair(j, curr));
          }
        }
      }
    }
  }

  private static List<String> reconstruct(Map<String, Pair> map, String s) {
    List<String> res = new ArrayList<>();
    Pair p = map.get(s);
    while (p != null) {
      res.add(String.valueOf(p.prefix));
      p = map.get(p.parent);
    }
    return res;
  }

  private static String transform(String s, int len) {
    StringBuilder prefix = new StringBuilder(s.substring(0, len));
    String suffix = s.substring(len);
    for (int i = 0; i < prefix.length(); i++) {
      prefix.setCharAt(i, prefix.charAt(i) == '0' ? '1' : '0');
    }
    return prefix.reverse().toString() + suffix;
  }

  public static void main(String[] args) {
    int testCaseCnt = scanner.nextInt();
    for (int i = 0; i < testCaseCnt; i++) {
      int n = scanner.nextInt();
      String s1 = scanner.next();
      String s2 = scanner.next();
      solve(s1, s2, n);
    }
  }

  private static class Pair {
    int prefix;
    String parent;

    Pair(int prefix, String parent) {
      this.prefix = prefix;
      this.parent = parent;
    }
  }

  private static final Scanner scanner = new Scanner(System.in);
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Test {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int testCases = Integer.parseInt(st.nextToken());
        for (int i = 0; i < testCases; i++) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            int[] aArr = new int[a];
            int[] bArr = new int[b];
            st = new StringTokenizer(br.readLine());
            for (int j = 0; j < a; j++) {
                int x = Integer.parseInt(st.nextToken());
                aArr[j] = x;
            }
            st = new StringTokenizer(br.readLine());
            for (int k = 0; k < b; k++) {
                int y = Integer.parseInt(st.nextToken());
                bArr[k] = y;
            }
            int index = 0;
            int value = 0;
            for (int k = 0; k < a; k++) {
                for (int j = 0; j < b; j++) {
                    if (aArr[k] == bArr[j]) {
                        value = aArr[k];
                        index++;
                    }
                }
            }
            if (index == 0) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
                System.out.print(1 + " ");
                System.out.print(value);
                System.out.println();
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Test {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int testCases = Integer.parseInt(st.nextToken());
        for (int i = 0; i < testCases; i++) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            int[] aArr = new int[a];
            int[] bArr = new int[b];
            st = new StringTokenizer(br.readLine());
            for (int j = 0; j < a; j++) {
                int x = Integer.parseInt(st.nextToken());
                aArr[j] = x;
            }
            st = new StringTokenizer(br.readLine());
            for (int k = 0; k < b; k++) {
                int y = Integer.parseInt(st.nextToken());
                bArr[k] = y;
            }
            int length = 0;
            if (a < b) {
                length = b;

            } else {
                length = a;
            }
            int[] tempArr = new int[length];
            int index = 0;
            for (int k = 0; k < a; k++) {
                for (int j = 0; j < b; j++) {
                    if (aArr[k] == bArr[j]) {
                        tempArr[index] = aArr[k];
                        index++;
                    }
                }
            }
            if (index == 0) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
                System.out.print(1 + " ");
                System.out.print(tempArr[0]);
                System.out.println();
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution extends Thread {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    private static final FastReader scanner = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Thread(null, new Solution(), "Main", 1<<26).start();
    }

    public void run() {
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            solve();
        }
        out.close();
    }

    private static void solve() {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] a = new int[1001];
        int output = -1;

        for (int i = 0; i < n; i++) {
            a[scanner.nextInt()]++;
        }
        for (int i = 0; i < m; i++) {
            int el = scanner.nextInt();
            a[el]++;
            if (a[el] >= 2) {
                output = el;
            }
        }

        if (output == -1) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
            System.out.println("1 " + output);
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution extends Thread {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    private static final FastReader scanner = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Thread(null, new Solution(), "Main", 1<<26).start();
    }

    public void run() {
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            solve();
        }
        out.close();
    }

    private static void solve() {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] a = new int[1001];
        int[] b = new int[1001];
        int output = -1;

        for (int i = 0; i < n; i++) {
            int el = scanner.nextInt();
            a[el]++;
        }
        for (int i = 0; i < m; i++) {
            int el = scanner.nextInt();
            b[el]++;
            if (a[el] >= 1 && b[el] >= 1) {
                output = el;
            }
        }

        if (output == -1) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
            System.out.println("1 " + output);
        }
    }
}


package helpers;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution extends Thread {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    private static final FastReader scanner = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Thread(null, new Solution(), "Main", 1<<26).start();
    }

    public void run() {
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            solve();
        }
        out.close();
    }

    private static void solve() {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] a = new int[1001];
        int output = -1;

        for (int i = 0; i < n; i++) {
            a[scanner.nextInt()]++;
        }
        for (int i = 0; i < m; i++) {
            int el = scanner.nextInt();
            a[el]++;
            if (a[el] >= 2) {
                output = el;
            }
        }

        if (output == -1) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
            System.out.println("1 " + output);
        }

    }
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n, m;
			n = sc.nextInt();
			m = sc.nextInt();
			List<Integer> a = new ArrayList<>();
			List<Integer> b = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				int a1 = sc.nextInt();
				a.add(a1);
			}
			for (int i = 0; i < n; i++) {
				int b1 = sc.nextInt();
				b.add(b1);
			}

			int j = Math.min(n, m);
			char ch;
			if (j == n) {
				ch = 'a';
			} else
				ch = 'b';
			String s = "NO";
			int c = 0;
			for (int i = 0; i < j; i++) {
				if (a.contains(b.get(i)) && ch == 'b') {
					s = "YES";
					c = b.get(i);
					break;
				} else if (b.contains(a.get(i)) && ch == 'a') {
					s = "YES";
					c = a.get(i);
					break;
				}
			}
			if (s == "YES") {
				System.out.println(s);
				System.out.println("1 " + c);
			} else {
				System.out.println(s);
			}

		}

	}

}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		try {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n, m;
			n = sc.nextInt();
			m = sc.nextInt();
			List<Integer> a = new ArrayList<>();
			List<Integer> b = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				int a1 = sc.nextInt();
				a.add(a1);
			}
			for (int i = 0; i < m; i++) {
				int b1 = sc.nextInt();
				b.add(b1);
			}

			int j = Math.min(n, m);
			String s = "NO";
			int c = 0;
			if (j == n) {
				for (int i = 0; i < n; i++) {
				if (b.contains(a.get(i))) {
					s = "YES";
					c = a.get(i);
					break;
				}
			}
		} else {
			for (int i = 0; i < m; i++) {
				if (a.contains(b.get(i))) {
					s = "YES";
					c = b.get(i);
					break;
				}
				}
			}
			if (s == "YES") {
				System.out.println(s);
				System.out.println("1 " + c);
			} else {
				System.out.println(s);
			}

		}
	} catch (Exception e) {
		System.out.println(e);
	}
	}

}


import java.util.*;
public class CFDIV2658 {

	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
	int n=sc.nextInt();
	int m=sc.nextInt();
	int a[]=new int[n];
	int b[]=new int[m];
	ArrayList<Integer> aa=new ArrayList<>();
	ArrayList<Integer> bb=new ArrayList<>();
	for(int i=0;i<n;i++) {
		a[i]=sc.nextInt();
		aa.add(a[i]);
	}for(int i=0;i<m;i++) {
		b[i]=sc.nextInt();
		bb.add(b[i]);
	}
	int flag=0;
	for(int i=0;i<aa.size();i++) {
		if(bb.contains(a[i])) {
			flag=1;
			System.out.println("YES");
			System.out.println("1"+" "+a[i]);
			break;
		}
	}
	if(flag==0) {
		System.out.println("NO");
	}
}
	}

}


package codeforces;
import java.util.*;
public class CFDIV2658 {

	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
	int n=sc.nextInt();
long a[]=new long[n];
HashSet<Long> s=new HashSet<>();
for(int i=0;i<n;i++) {
	a[i]=sc.nextLong();
	s.add(a[i]);
}
if(n==1) {
	System.out.println("First");
}else {
	if(n%2==0&&a[0]==1&&s.size()==1) {
		System.out.println("Second");
	}else {
	if(a[0]==1&&a[1]%2!=0) {
		System.out.println("First");
	}else if(a[0]>1){
		System.out.println("First");
	}else
		System.out.println("Second");
	}
}
}

}
	}


#include<bits/stdc++.h>
using namespace std;
struct node{
	int to,nxt;
}e[200005];
int head[100005],n,dp[100005];
int cnt,tmp,mid,ans[100005];
void add(int u,int v){
	e[++cnt].to=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
void dfs(int u,int fa){
	int max1=0,max2=0;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa) continue;
		dfs(v,u);
		if(dp[v]>max1){
			max2=max1;
			max1=dp[v];
		}
		else if(dp[v]>max2) max2=dp[v];
	}
	if(max1+max2+1>=mid){
		dp[u]=0;
		tmp++;
	}
	else dp[u]=max1+1;
}
void fz(int l,int r,int l1,int r1){
	if(l>r||l1>r1) return;
	if(l==r){
		for(int i=l1;i<=r1;i++) ans[i]=l;
		return;
	}
	tmp=0;mid=(l1+r1)>>1;
	dfs(1,0);
	ans[mid]=tmp;
	fz(l,tmp,mid+1,r1);
	fz(tmp,r,l1,mid-1);
}
int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	int li=sqrt(n);
	for(int i=1;i<=li;i++){
		mid=i;tmp=0;
		dfs(1,0);
		ans[i]=tmp;
	}
	fz(0,li,li+1,n);
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
#define R register
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100005;
int fir[N],nxt[N<<1],go[N<<1],f[N],cnt,id[N],rt,fa[N];
int n,Lim;
inline void Add(int u,int v){
	nxt[++cnt]=fir[u];
	fir[u]=cnt;
	go[cnt]=v;
}
void dfs(int u,int f){
	for(int e=fir[u];e;e=nxt[e]){
		int v=go[e];
		if(v==f) continue;
		fa[v]=u;
		dfs(v,u);
	}
	id[++rt]=u;
}
inline int work(int k){
	int res=0;
	for(int i=1;i<=n;i++) f[i]=1;
	for(int i=1;i<=n;i++){
		if(fa[id[i]]&&f[id[i]]!=-1&&f[fa[id[i]]]!=-1){
			if(f[id[i]]+f[fa[id[i]]]>=k){
				res++;
				f[fa[id[i]]]=-1;
			}else{
				f[fa[id[i]]]=max(f[fa[id[i]]],f[id[i]]+1);
			}
		}
	}
	return res;
}
int main(){
	n=read();
	int size=(int)(sqrt(n*log(n)/log(2)));
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
	dfs(1,0);
	write(n);putchar('\n');
	for(int i=2;i<=size;i++){
		write(work(i));putchar('\n');
	}
	int pos=size;
	while(pos<n){
		int fg=work(pos+1);
		if(fg==0){
			for(int i=pos+1;i<=n;i++){
				puts("0");
			}
			return 0;
		}
		R int l=pos+1,r=n+1,mid;
		while(r-l>1){
			mid=(l+r)>>1;
			if(work(mid)==fg) l=mid;
			else r=mid;
		}
		for(int i=pos+1;i<=l;i++){
			write(fg);putchar('\n');
		}
		pos=l;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct E{
	int v,nxt;
}g[200005];
int n,t,h[100005],ans[100005],tot,f[100005];
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
void add(int u,int v){g[++t].v=v,g[t].nxt=h[u],h[u]=t,g[++t].v=u,g[t].nxt=h[v],h[v]=t;}
void dfs(int u,int fa,int k){
	int mx=0,mx2=0;
	for(int i=h[u];i;i=g[i].nxt){
		int v=g[i].v;
		if(v==fa)continue;
		dfs(v,u,k);
		if(f[v]>mx)mx2=mx,mx=f[v];
		else mx2=max(mx2,f[v]);
	}
	if(mx+mx2+1>=k)f[u]=0,tot++;
	else f[u]=mx+1;
}
void solve(int l,int r,int minans,int maxans){
	if(minans>maxans||l>r)return;
	if(minans==maxans){for(int i=l;i<=r;++i)ans[i]=minans;return;}
	int m=l+r>>1;tot=0;dfs(1,0,m),ans[m]=tot;
	solve(l,m-1,tot,maxans),solve(m+1,r,minans,tot);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n-1;++i)add(read(),read());
	solve(1,n,0,n);
	for(int i=1;i<=n;++i)printf("%d\n",ans[i]);
}


#pragma GCC optimize("Ofast,no-stack-protector")
#pragma G++ optimize("Ofast,no-stack-protector")
#include<cstdio>
#include<iostream>
#include<algorithm>
#define rint register int
#define from(u) for(rint i=lst[u],v;(v=ed[i].v);i=ed[i].nxt)
using namespace std;
typedef long long ll;
const int maxn=100003;
inline void read(int &x) {
	x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
}
struct edge {
	int v,nxt;
} ed[maxn<<1];
int n,lst[maxn],cnt,K;
inline void addedge(int u,int v) {
	ed[++cnt].v=v;
	ed[cnt].nxt=lst[u];
	lst[u]=cnt;
}
int f[maxn][2],ans[maxn];
void dfs(int u,int fa) {
	f[u][0]=0,f[u][1]=1;
	from(u) {
		if(v==fa) continue;
		dfs(v,u);
		f[u][0]+=f[v][0];
		if(f[u][1]+f[v][1]>=K) ++f[u][0],f[u][1]=0;
		else if(f[u][1]&&f[v][1]) f[u][1]=max(f[u][1],f[v][1]+1);
	}
}
int main() {
	read(n);
	for(rint i=1;i<n;++i) {
		int u,v;read(u);read(v);
		addedge(u,v);addedge(v,u);
	}
	int T=min(n,(int)sqrt(n*log2(n)));
	ans[1]=n;
	for(rint i=2;i<=T;++i) ans[i]=(K=i,dfs(1,0),f[1][0]);
	for(rint l=T+1,r,L,R,x;l<=n;l=r+1) {
		L=l;R=n;x=(K=l,dfs(1,0),f[1][0]);
		while(L<=R) {
			K=L+R>>1;dfs(1,0);
			if(f[1][0]==x) r=K,L=K+1;
			else R=K-1;
		}
		for(rint i=l;i<=r;++i) ans[i]=x;
	}
	for(rint i=1;i<=n;++i) printf("%d\n",ans[i]);
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
const int N=100010;
int head[N],p,ans[N];
struct ss{int v,last;}G[N<<1];
void add(int a,int b){
	G[++p]=(ss){b,head[a]};head[a]=p;
	G[++p]=(ss){a,head[b]};head[b]=p;
}
int n;
int Max[N],Cmax[N];
void C_max(int i,int c){
	if(c>=Max[i])Cmax[i]=Max[i],Max[i]=c;
	else if(c>Cmax[i])Cmax[i]=c;
}
int sta[N],dfn[N],fa[N],tim;
void dfs(int a,int f){
	sta[dfn[a]=++tim]=a;fa[a]=f;
	for(int i=head[a];i;i=G[i].last)
	if(G[i].v!=f)dfs(G[i].v,a);
}
int dep[N];
int solve(int k){
	int ret=0;
	memset(Max,0,sizeof(Max));
	memset(Cmax,0,sizeof(Cmax));
	for(int i=n,u,v;i>=1;i--){
		u=sta[i];v=fa[u];
		if(!Max[u])dep[u]=1;
		if(Cmax[u]+Max[u]+1>=k)++ret,dep[u]=0;
		else dep[u]=Max[u]+1;
		C_max(v,dep[u]);
	}
	return ret;
}
int find(int l,int r,int val){
	while(l<r-1){
		int mid=l+r>>1;
		if(ans[mid]==-1)ans[mid]=solve(mid);
		if(ans[mid]>=val)l=mid;
		else r=mid-1;
	}
	return l;
}
int main()
{
	memset(ans,-1,sizeof(ans));
	n=read();
	for(int i=1,a,b;i<n;i++)
	a=read(),b=read(),add(a,b);
	dfs(1,0);
	ans[1]=n;int size=sqrt(n);
	for(int i=2;i<=size;i++)
	ans[i]=solve(i);
	for(int l=size+1,r;l<=n;l=r+1){
		if(ans[l]==-1)ans[l]=solve(l);
		r=find(l,n+1,ans[l]);
		for(int i=l+1;i<=r;i++)
		ans[i]=ans[l];
	}
	for(int i=1;i<=n;i++)
	printf("%d\n",ans[i]);
	return 0;
}


#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define N 1100000
#define L 1000000
#define eps 1e-7
#define inf 1e9+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline int read()
{
	char ch=0;
	int x=0,flag=1;
	while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*flag;
}
struct edge{int to,nxt;}e[N*2];
int num,head[N];
inline void add(int x,int y){e[++num]=(edge){y,head[x]};head[x]=num;}
int n,sq,times,p[N],id[N],fa[N],f[N],dp[N],ans[N],data[N];
void dfs(int x)
{
	id[x]=++times;p[times]=x;
	for(int i=head[x];i!=-1;i=e[i].nxt)
	{
		int to=e[i].to;
		if(id[to])continue;
		fa[to]=x;dfs(to);
	}
}
int solve(int k)
{
	if(data[k]!=-1)return data[k];
	for(int o=n;o>=1;o--)
	{
		int x=p[o];
		f[x]=0;dp[x]=0;
		int m1=0,m2=0;
		for(int i=head[x];i!=-1;i=e[i].nxt)
		{
			int to=e[i].to;
			if(to==fa[x])continue;
			if(f[to]>=m1)m2=m1,m1=f[to];
			else m2=max(m2,f[to]);
			dp[x]+=dp[to];
		}
		if(m1+m2+1>=k)dp[x]++;
		else f[x]=m1+1;
	}
	data[k]=dp[1];
	return data[k];
}
int main()
{
	n=read();sq=min(n,(int)sqrt(n*20));
	num=-1;memset(head,-1,sizeof(head));
	memset(data,-1,sizeof(data));
	for(int i=1;i<=n-1;i++){int x=read(),y=read();add(x,y);add(y,x);}
	dfs(1);
	for(int i=1;i<=sq;i++)ans[i]=solve(i);
	int x=sq+1;
	while(x<=n)
	{
		ans[x]=solve(x);
		int l=x,r=n,mid;
		while(l<r)
		{
			mid=((l+r)>>1)+1;
			if(ans[x]==solve(mid))l=mid;
			else r=mid-1;
		}
		for(int i=x+1;i<=l;i++)ans[i]=ans[x];
		x=l+1;
	}
	for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const int _=2e5+7;
char buf[1000001],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++)
inline int read() {
	int x=0,f=1;char s=getchar();
	for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
	for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
	return x*f;
}
int n,f[_],g[_],ans[_],head[_],tot;
struct node {int v,nxt;}e[_<<1];
inline void add(int u,int v) {e[++tot].v=v,e[tot].nxt=head[u],head[u]=tot;}
void dfs(int u,int fa,int L) {
	f[u]=0,g[u]=1;
	int flag=0;
	if(g[u]>=L) {flag=1,g[u]=0,f[u]++;}
	for(int i=head[u];i;i=e[i].nxt) {
		int v=e[i].v;
		if(v==fa) continue;
		dfs(v,u,L);
		f[u]+=f[v];
		if(flag) continue;
		if(g[v]+g[u]>=L) {flag=1,g[u]=0,f[u]++;continue;}
		g[u]=max(g[u],g[v]+1);
	}
}
int main() {
	n=read();
	for(register int i=1,u,v;i<n;++i) {
		u=read(),v=read();
		add(u,v),add(v,u);
	}
	int k=min(n,400);
	for(register int i=1;i<=k;++i)
		dfs(1,0,i),ans[i]=f[1];
	for(register int i=k+1;i<=n;) {
		register int l=i,r=n,R=i;
		dfs(1,0,i),ans[i]=f[1];
		while(l<=r) {
			int mid=(l+r)>>1;
			dfs(1,0,mid);
			if(f[1]==ans[i]) R=mid,l=mid+1;
			else r=mid-1;
		}
		for(register int j=i+1;j<=R;++j) ans[j]=ans[i];
		i=max(i+1,R+1);
	}
	for(register int i=1;i<=n;++i) printf("%d\n",ans[i]);
	return 0;
}


#include <cstdio>
#include <cmath>
#define max(a,b) ((a)>(b)?(a):(b))

const int maxn=100000+10,maxm=200000+10;
int n,sq,su[maxn],le[maxn],ans[maxn];

struct Edge{
    int cnt,beg[maxn],nxt[maxm],poi[maxm];
    void push(int u,int v){
        ++cnt;
        nxt[cnt]=beg[u];
        poi[cnt]=v;
        beg[u]=cnt;
    }
}e;

int dfs(int u,int fa,int k){
    su[u]=le[u]=0;
    int max1=0,max2=0;
    for(int i=e.beg[u];i;i=e.nxt[i]){
        int v=e.poi[i];if(v==fa)continue;
        su[u]+=dfs(v,u,k);
        if(le[v]>max1){max2=max1;max1=le[v];}
        else if(le[v]>max2)max2=le[v];
    }
    if(max1+max2>=k)++su[u];
    else le[u]=max1+1;
    return su[u];
}

void meow(int x){
    for(int l=sq+1,r=n-1,mid;l<=r;){
        mid=(l+r)/2;
        if(dfs(1,0,mid)>=x){ans[mid]=x;l=mid+1;}
        else r=mid-1;
    }
}

int main(){
    int u,v;scanf("%d",&n);sq=ceil(sqrt(n-1));
    for(int i=1;i<n;++i){scanf("%d%d",&u,&v);e.push(u,v);e.push(v,u);}
    for(int i=0;i<=sq;++i)ans[i]=dfs(1,0,i);
    for(int i=1;i<=sq;++i)meow(i);
    for(int i=n-2;i>=0;--i)ans[i]=max(ans[i],ans[i+1]);
    for(int i=0;i<n;++i)printf("%d\n",ans[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, T, k;
vector<int> e[maxn];
int ans[maxn], f[maxn], len[maxn];
inline void dfs(int u, int pa) {
    int l1=0, l2=0; f[u]=len[u]=0;
    for (auto v:e[u]) if (v!=pa) {
        dfs(v, u);
        f[u]+=f[v];
        if (len[v]>l1) l2=l1, l1=len[v];
        else if (len[v]>l2) l2=len[v];
    }
    if (l1+l2+1>=k) f[u]++, len[u]=0;
    else len[u]=l1+1;
}
inline int solve() {
    dfs(1, 0);
    return f[1];
}
int main() {
    scanf("%d", &n);
    for (int i=0; i<n-1; i++) {
        int u, v; scanf("%d%d", &u, &v);
        e[u].push_back(v); e[v].push_back(u);
    }
    if (n<=5000) T=n;
    else T=sqrt(n*log2(n));
    memset(ans, -1, sizeof(ans));
    ans[1]=n;
    for (k=2; k<=T; k++) ans[k]=solve();
    int cur=T+1;
    while (cur<=n) {
        if (ans[cur]==-1) {
            k=cur; ans[cur]=solve();
        }
        if (ans[cur]==0) {
            for (int i=cur+1; i<=n; i++) ans[i]=0;
            break;
        }
        int l=cur+1, r=n, mid, pos=cur;
        while (l<=r) {
            k=mid=(l+r)>>1;
            if (ans[k]==-1) ans[k]=solve();
            if (ans[k]==ans[cur]) pos=mid, l=mid+1;
            else r=mid-1;
        }
        for (int j=cur+1; j<=pos; j++) ans[j]=ans[cur];
        cur=pos+1;
    }
    for (int i=1; i<=n; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, T, k;
vector<int> e[maxn];
int ans[maxn], f[maxn], len[maxn];
inline void dfs(int u, int pa) {
    int l1=0, l2=0; f[u]=len[u]=0;
    for (auto v:e[u]) if (v!=pa) {
        dfs(v, u);
        f[u]+=f[v];
        if (len[v]>l1) l2=l1, l1=len[v];
        else if (len[v]>l2) l2=len[v];
    }
    if (l1+l2+1>=k) f[u]++, len[u]=0;
    else len[u]=l1+1;
}
inline int solve() {
    dfs(1, 0);
    return f[1];
}
int main() {
    scanf("%d", &n);
    for (int i=0; i<n-1; i++) {
        int u, v; scanf("%d%d", &u, &v);
        e[u].push_back(v); e[v].push_back(u);
    }
    if (n<=1000) T=n;
    else T=sqrt(n*log2(n));
    memset(ans, -1, sizeof(ans));
    ans[1]=n;
    for (k=2; k<=T; k++) ans[k]=solve();
    int cur=T+1;
    while (cur<=n) {
        if (ans[cur]==-1) {
            k=cur; ans[cur]=solve();
        }
        if (ans[cur]==0) {
            for (int i=cur+1; i<=n; i++) ans[i]=0;
            break;
        }
        int l=cur+1, r=n, mid, pos=cur;
        while (l<=r) {
            k=mid=(l+r)>>1;
            if (ans[k]==-1) ans[k]=solve();
            if (ans[k]==ans[cur]) pos=mid, l=mid+1;
            else r=mid-1;
        }
        for (int j=cur+1; j<=pos; j++) ans[j]=ans[cur];
        cur=pos+1;
    }
    for (int i=1; i<=n; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, T, k, tot=0;
vector<int> e[maxn];
int ans[maxn], f[maxn], len[maxn][2], dfn[maxn], fa[maxn], id[maxn];
void dfs(int u, int pa) {
    dfn[u]=++tot; fa[u]=pa; id[tot]=u;
    for (auto v:e[u]) if (v!=pa) dfs(v, u);
}
int solve() {
    for (int i=1; i<=n; i++) f[i]=len[i][0]=len[i][1]=0;
    for (int i=n; i>=1; i--) {
        int u=id[i];
        if (len[u][0]+len[u][1]+1>=k) f[u]++, f[fa[u]]+=f[u];
        else {
            f[fa[u]]+=f[u]; len[u][0]++;
            if (len[u][0]>len[fa[u]][0]) len[fa[u]][1]=len[fa[u]][0], len[fa[u]][0]=len[u][0];
            else if (len[u][0]>len[fa[u]][1]) len[fa[u]][1]=len[u][0];
        }
    }
    return f[id[1]];
}
int main() {
    scanf("%d", &n);
    for (int i=0; i<n-1; i++) {
        int u, v; scanf("%d%d", &u, &v);
        e[u].push_back(v); e[v].push_back(u);
    }
    dfs(1, 0);
    if (n<=5000) T=n;
    else T=sqrt(n*log(n)/log(2));
    memset(ans, -1, sizeof(ans));
    ans[1]=n;
    for (k=2; k<=T; k++) ans[k]=solve();
    int cur=T+1;
    while (cur<=n) {
        if (ans[cur]==-1) {
            k=cur; ans[cur]=solve();
        }
        if (ans[cur]==0) {
            for (int i=cur+1; i<=n; i++) ans[i]=0;
            break;
        }
        int l=cur+1, r=n, mid, pos=cur;
        while (l<=r) {
            k=mid=(l+r)>>1;
            if (ans[k]==-1) ans[k]=solve();
            if (ans[k]==ans[cur]) pos=mid, l=mid+1;
            else r=mid-1;
        }
        for (int j=cur+1; j<=pos; j++) ans[j]=ans[cur];
        cur=pos+1;
    }
    for (int i=1; i<=n; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, T, k;
vector<int> e[maxn];
int ans[maxn], f[maxn], len[maxn];
void dfs(int u, int pa) {
    int l1=0, l2=0; f[u]=len[u]=0;
    for (auto v:e[u]) if (v!=pa) {
        dfs(v, u);
        f[u]+=f[v];
        if (len[v]>l1) l2=l1, l1=len[v];
        else if (len[v]>l2) l2=len[v];
    }
    if (l1+l2+1>=k) f[u]++, len[u]=0;
    else len[u]=l1+1;
}
int solve() {
    dfs(1, 0);
    return f[1];
}
int main() {
    scanf("%d", &n);
    for (int i=0; i<n-1; i++) {
        int u, v; scanf("%d%d", &u, &v);
        e[u].push_back(v); e[v].push_back(u);
    }
    if (n<=5000) T=n;
    else T=sqrt(n*log2(n));
    memset(ans, -1, sizeof(ans));
    ans[1]=n;
    for (k=2; k<=T; k++) ans[k]=solve();
    int cur=T+1;
    while (cur<=n) {
        if (ans[cur]==-1) {
            k=cur; ans[cur]=solve();
        }
        if (ans[cur]==0) {
            for (int i=cur+1; i<=n; i++) ans[i]=0;
            break;
        }
        int l=cur+1, r=n, mid, pos=cur;
        while (l<=r) {
            k=mid=(l+r)>>1;
            if (ans[k]==-1) ans[k]=solve();
            if (ans[k]==ans[cur]) pos=mid, l=mid+1;
            else r=mid-1;
        }
        for (int j=cur+1; j<=pos; j++) ans[j]=ans[cur];
        cur=pos+1;
    }
    for (int i=1; i<=n; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, T, k;
vector<int> e[maxn];
int ans[maxn], f[maxn], len[maxn];
inline void dfs(int u, int pa) {
    if (e[u].size()==1&&pa!=0) {
        f[u]=0; len[u]=1; return;
    }
    int l1=0, l2=0; f[u]=0;
    for (int i=0; i<e[u].size(); i++) {
        int v=e[u][i];
        if (v==pa) continue;
        dfs(v, u);
        f[u]+=f[v];
        if (len[v]>l1) {
            l2=l1; l1=len[v];
        } else if (len[v]>l2) l2=len[v];
    }
    if (l1+l2+1>=k) {
        f[u]++; len[u]=0;
    } else len[u]=l1+1;
}
inline int solve() {
    dfs(1, 0);
    return f[1];
}
int main() {
    scanf("%d", &n);
    for (int i=0; i<n-1; i++) {
        int u, v; scanf("%d%d", &u, &v);
        e[u].push_back(v); e[v].push_back(u);
    }
    if (n<=1000) T=n;
    else T=sqrt(n*log2(n));
    memset(ans, -1, sizeof(ans));
    ans[1]=n;
    for (k=2; k<=T; k++) ans[k]=solve();
    int cur=T+1;
    while (cur<=n) {
        if (ans[cur]==-1) {
            k=cur; ans[cur]=solve();
        }
        if (ans[cur]==0) {
            for (int i=cur+1; i<=n; i++) ans[i]=0;
            break;
        }
        int l=cur+1, r=n, mid, pos=cur;
        while (l<=r) {
            k=mid=(l+r)>>1;
            if (ans[k]==-1) ans[k]=solve();
            if (ans[k]==ans[cur]) pos=mid, l=mid+1;
            else r=mid-1;
        }
        for (int j=cur+1; j<=pos; j++) ans[j]=ans[cur];
        cur=pos+1;
    }
    for (int i=1; i<=n; i++) printf("%d\n", ans[i]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100005;
int fir[N],nxt[N<<1],go[N<<1],f[N],cnt;
int n,Lim;
inline void Add(int u,int v){
	nxt[++cnt]=fir[u];
	fir[u]=cnt;
	go[cnt]=v;
}
int dfs(int u,int fa){
	int no1=0,no2=0;
	for(int e=fir[u];e;e=nxt[e]){
		int v=go[e];
		if(v==fa) continue;
		int w=dfs(v,u);
		f[u]+=f[v];
		if(w>no1) no2=no1,no1=w;
		else if(w>no2) no2=w;
	}
	if(no1+no2+1>=Lim){f[u]++;return 0;}
	else return no1+1;
}

int main(){
	n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
	for(int i=1;i<=n;i++){
		Lim=i;
		memset(f,0,sizeof(f));
		dfs(1,0);
		write(f[1]);putchar('\n');
	}
	return 0;
}


#include<bits/stdc++.h>
#define R register
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100005;
int fir[N],nxt[N<<1],go[N<<1],f[N],cnt,id[N],rt,fa[N];
int n,Lim;
inline void Add(int u,int v){
	nxt[++cnt]=fir[u];
	fir[u]=cnt;
	go[cnt]=v;
}
void dfs(int u,int f){
	for(int e=fir[u];e;e=nxt[e]){
		int v=go[e];
		if(v==f) continue;
		fa[v]=u;
		dfs(v,u);
	}
	id[++rt]=u;
}
//inline int dfs(int u,int fa){
//	R int no1=0,no2=0;
//	for(R int e=fir[u];e;e=nxt[e]){
//		int v=go[e];
//		if(v==fa) continue;
//		int w=dfs(v,u);
//		f[u]+=f[v];
//		if(w>no1) no2=no1,no1=w;
//		else if(w>no2) no2=w;
//	}
//	if(no1+no2+1>=Lim){f[u]++;return 0;}
//	else return no1+1;
//}
inline int work(int k){
	int res=0;
	for(int i=1;i<=n;i++) f[i]=1;
	for(int i=1;i<=n;i++){
		if(fa[id[i]]&&f[id[i]]!=-1&&f[fa[id[i]]]!=-1){
			if(f[id[i]]+f[fa[id[i]]]>=k){
				res++;
				f[fa[id[i]]]=-1;
			}else{
				f[fa[id[i]]]=max(f[fa[id[i]]],f[id[i]]+1);
			}
		}
	}
	return res;
}
int main(){
	n=read();
	int size=(int)(sqrt(n*log(n)/log(2)));
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
	dfs(1,0);
	write(n);putchar('\n');
	for(int i=2;i<=size;i++){
		write(work(i));putchar('\n');
	}
	int pos=size;
	while(pos<n){
		int fg=work(pos+1);
		if(fg==0){
			for(int i=pos+1;i<=n;i++){
				puts("0");
			}
			return 0;
		}
		R int l=pos+1,r=n+1,mid;
		while(r-l>1){
			mid=(l+r)>>1;
			if(work(mid)==fg) l=mid;
			else r=mid;
		}
		for(int i=pos+1;i<=l;i++){
			write(fg);putchar('\n');
		}
		pos=l;
	}
	return 0;
}


#include<bits/stdc++.h>
#define R register
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100005;
int fir[N],nxt[N<<1],go[N<<1],f[N],cnt;
int n,Lim;
inline void Add(int u,int v){
	nxt[++cnt]=fir[u];
	fir[u]=cnt;
	go[cnt]=v;
}
inline int dfs(int u,int fa){
	int no1=0,no2=0;
	for(int e=fir[u];e;e=nxt[e]){
		int v=go[e];
		if(v==fa) continue;
		int w=dfs(v,u);
		f[u]+=f[v];
		if(w>no1) no2=no1,no1=w;
		else if(w>no2) no2=w;
	}
	if(no1+no2+1>=Lim){f[u]++;return 0;}
	else return no1+1;
}
inline int work(int k){
	Lim=k;
	memset(f,0,sizeof(f));
	dfs(1,0);
	return f[1];
}
int main(){
	n=read();
	int size=(int)(sqrt(n*log(n)/log(2)));
//	cout<<size<<endl;
//	cout<<log2(n)<<endl;
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
//	for(int i=1;i<=n;i++){
//		Lim=i;
//		memset(f,0,sizeof(f));
//		dfs(1,0);
//		write(f[1]);putchar('\n');
//	}
	write(n);putchar('\n');
	for(int i=2;i<=size;i++){
		write(work(i));putchar('\n');
	}
	int pos=size;
	while(pos<n){
		int fg=work(pos+1);
		if(fg==0){
			for(int i=pos+1;i<=n;i++){
				puts("0");
			}
			return 0;
		}
		R int l=pos+1,r=n+1,mid;
		while(r-l>1){
			mid=(l+r)>>1;
			if(work(mid)==fg) l=mid;
			else r=mid;
		}
		for(int i=pos+1;i<=l;i++){
			write(fg);putchar('\n');
		}
		pos=l;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100005;
int fir[N],nxt[N<<1],go[N<<1],f[N],cnt;
int n,Lim;
inline void Add(int u,int v){
	nxt[++cnt]=fir[u];
	fir[u]=cnt;
	go[cnt]=v;
}
int dfs(int u,int fa){
	int no1=0,no2=0;
	for(int e=fir[u];e;e=nxt[e]){
		int v=go[e];
		if(v==fa) continue;
		int w=dfs(v,u);
		f[u]+=f[v];
		if(w>no1) no2=no1,no1=w;
		else if(w>no2) no2=w;
	}
	if(no1+no2+1>=Lim){f[u]++;return 0;}
	else return no1+1;
}
inline int work(int k){
	Lim=k;
	memset(f,0,sizeof(f));
	dfs(1,0);
	return f[1];
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
//	for(int i=1;i<=n;i++){
//		Lim=i;
//		memset(f,0,sizeof(f));
//		dfs(1,0);
//		write(f[1]);putchar('\n');
//	}
	int size=sqrt(n);
	for(int i=1;i<=size;i++){
		write(work(i));putchar('\n');
	}
	int pos=size;
	while(pos<n){
		int fg=work(pos+1);
		if(fg==0){
			for(int i=pos+1;i<=n;i++){
				puts("0");
			}
			return 0;
		}
		int l=pos+1,r=n+1;
		while(r-l>1){
			int mid=(l+r)>>1;
			if(work(mid)==fg) l=mid;
			else r=mid;
		}
		for(int i=pos+1;i<=l;i++){
			write(fg);putchar('\n');
		}
		pos=l;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100005;
int fir[N],nxt[N<<1],go[N<<1],f[N],cnt;
int n,Lim;
inline void Add(int u,int v){
	nxt[++cnt]=fir[u];
	fir[u]=cnt;
	go[cnt]=v;
}
int dfs(int u,int fa){
	int no1=0,no2=0;
	for(int e=fir[u];e;e=nxt[e]){
		int v=go[e];
		if(v==fa) continue;
		int w=dfs(v,u);
		f[u]+=f[v];
		if(w>no1) no2=no1,no1=w;
		else if(w>no2) no2=w;
	}
	if(no1+no2+1>=Lim){f[u]++;return 0;}
	else return no1+1;
}
inline int work(int k){
	Lim=k;
	memset(f,0,sizeof(f));
	dfs(1,0);
	return f[1];
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
//	for(int i=1;i<=n;i++){
//		Lim=i;
//		memset(f,0,sizeof(f));
//		dfs(1,0);
//		write(f[1]);putchar('\n');
//	}
	int size=sqrt(n)*log2(n);
	for(int i=1;i<=size;i++){
		write(work(i));putchar('\n');
	}
	int pos=size;
	while(pos<n){
		int fg=work(pos+1);
		if(fg==0){
			for(int i=pos+1;i<=n;i++){
				puts("0");
			}
			return 0;
		}
		int l=pos+1,r=n+1;
		while(r-l>1){
			int mid=(l+r)>>1;
			if(work(mid)==fg) l=mid;
			else r=mid;
		}
		for(int i=pos+1;i<=l;i++){
			write(fg);putchar('\n');
		}
		pos=l;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100005;
int fir[N],nxt[N<<1],go[N<<1],f[N],cnt;
int n,Lim;
inline void Add(int u,int v){
	nxt[++cnt]=fir[u];
	fir[u]=cnt;
	go[cnt]=v;
}
int dfs(int u,int fa){
	int no1=0,no2=0;
	for(int e=fir[u];e;e=nxt[e]){
		int v=go[e];
		if(v==fa) continue;
		int w=dfs(v,u);
		f[u]+=f[v];
		if(w>no1) no2=no1,no1=w;
		else if(w>no2) no2=w;
	}
	if(no1+no2+1>=Lim){f[u]++;return 0;}
	else return no1+1;
}
inline int work(int k){
	Lim=k;
	memset(f,0,sizeof(f));
	dfs(1,0);
	return f[1];
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
//	for(int i=1;i<=n;i++){
//		Lim=i;
//		memset(f,0,sizeof(f));
//		dfs(1,0);
//		write(f[1]);putchar('\n');
//	}
	int pos=0;
	while(pos<n){
		int fg=work(pos+1);
		int l=pos+1,r=n+1;
		while(r-l>1){
			int mid=(l+r)>>1;
			if(work(mid)==fg) l=mid;
			else r=mid;
		}
		for(int i=pos+1;i<=l;i++){
			write(fg);putchar('\n');
		}
		pos=l;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100005;
int fir[N],nxt[N<<1],go[N<<1],f[N],cnt;
int n,Lim;
inline void Add(int u,int v){
	nxt[++cnt]=fir[u];
	fir[u]=cnt;
	go[cnt]=v;
}
int dfs(int u,int fa){
	int no1=0,no2=0;
	for(int e=fir[u];e;e=nxt[e]){
		int v=go[e];
		if(v==fa) continue;
		int w=dfs(v,u);
		f[u]+=f[v];
		if(w>no1) no2=no1,no1=w;
		else if(w>no2) no2=w;
	}
	if(no1+no2+1>=Lim){f[u]++;return 0;}
	else return no1+1;
}
inline int work(int k){
	Lim=k;
	memset(f,0,sizeof(f));
	dfs(1,0);
	return f[1];
}
int main(){
	n=read();
	int size=(int)(sqrt(n*log2(n)));
//	cout<<size<<endl;
//	cout<<log2(n)<<endl;
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
//	for(int i=1;i<=n;i++){
//		Lim=i;
//		memset(f,0,sizeof(f));
//		dfs(1,0);
//		write(f[1]);putchar('\n');
//	}
	for(int i=1;i<=size;i++){
		write(work(i));putchar('\n');
	}
	int pos=size;
	while(pos<n){
		int fg=work(pos+1);
		if(fg==0){
			for(int i=pos+1;i<=n;i++){
				puts("0");
			}
			return 0;
		}
		int l=pos+1,r=pos+size+1;
		while(r-l>1){
			int mid=(l+r)>>1;
			if(work(mid)==fg) l=mid;
			else r=mid;
		}
		for(int i=pos+1;i<=l;i++){
			write(fg);putchar('\n');
		}
		pos=l;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100005;
int fir[N],nxt[N<<1],go[N<<1],f[N],cnt;
int n,Lim;
inline void Add(int u,int v){
	nxt[++cnt]=fir[u];
	fir[u]=cnt;
	go[cnt]=v;
}
int dfs(int u,int fa){
	int no1=0,no2=0;
	for(int e=fir[u];e;e=nxt[e]){
		int v=go[e];
		if(v==fa) continue;
		int w=dfs(v,u);
		f[u]+=f[v];
		if(w>no1) no2=no1,no1=w;
		else if(w>no2) no2=w;
	}
	if(no1+no2+1>=Lim){f[u]++;return 0;}
	else return no1+1;
}
inline int work(int k){
	Lim=k;
	memset(f,0,sizeof(f));
	dfs(1,0);
	return f[1];
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
//	for(int i=1;i<=n;i++){
//		Lim=i;
//		memset(f,0,sizeof(f));
//		dfs(1,0);
//		write(f[1]);putchar('\n');
//	}
	int pos=0;
	while(pos<n){
		int fg=work(pos+1);
		if(fg==0){
			for(int i=pos+1;i<=n;i++){
				puts("0");
			}
			return 0;
		}
		int l=pos+1,r=n+1;
		while(r-l>1){
			int mid=(l+r)>>1;
			if(work(mid)==fg) l=mid;
			else r=mid;
		}
		for(int i=pos+1;i<=l;i++){
			write(fg);putchar('\n');
		}
		pos=l;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
const int N=100005;
int fir[N],nxt[N<<1],go[N<<1],f[N],cnt;
int n,Lim;
inline void Add(int u,int v){
	nxt[++cnt]=fir[u];
	fir[u]=cnt;
	go[cnt]=v;
}
int dfs(int u,int fa){
	int no1=0,no2=0;
	for(int e=fir[u];e;e=nxt[e]){
		int v=go[e];
		if(v==fa) continue;
		int w=dfs(v,u);
		f[u]+=f[v];
		if(w>no1) no2=no1,no1=w;
		else if(w>no2) no2=w;
	}
	if(no1+no2+1>=Lim){f[u]++;return 0;}
	else return no1+1;
}
inline int work(int k){
	Lim=k;
	memset(f,0,sizeof(f));
	dfs(1,0);
	return f[1];
}
int main(){
	n=read();
	int size=(int)(sqrt(n*log2(n)));
//	cout<<size<<endl;
//	cout<<log2(n)<<endl;
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
//	for(int i=1;i<=n;i++){
//		Lim=i;
//		memset(f,0,sizeof(f));
//		dfs(1,0);
//		write(f[1]);putchar('\n');
//	}
	for(int i=1;i<=size;i++){
		write(work(i));putchar('\n');
	}
	int pos=size;
	while(pos<n){
		int fg=work(pos+1);
		if(fg==0){
			for(int i=pos+1;i<=n;i++){
				puts("0");
			}
			return 0;
		}
		int l=pos+1,r=n+1;
		while(r-l>1){
			int mid=(l+r)>>1;
			if(work(mid)==fg) l=mid;
			else r=mid;
		}
		for(int i=pos+1;i<=l;i++){
			write(fg);putchar('\n');
		}
		pos=l;
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
    char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}

int head[202002],to[202002],nxt[202022];
int tot;

void add(int x,int y){
    tot++;
    to[tot]=y;
    nxt[tot]=head[x];
    head[x]=tot;
}

int f[202200],dis[220222];
int cnt,mid,d;
vector<int> G[101001];

int dfs(int x){
    int mx=0,cmx=0;
    for(int i=0;i<G[x].size();++i){
        d=dfs(G[x][i]);
        if(d>mx)cmx=mx,mx=d;
        else if(d>cmx)cmx=d;
    }
    if(mx+cmx+1>=mid)++cnt,mx=-1;
    return mx+1;
}
void DFS(int x,int fa=-1){
    for(int i=head[x];i;i=nxt[i]){
        if(fa==to[i])continue;
        G[x].push_back(to[i]);
        DFS(to[i],x);
    }
}
int a[2020202];

int main(){
    int n=read();
    for(int i=1;i<n;i++){
        int x=read(),y=read();
        add(x,y);
        add(y,x);
    }
    DFS(1);
    int blk=sqrt(n*log2(n));
    for(int i=1;i<=blk;i++){
        mid=i,cnt=0;dfs(1);
        printf("%d\n",cnt);
    }
    for(int i=blk+1;i<=n;){
    	cnt=0;
    	mid=i;
    	dfs(1);
        int l=i,r=n,tmp=cnt,ans;
        while(l<=r){
            mid=(l+r)/2;
            cnt=0;
            dfs(1);
            if(cnt==tmp) ans=mid,l=mid+1;
            else r=mid-1;
        }
        int j=ans;
        for(int k=i;k<=j;k++){
        	a[k]=tmp;
		}
        i=j+1;j=i;
    }
    for(int i=blk+1;i<=n;i++){
        printf("%d\n",a[i]);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
	char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int head[202002],to[202002],nxt[202022];
int tot;

void add(int x,int y){
	tot++;
	to[tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}

int f[202200],dis[220222];

void dfs(int x,int fa,int k){
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==fa) continue;
		dfs(y,x,k);
		f[x]+=f[y];
	}
	int mx1=0,mx2=0;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==fa) continue;
		int d=dis[y];
		if(d>=mx1){
			mx2=mx1;
			mx1=d;
		}
		else if(d>=mx2 && d<mx1){
			mx2=d;
		}
	}
	if(mx1+mx2+1>=k){
		dis[x]=0;
		f[x]++;
	}
	else {
		dis[x]=mx1+1;
	}
}

int check(int lim,int k){
	memset(f,0,sizeof(f));
	memset(dis,0,sizeof(dis));
	dfs(1,0,k);
	if(f[1]>=lim) return 1;
	else return 0;
}

int main(){
	int n=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	for(int i=1;i<=n;i++){
		int l=0,r=n/i,mid,ans;
		while(l<=r){
			mid=(l+r)>>1;
			if(check(mid,i)){
				ans=mid;
				l=mid+1;
			}
			else r=mid-1;
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
    char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}

int head[202002],to[202002],nxt[202022];
int tot;

void add(int x,int y){
    tot++;
    to[tot]=y;
    nxt[tot]=head[x];
    head[x]=tot;
}

int f[202200],dis[220222];
int cnt,d;
vector<int> G[101001];

int dfs(int x,int mid){
    int mx=0,cmx=0;
    for(int i=0;i<G[x].size();++i){
        d=dfs(G[x][i],mid);
        if(d>mx)cmx=mx,mx=d;
        else if(d>cmx)cmx=d;
    }
    if(mx+cmx+1>=mid)++cnt,mx=-1;
    return mx+1;
}
void DFS(int x,int fa=-1){
    for(int i=head[x];i;i=nxt[i]){
        if(fa==to[i])continue;
        G[x].push_back(to[i]);
        DFS(to[i],x);
    }
}
int a[2020202];

int main(){
    int n=read();
    for(int i=1;i<n;i++){
        int x=read(),y=read();
        add(x,y);
        add(y,x);
    }
    DFS(1);
    int blk=sqrt(n*log2(n));
    for(int i=1;i<=blk;i++){
        cnt=0;dfs(1,i);
        printf("%d\n",cnt);
    }
    for(int i=blk+1;i<=n;){
    	cnt=0;
    	dfs(1,i);
        int l=i,r=n,tmp=cnt,ans,mid;
        while(l<=r){
            mid=(l+r)/2;
            cnt=0;
            dfs(1,mid);
            if(cnt==tmp) ans=mid,l=mid+1;
            else r=mid-1;
        }
        int j=ans;
        for(int k=i;k<=j;k++){
        	a[k]=tmp;
		}
        i=j+1;j=i;
    }
    for(int i=blk+1;i<=n;i++){
        printf("%d\n",a[i]);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
	char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int head[2020202],to[2020202],nxt[2020202];
int tot;

void add(int x,int y){
	tot++;
	to[tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}

int f[2020200],dis[2202022];

void dfs(int x,int fa,int k){
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==fa) continue;
		dfs(y,x,k);
		f[x]+=f[y];
	}
	int mx1=0,mx2=0;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==fa) continue;
		int d=dis[y];
		if(d>=mx1){
			mx2=mx1;
			mx1=d;
		}
		else if(d>=mx2 && d<mx1){
			mx2=d;
		}
	}
	if(mx1+mx2+1>=k){
		dis[x]=0;
		f[x]++;
	}
	else {
		dis[x]=mx1+1;
	}
}

int check(int lim,int k){
	memset(f,0,sizeof(f));
	memset(dis,0,sizeof(dis));
	dfs(1,0,k);
	if(f[1]>=lim) return 1;
	else return 0;
}

int main(){
	int n=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	for(int i=1;i<=n;i++){
		int l=0,r=n/i+1,mid,ans;
		while(l<=r){
			mid=(l+r)>>1;
			if(check(mid,i)){
				ans=mid;
				l=mid+1;
			}
			else r=mid-1;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
    char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}

int head[202002],to[202002],nxt[202022];
int tot;

void add(int x,int y){
    tot++;
    to[tot]=y;
    nxt[tot]=head[x];
    head[x]=tot;
}

int f[202200],dis[220222];
int cnt,mid,d;
vector<int> G[101001];

int dfs(int x){
    int mx=0,cmx=0;
    for(int i=0;i<G[x].size();++i){
        d=dfs(G[x][i]);
        if(d>mx)cmx=mx,mx=d;
        else if(d>cmx)cmx=d;
    }
    if(mx+cmx+1>=mid)++cnt,mx=-1;
    return mx+1;
}
void DFS(int x,int fa=-1){
    for(int i=head[x];i;i=nxt[i]){
        if(fa==to[i])continue;
        G[x].push_back(to[i]);
        DFS(to[i],x);
    }
}
int a[2020202];

int main(){
    int n=read();
    for(int i=1;i<n;i++){
        int x=read(),y=read();
        add(x,y);
        add(y,x);
    }
    DFS(1);
    int blk=sqrt(n*log2(n));
    for(int i=1;i<=blk;i++){
        mid=i,cnt=0;dfs(1);
        printf("%d\n",cnt);
    }
    for(int i=blk+1;i<=n;){
    	cnt=0;
    	mid=i;
    	dfs(1);
        int l=i,r=n,tmp=cnt;
        while(l<=r){
            mid=(l+r)/2;
            cnt=0;
            dfs(1);
            if(cnt==tmp) l=mid+1;
            else r=mid-1;
        }
        int j=l;
        for(int k=i;k<=j;k++){
        	a[k]=tmp;
		}
        i=j+1;j=i;
    }
    for(int i=blk+1;i<=n;i++){
        printf("%d\n",a[i]);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
	char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int head[202002],to[202002],nxt[202022];
int tot;

void add(int x,int y){
	tot++;
	to[tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}

int f[202200],dis[220222];
int cnt,mid,d;
vector<int> G[101001];

int dfs(int x,int fa){
    int mx=0,cmx=0;
    for(int i=head[x];i;i=nxt[i]){
    	int y=to[i];
    	if(y==fa) continue;
        d=dfs(y,x);
        if(d>mx)cmx=mx,mx=d;
        else if(d>cmx)cmx=d;
    }
    if(mx+cmx+1>=mid)++cnt,mx=-1;
    return mx+1;
}

int a[2020202];

int main(){
	int n=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	int blk=sqrt(n*log2(n)),lim=n/blk;
	for(int i=1;i<=blk;i++){
		mid=i,cnt=0;dfs(1,0);
		printf("%d\n",cnt);
	}
	for(int i=0;i<=lim;i++){
		int l=0,r=n;
		while(l<r){
			mid=(l+r>>1)+1;
			cnt=0;
			dfs(1,0);
			if(cnt>=i) l=mid;
			else r=mid-1;
		}
		a[i]=l;
	}
	for(int i=blk+1;i<=n;i++){
		while(a[lim]<i) lim--;
		printf("%d\n",lim);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
	char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int head[202002],to[202002],nxt[202022];
int tot;

void add(int x,int y){
	tot++;
	to[tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}

int f[202200],dis[220222];

void dfs(int x,int fa,int k){
	f[x]=0,dis[x]=0;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==fa) continue;
		dfs(y,x,k);
		f[x]+=f[y];
	}
	int mx1=0,mx2=0;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==fa) continue;
		int d=dis[y];
		if(d>=mx1){
			mx2=mx1;
			mx1=d;
		}
		else if(d>=mx2 && d<mx1){
			mx2=d;
		}
	}
	if(mx1+mx2+1>=k){
		dis[x]=0;
		f[x]++;
	}
	else {
		dis[x]=mx1+1;
	}
}

int a[2020202];

int ans[2020022];

int main(){
	int n=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	int blk=sqrt(n*log2(n)),lim=n/blk;
	for(int i=1;i<=blk;i++){
		dfs(1,0,i);
		printf("%d\n",f[1]);
	}
	for(int i=0;i<=lim;i++){
		int l=0,r=n,mid;
		while(l<r){
			mid=(l+r>>1)+1;
			dfs(1,0,mid);
			if(f[1]>=i) l=mid;
			else r=mid-1;
		}
		a[i]=l;
	}
	for(int i=blk+1;i<=n;i++){
		while(a[lim]<i) lim--;
		printf("%d\n",lim);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
	char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int head[202002],to[202002],nxt[202022];
int tot;

void add(int x,int y){
	tot++;
	to[tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}

int f[202200],dis[220222];
int cnt,mid,d;
vector<int> G[101001];

int dfs(int x){
    int mx=0,cmx=0;
    for(int i=0;i<G[x].size();++i){
        d=dfs(G[x][i]);
        if(d>mx)cmx=mx,mx=d;
        else if(d>cmx)cmx=d;
    }
    if(mx+cmx+1>=mid)++cnt,mx=-1;
    return mx+1;
}
void DFS(int x,int fa=-1){
    for(int i=head[x];i;i=nxt[i]){
        if(fa==to[i])continue;
        G[x].push_back(to[i]);
        DFS(to[i],x);
    }
}
int a[2020202];

int main(){
	int n=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	DFS(1);
	int blk=sqrt(n*log2(n)),lim=n/blk;
	for(int i=1;i<=blk;i++){
		mid=i,cnt=0;dfs(1);
		printf("%d\n",cnt);
	}
	for(int i=0;i<=lim;i++){
		int l=0,r=n;
		while(l<r){
			mid=(l+r>>1)+1;
			cnt=0;
			dfs(1);
			if(cnt>=i) l=mid;
			else r=mid-1;
		}
		a[i]=l;
	}
	for(int i=blk+1;i<=n;i++){
		while(a[lim]<i) lim--;
		printf("%d\n",lim);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
	char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int head[202002],to[202002],nxt[202022];
int tot;

void add(int x,int y){
	tot++;
	to[tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}

int f[202200],dis[220222];

void dfs(int x,int fa,int k){
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==fa) continue;
		dfs(y,x,k);
		f[x]+=f[y];
	}
	int mx1=0,mx2=0;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==fa) continue;
		int d=dis[y];
		if(d>=mx1){
			mx2=mx1;
			mx1=d;
		}
		else if(d>=mx2 && d<mx1){
			mx2=d;
		}
	}
	if(mx1+mx2+1>=k){
		dis[x]=0;
		f[x]++;
	}
	else {
		dis[x]=mx1+1;
	}
}

int check(int lim,int k){
	memset(f,0,sizeof(f));
	memset(dis,0,sizeof(dis));
	dfs(1,0,k);
	if(f[1]>=lim) return 1;
	else return 0;
}

int main(){
	int n=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	for(int i=1;i<=n;i++){
		int l=0,r=n/i+1,mid,ans;
		while(l<=r){
			mid=(l+r)>>1;
			if(check(mid,i)){
				ans=mid;
				l=mid+1;
			}
			else r=mid-1;
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
    char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}

int head[202002],to[202002],nxt[202022];
int tot;

void add(int x,int y){
    tot++;
    to[tot]=y;
    nxt[tot]=head[x];
    head[x]=tot;
}

int f[202200],dis[220222];
int cnt,mid,d;
vector<int> G[101001];

int dfs(int x){
    int mx=0,cmx=0;
    for(int i=0;i<G[x].size();++i){
        d=dfs(G[x][i]);
        if(d>mx)cmx=mx,mx=d;
        else if(d>cmx)cmx=d;
    }
    if(mx+cmx+1>=mid)++cnt,mx=-1;
    return mx+1;
}
void DFS(int x,int fa=-1){
    for(int i=head[x];i;i=nxt[i]){
        if(fa==to[i])continue;
        G[x].push_back(to[i]);
        DFS(to[i],x);
    }
}
int a[2020202];

int main(){
    int n=read();
    for(int i=1;i<n;i++){
        int x=read(),y=read();
        add(x,y);
        add(y,x);
    }
    DFS(1);
    int blk=sqrt(n*log2(n));
    for(int i=1;i<=blk;i++){
        mid=i,cnt=0;dfs(1);
        printf("%d\n",cnt);
    }
    for(int i=blk+1;i<=n;){
    	cnt=0;
    	mid=i;
    	dfs(1);
        int l=i,r=n,tmp=cnt;
        while(l<r){
            mid=(l+r+1)/2;
            cnt=0;
            dfs(1);
            if(cnt==tmp) l=mid;
            else r=mid-1;
        }
        int j=l;
        for(int k=i;k<=j;k++){
        	a[k]=tmp;
		}
        i=j+1;j=i;
    }
    for(int i=blk+1;i<=n;i++){
        printf("%d\n",a[i]);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
	char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

int head[202002],to[202002],nxt[202022];
int tot;

void add(int x,int y){
	tot++;
	to[tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}

int f[202200],dis[220222];

void dfs(int x,int fa,int k){
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==fa) continue;
		dfs(y,x,k);
		f[x]+=f[y];
	}
	int mx1=0,mx2=0;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==fa) continue;
		int d=dis[y];
		if(d>=mx1){
			mx2=mx1;
			mx1=d;
		}
		else if(d>=mx2 && d<mx1){
			mx2=d;
		}
	}
	if(mx1+mx2+1>=k){
		dis[x]=0;
		f[x]++;
	}
	else {
		dis[x]=mx1+1;
	}
}

int check(int lim,int k){
	memset(f,0,sizeof(f));
	memset(dis,0,sizeof(dis));
	dfs(1,0,k);
	if(f[1]>=lim) return 1;
	else return 0;
}

int ans[2020022];

int main(){
	int n=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	ans[0]=n;
	for(int i=1;i<=n;i++){
		int l=0,r=ans[i-1],mid;
		while(l<=r){
			mid=(l+r)>>1;
			if(check(mid,i)){
				ans[i]=mid;
				l=mid+1;
			}
			else r=mid-1;
		}
		printf("%d\n",ans[i]);
	}
	return 0;
}


#include<bits/stdc++.h>
#define il inline
#define vd void
typedef long long ll;
il int gi(){
    int x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int fir[100010],dis[200010],nxt[200010],id;
il vd link(int a,int b){nxt[++id]=fir[a],fir[a]=id,dis[id]=b;}
std::vector<int>G[100010];
int tot,mid,d;
il int dfs(int x){
    int mx=0,cmx=0;
    for(int i=0;i<G[x].size();++i){
        d=dfs(G[x][i]);
        if(d>mx)cmx=mx,mx=d;
        else if(d>cmx)cmx=d;
    }
    if(mx+cmx+1>=mid)++tot,mx=-1;
    return mx+1;
}
il vd DFS(int x,int fa=-1){
    for(int i=fir[x];i;i=nxt[i]){
        if(fa==dis[i])continue;
        G[x].push_back(dis[i]);
        DFS(dis[i],x);
    }
}
int R[100010];
int main(){
    int n=gi(),a,b,blk=sqrt(n*log2(n)),lim=n/blk,l,r;
    for(int i=1;i<n;++i)a=gi(),b=gi(),link(a,b),link(b,a);
    DFS(1);
    for(int i=1;i<=blk;++i)mid=i,tot=0,dfs(1),printf("%d\n",tot);
    for(int i=0;i<=lim;++i){
        l=0,r=n;
        while(l<r){
            mid=((l+r)>>1)+1;tot=0;dfs(1);
            if(tot>=i)l=mid;
            else r=mid-1;
        }
        R[i]=l;
    }
    int p=lim;
    for(int i=blk+1;i<=n;++i){
        while(R[p]<i)--p;
        printf("%d\n",p);
    }
    return 0;
}