A guy has to reach his home and does not want to be late. He takes train to reach home. He has a mental illness, so he always switches train at every station.
For eg: If he starts with train A then at station 2 he will switch his train to train B and so on. Similarly, if he starts with train B then he will switch to train A at station 2 and so on. Please help him to find the minimum total time he would take to reach his home.
 
Example 1:
Input:
N = 3
A[] = {2, 1, 2}
B[] = {3, 2, 1}
Output:
5
Explanation:
If he chose train A initially, then time to
reach home will be : 2 + 2 + 2 = 6 
If he Chose train B initially, then time to
reach home will be : 3 + 1 + 1 = 5
5 is minimum hence the answer.
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function minTime() which takes the array A[], B[] and its size N as inputs and returns the minimum total time in seconds to reach home.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1 ≤ N ≤ 10^{6}
1 ≤ Ai, Bi ≤ 10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3

class Solution:
    def minTime(self, a, b, n):
    # Your code goes here 
    


Solutions:
class Solution:

	def minTime(self, a, b, n):
		(c, d) = (0, 0)
		for i in range(n):
			if i % 2 == 0:
				c += a[i]
			else:
				c += b[i]
		for i in range(n):
			if i % 2 == 0:
				d += b[i]
			else:
				d += a[i]
		return min(c, d)


class Solution:

	def minTime(self, a, b, n):
		trainA = sum(a[::2]) + sum(b[1::2])
		trainB = sum(b[::2]) + sum(a[1::2])
		return min(trainA, trainB)


class Solution:

	def minTime(self, a, b, n):
		(timeA, timeB) = (0, 0)
		for i in range(0, n, 2):
			timeA += a[i]
			timeB += b[i]
		return min(timeA + sum(b) - timeB, timeB + sum(a) - timeA)


class Solution:

	def minTime(self, a, b, n):
		su1 = 0
		su2 = 0
		for i in range(n):
			if i % 2 == 0:
				su1 += a[i]
				su2 += b[i]
			else:
				su1 += b[i]
				su2 += a[i]
		return min(su1, su2)


class Solution:

	def minTime(self, a, b, n):
		atrain = 0
		btrain = 0
		for i in range(n):
			if i % 2 == 0:
				atrain += a[i]
				btrain += b[i]
			else:
				atrain += b[i]
				btrain += a[i]
		return min(atrain, btrain)


class Solution:

	def minTime(self, a, b, n):
		s1 = 0
		s2 = 0
		for i in range(n):
			if i % 2 == 0:
				s1 = s1 + a[i]
				s2 = s2 + b[i]
			elif i % 2 == 1:
				s1 = s1 + b[i]
				s2 = s2 + a[i]
		return min([s1, s2])


class Solution:

	def minTime(self, a, b, n):
		dp = [[0, 0] for i in range(n)]
		dp[0][0] = a[0]
		dp[0][1] = b[0]
		for i in range(1, n):
			dp[i][0] = dp[i - 1][1] + a[i]
			dp[i][1] = dp[i - 1][0] + b[i]
		return min(dp[n - 1])


class Solution:

	def minTime(self, a, b, n):
		time_a = 0
		time_b = 0
		a_even = 0
		a_odd = 0
		b_even = 0
		b_odd = 0
		for i in range(0, n, 2):
			a_even += a[i]
			b_even += b[i]
		for i in range(1, n, 2):
			a_odd += a[i]
			b_odd += b[i]
		time_a = a_odd + b_even
		time_b = a_even + b_odd
		return min(time_a, time_b)


class Solution:

	def minTime(self, a, b, n):
		ans1 = 0
		ans2 = 0
		for i in range(n):
			if i % 2 != 0:
				ans1 = ans1 + a[i]
			else:
				ans1 = ans1 + b[i]
		for i in range(n):
			if i % 2 != 0:
				ans2 = ans2 + b[i]
			else:
				ans2 = ans2 + a[i]
		if ans1 < ans2:
			return ans1
		return ans2


class Solution:

	def minTime(self, a, b, n):
		sa = 0
		sb = 0
		for i in range(n):
			if i % 2 == 0:
				sa += a[i]
				sb += b[i]
			else:
				sb += a[i]
				sa += b[i]
		return min(sa, sb)


class Solution:

	def minTime(self, a, b, n):
		count = 0
		toun = 0
		coun = 0
		tou = 0
		for i in range(0, len(a), 2):
			count += a[i]
		for j in range(1, len(b), 2):
			coun += b[j]
		for k in range(1, len(a), 2):
			toun += a[k]
		for l in range(0, len(b), 2):
			tou += b[l]
		co = count + coun
		to = toun + tou
		if co > to:
			return to
		else:
			return co


class Solution:

	def minTime(self, a, b, n):
		(i, j) = (0, 1)
		l1 = a[i::2]
		l2 = b[j::2]
		sum1 = sum(l1) + sum(l2)
		(k, l) = (1, 0)
		l3 = a[k::2]
		l4 = b[l::2]
		sum2 = sum(l3) + sum(l4)
		if sum1 < sum2:
			return sum1
		return sum2


class Solution:

	def minTime(self, a, b, n):
		a_time = 0
		b_time = 0
		for index in range(n):
			if index % 2 == 0:
				a_time += a[index]
				b_time += b[index]
			else:
				a_time += b[index]
				b_time += a[index]
		return a_time if a_time < b_time else b_time


class Solution:

	def minTime(self, a, b, n):
		sum_a = 0
		sum_b = 0
		for i in range(n):
			if i % 2 == 0:
				sum_a += a[i]
				sum_b += b[i]
			else:
				sum_a += b[i]
				sum_b += a[i]
		return min(sum_a, sum_b)


class Solution:

	def minTime(self, a, b, n):
		a_min = 0
		b_min = 0
		for i in range(n):
			if i % 2 == 0:
				a_min += a[i]
				b_min += b[i]
			else:
				a_min += b[i]
				b_min += a[i]
		output = min([a_min, b_min])
		return output


class Solution:

	def minTime(self, a, b, n):
		for i in range(1, n, 2):
			(a[i], b[i]) = (b[i], a[i])
		return min(sum(a), sum(b))


class Solution:

	def minTime(self, a, b, n):
		A = 0
		B = 0
		for i in range(n):
			if i % 2 == 0:
				A += a[i]
				B += b[i]
			else:
				A += b[i]
				B += a[i]
		return min(A, B)


class Solution:

	def minTime(self, a, b, n):
		sum1 = 0
		sum2 = 0
		for i in range(0, n):
			if i % 2 != 0:
				sum1 += b[i]
				sum2 += a[i]
			elif i % 2 == 0:
				sum1 += a[i]
				sum2 += b[i]
		if sum1 > sum2:
			return sum2
		else:
			return sum1


class Solution:

	def minTime(self, a, b, n):
		s = 0
		k = 0
		for j in range(n):
			if k == 0:
				s += a[j]
				k = 1
			else:
				s += b[j]
				k = 0
		s1 = 0
		k = 0
		for j in range(n):
			if k == 0:
				s1 += b[j]
				k = 1
			else:
				s1 += a[j]
				k = 0
		return min(s, s1)


class Solution:

	def minTime(self, a, b, n):
		one = 0
		two = 0
		for i in range(n):
			if i % 2 == 0:
				one += a[i]
				two += b[i]
			else:
				one += b[i]
				two += a[i]
		return min(one, two)


class Solution:

	def minTime(self, a, b, n):
		tot1 = 0
		tot2 = 0
		for i in range(n):
			if i % 2 == 0:
				tot1 += a[i]
				tot2 += b[i]
			else:
				tot1 += b[i]
				tot2 += a[i]
		return min(tot1, tot2)


class Solution:

	def minTime(self, a, b, n):
		k = 0
		j = 0
		for i in range(0, n):
			if i % 2 == 0:
				k = k + a[i]
			else:
				k = k + b[i]
		for i in range(0, n):
			if i % 2 == 0:
				j = j + b[i]
			else:
				j = j + a[i]
		return min(k, j)


class Solution:

	def minTime(self, a, b, n):
		su = 0
		bu = 0
		for i in range(n):
			if i % 2 == 0:
				su += a[i]
			else:
				su += b[i]
		for i in range(n):
			if i % 2 == 0:
				bu += b[i]
			else:
				bu += a[i]
		return min(su, bu)


class Solution:

	def minTime(self, a: list, b: list, n: int) -> int:
		summation1 = summation2 = 0
		for i in range(n):
			if i % 2:
				summation1 += a[i]
				summation2 += b[i]
			else:
				summation1 += b[i]
				summation2 += a[i]
		return summation1 if summation1 < summation2 else summation2


class Solution:

	def minTime(self, a, b, n):
		x = 0
		ch = 1
		for i in range(n):
			if ch == 1:
				x += a[i]
				ch = 0
			elif ch == 0:
				x += b[i]
				ch = 1
		y = 0
		ch = 0
		for i in range(n):
			if ch == 1:
				y += a[i]
				ch = 0
			elif ch == 0:
				y += b[i]
				ch = 1
		if x > y:
			return y
		else:
			return x


class Solution:

	def minTime(self, a, b, n):
		s = 0
		l = []
		a1 = a[::2]
		a2 = a[1::2]
		b1 = b[::2]
		b2 = b[1::2]
		a1 += b2
		a2 += b1
		s1 = sum(a1)
		s2 = sum(a2)
		s = min(s1, s2)
		return s


class Solution:

	def minTime(self, a, b, n):
		od1 = od2 = ev1 = ev2 = 0
		for i in range(n):
			if i & 1:
				od1 += a[i]
				od2 += b[i]
			else:
				ev1 += a[i]
				ev2 += b[i]
		return min(od1 + ev2, od2 + ev1)


class Solution:

	def minTime(self, a, b, n):
		x = 0
		y = 0
		for i in range(n):
			if i % 2 == 0:
				x = x + a[i]
				y = y + b[i]
			else:
				x = x + b[i]
				y = y + a[i]
		return min(x, y)


class Solution:

	def minTime(self, a, b, n):
		ar = a[0:n:2]
		br = b[1:n:2]
		ar1 = a[1:n:2]
		br1 = b[0:n:2]
		c = ar + br
		c1 = ar1 + br1
		s = 0
		s1 = 0
		for i in c:
			s = s + i
		for i in c1:
			s1 = s1 + i
		if s < s1:
			return s
		else:
			return s1


class Solution:

	def minTime(self, a, b, n):
		asum = 0
		bsum = 0
		for i in range(n):
			if i % 2 == 0:
				asum += a[i]
				bsum += b[i]
			else:
				asum += b[i]
				bsum += a[i]
		return min(asum, bsum)


class Solution:

	def minTime(self, a, b, n):
		train_a = 0
		train_b = 0
		for i in range(n):
			if i % 2 == 0:
				train_a += a[i]
				train_b += b[i]
			else:
				train_a += b[i]
				train_b += a[i]
		return min(train_a, train_b)


class Solution:

	def minTime(self, a, b, n):
		c1 = 0
		c2 = 0
		for i in range(n):
			if i % 2 == 0:
				c1 += b[i]
				c2 += a[i]
			else:
				c1 += a[i]
				c2 += b[i]
		return min(c1, c2)


class Solution:

	def minTime(self, a, b, n):
		s = 0
		s1 = 0
		for i in range(0, len(a)):
			if i % 2 == 0:
				s = s + a[i]
			else:
				s = s + b[i]
			if i % 2 != 0:
				s1 = s1 + a[i]
			else:
				s1 += b[i]
		return s < s1 and s or s1


class Solution:

	def minTime(self, a, b, n):
		s = []
		d = []
		for i in range(0, n, 2):
			s.append(a[i])
			d.append(b[i])
		for j in range(1, n, 2):
			s.append(b[j])
			d.append(a[j])
		return min(sum(s), sum(d))


class Solution:

	def minTime(self, a, b, n):
		AB = 0
		BA = 0
		for i in range(0, n):
			if i % 2 == 0:
				AB = AB + a[i]
				BA = BA + b[i]
			else:
				AB = AB + b[i]
				BA = BA + a[i]
		return min(AB, BA)


class Solution:

	def minTime(self, a, b, n):
		p = []
		q = []
		for i in range(0, n):
			if i % 2 == 0:
				p.append(a[i])
				q.append(b[i])
			else:
				p.append(b[i])
				q.append(a[i])
		if sum(p) < sum(q):
			return sum(p)
		else:
			return sum(q)


class Solution:

	def minTime(self, a, b, n):
		m = a[0:n:2]
		r = b[1:n:2]
		s = a[1:n:2]
		k = b[0:n:2]
		t = sum(m) + sum(r)
		j = sum(s) + sum(k)
		return min(t, j)


class Solution:

	def minTime(self, a, b, n):
		sum_A = 0
		sum_B = 0
		for i in range(n):
			if i % 2 == 0:
				sum_A += a[i]
			else:
				sum_A += b[i]
		for i in range(n):
			if i % 2 == 0:
				sum_B += b[i]
			else:
				sum_B += a[i]
		return min(sum_A, sum_B)


class Solution:

	def minTime(self, A, B, n):
		res = []
		s = 0
		for x in range(n):
			if x % 2 == 0:
				s += A[x]
			else:
				s += B[x]
		res.append(s)
		s = 0
		for x in range(n):
			if x % 2 == 0:
				s += B[x]
			else:
				s += A[x]
		res.append(s)
		return min(res)


class Solution:

	def minTime(self, a, b, n):
		sa = 0
		sb = 0
		for i in range(n):
			if i % 2 == 0:
				sa += a[i]
			else:
				sa += b[i]
		for i in range(n):
			if i % 2 == 0:
				sb += b[i]
			else:
				sb += a[i]
		return min(sa, sb)

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		b = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.minTime(a, b, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def minTime(self, a, b, n):
		sa = sum(a)
		sb = sum(b)
		sae = 0
		sbe = 0
		if n % 2 != 0:
			for i in range(int(n / 2) + 1):
				sae += a[2 * i]
				sbe += b[2 * i]
			ao = sum(a) - sae
			bo = sum(b) - sbe
		else:
			for i in range(int(n / 2)):
				sae += a[2 * i]
				sbe += b[2 * i]
			ao = sum(a) - sae
			bo = sum(b) - sbe
		ta = sae + bo
		tb = ao + sbe
		return min(ta, tb)

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		b = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.minTime(a, b, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def minTime(self, a, b, n):
		new_arr = []
		new_arr1 = []
		for i in range(n):
			if i % 2 == 0:
				new_arr.append(a[i])
				new_arr1.append(b[i])
			else:
				new_arr.append(b[i])
				new_arr1.append(a[i])
		result = sum(new_arr)
		result1 = sum(new_arr1)
		final_result = 0
		if result < result1:
			final_result = result
		else:
			final_result = result1
		return final_result

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		b = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.minTime(a, b, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def minTime(self, a, b, n):
		s = a[0::2]
		t = a[1::2]
		u = b[0::2]
		v = b[1::2]
		return min(sum(s) + sum(v), sum(t) + sum(u))

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		b = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.minTime(a, b, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def minTime(self, a, b, n):
		minTime = 9999999999
		count = 0
		total = 0
		total2 = 0
		for itr in range(n):
			if count % 2 == 0:
				total += a[itr]
			else:
				total += b[itr]
			count += 1
		count = 0
		for itr in range(n):
			if count % 2 == 0:
				total2 += b[itr]
			else:
				total2 += a[itr]
			count += 1
		return min(total, total2)

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		b = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.minTime(a, b, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def minTime(self, a, b, n):
		sumOddA = 0
		sumEvenA = 0
		sumOddB = 0
		sumEvenB = 0
		for i in range(n):
			if i % 2 == 0:
				sumEvenA += a[i]
			else:
				sumOddA += a[i]
		for i in range(n):
			if i % 2 == 0:
				sumEvenB += b[i]
			else:
				sumOddB += b[i]
		if sumOddA + sumEvenB < sumOddB + sumEvenA:
			return sumOddA + sumEvenB
		return sumOddB + sumEvenA

def main():
	T = int(input())
	while T > 0:
		n = int(input())
		a = [int(x) for x in input().strip().split()]
		b = [int(x) for x in input().strip().split()]
		ob = Solution()
		print(ob.minTime(a, b, n))
		T -= 1
if __name__ == '__main__':
	main()


class Solution:

	def minTime(self, a, b, n):
		sum_even_a = 0
		sum_odd_a = 0
		sum_even_b = 0
		sum_odd_b = 0
		for i in range(0, n):
			if i % 2 == 0:
				sum_even_a += a[i]
			else:
				sum_odd_a += a[i]
		for i in range(0, n):
			if i % 2 == 0:
				sum_even_b += b[i]
			else:
				sum_odd_b += b[i]
		if sum_even_a + sum_odd_b < sum_even_b + sum_odd_a:
			return sum_even_a + sum_odd_b
		else:
			return sum_even_b + sum_odd_a


class Solution:

	def minTime(self, a, b, n):
		(t1, t2) = (0, 0)
		for i in range(n):
			if not i & 1:
				t1 += a[i]
				t2 += b[i]
			else:
				t1 += b[i]
				t2 += a[i]
		return min(t1, t2)


class Solution:

	def minTime(self, a, b, n):
		sum1 = sum(a[0:n:2]) + sum(b[1:n:2])
		sum2 = sum(b[0:n:2]) + sum(a[1:n:2])
		ans = min(sum1, sum2)
		return ans


class Solution:

	def minTime(self, a, b, n):
		(atime, btime) = (0, 0)
		for i in range(n):
			if i % 2 == 0:
				atime += a[i]
				btime += b[i]
			else:
				atime += b[i]
				btime += a[i]
		return min(atime, btime)


class Solution:

	def minTime(self, a, b, n):
		sum1 = sum2 = 0
		q = a[0:n:2] + b[1:n:2]
		r = a[1:n:2] + b[0:n:2]
		return min(sum(q), sum(r))


class Solution:

	def minTime(self, a, b, n):
		time1 = 0
		time2 = 0
		for i in range(n):
			if i % 2 == 0:
				time1 += a[i]
				time2 += b[i]
			else:
				time1 += b[i]
				time2 += a[i]
		return min(time1, time2)


class Solution:

	def minTime(self, a, b, n):
		minTimeAStart = 0
		minTimeBStart = 0
		for i in range(n):
			if i % 2 == 0:
				minTimeAStart += a[i]
				minTimeBStart += b[i]
			else:
				minTimeAStart += b[i]
				minTimeBStart += a[i]
		if minTimeAStart <= minTimeBStart:
			return minTimeAStart
		else:
			return minTimeBStart


class Solution:

	def minTime(self, a, b, n):
		suma = 0
		sumb = 0
		for i in range(n):
			if i % 2 == 0:
				suma += a[i]
				sumb += b[i]
			else:
				suma += b[i]
				sumb += a[i]
		if suma < sumb:
			return suma
		else:
			return sumb


class Solution:

	def minTime(self, a, b, n):
		a_time = 0
		b_time = 0
		j = 1
		for i in range(0, n, 2):
			if i == n - 1:
				a_time = a_time + a[i]
			else:
				a_time = a_time + (a[i] + b[j])
			j += 2
		i = 1
		for j in range(0, n, 2):
			if j == n - 1:
				b_time = b_time + b[j]
			else:
				b_time = b_time + (b[j] + a[i])
			i += 2
		return min(a_time, b_time)


class Solution:

	def minTime(self, a, b, n):
		sum = 0
		for i in range(1, n, 2):
			sum = sum + a[i - 1] + b[i]
		if n % 2 != 0:
			sum = sum + a[-1]
		sum2 = 0
		for i in range(1, n, 2):
			sum2 = sum2 + b[i - 1] + a[i]
		if n % 2 != 0:
			sum2 = sum2 + b[-1]
		if sum > sum2:
			return sum2
		return sum


class Solution:

	def minTime(self, a, b, n):
		f1 = 0
		s1 = 0
		s2 = 0
		for i in range(n):
			if f1 == 0:
				s1 = s1 + a[i]
				f1 = 1
			else:
				s1 = s1 + b[i]
				f1 = 0
		f1 = 0
		for i in range(n):
			if f1 == 0:
				s2 = s2 + b[i]
				f1 = 1
			else:
				s2 = s2 + a[i]
				f1 = 0
		return min(s1, s2)


class Solution:

	def minTime(self, a, b, n):
		ta = 0
		tb = 0
		for i in range(n):
			if i % 2 == 0:
				ta += a[i]
			else:
				ta += b[i]
		for i in range(n):
			if i % 2 == 0:
				tb += b[i]
			else:
				tb += a[i]
		return min(ta, tb)


class Solution:

	def minTime(self, a, b, n):
		s = 0
		s1 = 0
		for i in range(n):
			if i % 2 == 0:
				s += a[i]
				s1 += b[i]
			else:
				s1 += a[i]
				s += b[i]
		return min(s, s1)


class Solution:

	def minTime(self, a, b, n):
		ans = 0
		ans1 = 0
		ans2 = 0
		ans3 = 0
		if a:
			for i in range(n):
				if i % 2 == 0:
					ans += a[i]
				if i % 2 != 0:
					ans1 += b[i]
		d = ans + ans1
		if b:
			for i in range(n):
				if i % 2 == 0:
					ans2 += b[i]
				if i % 2 != 0:
					ans3 += a[i]
		z = ans2 + ans3
		return min(d, z)


class Solution:

	def minTime(self, a, b, n):
		time_a = 0
		time_b = 0
		for i in range(n):
			if i % 2 == 0:
				time_a += a[i]
				time_b += b[i]
			else:
				time_a += b[i]
				time_b += a[i]
		return min(time_a, time_b)