#K58032. Count Pairs With Sum

    ID: 30552 Type: Default 1000ms 256MiB

Count Pairs With Sum

Count Pairs With Sum

You are given two arrays A and B, each containing N integers, and a target integer X. Your task is to count the number of ordered pairs (i, j) (with 0-based indexing) such that:

\( A_i + B_j = X \)

The problem tests your ability to implement simple nested iterations (or more efficient methods) to determine the count of all valid pairs. Note that the arrays can contain duplicate values and each occurrence is considered distinct.

inputFormat

The input is read from stdin and has the following format:

  1. First line: an integer N, the number of elements in each array.
  2. Second line: N space-separated integers representing array A.
  3. Third line: N space-separated integers representing array B.
  4. Fourth line: an integer X, the target sum.

outputFormat

Output a single integer to stdout representing the number of pairs (i, j) such that \( A_i + B_j = X \).

## sample
4
1 2 3 4
5 2 2 1
6
3