Problem:
Score : 100 points

Problem Statement

On the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.

You are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.

Constraints

b is one of the letters A, C, G and T.

Input

Input is given from Standard Input in the following format:

b

Output

Print the letter representing the base that bonds with the base b.

Sample Input 1

A

Sample Output 1

T

Sample Input 2

G

Sample Output 2

C

Solution in Java (OpenJDK 11.0.6) (judge verdict: Wrong Answer)

import java.util.*;
public class Main {

	/*
	 * 122B - 2nd Solution
	 * 
	 * For every right end point of a substring, we try to find the farthest left end point 
	 * Done so by having a loop to control the right end point 
	 * And then start going away from the right end point one by one
	 * The first if statement is that if the j-th character is not part of ACGT then we can just stop there because going any further won't produce an AGCT string
	 * The else if statement just means that if all the letters before the right end point (including itself) is part of AGCT then [0 ... i] is a possible AGCT string
	 * 
	 * Time Complexity O(N^2), Memory Complexity O(N)
	 * 
	 */
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int N = s.length();
		int ans = 0;
		for(int i = 0; i<N; i++) {
			for(int j = i; j>=0; j--) {
				if(s.charAt(j) != 'A' && s.charAt(j) != 'C' && s.charAt(j) != 'G' && s.charAt(j) != 'T') {
					ans = Math.max(ans, j - i);
					break;
				}
				else if(i == 0) {
					ans = Math.max(ans, j+1);
				}
			}
		}
		System.out.println(ans);
	}
}