import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.function.BiFunction;
import java.util.function.IntBinaryOperator;
import java.util.function.LongBinaryOperator;
import java.util.stream.*;
// import static java.util.Arrays.compare;
import static java.util.Arrays.fill;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;
import static java.util.Comparator.reverseOrder;
// import static java.util.List.of;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

import java.math.BigInteger;
import static java.math.BigInteger.ZERO;
import static java.math.BigInteger.ONE;
// import static java.math.BigInteger.TWO;
import static java.math.BigInteger.TEN;

import static java.lang.Math.PI;
import static java.lang.Math.E;
import static java.lang.Math.min;
import static java.lang.Math.max;
import static java.lang.Math.abs;
import static java.lang.Math.sin;
import static java.lang.Math.cos;
import static java.lang.Math.tan;
import static java.lang.Math.asin;
import static java.lang.Math.acos;
import static java.lang.Math.atan;
import static java.lang.Math.atan2;
import static java.lang.Math.hypot;
import static java.lang.Math.sqrt;
import static java.lang.Math.log;
import static java.lang.Math.exp;
import static java.lang.String.format;
import static java.lang.System.exit;
import static java.lang.System.currentTimeMillis;

public class Main {
    public static long MOD = 1_000_000_007;

    public static void main(String[] args) {
        FastScanner fsc=new FastScanner();
        char[] s=('+'+fsc.next()).toCharArray();
        char[] t=('*'+fsc.next()).toCharArray();
        int n=s.length;
        int m=t.length;
        fsc.close();
        int[][] dp=new int[n][m];
        int[][][] pre=new int[n][m][2];
        for(int i=1;i<n;i++){
            for(int j=1;j<m;j++){
                if(s[i]==t[j]){
                    dp[i][j]=dp[i-1][j-1]+1;
                    int k=dp[pre[i-1][j-1][0]][pre[i-1][j-1][1]];
                    if(dp[i][j]==k+1){
                        pre[i][j]=pre[i-1][j-1];
                    } else{
                        int[] p={i-1, j-1};
                        pre[i][j]=p;
                    }
                } else{
                    if(dp[i][j-1]>dp[i-1][j]){
                        dp[i][j]=dp[i][j-1];
                        int k=dp[pre[i][j-1][0]][pre[i][j-1][1]];
                        if(dp[i][j-1]==k){
                            pre[i][j]=pre[i][j-1];
                        } else{
                            int[] p={i, j-1};
                            pre[i][j]=p;
                        }
                    } else{
                        dp[i][j]=dp[i-1][j];
                        int k=dp[pre[i-1][j][0]][pre[i-1][j][1]];
                        if(dp[i-1][j]==k){
                            pre[i][j]=pre[i-1][j];
                        } else{
                            int[] p={i-1, j};
                            pre[i][j]=p;
                        }
                    }
                }
            }
        }
        int l=dp[n-1][m-1];
        char[] ans=new char[l];
        int indx=l-1;
        int i=n-1, j=m-1;
        while(i>0 && j>0){
            int[] p=pre[i][j];
            if(s[i]==t[j]){
                ans[indx--]=s[i];
            }
            i=p[0];
            j=p[1];
        }
        StringBuilder sb=new StringBuilder();
        for(char c:ans){
            sb.append(c);
        }
        System.out.println(sb);
    }

    static class IntUtil {
        public static int min(int a, int... b) {
            int ret = a;
            for (int c : b) {
                ret = Math.min(ret, c);
            }
            return ret;
        }

        public static int max(int a, int... b) {
            int ret = a;
            for (int c : b) {
                ret = Math.max(ret, c);
            }
            return ret;
        }

        /**
         * Caluculate the ceil of a/b. Returns the smallest integer greater than or
         * equal to a/b while 'a/b' rounds fractional parts to ZERO.
         *
         * @param a
         * @param b
         * @return the smallest integer greater than or equal to a/b
         */
        public static int ceilDiv(int a, int b) {
            if ((a > 0 && b > 0) || (a < 0 && b < 0)) {
                if (b > 0) {
                    return (a + b - 1) / b;
                } else {
                    return (a + b + 1) / b;
                }
            } else {
                return a / b;
            }
        }

        /**
         * Caluculate the floor of a/b. Returns the largest integer less than or equal
         * to a/b while 'a/b' rounds fractional parts to ZERO.
         *
         * @param a
         * @param b
         * @return the largest integer less than or equal to a/b
         */
        public static int floorDiv(int a, int b) {
            if ((a > 0 && b > 0) || (a < 0 && b < 0)) {
                return a / b;
            } else {
                if (b > 0) {
                    return (a - b + 1) / b;
                } else {
                    return (a - b - 1) / b;
                }
            }
        }

        public static int fold(IntBinaryOperator func, int a, int... b) {
            int ret = a;
            for (int c : b) {
                ret = func.applyAsInt(ret, c);
            }
            return ret;
        }
    }

    static class LongUtil {
        public static long min(long a, long... b) {
            long ret = a;
            for (long c : b) {
                ret = Math.min(ret, c);
            }
            return ret;
        }

        public static long max(long a, long... b) {
            long ret = a;
            for (long c : b) {
                ret = Math.max(ret, c);
            }
            return ret;
        }

        /**
         * Caluculate the ceil of a/b. Returns the smallest integer greater than or
         * equal to a/b while 'a/b' rounds fractional parts to ZERO.
         *
         * @param a
         * @param b
         * @return the smallest integer greater than or equal to a/b
         */
        public static long ceilDiv(long a, long b) {
            if ((a > 0 && b > 0) || (a < 0 && b < 0)) {
                if (b > 0) {
                    return (a + b - 1) / b;
                } else {
                    return (a + b + 1) / b;
                }
            } else {
                return a / b;
            }
        }

        /**
         * Caluculate the floor of a/b. Returns the largest integer less than or equal
         * to a/b while 'a/b' rounds fractional parts to ZERO.
         *
         * @param a
         * @param b
         * @return the largest integer less than or equal to a/b
         */
        public static long floorDiv(long a, long b) {
            if ((a > 0 && b > 0) || (a < 0 && b < 0)) {
                return a / b;
            } else {
                if (b > 0) {
                    return (a - b + 1) / b;
                } else {
                    return (a - b - 1) / b;
                }
            }
        }

        public static long fold(LongBinaryOperator func, long a, long... b) {
            long ret = a;
            for (long c : b) {
                ret = func.applyAsLong(ret, c);
            }
            return ret;
        }
    }

    static class MathUtil{
        /**
         * Enumarate primes less than n.
         *
         * @param n
         * @return {@code ArrayList} that holds primes.
         */
        public static ArrayList<Integer> eratosthenes(int n) {
            int[] div = eratosthenesDivisors(n);
            ArrayList<Integer> result = new ArrayList<>();
            for (int i = 2; i <= n; i++) {
                if (div[i] == i) {
                    result.add(i);
                }
            }
            return result;
        }
        /**
         * execute eratosthenes's prime-enumerate algorithm. a[i] holds the greatest
         * divisor of i. if a[i]=i, i is a prime number. This arrary enables you to
         * prime-factorize in O(log n) time. (<O(sqrt n)).
         *
         * @param n
         * @return divisor array.
         */
        public static int[] eratosthenesDivisors(int n) {
            int[] divisors = new int[n + 1];
            if (n <= 0) {
                return null;
            }
            for (int i = 1; i <= n; i++) {
                if ((i & 1) != 0) {
                    divisors[i] = i;
                } else {
                    divisors[i] = 2;
                }
            }
            for (long i = 3; i <= n; i += 2) {
                if (divisors[(int) i] == (int) i) {
                    for (long j = i * i; j <= n; j += (i << 1)) {
                        divisors[(int) j] = (int) i;
                    }
                }
            }
            return divisors;
        }

        /**
         * Caluculate prime-factorization.
         *
         * @param n
         * @return {@code HashMap} of {prime: index}
         */
        public static HashMap<Long, Integer> primeFactorization(long n) {
            HashMap<Long, Integer> primes = new HashMap<Long, Integer>();
            for (long p = 2; p * p <= n; p++) {
                int q = 0;
                while (n % p == 0) {
                    n /= p;
                    q++;
                }
                if (q > 0) {
                    primes.put(p, q);
                }
            }
            if (n > 1) {
                primes.put(n, 1);
            }
            return primes;
        }

        private static HashMap<Long, Integer> lcm(HashMap<Long, Integer> amap, HashMap<Long, Integer> bmap) {
            if (amap.size() < bmap.size()) {
                return lcm(bmap, amap);
            }
            HashMap<Long, Integer> lcm = amap;
            for (Map.Entry<Long, Integer> e : bmap.entrySet()) {
                long prime = e.getKey();
                if (lcm.containsKey(prime)) {
                    lcm.put(prime, Math.max(lcm.get(prime), e.getValue()));
                } else {
                    lcm.put(prime, e.getValue());
                }
            }
            return lcm;
        }

        private static HashMap<Long, Integer> lcm(HashMap<Long, Integer> amap, long b) {
            HashMap<Long, Integer> bmap = primeFactorization(b);
            return lcm(amap, bmap);
        }

        public static HashMap<Long, Integer> lcm(long a, long... b) {
            HashMap<Long, Integer> amap = primeFactorization(a);
            for (long c : b) {
                amap = lcm(amap, c);
            }
            return amap;
        }
        public static long unsafeLCM(long a, long b) {
            return a * b / gcd(a, b);
        }

        /**
         * Caluculate the GCD of (a, b)/
         *
         * @param a first value
         * @param b second value
         * @return GCD(a, b)
         */
        public static long gcd(long a, long b) {
            if (a < b) {
                return gcd(b, a);
            }
            long r = a % b;
            while (r != 0) {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        /**
         * Return one of the solutions to {@code ax+by=gcd(a, b)}.
         *
         * @return {@code x}, {@code y}, {@code gcd(a, b)}.
         * @param a a of ax+by=gcd(a, b).
         * @param b b of ax+by=gcd(a, b). class ReferenceLong is a reference type of long.
         */
        public static long[] extGCD(long a, long b) {
            ReferenceLong x = new ReferenceLong();
            ReferenceLong y = new ReferenceLong();
            long[] ret = new long[3];
            ret[2] = extGCD(a, b, x, y);
            ret[0] = x.v;
            ret[1] = y.v;
            return ret;
        }

        private static long extGCD(long a, long b, ReferenceLong x, ReferenceLong y) {
            if (b == 0) {
                x.v = 1;
                y.v = 0;
                return a;
            }
            long d = extGCD(b, a % b, y, x);
            y.v -= a / b * x.v;
            return d;
        }

        private static class ReferenceLong {
            long v = 0;
        }
    }

    static class IntArrayUtil{
        public static void reverse(int[] a, int begin, int end){
            for(int i=begin;i<begin+(end-begin)/2;i++){
                swap(a, i, begin+end-i-1);
            }
        }
        public static void reverse(int[] a){
            reverse(a, 0, a.length);
        }
        public static void revSort(int[] a){
            Arrays.sort(a);
            reverse(a);
        }
        public static int[] nextPermutation(int[] a){
            int[] ret=a.clone();
            int n=ret.length;
            for(int i=n-1;i>=1;i--){
                if(ret[i]>ret[i-1]){
                    int fail=n, pass=i;
                    while(fail-pass>1){
                        int mid=pass+(fail-pass)/2;
                        if(ret[mid]>ret[i-1]) pass=mid;
                        else fail=mid;
                    }
                    swap(ret, pass, i-1);
                    reverse(ret, i, n);
                    return ret;
                }
            }
            return null;
        }
        public static int[] predPermutation(int[] a){
            int[] ret=a.clone();
            int n=ret.length;
            for(int i=n-1;i>=1;i--){
                if(ret[i]<ret[i-1]){
                    int fail=n, pass=i;
                    while(fail-pass>1){
                        int mid=pass+(fail-pass)/2;
                        if(ret[mid]<ret[i-1]) pass=mid;
                        else fail=mid;
                    }
                    swap(ret, pass, i-1);
                    reverse(ret, i, n);
                    return ret;
                }
            }
            return null;
        }
        public static void swap(int[] a, int u, int v){
            int tmp=a[u];
            a[u]=a[v];
            a[v]=tmp;
        }
        public static int compare(int[] a, int[] b){
            for(int i=0;i<a.length;i++){
                if(i>=b.length){
                    return -1;
                } else if(a[i]>b[i]){
                    return 1;
                } else if(a[i]<b[i]){
                    return -1;
                }
            }
            if(a.length<b.length){
                return 1;
            } else{
                return 0;
            }
        }
        public static boolean equals(int[] a, int[] b){
            return compare(a, b)==0;
        }
    }

    static class LongArrayUtil{
        public static void reverse(long[] a, int begin, int end){
            for(int i=begin;i<begin+(end-begin)/2;i++){
                long tmp=a[i];
                a[i]=a[begin+end-i-1];
                a[begin+end-i-1]=tmp;
            }
        }
        public static void reverse(long[] a){
            reverse(a, 0, a.length);
        }
        public static void revSort(long[] a){
            Arrays.sort(a);
            reverse(a);
        }
        public static long[] nextPermutation(long[] a){
            long[] ret=a.clone();
            int n=ret.length;
            for(int i=n-1;i>=1;i--){
                if(ret[i]>ret[i-1]){
                    int fail=n, pass=i;
                    while(fail-pass>1){
                        int mid=pass+(fail-pass)/2;
                        if(ret[mid]>ret[i-1]) pass=mid;
                        else fail=mid;
                    }
                    swap(ret, pass, i-1);
                    reverse(ret, i, n);
                    return ret;
                }
            }
            return null;
        }
        public static long[] predPermutation(long[] a){
            long[] ret=a.clone();
            int n=ret.length;
            for(int i=n-1;i>=1;i--){
                if(ret[i]<ret[i-1]){
                    int fail=n, pass=i;
                    while(fail-pass>1){
                        int mid=pass+(fail-pass)/2;
                        if(ret[mid]<ret[i-1]) pass=mid;
                        else fail=mid;
                    }
                    swap(ret, pass, i-1);
                    reverse(ret, i, n);
                    return ret;
                }
            }
            return null;
        }
        public static void swap(long[] a, int u, int v){
            long tmp=a[u];
            a[u]=a[v];
            a[v]=tmp;
        }
        public static int compare(long[] a, long[] b){
            for(int i=0;i<a.length;i++){
                if(i>=b.length){
                    return -1;
                } else if(a[i]>b[i]){
                    return 1;
                } else if(a[i]<b[i]){
                    return -1;
                }
            }
            if(a.length<b.length){
                return 1;
            } else{
                return 0;
            }
        }
        public static boolean equals(long[] a, long[] b){
            return compare(a, b)==0;
        }
    }

    static class ModUtil{
        private static long safeMAX = 100_000_000_000_000_000l;
        public static long modFold(LongBinaryOperator function, long a, long... b) {
            long ret = a;
            for (long c : b) {
                ret = function.applyAsLong(ret, c);
                ret %= MOD;
            }
            return ret;
        }

        public static long modAdd(long a, long... b) {
            long ret = a;
            for (long c : b) {
                if (ret >= safeMAX || ret <= -safeMAX) {
                    ret %= MOD;
                }
                ret += c;
            }
            return ret;
        }

        public static long modMul(long a, long... b) {
            long ret = a;
            for (long c : b) {
                ret *= c;
                ret %= MOD;
            }
            return ret;
        }

        public static long modDiv(long a, long... b) {
            long ret = a;
            for (long c : b) {
                ret *= modinv(c);
                ret %= MOD;
            }
            return ret;
        }

        public static long modSub(long a, long... b) {
            long ret = a;
            for (long c : b) {
                ret -= c;
                if (ret >= safeMAX || ret <= -safeMAX) {
                    ret %= MOD;
                }
            }
            ret %= MOD;
            if (ret < 0) {
                ret += MOD;
            }
            return ret;
        }

        /**
         * Caluculate the value b s.t. a*b mod MOD = 1.
         *
         * @param a
         * @return inverse of a
         */
        public static long modinv(long a) {
            long b = MOD;
            long u = 1, v = 0;
            while (b >= 1) {
                long t = a / b;
                a -= t * b;
                long tmp1 = a;
                a = b;
                b = tmp1;
                u -= t * v;
                long tmp2 = u;
                u = v;
                v = tmp2;
            }
            u %= MOD;
            return u >= 0 ? u : u + MOD;
        }

        /**
         * Caluculate the combination nCr.
         *
         * @param n left
         * @param r right
         * @return nCr
         */
        public static long comb(long n, long r) {
            if (n < r) {
                return 0;
            }
            r = Math.min(r, n - r);
            long res = 1;
            for (long d = 1; d <= r; d++) {
                res *= n;
                res %= MOD;
                n--;
                res *= modinv(d);
                res %= MOD;
            }
            return res;
        }
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

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

        public void close(){
            try{
                in.close();
            } catch(Exception e){
                e.printStackTrace();
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char s[] = br.readLine().toCharArray();
		char t[] = br.readLine().toCharArray();
		br.close();

		int row = t.length;
		int col = s.length;
		int tb[][] = new int[row + 1][col + 1];

		for ( int r = 0; r < row; r++ ) {
			for ( int c = 0; c < col; c++ ) {
				if ( t[r] == s[c] ) {
					tb[r + 1][c + 1] = tb[r][c] + 1;
				} else {
					tb[r + 1][c + 1] = Math.max(tb[r + 1][c], tb[r][c + 1]);
				}
			}
		}

		int r = row;
		int c = col;
		ArrayDeque<Character> stack = new ArrayDeque<Character>();
		stack.add(' ');
		while ( tb[r][c] != 0 ) {

			// 左上に行けるとき
			if ( tb[r - 1][c - 1] == tb[r][c] ) {
				r -= 1;
				c -= 1;
			} else
			// 上にだけ行けるとき
			if ( tb[r - 1][c] == tb[r][c] ) {
				r -= 1;
			} else
			// 左にだけ行けるとき
			if ( tb[r][c - 1] == tb[r][c] ) {
				c -= 1;
			} else
			// 行き止まり
			{
				stack.add((Character) s[c - 1]);
				r -= 1;
				c -= 1;
			}
		}

		StringBuilder sb = new StringBuilder();
		while ( stack.size() > 0 ) {
			sb.append(stack.pollLast());
		}
		System.out.println(sb);
	}
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 100 points

Problem Statement

You are given strings s and t.
Find one longest string that is a subsequence of both s and t.

Notes

A subsequence of a string x is the string obtained by removing zero or more characters from x and concatenating the remaining characters without changing the order.

Constraints

s and t are strings consisting of lowercase English letters.

1 \leq |s|, |t| \leq 3000

Input

Input is given from Standard Input in the following format:

s
t

Output

Print one longest string that is a subsequence of both s and t.
If there are multiple such strings, any of them will be accepted.

Sample Input 1

axyb
abyxb

Sample Output 1

axb

The answer is axb or ayb; either will be accepted.

Sample Input 2

aa
xayaz

Sample Output 2

aa

Sample Input 3

a
z

Sample Output 3

The answer is (an empty string).

Sample Input 4

abracadabra
avadakedavra

Sample Output 4

aaadara

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	static char	s[];
	static char	t[];

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		s = in.next().toCharArray();
		t = in.next().toCharArray();
		in.close();

		int row = t.length;
		int col = s.length;
		int tb[][] = new int[row + 1][col + 1];
		//int lcs = 0;

		for ( int r = 0; r < row; r++ ) {
			for ( int c = 0; c < col; c++ ) {
				if ( t[r] == s[c] ) {
					tb[r + 1][c + 1] = tb[r][c] + 1;
					// lcs = Math.max(lcs, tb[r + 1][c + 1]);
				} else {
					tb[r + 1][c + 1] = Math.max(tb[r + 1][c], tb[r][c + 1]);
				}
			}
		}

//		for ( int[] is : tb ) {
//			for ( int i : is ) {
//				System.out.print(i + " ");
//			}
//			System.out.println();
//		}

		int r = row;
		int c = col;
		ArrayDeque<Character> stack = new ArrayDeque();
		while ( r > 0 && c > 0 ) {

			// 左上に行けるとき
			if ( tb[r][c] == tb[r - 1][c - 1] ) {
				r -= 1;
				c -= 1;
			} else
			// 上にだけ行けるとき
			if ( tb[r][c] != tb[r][c - 1] && tb[r][c] == tb[r - 1][c] ) {
				r -= 1;
			} else
			// 左にだけ行けるとき
			if ( tb[r][c] == tb[r][c - 1] && tb[r][c] != tb[r - 1][c] ) {
				c -= 1;
			} else
			// 行き止まり
			{
				stack.add((Character) s[c-1]);
				r -= 1;
				c -= 1;
			}
		}
		if(stack.size() == 0) {
			System.out.print(' ');
			return;
		}

		while ( stack.size() > 0 ) {
			System.out.print(stack.pollLast());
		}
//		System.out.println();
//		System.out.println(tb[row][col]);
	}
}


import java.util.*;
import java.io.*;

/*
 * F - LCS
 */
public class Main
{
static char[] s;
static char[] t;
static StringBuilder[][] cache2;
static String answer;
static final StringBuilder nullBuilder = new StringBuilder();

public static void main( String[] args ) throws Exception
{
	long now = System.currentTimeMillis();
	final BufferedReader reader = new BufferedReader( new InputStreamReader( getInputStream() ) );// System.in ) );
	s = reader.readLine().toCharArray();
	t = reader.readLine().toCharArray();
	cache2 = new StringBuilder[ s.length ][ t.length ];

	answer = search( 0, 0 ).toString();

	p( answer );
	if( System.getProperty( "test" ) != null )
	{
		p( answer.length() );
		p( System.currentTimeMillis() - now );
	}
}

public static InputStream getInputStream() throws IOException
{
	//p( System.getProperties() );
	if( System.getProperty( "test" ) != null )
	{
		return new FileInputStream( "1" );
	}
	else
	{
		return System.in;
	}
}

public static StringBuilder search( int I, int J )
{
	if( I == s.length || J == t.length )
	{
		//p( "return null" );
		return nullBuilder;
	}

	{
		final StringBuilder cached = cache2[ I ][ J ];
		if( cached != null )
		{
			//p( "return cached:" + I + " " + J + " " + cached );
			return cached;
		}
	}

	StringBuilder result = null;

	if( s[ I ] == t[ J ] )
	{
		StringBuilder searchResult = search( I + 1, J + 1 );
		StringBuilder tmpResult = new StringBuilder( searchResult.length() + 100 );
		tmpResult.append( s[ I ] );
		tmpResult.append( searchResult );
		result = tmpResult;
	}
	else
	{
		//捨てる場合の結果を取得
		final StringBuilder resultOnDrop = search( I + 1, J );

		//捨てない場合の結果を取得
		//tの最初のs[ I ]と同じ文字の位置を探す
		int index = -1;
		for( int j = J + 1; j < t.length; ++j )
		{
			if( t[ j ] == s[ I ] )
			{
				index = j;
				break;
			}
		}

		if( index != -1 )
		{
			//見つかった
			StringBuilder searchResult = search( I + 1, index + 1 );
			int lengthOnUse = searchResult.length() + 1;

			if( resultOnDrop.length() > lengthOnUse )
			{
				result = resultOnDrop;
			}
			else
			{
				final StringBuilder resultOnUse = new StringBuilder( searchResult.length() + 100 );
				resultOnUse.append( s[ I ] );
				resultOnUse.append( searchResult );
				result = resultOnUse;

				//キャッシュ
				for( int j = J; j < index + 1; ++j )
				{
					cache2[ I ][ j ] = result;
				}
			}
		}
		else
		{
			result = resultOnDrop;
		}

		int cached = 0;
		if( result == resultOnDrop )
		{
			for( int i = I + 1; i < s.length; ++i )
			{
				if( s[ I ] == s[ i ] )
				{
					cache2[ i ][ J ] = result;
					++cached;
				}
				else
				{
					break;
				}
			}

			for( int j = J + 1; j < t.length; ++j )
			{
				if( t[ J ] == t[ j ] )
				{
					cache2[ I ][ j ] = result;
					++cached;
				}
			}
		}
		//p( cached );
	}

	//キャッシュ
	cache2[ I ][ J ] = result;

	return result;
}

public static void p( Object o )
{
	System.out.println( o );
}

}


import java.util.*;
import java.io.*;

/*
 * F - LCS
 */
public class Main
{
static char[] s;
static char[] t;
static StringBuilder[][] cache2;
static String answer;
static final StringBuilder nullBuilder = new StringBuilder();

public static void main( String[] args ) throws Exception
{
	long now = System.currentTimeMillis();
	final BufferedReader reader = new BufferedReader( new InputStreamReader( getInputStream() ) );// System.in ) );
	s = reader.readLine().toCharArray();
	t = reader.readLine().toCharArray();
	cache2 = new StringBuilder[ s.length ][ t.length ];

	answer = search( 0, 0 ).toString();

	p( answer );
	if( System.getProperty( "test" ) != null )
	{
		p( answer.length() );
		p( System.currentTimeMillis() - now );
	}
}

public static InputStream getInputStream() throws IOException
{
	//p( System.getProperties() );
	if( System.getProperty( "test" ) != null )
	{
		return new FileInputStream( "1" );
	}
	else
	{
		return System.in;
	}
}

public static StringBuilder search( int I, int J )
{
	if( I == s.length || J == t.length )
	{
		//p( "return null" );
		return nullBuilder;
	}
	final StringBuilder cached = cache2[ I ][ J ];
	if( cached != null )
	{
		//p( "return cached:" + I + " " + J + " " + cached );
		return cached;
	}

	StringBuilder result = null;

	if( s[ I ] == t[ J ] )
	{
		StringBuilder tmpResult = new StringBuilder();
		tmpResult.append( s[ I ] );
		tmpResult.append( search( I + 1, J + 1 ) );
		result = tmpResult;
	}
	else
	{
		//捨てる場合の結果を取得
		final StringBuilder resultOnDrop = search( I + 1, J );

		//捨てない場合の結果を取得
		//tの最初のs[ I ]と同じ文字の位置を探す
		int index = -1;
		for( int j = J; j < t.length; ++j )
		{
			if( t[ j ] == s[ I ] )
			{
				index = j;
				break;
			}
		}

		if( index != -1 )
		{
			//見つかった
			StringBuilder searchResult = search( I + 1, index + 1 );
			int lengthOnUse = searchResult.length() + 1;

			if( resultOnDrop.length() > lengthOnUse )
			{
				result = resultOnDrop;
			}
			else
			{
				final StringBuilder resultOnUse = new StringBuilder();
				resultOnUse.append( s[ I ] );
				resultOnUse.append( search( I + 1, index + 1 ) );
				result = resultOnUse;

				//キャッシュ
				for( int j = J; j < index + 1; ++j )
				{
					cache2[ I ][ j ] = result;
				}
			}

		}
		else
		{
			result = resultOnDrop;
		}
	}

	//キャッシュ
	cache2[ I ][ J ] = result;

	return result;
}

public static void p( Object o )
{
	System.out.println( o );
}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    private static final BufferedReader READER = new BufferedReader(new InputStreamReader(System.in));

    private static int getInt() {
        return Integer.parseInt(line());
    }

    private static int[] getIntArr(int n) {
        int[] ans = new int[n];

        StringTokenizer stringTokenizer = new StringTokenizer(line(), " ");
        for (int i = 0; i < n && stringTokenizer.hasMoreTokens(); i++) {
            ans[i] = Integer.parseInt(stringTokenizer.nextToken());
        }

        return ans;
    }

    private static String line() {
        try {
            return READER.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static String solve() {
        return solveInternal(line(), line());
    }

    private static String solveInternal(String s, String t) {
        if (s.equals(t)) {
            return s;
        }
        if (s.isEmpty() || t.isEmpty()) {
            return "";
        }

        int[][] dp = new int[s.length()][t.length()];

        char firstS = s.charAt(0);
        char firstT = t.charAt(0);

        dp[0][0] = firstS == firstT ? 1 : 0;

        for (int i = 1; i < s.length(); i++) {
            dp[i][0] = s.charAt(i) == firstT ? 1 : dp[i - 1][0];
        }
        for (int i = 1; i < t.length(); i++) {
            dp[0][i] = t.charAt(i) == firstS ? 1 : dp[0][i - 1];
        }

        for (int i = 1; i < s.length(); i++) {
            for (int j = 1; j < t.length(); j++) {
                if (s.charAt(i) == t.charAt(j)) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }

        char[] ans = new char[dp[s.length() - 1][t.length() - 1]];

        int i = s.length() - 1;
        int j = t.length() - 1;
        int k = ans.length;
        while (k > 0) {

            if (i > 0 && j > 0 && dp[i - 1][j - 1] == k) {
                i--;
                j--;
            } else if (i > 0 && dp[i - 1][j] == k) {
                i--;
            } else if (j > 0 && dp[i][j - 1] == k) {
                j--;
            } else {
                if (s.charAt(i) != t.charAt(j)) {
                    throw new IllegalStateException();
                }
                k--;
                ans[k] = s.charAt(i);
            }
        }
        return new String(ans);
    }

    private static int max(int x, int y, int z) {
        return Math.max(Math.max(x, y), z);
    }

    public static void main(String... args) {
        System.out.println(solve());
//        String s = "aaaaaaaggggaaaaaaaaui";
//        String t = "baaaaahhhhhaaaaaaaaazpok";
//        System.out.println(
//                solveInternal(s, t)
//        );
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static long solve[][] = new long[3002][3002];
    public static char direction[][] = new char[3002][3002];
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s=br.readLine();
        String t=br.readLine();
        int SL=s.length();
        int TL=t.length();
        solve[0][0]=0;
        for(int i=0;i<s.length();i++)
            solve[0][i+1]=0;
        for(int i=0;i<t.length();i++)
            solve[i+1][0]=0;
        //System.out.println(DP(0,0));
        for(int i=1;i<=SL;i++)
        {
            for(int j=1;j<=TL;j++)
            {
                if(s.charAt(i-1)==t.charAt(j-1))
                {
                    solve[i][j]=solve[i-1][j-1]+1;
                    direction[i][j]='d';
                }
                else
                {
                    if(solve[i-1][j]>solve[i][j-1])
                    {
                        solve[i][j]=solve[i-1][j];
                        direction[i][j]='u';
                    }
                    else
                    {
                        solve[i][j]=solve[i][j-1];
                        direction[i][j]='l';
                    }
                }
            }
        }
        //System.out.println(solve[SL][TL]);
        int i=SL,j=TL;
        StringBuilder sb = new StringBuilder("");
        while(i!=0&&j!=0)
        {
            if(direction[i][j]=='d')
            {
                sb.append(s.charAt(i-1));
                i--;
                j--;
            }
            else if(direction[i][j]=='u')
                i--;
            else
                j--;
        }
        System.out.println(sb.reverse().toString());
        /*for(int i=1;i<=SL;i++)
        {
            for(int j=1;j<=TL;j++)
                System.out.print(direction[i][j]+" ");
            System.out.println();
        }*/
    }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        String[][] dp = new String[s.length() + 1][t.length() + 1];
        for (int i = 0 ; i < s.length() + 1 ; i++) {
            for (int j = 0; j < t.length() + 1; j++) {
                dp[i][j] = "";
            }
        }
        for (int i = 0 ; i < s.length(); i++) {
            for (int j = 0 ; j < t.length(); j++) {
                if (s.substring(i, i + 1).equals(t.substring(j, j+1))) {
                    dp[i +1][j + 1] = dp[i][j] + s.substring(i, i + 1);
                } else {
                    if (dp[i][j + 1].length() > dp[i + 1][j].length()) {
                        dp[i +1][j + 1] = dp[i][j + 1];
                    } else {
                        dp[i +1][j + 1] = dp[i + 1][j];
                    }
                }
            }
        }
        System.out.println(dp[s.length()][t.length()]);
    }

}


import java.util.*;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int input = sc.nextInt();

      if (input == 25) {
        System.out.println("Christmas");
      } else if (input == 24) {
        System.out.println("Christmas Eve");
      } else if (input == 23) {
        System.out.println("Christmas Eve Eve");
      } else if (input == 22) {
        System.out.println("Christmas Eve Eve Eve");
      }
    }
  }
}

Score : 100 points

Problem Statement

In some other world, today is December D-th.

Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.

Constraints

22 \leq D \leq 25

D is an integer.

Input

Input is given from Standard Input in the following format:

D

Output

Print the specified string (case-sensitive).

Sample Input 1

25

Sample Output 1

Christmas

Sample Input 2

22

Sample Output 2

Christmas Eve Eve Eve

Be sure to print spaces between the words.


import java.util.Scanner;
/**方針
//層の数が、Stringの桁数を溢れるかいなかの判断が必要。
//レベルN+1のバーガーには、レベルNのバーガーが2つ含まれるので、
//ざっくりレベルNのバーガーは、2^Nの文字数になる。（レベル０のバーガーが１文字なので）
//N<50なので、文字数の最大は2^50≒10^15。
//Stringは大体1億文字（10^8程度）までしか使えないので、単純にバーガーを文字で作ることはできない。
//
//そこで、バーガーの対称性や、再帰性に注目して、以下の作業を繰り返す。
//（ア）XがレベルNバーガーの中心層より、下のとき、
//レベルNバーガーのX番目だが、これはレベルN-1バーガーのX-1番目である。
//（イ）XがレベルNバーガーの中心層より、上のとき、
//レベルNバーガーのX番目は、レベルN-1バーガーの"X-(レベルN-1バーガーの層数)"層目である。
//ただし、このときはレベルN-1バーガーに含まれるパテ数＋１枚のパテを食べていることに注意（足していく）。
//この作業を繰り返していき、「1層目までを食べる。」となったときに終了し、それまでに食べたパテ数が答え。
//ただし繰り返しの中で、もしも途中でXがレベルNバーガーの中心層になったら、簡単に計算できるので求めて、終わり。
*/

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long X = sc.nextLong();
		long ans = 0;
		sc.close();

		//レベルNバーガーの中心の層の数が格納された配列。
		long mid[] = new long[N+1];
		mid[0]=1;
		for(int i=1;i<=N;i++) {
			mid[i]=(mid[i-1]*2-1)+2;
		}

		int levelcount=N;//バーガーのレベル数(ループの度に小さくなる。)
		while (X>1) {
			//Xがバーガーの中心に当たる場合
			//1つ低いレベルのバーガーのパテ数＋１枚食べて終わり
			if(X==mid[levelcount]) {
				ans += getPuttyNum(levelcount-1)+1;
				break;
			}
			//Xがバーガーの中心より上にある場合
			else if(X>mid[levelcount]) {
				//Xがバーガーの一番上だった場合は、そのバーガーを食べきって終了
				if(X==mid[levelcount]*2-1) {
					ans += getPuttyNum(levelcount);
					break;
				}else {
				ans += getPuttyNum(levelcount-1)+1;
				X -= mid[levelcount];
				}
			}
			//Xがバーガーの中心より下にある場合
			else{
				X --;
			}
			levelcount--;
		}
		System.out.println(ans);
	}

	//入力したレベルのバーガーのパテ数を教えてくれる。
	//繰り返し呼び出されるので、これは毎回計算するのではなく、記録すべき。
	//配列に入れればいいが、一旦このまま実行してみて、配列にする場合と比較してみる。
	static long getPuttyNum(int level) {
		long putty_num=0;
		for(int i=0;i<=level;i++) {
			if(i==0) {
				putty_num=1;
			}else {
				putty_num = 2*putty_num+1;
			}
		}
		return putty_num;
	}
}


import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int a = s.nextInt();

    if(a == 25){
      System.out.println("Christmas");
    }else if(a == 24){
      System.out.println("Christmas Eve");
    }else if(a == 23){
      System.out.println("Christmas Eve Eve");
    }else if(a == 22){
      System.out.println("Christmas Eve Eve Eve");
    }
  }
}


import java.util.*;

public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if(x == 25){
            System.out.println("Christmas");
        }else if(x==24){
            System.out.println("Christmas Eve");
        }else if(x==23){
            System.out.println("Christmas Eve Eve");
        }else{
            System.out.println("Christmas Eve Eve Eve");
        }
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0; i<n; i++) {
			nums[i] = sc.nextInt();
		}

		Arrays.sort(nums);
		int min = Integer.MAX_VALUE;
		int start = 0;
		while(k<nums.length) {
			int res = 0;
			for(int i=start; i<k; i++) {
				res = nums[k-1] - nums[0];
			}
			start++;
			k++;
			min = Math.min(min, res);
		}
		System.out.println(min);
	}
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String s = sc.next();

        if (a == 22) {
            System.out.println("Christmas Eve Eve Eve");
        } else if (a == 23) {
            System.out.println("Christmas Eve Eve");
        } else if (a == 24) {
            System.out.println("Christmas Eve");
        } else if (a == 25) {
            System.out.println("Christmas");
        }
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // System.out.println("input a number: ");
        int d = sc.nextInt();

        String result = "Christmas";
        for (int i = 24; i >= d && i>=22; i--) {
            result += " Eve";
        }
        System.out.println(result);
    }
}


import java.util.*;
public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int D = Integer .parseInt(scan.next());

        if(D == 25) System.out.println("Christmas");
        if(D == 24) System.out.println("Christmas Eve");
        if(D == 23) System.out.println("Christmas Eve Eve");
        if(D == 22) System.out.println("Christmas Eve Eve Eve");
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.NoSuchElementException;
/** ABC115-A */
public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();

		//************************************/
		// ここから出力処理
		//************************************/
		PrintWriter out = new PrintWriter(System.out);

		if(N == 25){
			out.println("Christmas");

		}else if(N == 24) {
			out.println("Christmas Eve");

		}else if(N == 23) {
			out.println("Christmas Eve Eve");

		}else if(N == 22) {
			out.println("hristmas Eve Eve Eve");

		}

		// 最後に必ずFlush
		out.flush();
	}
}

///** テンプレート */
//public class Main {
//	public static void main(String[] args) {
//		FastScanner sc = new FastScanner();
//		int N = sc.nextInt();
//		int M =  sc.nextInt();
//
//		int[] ary = new int[N];
//		for(int i = 0; i < N; i++) {
//			ary[i] = sc.nextInt();
//		}
//
//		//************************************/
//		// ここから出力処理
//		//************************************/
//		PrintWriter out = new PrintWriter(System.out);
//
//
//		out.println("hoge");
//
//		// 最後に必ずFlush
//		out.flush();
//	}
//}

/** スキャン用 */
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	/** クラス内部用だよ */
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	/** クラス内部用だよ */
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	/**
	 * クラス内部用だよ
	 * ASCII の文字の内、表示用の文字を返す関数
	 *
	 * @return 改行とか制御文字じゃない、表示用文字ならtrue
	 * */
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	/**
	 * @return 改行文字とか空白以外を除いた、次の文字があればtrue
	 * */
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	/**
	 *
	 * @return 次の文字列
	 */
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}

		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	/**
	 *
	 * @return 次のLong
	 */
	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	/**
	 *
	 * @return 次のInt
	 */
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	/**
	 *
	 * @return 次のDouble
	 */
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {
	/** serialVersionUID. */
	private static final long serialVersionUID = 6411527075103472113L;

	public Pair(final K key, final V value) {
		super(key, value);
	}
}


import java.io.*;
import java.util.*;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] x = new int[N * 3];
        for (int i = 0; i < x.length; ) {
            x[i++] = in.i();
            x[i++] = in.i();
            x[i++] = in.i();
        }

        int x0 = 0;
        int y0 = 0;
        int h0 = 0;
        for (int i = 0; i < x.length; ) {
            x0 = x[i++];
            y0 = x[i++];
            h0 = x[i++];
            if (0 < h0) {
                break;
            }
        }

        for (int Cx = 0; Cx <= 100; Cx++) {
            loop: for (int Cy = 0; Cy <= 100; Cy++) {
                int H = h0 + Math.abs(Cx - x0) + Math.abs(Cy - y0);
                for (int i = 0; i < x.length; ) {
                    int h = Math.max(H - Math.abs(Cx - x[i++]) - Math.abs(Cy - x[i++]), 0);
                    if (h != x[i++]) {
                        continue loop;
                    }
                }
                System.out.printf("%d %d %d\n", Cx, Cy, H);
                return;
            }
        }
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}

Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

N is an integer between 1 and 100 (inclusive).

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.


//package Atcoder;

import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

	static class IO
    {
        BufferedReader br;
        StringTokenizer st;

        public IO()
        {
            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;
        }
    }

	public static void main(String[] args) {
		IO fs = new IO();
		int n = fs.nextInt();
		int [] x = new int[n];
		int [] y = new int[n];
		int [] h = new int[n];
		for(int i = 0; i<n; i++) {
			x[i] = fs.nextInt();
			y[i] = fs.nextInt();
			h[i] = fs.nextInt();
		}
		int ansx,ansy;
		int resx = -1,resy = -1,resh = -1;
		Set<Integer> st = new HashSet<Integer>();
		for(ansx = 0; ansx<=100; ansx++) {
			for(ansy = 0; ansy<=100; ansy++) {
				st.clear();
				boolean canbe = true;
				int ph = 0;
				for(int i = 0; i<n; i++) {
					if(h[i]!=0) {
						ph = h[i] + Math.abs(ansx-x[i]) + Math.abs(ansy - y[i]);
						if(st.isEmpty()||st.contains(ph)) {
							st.add(ph);
							continue;
						}
						else {
							canbe = false;
							break;
						}
					}
				}
				if(canbe) {
					boolean stillpos = true;
					for(int i = 0; i<n; i++) {
						if(h[i] == 0) {
							if(ph> Math.abs(ansx-x[i])+Math.abs(ansy-y[i])) {
								stillpos = false;
								break;
							}
						}
					}
					if(stillpos) {
						resx = ansx;resy = ansy;resh = ph;
						break;
					}
				}
			}
			if(resx!=-1 || resy!=-1 || resh!=-1)break;
		}
		System.out.println(resx+" "+resy+" "+resh);
	}

}


import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        ArrayList<Point> li = new ArrayList<Point>();
        for(int i = 0; i < n; i++){
            li.add(new Point(sc.nextInt(),sc.nextInt(),sc.nextInt()));
        }
        Collections.sort(li);
        for(int i = 0; i <= 100; i++){
            for(int j = 0; j <= 100; j++){
                boolean flg = true;
                Point c = li.get(0);
                int chk = Math.abs(c.x-i)+Math.abs(c.y-j)+c.h;
                for(int k = 1; k < n; k++){
                    Point p = li.get(k);
                    if(!(p.h == 0 && chk <= Math.abs(p.x-i)+Math.abs(p.y-j)) && chk != Math.abs(p.x-i)+Math.abs(p.y-j)+p.h){
                        flg = false;
                        break;
                    }
                }
                if(flg){
                    System.out.println(i+" "+j+" "+chk);
                    return;
                }
            }
        }
    }
}

class Point implements Comparable<Point>{
    int x,y,h;
    public Point(int x, int y, int h){
        this.x = x;
        this.y = y;
        this.h = h;
    }
    public int compareTo(Point p){
        if(this.h > p.h){
            return -1;
        }else if(this.h < p.h){
            return 1;
        }else{
            return 0;
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}


// 20/02/03 17:00

import java.io.*;
import java.util.*;

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve(){

        int n = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        int[] h = new int[n];
        int f = 0;

        for(int i = 0; i < n; i++){
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            h[i] = sc.nextInt();
            if(h[i] > 0 && f == 0) f = i;
        }

        for(int i = 0; i <= 100; i++){
            for(int j = 0; j <= 100; j++){
                boolean flag = true;
                for(int k = 1; k < n; k++){
                    int max = Math.max(h[k], h[k - 1]);
                    int min = Math.min(h[k], h[k - 1]);
                    int maxX;
                    int maxY;
                    int minX;
                    int minY;
                    if(h[k] == max){
                        maxX = x[k];
                        maxY = y[k];
                        minX = x[k - 1];
                        minY = y[k - 1];
                    }else{
                        maxX = x[k - 1];
                        maxY = y[k - 1];
                        minX = x[k];
                        minY = y[k];
                    }
                    if((h[k] != 0 && h[k - 1] != 0) && Math.abs(Math.abs(i - x[k]) + Math.abs(j - y[k]) - Math.abs(Math.abs(i - x[k - 1]) + Math.abs(j - y[k - 1]))) != Math.abs(h[k] - h[k - 1]) || Math.abs(i - maxX) + Math.abs(j - maxY) > Math.abs(i - minX) + Math.abs(j - minY)){ //2点からの距離を満たすか, 高い方から遠くないか
                        flag = false;
                        break;
                    }
                }
                if(flag){
                    int cx = i;
                    int cy = j;
                    int hc = h[f] + Math.abs(cx - x[f]) + Math.abs(cy - y[f]);
                    for(int k = 0; k < n; k++){
                        if(Math.abs(cx - x[k]) + Math.abs(cy - y[k]) != Math.abs(hc - h[k])){
                            flag = false;
                        }
                    }
                    if(flag){
                        System.out.println(cx + " " + cy + " " + hc);
                    }
                }
            }
        }

    }

    long mod_pow(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

    long mod_inv(long a){ // return aの逆元 (mod MOD)
        return mod_pow(a, MOD - 2);
    }

    long fact(long n){ // return n!
        if(n == 0){
            return 1;
        }
        return n * fact(n - 1);
    }

    long mod_fact(long n){ // retur n! (mod MOD)
        if(n == 0){
            return 1;
        }
        return n * mod_fact(n - 1) % MOD;
    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    boolean is_prime(long a){ // aの素数判定
        if(a <= 1) return false;
        for(int i = 2; i * i <= a; i++){
            if(a % i == 0) return false;
        }
        return true;
    }

    String nextPermutation(String s){ // return sの次の順列
        ArrayList<Character> list = new ArrayList<>();
        for(int i = 0; i < s.length(); i++) list.add(s.charAt(i));

        int pivotPos = -1;
        char pivot = 0;
        for(int i = list.size() - 2; i >= 0; i--){
            if(list.get(i) < list.get(i+1)){
    			pivotPos = i;
    			pivot = list.get(i);
    			break;
    		}
    	}

        if(pivotPos == -1 && pivot == 0) return null;

        int L = pivotPos + 1;
        int R = list.size() - 1;
    	int minPos = -1;
    	char min = Character.MAX_VALUE;
    	for(int i = R; i >= L; i--){
    		if(pivot < list.get(i)){
    			if(list.get(i) < min){
    				min = list.get(i);
    				minPos = i;
    			}
    		}
    	}

    	Collections.swap(list, pivotPos, minPos);
    	Collections.sort(list.subList(L, R + 1));

    	StringBuilder sb = new StringBuilder();
    	for(int i=0; i<list.size(); i++) sb.append(list.get(i));

    	return sb.toString();
    }

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <= 0){
                return false;
            }
        }
        return true;
    }
    private int readByte(){
        if(hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c){
        return 33 <= c && c <= 126;
    }
    public boolean hasNext(){
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b <= '9'){
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble(){
        return Double.parseDouble(next());
    }
}

class Pair implements Comparable<Pair>{
    long a, b;
    public Pair(long i, long j){
        a = i;
        b = j;
    }

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


import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();//入力される数
        int[] inx = new int[N];
        int[] iny = new int[N];
        int[] inh = new int[N];
        int H = 0;
        int Cx = 0;
        int Cy = 0;
        int w;
        int temp = 0;
        int flag;

        for(int i = 0;i<N;i++){
            inx[i] = scan.nextInt();
            iny[i] = scan.nextInt();
            inh[i] = scan.nextInt();
        }

        for(int k = 0;k<=100;k++){
            for(int r = 0;r <= 100;r++){
                flag = 1;
                for(int s = 0;s < N;s++){
                    w = getH(inx[s],iny[s],k,r,inh[s]);
                    if(s == 0){
                        temp = w;
                    }else{
                        if(temp != w){
                            flag = -1;
                            break;
                        }
                    }
                }
                if(flag == 1) {
                    Cx = k;
                    Cy = r;
                    H = temp;
                }
            }

        }

        if(H != -1){
            System.out.println(Cx + " " + Cy + " " +H);
        }

    }

    public static int getH(int x,int y,int Cx,int Cy,int h){
        int t = x - Cx > 0 ? x - Cx:Cx - x;
        int u = y - Cy > 0 ? y - Cy:Cy - y;
        int H = h + t + u;
        if(h >= 0){
            return H;
        }else{
            return 0;
        }
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int hi = 0;
		ArrayList<Integer> xlist = new ArrayList<Integer>();
		ArrayList<Integer> ylist = new ArrayList<Integer>();
		ArrayList<Integer> hlist = new ArrayList<Integer>();
		for ( int i = 0; i < n; i++ ) {
			xlist.add(in.nextInt());
			ylist.add(in.nextInt());
			hlist.add(in.nextInt());

			if ( hlist.get(i) != 0 ) hi = i;
		}
		in.close();

		for ( int cy = 0; cy <= 100; cy++ ) {
			for ( int cx = 0; cx <= 100; cx++ ) {
				boolean match = true;
				int Height = hlist.get(hi) + Math.abs(xlist.get(hi) - cx) + Math.abs(ylist.get(hi) - cy);

				for ( int i = 0; i < hlist.size(); i++ ) {
					if(hlist.get(i) != 0) {
						int tempH = hlist.get(i) + Math.abs(xlist.get(i) - cx) + Math.abs(ylist.get(i) - cy);
						if ( Height != tempH ) {
							match = false;
							break;
						} else {
							Height = tempH;
						}
					}

					if(hlist.get(i) == 0 && Height > Math.abs(xlist.get(i) - cx) + Math.abs(ylist.get(i) - cy)) {
						match = false;
						break;
					}
				}
				if ( match ) {
					System.out.println(cx + " " + cy + " " + Height);
					return;
				}
			}
		}
	}
}


import java.util.Scanner;

public class Main {
    static final Scanner sc = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;

    public static void main(String[] args) {
        int N = nint();
        Point[] a = new Point[N];
        for (int i = 0; i < N; i++) {
            a[i] = new Point(nint(), nint(), nint());
        }

        for (int x = 0; x <= 100; x++) {
            loop: for (int y = 0; y < 100; y++) {
                Point maybeC = new Point(x, y);
                maybeC.h = calc_H(maybeC, a[0]);

                for (int i = 0; i < a.length; i++) {
                    if (calc_h(maybeC, a[i]) != a[i].h) {
                        continue loop;
                    }
                }

                System.out.println(maybeC.forAns());
                return;
            }
        }
    }

    static int calc_H(Point maybeC, Point defined) {
        int absX = Math.abs(maybeC.x - defined.x);
        int absY = Math.abs(maybeC.y - defined.y);
        return defined.h + absX + absY;
    }

    static int calc_h(Point c, Point toCalc) {
        return Math.max(c.h - Math.abs(c.x - toCalc.x) - Math.abs(c.y - toCalc.y), 0);
    }

    static class Point {
        int x;
        int y;
        int h;
        public Point(int x, int y, int h) {
            super();
            this.x = x;
            this.y = y;
            this.h = h;
        }

        public Point(int x, int y) {
            this(x, y, -1);
        }

        @Override
        public String toString() {
            return String.format("Point[x:%d, y:%d, h:%d]", x, y, h);
        }

        public String forAns() {
            return x + " " + y + " " + h;
        }
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static String[] nstrs(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = nstr();
        return a;
    }

    private static char[][] nsToChars2D(int h, int w) {
        return nsToChars2D(h, w, 0);
    }

    private static char[][] nsToChars2D(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nsToChars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] h = new int[n];
		int px = 0;
		int py = 0;
		int ph = 0;

		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			h[i] = sc.nextInt();
			if (h[i] > 0 && ph == 0) {
				px = x[i];
				py = y[i];
				ph = h[i];
			}
		}

		for (int i = 0; i <= 100; i++) {
			loop: for (int j = 0; j <= 100; j++) {
				int cx = i;
				int cy = j;
				int ch = ph + Math.abs(cx - px) + Math.abs(cy - py);

//				System.out.println(cx + ", " + cy + ", " + ch);

				for (int k = 0; k < n; k++) {
//					System.out.print("ch=" + ch + ", k=" + k + ", ");
//					System.out.println(h[k] + Math.abs(cx - x[k]) + Math.abs(cy - y[k]));
					if (ch != h[k] + Math.abs(cx - x[k]) + Math.abs(cy - y[k])) {
						continue loop;
					}
				}
				System.out.println(cx + " " + cy + " " + ch);
				System.exit(0);
			}
		}

		sc.close();
	}

}


import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        try{
            //入力
            int N = scan.nextInt();
            int[] x = new int[N];
            int[] y = new int[N];
            int[] h = new int[N];
            for(int i = 0; i < N; i++){
                x[i] = scan.nextInt();
                y[i] = scan.nextInt();
                h[i] = scan.nextInt();
            }

            int X = 0;
            int Y = 0;
            int H = 0;
            loop: for(int cx = 0; cx <= 100; cx++){
                for(int cy = 0; cy <= 100; cy++){
                    for(int i = 0; i < N; i++){
                        if(h[i] != 0){
                            H = h[i] + Math.abs(cx-x[i]) + Math.abs(cy-y[i]);
                            break;
                        }
                    }
                    H = getHeight(H, cx, cy, N, h, x, y);
                    if(H != -1){
                        X = cx;
                        Y = cy;
                        break loop;
                    }
                }
            }

            System.out.println(X+" "+Y+" "+H);

        }finally{
            scan.close();
        }
    }

    static int getHeight(int H, int cx, int cy, int N, int[] h, int[] x, int[] y){
        for(int i = 0; i < N; i++){
            if(h[i] != Math.max(H-Math.abs(cx-x[i])-Math.abs(cy-y[i]), 0)){
                H = -1;
            }
        }
        return H;
    }
}


import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];
	static int ans = 0;
	static long n = 0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] x = new int[n];
		int[]y = new int[n];
		int[] h = new int[n];
		for(int i = 0;i < n;i++){
			x[i] =sc.nextInt();
			y[i] = sc.nextInt();
			h[i] = sc.nextInt();
		}
		for(int cx = 0;cx <= 100;cx++){
			for(int cy = 0;cy <= 100;cy++){
				long H = 0;
				for(int i = 0;i < n;i++){
					if(h[i] != 0){
						H= (long)( h[i] +(long) Math.abs(x[i]-cx) +  Math.abs(y[i]-cy));
						break;
					}
				}

				boolean flag = true;
				for(int i = 0;i < n;i++){
					if(h[i] != 0){
						if(h[i] != H - (long)Math.abs(x[i]-cx) -  Math.abs(y[i]-cy)){
							flag = false;
							break;
						}else{
							if(H - Math.abs(x[i]-cx) -  Math.abs(y[i]-cy)!= 0){
								flag = false;
								break;
							}
						}
					}
				}

				if(flag){
					System.out.println(cx + " " + cy + " " + H);
					return;
				}
			}
		}
	}
}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        Point[] ps = new Point[n];

        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int h = sc.nextInt();
            if (h == 100) {
                System.out.printf("%d %d %d%n", x, y, h);
                return;
            }
            ps[i] = new Point(x, y, h);
        }

        Arrays.sort(ps, (x, y) -> y.h - x.h);

        for (int x = 0; x <= 100; x++) {
            for (int y = 0; y <= 100; y++) {
                if (n >= 3) {
                    int h1 = ps[0].h + Math.abs(ps[0].x - x) + Math.abs(ps[0].y - y);
                    int h2 = ps[1].h + Math.abs(ps[1].x - x) + Math.abs(ps[1].y - y);

                    if (h1 == h2) {
                        System.out.printf("%d %d %d%n", x, y, h1);
                        return;
                    }
                }
            }
        }
    }
}

class Point {
    int x;
    int y;
    int h;

    Point(int x, int y, int h) {
        this.x = x;
        this.y = y;
        this.h = h;
    }
}


import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Point[] arr = new Point[n];
		int zero = 0;
		for(int i=0;i<n;i++){

			arr[i] = new Point(sc.nextInt(), sc.nextInt(), sc.nextInt());

			if(arr[i].h==0)
			    zero++;
		}

		/*if(zero==n){
		    System.out.println("0 0 1");
		}*/
		//else{

			Arrays.sort(arr, new Comparator<Point>(){

				@Override
				public int compare(Point arg0, Point arg1) {
					// TODO Auto-generated method stub
					return -Integer.compare(arg0.h, arg1.h);
				}

			});

    		int h = 0;
    		boolean val=true;
    		L1:for(int x=0;x<=100;x++){
    			for(int y=0;y<=100;y++){
    				val=true;
    				for(int i=0;i<n;i++){
    					if(i==0){
    						h = Math.abs(x-arr[i].x)+Math.abs(y-arr[i].y)+arr[i].h;
    					}
    					else{
    						if(Math.max(h-Math.abs(x-arr[i].x)-Math.abs(y-arr[i].y), 0)!=arr[i].h){
    							val=false;
    							break;
    						}
    					}
    				}
    				if(val && h>=1){
    					System.out.println(x+" "+y+" "+h);
    					break L1;
    				}
    			}
    		}
		//}
	}
}
class Point{
	int x, y, h;
	Point(int x, int y, int h){
		this.x=x;
		this.y=y;
		this.h=h;
	}
}
/*
4
2 3 5
2 1 5
1 2 5
3 2 5

5
2 3 5
2 1 5
1 2 5
3 2 5
10 20 0

2
47 23 0
10 20 0
*/


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] xA = new int[n];
        int[] yA = new int[n];
        int[] hA = new int[n];

        for (int i = 0; i < n; i++) {
            xA[i] = sc.nextInt();
            yA[i] = sc.nextInt();
            hA[i] = sc.nextInt();
        }

        for (int x = 0; x <= 100; x++) {
            for (int y = 0; y <= 100; y++) {
                int i = 0;
                int h = hA[i] + Math.abs(xA[i] - x) + Math.abs(yA[i] - y);
                do {
                    i++;
                    if (i >= n) {
                        if (h < 0)
                            h = 0;
                        System.out.println(x + " " + y + " " + h);
                        System.exit(0);
                    }
                } while (h == hA[i] + Math.abs(xA[i] - x) + Math.abs(yA[i] - y));
            }
        }
    }
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[]x = new int[N];
		int[]y = new int[N];
		int[]h = new int[N];
		for(int i = 0; i < N; i++) {
			x[i] = scan.nextInt();
			y[i] = scan.nextInt();
			h[i] = scan.nextInt();
		}
		scan.close();

		ArrayList<Map<Integer, ArrayList<int[]>>> mlist = new ArrayList<Map<Integer, ArrayList<int[]>>>();
		for(int i = 0; i < N; i++) {
			Map<Integer, ArrayList<int[]>> map = new HashMap<Integer, ArrayList<int[]>>();
			for(int cx = 0; cx <= 100; cx++) {
				for(int cy = 0; cy <= 100; cy++) {
					int H = h[i] + Math.abs(x[i] - cx) + Math.abs(y[i]- cy);
					if(H == 0) continue;
					if(map.containsKey(H)) {
						ArrayList<int[]> list = map.get(H);
						int[]t = {cx, cy};
						list.add(t);
						map.put(H, list);
					}else {
						int[]t = {cx, cy};
						ArrayList<int[]> list = new ArrayList<int[]>();
						list.add(t);
						map.put(H, list);
					}
				}
			}
			mlist.add(map);
		}
		Set<Integer> set = new HashSet<Integer>();
		for(int k : mlist.get(0).keySet()){
			boolean flag = true;
			for(int i = 1; i < N; i++) {
				Map<Integer, ArrayList<int[]>> map = mlist.get(i);
				if(!map.containsKey(k)) {
					flag = false;
					break;
				}
			}
			if(flag) {
				if(k >= 1 && k <= 100) {
					set.add(k);
				}
			}
		}
		int cnt = 0;
		int a[] = new int[3];
		List<int[]> list = new ArrayList<int[]>();
		for(int i : set) {
			Map<Integer, ArrayList<int[]>> map = mlist.get(0);
			for(int j = 0; j < map.get(i).size(); j++) {
				int[]p = map.get(i).get(j);
				int cx = p[0];
				int cy = p[1];
				//System.out.println(cx + " " + cy);
				boolean flag1 = true;
				for(int k = 0; k < N; k++) {
					int t = Math.max(0, i - Math.abs(x[k] - cx) - Math.abs(y[k] - cy));
					if(t != h[k]) {
						flag1 = false;
						break;
					}
				}
				if(flag1) {
					boolean flag0 = true;
					for(int k = 1; k < N; k++) {
						Map<Integer, ArrayList<int[]>> mapK = mlist.get(k);
						List<int[]> listK = mapK.get(i);
						boolean flag = false;
						for(int l = 0; l < listK.size(); l++){
							int[]pK = listK.get(l);
							if(cx == pK[0] || cy == pK[1]) {
								break;
							}
						}
						if(flag) {
							flag0 = false;
							break;
						}
					}
					if(flag0) {
						System.out.println(cx + " " + cy + " " + i);
						System.exit(0);
					}
				}
			}
		}
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc;
	static PrintWriter out;
	public static void main(String[] args){
		sc = new FastScanner();
		out = new PrintWriter(System.out);
		//out.println(solve());
		solve();
		out.flush();
	}

	static void solve(){
		int N = sc.nextInt();
		int[] xList = new int[N];
		int[] yList = new int[N];
		int[] hList = new int[N];
		for(int i=0;i<N;i++){
			xList[i] = sc.nextInt();
			yList[i] = sc.nextInt();
			hList[i] = sc.nextInt();
		}
		int H;
		int tmp;
		boolean res = true;
		for(int x=0;x<=100;x++){
			for(int y=0;y<=100;y++){
				H=-1;
				res = true;
				for(int i=0;i<N;i++){
					tmp = hList[i] + (int)Math.abs(xList[i]-x) + (int)Math.abs(yList[i]-y);
					if(H==-1) H = tmp;
					else if(H!=tmp){
						res = false;
						break;
					}
				}
				if(res && H > 0){
					out.println(x + " " + y + " " + H);
					return;
				}
			}
		}

	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
}


import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] h = new int[n];
		int xtemp = 0;
		int ytemp = 0;
		int htemp = 0;
		int hmax = 0;
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			h[i] = sc.nextInt();
			if (h[i] > 1) {
				xtemp = x[i];
				ytemp = y[i];
				htemp = h[i];
			}
		}
		for (int i = 0; i <= 100; i++) {
			for (int j = 0; j <= 100; j++) {
				hmax = htemp + Math.abs(xtemp - i) + Math.abs(ytemp - j);
				for (int k = 0; k < n; k++) {
					if (hmax - Math.abs(x[k] - i) - Math.abs(y[k] - j) == h[k]) {
						if (k == n - 1) {
							System.out.println(i + " " + j + " " + hmax);
							return;
						}
					} else {
						break;
					}
				}
			}
		}
	}
}


import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		int n;
		int[] xi, yi, hi;
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			n = in.nextInt();
			xi = new int[n];
			yi = new int[n];
			hi = new int[n];

			for (int i = 0; i < n; i++) {
				xi[i] = in.nextInt();
				yi[i] = in.nextInt();
				hi[i] = in.nextInt();
			}

			for (int cx = 0; cx <= 100; cx++) {
				for (int cy = 0; cy <= 100; cy++) {
					int h = -1;
					boolean ok = true;
					for (int i = 0; i < n; i++) {
						int tmp = hi[i] + abs(xi[i] - cx) + abs(yi[i] - cy);
						if (hi[i] > 0) {
							if (h == -1) {
								h = hi[i] + tmp;
							} else {
								if (h != tmp) {
									ok = false;
									break;
								}
							}
						}
					}

					if (!ok) continue;

					for (int i = 0; i < n; i++) {
						if (hi[i] == 0) {
							int dist = abs(xi[i] - cx) + abs(yi[i] - cy);
							if (h > dist) {
								ok = false;
								break;
							}
						}
					}

					if (ok) {
						out.printf("%d %d %d\n", cx, cy, h);
						return;
					}
				}
			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


package atCoder.contest.D;

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] a_x = new int[n];
        int[] a_y = new int[n];
        int[] a_h = new int[n];

        int[][] map = new int [101][101];

        int temp = 0;
        boolean flag = false;

        for(int i = 0;i < n;i++){
            a_x[i] = sc.nextInt();
            a_y[i] = sc.nextInt();
            a_h[i] = sc.nextInt();
        }

        boolean k_flag = true;

        for(int i = 0;i < n;i++){
            map[a_x[i]][a_y[i]] = a_h[i];
        }

        for(int i = 0;i <= 100;i ++){
            for(int j = 0;j <= 100;j ++){
                flag = true;
                for(int k = 0;k < n;k ++){
                    if(a_h[k]!=0) {
                        if (k_flag) {
                            temp = Math.abs(a_x[k] - i) + Math.abs(a_y[k] - j) + a_h[k];
                            k_flag = false;
                        }

//                    System.out.println(i + " " + j + " " + temp);

                        if (temp != Math.abs(a_x[k] - i) + Math.abs(a_y[k] - j) + a_h[k]) {
                            flag = false;
                            break;
                        }
                    }
                }

                if(flag){
                    System.out.println(i + " " + j + " " + temp);
                }
            }
        }

    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int jou[][]=new int[n][3];

		for(int i=0;i<n;i++) {
			jou[i][0]=sc.nextInt();
			jou[i][1]=sc.nextInt();
			jou[i][2]=sc.nextInt();
		}

		for(int i=0;i<=100;i++) {
			for(int j=0;j<=100;j++) {
				sindan(i,j,n, jou);
			}
		}

	}

	public static void sindan(int x, int y, int n, int[][] jou) {

		int height=0;
		boolean ha = true;
		for(int i=0;i<n;i++) {
			if(jou[i][2]!=0) {
				if(height==0) {
					height= jou[i][2] + zettaichi(jou[i][0]-x) + zettaichi(jou[i][1]-y);
					continue;
				}

				if(height!=jou[i][2] + zettaichi(jou[i][0]-x) + zettaichi(jou[i][1]-y)) {
					ha=false;
				}
			}
		}

		for(int i=0;i<n;i++) {
			if(jou[i][2]==0) {
				if(height>jou[i][2] + zettaichi(jou[i][0]-x) + zettaichi(jou[i][1]-y)) {
					ha=false;
				}
			}
		}

		if(ha)
			System.out.print(x + " " + y + " " + height);

	}

	public static int zettaichi(int x) {
		if(x>=0)
			return x;
		else
			return -x;
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
// import java.awt.Point;

public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    // static int mod = 1_000_000_007;
    long inf = Long.MAX_VALUE;

    void solve(){
        int n = ni();
        int[][] res = new int[n][3];
        for(int i = 0; i < n; i++){
            res[i][0] = ni();
            res[i][1] = ni();
            res[i][2] = ni();
        }
        for(int i = 0; i <= 100; i++){
            for(int j= 0; j <= 100; j++){
                int h = -1;
                long upper = inf;
                boolean flag = true;
                for(int k = 0; k < n; k++){
                    if(res[k][2]==0){
                        upper = Math.min((int)Math.abs(res[k][0]-i) + (int)Math.abs(res[k][1]-j), upper);
                        continue;
                    }
                    int h1 = res[k][2] + (int)Math.abs(res[k][0]-i) + (int)Math.abs(res[k][1]-j);
                    if(h==-1){
                        h = h1;
                        continue;
                    }
                    if(h!=h1 || h1>upper){
                        flag = false;
                        break;
                    }
                    h = h1;
                }
                if(h<1) continue;
                if(flag){
                    out.println(i+" "+j+" "+h);
                    return;
                }
            }
        }
    }

    void run() throws Exception
    {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }

}


import java.io.*;
import java.util.*;
import java.math.*;
// import java.awt.Point;

public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    // static int mod = 1_000_000_007;
    long inf = Long.MAX_VALUE;

    void solve(){
        int n = ni();
        int[][] res = new int[n][3];
        for(int i = 0; i < n; i++){
            res[i][0] = ni();
            res[i][1] = ni();
            res[i][2] = ni();
        }
        for(int i = 0; i <= 100; i++){
            for(int j= 0; j <= 100; j++){
                int h = -1;
                int upper = 1000000000;
                boolean flag = true;
                for(int k = 0; k < n; k++){
                    if(res[k][2]==0){
                        upper = Math.min((int)Math.abs(res[k][0]-i) + (int)Math.abs(res[k][1]-j), upper);
                        continue;
                    }
                    int h1 = res[k][2] + (int)Math.abs(res[k][0]-i) + (int)Math.abs(res[k][1]-j);
                    if(h==-1){
                        h = h1;
                        continue;
                    }
                    if(h!=h1 || h1>upper){
                        flag = false;
                        break;
                    }
                    h = h1;
                }
                if(h<1) continue;
                if(flag){
                    out.println(i+" "+j+" "+h);
                    return;
                }
            }
        }
    }

    void run() throws Exception
    {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }

}