#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<cstring>
#include<string>
using namespace std;
typedef struct Node{
char data;
bool flag;
struct Node *next;
}Node;
string str;
void InitList(Node *&L){
L=(Node *)malloc(sizeof(Node));
L->next=NULL;
}
void CreateListR(Node *&L){
Node *s,*r;
L=(Node *)malloc(sizeof(Node));
r=L;
for(int i=0;i<str.size();i++){
if(isalpha(str[i])){
s=(Node *)malloc(sizeof(Node));
s->data=str[i];
r->next=s;
r=s;
}
}
r->next=NULL;
}
void DispList(Node *L,bool f){
Node *p=L->next;
while(p!=NULL){
if(p->flag==f) cout<<p->data<<" ";
p=p->next;
}
}
void solve(Node *&L,char c){
Node *p=L->next;
while(p!=NULL){
if(p->data<c) p->flag=true;
else p->flag=false;
p=p->next;
}
}
int main(){
Node *L;
char c;
getline(cin,str);
CreateListR(L);
cin>>c;
solve(L,c);
DispList(L,true);
DispList(L,false);
return 0;
}
#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef struct Node{
char data;
struct Node *next;
}Node;
void InitList(Node *&L){
L=(Node *)malloc(sizeof(Node));
L->next=NULL;
}
void CreateListR(Node *&L,string ss){
Node *s,*r;
L=(Node *)malloc(sizeof(Node));
r=L;
for(int i=ss.size()-1;i>=0;i--){
s=(Node *)malloc(sizeof(Node));
s->data=ss[i];
r->next=s;
r=s;
}
r->next=NULL;
}
void DispList(Node *L){
Node *p=L->next;
while(p!=NULL){
cout<<p->data;
p=p->next;
}
}
void solve(Node *a1,Node *a2,Node *&ans){
Node *p1,*p2,*s,*r;
p1=a1->next;
p2=a2->next;
int t=0,num;
ans=(Node *)malloc(sizeof(Node));
r=ans;
while(p1!=NULL&&p2!=NULL){
int x=p1->data-'0';
int y=p2->data-'0';
num=(x+y+t)%10;
t=(x+y)/10;
s=(Node *)malloc(sizeof(Node));
s->data=(char)num+'0';
r->next=s;
r=s;
p1=p1->next;
p2=p2->next;
}
while(p1!=NULL){
int x=p1->data-'0';
num=(t+x)%10;
t=(t+x)/10;
s=(Node *)malloc(sizeof(Node));
s->data=(char)num+'0';
r->next=s;
r=s;
p1=p1->next;
}
while(p2!=NULL){
int x=p2->data-'0';
num=(t+x)%10;
t=(t+x)/10;
s=(Node *)malloc(sizeof(Node));
s->data=(char)num+'0';
r->next=s;
r=s;
p2=p2->next;
}
r->next=NULL;
}
void printans(Node *ans){
string s="";
Node *p=ans->next;
while(p!=NULL){
s+=p->data;
p=p->next;
}
reverse(s.begin(),s.end());
cout<<s<<endl;
}
int main(){
Node *a1,*a2,*ans;
string s1,s2;
cin>>s1>>s2;
CreateListR(a1,s1);
CreateListR(a2,s2);
solve(a1,a2,ans);
printans(ans);
return 0;
}