using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
int[] v = new int[] {2, 1, 8, 4, 7, 3};
test(v, 3);
test(v, 20);
test(v, 1);
test(v, 2);
test(v, 7);
}
static void test(int[] v, int val)
bool output = find_sum_of_two(v, val);
Console.WriteLine("exists(A, " + val + ") = " + output);
static bool find_sum_of_two(int[] A, int val)
HashSet<int> found_values = new HashSet<int>();
for(int i=0; i < A.Length; i++)
if(found_values.Contains(val - A[i]))
return true;
found_values.Add(A[i]);
return false;