jiahuimbzuai/CoQuIR huggingface dataset:
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String{
    input!{
        source = src,
        x: isize,
        n: isize,
        pn: [isize; n],
    }

    let mut pnn = pn;
    pnn.sort();

    let ans1 = solve_rec_i(x, &pnn);
    let ans2 = solve_rec_d(x, &pnn);


    if let Some(a1) = ans1 {
        if let Some(b1) = ans2 {
            let a = x - a1;
            let aa = a * a;

            let b = x - b1;
            let bb = b * b;

            if aa > bb {
                return b1.to_string();
            } else if aa < bb {
                return a1.to_string();
            }
            if a1 >= b1 { 
                return b1.to_string();
            }
            return a1.to_string();
        }
    }

    return 0.to_string();
}

fn solve_rec_i(x: isize, pn: &Vec<isize>) -> Option<isize> {
    let res = pn.binary_search(&x); 
    if let Err(_v) = res {
        return Some(x);
    }

    let a = solve_rec_i(x + 1, pn);
    return a;
}
fn solve_rec_d(x: isize, pn: &Vec<isize>) -> Option<isize> {
    let res = pn.binary_search(&x); 
    if let Err(_v) = res {
        return Some(x);
    }

    let a = solve_rec_d(x - 1, pn);
    return a;
}
//  [rust]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        x: usize,
        n: usize,
        p: [usize; n],
    }
    let mut ans = if n == 0 { x } else { 1000 };

    for i in (0..x).rev() {
        if 0 < p.iter().filter(|&&l| l == i).count() {
            continue;
        }
        ans = i;
        break;
    }

    for i in x..101+1 {
        if 0 < p.iter().filter(|&&l| l == i).count() {
            continue;
        }
        if ans <= x && x - ans == i - x {
            break;
        }
        ans = i;
        break;
    }

    if ans == 1000 {
        ans = 0;
    }

    println!("{}", ans);
}
//  [rust]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        x: usize,
        n: usize,
        p: [usize; n],
    }
    let mut ans = if n == 0 { x } else { 1000 };

    for i in (0..x).rev() {
        if 0 < p.iter().filter(|&&l| l == i).count() {
            continue;
        }
        ans = i;
        break;
    }

    for i in x..101+1 {
        if 0 < p.iter().filter(|&&l| l == i).count() {
            continue;
        }
        if ans <= x && x - ans == i - x {
            break;
        }
        ans = i;
        break;
    }

    println!("{}", ans);
}
//  [rust]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        x: usize,
        n: usize,
        p: [usize; n],
    }
    let mut ans = if n == 0 { x } else { 1000 };

    for i in (0..x).rev() {
        if 0 < p.iter().filter(|&&l| l == i).count() {
            continue;
        }
        ans = i;
        break;
    }

    for i in x..100+1 {
        if 0 < p.iter().filter(|&&l| l == i).count() {
            continue;
        }
        if ans <= x && x - ans == i - x {
            break;
        }
        ans = i;
        break;
    }

    println!("{}", ans);
}
//  [swift]
let inputs = readLine()!.split(separator: " ").map { Int($0)! }

let X = inputs[0]
let N = inputs[1]

if N == 0 {
  print(X)
} else {
	let banned = Set(readLine()!.split(separator: " ").map { Int($0)! })
  	var lessThan = X
  	var graterThan = X
  	for num in X...101 {
      if !banned.contains(num) {
        graterThan = num
        break
      }
    }
  	for num in (0...X).reversed() {
      if !banned.contains(num) {
        lessThan = num
        break
      }
    }
  	if (graterThan - X) * (graterThan - X) > (lessThan - X) * (lessThan - X) {
      print(lessThan)
    } else if (graterThan - X) * (graterThan - X) < (lessThan - X) * (lessThan - X) {
      print(graterThan)
    } else {
      print(lessThan)
    }
}
//  [swift]
class C {
    static func solve() {
        let X = readLine()!.split(separator: " ").map { Int($0)! }.first!
        let ps = readLine()!.split(separator: " ").map { Int($0)! }.sorted()

        if ps.isEmpty {
            print(X)
            return
        }

        var temp = 500
        var diffTemp = 500
        ps.forEach { i in
            let diff = min(abs(X - i), diffTemp)
            if diff < diffTemp {
                temp = i
                diffTemp = diff
            }
        }
        var diff = 0
        while true {
            if !ps.contains(temp - diff) {
                print(temp - diff)
                break
            } else if !ps.contains(temp + diff) {
                print(temp + diff)
                break
            } else {
                diff += 1
            }
        }
    }
}

C.solve()
//  [swift]
import Foundation

let (x, n) = readInts().mapToTuple()
let ps = Set(readInts())
let r = Set(0...101)
    .symmetricDifference(ps)
    .sorted(by: <)
    .sorted { abs($0 - x) < abs($1 - x) }
print(r.first!)

// MARK: -----------------------------------------------------------------------


func readInt() -> Int {
    Int(readLine()!)!
}

func readInts() -> [Int] {
    readLine()!.split(separator: " ").map { Int($0)! }
}

extension Collection {
    func mapToTuple() -> (Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!)
    }
    func mapToTuple() -> (Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!)
    }
    func mapToTuple() -> (Element, Element, Element, Element) {
        var i = makeIterator()
        return (i.next()!, i.next()!, i.next()!, i.next()!)
    }
}

struct DP<Argument: Hashable, Element> {
    var dictionary = [Argument: Element]()
    
    var expression: (Argument, (Argument) -> Element) -> Element
    
    init(expression: @escaping (_ argument: Argument, _ note: (Argument) -> Element) -> Element) {
        self.expression = expression
    }
    
    subscript(_ argument: Argument) -> Element {
        mutating get {
            if let note = dictionary[argument] {
                return note
            } else {
                let result = expression(argument) { self[$0] }
                dictionary[argument] = result
                return result
            }
        }
    }
}
//  [swift]
let xn = readLine()!.split(separator: " ").map{Int($0)!}
let x = xn[0]
let n = xn[1]
let pArray = readLine()!.split(separator: " ").map{Int($0)!}
var lastSmallerX: Int?
var firstBiggerX: Int?

for i in 0...101 {
    if i > x {
        if pArray.contains(i) {
            continue
        } else {
            firstBiggerX = i
            break
        }
    } else {
        if pArray.contains(i) {
            continue
        } else {
            lastSmallerX = i
            continue
        }
    }
}

print(x - lastSmallerX <= firstBiggerX - x ? lastSmallerX! : firstBiggerX!)
//  [swift]
import Foundation

let values = readLine()!.components(separatedBy: " ").map({Int($0)!})
let X = values[0]
let N = values[1]

if N == 0 {
    print(X)
    exit(0)
}

let numbers = readLine()!.components(separatedBy: " ").map({Int($0)!}).sorted()
// numbersの中に含まれない数を抜き出す
let targetValues = [Int]((numbers[0]-1)...(numbers[N-1]+1)).filter{!numbers.contains($0)}

print(targetValues)
if targetValues.count == 0 {
    // 全て連続していた場合
    print(X)
    exit(0)
}

// Xとの絶対値が一番小さいものを探す
var ans = X
var diff = Int.max
for val in targetValues {
    let tmp = abs(val - X)
    if tmp < diff {
        ans = val
        diff = tmp
    }
}

print(ans)
//  [typescript]
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [x, n]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    if (n == 0) {
      return `${x}`;
    }
    const p: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    const pSet = new Set();
    for (let i = 0, len = p.length; i < len; i++) {
      pSet.add(p[i]);
    }
    let i = 0;
    while (true) {
      if (!pSet.has(x - i)) {
        return `${x - i}`;
      }
      if (!pSet.has(x + i)) {
        return `${x + i}`;
      }
      i++;
    }
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));
//  [typescript]
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');
const [xn, _p] = input.split('\n');
const [x, n] = xn.split(' ').map((s) => s >> 0);
const p = new Set(
  _p
    .split(' ')
    .filter((s) => s)
    .map((s) => s >> 0)
);

// console.log(x, n);
// console.log(p);

for (let diff = 0; diff < 100; diff++) {
  // 下方向を見る
  const down = x - diff;
  if (!p.has(down)) {
    console.log(down);
    break;
  }

  // 上方向を見る
  const up = x + diff;
  if (!p.has(up)) {
    console.log(up);
    break;
  }
}
//  [typescript]
// import std = require('tstl')

{
  type Print = void | string | number | string[] | number[]
  let outs: Print[] = []

  const main = (): Print => {
    const r = _io()
    const [X, N] = r.nn()

    if (N === 0) return X
    const p = r.nn()

    const lib = {}

    p.forEach((pv) => {
      lib[pv] = true
    })
    if (!lib[X]) return X
    for (let i = 1; i < 1000; i++) {
      if (!lib[X - i]) return X - i
      if (!lib[X + i]) return X + i
    }

    return -1
  }

  const _io = (i = 0) => {
    const str = require('fs').readFileSync('/dev/stdin', 'utf8')
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')

    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map((v) => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  outs.push(main())

  console.log(
    outs
      .map((line) => (typeof line === 'object' ? line.join(' ') : String(line)))
      .join('\n')
  )
}
//  [python]
# coding: utf-8

a,b,c = input().rstrip().split(" ")

if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")
//  [python]
A, B, C = input().split()
if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")
//  [python]
A, B, C = input().split()
if A[-1] == B[0] and B[-1] == C[0]:
  print("YES")
else :
  print("NO")
//  [python]
a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
  print("Yes")
else:
  print("No")
//  [python]
a,b,c=list(input().split())
if a[-1]==b[1] and b[-1]==c[1]:
  print("Yes")
else:
  print("No")
//  [python]
a,b,c=input().split()
if a[-1]==b[1] and b[-1]==c[1]:
  print("Yes")
else:
  print("No")
//  [java]
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		if (A.endsWith(B.substring(0, 1)) && B.endsWith(C.substring(0, 1))) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b, int[] c) throws IOException {
			if (a.length != b.length || b.length != c.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
				c[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}
//  [java]
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		char[] a = nextString().toCharArray();
		char[] b = nextString().toCharArray();
		char[] c = nextString().toCharArray();


		String ans = "NO";

		if(a[a.length-1]==b[0]&&b[b.length-1]==c[0])
			ans="YES";

		System.out.println(ans);

	}

	public static boolean isPalindromicStr(String s) {
		int h = 0;
		int t = s.length() - 1;
		while (h <= t) {
			if (s.charAt(h) != s.charAt(t)) {
				break;
			}
			h++;
			t--;
		}
		if (h > t) {
			return true;
		}
		return false;
	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            String str1 = strArr[0];
            int str1Length = str1.length();
            String str2 = strArr[1];
            int str2Length = str2.length();
            String str3 = strArr[2];
            if (str1.substring(str1Length - 1, str1Length).equals(str2.substring(0, 1)) && str2.substring(str2Length - 1, str2Length).equals(str3.substring(0, 1))) {
            	System.out.println("YES");
            } else {
            	System.out.println("NO");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
//  [java]
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    if(a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0)) {
		System.out.println("YES");
	}else {
		System.out.println("NO");
	}
  }
}
//  [java]
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<String> one = nextStrArray();
		ArrayList<String> A = myconv(one.get(0), 0);
		ArrayList<String> B = myconv(one.get(1), 0);
		ArrayList<String> C = myconv(one.get(2), 0);
		if(A.get(A.size() - 1).equals(B.get(0)) && A.get(B.size() - 1).equals(C.get(0))){
			myout("YES");
		}else{
			myout("NO");
		}
	}
	//Method addition frame start



	//Method addition frame end
}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		System.out.println(String.valueOf(a.charAt(a.length() - 1)).equals(String.valueOf(b.charAt(0))) &&
				String.valueOf(b.charAt(b.length() - 1)).equals(String.valueOf(c.charAt(0)))? "Yes" : "No");

		sc.close();

	}

}
//  [cpp]
#include<cstdio>
#include<cstring>
int main()
{
	char a[100],b[100],c[100];
	scanf("%s%s%s",a,b,c);
	int x = strlen(a), y = strlen(b), z = strlen(c);
	if(a[x-1] == b[0] && b[y-1] == c[0]) printf("YES");
	else printf("NO");
	return 0;
}
//  [cpp]
#include <cstdio>
#include <cstdlib>
#include <cstring>

int main(){
	char a[20],b[20],c[20];

	scanf("%s %s %s",a,b,c);

	if(a[strlen(a)-1]==b[0]&&b[strlen(b)-1]==c[0]){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

	return 0;
}
//  [cpp]
#include <cstdio>
#include <cstring>
using namespace std;
char s1[20],s2[20],s3[20];
int main() {
	scanf("%s %s %s",s1,s2,s3);
	if (s1[strlen(s1)-1]==s2[0]&&s2[strlen(s2)-1]==s3[0])
		printf("YES\n");
	else printf("NO\n");
	return 0;
}
//  [cpp]
#include <iostream>

int main () {
	std::string a, b, c;
      
  std::cin >> a >> b >> c;
 
  if(a.substr(a.size() -1, 1) == b.substr(0, 1) && b.substr(b.size() -1, 1) == c.substr(0, 1)) {
  	std::cout << "YES" << std::endl;
  }else {
  	std::cout << "NO" << std::endl;
  	std::cout << a.substr(a.size() -1, 1) << std::endl;
  	std::cout << b.substr(0, 1) << std::endl;
    
  }
}
//  [cpp]
#include<iostream>
#include<string>
using namespace std;
int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a.back() == b[0] && b.back() == c[0]) cout << "YES" << endl;
	cout << "NO" << endl;
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>

#define debug_input freopen("stdin.in", "r", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORALL(i, n) for(int i = 0; i < n; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define SORT(a) sort(a.begin(), a.end())
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())
#define ALL(a) a.begin, a.end()
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	string a, b, c, s[3];
	cin >> s[0] >> s[1] >> s[2];
	sort(s, s + 3);

	do {
		a = s[0], b = s[1], c = s[2];
		if(a[a.length() - 1] == b[0] && b[b.length()] == c[0]) {
			cout << "YES" << endl;
			return 0;
		}
	} while(next_permutation(s, s + 3));
	cout << "NO" << endl;
	return 0;
}
//  [c]
//
//  main.c
//  abc060_a
//
//  Created by Ding Chao on 4/29/17.
//  Copyright © 2017 Ding Chao. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    char end = 0, mid = 0, ini = 0;
    while (mid != ' ') {
        end = mid;
        mid = ini;
        ini = getchar();
    }
    if (end != ini) {
        printf("NO");
        return 0;
    }
    else {
        mid = 0;
        while (mid != ' ') {
            end = mid;
            mid = ini;
            ini = getchar();
        }
        if (end != ini) {
            printf("NO");
        }
        else
            printf("YES");
    }
    return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>

int main () {
    char a[10];
    char b[10];
    char c[10];
    scanf("%s %s %s", a, b, c);
    if (a[strlen(a) - 1] == b[0] && b[strlen(b) - 1] == c[0]) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}
//  [c]
#include<stdio.h>
#include<string.h>
int main()
{
	char a[11],b[11],c[11];
	int n=0;
	scanf("%s",a);
	scanf("%s",b);
	scanf("%s",c);
	if(a[strlen(a)-1]==b[0]&&b[strlen(b)-1]==c[0])  printf("YES");
	else printf("NO");
	return 0;
}
//  [c]
#include <stdio.h>

int main (){
    
    char str[10005];
    scanf("%s", str);
    int flag = 0;
    for(int i = 0;str[i] != '\0';i++){
    	if(str[i] == ' '){
    		if(str[i-1] != str[i+1]){
    			flag = 1;
    			break;
			}
		}
	}
	flag == 0 ? puts("YES") : puts("NO");
    
    return 0;
}
//  [c]
#include <stdio.h>

int main (){
    
    char str[1005];
    scanf("%s", str);
    int flag = 0;
    for(int i = 0;str[i] != '\0';i++){
    	if(str[i] == ' '){
    		if(str[i-1] != str[i+1]){
    			flag = 1;
			}
		}
	}
	flag == 0 ? puts("YES") : puts("NO");
    
    return 0;
}
//  [c]
#include <stdio.h>

int main (){
    
    char str[1005];
    scanf("%s", str);
    int flag = 0;
    for(int i = 0;str[i] != '\0';i++){
    	if(str[i] == 'a'){
    		if(str[i-1] != str[i+1]){
    			flag = 1;
			}
		}
	}
	flag == 0 ? puts("YES") : puts("NO");
    
    return 0;
}
//  [javascript]
function Main(input) {
  input = input.trim()
  input = input.split(" ");
if(input[1].slice( 0,1 )==input[0].slice( -1 )&&input[2].slice( 0,1 )==input[1].slice( -1 )){
  console.log("YES");
}else{
  console.log("NO");
}}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
const Main = function(input){
	let xs = input.trim().split(' ');
    let z = xs[1].split('');
    let a = xs[0].split('').reverse();
    let b = xs[1].split('').reverse();
    let c = xs[2].split('');
    
    if(a[0] == z[0] && b[0] == c[0]){
      console.log('YES');
    }else{
      console.log('NO');
    }
  
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));
//  [javascript]
"use strict";
const Main = function(input){
	let xs = input.trim().split(' ');
    let a =xs[0].charAt(xs[0].length-1);
    let b =xs[1].charAt(0);
    let c =xs[1].charAt(xs[1].length-1);
    let d =xs[2].charAt(0);
    
    if(a == b && c == d){
      console.log('YES');
    }else{
      console.log('NO');
    }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));
//  [javascript]
function main(input) {
  input = input.trim();
  const [a,b,c] = input.split(" ").map(Number);
 
  if(a.slice(-1)==b.slice(0,1) && b.slice(-1)==c.slice(0,1)){
    console.log("YES");
  }else{
    console.log("NO");
  }
 
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  input = input.trim();
  const [a,b,c] = input.split(" ").map(Number);

  if(a.slice(-1)==b.slice(0,1) && b.slice(-1)==c.slice(0,1)){
    console.log("Yes");
  }else{
    console.log("No");
  }

}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
	input = input.trim().split(" ");
  var list1 = input[0].split("");
  var list2 = input[1].split("");
  var list3 = input[2].split("");
  if(list1[list1.length - 1] == list2[0] && list2[list1.length - 1] == list3[0]){
     console.log("YES");
     }else{
     console.log("NO");
     }
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import "fmt"

func main() {
	var a string
	var b string
	var c string

	fmt.Scan(&a, &b, &c)

	if a[len(a)-1] == b[0] && b[len(b)-1] == c[0] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}
//  [go]
package main

import (
  "fmt"
)

func areChained(s, t string) bool {return s[len(s)-1] == t[0]}

func main() {
  var a [3]string
  for i := 0; i < 3; i++ {fmt.Scan(&a[i])}
  ans := "YES"
  for i := 0; i < 2; i++ {
    if !areChained(a[i], a[i+1]) {
      ans = "NO"
      break
    }
  }
  fmt.Println(ans)
}
//  [go]
package main

import (
    "bufio"
    "fmt"
    "math"
    "os"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
    sc.Split(bufio.ScanWords)
  sc.Scan()
  var a = sc.Text()
  sc.Scan()
  var b = sc.Text()
  sc.Scan()
  var c = sc.Text()
  
  if(a == b == c) {
    fmt.Println("YES")
  }
  else {
    fmt.Println("NO")
  }
}
//  [go]
package main

import (
  "fmt"
  "strings"
)

func main() {
  var a, b, c string
  
  fmt.Scanf("%s %s %s", &a, &b, &c)
  
  ans := "Yes"
  if !strings.HasSuffix(a, b[:1]) {
  	ans = "NO"
  }
  if !strings.HasSuffix(b, c[:1]) {
  	ans = "NO"
  }
  
  fmt.Printf("%s", ans)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	args := readLine()
	argv := strings.Split(args, " ")
	result := "NO"
	numA, _ := strconv.Atoi(argv[0])
	numB, _ := strconv.Atoi(argv[1])
	numC, _ := strconv.Atoi(argv[2])
	for i := 1; i <= numB; i++ {
		if (numA*i)%numB == numC {
			result = "YES"
			break
		}
	}
	fmt.Println(result)
}
//  [ruby]
arrays = gets.split(' ')
i = 0
f = []
while i < arrays.size
  word = arrays[i].split('')
  f << word
  i += 1
end
# [["r", "n", "g"],
#  ["g", "o", "r", "i", "l", "l", "a"],
#  ["a", "p", "p", "l", "e"]]

if f[0][-1]==f[1][0] && f[1][-1]==f[2][0]
  puts "YES"
else
  puts "NO"
end
//  [ruby]
# abc060 A
a, b, c = gets.split.map(&:chomp)
puts a[-1] == b[0] && b[-1] == c[0] ? 'YES' : 'NO'
//  [ruby]
a,b,c = gets.split
puts a[-1] == b[0] && b[-1] == c[0] ? 'YES' : 'NO'
//  [ruby]
a, b, c = gets.chomp.split
if a[-1] == b[0] && b[-1] == c[0]
  puts 'YES'
else
  puts 'No'
end
//  [ruby]
s = gets
puts s.scan(/(.) \1/).size == 2 ? "YES" : "NO"
//  [ruby]
s = gets
puts s.gsub(/(.) \1/){ $1 } && s.gsub(/(.) \1/){ $1 } ? "YES" : "NO"
//  [rust]
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    assert_eq!(!0usize, std::usize::MAX); //🙊
    let (a, b, c) = (io.chars(), io.chars(), io.chars());
    if a.last() == b.first() && b.last() == c.first() {
        io.writeln("YES");
    } else {
        io.writeln("NO");
    }
}

static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}
//  [rust]
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let (a, b, c) = (vecchar(), vecchar(), vecchar());
    println!(
        "{}",
        if a.last().unwrap() == &b[0] && b.last().unwrap() == &c[0] {
            "YES"
        } else {
            "NO"
        }
    )
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a:chars,
        b:chars,
        c:chars,
    }
    if &a[a.len()-1] == &b[0] && &b[b.len()-1] == &c[0]{
        println!("YES");
    }else{
        println!("NO");
    }
}
//  [rust]
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_string().split_ascii_whitespace().map(|s| s.chars().collect::<Vec<char>>())
        .collect::<Vec<Vec<char>>>();
    let (a, b, c) = (&line[0], &line[1], &line[2]);

    if *a.last().unwrap() == *b.first().unwrap() && *b.last().unwrap() == *c.first().unwrap(){
        println!("YES");
    }else{
        println!("NO");
    }
}
//  [rust]
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{a:[chars;3]};
    println!("{}", if a[0][a[0].len()-1] == a[1][0] && a[1][a[1].len()-1] == a[2][0] {"YES"} else {"No"});
}
//  [rust]
a, b, c = input().split(' ')
if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    func count() -> Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
}
extension Array where Element: Comparable {
    func max() -> Element! {
        return self.maxElement()
    }
    func min() -> Element! {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let input = readStringSplit(by: " ").map{$0.toArray()}
let (A, B, C) = (input[0], input[1], input[2])
print(A[A.count-1]==B[0]&&B[B.count-1]==C[0] ? "YES" : "NO")
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    func count() -> Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
}
extension Array where Element: Comparable {
    func max() -> Element! {
        return self.maxElement()
    }
    func min() -> Element! {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let input = readStringSplit(by: " ").map{$0.toArray()}
let (A, B, C) = (input[0], input[1], input[2])
print(A[A.count()-1]==B[0]&&B[B.count()-1]==C[0] ? "YES" : "NO")
//  [swift]
let i=readLine()!.characters.split(" ").map{String($0).characters.map{String($0)}};print(i[0][i[0].characters.count-1]==i[1][0]&&i[1][i[0].characters.count-1]==i[2][0] ?"YES":"NO")
//  [swift]
let i=readLine()!.characters.split(" ").map{String($0).characters.map{String($0)}};print(i[0][0]==i[1][i.characters.count-1]&&i[1][0]==i[2][i.characters.count-1] ?"YES":"NO")
//  [typescript]
const main = (input) => {
  input = input.split(' ');
  const A = input[0];
  const B = input[1];
  const C = input[2];
  
  const resultA = A.slice(-1);
  const resultB = B.slice(0,1);
  const resultb = B.slice(-1);
  const resultC = C.slice(0,1);
  
  if (resultA==resultB && resultb==resultC) {
    console.log('YES');
  }else{
    console.log('NO');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let[a,b,c]=srin(3)
  out(a[a.length-1]==b[0]&&b[b.length-1]==c[0]?'YES':'NO')
}
main()
//  [typescript]
const main = (input) => {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inpt: Array<string> = input.split(' ');
	let ans = true;
	for (let i = 0; i < 2; i++) {
		ans = inpt[i].charAt(inpt[i].length-1) === inpt[i+1].charAt(0);
		if (!ans) break;
	}

	console.log(ans ? 'YES' : 'NO');
}

// *** debug start ***
const debug = ()  => {
	const input = (<HTMLInputElement>document.getElementById('input')).value;
	input && main(input);
}
// *** debug end ***

//
declare function require(x: string): any;
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
function main(input:string) {
  const i = input.split(" ");
  const a = parseInt(i[0], 10);
  const b = parseInt(i[1], 10);
  const c = parseInt(i[2], 10);
  let result = "NO";

  for (let i = 1; i <= 100; i++){
    if ((i*a) % b === c) {
      result = "YES";
      break;
    }
  }
  console.log(result);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let[a,b,c]=srin(3)
  out(a[a.length-1]==b[0]&&b[b.length-1]==c[0]??'YES':'NO')
}
main()