#include<bits/stdc++.h>
using namespace std;
string s;
struct{
int first,end;
int leng;
}maxx,minn;
int now;
int main(){
getline(cin,s);
int len=s.length();
for(int i=0;i<len;i++){
if(s[i]==' '||s[i]==','||s[i]=='.'){
now=0;
}
else{
now++;
if(now>maxx.leng){
maxx.leng=now;
maxx.end=i;
maxx.first=i-now+1;
}
if(now<minn.leng){
minn.leng=now;
minn.first=i-now+1;
minn.end=i;
}
}
}
for(int i=maxx.first;i<=maxx.end;i++){
putchar(s[i]);
}
cout<<"\n";
// printf("\n");
for(int i=minn.first;i<=minn.end;i++){
putchar(s[i]);
}
return 0;
}