/*
ID:bbezxcy1
PROG: milk2
LANG: C++
*/
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
bool vis[1200000];
int main()
{
freopen("milk2.in","r",stdin );
freopen("milk2.out","w",stdout );
int n,i,j,a,b,c,d,ans1,ans2;
while(scanf("%d",&n)!=EOF)
{
c=1200000,d=0;
memset(vis,0,sizeof(vis));
for(i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
b--;
for(j=a;j<=b;j++)
{
vis[j]=1;
}
c=min(a,c);
d=max(b,d);
}
a=0,b=0;
ans1=ans2=0;
for(i=c;i<=d;i++)
{
if(vis[i]==1)
{
a=0;
b++;
ans1=max(b,ans1);
}
else
{
b=0;
a++;
ans2=max(a,ans2);
}
}
printf("%d %d\n",ans1,ans2);
}
return 0;
}
/*
ID:bbezxcy1
PROG: transform
LANG: C++
*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char str[20][20],cha1[20][20],cha2[20][20],cha[20][20],dir[20][20];
bool check(int n){
int i,j,a,b,c;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(dir[i][j]!=cha[i][j]){
return 0;
}
}
}
return 1;
}
void change1(int n){
int i,j,k,a,b,c;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
cha[i][j]=str[n-j-1][i];
}
}
}
void change2(int n){
int i,j,a,b,c;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
cha[i][j]=str[n-j-1][i];
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
cha1[i][j]=cha[n-j-1][i];
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
cha[i][j]=cha1[i][j];
}
}
}
void change3(int n){
int i,j,a,b,c;
change2(n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
cha[i][j]=cha1[n-j-1][i];
}
}
}
void change4(int n){
int i,j,k,a,b,c;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
cha[i][j]=str[i][n-j-1];
}
}
}
char cpy[20][20];
bool change5(int n){
int i,j;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
cpy[i][j]=str[i][j];
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
str[i][j]=cpy[i][n-j-1];
}
}
change1(n);
if(check(n))return 1;
change2(n);
if(check(n))return 1;
change3(n);
if(check(n))return 1;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
str[i][j]=cpy[i][j];
}
}
return 0;
}
bool change6(int n){
int i,j,k,a,b,c;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(str[i][j]!=dir[i][j]){
return 0;
}
}
}
return 1;
}
int main(){
int n,i,j,k,l;
freopen("transform.in","r",stdin );
freopen("transform.out","w",stdout );
while(scanf("%d",&n)!=EOF){
for(i=0;i<n;i++){
scanf("%s",str[i]);
}
for(i=0;i<n;i++){
scanf("%s",dir[i]);
}
change1(n);
if(check(n)){
printf("1\n");
continue;
}
change2(n);
if(check(n)){
printf("2\n");
continue;
}
change3(n);
if(check(n)){
printf("3\n");
continue;
}
change4(n);
if(check(n)){
printf("4\n");
continue;
}
if(change5(n)){
printf("5\n");
continue;
}
if(change6(n)){
printf("6\n");
}
else{
printf("7\n");
}
}
return 0;
}
/*
ID:bbezxcy1
PROG: namenum
LANG: C++
*/
#include<iostream>
#include<cstring>
#include<fstream>
#include<cstdio>
#include<map>
using namespace std;
ifstream tin("dict.txt");
class nodea{
public:
int id;
nodea *p[30];
nodea(){
int i;
id=-1;
for(i=0;i<30;i++)p[i]=NULL;
}
};
nodea *root;
int cnt;
bool flag;
int getnum(char *s){
int i;
nodea *r=root;
int l=strlen(s);
for(i=0;i<l;i++){
if(r->p[s[i]-'A']==NULL){
r->p[s[i]-'A']=new nodea();
}
r=r->p[s[i]-'A'];
}
if(r->id==-1){
r->id=cnt;
cnt++;
}
return r->id;
}
const char key[20][3] = {
{ 0, 0, 0 }, { 0, 0, 0 },
{ 'A', 'B', 'C' }, { 'D', 'E', 'F' }, { 'G', 'H', 'I' }, { 'J', 'K', 'L' },
{ 'M', 'N', 'O' }, { 'P', 'R', 'S' }, { 'T', 'U', 'V' }, { 'W', 'X', 'Y' }
};
char str[20],cha[20];
int tot,len;
void dfs(int dep){
if(dep==len){
cha[dep]='\0';
if(getnum(cha)<tot){
printf("%s\n",cha);
flag=1;
}
return;
}
for(int i=0;i<3;i++){
cha[dep]=key[str[dep]-'0'][i];
dfs(dep+1);
}
}
int main(){
cnt=1;
root=new nodea();
while(tin>>str){
if(str[0]=='0')break;
getnum(str);
}
freopen("namenum.in","r",stdin );
freopen("namenum.out","w",stdout );
tot=cnt;
flag=0;
scanf("%s",str);
len=strlen(str);
dfs(0);
if(!flag)printf("NONE\n");
return 0;
}
/*
ID:bbezxcy1
PROG: palsquare
LANG: C++
*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int num[1000];
bool ispar(int a,int n){
int b=a;
int c=0;
while(b){
num[c++]=b%n;
b/=n;
}
for(int i=0;i<c;i++){
if(num[i]!=num[c-i-1]){
return 0;
}
}
return 1;
}
void print(int a,int n){
int b=a;
int c=0;
while(b){
num[c++]=b%n;
b/=n;
}
for(int i=c-1;i>=0;i--){
if(num[i]<10){
printf("%d",num[i]);
}
else{
printf("%c",num[i]-10+'A');
}
}
}
int main(){
int n;
freopen("palsquare.in","r",stdin );
freopen("palsquare.out","w",stdout );
while(scanf("%d",&n)!=EOF){
for(int i=1;i<=300;i++){
if(ispar(i*i,n)){
print(i,n);
printf(" ");
print(i*i,n);
printf("\n");
}
}
}
return 0;
}
/*
ID:bbezxcy1
PROG: dualpal
LANG: C++
*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int num[1000000];
bool ispar(int a,int n){
int b=a;
int c=0;
while(b){
num[c++]=b%n;
b/=n;
}
for(int i=0;i<c;i++){
if(num[i]!=num[c-i-1]){
return 0;
}
}
return 1;
}
int main(){
int n,s,i,j,a,b,c;
freopen("dualpal.in","r",stdin );
freopen("dualpal.out","w",stdout );
while(scanf("%d%d",&n,&s)!=EOF){
a=s;
for(i=n;i>0;){
a++;
b=0;
for(j=2;j<=10;j++){
if(ispar(a,j)){
b++;
}
}
if(b>=2){
i--;
printf("%d\n",a);
}
}
}
return 0;
}