#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<ctime>
#include<stdio.h>
#include<time.h>
#define int long long
#define debug() cout<<"come here\n"
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pb push_back
using namespace std;
int qpow(int a,int b,int p){int ret=1;while(b){if(b&1)ret=(ret*a)%p;a=(a*a)%p;b>>=1;}return ret;}
inline int read(){int ret=0,f=1;char ch=getchar();while(ch<'0'||ch>'9')f=(ch=='-'?-1:f),ch=getchar();while(ch>='0'&&ch<='9')ret=(ret<<3)+(ret<<1)+(ch^48),ch=getchar();return ret*f;}
inline void write(int x){if(x<0){putchar('-');write(-x);return ;}if(x>9)write(x/10);putchar((char)(x%10+48));}
inline void writech(int x,char ch){write(x);putchar(ch);};
void slowout(string s,int x)
{
	for(int i=0;i<s.size();i++)
	{
		Sleep(x);
		printf("%c",s[i]);
	}
}
void setpos(int y,int x){
	HANDLE hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
	COORD coo;
	coo.X=x;
	coo.Y=y;
	SetConsoleCursorPosition(hOutput, coo);
}
int a[11],cnt[11],cnts[11];
signed main()
{
//	ios::sync_with_stdio(0);
//	cin.tie(0);
//	cout.tie(0);
	mt19937 rng(time(0));
	bool flag=0;
	while(1)
	{
		memset(cnt,0,sizeof(cnt));
		if(flag==0)
		{
			Sleep(500);
			setpos(0,0);
			slowout("Number len(2~9):",10);
		}
		else
		{
			setpos(0,0);
			slowout("Number len(2~9):",0);
		}
		int n=_getch()-'0';
		if(n>10||n<2)
		{
			flag=1;
			system("cls");
			continue;
		}
		printf("%lld",n);
		for(int i=1;i<=n;i++)
		{
			a[i]=rng()%10;
			cnt[a[i]]++;
		}
		Sleep(500);
		for(int i=16;i>=0;i--)
		{
			setpos(0,i);
			printf(" ");
			Sleep(10);
		}
		Sleep(500);
		int times=0;
		while(1)
		{
			times++;
			setpos(0,0);
			slowout("Guess:",20);
			string s;
			cin>>s;
			Sleep(500);
			for(int i=5+s.size();i>=0;i--)
			{
				setpos(0,i);
				printf(" ");
				Sleep(20);
			}
			setpos(0,0);
			Sleep(500);
			if(s.size()!=n)
			{
				slowout("Error!",20);
				Sleep(500);
				for(int i=5;i>=0;i--)
				{
					setpos(0,i);
					printf(" ");
					Sleep(20);
				}
				continue;
			}
			else
			{
				s=' '+s;
				int ca=0,cb=0;
				memset(cnts,0,sizeof(cnts));
				for(int i=1;i<=n;i++)
				{
					cnts[s[i]-'0']++;
				}
				for(int i=0;i<10;i++)
				{
					cb+=min(cnt[i],cnts[i]);
				}
				for(int i=1;i<=n;i++)
				{
					if(a[i]==s[i]-'0')ca++;
				}
				cb-=ca;
				if(ca==n)break;
				string s1="";
				s1+=ca+'0';
				s1+='A';
				s1+=cb+'0';
				s1+='B';
				slowout(s1,20);
				Sleep(1000);
				for(int i=3;i>=0;i--)
				{
					setpos(0,i);
					printf(" ");
					Sleep(20);
				}
			}
		}
		Sleep(500);
		setpos(0,0);
		int cnt=0;
		string s1="";
		while(times)
		{
			s1=(char)(times%10+'0')+s1;
			cnt++;
			times/=10;
		}
		slowout("You use "+s1+" times guess to get the right answer.",10);
		Sleep(2000);
		for(int i=44+cnt;i>=0;i--)
		{
			setpos(0,i);
			printf(" ");
			Sleep(10);
		}
		flag=0;
	}
	return 0;
}