/*
ID: sdjllyh1
PROG: transform
LANG: JAVA
complete date: 2008/9/21
efficiency: o(n^2)
author: LiuYongHui From GuiZhou University Of China
more article: www.cnblogs.com/sdjl
*/
import java.io.*;
import java.util.*;
public class transform {
public static Pattern beforPattern = null;
public static Pattern afterPattern = null;
public static int answer;
public static void main(String[] args) throws IOException {
init();
run();
output();
}
public static void init() throws IOException {
BufferedReader f = new BufferedReader(new FileReader("transform.in"));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
String beforChars = "";
for(int i=0; i<n; i++){
st = new StringTokenizer(f.readLine());
beforChars += st.nextToken();
}
beforPattern = new Pattern(n,beforChars.toCharArray());
String afterChars = "";
for(int i=0; i<n; i++){
st = new StringTokenizer(f.readLine());
afterChars += st.nextToken();
}
afterPattern = new Pattern(n,afterChars.toCharArray());
}
public static void run(){
if(afterPattern.equals(beforPattern.DegreeRotation90())){
answer = 1;
}
else if(afterPattern.equals(beforPattern.DegreeRotation180())){
answer = 2;
}
else if(afterPattern.equals(beforPattern.DegreeRotation270())){
answer = 3;
}
else if(afterPattern.equals(beforPattern.Reflection())){
answer = 4;
}
else if(afterPattern.equals(beforPattern.Combination1())){
answer = 5;
}
else if(afterPattern.equals(beforPattern.Combination2())){
answer = 5;
}
else if(afterPattern.equals(beforPattern.Combination3())){
answer = 5;
}
else if(afterPattern.equals(beforPattern)){
answer = 6;
}
else{
answer = 7;
}
}
public static void output() throws IOException{
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("transform.out")));
out.println(answer);
out.close();
}
}
class Pattern {
private int size = 0;
private char[] characters;
public Pattern(int size, char[] characters){
assert(size * size == characters.length);
this.size = size;
this.characters = characters;
}
public Pattern DegreeRotation90(){
char[] newCharacters = this.characters.clone();
for(int i=0; i<this.size; i++){
for(int j=0; j<this.size; j++){
newCharacters[j*this.size + (this.size - i -1)]
= this.characters[i*size + j];
}
}
return new Pattern(this.size, newCharacters);
}
public Pattern DegreeRotation180(){
char[] newCharacters = this.characters.clone();
for(int i=0; i<this.size; i++){
for(int j=0; j<this.size; j++){
newCharacters[(this.size - i -1)*this.size + (this.size - j -1)]
= this.characters[i*size + j];
}
}
return new Pattern(this.size, newCharacters);
}
public Pattern DegreeRotation270(){
char[] newCharacters = this.characters.clone();
for(int i=0; i<this.size; i++){
for(int j=0; j<this.size; j++){
newCharacters[(this.size - j -1)*this.size + i]
= this.characters[i*size + j];
}
}
return new Pattern(this.size, newCharacters);
}
public Pattern Reflection(){
char[] newCharacters = this.characters.clone();
for(int i=0; i<this.size; i++){
for(int j=0; j<this.size; j++){
newCharacters[i*this.size + (this.size - j -1)]
= this.characters[i*size + j];
}
}
return new Pattern(this.size, newCharacters);
}
public Pattern Combination1(){
return this.Reflection().DegreeRotation90();
}
public Pattern Combination2(){
return this.Reflection().DegreeRotation180();
}
public Pattern Combination3(){
return this.Reflection().DegreeRotation270();
}
public boolean equals(Object value){
assert(value instanceof Pattern);
Pattern compare = (Pattern)value;
boolean retEquals = true;
for(int i=0; i<this.size * this.size; i++){
if(this.characters[i] != compare.characters[i])
{
retEquals = false;
break;
}
}
return retEquals;
}
}
ID: sdjllyh1
PROG: transform
LANG: JAVA
complete date: 2008/9/21
efficiency: o(n^2)
author: LiuYongHui From GuiZhou University Of China
more article: www.cnblogs.com/sdjl
*/
import java.io.*;
import java.util.*;
public class transform {
public static Pattern beforPattern = null;
public static Pattern afterPattern = null;
public static int answer;
public static void main(String[] args) throws IOException {
init();
run();
output();
}
public static void init() throws IOException {
BufferedReader f = new BufferedReader(new FileReader("transform.in"));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
String beforChars = "";
for(int i=0; i<n; i++){
st = new StringTokenizer(f.readLine());
beforChars += st.nextToken();
}
beforPattern = new Pattern(n,beforChars.toCharArray());
String afterChars = "";
for(int i=0; i<n; i++){
st = new StringTokenizer(f.readLine());
afterChars += st.nextToken();
}
afterPattern = new Pattern(n,afterChars.toCharArray());
}
public static void run(){
if(afterPattern.equals(beforPattern.DegreeRotation90())){
answer = 1;
}
else if(afterPattern.equals(beforPattern.DegreeRotation180())){
answer = 2;
}
else if(afterPattern.equals(beforPattern.DegreeRotation270())){
answer = 3;
}
else if(afterPattern.equals(beforPattern.Reflection())){
answer = 4;
}
else if(afterPattern.equals(beforPattern.Combination1())){
answer = 5;
}
else if(afterPattern.equals(beforPattern.Combination2())){
answer = 5;
}
else if(afterPattern.equals(beforPattern.Combination3())){
answer = 5;
}
else if(afterPattern.equals(beforPattern)){
answer = 6;
}
else{
answer = 7;
}
}
public static void output() throws IOException{
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("transform.out")));
out.println(answer);
out.close();
}
}
class Pattern {
private int size = 0;
private char[] characters;
public Pattern(int size, char[] characters){
assert(size * size == characters.length);
this.size = size;
this.characters = characters;
}
public Pattern DegreeRotation90(){
char[] newCharacters = this.characters.clone();
for(int i=0; i<this.size; i++){
for(int j=0; j<this.size; j++){
newCharacters[j*this.size + (this.size - i -1)]
= this.characters[i*size + j];
}
}
return new Pattern(this.size, newCharacters);
}
public Pattern DegreeRotation180(){
char[] newCharacters = this.characters.clone();
for(int i=0; i<this.size; i++){
for(int j=0; j<this.size; j++){
newCharacters[(this.size - i -1)*this.size + (this.size - j -1)]
= this.characters[i*size + j];
}
}
return new Pattern(this.size, newCharacters);
}
public Pattern DegreeRotation270(){
char[] newCharacters = this.characters.clone();
for(int i=0; i<this.size; i++){
for(int j=0; j<this.size; j++){
newCharacters[(this.size - j -1)*this.size + i]
= this.characters[i*size + j];
}
}
return new Pattern(this.size, newCharacters);
}
public Pattern Reflection(){
char[] newCharacters = this.characters.clone();
for(int i=0; i<this.size; i++){
for(int j=0; j<this.size; j++){
newCharacters[i*this.size + (this.size - j -1)]
= this.characters[i*size + j];
}
}
return new Pattern(this.size, newCharacters);
}
public Pattern Combination1(){
return this.Reflection().DegreeRotation90();
}
public Pattern Combination2(){
return this.Reflection().DegreeRotation180();
}
public Pattern Combination3(){
return this.Reflection().DegreeRotation270();
}
public boolean equals(Object value){
assert(value instanceof Pattern);
Pattern compare = (Pattern)value;
boolean retEquals = true;
for(int i=0; i<this.size * this.size; i++){
if(this.characters[i] != compare.characters[i])
{
retEquals = false;
break;
}
}
return retEquals;
}
}