Under construction

Still being built. Things may change

Finding matching pairs

Time limit2sMemory limit512 MB

Summary
Given 2 to 10 integers and a target, print every position pair that sums to the target in lexicographic order, then the count.
Level

Easy3 of 10

Topics
Sorting, Brute force, Implementation
Solved
No attempts yet

Problem

The first line holds several integers and the second line holds one target value. Print every pair of numbers that sit at two different positions and sum to the target value, then print the number of such pairs on the last line.

Input

The first line has 2 to 10 integers separated by spaces. The second line has one integer, the target value. Every integer given is a natural number not greater than 100,000.

Output

Print one pair per line, then print the number of pairs on the last line.

Print a pair as aa and bb in that order on one line, with a≤ba \le b. The pairs (a,b)(a, b) and (b,a)(b, a) have the same composition and count as one pair.

Pairs are counted by position. Print one line for each choice of two different positions i<ji < j that meets the condition, and count each choice separately even when an identical pair of values was already printed. For the input 1 1 2 with target value 33, print (1,2)(1, 2) on two lines and print the count 22.

When several pairs exist, print them in lexicographic order. (a,b)(a, b) comes before (c,d)(c, d) when a<ca < c, or when a=ca = c and b<db < d.

When no pair meets the condition, print only the count 00.

Examples3

  1. Example 1

    Input
    1 2
    3
    
    Expected output
    1 2
    1
    
  2. Example 2

    Input
    1 2 3
    100
    
    Expected output
    0
    
  3. Example 3

    Input
    1 2 3 4 5
    6
    
    Expected output
    1 5
    2 4
    2