using System.Collections.Generic;
static List<int> addLists(int[] l1, int[] l2) {
var res = new List<int>(Math.Max(l1.Length, l2.Length) + 1);
int i1 = l1.Length - 1, i2 = l2.Length - 1;
for(; i1 >= 0 && i2 >= 0; --i1, --i2) {
int s = l1[i1] + l2[i2] + carry;
if(carry > 0) res.Add(carry);
public static void Main() {
var r = addLists(new int[]{3,4,9,7,1}, new int[]{4,3});
foreach(var i in r) Console.Write("{0} ", i);
r = addLists(new int[]{9,9,9,9,9}, new int[]{1});
foreach(var i in r) Console.Write("{0} ", i);