n = int(input())
s  = input()
p = [list() for i in range(27)]
# print(p)
i=0

for e in s:
	p[ord(e)-ord('a')].append(i+1)
	i+=1
# print(p)
t = int(input())
for _ in range(t):
	si  = input()
	cnt = [0]*27
	for e in si:
		cnt[ord(e)-ord('a')]+=1
	ans = -1
	for i in range(27):
		if(cnt[i]>0):
			ans = max(ans,p[i][cnt[i]-1])
	print(ans)


n = int(input())
s  = input()
t = int(input())
for _ in range(t):
	si = input()
	mp = [0]*27
	for e in si:
		mp[ord(e)-ord('a')]+=1
	cnt=0
	ln=0
	for e in s:
		if mp[ord(e)-ord('a')]>0:
			mp[ord(e)-ord('a')]-=1
			ln+=1
		cnt+=1
		if ln == len(si):
			break

	print(cnt)


from collections import defaultdict, Counter

n = int(input())

s = input()

m = int(input())

for i in range(m):

    name = input()
    d = dict(Counter(name))

    for j in range(len(s)):
        if s[j] in d:
            d[s[j]] -= 1
            if d[s[j]] == 0:
                del d[s[j]]

        if not d:
            print(j + 1)
            break


from collections import defaultdict, deque, Counter
from copy import deepcopy

n = int(input())

s = input()

m = int(input())

d = defaultdict(deque)
for c in range(len(s)):
    d[s[c]].append(c + 1)

for i in range(m):

    name = input()

    temp = d.copy()

    ret = -1

    now = dict(Counter(name))

    for k, v in now.items():
        ret = max(ret, d[k][v-1])

    print(ret)


from collections import defaultdict, deque, Counter
from copy import deepcopy

n = int(input())

s = input()

m = int(input())

d = defaultdict(deque)
for c in range(len(s)):
    d[s[c]].append(c + 1)

for i in range(m):

    name = input()

    temp = deepcopy(d)

    ret = -1

    now = dict(Counter(name))

    for k, v in now.items():
        ret = max(ret, d[k][v-1])

    print(ret)


from collections import defaultdict

n = int(input())

s = input()

m = int(input())

for i in range(m):
    d = defaultdict(int)
    name = input()

    for c in name:
        d[c] += 1

    for j in range(len(s)):
        if s[j] in d and d[s[j]] > 0:
            d[s[j]] -= 1
            if d[s[j]] == 0:
                del d[s[j]]

        if not d:
            print(j + 1)
            break


from collections import defaultdict, deque
from copy import deepcopy

n = int(input())

s = input()

m = int(input())

d = defaultdict(deque)
for c in range(len(s)):
    d[s[c]].append(c + 1)

for i in range(m):

    name = input()

    temp = deepcopy(d)

    ret = -1

    for c in name:
        now = temp[c].popleft()
        ret = max(ret, now)

    print(ret)


length = int(input())
string = input()
n = int(input())
result =[]
for _ in range(n):
    lowstring = list(input())
    for i in range(length):
        if  string[i] in lowstring:
            lowstring.remove(string[i])
            if len(lowstring)==0:
                result.append(i+1)
                break
[print(i) for i in result]


length = int(input())
string = input()
a=dict()
i =1
for  c in string:
    if c not in a.keys():
        a[c]=[]
    a[c].append(i)
    i +=1
n = int(input())
result =[]
for _ in range(n):
    lowstring = list(input())
    temp = dict()
    r = 0
    for c in lowstring:
        if c not in temp.keys():
            temp[c]=-1
        temp[c]+=1
        r = max(a[c][temp[c]],r)
    result.append(r)

[print(i) for i in result]


from collections import Counter
n = int(input())
s = input()
table = {}
for i in range(n):
    table[s[i]] = table.get(s[i],[]) + [i+1]

m = int(input())
for i in range(m):
    t = input()
    d = Counter(t)
    mx = 0
    for i in d.keys():
        mx = max(table[i][d[i]-1],mx)
    print(mx)


n = int(input())
s = input()
table = {}
for i in range(n):
    table[s[i]] = table.get(s[i],[]) + [i+1]

m = int(input())
for i in range(m):
    t = input()
    mx = 0
    d = {}
    for i in t:
        d[i] = d.get(i,0)+1
        mx = max(table[i][d[i]-1],mx)
    print(mx)


n = int(input())
s = input()
table = {}
for i in range(n):
    table[s[i]] = table.get(s[i],[]) + [i+1]

m = int(input())
for _ in range(m):
    t = input()
    mx = 0
    d = {}
    for i in t:
        d[i] = d.get(i,0)+1
        mx = max(table[i][d[i]-1],mx)
    print(mx)


from collections import Counter , defaultdict
n = int(input())
s = input()
m = int(input())
table = defaultdict(list)
for i,ch in enumerate(s):
    table[ch].append(i+1)

for _ in range(m):
    t = input()
    mx = 0
    d = {}
    for i in t:
        d[i] = d.get(i,0)+1
        mx = max(table[i][d[i]-1],mx)
    print(mx)


from collections import Counter
n = int(input())
s = input()
m = int(input())
for i in range(m):
    t = input()
    d = Counter(t)
    total = len(t)
    count = 0
    for i in range(n):
        if d.get(s[i]) and d[s[i]]>0:
            d[s[i]] -= 1
            count += 1
        if count == total:
            break
    if count!= len(t):
        print(-1)
    else:
        print(i+1)


n = int(input())
s = input()
l = [[] for _ in range(26)]
for i in range(len(s)):
    l[ord(s[i])-97].append(i+1)
# print(l)

for _ in range(int(input())):
    s2 = input()
    arr = [0 for _ in range(26)]
    ans = 0
    for c in s2:
        ans = max(ans, l[ord(c) - 97][arr[ord(c)-97]])
        arr[ord(c)-97] += 1
    print(ans)


n = int(input())
s = input()

occ = [list() for i in range(26)]
for i in range(n):
    occ[ord(s[i]) - ord('a')].append(i + 1)

m = int(input())
for _ in range(m):
    t = input()

    cnt = [0 for i in range(26)]
    for x in t:
        cnt[ord(x) - ord('a')] += 1

    ans = -1
    for i in range(26):
        if(cnt[i] > 0):
            ans = max(ans, occ[i][cnt[i] - 1])

    print(ans)


from collections import Counter

N = int(input())
S = input()
Q = int(input())
Query = [input() for _ in range(Q)]

dic = {}
for i, s in enumerate(S):
    if not s in dic.keys():
        dic[s] = [i]
    else:
        dic[s].append(i)

for T in Query:
    ans = 0
    C = Counter(list(T))
    for alp, num in C.items():
        ans = max(dic[alp][num-1]+1, ans)
    print(ans)


from collections import defaultdict

n = int(input())
s = input()
r = defaultdict(list)
for i, c in enumerate(s):
    r[c].append(i)
m = int(input())
for i in range(m):
    t = input()
    ans = 0
    pos = defaultdict(int)
    for c in t:
        pos[c] += 1
        ans = max(ans, r[c][pos[c]-1])
    print(ans+1)


from collections import defaultdict

m=int(input())
str=input()
r=defaultdict(list)
for i,c in enumerate(str):
    r[c].append(i)
n=int(input())
for i in range(m):
    str1=input()
    d=defaultdict(int)
    ans=0
    for t in str1:
        d[t]+=1
        ans=max(ans,r[t][d[t]-1])
    print(ans+1)


n=int(input())
s=input()
m=int(input())
for i in range(m):
  x=input()
  d={}
  count=0
  for j in x:
    if j not in d.keys():
      d[j]=1
      count+=1
    else:
      d[j]+=1
      count+=1

  c=0
  for j in s:

    if count==0:
       break
    c+=1
    if j in d and d[j]!=0:
       d[j]-=1
       count-=1

  print(c)


import collections
n=int(input())
s=input()
m=int(input())
d=collections.defaultdict(list)
for j in range(len(s)):
    d[s[j]].append(j)

for i in range(m):
  x=input()

  ma=0
  di=[]
  z=0
  for j in range(26):
    di.append(0)
  for j in x:

    z=d[j][di[ord(j)-97]]
    if z>ma:
      ma=z
    di[ord(j)-97]+=1

  print(ma+1)


def letters_shop(s, name, x):
    d=[]
    c=0
    for a in s:
        if a in name:
            name=name.replace(a,'',1)
            c+=1
            if len(name)==0:
                break
        else:
            c+=1
    return len(name)+c
# --------------------------------------------------------------
if __name__ == '__main__':
    n = int(input())
    ss = input()
    nn = int(input())
    for i in range(nn):
        tt = input()
        print(letters_shop(ss, tt, n))


n=int(input())
name=input()
mydict={chr(i):[] for i in range(97,123)}
for i in range(n):
    mydict[name[i]].append(i+1)

k=int(input())
for i in range(k):
    z=list(input())
    mydict2=dict()
    for i in z:
        mydict2[i]=mydict2.get(i,0)+1
    maxi=-1
    for i in mydict2:
        maxi=max(maxi,mydict[i][mydict2[i]-1])
    print(maxi)


def letters_shop(s, name):
    c=0
    f = len(name)
    for a in s:
        if a in name:
            name=name.replace(a,'',1)
            if len(name)==0:
                break
        else:
            c+=1
    if c>0:
        return f+c
    else:
        return f
# --------------------------------------------------------------
if __name__ == '__main__':
    n = int(input())
    ss = input()
    nn = int(input())
    for i in range(nn):
        tt = input()
        print()
        print(letters_shop(ss, tt))


def letters_shop(dict_word, no_of_letters, friend):

    for i in range(no_of_letters):
        dict_name = dict()
        for i in friend:
            dict_name[i] = dict_name.get(i, 0) + 1
        maximum_i = -1
        for i in dict_name:
            maximum_i = max(maximum_i, dict_word[i][dict_name[i] - 1])
    return maximum_i

if __name__ == '__main__':
    b = 'abcdefghijklmnopqrstuvwxyz'
    length_of_word = int(input())
    word = input()
    word_dict = {i: [] for i in b}
    for i in range(length_of_word):
        word_dict[word[i]].append(i + 1)
    no_of_friends = int(input())
    for i in range(no_of_friends):
        friend_name = input()
        print(letters_shop(word_dict, length_of_word, friend_name))


def letters_shop(s, name):
    d=[]
    c=0
    for a in name:
        d.append(s.index(a)+1)
        s=s.replace(a,'@',1)
    return max(d)

# --------------------------------------------------------------
if __name__ == '__main__':
    n = int(input())
    ss = input()
    nn = int(input())
    for i in range(nn):
        tt = list(input())
        print(letters_shop(ss, tt))


def letters_shop(s, name):
    d=[]
    c=0
    for a in name:
        d.append(s.index(a)+1)
    d.append(len(name))
    return max(d)

# --------------------------------------------------------------
if __name__ == '__main__':
    n = int(input())
    ss = list(input())
    nn = int(input())
    for i in range(nn):
        tt = list(input())
        print(letters_shop(ss, tt))


n = int(input())
s = input()
m = int(input())
for i in range(m):
    used = [-1]*n
    t = input()
    maxIndex = 0
    for j in range(len(t)):
        for k in range(n):
            if(s[k]==t[j] and used[k]==-1):
                used[k] = 1
                maxIndex = max(maxIndex,k+1)
                break
    print(maxIndex)


n = int(input())
s = input()
m = int(input())

pos = dict()
for i in range(n):
    if(s[i] in pos):
        pos[s[i]].append(i+1)
    else:
        pos[s[i]] = [i+1]

for i in range(m):
    t = input()
    freq = dict()
    for j in range(len(t)):
        if(t[j] in freq):
            freq[t[j]] += 1
        else:
            freq[t[j]] = 1
    maxIndex = 0
    for key, value in freq.items():
        temp = pos[key][value-1]
        maxIndex = max(maxIndex,temp)
    print(maxIndex)


n = int(input())
s = input()
m = int(input())
for i in range(m):
    used = [-1]*n
    t = input()
    maxIndex = 0
    for j in range(len(t)):
        for k in range(n):
            if(s[k]==t[j] and used[k]==-1):
                used[i] = 1
                maxIndex = max(maxIndex,k+1)
                break


import collections
n = int(input())
s = input()
t = int(input())
for _ in range(t):
    nameMap = collections.defaultdict(int)
    name = input()
    for c in name:
        nameMap[c] += 1
    changed = 0
    for i,c in enumerate(s,1):
        if c in nameMap and nameMap[c] > 0:
            nameMap[c] -= 1
            changed += 1
            if changed == len(name):
                print(i)
                break


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int cnt = (n/2 + n%2)*(n/2 + n%2) + (n/2)*(n/2);
        System.out.println(cnt);
        String s0 = "";
        String s1 = "";
        for(int i = 0; i < n; i++){
            if(i%2 == 0) s0 += "C";
            else s1 += ".";
        }
        for(int i = 0; i < n; i++){
            if(i%2 == 0) System.out.println(s0);
            else System.out.println(s1);
        }
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if((i+j)%2==0){
                    System.out.print("C");
                }
                else{
                    System.out.print(".");
                }
            }
            System.out.print("\n");
        }
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int cnt = (n/2 + n%2)*(n/2 + n%2) + (n/2)*(n/2);
        System.out.println(cnt);
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if((i+j)%2==0){
                    System.out.print("C");
                }
                else{
                    System.out.print(".");
                }
            }
            System.out.print("\n");
        }
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int cnt = (n/2 + n%2)*(n/2 + n%2) + (n/2)*(n/2);
        System.out.println(cnt);
        String s0 = "";
        String s1 = "";
        for(int i = 0; i < n; i++){
            if(i%2 == 0){
                s0 += "C";
                s1 += ".";
            }
            else{
                s1 += "C";
                s0 += ".";
            }
        }
        for(int i = 0; i < n; i++){
            if(i%2 == 0) System.out.println(s0);
            else System.out.println(s1);
        }
    }
}


import java.io.BufferedOutputStream;
import java.io.PrintWriter;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) throws IOException {
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

		MyScanner fr = new MyScanner();
		TaskW solver = new TaskW();
		solver.solve(fr, out);
	}
}

class TaskW {
	public void solve(MyScanner fr, PrintWriter out) {

		int n = fr.nextInt();
		char[][] a = new char[n][n];
		char D = '.';
		char C = 'C';
		char cell = C;
		int count = 0;
		for (int i = 0; i < n; i++) {

			for (int j = 0; j < n; j++) {
				a[i][j] = cell;
				if (cell == D)
					cell = C;
				else {
					count++;
					cell = D;
				}
			}
			if (n % 2 == 0) {
				if (cell == D)
					cell = C;
				else
					cell = D;
			}
		}
		out.println(count);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				out.print(a[i][j]);
			}
			out.println();
		}

		out.close();
	}
}

class MyScanner {
	BufferedReader br;
	StringTokenizer st;

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

	public MyScanner(String file) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(file));
	}

	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;
	}

}


import java.io.BufferedOutputStream;
import java.io.PrintWriter;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) throws IOException {
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

		MyScanner fr = new MyScanner();
		TaskW solver = new TaskW();
		solver.solve(fr, out);
	}
}

class TaskW {
	public void solve(MyScanner fr, PrintWriter out) {

		int n = fr.nextInt();
		char[][] a = new char[n][n];
		char D = '.';
		char C = 'C';
		char cell = D;
		int count = 0;
		for (int i = 0; i < n; i++) {

			for (int j = 0; j < n; j++) {
				a[i][j] = cell;
				if (cell == D)
					cell = C;
				else {
					count++;
					cell = D;
				}
			}
			if (n % 2 == 0) {
				if (cell == D)
					cell = C;
				else
					cell = D;
			}
		}
		out.println(count);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				out.print(a[i][j]);
			}
			out.println();
		}

		out.close();
	}
}

class MyScanner{
	BufferedReader br;
	StringTokenizer st;

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

	public MyScanner(String file) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(file));
	}

	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;
	}

}


import java.io.BufferedOutputStream;
import java.io.PrintWriter;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) throws IOException {
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

		MyScanner fr = new MyScanner();
		TaskW solver = new TaskW();
		solver.solve(fr, out);
	}
}

class TaskW {
	public void solve(MyScanner fr, PrintWriter out) {

		int n = fr.nextInt();
		char[][] a = new char[n][n];
		char D = '.';
		char C = 'C';
		char cell = D;
		int count = 0;
		for (int i = 0; i < n; i++) {

			for (int j = 0; j < n; j++) {
				a[i][j] = cell;
				if (cell == D)
					cell = C;
				else {
					count++;
					cell = D;
				}
			}
			if (n % 2 == 0) {
				if (cell == D)
					cell = C;
				else
					cell = D;
			}
		}
		out.println(count);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				out.print(a[i][j]);
			}
			out.println();
		}

		out.close();
	}
}

public class MyScanner {
	BufferedReader br;
	StringTokenizer st;

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

	public MyScanner(String file) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(file));
	}

	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;
	}

}


import java.io.BufferedOutputStream;
import java.io.PrintWriter;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) throws IOException {
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

		MyScanner fr = new MyScanner();
		TaskW solver = new TaskW();
		solver.solve(fr, out);
	}
}

class TaskW {
	public void solve(MyScanner fr, PrintWriter out) {

		int n = fr.nextInt();
		char[][] a = new char[n][n];
		char D = '.';
		char C = 'C';
		char cell = D;
		int count = 0;
		for (int i = 0; i < n; i++) {

			for (int j = 0; j < n; j++) {
				a[i][j] = cell;
				if (cell == D)
					cell = C;
				else {
					count++;
					cell = D;
				}
			}
			if (n % 2 == 0) {
				if (cell == D)
					cell = C;
				else
					cell = D;
			}
		}
		out.println(count);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				out.print(a[i][j]);
			}
			out.println();
		}

		out.close();
	}
}

class MyScanner {
	BufferedReader br;
	StringTokenizer st;

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

	public MyScanner(String file) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(file));
	}

	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;
	}

}


import java.util.Scanner;

/**
 * Created by kit on 30/01/2017.
 */
public class Sol {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = 0;
        if(n % 2 == 0){
            c = n*n /2;
        }
        else{
            c= n*n - n*n/2;
        }
        System.out.println(c);
        boolean [][] arr = new boolean[n][n];
        arr[0][0] = true;
        for(int k = 0; k < n; k++){
            if(k % 2 == 0){
                arr[0][k] = true;
                System.out.print("C");
            }
            else{
                System.out.print(".");
            }
        }
        System.out.println();
        for(int i = 1; i < n; i++){
            for(int j = 0; j < n; j++){
               if(arr[i-1][j] == false) {
                   arr[i][j] = true;
                   System.out.print("C");
               }
               else{
                   System.out.print(".");
               }
            }
            System.out.println();
        }

    }
}


import java.util.Scanner;

/**
 * Created by kit on 30/01/2017.
 */
public class Sol {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = 0;
        int inc = 0;
        if(n % 2 != 0){
            c = n*n- n*n /2;
            System.out.println(c);
            for(int i = 0; i < n*n; i++){
                if(i % 2 == 0){
                    System.out.print("C");
                }
               else {
                    System.out.print(".");
                }
                if((i+1) % n == 0){
                    System.out.println();
                }
            }
        }
        else {
            c = n * n - n * n / 2;
            System.out.println(c);
            boolean[][] arr = new boolean[n][n];
            arr[0][0] = true;
            for (int k = 0; k < n; k++) {
                if (k % 2 == 0) {
                    arr[0][k] = true;
                    System.out.print("C");
                } else {
                    System.out.print(".");
                }
            }
            System.out.println();
            for (int i = 1; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (arr[i - 1][j] == false) {
                        arr[i][j] = true;
                        System.out.print("C");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
        }
    }
}


import java.util.Scanner;

/**
 * Created by kit on 30/01/2017.
 */
public class Sol {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = 0;
        String s = "";
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                s += "C";
            } else {
                s += ".";
            }
        }
        c = n * n - n * n / 2;
        System.out.println(c);
        String s1 = s.substring(0, n);
        String s2 = s.substring(1, n);
        if (n % 2 == 0) {
            for (int o = 0; o < n; o++) {
                if (o % 2 == 0) {
                    System.out.println(s1);
                } else {
                    System.out.println(s2 + "C");
                }
            }
        } else {
            for (int o = 0; o < n; o++) {
                if (o % 2 == 0) {
                    System.out.println(s1);
                } else {
                    System.out.println(s2 + ".");
                }
            }
        }
    }
}


import java.util.Scanner;

/**
 * Created by kit on 30/01/2017.
 */
public class Sol {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = 0;
        int inc = 0;
        if(n % 2 != 0){
            c = n*n- n*n /2;
            System.out.println(c);
            String s = "";
            for(int i = 0; i < n; i++){
                if(i % 2 == 0) {
                    s += "C";
                }
                else{
                    s += ".";
                }
            }
            String s1 = s.substring(0, n);
            String s2 = s.substring(1, n);
            for(int o = 0 ; o < n; o++){
                if(o % 2 == 0){
                    System.out.println(s1);
                }
                else{
                    System.out.println(s2+ ".");
                }
            }
        }
        else {
            int h = 2;
            c = n * n - n * n / 2;
            System.out.println(c);
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if(j == 0 && i % 2 != 0){
                        System.out.print(".");
                    }
                    else if (j % h == 0) {
                        if(h == 1){
                            if(j % 2 != 0){
                                System.out.print("C");
                            }
                            else {
                                System.out.print(".");
                            }
                        }
                        else {
                            System.out.print("C");
                        }
                    }
                    else {
                        System.out.print(".");
                    }
                    if(j+1 == n){
                        if(h == 2){
                            h = 1;
                        }
                        else{
                            h = 2;
                        }
                        System.out.println();
                    }
                }
            }
        }
    }
}


import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Created by Timur on 06.11.2016.
 */
public class _384A {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        PrintWriter out = new PrintWriter(System.out);
        out.println( (n*n+1)/2);

        for(int i=0;i<n;i++) {
            int b = i%2==0 ? 1 : 0;
            for(int j=0;j<n;j++)
                if(b==1){
                    out.print("C");
                    b = 0;
                }else if(b==0){
                    out.print(".");
                    b = 1;
                }
            out.println();
        }
        out.close();
    }
}


import java.util.Scanner;

/**
 * Created by Timur on 06.11.2016.
 */
public class _384A {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println(n*n%2==0 ? n*n/2 : n*n/2+1);
        for(int i=0;i<n;i++){
            boolean b = i%2==0 ? true : false;
            for(int j=0;j<n;j++)
                if(b){
                    System.out.print("C");
                    b = false;
                }else if(!b){
                    System.out.print(".");
                    b = true;
                }
            System.out.println();
        }
    }
}


import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Created by Timur on 06.11.2016.
 */
public class _384A_TVH {
    public static void main(String[] args)throws Exception {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        PrintWriter out = new PrintWriter(System.out);
        System.out.println(((n * n) + 1) / 2);
        int parity = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                out.print(parity == 1 ? "C" : ".");
                parity ^= 1;
            }
            parity ^= n % 2 == 0 ? 1 : 0;
            out.println();
        }
        out.close();
    }
}


import java.util.Scanner;

/**
 * Created by Timur on 06.11.2016.
 */
public class _384A {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println( (n*n+1)/2);

        for(int i=0;i<n;i++) {
            int b = i%2==0 ? 1 : 0;
            for(int j=0;j<n;j++)
                if(b==1){
                    System.out.print("C");
                    b = 0;
                }else if(b==0){
                    System.out.print(".");
                    b = 1;
                }
            System.out.println();
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
   public static void main(String[] args) throws IOException {
      BufferedReader var = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(var.readLine());
      StringBuilder str = new StringBuilder("");
      int cnt = 0;
      for (int i = 0; i < n; i++) {
         for (int j = 0; j < n; j++) {
            if (((i == 0 || i % 2 == 0) && (j == 0 || j % 2 == 0)) || ((i > 0 && i % 2 != 0) && (j > 0 && j % 2 != 0))) {
               str.append("C");
               cnt++;
            } else
               str.append(".");
         }
         str.append("\n");
      }
      System.out.println(cnt);
      System.out.println(str);
   }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
   public static void main(String[] args) throws IOException {
      BufferedReader var = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(var.readLine());
      for (int i = 0; i < n; i++) {
         for (int j = 0; j < n; j++) {
            if (i == j)
               System.out.print("C");
            else
               System.out.print(".");
         }
         System.out.println("");
      }
   }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
   public static void main(String[] args) throws IOException {
      BufferedReader var = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(var.readLine());
      StringBuilder str = new StringBuilder("");
      int cnt = 0;
      System.out.println(n);
      for (int i = 0; i < n; i++) {
         for (int j = 0; j < n; j++) {
            if (((i == 0 || i % 2 == 0) && (j == 0 || j % 2 == 0)) || ((i > 0 && i % 2 != 0) && (j > 0 && j % 2 != 0))) {
               str.append("C");
               cnt++;
            } else
               str.append(".");
         }
         str.append("\n");
      }
      System.out.println(cnt);
      System.out.println(str);
   }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
   public static void main(String[] args) throws IOException {
      BufferedReader var = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(var.readLine());
      System.out.println(n);
      for (int i = 0; i < n; i++) {
         for (int j = 0; j < n; j++) {
            if (i == j)
               System.out.print("C");
            else
               System.out.print(".");
         }
         System.out.println("");
      }
   }
}


import java.util.Scanner;

public class Mahon {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if(n%2 != 0) System.out.println(((n*n)/2)+1);
		else System.out.println((n*n)/2);
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				if(i%2 == 0){
					if(j%2 == 0) System.out.print("C");
					else System.out.print(".");
				}
				else{
					if(j%2 != 0) System.out.print("C");
					else System.out.print(".");
				}
			}
			System.out.println();
		}
	}
}


import java.util.Scanner;

public class Mahón {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if(n%2 != 0) System.out.println(((n*n)/2)+1);
		else System.out.println((n*n)/2);
		char[][] a = new char[n][n];
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				if(i%2 == 0){
					if(j%2 == 0) a[i][j] = 'C';
					else a[i][j] = '.';
				}
				else{
					if(j%2 != 0)  a[i][j] = 'C';
					else a[i][j] = '.';
				}
			}
		}
		for(int i = 0 ; i < n ; i++){
		System.out.println(a[i]);
		}
	}
}


import java.util.Scanner;

public class Mahón {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if(n%2 != 0) System.out.println(((n*n)/2)+1);
		else System.out.println((n*n)/2);
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				if(i%2 == 0){
					if(j%2 == 0) System.out.print("C");
					else System.out.print(".");
				}
				else{
					if(j%2 != 0) System.out.print("C");
					else System.out.print(".");
				}
			}
			System.out.println();
		}
	}
}


import java.util.Scanner;

public class Mahon {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if(n%2 != 0) System.out.println(((n*n)/2)+1);
		else System.out.println((n*n)/2);
		char[][] a = new char[n][n];
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				if(i%2 == 0){
					if(j%2 == 0) a[i][j] = 'C';
					else a[i][j] = '.';
				}
				else{
					if(j%2 != 0)  a[i][j] = 'C';
					else a[i][j] = '.';
				}
			}
		}
		for(int i = 0 ; i < n ; i++){
		System.out.println(a[i]);
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tanzim Ibn Patowary
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            for (int test = 0; test < testNumber; test++) {
                int n = in.nextInt();
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        if (j == 0) {
                            out.print('C');
                        } else {
                            out.print('.');
                        }
                    }
                    out.println();
                }
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tanzim Ibn Patowary
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            for (int test = 0; test < testNumber; test++) {
                int n = in.nextInt();
                int count, tot = n * n;
                if (tot % 2 != 0) {
                    count = tot / 2 + 1;
                } else {
                    count = tot / 2;
                }
                String str1 = "", str2 = "";
                for (int i = 1; i <= n; i++) {
                    if (i % 2 != 0) {
                        str1 += "" + 'C';
                        str2 += "" + '.';
                    } else {
                        str1 += "" + '.';
                        str2 += "" + 'C';
                    }
                }
                out.println(count);
                for (int i = 1; i <= n; i++) {
                    if (i % 2 != 0) {
                        out.println(str1);
                    } else {
                        out.println(str2);
                    }
                }
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tanzim Ibn Patowary
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            for (int test = 0; test < testNumber; test++) {
                int n = in.nextInt();
                int count, tot = n * n;
                if (tot % 2 != 0) {
                    count = tot / 2 + 1;
                } else {
                    count = tot / 2;
                }
                String str1 = "", str2 = "";
                for (int i = 1; i <= n; i++) {
                    if (i % 2 != 0) {
                        str1 += "" + 'C';
                        str2 += "" + '.';
                    } else {
                        str1 += "" + '.';
                        str2 += "" + 'C';
                    }
                }


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tanzim Ibn Patowary
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            for (int test = 0; test < testNumber; test++) {
                int n = in.nextInt();
                out.println(n);
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        if (j == 0) {
                            out.print('C');
                        } else {
                            out.print('.');
                        }
                    }
                    out.println();
                }
            }
        }

    }
}


import java.util.Scanner;

public class main{

    public static void main(String[] args) {

        Scanner  s = new Scanner(System.in);

        int n = s.nextInt();

        String arr[][]=new String[n][n];

        for(int i=0;i<arr.length;i++)
        {
            for (int j = 0; j < arr[i].length; j++) {
                if(i%2!=0)
                    if(j%2==0)
                        arr[i][j]=".";
                else
                        arr[i][j]="C";
                else
                      if(j%2==0)
                        arr[i][j]="C";
                else
                        arr[i][j]=".";
            }
        }

        for(int i=0;i<arr.length;i++)
        {
            for (int j = 0; j < arr[i].length; j++)
                System.out.print(arr[i][j]);

            System.out.println("");
        }

  }

}


import java.util.Scanner;

public class main{

    public static void main(String[] args) {

        Scanner  s = new Scanner(System.in);

        int n = s.nextInt();

        String arr[][]=new String[n][n];

        for(int i=0;i<arr.length;i++)
        {
            for (int j = 0; j < arr[i].length; j++) {
                if(i%2!=0)
                    if(j%2==0)
                        arr[i][j]=".";
                else
                        arr[i][j]="C";
                else
                      if(j%2==0)
                        arr[i][j]="C";
                else
                        arr[i][j]=".";
            }
        }

        System.out.println((n*n)/2);
        for(int i=0;i<arr.length;i++)
        {
            for (int j = 0; j < arr[i].length; j++)
                System.out.print(arr[i][j]);

            System.out.println("");
        }

  }

}


import java.util.Scanner;

 public class main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int n = s.nextInt();
        double t = Math.ceil(n / 2.0);
        int x = (int) t;
        System.out.println((x * x) + ((n / 2) * (n / 2)));
        String sol[] = new String[n];
        for (int i = 0; i < n; i++) {
            sol[i]="";
            for (int j = 0; j < n; j++) {
                if ((i + j) % 2 == 0) {
                    sol[i] += 'C';
                } else {
                    sol[i] += '.';
                }
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.println(sol[i]);
        }
    }

}


import java.util.Scanner;

public class main{

    public static void main(String[] args) {

        Scanner  s = new Scanner(System.in);

        int n = s.nextInt();

        String arr[][]=new String[n][n];

        for(int i=0;i<arr.length;i++)
        {
            for (int j = 0; j < arr[i].length; j++) {
                if(i%2!=0)
                    if(j%2==0)
                        arr[i][j]=".";
                else
                        arr[i][j]="C";
                else
                      if(j%2==0)
                        arr[i][j]="C";
                else
                        arr[i][j]=".";
            }
        }

        if(n%2==0)
        System.out.println((n*n)/2);
        else
            System.out.println((int)Math.ceil((n*n)/2.0));
        for(int i=0;i<arr.length;i++)
        {
            for (int j = 0; j < arr[i].length; j++)
                System.out.print(arr[i][j]);

            System.out.println("");
        }

  }

}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author anhnth37
 */
public class A_0384 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        System.out.println((n / 2) * (n / 2) + (n - n / 2) * (n - n / 2));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i % 2 == 0) {
                    if (j % 2 == 1) {
                        System.out.print("C");
                    } else {
                        System.out.print(".");
                    }
                } else {
                    if (j % 2 == 0) {
                        System.out.print("C");
                    } else {
                        System.out.print(".");
                    }
                }
            }
            System.out.println("");
        }
    }
}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author anhnth37
 */
public class A_0384 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        char[][] a = new char[n][n];
        int c = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 && j == 0) {
                    System.out.print('C');
                } else if (i == 0 && j != 0) {
                    if ((j != n - 1 ? a[0][j + 1] == 'C' : false) || a[0][j - 1] == 'C' || (j != n - 1 ? a[1][j] == 'C' : false)) {
                        System.out.print('.');
                    } else {
                        System.out.print('C');
                        c++;
                    }
                } else if (i != 0 && j == 0) {
                    if ((i != n - 1 ? a[i + 1][0] == 'C' : false) || a[i - 1][0] == 'C' || (i != n - 1 ? a[i][1] == 'C' : false)) {
                        System.out.print('.');
                    } else {
                        System.out.print('C');
                        c++;
                    }
                } else {
                    if ((i != n - 1 ? a[i + 1][j] == 'C' : false) || a[i - 1][j] == 'C' || (j != n - 1 ? a[i][j + 1] == 'C' : false) || a[i][j - 1] == 'C') {
                        System.out.print('.');
                    } else {
                        System.out.print('C');
                        c++;
                    }
                }
            }
        }

        System.out.println(c);
    }
}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author anhnth37
 */
public class A_0384 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int t1 = n;
        int t2 = n;
        System.out.println((n / 2) * (n / 2) + (n - n / 2) * (n - n / 2));
        String s1 = "";
        String s2 = "";
        while (t1-- > 0) {
            s1 += t1 % 2 == 0 ? "C" : ".";
        }
        while (t2-- > 0) {
            s2 += t2 % 2 == 0 ? "." : "C";
        }
        while (n-- > 0) {
            System.out.println(n % 2 == 0 ? s1 : s2);
        }
    }
}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author anhnth37
 */
public class A_0384 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        char[][] a = new char[n][n];
        int c = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 && j == 0) {
                    a[0][0] = 'C';
                } else if (i == 0 && j != 0) {
                    if ((j != n - 1 ? a[0][j + 1] == 'C' : false) || a[0][j - 1] == 'C' || (j != n - 1 ? a[1][j] == 'C' : false)) {
                        a[0][j] = '.';
                    } else {
                        a[0][j] = 'C';
                        c++;
                    }
                } else if (i != 0 && j == 0) {
                    if ((i != n - 1 ? a[i + 1][0] == 'C' : false) || a[i - 1][0] == 'C' || (i != n - 1 ? a[i][1] == 'C' : false)) {
                        a[i][0] = '.';
                    } else {
                        a[i][0] = 'C';
                        c++;
                    }
                } else {
                    if ((i != n - 1 ? a[i + 1][j] == 'C' : false) || a[i - 1][j] == 'C' || (j != n - 1 ? a[i][j + 1] == 'C' : false) || a[i][j - 1] == 'C') {
                        a[i][j] = '.';
                    } else {
                        a[i][j] = 'C';
                        c++;
                    }
                }
                System.out.print(a[i][j]);
            }
            System.out.println("");
        }

        System.out.println(n);
    }
}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author anhnth37
 */
public class A_0384 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        System.out.println((n / 2) * (n / 2) + (n - n / 2) * (n - n / 2));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i % 2 == 0) {
                    if (j % 2 == 1) {
                        System.out.print(".");
                    } else {
                        System.out.print("C");
                    }
                } else {
                    if (j % 2 == 0) {
                        System.out.print(".");
                    } else {
                        System.out.print("C");
                    }
                }
            }
            System.out.println("");
        }
    }
}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author anhnth37
 */
public class A_0384 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        char[][] a = new char[n][n];
        int c = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 && j == 0) {
                    a[0][0] = 'C';
                } else if (i == 0 && j != 0) {
                    if ((j != n - 1 ? a[0][j + 1] == 'C' : false) || a[0][j - 1] == 'C' || (j != n - 1 ? a[1][j] == 'C' : false)) {
                        a[0][j] = '.';
                    } else {
                        a[0][j] = 'C';
                        c++;
                    }
                } else if (i != 0 && j == 0) {
                    if ((i != n - 1 ? a[i + 1][0] == 'C' : false) || a[i - 1][0] == 'C' || (i != n - 1 ? a[i][1] == 'C' : false)) {
                        a[i][0] = '.';
                    } else {
                        a[i][0] = 'C';
                        c++;
                    }
                } else {
                    if ((i != n - 1 ? a[i + 1][j] == 'C' : false) || a[i - 1][j] == 'C' || (j != n - 1 ? a[i][j + 1] == 'C' : false) || a[i][j - 1] == 'C') {
                        a[i][j] = '.';
                    } else {
                        a[i][j] = 'C';
                        c++;
                    }
                }
            }
        }

        System.out.println(c);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(a[i][j]);
            }
            System.out.println("");
        }
    }
}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author anhnth37
 */
public class A_0384 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        char[][] a = new char[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 && j == 0) {
                    a[0][0] = 'C';
                } else if (i == 0 && j != 0) {
                    if ((j != n - 1 ? a[0][j + 1] == 'C' : false) || a[0][j - 1] == 'C' || (j != n - 1 ? a[1][j] == 'C' : false)) {
                        a[0][j] = '.';
                    } else {
                        a[0][j] = 'C';
                    }
                } else if (i != 0 && j == 0) {
                    if ((i != n - 1 ? a[i + 1][0] == 'C' : false) || a[i - 1][0] == 'C' || (i != n - 1 ? a[i][1] == 'C' : false)) {
                        a[i][0] = '.';
                    } else {
                        a[i][0] = 'C';
                    }
                } else {
                    if ((i != n - 1 ? a[i + 1][j] == 'C' : false) || a[i - 1][j] == 'C' || (j != n - 1 ? a[i][j + 1] == 'C' : false) || a[i][j - 1] == 'C') {
                        a[i][j] = '.';
                    } else {
                        a[i][j] = 'C';
                    }
                }
            }
        }

        System.out.println(n);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(a[i][j]);
            }
            System.out.println("");
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		in.close();
		if(n%2 == 1){
			System.out.println((n/2 + 1)*(n/2 + 1) + n/2*(n/2));
		}
		else{
			System.out.println((n/2)*n);
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if((i + j)%2 == 0){
					System.out.print("C");
				}
				else
					System.out.print(".");
			}
			System.out.println();
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		int mode = 0;
		if(n%2 == 1){
			System.out.println((n/2 + 1)*(n/2 + 1) + n/2*(n/2));
		}
		else{
			System.out.println((n/2)*n);
		}
		for(int i = 0; i < n; i++){
			if(mode == 0){
				for(int j = 0; j < n/2; j++){
					System.out.print("C.");
				}
				if(n%2 == 1)
					System.out.print("C");
				System.out.println();
				mode = 1;
			}
			else if(mode == 1){
				for(int j = 0; j < n/2; j++){
					System.out.print(".C");
				}
				if(n%2 == 1)
					System.out.print(".");
				System.out.println();
				mode = 0;
			}
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		int mode = 0;
		if(n%2 == 1){
			System.out.println(2*(n/2 + 1) + n/2);
		}
		else{
			System.out.println((n/2)*n);
		}
		for(int i = 0; i < n; i++){
			if(mode == 0){
				for(int j = 0; j < n/2; j++){
					System.out.print("C.");
				}
				if(n%2 == 1)
					System.out.print("C");
				System.out.println();
				mode = 1;
			}
			else if(mode == 1){
				for(int j = 0; j < n/2; j++){
					System.out.print(".C");
				}
				if(n%2 == 1)
					System.out.print(".");
				System.out.println();
				mode = 0;
			}
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		boolean[][] store = new boolean[n][n];
		boolean[][] store2 = new boolean[n][n];
		int count = 0;

		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(store[i][j] == false){
					count++;
					store2[i][j] = true;
					if(i < n -1)
						store[i + 1][j] = true;
					if(j < n - 1)
						store[i][j + 1] = true;
				}
			}
		}
		System.out.println(count);
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(store2[i][j])
					System.out.print("C");
				else
					System.out.print(".");
			}
			System.out.println();
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		in.close();
		int mode = 0;
		if(n%2 == 1){
			System.out.println((n/2 + 1)*(n/2 + 1) + n/2*(n/2));
		}
		else{
			System.out.println((n/2)*n);
		}
		for(int i = 0; i < n; i++){
			if(mode == 0){
				for(int j = 0; j < n/2; j++){
					System.out.print("C.");
				}
				if(n%2 == 1)
					System.out.print("C");
				System.out.println();
				mode = 1;
			}
			else if(mode == 1){
				for(int j = 0; j < n/2; j++){
					System.out.print(".C");
				}
				if(n%2 == 1)
					System.out.print(".");
				System.out.println();
				mode = 0;
			}
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		in.close();
		if(n%2 == 1){
			System.out.println((n/2 + 1)*(n/2 + 1) + n/2*(n/2));
		}
		else{
			System.out.println((n/2)*n);
		}
		for(int i = 0; i < n; i++){
			String ans = "";
			int l = n;
			if(n%2 == 1){
				l--;
			}
			for(int j = 0; j < l; j+= 2){
				if((i + j)%2 == 0){
					ans += "C.";
				}
				else
					ans += ".C";
			}
			if(n%2 == 1){
				if(i%2 == 0)
					ans += "C";
				else
					ans+= ".";
			}
			System.out.println(ans);
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		in.close();
		int mode = 0;
		if(n%2 == 1){
			System.out.println((n/2 + 1)*(n/2 + 1) + n/2*(n/2));
		}
		else{
			System.out.println((n/2)*n);
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if((i + j)%2 == 0){
					System.out.print("C");
				}
				else
					System.out.print(".");
			}
			System.out.println();
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		int mode = 0;
		for(int i = 0; i < n; i++){
			if(mode == 0){
				for(int j = 0; j < n/2; j++){
					System.out.print("C.");
				}
				if(n%2 == 1)
					System.out.print("C");
				System.out.println();
				mode = 1;
			}
			else if(mode == 1){
				for(int j = 0; j < n/2; j++){
					System.out.print(".C");
				}
				if(n%2 == 1)
					System.out.print(".");
				System.out.println();
				mode = 0;
			}
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		int[][] store = new int[n][n];
		int count = 0;

		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(store[i][j] == 0){
					count++;
					store[i][j] = 2;
					if(i < n -1)
						store[i + 1][j] = 1;
					if(j < n - 1)
						store[i][j + 1] = 1;
				}
			}
		}
		System.out.println(count);
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(store[i][j] == 2)
					System.out.print("C");
				else
					System.out.print(".");
			}
			System.out.println();
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		in.close();
		if(n%2 == 1){
			System.out.println((n/2 + 1)*(n/2 + 1) + n/2*(n/2));
		}
		else{
			System.out.println((n/2)*n);
		}
		for(int i = 0; i < n; i++){
			String ans = "";
			for(int j = 0; j < n; j++){
				if((i + j)%2 == 0){
					ans += "C";
				}
				else
					ans += ".";
			}
			System.out.println(ans);
		}
	}

}


import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * coder
 */
public class CodeForS {
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        String nechet = "C.";
        String chet = ".C";

        if(n % 2 == 0){
            System.out.println(n*n/2);
            for(int i = 1; i <= n; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                }
                else {
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                }
                System.out.println();
            }
        }
        else {
            System.out.println(n * n / 2 + 1);
            for(int i = 1; i <= n; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                    System.out.print("C");
                }
                else {
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                    System.out.print(".");
                }
                System.out.println();
            }

        }
    }

}


import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * coder time limitasdas
 */
public class CodeForS {
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);

        int times = 0;
        int org = 0;
        int n = input.nextInt();
        String big_chet = "";
        String big_nechet = "";
        if(n > 400){
            for(int i = 0; i < 50; i++){
                big_chet += ".C";
                big_nechet += "C.";
            }
            times = n / 100;
            org = n;
            if(n % 2 == 0)
                System.out.println(n*n/2);
            else
                System.out.println(n*n/2 + 1);
            n = n % 100;
            method(n,times,big_chet,big_nechet,org);
        }
        else
            method(n);

    }
    public static void method(int n){
        String nechet = "C.";
        String chet = ".C";
        if(n % 2 == 0){
            System.out.println(n*n/2);
            for(int i = 1; i <= n; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                }
                else {
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                }
                System.out.println();
            }
        }
        else {
            System.out.println(n * n / 2 + 1);
            for(int i = 1; i <= n; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                    System.out.print("C");
                }
                else {
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                    System.out.print(".");
                }
                System.out.println();
            }

        }
    }
    public static void method(int n ,int times,String bchet, String bnechet,int org ){
        String nechet = "C.";
        String chet = ".C";
        System.out.println(bchet.length());
        if(n % 2 == 0){
            for(int i = 1; i <= org; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < times; c++){
                        System.out.print(bnechet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                }
                else {
                    for(int c =0; c < times; c++){
                        System.out.print(bchet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                }
                System.out.println();
            }

        }
        else {

            for(int i = 1; i <= org; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < times; c++){
                        System.out.print(bnechet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                    System.out.print("C");
                }
                else {
                    for(int c = 0; c < times; c++){
                        System.out.print(bchet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                    System.out.print(".");
                }
                System.out.println();
            }

        }
    }

}


import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * coder time limit
 */
public class CodeForS {
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);

        int times = 0;
        int org = 0;
        int n = input.nextInt();
        String big_chet = "";
        String big_nechet = "";
        if(n > 400){
            for(int i = 0; i < 50; i++){
                big_chet += ".C";
                big_nechet += "C.";
            }
            times = n / 100;
            org = n;
            if(n % 2 == 0)
                System.out.println(n*n/2);
            else
                System.out.println(n*n/2 + 1);
            n = n % 100;
            method(n,times,big_chet,big_nechet,org);
        }
        else
            method(n);

    }
    public static void method(int n){
        String nechet = "C.";
        String chet = ".C";
        if(n % 2 == 0){
            System.out.println(n*n/2);
            for(int i = 1; i <= n; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                }
                else {
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                }
                System.out.println();
            }
        }
        else {
            System.out.println(n * n / 2 + 1);
            for(int i = 1; i <= n; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                    System.out.print("C");
                }
                else {
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                    System.out.print(".");
                }
                System.out.println();
            }

        }
    }
    public static void method(int n ,int times,String bchet, String bnechet,int org ){
        String nechet = "C.";
        String chet = ".C";
        System.out.println(bchet.length());
        if(n % 2 == 0){
            for(int i = 1; i <= org; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < times; c++){
                        System.out.print(bnechet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                }
                else {
                    for(int c =0; c < times; c++){
                        System.out.print(bchet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                }
                System.out.println();
            }

        }
        else {

            for(int i = 1; i <= org; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < times; c++){
                        System.out.print(bnechet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                    System.out.print("C");
                }
                else {
                    for(int c = 0; c < times; c++){
                        System.out.print(bchet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                    System.out.print(".");
                }
                System.out.println();
            }

        }
    }

}


import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * coder time limit
 */
public class CodeForS {
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);

        int times = 0;
        int org = 0;
        int n = input.nextInt();
        String big_chet = "";
        String big_nechet = "";
        if(n > 400){
            for(int i = 0; i < 50; i++){
                big_chet += ".C";
                big_nechet += "C.";
            }
            times = n / 100;
            org = n;
            if(n % 2 == 0)
                System.out.println(n*n/2);
            else
                System.out.println(n*n/2 + 1);
            n = n % 100;
            method(n,times,big_chet,big_nechet,org);
        }
        else
            method(n);

    }
    public static void method(int n){
        String nechet = "C.";
        String chet = ".C";
        if(n % 2 == 0){
            System.out.println(n*n/2);
            for(int i = 1; i <= n; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                }
                else {
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                }
                System.out.println();
            }
        }
        else {
            System.out.println(n * n / 2 + 1);
            for(int i = 1; i <= n; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                    System.out.print("C");
                }
                else {
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                    System.out.print(".");
                }
                System.out.println();
            }

        }
    }
    public static void method(int n ,int times,String bchet, String bnechet,int org ){
        String nechet = "C.";
        String chet = ".C";

        if(n % 2 == 0){
            for(int i = 1; i <= org; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < times; c++){
                        System.out.print(bnechet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                }
                else {
                    for(int c =0; c < times; c++){
                        System.out.print(bchet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                }
                System.out.println();
            }

        }
        else {

            for(int i = 1; i <= org; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < times; c++){
                        System.out.print(bnechet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                    System.out.print("C");
                }
                else {
                    for(int c = 0; c < times; c++){
                        System.out.print(bchet);
                    }
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                    System.out.print(".");
                }
                System.out.println();
            }

        }
    }

}


import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * coder time limit
 */
public class CodeForS {
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);

        int times = 0;
        int org = 0;
        int n = input.nextInt();
        String big_chet = "";
        String big_nechet = "";
        if(n > 400){
            for(int i = 0; i < 50; i++){
                big_chet += ".C";
                big_nechet += "C.";
            }
            times = n / 100;
            org = n;
            if(n % 2 == 0)
                System.out.println(n*n/2);
            else
                System.out.println(n*n/2 + 1);
            n = n % 100;
            method(n,times,big_chet,big_nechet,org);
        }
        else
            method(n);

    }
    public static void method(int n){
        String nechet = "C.";
        String chet = ".C";
        if(n % 2 == 0){
            System.out.println(n*n/2);
            for(int i = 1; i <= n; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                }
                else {
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                }
                System.out.println();
            }
        }
        else {
            System.out.println(n * n / 2 + 1);
            for(int i = 1; i <= n; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < n/2; c++){
                        System.out.print(nechet);
                    }
                    System.out.print("C");
                }
                else {
                    for(int c = 0; c < n/2; c++){
                        System.out.print(chet);
                    }
                    System.out.print(".");
                }
                System.out.println();
            }

        }
    }
    public static void method(int n ,int times,String bchet, String bnechet,int org ){
        String nechet = "C.";
        String chet = ".C";
        if(n % 2 == 0){
            for(int i = 1; i <= org; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < times; c++){
                        System.out.print(bnechet);
                    }
                    for(int c = 0; c < org/2; c++){
                        System.out.print(nechet);
                    }
                }
                else {
                    for(int c =0; c < times; c++){
                        System.out.print(bchet);
                    }
                    for(int c = 0; c < org/2; c++){
                        System.out.print(chet);
                    }
                }
                System.out.println();
            }
        }
        else {

            for(int i = 1; i <= org; i++){
                if(i % 2 != 0){
                    for(int c = 0; c < times; c++){
                        System.out.print(bnechet);
                    }
                    for(int c = 0; c < org/2; c++){
                        System.out.print(nechet);
                    }
                    System.out.print("C");
                }
                else {
                    for(int c = 0; c < times; c++){
                        System.out.print(bchet);
                    }
                    for(int c = 0; c < org/2; c++){
                        System.out.print(chet);
                    }
                    System.out.print(".");
                }
                System.out.println();
            }

        }
    }

}


import java.util.Scanner;

public class Coder {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        String m1 = "";
        int n = cin.nextInt();
        if (n % 2 == 0) {
            System.out.println(n * n / 2);
        } else {
            System.out.println((n * n / 2) + 1);
        }
        for (int i = 0; i < n; i++) {
            m1 = "";
            for (int e = 0; e < n; e++) {
                if ((i + e) % 2 == 0) {
                    m1 += "C";
                } else {
                    m1 += ".";
                }
            }
            System.out.println(m1);
        }
    }
}


import java.util.Scanner;

public class Coder {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        String m1 = "C.";
        String m2 = ".C";
        int n = cin.nextInt();
        if (n % 2 == 0) {
            System.out.println(n * n / 2);
            for (int i = 0; i < n; i++) {
                for (int e = 0; e < n; e += 2) {
                    if (i % 2 == 0) {
                        System.out.print(m1);
                    } else {
                        System.out.print(m2);
                    }
                }
                System.out.println();
            }
        } else {
            System.out.println((n * n / 2) + 1);
            for (int i = 0; i < n; i++) {
                for (int e = 1; e < n; e += 2) {
                    if (i % 2 == 0) {
                        System.out.print(m1);
                    } else {
                        System.out.print(m2);
                    }
                }
                if (i % 2 == 0) {
                    System.out.println("C");
                } else {
                    System.out.println(".");
                }
            }
        }
    }

}


import java.util.Scanner;

public class Coder {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		String m1="C .";
		String m2=". C";
		int n = cin.nextInt();
		if (n % 2 == 0) {
			System.out.println(n * n / 2);
		} else {
			System.out.println((n * n / 2) + 1);
		}
		for (int i = 0; i < n; i++) {
			for (int e = 1; e < n; e+=2) {
				if (i% 2 == 0) {
					System.out.print(m1 + " ");
				} else {
					System.out.print(m2 + " ");
				}
			}
			if (i% 2 == 0) {
				System.out.println("C");
			} else {
				System.out.println(".");
			}
		}
	}

}


import java.util.Scanner;

public class Coder {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        if (n % 2 == 0) {
            System.out.println(n * n / 2);
        } else {
            System.out.println((n * n / 2) + 1);
        }
        for (int i = 0; i < n; i++) {
            for (int e = 0; e < n; e++) {
                if ((i + e) % 2 == 0) {
                    System.out.print("C");
                } else {
                    System.out.print(".");
                }
            }
            System.out.println();
        }
    }

}


import java.util.Scanner;

public class Coder {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        if (n % 2 == 0) {
            System.out.println(n * n / 2);
        } else {
            System.out.println((n * n / 2) + 1);
        }
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                for (int e = 0; e < n; e++) {
                    if (e % 2 == 0) {
                        System.out.print("C");
                    } else {
                        System.out.print(".");
                    }
                }
            } else {
                for (int e = 0; e < n; e++) {
                    if (e % 2 == 0) {
                        System.out.print(".");
                    } else {
                        System.out.print("C");
                    }
                }
            }
            System.out.println();
        }
    }

}


import java.util.Scanner;

public class Coder {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        String m1="C .";
        String m2=". C";
        int n = cin.nextInt();
        if (n % 2 == 0) {
            System.out.println(n * n / 2);
        } else {
            System.out.println((n * n / 2) + 1);
        }
        for (int i = 0; i < n; i++) {
            for (int e = 0; e < n; e+=2) {
                if (i% 2 == 0) {
                    System.out.print(m1 + " ");
                } else {
                    System.out.print(m2 + " ");
                }
            }
            System.out.println();
        }
    }

}


import java.util.Scanner;

public class Coder {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        String m1 = "C.";
        String m2 = ".C";
        int n = cin.nextInt();
        if (n % 2 == 0) {
            System.out.println(n * n / 2);
        } else {
            System.out.println((n * n / 2) + 1);
        }
        for (int i = 0; i < n; i++) {
            for (int e = 0; e < n; e++) {
                if ((i + e) % 2 == 0) {
                    System.out.print("C");
                } else {
                    System.out.print(".");
                }
            }
            System.out.println();
        }
    }
}


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

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(n);

        for (int i = 0; i < n; i++) {
            if(i%2==0) {
                for (int j = 0; j < n; j++) {
                    if (j % 2 == 0) {
                        System.out.print('C');
                    } else {
                        System.out.print('.');
                    }
                }
            }else {
                for (int j = 0; j < n; j++) {
                    if (j % 2 == 1) {
                        System.out.print('C');
                    } else {
                        System.out.print('.');
                    }
                }
            }
            System.out.println();
        }
    }
}


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

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[][]a = new char[n][n];
int count = 0;

        for (int i = 0; i < n; i++) {
            if(i%2==0) {
                for (int j = 0; j < n; j++) {
                    if (j % 2 == 0) {
                        a[i][j] = 'C';
                        count++;
                    } else {
                       a[i][j] = '.';
                    }
                }
            }else {
                for (int j = 0; j < n; j++) {
                    if (j % 2 == 1) {
                        count++;
                        a[i][j] = 'C';
                    } else {
                        a[i][j] = '.';
                    }
                }
            }
        }
        System.out.println(count);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(a[i][j]);
            }
            System.out.println();
        }
    }
}


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

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String a = "";
        String b ="";
        int count = 0;
        int first = 0;
        for (int i = 0; i < n; i++) {
           if(i%2==0){
               a+="C";
               b+=".";
               first++;
               count++;
           }else {
               a+=".";
               b+="C";
               count++;
           }
        }
        int i = 0;
        if(n%2==0){
            System.out.println((n/2)*count);
        }else {
            System.out.println(((n/2)*count)+first);
        }
       while (i<n){
           System.out.println(a);
           i++;
           if(i<n){
               System.out.println(b);
               i++;
           }
       }
    }
}


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

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[][]a = new char[n][n];
int count = 0;

        for (int i = 0; i < n; i++) {
            if(i%2==0) {
                for (int j = 0; j < n; j++) {
                    if (j % 2 == 0) {
                        a[i][j] = 'C';
                        count++;
                    } else {
                       a[i][j] = '.';
                    }
                }
            }else {
                for (int j = 0; j < n; j++) {
                    if (j % 2 == 1) {
                        count++;
                        a[i][j] = 'C';
                    } else {
                        a[i][j] = '.';
                    }
                }
            }
        }
        System.out.println(count);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(a[i][j]+" ");
            }
            System.out.println();
        }
    }
}


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

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[][] a = new char[n][n];
        int count = 0;
        int t = 0;
        while (t < n) {
            for (int i = 0; i < n - 2; i += 2) {
                a[t][i] = 'C';
                count++;
            }
            for (int i = 1; i < n - 2; i += 2) {
                a[t][i] = '.';
            }
            if (t < n) {
                t++;
                for (int i = 1; i < n - 2; i += 2) {
                    a[t][i] = 'C';
                    count++;
                }
                for (int i = 0; i < n - 2; i += 2) {
                    a[t][i] = '.';
                }
            }
            t++;
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(a[i][j]+" ");
            }
            System.out.println();
        }
    }
}


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

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[][] a = new char[n][n];
        int count = 0;
        int t = 0;
        while (t < n) {
            for (int i = 0; i < n - 2; i += 2) {
                a[t][i] = 'C';
                count++;
            }
            for (int i = 1; i < n - 2; i += 2) {
                a[t][i] = '.';
            }
            if (t < n) {
                t++;
                for (int i = 1; i < n - 2; i += 2) {
                    a[t][i] = 'C';
                    count++;
                }
                for (int i = 0; i < n - 2; i += 2) {
                    a[t][i] = '.';
                }
            }
            t++;
        }
        System.out.println(count);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(a[i][j]+" ");
            }
            System.out.println();
        }
    }
}


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

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[][] a = new char[n][n];
        int count = 0;
        int t = 0;
        while (t < n) {
            for (int i = 0; i < n - 2; i += 2) {
                a[t][i] = 'C';
                count++;
            }
            for (int i = 1; i < n - 2; i += 2) {
                a[t][i] = '.';
            }
            if (t < n) {
                t++;
                for (int i = 1; i < n - 2; i += 2) {
                    a[t][i] = 'C';
                    count++;
                }
                for (int i = 0; i < n - 2; i += 2) {
                    a[t][i] = '.';
                }
            }
            t++;
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(a[i][j]);
            }
            System.out.println();
        }
    }
}


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

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(n);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(j%2==0){
                    System.out.print('C');
                }else {
                    System.out.print('.');
                }
            }
            System.out.println();
        }
    }
}


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

public class codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String a = "";
        String b ="";
        int count = 0;
        for (int i = 0; i < n; i++) {
           if(i%2==0){
               a+="C";
               b+=".";
               count++;
           }else {
               a+=".";
               b+="C";
               count++;
           }
        }
        int i = 0;
       while (i<n){
           System.out.println(a);
           i++;
           if(i<n){
               System.out.println(b);
               i++;
           }
       }
    }
}


import java.util.Scanner;

public class P384A{
    public static void main(String[] args){
      Scanner scanner = new Scanner(System.in);
      int n = scanner.nextInt();
      System.out.println(n % 2 == 0? (n * n / 2):(n * n / 2 + 1));
      for(int i = 0; i < n; i++){
          for (int m = 0; m < n ; m++ ){
              if (i % 2 == 0 ){
                  if(m % 2 == 0){
                      System.out.print("C");
                    } else {
                      System.out.print(".");
                    }
              } else {
                  if(m % 2 == 0){
                      System.out.print(".");
                    } else {
                      System.out.print("C");
                    }
              }

          }
          System.out.println();
        }
    }
}


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

public class P384A{
    public static void main(String[] args) throws Exception {
      Scanner scanner = new Scanner(System.in);
      OutputStreamWriter outputStreamWriter = new OutputStreamWriter(System.out);
      BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
      int n = scanner.nextInt();
      System.out.println(n % 2 == 0? (n * n / 2):(n * n / 2 + 1));
      for(int i = 0; i < n; i++){
          for (int m = 0; m < n ; m++ ){
              if (i % 2 == 0 ){
                  if(m % 2 == 0){
                      bufferedWriter.write('C');
                    } else {
                      bufferedWriter.write('.');
                    }
              } else {
                  if(m % 2 == 0){
                      bufferedWriter.write('.');
                    } else {
                      bufferedWriter.write('C');
                    }
              }

          }
          bufferedWriter.write('\n');
        }
    }
}


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

public class P384A{
    public static void main(String[] args) throws Exception {
      Scanner scanner = new Scanner(System.in);
      OutputStreamWriter outputStreamWriter = new OutputStreamWriter(System.out);
      BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
      int n = scanner.nextInt();
      bufferedWriter.write((n % 2 == 0? (n * n / 2):(n * n / 2 + 1)) + "\n");
      for(int i = 0; i < n; i++){
          for (int m = 0; m < n ; m++ ){
              if (i % 2 == 0 ){
                  if(m % 2 == 0){
                      bufferedWriter.write('C');
                    } else {
                      bufferedWriter.write('.');
                    }
              } else {
                  if(m % 2 == 0){
                      bufferedWriter.write('.');
                    } else {
                      bufferedWriter.write('C');
                    }
              }

          }
          bufferedWriter.write('\n');
        }
        bufferedWriter.flush();
    }
}


import java.util.Scanner;

public class P384A{
    public static void main(String[] args){
      Scanner scanner = new Scanner(System.in);
      int n = scanner.nextInt();
      System.out.println(n % 2 == 0? (n * n / 2):(n * n / 2 + 1));
      for(int i = 0; i < n; i++){
          String line = "";
          for (int m = 0; m < n ; m++ ){
              if (i % 2 == 0 ){
                  if(m % 2 == 0){
                      line = line + "C";
                    } else {
                      line = line + ".";
                    }
              } else {
                  if(m % 2 == 0){
                      line = line + ".";
                    } else {
                      line = line + "C";
                    }
              }

          }
          System.out.println(line);
        }
    }
}


import java.util.Scanner  ;
public class aaa {

	public static void main(String[] args) {
		Scanner ss = new Scanner (System.in)  ;
		int n  = ss.nextInt() ;
		String wan1  = ""  ;
		String wan2 = "" ;
		String gg ="" ;
		for (int j = 0 ; j < n/2 ; j ++   ) {
				wan1+= "C." ;
		}
		if (n%2==1) {
			wan1+="C" ;
			wan2 = wan1.substring(1)+"." ; }
		else {
			wan2 = "."+wan1.substring(0,n-1) ;
		}
		for (int i = 0 ; i <n ; i ++ ) {
			if (i%2 == 0 ) {
				gg+=wan1+"\n" ;
			}
			else
				gg+=wan2+"\n" ;
		}
		int y = 0 ;
		if (n%2 == 0 )
			y = (n*n) / 2 ;
		else
			y = (n*n + 1 ) / 2 ;

		System.out.println(y);
		System.out.println(gg);
	}

}


import java.util.Scanner  ;
public class A384_coder {

	public static void main(String[] args) {
		Scanner ss = new Scanner (System.in)  ;
		int n  = ss.nextInt() ;
		String wan  = ""  ;
		int y = 0 ;
		for (int i = 0 ; i <n ; i ++ ) {
			for (int j = 0 ; j < n ; j ++  ){
				if (i%2== 0 ) {
					if (j%2 == 0 ){
						wan+="C" ;
						y++ ;
					}
					else
						wan+="." ;
				}
				else
				{
					if (j%2 == 0)
						wan+="." ;
					else {
						wan+="C" ;
						y++ ;
					}
				}
			}
			wan+="\n" ;
		}
		System.out.println(y);
		System.out.println(wan);
	}

}


import java.util.Scanner  ;
import java.io.PrintWriter ;
public class A384_coder {

	public static void main(String[] args) {
		Scanner ss = new Scanner (System.in)  ;
		PrintWriter pp = new PrintWriter(System.out) ;
		int n  = ss.nextInt() ;
		String wan1  = ""  ;
		String wan2 = "" ;
		for (int j = 0 ; j < n/2 ; j ++   ) {
				wan1+= "C." ;
			}

		if (n%2==0)
		{
			wan2+="."+wan1.substring(0,n-1) ;

		}
		else {
			wan1+="C" ;
			wan2=wan1.substring(1)+"." ;
		}
		String kk = wan1+"\n" +wan2 ;

		int y = 0 ;
		if (n%2 == 0 )
			y = (n*n) / 2 ;
		else
			y = (n*n + 1 ) / 2 ;

		System.out.println(y);
		for (int i = 0 ; i <n/2 ; i ++ ) {
			pp.println(kk);
			pp.flush();
		}
		if (n%2 == 1){
			pp.println(wan1);
			pp.flush();
			pp.close();
		}

	}

}


import java.util.Scanner  ;
public class A384_coder {

	public static void main(String[] args) {
		Scanner ss = new Scanner (System.in)  ;
		int n  = ss.nextInt() ;
		String wan1  = ""  ;
		String wan2 = "" ;
		String gg ="" ;
		for (int j = 0 ; j < n ; j ++   ) {
			if (j%2 == 0 ) {
				wan1+= "C" ;
				wan2+="." ;
			}
			else
			{
				wan1+="." ;
				wan2+="C" ;
			}
		}
		for (int i = 0 ; i <n ; i ++ ) {
			if (i%2 == 0 ) {
				gg+=wan1+"\n" ;
			}
			else
				gg+=wan2+"\n" ;
		}
		int y = 0 ;
		if (n%2 == 0 )
			y = (n*n) / 2 ;
		else
			y = (n*n + 1 ) / 2 ;

		System.out.println(y);
		System.out.println(gg);
	}

}


import java.util.Scanner;

public class JavaApplication2
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int ans=(int)Math.ceil((n*n)/2.0);
        System.out.println(ans);

        String s="";
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(i%2==0)
                {
                    if(j%2==0)
                        System.out.print("C");
                    else
                        System.out.print(".");
                }else
                {
                    if(j%2==0)
                        System.out.print(".");
                    else
                        System.out.print("C");
                }

            }
            System.out.println("");
        }

    }

}