Language: C++

#include<stdio.h>
char new[1002][1002];
int i,j,k;
int main(void)
{
	char old[5];
	char joi[3]={'J','O','I'};
	int m,n;
	int cnt,c,max;
	c=0;
	cnt=0;
	max=0;
	
	scanf("%d %d",&m,&n);
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			scanf(" %c",&new[i][j]);
		}
	}
	for(i=0;i<4;i++){
		scanf(" %c",&old[i]);
	}
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
				cnt++;
			}
			else if(new[i][j]=='J'){
				new[i][j]=joi[1];
				if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
					c++;
				}
				if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
					c++;
				}
				if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
					c++;
				}
				if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
					c++;
				}
				if(c>max){
					max=c;
				}
				c=0;
				new[i][j]=joi[2];
				if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
					c++;
				}
				if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
					c++;
				}
				if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
					c++;
				}
				if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
					c++;
				}
				if(c>max){
					max=c;
				}
			}
			else if(new[i][j]=='O'){
				new[i][j]=joi[0];
				if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
					c++;
				}
				if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
					c++;
				}
				if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
					c++;
				}
				if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
					c++;
				}
				if(c>max){
					max=c;
				}
				c=0;
				new[i][j]=joi[2];
				if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
					c++;
				}
				if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
					c++;
				}
				if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
					c++;
				}
				if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
					c++;
				}
				if(c>max){
					max=c;
				}
			}
			else if(new[i][j]=='I'){
				new[i][j]=joi[0];
				if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
					c++;
				}
				if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
					c++;
				}
				if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
					c++;
				}
				if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
					c++;
				}
				if(c>max){
					max=c;
				}
				c=0;
				new[i][j]=joi[1];
				if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
					c++;
				}
				if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
					c++;
				}
				if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
					c++;
				}
				if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
					c++;
				}
				if(c>max){
					max=c;
				}
			}
		}
	}
	printf("%d\n",cnt+max);
	return 0;
}

Compiler output:
a.cc:2:6: error: expected unqualified-id before 'new'
    2 | char new[1002][1002];
      |      ^~~
a.cc: In function 'int main()':
a.cc:17:41: error: expected type-specifier before '[' token
   17 |                         scanf(" %c",&new[i][j]);
      |                                         ^
a.cc:25:31: error: expected type-specifier before '[' token
   25 |                         if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
      |                               ^
a.cc:25:31: error: expected ')' before '[' token
   25 |                         if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
      |                           ~   ^
      |                               )
a.cc:28:36: error: expected type-specifier before '[' token
   28 |                         else if(new[i][j]=='J'){
      |                                    ^
a.cc:28:36: error: expected ')' before '[' token
   28 |                         else if(new[i][j]=='J'){
      |                                ~   ^
      |                                    )
a.cc:29:36: error: expected type-specifier before '[' token
   29 |                                 new[i][j]=joi[1];
      |                                    ^
a.cc:30:39: error: expected type-specifier before '[' token
   30 |                                 if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
      |                                       ^
a.cc:30:39: error: expected ')' before '[' token
   30 |                                 if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:33:39: error: expected type-specifier before '[' token
   33 |                                 if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
      |                                       ^
a.cc:33:39: error: expected ')' before '[' token
   33 |                                 if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:36:39: error: expected type-specifier before '[' token
   36 |                                 if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
      |                                       ^
a.cc:36:39: error: expected ')' before '[' token
   36 |                                 if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:39:39: error: expected type-specifier before '[' token
   39 |                                 if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
      |                                       ^
a.cc:39:39: error: expected ')' before '[' token
   39 |                                 if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:46:36: error: expected type-specifier before '[' token
   46 |                                 new[i][j]=joi[2];
      |                                    ^
a.cc:47:39: error: expected type-specifier before '[' token
   47 |                                 if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
      |                                       ^
a.cc:47:39: error: expected ')' before '[' token
   47 |                                 if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:50:39: error: expected type-specifier before '[' token
   50 |                                 if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
      |                                       ^
a.cc:50:39: error: expected ')' before '[' token
   50 |                                 if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:53:39: error: expected type-specifier before '[' token
   53 |                                 if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
      |                                       ^
a.cc:53:39: error: expected ')' before '[' token
   53 |                                 if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:56:39: error: expected type-specifier before '[' token
   56 |                                 if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
      |                                       ^
a.cc:56:39: error: expected ')' before '[' token
   56 |                                 if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:63:36: error: expected type-specifier before '[' token
   63 |                         else if(new[i][j]=='O'){
      |                                    ^
a.cc:63:36: error: expected ')' before '[' token
   63 |                         else if(new[i][j]=='O'){
      |                                ~   ^
      |                                    )
a.cc:64:36: error: expected type-specifier before '[' token
   64 |                                 new[i][j]=joi[0];
      |                                    ^
a.cc:65:39: error: expected type-specifier before '[' token
   65 |                                 if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
      |                                       ^
a.cc:65:39: error: expected ')' before '[' token
   65 |                                 if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:68:39: error: expected type-specifier before '[' token
   68 |                                 if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
      |                                       ^
a.cc:68:39: error: expected ')' before '[' token
   68 |                                 if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:71:39: error: expected type-specifier before '[' token
   71 |                                 if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
      |                                       ^
a.cc:71:39: error: expected ')' before '[' token
   71 |                                 if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:74:39: error: expected type-specifier before '[' token
   74 |                                 if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
      |                                       ^
a.cc:74:39: error: expected ')' before '[' token
   74 |                                 if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:81:36: error: expected type-specifier before '[' token
   81 |                                 new[i][j]=joi[2];
      |                                    ^
a.cc:82:39: error: expected type-specifier before '[' token
   82 |                                 if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
      |                                       ^
a.cc:82:39: error: expected ')' before '[' token
   82 |                                 if(new[i][j]==old[0] && new[i][j+1]==old[1] && new[i+1][j]==old[2] && new[i+1][j+1]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:85:39: error: expected type-specifier before '[' token
   85 |                                 if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
      |                                       ^
a.cc:85:39: error: expected ')' before '[' token
   85 |                                 if(new[i][j-1]==old[0] && new[i][j]==old[1] && new[i-1][j-1]==old[2] && new[i-1][j]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:88:39: error: expected type-specifier before '[' token
   88 |                                 if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
      |                                       ^
a.cc:88:39: error: expected ')' before '[' token
   88 |                                 if(new[i+1][j-1]==old[0] && new[i+1][j]==old[1] && new[i][j-1]==old[2] && new[i][j]==old[3]){
      |                                   ~   ^
      |                                       )
a.cc:91:39: error: expected type-specifier before '[' token
   91 |                                 if(new[i+1][j]==old[0] && new[i+1][j+1]==old[1] && new[i][j]==old[2] && new[i][j+1]==old[3]){
      |                                       ^
a.cc:91:39: error: expected ')' bef