Problem: 2050C - Uninteresting Number
Language: java

Solution 1 (runtime: 249 ms):

// /* Jai Guru Dev*/
// /*सब सुख लहै तुम्हारी सरना ।
// तुम रक्षक काहू को डरना ॥*/
// /*Don't cry in a corner, if you want something, mehnat kar, best ban, aur cheen le.*/
// //Modulus properties
// //1 (a+b)%y = (a%y+b%y)%y also 
// // <if to find pairs st (a+b)%y==0 one is (a%y) and other is b%y==((y-(a%y))%y)> 
// // < if (a+b)%y == (c+b)%y  then a%y = c%y (in  terms of remainder) >
// // 2 (a-b)%y = (a%y-b%y+y)%y also  
// //   < if (a-b)%y ==0 then a%y = b%y  >
// import java.io.BufferedReader;
// import java.io.InputStream;
// import java.io.InputStreamReader;
// import java.io.IOException;
// import java.util.StringTokenizer;
// import java.util.LinkedList;
// import java.util.Arrays;
// import java.util.*;

// /*
// learnings
// so the max value of the arrange ment (a[0]-a[1])+(a[1]-a[2])......(a[n-2]-a[n-1]) = Max(a)-Min(a)
// */
// public class one {

//     static final int INF = Integer.MAX_VALUE;
//     static final long MOD = 1000000007;

//     static class FastScanner {
//         BufferedReader br;
//         StringTokenizer st;

//         FastScanner(InputStream is) {
//             br = new BufferedReader(new InputStreamReader(is));
//         }

//         String next() {
//             while (st == null || !st.hasMoreTokens()) {
//                 try {
//                     st = new StringTokenizer(br.readLine());
//                 } catch (IOException e) {
//                     e.printStackTrace();
//                 }
//             }
//             return st.nextToken();
//         }

//         int nextInt() {
//             return Integer.parseInt(next());
//         }

//         long nextLong() {
//             return Long.parseLong(next());
//         }

//         double nextDouble() {
//             return Double.parseDouble(next());
//         }

//         String nextLine() {
//             String str = "";
//             try {
//                 str = br.readLine();
//             } catch (IOException e) {
//                 e.printStackTrace();
//             }
//             return str;
//         }
//     }

//     static class Graph {
//         int V;
//         LinkedList<Integer>[] adjList;

//         @SuppressWarnings("unchecked")
//         Graph(int V) {
//             this.V = V;
//             adjList = new LinkedList[V];
//             for (int i = 0; i < V; i++)
//                 adjList[i] = new LinkedList<>();
//         }

//         void addEdge(int u, int v) {
//             adjList[u].add(v);
//         }

//         // Add more graph algorithms as needed
//     }

//     static class DSU {
//         int[] parent;
//         int[] rank;

//         DSU(int n) {
//             parent = new int[n];
//             rank = new int[n];
//             for (int i = 0; i < n; i++) {
//                 parent[i] = i;
//                 rank[i] = 0;
//             }
//         }

//         int find(int x) {
//             if (parent[x] != x)
//                 parent[x] = find(parent[x]);
//             return parent[x];
//         }

//         void union(int x, int y) {
//             int xRoot = find(x);
//             int yRoot = find(y);
//             if (xRoot == yRoot)
//                 return;
//             if (rank[xRoot] < rank[yRoot])
//                 parent[xRoot] = yRoot;
//             else if (rank[xRoot] > rank[yRoot])
//                 parent[yRoot] = xRoot;
//             else {
//                 parent[yRoot] = xRoot;
//                 rank[xRoot]++;
//             }
//         }
//     }

//     static int gcd(int a, int b) {
//         while (b != 0) {
//             int temp = b;
//             b = a % b;
//             a = temp;
//         }
//         return a;
//     }

//     static long gcd(long a, long b) {
//         while (b != 0) {
//             long temp = b;
//             b = a % b;
//             a = temp;
//         }
//         return a;
//     }

//     static long power(long x, long y, long p) {
//         long res = 1;
//         x = x % p;

//         while (y > 0) {
//             if (y % 2 == 1)
//                 res = (res * x) % p;
//             y = y >> 1;
//             x = (x * x) % p;
//         }
//         return res;
//     }

//     static boolean[] sieveOfEratosthenes(int n) {
//         boolean[] prime = new boolean[n + 1];
//         Arrays.fill(prime, true);
//         prime[0] = prime[1] = false;
//         for (int p = 2; p * p <= n; p++) {
//             if (prime[p]) {
//                 for (int i = p * p; i <= n; i += p)
//                     prime[i] = false;
//             }
//         }
//         return prime;
//     }

//     // jai guru dev
//     static class Pair {
//         int x;
//         int y;

//         Pair(int x, int y) {
//             this.x = x;
//             this.y = y;
//         }
//     }

//     public static void main(String[] args) {
//         FastScanner sc = new FastScanner(System.in);
//         int t = sc.nextInt();
//         while (t-- > 0) {
//             int n = sc.nextInt();
//             int a[] = new int[n];
//             for (int i = 0; i < n; i++) {
//                 a[i] = sc.nextInt();
//             }
//             Arrays.sort(a);
//             int ans = 0;
//             long pref[] = new long[n];
//             pref[0] = a[0];
//             for (int i = 1; i < n; i++) {
//                 pref[i] = pref[i - 1] + a[i];
//             }
//             int i = 0;
//             int j = n - 1;
//             long x = 0;
//             long c = 0;
//             long ss = 0;
//             long ops = 0;
//             while (i <= j) {
//                 int si = i;

//                 while (i < j && ss + a[i] <= a[j]) {
//                     ss += a[i];
//                     i++;
//                 }

//                 if (ss == a[j]) {
//                     ops += a[j];
//                     ops++;
//                     ss = 0;
//                     j--;
//                     continue;
//                 }
//                 if (i == j) {
//                     if(ss==0){
//                         ops+=a[j];
//                         j--;
//                         break;
//                     }
//                     int s = 0;
//                     int e = a[i];
//                     // System.out.println(ss + " " + a[i]);
//                     long aa = -1;
//                     while (s <= e) {
//                         int mid = (s + e) / 2;
//                         if (ss + mid >= a[j] - mid) {
//                             aa = mid;
//                             e = mid - 1;
//                         } else {
//                             s = mid + 1;
//                         }
//                     }
//                     ops += (ss + aa);
//                     ops++;
//                     a[i] -= aa;
//                     i++;
//                     ss = 0;
//                     j--;
//                     break;
//                 }
//                 int s = 0;
//                 int e = a[i];
//                 long aa = -1;
//                 while (s <= e) {
//                     int mid = (s + e) / 2;
//                     if (ss + mid >= a[j]) {
//                         aa = mid;
//                         e = mid - 1;
//                     } else {
//                         s = mid + 1;
//                     }
//                 }
//                 ops += (ss + aa);
//                 // System.out.println(aa);
//                 ops++;
//                 a[i] -= aa;

//                 ss = 0;
//                 j--;
//             }
//             System.out.println(ops);
//         }
//     }
// }
// // 5
// // 6 6 6 6 4

/* Jai Guru Dev*/
/*सब सुख लहै तुम्हारी सरना ।
तुम रक्षक काहू को डरना ॥*/
/*Don't cry in a corner, if you want something, mehnat kar, best ban, aur cheen le.*/
//Modulus properties
//1 (a+b)%y = (a%y+b%y)%y also 
// <if to find pairs st (a+b)%y==0 one is (a%y) and other is b%y==((y-(a%y))%y)> 
// < if (a+b)%y == (c+b)%y  then a%y = c%y (in  terms of remainder) >
// 2 (a-b)%y = (a%y-b%y+y)%y also  
//   < if (a-b)%y ==0 then a%y = b%y  >
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.LinkedList;
import java.util.Arrays;
import java.util.*;

/*
learnings
so the max value of the arrange ment (a[0]-a[1])+(a[1]-a[2])......(a[n-2]-a[n-1]) = Max(a)-Min(a)
*/
public class one {

    static final int INF = Integer.MAX_VALUE;
    static final long MOD = 1000000007;

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static class Graph {
        int V;
        LinkedList<Integer>[] adjList;

        @SuppressWarnings("unchecked")
        Graph(int V) {
            this.V = V;
            adjList = new LinkedList[V];
            for (int i = 0; i < V; i++)
                adjList[i] = new LinkedList<>();
        }

        void addEdge(int u, int v) {
            adjList[u].add(v);
        }

        // Add more graph algorithms as needed
    }

    static class DSU {
        int[] parent;
        int[] rank;

        DSU(int n) {
            parent = new int[n];
            rank = new int[n];
            for (int i = 0; i < n; i++) {
                parent[i] = i;
                rank[i] = 0;
            }
        }

        int find(int x) {
            if (parent[x] != x)
                parent[x] = find(parent[x]);
            return parent[x];
        }

        void union(int x, int y) {
            int xRoot = find(x);
            int yRoot = find(y);
            if (xRoot == yRoot)
                return;
            if (rank[xRoot] < rank[yRoot])
                parent[xRoot] = yRoot;
            else if (rank[xRoot] > rank[yRoot])
                parent[yRoot] = xRoot;
            else {
                parent[yRoot] = xRoot;
                rank[xRoot]++;
            }
        }
    }

    static int gcd(int a, int b) {
        while (b != 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    static long gcd(long a, long b) {
        while (b != 0) {
            long temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    static long power(long x, long y, long p) {
        long res = 1;
        x = x % p;

        while (y > 0) {
            if (y % 2 == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    static boolean[] sieveOfEratosthenes(int n) {
        boolean[] prime = new boolean[n + 1];
        Arrays.fill(prime, true);
        prime[0] = prime[1] = false;
        for (int p = 2; p * p <= n; p++) {
            if (prime[p]) {
                for (int i = p * p; i <= n; i += p)
                    prime[i] = false;
            }
        }
        return prime;
    }

    static long sumofdigits(String s) {
        long sum = 0;
        for (int i = 0; i < s.length(); i++) {
            sum += s.charAt(i) - '0';
        }
        return sum;
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            String s = sc.next();
            long sum = sumofdigits(s);
            int f2 = 0;
            int f3 = 0;
            for (int i = 0; i < s.length(); i++) {
                if ((s.charAt(i) - '0') == 2) {
                    f2++;
                }
                if ((s.charAt(i) - '0') == 3) {
                    f3++;
                }
            }
            if (f2 == 0 && f3 == 0) {
                if (sum % 9 == 0) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
            } else {
                long val = (sum) % 9;
                // System.out.println(val);
                if (val == 0) {
                    System.out.println("YES");
                } else if (val == 1) {
                    if (f2 >= 4) {
                        System.out.println("YES");
                    } else if (f3 >= 1 && f2 >= 1) {
                        System.out.println("YES");
                    } else {
                        System.out.println("NO");
                    }
                } else if (val == 2) {
                    if (f2 >= 8) {
                        System.out.println("YES");
                    }
                    else if (f3 >= 1 && f2 >= 5) {
                        System.out.println("YES");
                    }
                    else if(f3>=2&&f2>=2){
                        System.out.println("YES");
                    }
                    else {
                        System.out.println("NO");
                    }
                } else if (val == 3) {
                    if (f3 >= 1) {
                        System.out.println("YES");
                    } else if (f2 >= 3) {
                        System.out.println("YES");
                    } else {
                        System.out.println("NO");
                    }
                } else if (val == 4) {
                    if (f2 >= 7) {
                        System.out.println("YES");
                    } else if (f3 >= 2 && f2 >= 1) {
                        System.out.println("YES");
                    } else if (f2 >= 4 && f3 >= 1) {
                        System.out.println("YES");
                    } else {
                        System.out.println("NO");
                    }
                } else if (val == 5) {
                    if (f2 >= 2) {
                        System.out.println("YES");
                    } else {
                        System.out.println("NO");
                    }
                } else if (val == 6) {
                    if (f2 >= 6) {
                        System.out.println("YES");
                    } else if (f3 >= 2) {
                        System.out.println("YES");
                    } else if (f2 >= 3 && f3 >= 1) {
                        System.out.println("YES");
                    } else {
                        System.out.println("NO");
                    }
                } else if (val == 7) {
                    if (f2 >= 1) {
                        System.out.println("YES");
                    } else {
                        System.out.println("NO");
                    }
                } else if (val == 8) {
                    if (f2 >= 2 && f3 >= 1) {
                        System.out.println("YES");
                    } else if (f2 >= 5) {
                        System.out.println("YES");
                    } else {
                        System.out.println("NO");

                    }
                }
            }
        }
    }
}


Solution 2 (runtime: 171 ms):
import java.util.*;
import java.io.*;

public class Main

{
	static FastReader sc = new FastReader();
	static int dp[][];
	// static boolean v[][][];
	// static int mod=998244353;;
	static int mod = 1000000007;
	static long max;
	static int bit[];
	static int bit1[];
	static int cnt;
	static PrintWriter out = new PrintWriter(System.out);
	static long aa=-1;
	static long bb=-1;

	@SuppressWarnings("unused")
	public static void main(String[] args) {
		// StringBuffer sb=new StringBuffer("");
		int ttt = 1;
		ttt = i();
		outer: while (ttt-- > 0) {
			char B[]=s().toCharArray();
			int n=B.length;
			int A[]=new int[n];
			for(int i=0;i<n;i++){
				A[i]=B[i]-'0';
			}
			int sum=0;
			int a=0;
			int b=0;
			for(int i : A){
				sum+=i;
				if(i==2){
					a++;
				}
				if(i==3)
				b++;
			}
			int ans=0;
			for(int i=0;i<=b;i++){
				int temp = sum+(i*6)%9;
				temp%=9;
				for(int j=0;j<=min(a,10);j++){
					int y=temp+(j*2)%9;
					y%=9;
					if(y==0){
						ans=1;
					}
				}
			}
			System.out.println(ans==1?"YES":"NO");
			
			







		}
		// System.out.println(sb.toString());
		out.close();

		// CHECK FOR N=1 //CHECK FOR M=0
		// CHECK FOR N=1 //CHECK FOR M=0
		// CHECK FOR N=1

	}
	
	

	    
	static class Pair implements Comparable<Pair> {
		int x;
		int y;
		int z;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;

		}

		@Override
		public int compareTo(Pair o) {
			if (this.x > o.x)
				return 1;
			else if (this.x < o.x)
				return -1;
			else {
				if (this.y > o.y)
					return 1;
				else if (this.y < o.y)
					return -1;
				else
					return 0;
			}
		}

		public int hashCode() {
			long ans = 1;
			ans = x * 31 + y * 13;
			return (int) ans;
		}

		// @Override
		public boolean equals(Object o) {
			if (this == o) {
				return true;
			}
			if (o == null) {
				return false;
			}
			if (this.getClass() != o.getClass()) {
				return false;
			}
			Pair other = (Pair) o;
			if (this.x != other.x || this.y != other.y) {
				return false;
			}
			return true;
		}
		//
		/* FOR TREE MAP PAIR USE */

		// public int compareTo(Pair o) {
		// if (x > o.x) {
		// return 1;
		// }
		// if (x < o.x) {
		// return -1;
		// }
		// if (y > o.y) {
		// return 1;
		// }
		// if (y < o.y) {
		// return -1;
		// }
		// return 0;
		// }

	}

	// static int find(int A[],int a) {
	// if(A[a]==a)
	// return a;
	// return A[a]=find(A, A[a]);
	// }
	// FENWICK TREE
	static void update(int i, int x) {
		for (; i < bit.length; i += (i & -i))
			bit[i] += x;
	}

	static int sum(int i) {
		int ans = 0;
		for (; i > 0; i -= (i & -i))
			ans += bit[i];
		return ans;
	}

	// END
	static void add(HashMap<Long, Integer> map, long v) {
		if (!map.containsKey(v)) {
			map.put(v, 1);
		} else {
			map.put(v, map.get(v) + 1);
		}
	}

	static void remove(HashMap<Long, Integer> map, long v) {
		if (map.containsKey(v)) {
			map.put(v, map.get(v) - 1);
			if (map.get(v) == 0)
				map.remove(v);
		}
	}

	static void add(HashMap<Integer, Integer> map, int v) {
		if (!map.containsKey(v)) {
			map.put(v, 1);
		} else {
			map.put(v, map.get(v) + 1);
		}
	}

	static void remove(HashMap<Integer, Integer> map, int v) {
		if (map.containsKey(v)) {
			map.put(v, map.get(v) - 1);
			if (map.get(v) == 0)
				map.remove(v);
		}
	}

	static void add(TreeMap<Integer, Integer> map, int v) {
		if (!map.containsKey(v)) {
			map.put(v, 1);
		} else {
			map.put(v, map.get(v) + 1);
		}
	}

	static void add(TreeMap<Long, Integer> map, long v) {
		if (!map.containsKey(v)) {
			map.put(v, 1);
		} else {
			map.put(v, map.get(v) + 1);
		}
	}

	static void remove(TreeMap<Integer, Integer> map, int v) {
		if (map.containsKey(v)) {
			map.put(v, map.get(v) - 1);
			if (map.get(v) == 0)
				map.remove(v);
		}
	}

	static void remove(TreeMap<Long, Integer> map, long v) {
		if (map.containsKey(v)) {
			map.put(v, map.get(v) - 1);
			if (map.get(v) == 0)
				map.remove(v);
		}
	}

	static long modInverse(long n, int p) {
		return power(n, p - 2, p);
	}

	static int[] copy(int A[]) {
		int B[] = new int[A.length];
		for (int i = 0; i < A.length; i++) {
			B[i] = A[i];
		}
		return B;
	}

	static long[] copy(long A[]) {
		long B[] = new long[A.length];
		for (int i = 0; i < A.length; i++) {
			B[i] = A[i];
		}
		return B;
	}

	static int[] input(int n) {
		int A[] = new int[n];
		for (int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}
		return A;
	}

	static long[] inputL(int n) {
		long A[] = new long[n];
		for (int i = 0; i < n; i++) {
			A[i] = sc.nextLong();
		}
		return A;
	}

	static String[] inputS(int n) {
		String A[] = new String[n];
		for (int i = 0; i < n; i++) {
			A[i] = sc.next();
		}
		return A;
	}

	static long sum(int A[]) {
		long sum = 0;
		for (int i : A) {
			sum += i;
		}
		return sum;
	}

	static long sum(long A[]) {
		long sum = 0;
		for (long i : A) {
			sum += i;
		}
		return sum;
	}

	static void reverse(long A[]) {
		int n = A.length;
		long B[] = new long[n];
		for (int i = 0; i < n; i++) {
			B[i] = A[n - i - 1];
		}
		for (int i = 0; i < n; i++)
			A[i] = B[i];

	}

	static void reverse(int A[]) {
		int n = A.length;
		int B[] = new int[n];
		for (int i = 0; i < n; i++) {
			B[i] = A[n - i - 1];
		}
		for (int i = 0; i < n; i++)
			A[i] = B[i];

	}

	static void input(int A[], int B[]) {
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
		}
	}

	static int[][] input(int n, int m) {
		int A[][] = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				A[i][j] = i();
			}
		}
		return A;
	}

	static char[][] charinput(int n, int m) {
		char A[][] = new char[n][m];
		for (int i = 0; i < n; i++) {
			String s = s();
			for (int j = 0; j < m; j++) {
				A[i][j] = s.charAt(j);
			}
		}
		return A;
	}

	static int nextPowerOf2(int n) {
		if (n == 0)
			return 1;
		n--;
		n |= n >> 1;
		n |= n >> 2;
		n |= n >> 4;
		n |= n >> 8;
		n |= n >> 16;
		n++;

		return n;
	}

	static int highestPowerof2(int x) {

		x |= x >> 1;
		x |= x >> 2;
		x |= x >> 4;
		x |= x >> 8;
		x |= x >> 16;

		return x ^ (x >> 1);

	}

	static long highestPowerof2(long x) {

		x |= x >> 1;
		x |= x >> 2;
		x |= x >> 4;
		x |= x >> 8;
		x |= x >> 16;
		return x ^ (x >> 1);

	}

	static int max(int A[]) {
		int max = Integer.MIN_VALUE;
		for (int i = 0; i < A.length; i++) {
			max = Math.max(max, A[i]);
		}
		return max;
	}

	static int min(int A[]) {
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < A.length; i++) {
			min = Math.min(min, A[i]);
		}
		return min;
	}

	static long max(long A[]) {
		long max = Long.MIN_VALUE;
		for (int i = 0; i < A.length; i++) {
			max = Math.max(max, A[i]);
		}
		return max;
	}

	static long min(long A[]) {
		long min = Long.MAX_VALUE;
		for (int i = 0; i < A.length; i++) {
			min = Math.min(min, A[i]);
		}
		return min;
	}

	static long[] prefix(long A[]) {
		long p[] = new long[A.length];
		p[0] = A[0];
		for (int i = 1; i < A.length; i++)
			p[i] = p[i - 1] + A[i];
		return p;
	}

	static long[] prefix(int A[]) {
		long p[] = new long[A.length];
		p[0] = A[0];
		for (int i = 1; i < A.length; i++)
			p[i] = p[i - 1] + A[i];
		return p;
	}

	static long[] suffix(long A[]) {
		long p[] = new long[A.length];
		p[A.length - 1] = A[A.length - 1];
		for (int i = A.length - 2; i >= 0; i--)
			p[i] = p[i + 1] + A[i];
		return p;
	}

	static long[] suffix(int A[]) {
		long p[] = new long[A.length];
		p[A.length - 1] = A[A.length - 1];
		for (int i = A.length - 2; i >= 0; i--)
			p[i] = p[i + 1] + A[i];
		return p;
	}

	static void fill(int dp[]) {
		Arrays.fill(dp, -1);
	}

	static void fill(int dp[][]) {
		for (int i = 0; i < dp.length; i++)
			Arrays.fill(dp[i], -1);
	}

	static void fill(int dp[][][]) {
		for (int i = 0; i < dp.length; i++) {
			for (int j = 0; j < dp[0].length; j++) {
				Arrays.fill(dp[i][j], -1);
			}
		}
	}

	static void fill(int dp[][][][]) {
		for (int i = 0; i < dp.length; i++) {
			for (int j = 0; j < dp[0].length; j++) {
				for (int k = 0; k < dp[0][0].length; k++) {
					Arrays.fill(dp[i][j][k], -1);
				}
			}
		}
	}

	static void fill(long dp[]) {
		Arrays.fill(dp, -1);
	}

	static void fill(long dp[][]) {
		for (int i = 0; i < dp.length; i++)
			Arrays.fill(dp[i], -1);
	}

	static void fill(long dp[][][]) {
		for (int i = 0; i < dp.length; i++) {
			for (int j = 0; j < dp[0].length; j++) {
				Arrays.fill(dp[i][j], -1);
			}
		}
	}

	static void fill(long dp[][][][]) {
		for (int i = 0; i < dp.length; i++) {
			for (int j = 0; j < dp[0].length; j++) {
				for (int k = 0; k < dp[0][0].length; k++) {
					Arrays.fill(dp[i][j][k], -1);
				}
			}
		}
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static int min(int a, int b, int c) {
		return Math.min(a, Math.min(b, c));
	}

	static int min(int a, int b, int c, int d) {
		return Math.min(a, Math.min(b, Math.min(c, d)));
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static int max(int a, int b, int c) {
		return Math.max(a, Math.max(b, c));
	}

	static int max(int a, int b, int c, int d) {
		return Math.max(a, Math.max(b, Math.max(c, d)));
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}

	static long min(long a, long b, long c) {
		return Math.min(a, Math.min(b, c));
	}

	static long min(long a, long b, long c, long d) {
		return Math.min(a, Math.min(b, Math.min(c, d)));
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static long max(long a, long b, long c) {
		return Math.max(a, Math.max(b, c));
	}

	static long max(long a, long b, long c, long d) {
		return Math.max(a, Math.max(b, Math.max(c, d)));
	}

	static long power(long x, long y, long p) {

		if (y == 0)
			return 1;
		if (x == 0)
			return 0;
		long res = 1;
		x = x % p;

		while (y > 0) {

			if (y % 2 == 1)
				res = (res * x) % p;

			y = y >> 1;
			x = (x * x) % p;
		}

		return res;
	}

	static long power(long x, long y) {

		if (y == 0)
			return 1;
		if (x == 0)
			return 0;
		long res = 1;

		while (y > 0) {

			if (y % 2 == 1)
				res = (res * x);

			y = y >> 1;
			x = (x * x);
		}

		return res;
	}

	static void print(int A[]) {
		for (int i : A) {
			out.print(i + " ");
		}
		out.println();
	}

	static void print(long A[]) {
		for (long i : A) {
			System.out.print(i + " ");
		}
		System.out.println();
	}

	static long mod(long x) {
		return ((x % mod + mod) % mod);
	}

	static String reverse(String s) {
		StringBuffer p = new StringBuffer(s);
		p.reverse();
		return p.toString();
	}

	static int i() {
		return sc.nextInt();
	}

	static String s() {
		return sc.next();
	}

	static long l() {
		return sc.nextLong();
	}

	static void sort(int[] A) {
		int n = A.length;
		Random rnd = new Random();
		for (int i = 0; i < n; ++i) {
			int tmp = A[i];
			int randomPos = i + rnd.nextInt(n - i);
			A[i] = A[randomPos];
			A[randomPos] = tmp;
		}
		Arrays.sort(A);
	}

	static void sort(long[] A) {
		int n = A.length;
		Random rnd = new Random();
		for (int i = 0; i < n; ++i) {
			long tmp = A[i];
			int randomPos = i + rnd.nextInt(n - i);
			A[i] = A[randomPos];
			A[randomPos] = tmp;
		}
		Arrays.sort(A);
	}

	static String sort(String s) {
		Character ch[] = new Character[s.length()];
		for (int i = 0; i < s.length(); i++) {
			ch[i] = s.charAt(i);
		}
		Arrays.sort(ch);
		StringBuffer st = new StringBuffer("");
		for (int i = 0; i < s.length(); i++) {
			st.append(ch[i]);
		}
		return st.toString();
	}

	static HashMap<Integer, Integer> hash(int A[]) {
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for (int i : A) {
			if (map.containsKey(i)) {
				map.put(i, map.get(i) + 1);
			} else {
				map.put(i, 1);
			}
		}
		return map;
	}

	static HashMap<Long, Integer> hash(long A[]) {
		HashMap<Long, Integer> map = new HashMap<Long, Integer>();
		for (long i : A) {
			if (map.containsKey(i)) {
				map.put(i, map.get(i) + 1);
			} else {
				map.put(i, 1);
			}
		}
		return map;
	}

	static TreeMap<Integer, Integer> tree(int A[]) {
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for (int i : A) {
			if (map.containsKey(i)) {
				map.put(i, map.get(i) + 1);
			} else {
				map.put(i, 1);
			}
		}
		return map;
	}

	static TreeMap<Long, Integer> tree(long A[]) {
		TreeMap<Long, Integer> map = new TreeMap<Long, Integer>();
		for (long i : A) {
			if (map.containsKey(i)) {
				map.put(i, map.get(i) + 1);
			} else {
				map.put(i, 1);
			}
		}
		return map;
	}

	static boolean prime(int n) {
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;
		if (n % 2 == 0 || n % 3 == 0)
			return false;
		double sq = Math.sqrt(n);

		for (int i = 5; i <= sq; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;
		return true;
	}

	static boolean prime(long n) {
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;
		if (n % 2 == 0 || n % 3 == 0)
			return false;
		double sq = Math.sqrt(n);

		for (int i = 5; i <= sq; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;
		return true;
	}

	static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}