Python Easy Challenges
Python Easy Challenges
ID:2581
A year Y will be passed as input. The program must find if the given year is a leap year or not.
- If it is leap year, the program must print yes else it should print no
Note: A year is a leap year if it is divisible by 4. If it is a century then it should be divisible by 400.
The pseudocode is as given below.
if year is divisible by 400 then is_leap_year
else if year is divisible by 100 then not_leap_year
else if year is divisible by 4 then is_leap_year
else not_leap_year
Example Input/Output:
If 2000 is the input, the program must print yes
If 2100 is the input, the program must print no
If 2013 is the input, the program must print no
Input Format:
A year as a number is passed to the standard input.
Output Format:
The string value as per the conditions above printed to the standard output.
Boundary Conditions:
0 < Y <= 8000
ID:2588
In a zoo there are some birds and animals. All birds have two legs and all animals have four legs.
GIven the head count and leg count of both birds and animals taken together, the program must print the head
count of birds and animals separated by a space as output.
Input Format:
First line will contain the integer value H representing the head count of both birds and animals taken together.
Second line will contain the integer value L representing the leg count of both birds and animals taken together.
Output Format:
First line will contain the integer values of the head count of birds and animals separated by a space.
Constraints:
0 < H < 1000
1 < L < 2000
Sample Input/Output:
Example 1:
Input:
27
84
Output:
12 15
Explanation:
There are 12 birds and 15 animals.
Example 2:
Input:
114
256
Output:
100 14
Explanation:
There are 100 birds and 14 animals.
ID:2587
A floating point value F indicating the amount in rupees is passed as input. The program must print the
corresponding value in paise.
Note: 1 rupee = 100 paise.
Input Format:
The first line contains F.
Output Format:
The first line contains the integer value denoting the paise.
Boundary Conditions:
0.00 <= F <= 999999.99
Example Input/Output 1:
Input:
11.30
Output:
1130
Example Input/Output 2:
Input:
0.80
Output:
80
Example Input/Output 3:
Input:
0.0
Output:
0
ID:2590
An integer value N is passed as the input. The program must reverse the sign of N and print -N as the output.
Input Format:
The first line contains N.
Output Format:
The first line contains -N.
Boundary Conditions:
-999999 <= N <= 999999
Example Input/Output 1:
Input:
125
Output:
-125
Example Input/Output 2:
Input:
-346
Output:
346
Example Input/Output 3:
Input:
0
Output:
0
ID:2583
Two string values S1 and S2 are passed as input. The program must print the count of common characters in the
strings S1 and S2. Assume the alphabets in S1 and S2 will be in lower case.
Input Format:
First line will contain the value of string S1
Second line will contain the value of string S2
Output Format:
First line will contain the count of common alphabets.
Boundary Conditions:
Length of S1 and S2 will be from 3 to 100.
Sample Input/Output:
Example 1:
Input:
china
india
Output:
3
Explanation:
The common characters are i,n,a
Example 2:
Input:
energy
every
Output:
3
Explanation:
The common characters are e,r,y
ID:2584
String S is passed as the input to the program. S may or may not have a single underscore embedded in it. The
program must reverse the String S till the first underscore and print it as the output.
Input Format:
The first line contains S.
Output Format:
The first line contains the string S modified based on the given conditions.
Boundary Conditions:
Length of S is from 3 to 100.
Example Input/Output 1:
Input:
abcd_pqrs
Output:
dcba_pqrs
Example Input/Output 2:
Input:
_kilo
Output:
_kilo
Example Input/Output 3:
Input:
nounderscore
Output:
erocsrednuon
ID:2586
A string S is passed as input. S will contain two integer values separated by one of these alphabets - A, S, M, D
where
- A or a is for addition
- S or s is for subtraction
- M or m is for multiplication
- D or d is for division
The program must perform the necessary operation and print the result as the output. (Ignore any floating point
values just print the integer result.)
Input Format:
The first line contains S.
Output Format:
The first line contains the resulting integer value.
Boundary Conditions:
Length of S is from 3 to 100.
Example Input/Output 1:
Input:
5A11
Output:
16
Explanation:
As the alphabet is A, 5 and 11 are added giving 16.
Example Input/Output 2:
Input:
120D6
Output:
20
Example Input/Output 3:
Input:
1405d10
Output:
140
ID:2585
A string S is passed as input. S will contain multiple integer values with each integer value followed by an alphabet.
The program must expand the alphabets based on the related integer value.
Input Format:
The first line contains S.
Output Format:
The first line contains the expanded string value.
Boundary Conditions:
Length of S is from 2 to 100.
Example Input/Output 1:
Input:
4a5h
Output:
aaaahhhhh
Explanation:
As it is 4a and 5h, four a's are printed followed by 5 h's
Example Input/Output 2:
Input:
1k2b4k
Output:
kbbkkkk
ID:2582
In a betting game involving the roll of a dice, Sandeep gains Rs.X if an odd number turns up and he loses Rs.Y is an
even number turns up. The numbers shown on the face of the dice in a certain number of games is passed as
input. The values of X and Y are also passed as input. The program must print the net gain or loss as the output.
Input Format:
First line will contain the numbers shown on the face of the dice separated by one or more spaces.
Second line will contain the value of X
Third line will contain the value of Y
Output Format:
The net gain or loss (loss will be a negative value)
Sample Input/Output:
Example 1:
Input:
143
10
30
Output:
-10
Explanation:
He gains 20 rupees for 1 and 3 and loses 30 rupees for 4. Hence there is a net loss of 20-30 = -10
Example 2:
Input:
46121
50
25
Output:
25
He gains 100 rupees for 1,1 and loses 75 rupees for 4,6,2. Hence there is a net gain of 100-75 = 25
ID:2589
Given a set of numbers where all other numbers are multiple of the smallest number, the program must find the
count of the common factors C excluding 1.
Input Format:
First line will contain the integer value N representing how many numbers are passed as input.
Next N lines will have the numbers.
Output Format:
First line will contain the count of common factors C.
Constraints:
N will be from 2 to 20.
Sample Input/Output:
Example 1:
Input:
2
100
75
Output:
2
Explanation:
The common factors excluding 1 are 5,25. Hence output is 2
Example 2:
Input:
3
10
20
30
Output:
3
Explanation:
The common factors excluding 1 are 2,5,10. Hence output is 3.
ID:2605
A square matrix of size N×N is passed as the input. The program must calculate and print the sum of the elements
in the corners.
Input Format:
The first line will contain the value of N.
The next N lines will contain the N values separated by one or more spaces.
Output Format:
The first line will contain the integer value denoting the sum of the elements in the corners.
Boundary Conditions:
2 <= N <= 20
Example Input/Output 1:
Input:
3
10 90 1
4 22 5
32 8 66
Output:
109
Explanation:
The sum = 10+1+66+32 = 109
ID:2603
The first three terms in an arithmetic progression are passed as input. A positive integer value N (where N > 3) is
also passed as the input. The program must print Nth term in the arithmetic progression.
Input Format:
The first line will contain the first three terms separated by a space.
The second line will contain N.
Output Format:
The integer value denoting the Nth term.
Example Input/Output 1:
Input:
5 10 15
6
Output:
30
Explanation:
The progression is 5 10 15 20 25 30 35 and so on.
The 6th term is 30.
Example Input/Output 2:
Input:
147
5
Output:
13
ID:2608
Two whole numbers N1 and N2 are passed as input. The program must print the number of primes present
between N1 and N2 (the range is inclusive of N1 and N2)
Input Format:
First line will contain the value of the first number N1
Second line will contain the value of the second number N2
Output Format:
First line will contain the count of prime numbers between N1 and N2
Sample Input/Output:
Example 1:
Input:
6142
6200
Output:
6
Explanation:
The prime numbers within the range 6142 to 6200 are 6143, 6151, 6163, 6173, 6197, 6199
Example 2:
Input:
38
70
Output:
7
Explanation:
The prime numbers within the range 38 to 70 are 41, 43, 47, 53, 59, 61, 67
ID:2606
A string S of length L is passed as the input. The program must rotate the string S by N position in forward direction
and print the result as the output.
Input Format:
The first line will contain the value of S.
The second line will contain N.
Output Format:
The first line will contain the rotated string value.
Boundary Conditions:
The length L of the string S is from 3 to 100.
0 <= N <= L
Example Input/Output 1:
Input:
cricket
2
Output:
etcrick
Example Input/Output 2:
Input:
truth
5
Output:
truth
ID:2604
A string S (with only LOWER case alphabets and length from 3 to 100) will be passed as input. The program should
print the alphabets in the string in descending order.
Input Format:
The first line will contain S.
Output Format:
The first line will contain the alphabets present in S in descending order.
Example Input/Output 1:
Input:
cake
Output:
keca
Example Input/Output 2:
Input:
innovation
Output:
vtonia
ID:2610
Two string values S1 and S2 are passed as the input. The program must concatenate them depending on which
string comes first in the alphabetical order.
Input Format:
The first line will contain S1.
The second line will contain S2
Output Format:
The first line will contain the concatenated string value.
Boundary Conditions:
Length of S1 and S2 is from 3 to 100.
Example Input/Output 1:
Input:
apple
orange
Output:
appleorange
Example Input/Output 2:
Input:
zoo
tiger
Output:
tigerzoo
ID:2602
Given a string S and two characters A, B the program must print the number of occurrences where A is followed
by B.
Boundary Conditions:
Length of the string S is between 2 and 200.
Input Format:
First line will contain the string value S.
Second line will contain the value of A.
Third line will contain the value of B.
Output Format:
First line will contain the integer which represents the number of occurrences in sring S where A is followed by B
Sample Input/Output:
Example 1:
Input:
malayalam
a
l
Output:
2
Explanation:
The two occurrences where a is followed by l is as highlighted below. malayalam
Example 2:
Input:
engine
e
n
Output:
1
ID:2607
A number N is passed as the input. The program must print the next immediate prime number.
Input Format:
The first line will contain N.
Output Format:
The first line will contain the integer value of next immediate prime number.
Boundary Conditions:
1 <= N <= 999999
Example Input/Output 1:
Input:
11
Output:
13
Example Input/Output 2:
Input:
2
Output:
3
ID:2601
An expression E is passed as an input to the program. The expression will contain three numbers A, B and C, one
equal symbol and one of the mathematical operators + - * /
But the given mathematical operator is incorrect and hence the expression is not valid. Hence the program must
identify the correct operator and print that as the output.
Input Format:
First line will contain the expression E
Output Format:
First line will contain the correct mathematical operator
Sample Input/Output:
Example 1:
Input:
5-4=20
Output:
*
Explanation:
Only 5 multiplied with 4 gives 20. Hence - must be replaced with *.
Example 2:
Input:
999+9=111
Output:
/
Explanation:
Only 999 divided by 9 gives 111. Hence + must be replaced with /.
ID:2609
A string S (only alphabets) is passed as input. The printed output should contain alphabets in odd positions in each
word in uppercase and alphabets in even positions in each word in lowercase.
Input Format:
The first line will contain S.
Output Format:
The first line will contain the resultant string value based on the conditions provided.
Boundary Conditions:
Length of S is from 3 to 100.
Example Input/Output 1:
Input:
tREE GiVES us fruiTS
Output:
TrEe GiVeS Us FrUiTs
Example Input/Output 2:
Input:
FLoweR iS beauTIFUL
Output:
FlOwEr Is BeAuTiFuL
ID:2531
The program must accept two numbers X and Y and then print their HCF/GCD.
Input Format:
The first line denotes the value of X.
The second line denotes the value of Y.
Output Format:
The first line contains the HCF of X and Y.
Boundary Conditions:
1 <= X <= 999999
1 <= Y <= 999999
Example Input/Output 1:
Input:
30
40
Output:
10
Example Input/Output 2:
Input:
15
10
Output:
5
ID:2534
The program must accept a number N and print the sum of tenth and unit digits.
Input Format:
The first line denotes the value of N.
Output Format:
The first line contains the sum of tenth and unit digits.
Boundary Conditions:
10 <= N <= 9999999
Example Input/Output 1:
Input:
231
Output:
4
Example Input/Output 2:
Input:
100
Output:
0
Example Input/Output 3:
Input:
192
Output:
11
ID:2567
An integer value N is passed as the input. The program must print YES if N is prime number. Else the program must
print NO.
Input Format:
The first line denotes the value of N.
Output Format:
YES or NO based on if N is a prime number or not. (The OUTPUT is CASE SENSITIVE).
Boundary Conditions:
2 <= N <= 9999999
Example Input/Output 1:
Input:
19
Output:
YES
Example Input/Output 2:
Input:
189210
Output:
NO
The program must accept N integers and print the second largest value among the N integers.
Input Format:
The first line denotes the value of N.
Next N lines will contain the N integer values.
Output Format:
The first line contains the second largest integer.
Boundary Conditions:
2 <= N <= 100
The value of the integers will be from -999999 to 999999.
Example Input/Output 1:
Input:
3
100
2200
345
Output:
345
Example Input/Output 2:
Input:
6
-23
-256
-87
-90
-11019
-2
Output:
-23
ID:2525
The program must accept two integers X and Y and print the odd integers between them.
Input Format:
The first line denotes the value of X.
The second line denotes the value of Y.
Output Format:
The first line contains the odd integers between X and Y separated by a space.
Boundary Conditions:
-999999 <= X <= 9999999
X < Y <= 9999999
Example Input/Output 1:
Input:
1
11
Output:
3579
Example Input/Output 2:
Input:
24
30
Output:
25 27 29
ID:2533
The program must accept a string value S and print the reverse of S.
Input Format:
The first line denotes the value of S.
Output Format:
The first line contains reversed value of S.
Boundary Conditions:
Length of string S is from 2 to 100.
Example Input/Output 1:
Input:
abcde
Output:
edcba
Example Input/Output 2:
Input:
look
Output:
kool
ID:2568
Solved By 21828 Users
An integer value N is passed as the input. The program must print the first N terms in the Fibonacci sequence.
Input Format:
The first line denotes the value of N.
Output Format:
The first N terms in the Fibonacci sequence (with each term separated by a space)
Boundary Conditions:
3 <= N <= 50
Example Input/Output 1:
Input:
5
Output:
01123
Example Input/Output 2:
Input:
10
Output:
0 1 1 2 3 5 8 13 21 34
ID:2570
A string S is passed as the input. The program must print the number of upper case letters in the string S.
Input Format:
The first line denotes the value of S.
Output Format:
The first line contains the count of upper case letters in S.
Boundary Conditions:
Length of S is from 3 to 100.
Example Input/Output 1:
Input:
ViCtorY
Output:
3
Example Input/Output 2:
Input:
zookeeper
Output:
0
Max Execution Time Limit: 5000 millisecs
String - Remove First & Last Characters
ID:2528
The program must accept a String value S and remove the first and last characters.
Input Format:
The first line denotes the value of S.
Output Format:
The first line contains the string value after removing the first and last characters in the string S.
Boundary Conditions:
Length of S is from 3 to 200.
Example Input/Output 1:
Input:
Lion
Output:
io
Example Input/Output 2:
Input:
jug
Output:
u
ID:2569
A string S is passed as the input. Character C is also passed as the input. The program must print the string value S
till C is encountered.
Input Format:
The first line denotes the value of S.
The second line denotes the value of C.
Output Format:
The first line contains the string value S till C is encountered.
Boundary Conditions:
Length of S is from 3 to 100.
Example Input/Output 1:
Input:
manager
e
Output:
manag
Example Input/Output 2:
Input:
Everest
e
Output:
Ev
Explanation:
As the input character C is e which is in lower case, the first letter in Everest< upper case E is ignored and the string
S is printed till a lower case e is encountered.
ID:2580
The number of rows N is passed as the input. The program must print the half pyramid using the numbers from 1
to N.
Input Format:
The first line contains N.
Output Format:
N lines representing the half pyramid pattern using the numbers from 1 to N. (A single space is used to separate the
numbers)
Boundary Conditions:
2 <= N <= 100
Example Input/Output 1:
Input:
5
Output:
1
12
123
1234
12345
Example Input/Output 2:
Input:
3
Output:
1
12
123
Max Execution Time Limit: 5000 millisecs
Pattern Printing - Half Pyramid Numbers
ID:2580
The number of rows N is passed as the input. The program must print the half pyramid using the numbers from 1
to N.
Input Format:
The first line contains N.
Output Format:
N lines representing the half pyramid pattern using the numbers from 1 to N. (A single space is used to separate the
numbers)
Boundary Conditions:
2 <= N <= 100
Example Input/Output 1:
Input:
5
Output:
1
12
123
1234
12345
Example Input/Output 2:
Input:
3
Output:
1
12
123
ID:2577
The number of rows N is passed as the input. The program must print the half pyramid using asterisk *.
Input Format:
The first line contains N.
Output Format:
N lines representing the half pyramid pattern using * (A single space is used to separate the *)
Boundary Conditions:
2 <= N <= 100
Example Input/Output 1:
Input:
5
Output:
*
**
***
****
*****
Example Input/Output 2:
Input:
3
Output:
*
**
***
ID:2576
A string S is passed as the input. S can contain alphabets, numbers and special characters. The program must print
only the alphabets in S.
Input Format:
The first line contains S.
Output Format:
The first line contains only the alphabets in S.
Boundary Conditions:
The length of the input string is between 1 to 1000.
Example Input/Output 1:
Input:
abcd_5ef8!xyz
Output:
abcdefxyz
Example Input/Output 2:
Input:
1239_-87
Output:
Explanation:
As there are no alphabets in the input value nothing is printed as output.
Max Execution Time Limit: 5000 millisecs
Space Separated Integers Sum
ID:2574
A single line consisting of a set of integers, each separated by space is passed as input to the program. The
program must print the sum of all the integers present.
Input Format:
The first line contains the integer values (Each separated by a space)
Output Format:
The first line contains the sum of all the integers.
Boundary Conditions:
The length of the input string is between 3 to 10000
The value of the integer values will be from -99999 to 99999
Example Input/Output 1:
Input:
100 -99 98 5
Output:
104
Example Input/Output 2:
Input:
100 200 -300 500 -450 -50
Output:
0
ID:2575
A certain number of people attended a meeting which was to begin at 10:00 am on a given day. The arrival time in
HH:MM format of those who attended the meeting is passed as the input in a single line, with each arrival time by
a space. The program must print the count of people who came late (after 10:00 am) to the meeting.
Input Format:
The first line contains the arrival time separated by a space.
Output Format:
The first line contains the count of late comers.
Boundary Conditions:
The length of the input string is between 4 to 10000.
The time HH:MM will be in 24 hour format (HH is hours and MM is minutes).
Example Input/Output 1:
Input:
10:00 9:55 10:02 9:45 11:00
Output:
2
Explanation:
The 2 people were those who came at 10:02 and 11:00
ID:2573
The runs scored by a cricket team in the first and second innings of N test cricket matches are passed as input. The
program must print the average of first and second innings (with precision upto two decimal places).
Input Format:
The first line denotes the value of N.
Next N lines will contain the first and second innings score separated by a space.
Output Format:
The first line contains the average of first innings score.
The second line contains the average of second innings score.
Boundary Conditions:
2 <= N <= 20
The value of the runs will be from 0 to 1000.
Example Input/Output 1:
Input:
3
250 200
450 300
200 250
Output:
300.00
250.00
ID:2579
String S which is a palindrome is passed as the input. But just one alphabet A is missing in S. The program must
print the missing alphabet A.
Note: The FIRST alphabet of S will always be present.
Input Format:
The first line contains S.
Output Format:
The first line contains the missing alphabet A.
Boundary Conditions:
The length of the input string S is between 3 to 100.
The FIRST alphabet of S will always be present.
Example Input/Output 1:
Input:
malayaam
Output:
l
Example Input/Output 2:
Input:
abcddcb
Output:
a
ID:2578
The name and mileage of certain cars is passed as the input. The format is CARNAME@MILEAGE and the input is as
a single line, with each car information separated by a space. The program must print the car with the lowest
mileage. (Assume no two cars will have the lowest mileage)
Input Format:
The first line contains the CARNAME@MILEAGE separated by a space.
Output Format:
The first line contains the name of the car with the lowest mileage.
Boundary Conditions:
The length of the input string is between 4 to 10000.
The length of the car name is from 1 to 50.
Example Input/Output 1:
Input:
Zantro@16.15 Zity@12.5 Gamry@9.8
Output:
Gamry
ID:2571
Solved By 11022 Users
The runs scored by N batsmen of a cricket team is passed as the input to the program. The program must print the
name of the batsman who scored the highest runs. (You can assume that no two batsmen will be the top scorers).
Input Format:
The first line denotes the value of N.
Next N lines will contain the name of the batsman and the runs score (both separated by a comma)
Output Format:
The first line contains the name of the batsman with the top score.
Boundary Conditions:
2 <= N <= 11
The length of the names will be from 3 to 100.
The value of the runs will be from 0 to 500.
Example Input/Output 1:
Input:
5
BatsmanA,45
BatsmanB,52
BatsmanC,12
BatsmanD,9
BatsmanE,78
Output:
BatsmanE
ID:2572
Names of N students and the marks scored by them in Maths, Physics and Chemistry are passed as the input. The
program must print the name of the student who has scored the maximum marks in these three subjects. (Assume
only one student will be the top scorer).
Input Format:
The first line denotes the value of N.
Next N lines will contain the name of the student and the marks in three subjects separated by colon.
Output Format:
The first line contains the name of the students with the highest marks.
Boundary Conditions:
2 <= N <= 50
The length of the names will be from 3 to 100.
The value of the marks will be from 0 to 100.
Example Input/Output 1:
Input:
4
Sasikumar:50:60:70
Arun:60:40:90
Manoj:50:50:60
Rekha:60:35:45
Output:
Arun
ID:2594
A string S is passed as the input. S has at least one repeating character. The program must print the first repeating
character C from the last.
Input Format:
The first line contains S.
Output Format:
The first line contains C.
Boundary Conditions:
Length of S will be from 3 to 100.
Example Input/Output 1:
Input:
abcdexyzbwqpooplj
Output:
p
ID:2592
A string S is passed as the input. A positive integer X is also passed as the input. The program must print the
characters at positions which are multiples of X.
Input Format:
The first line contains S.
The second line contains X.
Output Format:
The first line contains the characters at positions which are multiples of X.
Boundary Conditions:
Length of S will be from 3 to 100.
Example Input/Output 1:
Input:
abcdexyzwqpoolj
5
Output:
eqj
Explanation:
The multiples of 5 are like 5, 10, 15,...
So the characters in these positions are e,q,j
ID:2597
The program must accept a string S and print the count of words in S.
Boundary Condition(s):
1 <= Length of S <= 100
Input Format:
The first line contains S.
Output Format:
The first line contains the integer value representing the word count.
Example Input/Output 1:
Input:
I like tea
Output:
3
Example Input/Output 2:
Input:
I like coffee very much
Output:
5
ID:2591
A single line L with a set of space separated values indicating distance travelled and time taken is passed as the
input. The program must calculate the average speed S (with precision upto 2 decimal places) and print S as the
output.
Note: The distance and time taken will follow the format DISTANCE@TIMETAKEN. DISTANCE will be in kilometers
and TIMETAKEN will be in hours.
Input Format:
The first line contains L.
Output Format:
The first line contains the average speed S.
Boundary Conditions:
Length of L will be from 3 to 100.
Example Input/Output 1:
Input:
60@2 120@3
Output:
36.00 kmph
Explanation:
Total distance = 60+120 = 180 km.
Total time taken = 2+3 = 5 hours.
Hence average speed = 180/5 = 36.00 kmph
ID:2600
A date in DD-MM-YYYY format is passed as the input. The program must print the calendar month.
01 - January, 02 - February and so on till 12 - December.
Input Format:
First line will contain the date in DD-MM-YYYY format.
Output Format:
The string value denoting the month.
Example Input/Output 1:
Input:
23-12-2016
Output:
December
ID:2599
ID:2596
An odd length string S is passed as the input. The middle three letters of S must be printed as the output.
Input Format:
First line will contain the string value S
Output Format:
First line will contain the middle three letters of S.
Boundary Conditions:
Length of S is from 5 to 100
Example Input/Output 1:
Input:
level
Output:
eve
Example Input/Output 2:
Input:
manager
Output:
nag
ID:2598
A string value S is passed as the input. The program must print the first letter of each word in S in upper case.
Input Format:
First line will contain the string value S
Output Format:
First line will contain the string value with the first letter of each word in S in upper case.
Boundary Conditions:
Length of S is from 5 to 500
Example Input/Output 1:
Input:
She is happy.
Output:
She Is Happy.
Example Input/Output 2:
Input:
joIN tHE ParTY
Output:
JoIN THE ParTY
ID:2593
ID:2595
Two string values S1 and S2 are passed as input. The last portion of S1 will be the first portion of S2. The program
must print this common part in S1 and S2.
Input Format:
The first line contains S1.
The second line contains S2.
Output Format:
The first line contains the common part.
Boundary Conditions:
Length of S1 and S2 will be from 3 to 100.
Example Input/Output 1:
Input:
mayday
daybreak
Output:
day
Example Input/Output 2:
Input:
bridge
gear
Output:
ge