Problem:
Problem A: Equal Total Scores Taro and Hanako have numbers of cards in their hands.  
Each of the cards has a score on it.
Taro and Hanako wish to make the total scores of their cards equal
by exchanging one card in one's hand with one card in the other's hand.
Which of the cards should be exchanged with which? Note that they have to exchange their
cards even if they already have cards of the same total score. Input The input consists of a number of datasets. 
Each dataset is formatted as follows.   n  m  s 1   s 2  ...  s n   s n +1   s n +2  ...  s n + m     The first line of a dataset contains two numbers n and m delimited by a space, where n is the number of cards that Taro has
and m is the number of cards that Hanako has. 
The subsequent n + m lines 
list the score for each of the cards,
one score per line. The first n scores
(from s 1 up to s n )
are the scores of Taro's cards 
and the remaining m scores 
(from s n +1 up to s n + m )
are Hanako's. The numbers n and m are positive integers no greater than 100.  Each score
is a non-negative integer no greater than 100. The end of the input is indicated by a line containing two zeros delimited
by a single space. Output For each dataset, output a single line containing two numbers delimited
by a single space, where the first number is the score of the card Taro
gives to Hanako and the second number is the score of the card Hanako gives
to Taro. 
If there is more than one way to exchange a pair of cards
that makes the total scores equal, 
output a pair of scores whose sum is the smallest. In case no exchange can make the total scores equal, output a
single line containing solely -1.
The output must not contain any superfluous characters
that do not conform to the format. Sample Input 2 2
1
5
3
7
6 5
3
9
5
2
3
3
12
2
7
3
5
4 5
10
0
3
8
1
9
6
0
6
7 4
1
1
2
1
2
1
4
2
3
4
3
2 3
1
1
2
2
2
0 0 Output for the Sample Input 1 3
3 5
-1
2 2
-1

Solution (Python):
while 1:
    n,m=map(int,input().split())
    if n==m==0:break
    taro=[]
    hana=[]
    for i in range(n):taro.append(int(input()))
    for i in range(m):hana.append(int(input()))
    s_t=sum(taro)
    s_h=sum(hana)
    if (s_t+s_h)%2==1:print(-1)
    else:
        if s_t==s_h:
            taro.sort()
            for i in taro:
                if i in hana:
                    print(i,i)
                    break
            else:print(-1)
        elif s_t>s_h:
            i=(s_t-s_h)//2
            hana.sort()
            for j in hana:
                if i+j in taro:
                    print(i+j,j)
                    break
            else:print(-1)
        elif s_t<s_h:
            i=(s_h-s_t)//2
            taro.sort()
            for j in taro:
                if i+j in hana:
                    print(j,i+j)
                    break
            else:print(-1)

Solution (Python):
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
        
    t = [int(input()) for i in range(n)]
    h = [int(input()) for i in range(m)]

    t_sum = sum(t)
    h_sum = sum(h)

    ans_sum = 10e9
    ans = [0, 0]
    for ti in t:
        for hi in h:
            if t_sum - ti + hi == h_sum - hi + ti and ti + hi < ans_sum:
                ans_sum = ti + hi
                ans = [ti, hi]

    if ans == [0, 0]:
        print(-1)
    else:
        print(ans[0], ans[1])

Solution (Python):
while True:
  n, m = map(int, input().split())
  if n == 0:
    break
  a = [int(input()) for _ in range(n)]
  b = [int(input()) for _ in range(m)]
  a.sort
  b.sort
  suma = sum(a)
  sumb = sum(b)
 
  def change():
    for i in a:
      for j in b:
        if(i-j) * 2 == suma - sumb:
          print(i, j)
          return
    print(-1)
  
  change()

Solution (Python):

while 1:
    n,m=map(int,input().split())
    if n==0:
        break
    taro=[]
    hana=[]
    for i in range(n):
        taro.append(int(input()))
    for i in range(m):
        hana.append(int(input()))
    t_sum=sum(taro)
    h_sum=sum(hana)
    d=t_sum-h_sum
    mn=99999999
    ans=[-1]
    for i in range(n):
        for j in range(m):
            if (t_sum-taro[i]+hana[j])==(h_sum-hana[j]+taro[i]):
                if mn>taro[i]+hana[j]:
                    mn=taro[i]+hana[j]
                    ans=(taro[i],hana[j])
    print(*ans)

Solution (Python):
def solve(a, b):
    a.sort()
    b.sort()
    d = sum(a) - sum(b)
    if d % 2 != 0:
        return -1
    for x in a:
        for y in b:
            if x - y == d/2:
                return " ".join(map(str,[x, y]))
            if x - y <  d/2:
                break
    return -1

while True:
    n, m = map(int, raw_input().split())
    if n == 0 and m == 0:
        break
    s = [int(raw_input()) for _ in range(n+m)]
    
    print solve(s[:n], s[n:])