SDE Path

Add Two Numbers Represented as Linked Lists

Medium

Add Two Numbers Represented as Linked Lists

Given two numbers represented as linked lists in reverse order, add them and return the sum as a linked list.

Input format

The first line contains N and M. The next two lines contain the digits of two non-negative numbers in reverse order (least significant digit first).

Output format

Print the digits of their sum, least significant digit first.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
3 3
2 4 3
5 6 4
Expected output
7 0 8
Example 2
Input
1 1
0
0
Expected output
0